public void TestCalculateTotalBill() { var invoice = new Invoice(cartItems, DiscountType.FixedDiscount); invoice.CalculateTotal(); invoice.Total.Should().Be(1000); }
// GET: Invoices/Edit/5 public ActionResult Edit(int?id, string userID, int?customerID) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Invoice invoice = db.Invoices.Find(id); invoice.CalculateTotal(); if (userID != null) { invoice.employee_id = userID; invoice.AspNetUser = db.AspNetUsers.Find(userID); } else { invoice.AspNetUser = db.AspNetUsers.Find(invoice.employee_id); } if (customerID != null) { invoice.customer_id = Convert.ToInt32(customerID); invoice.Customer = db.Customers.Find(customerID); } else { invoice.Customer = db.Customers.Find(invoice.customer_id); } invoice.Customer = db.Customers.Find(invoice.customer_id); if (invoice == null) { return(HttpNotFound()); } ViewBag.ActionTitle = "Edit "; return(View(invoice)); }
public void CalculateTotal_EmptyCollection_0Returned() { var invoice = new Invoice(new List <SecurityObjectBase>()); int totalCost = invoice.CalculateTotal(); Assert.AreEqual(0, totalCost); }
public bool Validate(Invoice invoice) { if (invoice.CalculateTotal() < 0) { return(false); } return(true); }
public void TestCalculateDiscountedTotal() { var invoice = new Invoice(cartItems, DiscountType.FixedDiscount); invoice.CalculateTotal(); invoice.CalculateDiscount(); invoice.CalculateDiscountedTotal(); invoice.TotalWithDiscount.Should().Be(910); }
public void CalculateTotal_CollectionWithSingleItem_ExpectedResultReturned() { var invoice = new Invoice(new List <SecurityObjectBase> { new FakeSecurityObject { Cost = 1000 } }); int totalCost = invoice.CalculateTotal(); Assert.AreEqual(1000, totalCost); }
// GET: Invoices/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Invoice invoice = db.Invoices.Find(id); invoice.CalculateTotal(); if (invoice == null) { return(HttpNotFound()); } ViewBag.ActionTitle = "Detailed "; return(View(invoice)); }
private Invoice MapInvoice(InvoiceCreate request, Customer customer) { var invoice = new Invoice { Person = customer, PersonId = customer.Id, CustomerName = request.CustomerName, Shipping = request.Shipping ?? customer.Shipping ?? Shipping.Self, PaymentMethod = request.PaymentMethod ?? customer.PaymentMethod ?? PaymentMethod.Cash, Number = _documentNumberGenerator.NextForInvoice(), DeliveryAddress = request.DeliveryAddress, Items = MapInvoiceItems(request) }; invoice.Total = invoice.CalculateTotal(); return(invoice); }
public void CalculateTotal_CollectionWithMultipleEntries_ExpectedResultsReturned() { var invoice = new Invoice(new List <SecurityObjectBase> { new FakeSecurityObject { Cost = 1000 }, new FakeSecurityObject { Cost = 1500 }, new FakeSecurityObject { Cost = 2000 } }); int totalCost = invoice.CalculateTotal(); Assert.AreEqual(4500, totalCost); }
public Response <Invoice> Save(Invoice invoice) { try { Invoice newInvoice = new Invoice(invoice.IdInvoice, invoice.IdClient); foreach (InvoiceDetail detail in invoice.InvoiceDetails) { newInvoice.AddInvoiceDetails(detail.Product, detail.QuantityProduct, detail.Discount, detail.UnitValue); } newInvoice.CalculateTotal(); foreach (InvoiceDetail detail1 in newInvoice.InvoiceDetails) { detail1.Product = null; } _context.Invoices.Add(newInvoice); _context.SaveChanges(); return(new Response <Invoice>(newInvoice)); } catch (Exception e) { return(new Response <Invoice>($"Error del aplicacion: {e.Message}")); } }
public Response <Invoice> Save(Invoice invoice) { try { Invoice newInvoice = new Invoice(invoice.Client); foreach (InvoiceDetail detail in invoice.InvoiceDetails) { if (detail.Product.QuantityStock - detail.QuantityProduct < 0) { return(new Response <Invoice>("No hay suficiente stock")); } newInvoice.AddInvoiceDetails(detail.Product, detail.QuantityProduct, detail.Discount, detail.UnitValue); detail.Product.discountQuantityStock(detail.QuantityProduct); _context.Products.Update(detail.Product); } newInvoice.CalculateTotal(); _context.Invoices.Add(newInvoice); _context.SaveChanges(); return(new Response <Invoice>(newInvoice)); } catch (Exception e) { return(new Response <Invoice>($"Error del aplicacion: {e.Message}")); } }
public override bool Validate(Invoice invoice) { return(invoice.CalculateTotal( ) >= 0); }
public override bool Validate( Invoice invoice ) { return invoice.CalculateTotal( ) >= 0; }