예제 #1
0
        public static void PopulateFromModel(this Payment sagePayment, Company companyContext, Models.Data.Payment payment)
        {
            sagePayment.AccountReference         = sagePayment.AccountReference.PopulateFromModel(payment.Account, companyContext);
            sagePayment.DiscountAccountReference = sagePayment.DiscountAccountReference.PopulateFromModel(payment.DiscountAccount, companyContext);
            // Если Vendor == null, то обязательно
            sagePayment.MainAddress.PopulateFromModel(payment.MainAddress);
            sagePayment.ReferenceNumber = payment.ReferenceNumber;
            sagePayment.Date            = payment.Date;
            sagePayment.Memo            = payment.Memo;
            sagePayment.PaymentMethod   = payment.PaymentMethod;

            foreach (var expenseLine in payment.ApplyToExpenseLines)
            {
                var sageExpnseLine = sagePayment.AddExpenseLine();
                sageExpnseLine.AccountReference = sageExpnseLine.AccountReference.PopulateFromModel(expenseLine.Account, companyContext);
                sageExpnseLine.Amount           = expenseLine.Amount;
                sageExpnseLine.Description      = expenseLine.Description;
            }
            foreach (var invoiceLine in payment.ApplyToInvoiceLines)
            {
                var sageInvoiceLine = sagePayment.AddInvoiceLine(sagePayment);
                sageInvoiceLine.AccountReference = sageInvoiceLine.AccountReference.PopulateFromModel(invoiceLine.Account, companyContext);
                sageInvoiceLine.Amount           = invoiceLine.Amount;
                sageInvoiceLine.Description      = invoiceLine.Description;
            }
            sagePayment.Save();
        }