CalculateTotal() public method

public CalculateTotal ( ) : decimal
return decimal
コード例 #1
0
        public void TestCalculateTotalBill()
        {
            var invoice = new Invoice(cartItems, DiscountType.FixedDiscount);

            invoice.CalculateTotal();
            invoice.Total.Should().Be(1000);
        }
コード例 #2
0
        // 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));
        }
コード例 #3
0
        public void CalculateTotal_EmptyCollection_0Returned()
        {
            var invoice = new Invoice(new List <SecurityObjectBase>());

            int totalCost = invoice.CalculateTotal();

            Assert.AreEqual(0, totalCost);
        }
コード例 #4
0
        public bool Validate(Invoice invoice)
        {
            if (invoice.CalculateTotal() < 0)
            {
                return(false);
            }

            return(true);
        }
コード例 #5
0
        public void TestCalculateDiscountedTotal()
        {
            var invoice = new Invoice(cartItems, DiscountType.FixedDiscount);

            invoice.CalculateTotal();
            invoice.CalculateDiscount();
            invoice.CalculateDiscountedTotal();

            invoice.TotalWithDiscount.Should().Be(910);
        }
コード例 #6
0
        public void CalculateTotal_CollectionWithSingleItem_ExpectedResultReturned()
        {
            var invoice = new Invoice(new List <SecurityObjectBase> {
                new FakeSecurityObject {
                    Cost = 1000
                }
            });

            int totalCost = invoice.CalculateTotal();

            Assert.AreEqual(1000, totalCost);
        }
コード例 #7
0
        // 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));
        }
コード例 #8
0
ファイル: InvoiceService.cs プロジェクト: andres1447/FriMav
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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}"));
            }
        }
コード例 #11
0
 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}"));
     }
 }
コード例 #12
0
 public override bool Validate(Invoice invoice)
 {
     return(invoice.CalculateTotal( ) >= 0);
 }
 public override bool Validate( Invoice invoice )
 {
     return invoice.CalculateTotal( ) >= 0;
 }