public static void PopulateFromModel(this Receipt sageReceipt, Company companyContext, Models.Data.Receipt receipt, SalesInvoice invoice) { sageReceipt.AccountReference = sageReceipt.AccountReference.PopulateFromModel(receipt.Account, companyContext); sageReceipt.DiscountAccountReference = sageReceipt.DiscountAccountReference.PopulateFromModel(receipt.DiscountAccount, companyContext); // Если Customer == null, то обязательно sageReceipt.MainAddress.PopulateFromModel(receipt.MainAddress); sageReceipt.ReferenceNumber = receipt.ReferenceNumber; sageReceipt.ReceiptNumber = receipt.ReceiptNumber; sageReceipt.DepositTicketID = receipt.DepositTicketID; sageReceipt.Date = receipt.Date; sageReceipt.PaymentMethod = receipt.PaymentMethod; sageReceipt.CreditCardAuthorizationInfo.PopulateFromModel(receipt.CreditCardAuthorizationInfo); if (receipt.ApplyToSalesLines != null) { foreach (var salesLine in receipt.ApplyToSalesLines) { var sageSalesLine = sageReceipt.AddSalesLine(); sageSalesLine.AccountReference = sageSalesLine.AccountReference.PopulateFromModel(salesLine.Account, companyContext); sageSalesLine.Amount = salesLine.Amount; sageSalesLine.Description = salesLine.Description; sageSalesLine.Quantity = salesLine.Quantity; sageSalesLine.UnitPrice = salesLine.UnitPrice; sageSalesLine.SalesTaxType = salesLine.SalesTaxType; } } if (receipt.ApplyToInvoiceLines != null) { foreach (var invoiceLine in receipt.ApplyToInvoiceLines) { var sageInvoiceLine = sageReceipt.AddInvoiceLine(invoice); sageInvoiceLine.AccountReference = sageInvoiceLine.AccountReference.PopulateFromModel(invoiceLine.Account, companyContext); sageInvoiceLine.Amount = invoiceLine.Amount; sageInvoiceLine.DiscountAmount = invoiceLine.DiscountAmount; sageInvoiceLine.AmountPaid = invoiceLine.AmountPaid; sageInvoiceLine.Description = invoiceLine.Description; } } sageReceipt.Save(); }