using BeWo.Validation; using BeWo.ViewModel.ListViewModel; using BS.Shared.DataContracts; using BS.Shared; using BS.Shared.DataContracts.Light; using BS.Shared.Interface; using BS.Shared.Translation; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using BS.Shared.Core; namespace BeWo.ViewModel.Light { public class InvoiceBaseLightVM : AbstractDCMapperVM { private readonly Dictionary _TypeTranslation = new Dictionary { { InvoiceType.CustomerEquity, Translator.Translate("Eigenanteil") }, { InvoiceType.General, Translator.Translate("Allgemein") }, { InvoiceType.Settlement, Translator.Translate("Spitzabrechnung") }, { InvoiceType.Service, Translator.Translate("Rechnung") } }; private DateTime? _AccountingPeriodEnd; private DateTime? _AccountingPeriodStart; private string _CustomerName = string.Empty; private string _RecipientOrganisation = string.Empty; private DateTime? _InvoiceDate; private string _InvoiceNumber = string.Empty; private string _InvoiceTypeText = string.Empty; private decimal? _TotalAmount; internal bool _IsPaid; internal bool _IsChecked; private string _Notice = string.Empty; public InvoiceBaseLightVM(InvoiceBaseLightDC pDC, bool isChecked = false) : base(pDC, false) { _IsChecked = isChecked; } public bool IsGkvValid { get; private set; } public string IsGkvValidError { get; private set; } public bool? IsAlreadyInActiveGkvAbrechnung { get; private set; } public bool IsChecked { get { return _IsChecked; } set { if (AreDifferent(_IsChecked, value)) { _IsChecked = value; FirePropertyChanged("IsChecked"); } } } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public DateTime? AccountingPeriodEnd { get { return _AccountingPeriodEnd; } set { if (AreDifferent(_AccountingPeriodEnd, value)) { _AccountingPeriodEnd = value; StoreDirtyInformation(AreDifferent(DataContract.AccountingPeriodEnd, value), nameof(AccountingPeriodEnd)); FirePropertyChanged(nameof(AccountingPeriodEnd)); } } } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public DateTime? AccountingPeriodStart { get { return _AccountingPeriodStart; } set { if (AreDifferent(_AccountingPeriodStart, value)) { _AccountingPeriodStart = value; StoreDirtyInformation(AreDifferent(DataContract.AccountingPeriodStart, value), nameof(AccountingPeriodStart)); FirePropertyChanged(nameof(AccountingPeriodStart)); } } } public string AccountingPeriodString { get { return _AccountingPeriodEnd.HasValue && _AccountingPeriodStart.HasValue ? _AccountingPeriodStart.Value.ToShortDateString() + " - " + _AccountingPeriodEnd.Value.ToShortDateString() : string.Empty; } set { } } public string CustomerName { get { return _CustomerName; } set { if (AreDifferent(_CustomerName, value)) { _CustomerName = value; StoreDirtyInformation(AreDifferent(DataContract.CustomerName, value), nameof(CustomerName)); FirePropertyChanged(nameof(CustomerName)); } } } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public DateTime? InvoiceDate { get { return _InvoiceDate; } set { if (AreDifferent(_InvoiceDate, value)) { _InvoiceDate = value; StoreDirtyInformation(AreDifferent(DataContract.InvoiceDate, value), nameof(InvoiceDate)); FirePropertyChanged(nameof(InvoiceDate)); } } } public string InvoiceNumber { get { return _InvoiceNumber; } set { if (AreDifferent(_InvoiceNumber, value)) { _InvoiceNumber = value; StoreDirtyInformation(AreDifferent(DataContract.InvoiceNumber, value), nameof(InvoiceNumber)); FirePropertyChanged(nameof(InvoiceNumber)); } } } public string InvoiceTypeText { get { return _InvoiceTypeText; } set { if (AreDifferent(InvoiceTypeText, value)) { _InvoiceTypeText = value; StoreDirtyInformation(AreDifferent(DataContract.InvoiceTypeText, value), nameof(InvoiceTypeText)); FirePropertyChanged(nameof(InvoiceTypeText)); } } } public bool IsPaid { get { return _IsPaid; } set { if (AreDifferent(_IsPaid, value)) { _IsPaid = value; StoreDirtyInformation(AreDifferent(DataContract.IsPaid, value), nameof(IsPaid)); FirePropertyChanged(nameof(IsPaid)); } } } public string Notice { get { return _Notice; } set { if (AreDifferent(_Notice, value)) { _Notice = value; StoreDirtyInformation(AreDifferent(DataContract.Notice, value), nameof(Notice)); FirePropertyChanged(nameof(Notice)); } } } public string RecipientOrganisation { get { return _RecipientOrganisation; } set { if (AreDifferent(_RecipientOrganisation, value)) { _RecipientOrganisation = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientOrganisation, value), nameof(RecipientOrganisation)); FirePropertyChanged(nameof(RecipientOrganisation)); } } } public string ReportLink { get { string url = string.Empty; switch (DataContract.Type) { case InvoiceType.CustomerEquity: url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?ioid=" + DataContract.Oid + "&type=CustomerInvoice"; break; case InvoiceType.General: url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?ioid=" + DataContract.Oid + "&type=CustomerInvoice"; break; case InvoiceType.Settlement: url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?ibid=" + DataContract.Oid + "&type=" + Utils.EnumName(ReportTypes.Settlement); break; case InvoiceType.Service: url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?ibid=" + DataContract.Oid + "&type=" + Utils.EnumName(ReportTypes.ServiceInvoice); break; default: url = string.Empty; break; } return url; } } public decimal? TotalAmount { get { return _TotalAmount; } set { if (AreDifferent(_TotalAmount, value)) { _TotalAmount = value; StoreDirtyInformation(AreDifferent(DataContract.TotalAmount, value), nameof(TotalAmount)); FirePropertyChanged(nameof(TotalAmount)); } } } public string TypeString { get { if (!String.IsNullOrEmpty(DataContract.InvoiceTypeText)) { return DataContract.InvoiceTypeText; } return _TypeTranslation[DataContract.Type]; } } public String BackgroundColor { get; set; } protected override void InitByDataContract(InvoiceBaseLightDC pDataContract) { // private DateTime? _AccountingPeriodEnd; //private DateTime? _AccountingPeriodStart; //private string _CustomerName = string.Empty; //private string _RecipientOrganisation = string.Empty; //private string InvoiceTypeText = string.Empty; //private DateTime _InvoiceDate; _AccountingPeriodStart = pDataContract.AccountingPeriodStart; _AccountingPeriodEnd = pDataContract.AccountingPeriodEnd; _CustomerName = pDataContract.CustomerName; _RecipientOrganisation = pDataContract.RecipientOrganisation; _IsPaid = pDataContract.IsPaid; _InvoiceTypeText = pDataContract.InvoiceTypeText; _InvoiceNumber = pDataContract.InvoiceNumber; _InvoiceDate = pDataContract.InvoiceDate; _AccountingPeriodEnd = pDataContract.AccountingPeriodEnd; _AccountingPeriodStart = pDataContract.AccountingPeriodStart; _Notice = pDataContract.Notice; _TotalAmount = pDataContract.TotalAmount; } protected override InvoiceBaseLightDC MapToDataContract(InvoiceBaseLightDC pDataContract, bool doCommit) { pDataContract.IsPaid = _IsPaid; pDataContract.Notice = _Notice; return pDataContract; } } }