internal static Invoice createRandomInvoice() { Customer c = createRandomCustomer(); c.Save(0); Invoice i = new Invoice(Invoice.Type.Invoice); i.CustomerId = c.Id; return i; }
public static Invoice Load(int invoiceId) { Invoice bo = null; DAL.CustomersDataContext dc = new DAL.CustomersDataContext(); DAL.InvoiceHeader ih = findRecord(dc, invoiceId); if (ih != null) { bo = new Invoice((Type)Enum.Parse(typeof(Type), ih.InvoiceType)); map(ih, InvoiceDetail.LoadWithInvoiceId(dc, invoiceId), bo); } return bo; }
public void TestSetup() { dbConnStr = buildConnectionString(CustomerManagementTest.Properties.Settings.Default.TestDb, () => DateTimeOffset.UtcNow.ToString("yyyy-MM-dd_hh:mm:ssZ")); using (var db = new CustomerContext(dbConnStr)) { var customer = new Customer { CustomerType = "type", UserId = 1, FirstName = "First", LastName = "Last", Email = "*****@*****.**" }; db.Save(customer); db.SaveChanges(); var invoice = new Invoice { Customer = customer, InvoiceType = Invoice.Type.Invoice, Note="Note", PaymentNote="Payment Note" } ; db.Save(invoice); db.SaveChanges(); invId = invoice.Id; } }
// need to include itempricings/itemunits public Invoice CreateInvoice(long customerId, Invoice.Type type, List<UiItem> uiitems, string note, string paymentnote ) { using (var db = Db()) { var customer = db.Customers.FirstOrDefault(c => c.Id == customerId); if (customer == null) throw new ArgumentNullException("Customer does not exist"); if (uiitems.Count==0) throw new ArgumentNullException("There are no items"); if (type==Invoice.Type.Void) throw new ArgumentNullException("Cannot create void invoice"); db.Attach(customer); var invoice = new Invoice { Customer=customer, InvoiceType=type, Note=note.Trim(), PaymentNote=paymentnote.Trim() }; //Create Invoice Details invoice.InvoiceDetails = MapInvoiceDetails(uiitems); db.Save(invoice); db.SaveChanges(); return invoice; } }
public Invoice UpdateInvoice(long invoiceId, Invoice inv) { using (var db = Db()) { var invoice = db.Invoices.FirstOrDefault(i => i.Id == invoiceId); if (invoice == null) throw new ArgumentNullException("Invoice does not exist"); db.Attach(invoice); invoice.Note = inv.Note.Trim(); invoice.PaymentNote = inv.PaymentNote.TrimEnd(); invoice.InvoiceType = inv.InvoiceType; db.SaveChanges(); return inv; } }
public void TestUpdateInvoice() { List<UiItem> uiitems = new List<UiItem> { new UiItem {Item=items[0], Pricing=items[0].ItemPricings[0], ItemUnits=3}, new UiItem {Item=items[1], Pricing=items[1].ItemPricings[0], ItemUnits=4}, new UiItem {Item=items[2], Pricing=items[2].ItemPricings[0], ItemUnits=5}, }; var invoice = cs.CreateInvoice(customer.Id, Invoice.Type.Invoice, uiitems, "Note", "Payment Note"); var inv = new Invoice { InvoiceType = Invoice.Type.Credit, Note = "Update Note", PaymentNote = "Payment Note Update" }; cs.UpdateInvoice(invoice.Id, inv); var updateinvoice = cs.GetInvoice(invoice.Id); Assert.IsTrue(updateinvoice.InvoiceType == Invoice.Type.Credit && updateinvoice.Note == "Update Note" && updateinvoice.PaymentNote == "Payment Note Update", "Incorrect Invoice changes"); }
private static void map(DAL.InvoiceHeader ih, IEnumerable<InvoiceDetail> InvoiceDetails, Invoice i) { i.Id = ih.Id; i.CustomerId = ih.CustomerId; i.InvoiceType = (Type)Enum.Parse(typeof(Type), ih.InvoiceType); i.InvoiceDetails = new List<InvoiceDetail>(InvoiceDetails); }
private static void map(Invoice invoice, DAL.InvoiceHeader dalInvoiceHeader) { bool isNew = invoice.Id == 0; bool isModified = false; if (dalInvoiceHeader.CustomerId != invoice.CustomerId) { dalInvoiceHeader.CustomerId = invoice.CustomerId; isModified = true; } if (dalInvoiceHeader.InvoiceType != Enum.GetName(typeof(Type), invoice.InvoiceType)) { dalInvoiceHeader.InvoiceType = Enum.GetName(typeof(Type), invoice.InvoiceType); isModified = true; } if (isNew) { dalInvoiceHeader.CreatedBy = invoice.LastChangedBy; dalInvoiceHeader.CreatedDate = DateTime.Now; } if (isModified) { dalInvoiceHeader.LastChangedBy = invoice.LastChangedBy; dalInvoiceHeader.LastChangedDate = DateTime.Now; } }
public Invoice(Invoice.Type it) { this.InvoiceType = it; this.InvoiceDetails = new List<InvoiceDetail>(); this.LastChangedBy = 0; // TODO: get this from paymentStatusCodeId parameter }