using System; using System.Collections.Generic; using System.Linq; using BeWo.Validation; using BeWo.ViewModel.ListViewModel; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.Extensions; using BS.Shared.Interface; using BS.Shared.Translation; namespace BeWo.ViewModel { public class InvoiceBaseVM : AbstractDCMapperVM, IInvoiceBase { public static string PropertyName_AccountingPeriodEnd = "AccountingPeriodEnd"; public static string PropertyName_AccountingPeriodStart = "AccountingPeriodStart"; public static string PropertyName_CreatorFirstName = "CreatorFirstName"; public static string PropertyName_CreatorLastName = "CreatorLastName"; public static string PropertyName_CustomerReferenceNumber = "CustomerReferenceNumber"; public static string PropertyName_DueDate = "DueDate"; public static string PropertyName_DunningLetterCount = "DunningLetterCount"; public static string PropertyName_InvoiceDate = "InvoiceDate"; public static string PropertyName_InvoiceItems = "InvoiceItems"; public static string PropertyName_InvoiceNumber = "InvoiceNumber"; public static string PropertyName_InvoiceTitle = "InvoiceTitle"; public static string PropertyName_NeuErstellen = "NeuErstellen"; public static string PropertyName_DiffErstellen = "DiffErstellen"; public static string PropertyName_IsReviewed = "IsReviewed"; public static string PropertyName_IsSent = "IsSent"; public static string PropertyName_IsExported = "IsExported"; public static string PropertyName_IsPaid = "IsPaid"; public static string PropertyName_PartialPayment = "PartialPayment"; public static string PropertyName_Notice = "Notice"; public static string PropertyName_RecipientCostBearerOid = "RecipientCostBearerOid"; public static string PropertyName_RecipientCustomerOid = "RecipientCustomerOid"; public static string PropertyName_RecipientDivision = "RecipientDivision"; public static string PropertyName_RecipientOrganisation = "RecipientOrganisation"; public static string PropertyName_RecipientOrganisationOid = "RecipientOrganisationOid"; public static string PropertyName_RecipientPostBox = "RecipientPostBox"; public static string PropertyName_RecipientPersonFirstName = "RecipientPersonFirstName"; public static string PropertyName_RecipientPersonLastName = "RecipientPersonLastName"; public static string PropertyName_RecipientPersonOid = "RecipientPersonOid"; public static string PropertyName_RecipientPostCode = "RecipientPostCode"; public static string PropertyName_RecipientAddressLine1 = "RecipientAddressLine1"; public static string PropertyName_RecipientStreet = "RecipientStreet"; public static string PropertyName_RecipientTown = "RecipientTown"; public static string PropertyName_ReportLink = "ReportLink"; public static string PropertyName_SenderDivision = "SenderDivision"; public static string PropertyName_SenderFax = "SenderFax"; public static string PropertyName_SenderFirstName = "SenderFirstName"; public static string PropertyName_SenderLastName = "SenderLastName"; public static string PropertyName_SenderOrganisation = "SenderOrganisation"; public static string PropertyName_SenderPhone = "SenderPhone"; public static string PropertyName_SupportConceptOid = "SupportConceptOid"; public static string PropertyName_TotalAmount = "TotalAmount"; public static string PropertyName_TypeString = "TypeString"; 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 _CreatorFirstName = string.Empty; private string _CreatorLastName = string.Empty; private string _CustomerReferenceNumber = string.Empty; private DateTime? _DueDate; private int? _DunningLetterCount; private DateTime? _InvoiceDate; private InvoiceItemListVM _InvoiceItems; private string _InvoiceNumber = string.Empty; private string _InvoiceTitle = string.Empty; internal bool _IsReviewed; internal bool _IsSent; internal bool _IsExported; internal bool _IsPaid; private string _PartialPayment = string.Empty; internal bool _NeuErstellen; internal bool _DiffErstellen; internal bool _IsChecked; private string _Notice = string.Empty; private long? _RecipientCostBearerOid; private long? _RecipientCustomerOid; private string _RecipientDivision = string.Empty; private string _RecipientOrganisation = string.Empty; private long? _RecipientOrganisationOid; private String _RecipientPostBox; private string _RecipientPersonFirstName = string.Empty; private string _RecipientPersonLastName = string.Empty; private long? _RecipientPersonOid; private string _RecipientPostCode = string.Empty; private string _RecipientAddressLine1 = string.Empty; private string _RecipientStreet = string.Empty; private string _RecipientTown = string.Empty; private string _SenderDivision = string.Empty; private string _SenderFax = string.Empty; private string _SenderFirstName = string.Empty; private string _SenderLastName = string.Empty; private string _SenderOrganisation = string.Empty; private string _SenderPhone = string.Empty; private long? _SupportConceptOid; private decimal? _TotalAmount; public InvoiceBaseVM(InvoiceBaseDC pDC) : this(pDC, false) { } public InvoiceBaseVM(InvoiceBaseDC pDC, bool isChecked = false) : base(pDC, pDC.InvoiceBaseOid == null) { _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), PropertyName_AccountingPeriodEnd); FirePropertyChanged(PropertyName_AccountingPeriodEnd); } } } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public DateTime? AccountingPeriodStart { get { return _AccountingPeriodStart; } set { if (AreDifferent(_AccountingPeriodStart, value)) { _AccountingPeriodStart = value; StoreDirtyInformation(AreDifferent(DataContract.AccountingPeriodStart, value), PropertyName_AccountingPeriodStart); FirePropertyChanged(PropertyName_AccountingPeriodStart); } } } public string AccountingPeriodString { get { return _AccountingPeriodEnd.HasValue && _AccountingPeriodStart.HasValue ? _AccountingPeriodStart.Value.ToShortDateString() + " - " + _AccountingPeriodEnd.Value.ToShortDateString() : string.Empty; } set { } } public string CreatorFirstName { get { return _CreatorFirstName; } set { if (AreDifferent(_CreatorFirstName, value)) { _CreatorFirstName = value; StoreDirtyInformation(AreDifferent(DataContract.CreatorFirstName, value), PropertyName_CreatorFirstName); FirePropertyChanged(PropertyName_CreatorFirstName); } } } public string CreatorLastName { get { return _CreatorLastName; } set { if (AreDifferent(_CreatorLastName, value)) { _CreatorLastName = value; StoreDirtyInformation(AreDifferent(DataContract.CreatorLastName, value), PropertyName_CreatorLastName); FirePropertyChanged(PropertyName_CreatorLastName); } } } public string CustomerName { get { string result = string.Empty; if (!String.IsNullOrEmpty(DataContract.CustomerLastName)) { result = DataContract.CustomerLastName; } if (!String.IsNullOrEmpty(DataContract.CustomerFirstName)) { if (result.Length > 0) { result += ", "; } result += DataContract.CustomerFirstName; } return result; } set { } } public string CustomerReferenceNumber { get { return _CustomerReferenceNumber; } set { if (AreDifferent(_CustomerReferenceNumber, value)) { _CustomerReferenceNumber = value; StoreDirtyInformation(AreDifferent(DataContract.CustomerReferenceNumber, value), PropertyName_CustomerReferenceNumber); FirePropertyChanged(PropertyName_CustomerReferenceNumber); } } } public DateTime? DueDate { get { return _DueDate; } set { if (AreDifferent(_DueDate, value)) { _DueDate = value; StoreDirtyInformation(AreDifferent(DataContract.DueDate, value), PropertyName_DueDate); FirePropertyChanged(PropertyName_DueDate); } } } public int? DunningLetterCount { get { return _DunningLetterCount; } set { if (AreDifferent(_DunningLetterCount, value)) { _DunningLetterCount = value; StoreDirtyInformation(AreDifferent(DataContract.DunningLetterCount, value), PropertyName_DunningLetterCount); FirePropertyChanged(PropertyName_DunningLetterCount); } } } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public DateTime? InvoiceDate { get { return _InvoiceDate; } set { if (AreDifferent(_InvoiceDate, value)) { _InvoiceDate = value; StoreDirtyInformation(AreDifferent(DataContract.InvoiceDate, value), PropertyName_InvoiceDate); FirePropertyChanged(PropertyName_InvoiceDate); } } } public InvoiceItemListVM InvoiceItems { get { return _InvoiceItems; } set { if (AreDifferent(_InvoiceItems, value)) { _InvoiceItems = value; FirePropertyChanged(PropertyName_InvoiceItems); } } } public string InvoiceNumber { get { return _InvoiceNumber; } set { if (AreDifferent(_InvoiceNumber, value)) { _InvoiceNumber = value; StoreDirtyInformation(AreDifferent(DataContract.InvoiceNumber, value), PropertyName_InvoiceNumber); FirePropertyChanged(PropertyName_InvoiceNumber); } } } public string InvoiceTitle { get { return _InvoiceTitle; } set { if (AreDifferent(_InvoiceTitle, value)) { _InvoiceTitle = value; StoreDirtyInformation(AreDifferent(DataContract.InvoiceTitle, value), PropertyName_InvoiceTitle); FirePropertyChanged(PropertyName_InvoiceTitle); } } } public string Details { get { return DataContract.Details; } } public string Hinweise { get { return DataContract.Hinweise; } } public bool NeuErstellen { get { return _NeuErstellen; } set { if (AreDifferent(_NeuErstellen, value)) { _NeuErstellen = value; StoreDirtyInformation(AreDifferent(DataContract.NeuErstellen, value), PropertyName_NeuErstellen); FirePropertyChanged(PropertyName_NeuErstellen); } } } public bool DiffErstellen { get { return _DiffErstellen; } set { if (AreDifferent(_DiffErstellen, value)) { _DiffErstellen = value; StoreDirtyInformation(AreDifferent(DataContract.DiffErstellen, value), PropertyName_DiffErstellen); FirePropertyChanged(PropertyName_DiffErstellen); } } } public bool IsReviewed { get { return _IsReviewed; } set { if (AreDifferent(_IsReviewed, value)) { _IsReviewed = value; StoreDirtyInformation(AreDifferent(DataContract.IsReviewed, value), PropertyName_IsReviewed); FirePropertyChanged(PropertyName_IsReviewed); } } } public bool IsSent { get { return _IsSent; } set { if (AreDifferent(_IsSent, value)) { _IsSent = value; StoreDirtyInformation(AreDifferent(DataContract.IsSent, value), PropertyName_IsSent); FirePropertyChanged(PropertyName_IsSent); } } } public bool IsExported { get { return _IsExported; } set { if (AreDifferent(_IsExported, value)) { _IsExported = value; StoreDirtyInformation(AreDifferent(DataContract.IsExported, value), PropertyName_IsExported); FirePropertyChanged(PropertyName_IsExported); } } } public bool IsPaid { get { return _IsPaid; } set { if (AreDifferent(_IsPaid, value)) { _IsPaid = value; StoreDirtyInformation(AreDifferent(DataContract.IsPaid, value), PropertyName_IsPaid); FirePropertyChanged(PropertyName_IsPaid); } } } public string Notice { get { return _Notice; } set { if (AreDifferent(_Notice, value)) { _Notice = value; StoreDirtyInformation(AreDifferent(DataContract.Notice, value), PropertyName_Notice); FirePropertyChanged(PropertyName_Notice); } } } public string PartialPayment { get { return _PartialPayment; } set { if (AreDifferent(_PartialPayment, value)) { _PartialPayment = value; StoreDirtyInformation(AreDifferent(DataContract.PartialPayment, value), PropertyName_PartialPayment); FirePropertyChanged(PropertyName_PartialPayment); } } } public long? RecipientCostBearerOid { get { return _RecipientCostBearerOid; } set { if (AreDifferent(_RecipientCostBearerOid, value)) { _RecipientCostBearerOid = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientCostBearerOid, value), PropertyName_RecipientCostBearerOid); FirePropertyChanged(PropertyName_RecipientCostBearerOid); } } } public long? RecipientCustomerOid { get { return _RecipientCustomerOid; } set { if (AreDifferent(_RecipientCustomerOid, value)) { _RecipientCustomerOid = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientCustomerOid, value), PropertyName_RecipientCustomerOid); FirePropertyChanged(PropertyName_RecipientCustomerOid); } } } public string RecipientDivision { get { return _RecipientDivision; } set { if (AreDifferent(_RecipientDivision, value)) { _RecipientDivision = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientDivision, value), PropertyName_RecipientDivision); FirePropertyChanged(PropertyName_RecipientDivision); } } } public string RecipientOrganisation { get { return _RecipientOrganisation; } set { if (AreDifferent(_RecipientOrganisation, value)) { _RecipientOrganisation = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientOrganisation, value), PropertyName_RecipientOrganisation); FirePropertyChanged(PropertyName_RecipientOrganisation); } } } public long? RecipientOrganisationOid { get { return _RecipientOrganisationOid; } set { if (AreDifferent(_RecipientOrganisationOid, value)) { _RecipientOrganisationOid = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientOrganisationOid, value), PropertyName_RecipientOrganisationOid); FirePropertyChanged(PropertyName_RecipientOrganisationOid); } } } public String RecipientPostBox { get { return _RecipientPostBox; } set { if (AreDifferent(_RecipientPostBox, value)) { _RecipientPostBox = value; StoreDirtyInformation( DataContract.RecipientContactInformations.SingleOrDefault(con => con.ContactType == ContactType.business_POBox && con.ContactValue == value) == null, PropertyName_RecipientPostBox); FirePropertyChanged(PropertyName_RecipientPostBox); } } } public string RecipientPersonFirstName { get { return _RecipientPersonFirstName; } set { if (AreDifferent(_RecipientPersonFirstName, value)) { _RecipientPersonFirstName = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientPersonFirstName, value), PropertyName_RecipientPersonFirstName); FirePropertyChanged(PropertyName_RecipientPersonFirstName); } } } public string RecipientPersonLastName { get { return _RecipientPersonLastName; } set { if (AreDifferent(_RecipientPersonLastName, value)) { _RecipientPersonLastName = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientPersonLastName, value), PropertyName_RecipientPersonLastName); FirePropertyChanged(PropertyName_RecipientPersonLastName); } } } public long? RecipientPersonOid { get { return _RecipientPersonOid; } set { if (AreDifferent(_RecipientPersonOid, value)) { _RecipientPersonOid = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientPersonOid, value), PropertyName_RecipientPersonOid); FirePropertyChanged(PropertyName_RecipientPersonOid); } } } public string RecipientPostCode { get { return _RecipientPostCode; } set { if (AreDifferent(_RecipientPostCode, value)) { _RecipientPostCode = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientPostCode, value), PropertyName_RecipientPostCode); FirePropertyChanged(PropertyName_RecipientPostCode); } } } public string RecipientAddressLine1 { get { return _RecipientAddressLine1; } set { if (AreDifferent(_RecipientAddressLine1, value)) { _RecipientAddressLine1 = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientAddressLine1, value), PropertyName_RecipientAddressLine1); FirePropertyChanged(PropertyName_RecipientAddressLine1); } } } public string RecipientStreet { get { return _RecipientStreet; } set { if (AreDifferent(_RecipientStreet, value)) { _RecipientStreet = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientStreet, value), PropertyName_RecipientStreet); FirePropertyChanged(PropertyName_RecipientStreet); } } } public string RecipientString { get { string result = _RecipientOrganisation; if (!string.IsNullOrEmpty(result) && (!string.IsNullOrEmpty(_RecipientPersonFirstName) || !string.IsNullOrEmpty(_RecipientPersonLastName))) { result += " - "; } result += _RecipientPersonFirstName + " " + _RecipientPersonLastName; return result; } set { } } public string RecipientTown { get { return _RecipientTown; } set { if (AreDifferent(_RecipientTown, value)) { _RecipientTown = value; StoreDirtyInformation(AreDifferent(DataContract.RecipientTown, value), PropertyName_RecipientTown); FirePropertyChanged(PropertyName_RecipientTown); } } } public string ReportLink { get { string url = string.Empty; switch (DataContract.Type) { case InvoiceType.CustomerEquity: url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?ioid=" + DataContract.InvoiceBaseOid + "&type=CustomerInvoice"; break; case InvoiceType.General: url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?ioid=" + DataContract.InvoiceBaseOid + "&type=CustomerInvoice"; break; case InvoiceType.Settlement: url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?ibid=" + DataContract.InvoiceBaseOid + "&type=" + Utils.EnumName(ReportTypes.Settlement); break; case InvoiceType.Service: url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?ibid=" + DataContract.InvoiceBaseOid + "&type=" + Utils.EnumName(ReportTypes.ServiceInvoice); break; default: url = string.Empty; break; } return url; } } public string SenderDivision { get { return _SenderDivision; } set { if (AreDifferent(_SenderDivision, value)) { _SenderDivision = value; StoreDirtyInformation(AreDifferent(DataContract.SenderDivision, value), PropertyName_SenderDivision); FirePropertyChanged(PropertyName_SenderDivision); } } } public string SenderFax { get { return _SenderFax; } set { if (AreDifferent(_SenderFax, value)) { _SenderFax = value; StoreDirtyInformation( DataContract.SenderContactInformations.SingleOrDefault(con => con.ContactType == ContactType.business_Fax && con.ContactValue == value) == null, PropertyName_SenderFax); FirePropertyChanged(PropertyName_SenderFax); } } } public string SenderFirstName { get { return _SenderFirstName; } set { if (AreDifferent(_SenderFirstName, value)) { _SenderFirstName = value; StoreDirtyInformation(AreDifferent(DataContract.SenderFirstName, value), PropertyName_SenderFirstName); FirePropertyChanged(PropertyName_SenderFirstName); } } } public string SenderLastName { get { return _SenderLastName; } set { if (AreDifferent(_SenderLastName, value)) { _SenderLastName = value; StoreDirtyInformation(AreDifferent(DataContract.SenderLastName, value), PropertyName_SenderLastName); FirePropertyChanged(PropertyName_SenderLastName); } } } public string SenderOrganisation { get { return _SenderOrganisation; } set { if (AreDifferent(_SenderOrganisation, value)) { _SenderOrganisation = value; StoreDirtyInformation(AreDifferent(DataContract.SenderOrganisation, value), PropertyName_SenderOrganisation); FirePropertyChanged(PropertyName_SenderOrganisation); } } } public string SenderPhone { get { return _SenderPhone; } set { if (AreDifferent(_SenderPhone, value)) { _SenderPhone = value; StoreDirtyInformation( DataContract.SenderContactInformations.Where(con => con.ContactType == ContactType.business_Phone && con.ContactValue == value).SingleOrDefault() == null, PropertyName_SenderPhone); FirePropertyChanged(PropertyName_SenderPhone); } } } public long? SupportConceptOid { get { return _SupportConceptOid; } set { if (AreDifferent(_SupportConceptOid, value)) { _SupportConceptOid = value; StoreDirtyInformation(AreDifferent(DataContract.SupportConceptOid, value), PropertyName_SupportConceptOid); FirePropertyChanged(PropertyName_SupportConceptOid); } } } public string SenderAddressLine1 { get; set; } public decimal? TotalAmount { get { return _TotalAmount; } set { if (AreDifferent(_TotalAmount, value)) { _TotalAmount = value; StoreDirtyInformation(AreDifferent(DataContract.TotalAmount, value), PropertyName_TotalAmount); FirePropertyChanged(PropertyName_TotalAmount); } } } public string TypeString { get { if (!String.IsNullOrEmpty(DataContract.InvoiceTypeText)) { return DataContract.InvoiceTypeText; } return _TypeTranslation[DataContract.Type]; } } public String BackgroundColor { get; set; } public StoredFileVM XRechnungStoredFileVM { get; set; } public long? Oid => DataContract.InvoiceBaseOid; public string InvoiceId => DataContract.InvoiceId; public string SenderStreet => DataContract.SenderStreet; public string SenderTown => DataContract.SenderTown; public string SenderPostCode => DataContract.SenderPostCode; public IEnumerable IInvoiceItems => InvoiceItems.VMList; protected override void InitByDataContract(InvoiceBaseDC pDataContract) { _SupportConceptOid = pDataContract.SupportConceptOid; _SenderOrganisation = pDataContract.SenderOrganisation; _SenderLastName = pDataContract.SenderLastName; _SenderFirstName = pDataContract.SenderFirstName; _SenderDivision = pDataContract.SenderDivision; _RecipientPersonOid = pDataContract.RecipientPersonOid; _RecipientPersonLastName = pDataContract.RecipientPersonLastName; _RecipientPersonFirstName = pDataContract.RecipientPersonFirstName; _RecipientOrganisationOid = pDataContract.RecipientOrganisationOid; _RecipientOrganisation = pDataContract.RecipientOrganisation; _RecipientDivision = pDataContract.RecipientDivision; _RecipientCustomerOid = pDataContract.RecipientCustomerOid; _RecipientCostBearerOid = pDataContract.RecipientCostBearerOid; _RecipientStreet = pDataContract.RecipientStreet; _RecipientAddressLine1 = pDataContract.RecipientAddressLine1; _RecipientTown = pDataContract.RecipientTown; _RecipientPostCode = pDataContract.RecipientPostCode; _IsReviewed = pDataContract.IsReviewed; _IsSent = pDataContract.IsSent; _IsExported = pDataContract.IsExported; _IsPaid = pDataContract.IsPaid; _PartialPayment = pDataContract.PartialPayment; _NeuErstellen = pDataContract.NeuErstellen; _DiffErstellen = pDataContract.DiffErstellen; _InvoiceTitle = pDataContract.InvoiceTitle; _InvoiceNumber = pDataContract.InvoiceNumber; _InvoiceDate = pDataContract.InvoiceDate; _DueDate = pDataContract.DueDate; _CreatorLastName = pDataContract.CreatorLastName; _CreatorFirstName = pDataContract.CreatorFirstName; _AccountingPeriodEnd = pDataContract.AccountingPeriodEnd; _AccountingPeriodStart = pDataContract.AccountingPeriodStart; _Notice = pDataContract.Notice; _DunningLetterCount = pDataContract.DunningLetterCount; _TotalAmount = pDataContract.TotalAmount; _CustomerReferenceNumber = pDataContract.CustomerReferenceNumber; BackgroundColor = pDataContract.BackgroundColor; foreach (var iContactDC in pDataContract.SenderContactInformations) { if (iContactDC.ContactType == ContactType.business_Fax) { _SenderFax = iContactDC.ContactValue; } if (iContactDC.ContactType == ContactType.business_Phone) { _SenderPhone = iContactDC.ContactValue; } } foreach (var iContactDC in pDataContract.RecipientContactInformations) { if (iContactDC.ContactType == ContactType.business_POBox) { _RecipientPostBox = iContactDC.ContactValue; } } _InvoiceItems = new InvoiceItemListVM(pDataContract.InvoiceItems); IsGkvValid = pDataContract.IsGkvValid; IsGkvValidError = pDataContract.IsGkvValidError; IsAlreadyInActiveGkvAbrechnung = pDataContract.IsAlreadyInActiveGkvAbrechnung; XRechnungStoredFileVM = new StoredFileVM(pDataContract.XRechnungStoredFile); } protected override InvoiceBaseDC MapToDataContract(InvoiceBaseDC pDataContract, bool doCommit) { pDataContract.SupportConceptOid = _SupportConceptOid; pDataContract.SenderOrganisation = _SenderOrganisation; pDataContract.SenderLastName = _SenderLastName; pDataContract.SenderFirstName = _SenderFirstName; pDataContract.SenderDivision = _SenderDivision; pDataContract.RecipientPersonOid = _RecipientPersonOid; pDataContract.RecipientPersonLastName = _RecipientPersonLastName; pDataContract.RecipientPersonFirstName = _RecipientPersonFirstName; pDataContract.RecipientOrganisationOid = _RecipientOrganisationOid; pDataContract.RecipientOrganisation = _RecipientOrganisation; pDataContract.RecipientDivision = _RecipientDivision; pDataContract.RecipientCustomerOid = _RecipientCustomerOid; pDataContract.RecipientCostBearerOid = _RecipientCostBearerOid; pDataContract.RecipientPostCode = _RecipientPostCode; pDataContract.RecipientStreet = _RecipientStreet; pDataContract.RecipientAddressLine1 = _RecipientAddressLine1; pDataContract.RecipientTown = _RecipientTown; pDataContract.IsReviewed = _IsReviewed; pDataContract.IsSent = _IsSent; pDataContract.IsExported = _IsExported; pDataContract.IsPaid = _IsPaid; pDataContract.PartialPayment = _PartialPayment; pDataContract.NeuErstellen = _NeuErstellen; pDataContract.DiffErstellen = _DiffErstellen; pDataContract.InvoiceTitle = _InvoiceTitle; pDataContract.InvoiceNumber = _InvoiceNumber; pDataContract.InvoiceDate = _InvoiceDate; pDataContract.DueDate = _DueDate; pDataContract.CreatorLastName = _CreatorLastName; pDataContract.CreatorFirstName = _CreatorFirstName; pDataContract.AccountingPeriodEnd = _AccountingPeriodEnd; pDataContract.AccountingPeriodStart = _AccountingPeriodStart; pDataContract.Notice = _Notice; pDataContract.DunningLetterCount = _DunningLetterCount; pDataContract.TotalAmount = _TotalAmount; pDataContract.CustomerReferenceNumber = _CustomerReferenceNumber; CommitSenderContact(_SenderFax, ContactType.business_Fax); CommitSenderContact(_SenderPhone, ContactType.business_Phone); CommitReceiverContact(_RecipientPostBox, ContactType.business_POBox); pDataContract.InvoiceItems = _InvoiceItems.CopyToDCList(doCommit); return pDataContract; } private void CommitSenderContact(string pValue, ContactType pContactType) { var lOldContactDCs = DataContract.SenderContactInformations != null ? DataContract.SenderContactInformations.ToList() : new List(); CommitContact(pValue, pContactType, lOldContactDCs); DataContract.SenderContactInformations = lOldContactDCs; } private void CommitReceiverContact(string pValue, ContactType pContactType) { var lOldContactDCs = DataContract.RecipientContactInformations != null ? DataContract.RecipientContactInformations.ToList() : new List(); CommitContact(pValue, pContactType, lOldContactDCs); DataContract.RecipientContactInformations = lOldContactDCs; } private void CommitContact(string pValue, ContactType pContactType, List lOldContactDCs) { var lContactDC = lOldContactDCs.SingleOrDefault(con => con.ContactType == pContactType); if (string.IsNullOrEmpty(pValue) && lContactDC != null) { lOldContactDCs.Remove(lContactDC); } else if (!string.IsNullOrEmpty(pValue)) { if (lContactDC == null) { lContactDC = new ContactDC { ContactType = pContactType }; lOldContactDCs.Add(lContactDC); } lContactDC.ContactValue = pValue; } } } }