Ejemplo n.º 1
0
        //--------------------------------------------------------
        public string CreateReceiptString(Invoice invoice, ref List<ShoppingCartItem> gscList)
        {
            int itemNo = 1;
            string receiptString = null;
            PricingRule pr = null;
            if (invoice != null)
            {
                receiptString = "\t\t\t" +invoice.CompanyName + "\t\t\n";
                receiptString += "\t\t\t9999 Any Stree NW\t\t\n";
                receiptString += "\t\t\tCalgary, AB T9T T9T\t\t\n";
                receiptString += "\t\t\tCanada\t\t\n";
                receiptString += "\t\t\tTel: 403-403-4040\t\t\n";
                receiptString += "\t\t\tDate: " + DateTime.Now +"\t\t\n";
                receiptString += "----------------------------------------------------------------------\n";
                if (gscList != null && gscList.Count() > 0)
                {
                    foreach (var item in gscList)
                    {
                        receiptString += itemNo + ".\t" + item.Product.Name + "\t" + item.Total + "\n";

                        pr = db.PricingRules.Find(item.PricingRuleId);
                        receiptString += "\t" + (itemNo++) + "\t" + pr.Name + "\t";
                        if (item.Discount > 0)
                            receiptString += item.Discount + "\n";
                    }
                    receiptString +=  "----------------------------------------------------------------------\n";
                    receiptString += "\tTotalDiscount: " + invoice.TotalDiscount + "\tTotal: " + invoice.Total + "\n";
                }
            }

            return receiptString;
        }
Ejemplo n.º 2
0
        public ShoppingCartVM()
        {
            Invoice = new Invoice() { };
            PricingRule = new PricingRule();
            ShoppingCartItem = new ShoppingCartItem();

            ProductList = new List<Product>() { };
            ShoppingCartPricingRuleList = new List<PricingRule>() { };
            CartItemList = new List<ShoppingCartItem>() { };
        }
Ejemplo n.º 3
0
 //--------------------------------------------------------
 public Invoice CalculateInvoice(Invoice invoice)
 {
     if (invoice != null)
     {
         decimal total = 0, discount = 0;
         foreach (var item in invoice.CartItemList)
         {
             total = (decimal)(total + item.Total);
             discount = (decimal)(discount + item.Discount);
         }
         invoice.Total = total;
         invoice.TotalDiscount = discount;
     }
     return invoice;
 }
Ejemplo n.º 4
0
        //--------------------------------------------------------
        public Invoice CreateInvoice(ref List<ShoppingCartItem> scList, ref List<ShoppingCartItem> gscList)
        {
            Invoice invoice = new Invoice() { };

            if (scList != null  && gscList != null)
            {
                ProcessShoppingCart.ProcessCart(ref scList, ref gscList);

                invoice.CartItemList = gscList;
            }

            invoice.CompanyName = "GroceryCo";
            invoice.InvoiceString = CreateReceiptString(invoice, ref gscList);
            //invoice = CalculateInvoice(invoice);

            db.Invoices.Add(invoice);
            db.SaveChanges();

            return invoice;
        }
Ejemplo n.º 5
0
        //--------------------------------------
        //
        // GET: /ShoppingCart/Receipt
        public ActionResult Receipt()
        {
            ProcessCheckout ProcessCheckout = new ProcessCheckout(){};
            scList = new List<ShoppingCartItem>() { };
            gscList = new List<ShoppingCartItem>() { };

            scList = db.ShoppingCartItems.ToList();
            foreach (var item in scList)
            {
                item.Product = db.Products.Find(item.ProductId);
            }
            Invoice invoice = new Invoice() { };
            invoice = ProcessCheckout.CreateInvoice(ref scList, ref gscList);
            invoice.InvoiceString = ProcessCheckout.CreateReceiptString(invoice, ref gscList);
            return View(invoice);
        }