using System;

using BeWo.Validation;

using BS.Shared.DataContracts;
using BeWo.ViewModel.ListViewModel;

namespace BeWo.ViewModel
{
    public class SettlementVM : AbstractDCMapperVM<Settlement2DC>
    {
        public static string PropertyName_AccountingPeriodEnd = "AccountingPeriodEnd";

        public static string PropertyName_AccountingPeriodStart = "AccountingPeriodStart";

        public static string PropertyName_AmountAdvancedPayments = "AmountAdvancedPayments";

        public static string PropertyName_AmountRateFactor = "AmountRateFactor";

        public static string PropertyName_AmountBillableTotal = "AmountBillableTotal";

        public static string PropertyName_ApprovalNoticeDate = "ApprovalNoticeDate";

        public static string PropertyName_ApprovedFLS = "ApprovedFLS";

        // public static string PropertyName_ApprovedFLSIncludingFactor = "ApprovedFLSIncludingFactor";
        public static string PropertyName_Claim = "Claim";

        public static string PropertyName_CreatorFirstName = "CreatorFirstName";

        public static string PropertyName_CreatorLastName = "CreatorLastName";

        public static string PropertyName_CustomerReferenceNumber = "CustomerReferenceNumber";

        public static string PropertyName_DunningLetterCount = "DunningLetterCount";

        public static string PropertyName_EquityContribution = "EquityContribution";

        public static string PropertyName_InvoiceDate = "InvoiceDate";

        public static string PropertyName_InvoiceNumber = "InvoiceNumber";

        public static string PropertyName_Notice = "Notice";

        public static string PropertyName_RateFactor = "RateFactor";

        public static string PropertyName_RecipientContactPerson = "RecipientContactPerson";

        public static string PropertyName_RecipientDivision = "RecipientDivision";

        public static string PropertyName_RecipientOrganisation = "RecipientOrganisation";

        public static string PropertyName_RecipientPostBox = "RecipientPostBox";

        public static string PropertyName_RecipientPostCode = "RecipientPostCode";

        public static string PropertyName_RecipientStreet = "RecipientStreet";

        public static string PropertyName_RecipientTown = "RecipientTown";

        public static string PropertyName_RecordedBillableFLSBrutto = "RecordedBillableFLSBrutto";

        public static string PropertyName_RecordedBillableFLSNetto = "RecordedBillableFLSNetto";

        public static string PropertyName_RecordedBillableFLSNotBillableCustomerAbsent = "RecordedBillableFLSNotBillableCustomerAbsent";

        public static string PropertyName_RecordedBillableFLSNotBillableOutOfApprovedSpan = "RecordedBillableFLSNotBillableOutOfApprovedSpan";

        public static string PropertyName_SenderContactPersonDivision = "SenderContactPersonDivision";

        public static string PropertyName_SenderContactPersonFax = "SenderContactPersonFax";

        public static string PropertyName_SenderContactPersonFirstName = "SenderContactPersonFirstName";

        public static string PropertyName_SenderContactPersonLastName = "SenderContactPersonLastName";

        public static string PropertyName_SenderContactPersonMail = "SenderContactPersonMail";

        public static string PropertyName_SenderContactPersonPhone = "SenderContactPersonPhone";

        public static string PropertyName_ServiceUnitName = "ServiceUnitName";

        public static string PropertyName_InvoiceItems = "InvoiceItems";

		public static string PropertyName_ErrorNotice = "ErrorNotice";

        private DateTime? _AccountingPeriodEnd;

        private DateTime? _AccountingPeriodStart;

        private decimal? _AmountAdvancedPayments;

        private decimal? _AmountRateFactor;

        private decimal? _AmountBillableTotal;

        private DateTime? _ApprovalNoticeDate;

        private decimal? _ApprovedFLS;

        // private decimal? _ApprovedFLSIncludingFactor;
        private decimal? _Claim;

        private string _CreatorFirstName;

        private string _CreatorLastName;

        private string _CustomerReferenceNumber;

        private int? _DunningLetterCount;

        private decimal? _EquityContribution;

        private DateTime? _InvoiceDate;

        private string _InvoiceNumber;

        private string _Notice;

        private decimal? _RateFactor;

        private string _RecipientContactPerson;

        private string _RecipientDivision;

        private string _RecipientOrganisation;

		private string _ErrorNotice;
		
        private String _RecipientPostBox;

        private string _RecipientPostCode;

        private string _RecipientStreet;

        private string _RecipientTown;

        private decimal? _RecordedBillableFLSBrutto;

        private decimal _RecordedBillableFLSNetto;

        private decimal _RecordedBillableFLSNotBillableCustomerAbsent;

        private decimal _RecordedBillableFLSNotBillableOutOfApprovedSpan;

        private string _SenderContactPersonDivision;

        private string _SenderContactPersonFax;

        private string _SenderContactPersonFirstName;

        private string _SenderContactPersonLastName;

        private string _SenderContactPersonMail;

        private string _SenderContactPersonPhone;

        private string _ServiceUnitName;

        private InvoiceItemListVM _InvoiceItems;

        public SettlementVM(Settlement2DC pDC) : base(pDC, pDC.SettlementIvoiceOid == null) { }

        [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public DateTime? AccountingPeriodEnd
        {
            get { return this._AccountingPeriodEnd; }

            set
            {
                if (this.AreDifferent(this._AccountingPeriodEnd, value))
                {
                    this._AccountingPeriodEnd = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.AccountingPeriodEnd, value), PropertyName_AccountingPeriodEnd);
                    this.FirePropertyChanged(PropertyName_AccountingPeriodEnd);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public DateTime? AccountingPeriodStart
        {
            get { return this._AccountingPeriodStart; }

            set
            {
                if (this.AreDifferent(this._AccountingPeriodStart, value))
                {
                    this._AccountingPeriodStart = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.AccountingPeriodStart, value), PropertyName_AccountingPeriodStart);
                    this.FirePropertyChanged(PropertyName_AccountingPeriodStart);
                }
            }
        }

        public decimal? AmountAdvancedPayments
        {
            get { return this._AmountAdvancedPayments; }

            set
            {
                if (this.AreDifferent(this._AmountAdvancedPayments, value))
                {
                    this._AmountAdvancedPayments = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.AmountAdvancedPayments, value), PropertyName_AmountAdvancedPayments);
                    this.FirePropertyChanged(PropertyName_AmountAdvancedPayments);
                }
            }
        }

        public decimal? AmountRateFactor
        {
            get { return this._AmountRateFactor; }

            set { }
        }

        public decimal? AmountBillableTotal
        {
            get { return this._AmountBillableTotal; }

            set
            {
                if (this.AreDifferent(this._AmountBillableTotal, value))
                {
                    this._AmountBillableTotal = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.AmountBillableTotal, value),
                                               PropertyName_AmountBillableTotal);
                    this.FirePropertyChanged(PropertyName_AmountBillableTotal);
                }
            }
        }

        public decimal AmountBillableTotalUntilMax
        {
            get
            {
                decimal amount = AmountBillableTotal ?? 0;
                if (InvoiceItems.VMList.Count > 0)
                {
                    decimal maxApprovedAmount = 0;
                    foreach (var ii in InvoiceItems.VMList)
                    {
                        if (ii.MaxApprovedAmount.HasValue)
                            maxApprovedAmount += ii.MaxApprovedAmount.Value;
                    }
                    if (maxApprovedAmount > 0 && amount > maxApprovedAmount)
                        amount = maxApprovedAmount;
                }
                return amount;

            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.AlwaysValid)]
        public DateTime? ApprovalNoticeDate
        {
            get { return this._ApprovalNoticeDate; }

            set
            {
                if (this.AreDifferent(this._ApprovalNoticeDate, value))
                {
                    this._ApprovalNoticeDate = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ApprovalNoticeDate, value), PropertyName_ApprovalNoticeDate);
                    this.FirePropertyChanged(PropertyName_ApprovalNoticeDate);
                }
            }
        }

        // public decimal? ApprovedFLSIncludingFactor
        // {
        // get { return _ApprovedFLSIncludingFactor; }
        // set
        // {
        // if (base.AreDifferent(_ApprovedFLSIncludingFactor, value))
        // {
        // _ApprovedFLSIncludingFactor = value;
        // StoreDirtyInformation(AreDifferent(DataContract.ApprovedFLSIncludingFactor, value), PropertyName_ApprovedFLSIncludingFactor);
        // FirePropertyChanged(PropertyName_ApprovedFLSIncludingFactor);
        // }
        // }
        // }
        public decimal? ApprovedFLS
        {
            get { return this._ApprovedFLS; }

            set
            {
                if (this.AreDifferent(this._ApprovedFLS, value))
                {
                    this._ApprovedFLS = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ApprovedFLS, value), PropertyName_ApprovedFLS);
                    this.FirePropertyChanged(PropertyName_ApprovedFLS);
                }
            }
        }

        public decimal? Claim
        {
            get { return this._Claim; }

            set
            {
                if (this.AreDifferent(this._Claim, value))
                {
                    this._Claim = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Claim, value), PropertyName_Claim);
                    this.FirePropertyChanged(PropertyName_Claim);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string CreatorFirstName
        {
            get { return this._CreatorFirstName; }

            set
            {
                if (this.AreDifferent(this._CreatorFirstName, value))
                {
                    this._CreatorFirstName = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.CreatorFirstName, value), PropertyName_CreatorFirstName);
                    this.FirePropertyChanged(PropertyName_CreatorFirstName);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string CreatorLastName
        {
            get { return this._CreatorLastName; }

            set
            {
                if (this.AreDifferent(this._CreatorLastName, value))
                {
                    this._CreatorLastName = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.CreatorLastName, value), PropertyName_CreatorLastName);
                    this.FirePropertyChanged(PropertyName_CreatorLastName);
                }
            }
        }

        [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string CustomerReferenceNumber
        {
            get { return this._CustomerReferenceNumber; }

            set
            {
                if (this.AreDifferent(this._CustomerReferenceNumber, value))
                {
                    this._CustomerReferenceNumber = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.CustomerReferenceNumber, value), 
                                               PropertyName_CustomerReferenceNumber);
                    this.FirePropertyChanged(PropertyName_CustomerReferenceNumber);
                }
            }
        }

        public int? DunningLetterCount
        {
            get { return this._DunningLetterCount; }

            set
            {
                if (this.AreDifferent(this._DunningLetterCount, value))
                {
                    this._DunningLetterCount = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.DunningLetterCount, value), PropertyName_DunningLetterCount);
                    this.FirePropertyChanged(PropertyName_DunningLetterCount);
                }
            }
        }

        public decimal? EquityContribution
        {
            get { return this._EquityContribution; }

            set
            {
                if (this.AreDifferent(this._EquityContribution, value))
                {
                    this._EquityContribution = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.EquityContribution, value), PropertyName_EquityContribution);
                    this.FirePropertyChanged(PropertyName_EquityContribution);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public DateTime? InvoiceDate
        {
            get { return this._InvoiceDate; }

            set
            {
                if (this.AreDifferent(this._InvoiceDate, value))
                {
                    this._InvoiceDate = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.InvoiceDate, value), PropertyName_InvoiceDate);
                    this.FirePropertyChanged(PropertyName_InvoiceDate);
                }
            }
        }

        public string InvoiceNumber
        {
            get { return this._InvoiceNumber; }

            set
            {
                if (this.AreDifferent(this._InvoiceNumber, value))
                {
                    this._InvoiceNumber = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.InvoiceNumber, value), PropertyName_InvoiceNumber);
                    this.FirePropertyChanged(PropertyName_InvoiceNumber);
                }
            }
        }

        public string Notice
        {
            get { return this._Notice; }

            set
            {
                if (this.AreDifferent(this._Notice, value))
                {
                    this._Notice = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Notice, value), PropertyName_Notice);
                    this.FirePropertyChanged(PropertyName_Notice);
                }
            }
        }

        public decimal? RateFactor
        {
            get { return this._RateFactor; }

            set { }
        }

        public string RecipientContactPerson
        {
            get { return this._RecipientContactPerson; }

            set
            {
                if (this.AreDifferent(this._RecipientContactPerson, value))
                {
                    this._RecipientContactPerson = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.RecipientContactPerson, value), PropertyName_RecipientContactPerson);
                    this.FirePropertyChanged(PropertyName_RecipientContactPerson);
                }
            }
        }

        public string RecipientDivision
        {
            get { return this._RecipientDivision; }

            set
            {
                if (this.AreDifferent(this._RecipientDivision, value))
                {
                    this._RecipientDivision = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.RecipientDivision, value), PropertyName_RecipientDivision);
                    this.FirePropertyChanged(PropertyName_RecipientDivision);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string RecipientOrganisation
        {
            get { return this._RecipientOrganisation; }

            set
            {
                if (this.AreDifferent(this._RecipientOrganisation, value))
                {
                    this._RecipientOrganisation = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.RecipientOrganisation, value), PropertyName_RecipientOrganisation);
                    this.FirePropertyChanged(PropertyName_RecipientOrganisation);
                }
            }
        }

        public String RecipientPostBox
        {
            get { return _RecipientPostBox; }

            set
            {
                if (AreDifferent(_RecipientPostBox, value))
                {
                    _RecipientPostBox = value;
                    StoreDirtyInformation(AreDifferent(DataContract.RecipientPostBox, value), PropertyName_RecipientPostBox);
                    FirePropertyChanged(PropertyName_RecipientPostBox);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string RecipientPostCode
        {
            get { return this._RecipientPostCode; }

            set
            {
                if (this.AreDifferent(this._RecipientPostCode, value))
                {
                    this._RecipientPostCode = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.RecipientPostCode, value), PropertyName_RecipientPostCode);
                    this.FirePropertyChanged(PropertyName_RecipientPostCode);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string RecipientStreet
        {
            get { return this._RecipientStreet; }

            set
            {
                if (this.AreDifferent(this._RecipientStreet, value))
                {
                    this._RecipientStreet = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.RecipientStreet, value), PropertyName_RecipientStreet);
                    this.FirePropertyChanged(PropertyName_RecipientStreet);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string RecipientTown
        {
            get { return this._RecipientTown; }

            set
            {
                if (this.AreDifferent(this._RecipientTown, value))
                {
                    this._RecipientTown = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.RecipientTown, value), PropertyName_RecipientTown);
                    this.FirePropertyChanged(PropertyName_RecipientTown);
                }
            }
        }

        public decimal? RecordedBillableFLSBrutto
        {
            get { return this._RecordedBillableFLSBrutto; }

            set
            {
                if (this.AreDifferent(this._RecordedBillableFLSBrutto, value))
                {
                    this._RecordedBillableFLSBrutto = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.RecordedBillableFLSBrutto, value), 
                                               PropertyName_RecordedBillableFLSBrutto);
                    this.FirePropertyChanged(PropertyName_RecordedBillableFLSBrutto);
                }
            }
        }

        public decimal RecordedBillableFLSNetto
        {
            get { return this._RecordedBillableFLSNetto; }

            set
            {
                if (this.AreDifferent(this._RecordedBillableFLSNetto, value))
                {
                    this._RecordedBillableFLSNetto = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.RecordedBillableFLSNetto, value), 
                                               PropertyName_RecordedBillableFLSNetto);
                    this.FirePropertyChanged(PropertyName_RecordedBillableFLSNetto);
                }
            }
        }

        public decimal RecordedBillableFLSNotBillableCustomerAbsent
        {
            get { return this._RecordedBillableFLSNotBillableCustomerAbsent; }

            set
            {
                if (this.AreDifferent(this._RecordedBillableFLSNotBillableCustomerAbsent, value))
                {
                    this._RecordedBillableFLSNotBillableCustomerAbsent = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.RecordedBillableFLSNotBillableCustomerAbsent, value), 
                                               PropertyName_RecordedBillableFLSNotBillableCustomerAbsent);
                    this.FirePropertyChanged(PropertyName_RecordedBillableFLSNotBillableCustomerAbsent);
                }
            }
        }

        public decimal RecordedBillableFLSNotBillableOutOfApprovedSpan
        {
            get { return this._RecordedBillableFLSNotBillableOutOfApprovedSpan; }

            set
            {
                if (this.AreDifferent(this._RecordedBillableFLSNotBillableOutOfApprovedSpan, value))
                {
                    this._RecordedBillableFLSNotBillableOutOfApprovedSpan = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.RecordedBillableFLSNotBillableOutOfApprovedSpan, value), 
                                               PropertyName_RecordedBillableFLSNotBillableOutOfApprovedSpan);
                    this.FirePropertyChanged(PropertyName_RecordedBillableFLSNotBillableOutOfApprovedSpan);
                }
            }
        }

        public string SenderContactPersonDivision
        {
            get { return this._SenderContactPersonDivision; }

            set
            {
                if (this.AreDifferent(this._SenderContactPersonDivision, value))
                {
                    this._SenderContactPersonDivision = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.SenderContactPersonDivision, value), 
                                               PropertyName_SenderContactPersonDivision);
                    this.FirePropertyChanged(PropertyName_SenderContactPersonDivision);
                }
            }
        }

        public string SenderContactPersonFax
        {
            get { return this._SenderContactPersonFax; }

            set
            {
                if (this.AreDifferent(this._SenderContactPersonFax, value))
                {
                    this._SenderContactPersonFax = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.SenderContactPersonFax, value), PropertyName_SenderContactPersonFax);
                    this.FirePropertyChanged(PropertyName_SenderContactPersonFax);
                }
            }
        }

        public string SenderContactPersonFirstName
        {
            get { return this._SenderContactPersonFirstName; }

            set
            {
                if (this.AreDifferent(this._SenderContactPersonFirstName, value))
                {
                    this._SenderContactPersonFirstName = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.SenderContactPersonFirstName, value), 
                                               PropertyName_SenderContactPersonFirstName);
                    this.FirePropertyChanged(PropertyName_SenderContactPersonFirstName);
                }
            }
        }

        public string SenderContactPersonLastName
        {
            get { return this._SenderContactPersonLastName; }

            set
            {
                if (this.AreDifferent(this._SenderContactPersonLastName, value))
                {
                    this._SenderContactPersonLastName = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.SenderContactPersonLastName, value), 
                                               PropertyName_SenderContactPersonLastName);
                    this.FirePropertyChanged(PropertyName_SenderContactPersonLastName);
                }
            }
        }

        public string SenderContactPersonMail
        {
            get { return this._SenderContactPersonMail; }

            set
            {
                if (this.AreDifferent(this._SenderContactPersonMail, value))
                {
                    this._SenderContactPersonMail = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.SenderContactPersonMail, value), 
                                               PropertyName_SenderContactPersonMail);
                    this.FirePropertyChanged(PropertyName_SenderContactPersonMail);
                }
            }
        }

        public string SenderContactPersonPhone
        {
            get { return this._SenderContactPersonPhone; }

            set
            {
                if (this.AreDifferent(this._SenderContactPersonPhone, value))
                {
                    this._SenderContactPersonPhone = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.SenderContactPersonPhone, value), 
                                               PropertyName_SenderContactPersonPhone);
                    this.FirePropertyChanged(PropertyName_SenderContactPersonPhone);
                }
            }
        }

        public string ServiceUnitName
        {
            get { return this._ServiceUnitName; }

            set
            {
                if (this.AreDifferent(this._ServiceUnitName, value))
                {
                    this._ServiceUnitName = value;
                    this.FirePropertyChanged(PropertyName_ServiceUnitName);
                }
            }
        }


		public string ErrorNotice
		{
			get { return this._ErrorNotice; }

			set
			{
				if (this.AreDifferent(this._ErrorNotice, value))
				{
					this._ErrorNotice = value;
					this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ErrorNotice, value), PropertyName_ErrorNotice);
					this.FirePropertyChanged(PropertyName_ErrorNotice);
				}
			}
		}

        public InvoiceItemListVM InvoiceItems
        {
            get
            {
                return this._InvoiceItems;
            }

            set
            {
                if (this.AreDifferent(this._InvoiceItems, value))
                {
                    this._InvoiceItems = value;
                    this.FirePropertyChanged(PropertyName_InvoiceItems);
                }
            }
        }

        protected override void InitByDataContract(Settlement2DC pDataContract)
        {
            AccountingPeriodEnd                             = pDataContract.AccountingPeriodEnd;
            AccountingPeriodStart                           = pDataContract.AccountingPeriodStart;
            ApprovalNoticeDate                              = pDataContract.ApprovalNoticeDate;
            CreatorFirstName                                = pDataContract.CreatorFirstName;
            CreatorLastName                                 = pDataContract.CreatorLastName;
            CustomerReferenceNumber                         = pDataContract.CustomerReferenceNumber;
            InvoiceDate                                     = pDataContract.InvoiceDate;
            InvoiceNumber                                   = pDataContract.InvoiceNumber;
            Notice                                          = pDataContract.Notice;
            RecipientContactPerson                          = pDataContract.RecipientContactPerson;
            RecipientDivision                               = pDataContract.RecipientDivision;
            RecipientOrganisation                           = pDataContract.RecipientOrganisation;
            RecipientPostBox                                = pDataContract.RecipientPostBox;
            RecipientPostCode                               = pDataContract.RecipientPostCode;
            RecipientStreet                                 = pDataContract.RecipientStreet;
            RecipientTown                                   = pDataContract.RecipientTown;
            SenderContactPersonDivision                     = pDataContract.SenderContactPersonDivision;
            SenderContactPersonFax                          = pDataContract.SenderContactPersonFax;
            SenderContactPersonFirstName                    = pDataContract.SenderContactPersonFirstName;
            SenderContactPersonLastName                     = pDataContract.SenderContactPersonLastName;
            SenderContactPersonMail                         = pDataContract.SenderContactPersonMail;
            SenderContactPersonPhone                        = pDataContract.SenderContactPersonPhone;
            ServiceUnitName                                 = pDataContract.ServiceUnit.UnitName;
            RecordedBillableFLSBrutto                       = pDataContract.RecordedBillableFLSBrutto;
            RecordedBillableFLSNetto                        = pDataContract.RecordedBillableFLSNetto;
            RecordedBillableFLSNotBillableOutOfApprovedSpan = pDataContract.RecordedBillableFLSNotBillableOutOfApprovedSpan;
            RecordedBillableFLSNotBillableCustomerAbsent    = pDataContract.RecordedBillableFLSNotBillableCustomerAbsent;
            ApprovedFLS                                     = pDataContract.ApprovedFLS;
			ErrorNotice = pDataContract.ErrorNotice;

            // ApprovedFLSIncludingFactor = pDataContract.ApprovedFLSIncludingFactor;
            Claim                         = pDataContract.Claim;
            AmountBillableTotal           = pDataContract.AmountBillableTotal;
            AmountAdvancedPayments        = pDataContract.AmountAdvancedPayments;
            _RateFactor                   = pDataContract.RateFactor;
            _AmountRateFactor             = pDataContract.AmountWithRateFactor;
            _DunningLetterCount           = pDataContract.DunningLetterCount;
            _EquityContribution           = pDataContract.EquityContribution;

            _InvoiceItems = new InvoiceItemListVM(pDataContract.InvoiceItems);
        }

        protected override Settlement2DC MapToDataContract(Settlement2DC pDataContract, bool doCommit)
        {
            pDataContract.AccountingPeriodEnd                             = AccountingPeriodEnd;
            pDataContract.AccountingPeriodStart                           = AccountingPeriodStart;
            pDataContract.ApprovalNoticeDate                              = ApprovalNoticeDate;
            pDataContract.CreatorFirstName                                = CreatorFirstName;
            pDataContract.CreatorLastName                                 = CreatorLastName;
            pDataContract.CustomerReferenceNumber                         = CustomerReferenceNumber;
            pDataContract.InvoiceDate                                     = InvoiceDate;
            pDataContract.InvoiceNumber                                   = InvoiceNumber;
            pDataContract.Notice                                          = Notice;
            pDataContract.RecipientContactPerson                          = RecipientContactPerson;
            pDataContract.RecipientDivision                               = RecipientDivision;
            pDataContract.RecipientOrganisation                           = RecipientOrganisation;
            pDataContract.RecipientPostBox                                = RecipientPostBox;
            pDataContract.RecipientPostCode                               = RecipientPostCode;
            pDataContract.RecipientStreet                                 = RecipientStreet;
            pDataContract.RecipientTown                                   = RecipientTown;
            pDataContract.SenderContactPersonDivision                     = SenderContactPersonDivision;
            pDataContract.SenderContactPersonFax                          = SenderContactPersonFax;
            pDataContract.SenderContactPersonFirstName                    = SenderContactPersonFirstName;
            pDataContract.SenderContactPersonLastName                     = SenderContactPersonLastName;
            pDataContract.SenderContactPersonMail                         = SenderContactPersonMail;
            pDataContract.SenderContactPersonPhone                        = SenderContactPersonPhone;
            pDataContract.DunningLetterCount                              = _DunningLetterCount;
            pDataContract.RecordedBillableFLSBrutto                       = RecordedBillableFLSBrutto;
            pDataContract.RecordedBillableFLSNetto                        = RecordedBillableFLSNetto;
            pDataContract.RecordedBillableFLSNotBillableOutOfApprovedSpan = RecordedBillableFLSNotBillableOutOfApprovedSpan;
            pDataContract.RecordedBillableFLSNotBillableCustomerAbsent    = RecordedBillableFLSNotBillableCustomerAbsent;
            pDataContract.ApprovedFLS                                     = ApprovedFLS;
			pDataContract.ErrorNotice = ErrorNotice;

            // DataContract.ApprovedFLSIncludingFactor = ApprovedFLSIncludingFactor;
            pDataContract.Claim                        = Claim;
            pDataContract.AmountBillableTotal          = AmountBillableTotal;
            pDataContract.AmountAdvancedPayments       = AmountAdvancedPayments;
            pDataContract.EquityContribution           = EquityContribution;

            if (_InvoiceItems.VMList.Count > 0)
                pDataContract.InvoiceItems = _InvoiceItems.CopyToDCList(doCommit);

            return pDataContract;
        }
    }
}