Esempio n. 1
0
        //public ActionResult AddItem(int? id)
        //{
        //    TempProduct temp = db.TempProducts.Find(id);
        //    if (temp.Quantity >= 1)
        //    {
        //        temp.QtyPurchased = temp.QtyPurchased + 1;
        //        temp.Quantity = temp.Quantity - 1;
        //        db.Entry(temp).State = EntityState.Modified;
        //        db.SaveChanges();
        //    }
        //    else
        //    {
        //        ViewBag.Message = "Insufficient Quntity";
        //    }

        //    AllClassViewModel viewModel = new AllClassViewModel
        //    {
        //        TempProducts = db.TempProducts.ToList()
        //    };

        //    return View("ExchangeView", viewModel);
        //}

        public ActionResult RemItem(int?id)
        {
            SellingHistory sellingHistory = db.SellingHistories.Find(id);
            Billing        bill           = db.Billings.Find(sellingHistory.BillingId);
            Product        product        = db.Products.Find(sellingHistory.ProductId);

            if (sellingHistory.Quantity <= 1)
            {
                sellingHistory.Quantity = 1;
                AllClassViewModel viewModel1 = new AllClassViewModel
                {
                    Billing          = bill,
                    Products         = db.Products.ToList(),
                    SellingHistories = db.SellingHistories.Where(m => m.BillingId == bill.Id)
                };
                return(View("ExchangeView", viewModel1));
            }
            product.Quantity               = product.Quantity + 1;
            sellingHistory.Quantity        = sellingHistory.Quantity - 1;
            db.Entry(sellingHistory).State = EntityState.Modified;
            db.Entry(product).State        = EntityState.Modified;
            db.SaveChanges();
            AllClassViewModel viewModel = new AllClassViewModel
            {
                Billing          = bill,
                Products         = db.Products.ToList(),
                SellingHistories = db.SellingHistories.Where(m => m.BillingId == bill.Id)
            };

            return(View("ExchangeView", viewModel));
        }
Esempio n. 2
0
        public ActionResult StarCustomer()
        {
            AllClassViewModel allClassViewModel = new AllClassViewModel
            {
                Billings  = db.Billings.ToList(),
                Customers = db.Customers.ToList()
            };

            return(View(allClassViewModel));
        }
Esempio n. 3
0
        public ActionResult ViewProducts(int?id)
        {
            Billing           billing   = db.Billings.Find(id);
            AllClassViewModel viewModel = new AllClassViewModel()
            {
                SellingHistories = db.SellingHistories.Where(m => m.BillingId == id),
                Products         = db.Products.ToList()
            };

            return(View(viewModel));
        }
        public ActionResult TotalAmountDueOfClient()
        {
            var customers = db.Customers.ToList();
            var billings  = db.Billings.ToList();

            AllClassViewModel viewModel = new AllClassViewModel
            {
                Customers = customers,
                Billings  = billings
            };

            return(View(viewModel));
        }
        public ActionResult RemoveTemp(int?id)
        {
            TempProduct temp = db.TempProducts.Find(id);

            db.TempProducts.Remove(temp);
            db.SaveChanges();
            AllClassViewModel viewModel = new AllClassViewModel
            {
                TempProducts = db.TempProducts.ToList()
            };

            ModelState.Clear();
            return(View("GenerateBill", viewModel));
        }
Esempio n. 6
0
        public ActionResult ExchangeView(FormCollection form)
        {
            try
            {
                Billing bill       = null;
                string  billID     = Request.Form["BillId"];
                int     id         = Convert.ToInt32(billID);
                bool    isBillExit = false;
                foreach (var item in db.Billings.ToList())
                {
                    if (item.Id == id)
                    {
                        isBillExit = true;
                        break;
                    }
                }

                if (isBillExit == true)
                {
                    bill = db.Billings.Find(id);
                }
                else
                {
                    return(RedirectToAction("ExcahngeProduct", new { error = "Invalid Bill Number" }));
                }



                AllClassViewModel viewModel = new AllClassViewModel
                {
                    Billing          = bill,
                    Products         = db.Products.ToList(),
                    SellingHistories = db.SellingHistories.Where(m => m.BillingId == bill.Id)
                };

                return(View(viewModel));
            }
            catch (Exception e)
            {
                return(RedirectToAction("ExcahngeProduct", new { error = "Invalid Bill Number" }));
            }
        }
        public ActionResult ViewDueBills(int?id)
        {
            Customer        customer = db.Customers.Find(id);
            IList <Billing> bills    = new List <Billing>();

            foreach (var item in db.Billings.ToList())
            {
                if (item.CustomerId == customer.Id && item.AmountDue > 0)
                {
                    bills.Add(item);
                }
            }
            AllClassViewModel viewModel = new AllClassViewModel
            {
                Customer = customer,
                Billings = bills
            };

            return(View(viewModel));
        }
        public ActionResult RemItem(int?id)
        {
            TempProduct temp = db.TempProducts.Find(id);

            temp.QtyPurchased = temp.QtyPurchased - 1;
            temp.Quantity     = temp.Quantity + 1;
            if (temp.QtyPurchased <= 1)
            {
                temp.QtyPurchased = 1;
            }
            db.Entry(temp).State = EntityState.Modified;
            db.SaveChanges();
            AllClassViewModel viewModel = new AllClassViewModel
            {
                TempProducts = db.TempProducts.ToList()
            };

            ModelState.Clear();
            return(View("GenerateBill", viewModel));
        }
        public ActionResult AddItem(int?id)
        {
            TempProduct temp = db.TempProducts.Find(id);

            if (temp.Quantity >= 1)
            {
                temp.QtyPurchased    = temp.QtyPurchased + 1;
                temp.Quantity        = temp.Quantity - 1;
                db.Entry(temp).State = EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                ViewBag.Message = "Insufficient Quntity";
            }

            AllClassViewModel viewModel = new AllClassViewModel
            {
                TempProducts = db.TempProducts.ToList()
            };

            ModelState.Clear();
            return(View("GenerateBill", viewModel));
        }
        public ActionResult FinalBillPrint(Billing bill)
        {
            string barcode = bill.Id.ToString();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (Bitmap bitMap = new Bitmap(barcode.Length * 40, 100))
                {
                    using (Graphics graphics = Graphics.FromImage(bitMap))
                    {
                        Font   oFont = new Font("IDAutomationHC39M", 16);
                        Font   bFont = new Font(FontFamily.GenericSerif, 8);
                        PointF point = new PointF(2f, 2f);
                        //PointF point3 = new PointF(45f, 0.5f);
                        PointF     point2     = new PointF(56f, 76f);
                        SolidBrush whiteBrush = new SolidBrush(Color.White);
                        graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height);
                        SolidBrush blackBrush = new SolidBrush(Color.Black);
                        graphics.DrawString("*" + barcode + "*", oFont, blackBrush, point);
                    }

                    bitMap.Save(memoryStream, ImageFormat.Jpeg);

                    ViewBag.BarcodeImage = "data:image/png;base64," + Convert.ToBase64String(memoryStream.ToArray());
                }
            }



            //Billing bill = db.Billings.Find(id);
            Customer customer = new Customer()
            {
            };

            foreach (var item in db.Customers.ToList())
            {
                if (item.Id == bill.CustomerId)
                {
                    customer = item;
                    break;
                }
            }
            List <SellingHistory> sellingHistories = new List <SellingHistory>();

            foreach (var item in db.SellingHistories.ToList())
            {
                if (item.BillingId == bill.Id)
                {
                    sellingHistories.Add(item);
                }
            }
            List <Product> products = new List <Product>();
            int            sum      = 0;

            foreach (var item in db.Products.ToList())
            {
                foreach (var item1 in sellingHistories)
                {
                    if (item.Id == item1.ProductId)
                    {
                        products.Add(item);
                        sum = sum + (item1.Quantity) * (item.Price);
                    }
                }
            }
            ViewBag.TotalPrice = sum;
            ViewBag.AmountDue  = sum - bill.AmountPaid;

            AllClassViewModel viewModel = new AllClassViewModel()
            {
                Customer         = customer,
                Billing          = bill,
                Products         = products,
                SellingHistories = sellingHistories
            };

            return(View(viewModel));
        }
        public ActionResult PrintBill(AllClassViewModel allClass)
        {
            bool flag = false;
            int  id   = 0;

            foreach (var item in db.Customers.ToList())
            {
                if (allClass.Customer.PhoneNo.Equals(item.PhoneNo))
                {
                    flag = true;
                    id   = item.Id;
                    break;
                }
            }

            if (!flag)
            {
                Customer customer = new Customer()
                {
                    Address = allClass.Customer.Address,
                    Name    = allClass.Customer.Name,
                    PhoneNo = allClass.Customer.PhoneNo
                };
                db.Customers.Add(customer);
                db.SaveChanges();
                foreach (var item in db.Customers.ToList())
                {
                    if (item.PhoneNo == allClass.Customer.PhoneNo)
                    {
                        id = item.Id;
                        break;
                    }
                }
            }

            int totalAmount = 0;

            foreach (var item in db.TempProducts.ToList())
            {
                totalAmount = totalAmount + (item.Price) * (item.QtyPurchased);
            }

            Billing bill = new Billing()
            {
                CustomerId = id,
                AmountPaid = allClass.Billing.AmountPaid,
                Date       = allClass.Billing.Date,
                DueDate    = allClass.Billing.DueDate,
                AmountDue  = totalAmount - allClass.Billing.AmountPaid
                             //enter amount due here
            };

            db.Billings.Add(bill);
            db.SaveChanges();
            var     lastbills = db.Billings.ToList();
            Billing lastbill  = lastbills.Last();
            int     lastId    = lastbill.Id;

            SellingHistory history = new SellingHistory()
            {
            };

            foreach (var item in db.TempProducts.ToList())
            {
                foreach (var item1 in db.Products.ToList())
                {
                    if (item1.BarCodeId == item.BarCodeId)
                    {
                        history.BillingId = lastId;
                        history.ProductId = item1.Id;
                        history.Quantity  = item.QtyPurchased;
                        db.SellingHistories.Add(history);
                        item1.Quantity        = item1.Quantity - item.QtyPurchased;
                        db.Entry(item1).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }

            foreach (var item in db.TempProducts.ToList())
            {
                db.TempProducts.Remove(item);
                db.SaveChanges();
            }

            return(RedirectToAction("FinalBillPrint", lastbill));
        }
        public ActionResult GenerateBill(TempProduct tempProduct)
        {
            string barcode = tempProduct.BarCodeId.ToString();
            IEnumerable <Product> products = db.Products.ToList();
            bool flag = false;

            foreach (var item in products)
            {
                if (item.BarCodeId.Equals(barcode))
                {
                    flag = true;
                    tempProduct.BarCodeId    = item.BarCodeId;
                    tempProduct.Brand        = item.Brand;
                    tempProduct.Category     = item.Category;
                    tempProduct.Colour       = item.Colour;
                    tempProduct.Price        = item.Price;
                    tempProduct.Quantity     = item.Quantity;
                    tempProduct.Size         = item.Size;
                    tempProduct.QtyPurchased = 0;
                }
            }
            if (flag)
            {
                bool fl = false;
                foreach (var item in db.TempProducts.ToList())
                {
                    if (tempProduct.BarCodeId == item.BarCodeId)
                    {
                        item.QtyPurchased    = item.QtyPurchased + 1;
                        item.Quantity        = item.Quantity - 1;
                        db.Entry(item).State = EntityState.Modified;
                        fl = true;
                        if (item.Quantity >= 1)
                        {
                            db.SaveChanges();
                        }
                        else
                        {
                            ViewBag.Message = "Insufficient Quantity";
                        }
                        break;
                    }
                }
                if (!fl)
                {
                    if (tempProduct.Quantity >= 1)
                    {
                        tempProduct.Quantity     = tempProduct.Quantity - 1;
                        tempProduct.QtyPurchased = tempProduct.QtyPurchased + 1;
                        db.TempProducts.Add(tempProduct);
                        db.SaveChanges();
                    }
                    else
                    {
                        ViewBag.Message = "Insufficient Quantity";
                    }
                }
            }
            else
            {
                ViewBag.Message = "Incorrect Product";
            }
            AllClassViewModel viewModel = new AllClassViewModel
            {
                TempProducts = db.TempProducts.ToList()
            };

            ModelState.Clear();
            return(View(viewModel));
        }