public virtual void AddLine(string description, double quantity, decimal lineAmount, Call call, Contract contract) { var line = new InvoiceLine { Description = description, Quantity = quantity, LineAmount = lineAmount, GstAmount = lineAmount/11M, Call = call, Invoice = this }; if (contract != null) line.ContractId = contract.Id.Value; _lines.Add(line); }
public static Invoice GetInvoiceEntity(this InvoiceHeader header) { var address = new Address { Street = header.Street, Street2 = header.Street2, Suburb = header.Suburb, State = header.State, Postcode = header.Postcode }; Invoice entity; if (header.IsInternational.HasValue && header.IsInternational.Value) { entity = new NoGstInvoice(header.InvoiceHeaderId); } else { entity = new Invoice(header.InvoiceHeaderId); } entity.InvoiceNumber = header.InvoiceNumber; entity.InvoiceDate = header.InvoiceDate; entity.InvoiceAddress = address; entity.FromDate = header.FromDate; entity.ToDate = header.ToDate; entity.InvoiceRunNumber = header.InvoiceRunNumber; entity.To = header.To; entity.PreviousBill = header.PreviousBill; entity.AmountPaid = header.AmountPaid; entity.Outstanding = header.Outstanding; entity.NewCharges = header.NewCharges; entity.CurrentBill = header.CurrentBill; entity.TotalIncGst = header.TotalIncGst; entity.TotalGst = header.TotalGst; entity.TotalExGst = header.TotalExGst; entity.HasFailedPayment = header.HasFailedPayment; if (header.PaymentDue.HasValue) entity.PaymentDue = header.PaymentDue.Value; foreach (var item in header.InvoiceLineItems) { var call = item.Call.CreateEntity(); var line = new InvoiceLine(item.InvoiceLineItemId) { Call = call, Description = item.Description, LineAmount = item.LineAmount, GstAmount = item.GstAmount, Invoice = entity, ContractId = item.ContractId }; entity.AddLine(line); } foreach (var account in header.AccountInvoices) { entity.AddAccount(account.AccountId); if (account.Account.IsInvoiceRoot) { entity.InvoiceRootAccountId = account.AccountId; } } using (var db = DbFactory.GetDataContext()) { var item = (from h in db.InvoiceHeaders join ai in db.AccountInvoices on h.InvoiceHeaderId equals ai.InvoiceHeaderId where h.InvoiceNumber.Equals(header.InvoiceNumber) && ai.Account.IsInvoiceRoot select new { ai.Account.Contact.Email }).FirstOrDefault(); if (item != null) { entity.Email = item.Email; } } return entity; }
public virtual void AddLine(InvoiceLine line) { line.Invoice = this; _lines.Add(line); }