示例#1
0
        // GET: Customer
        public ActionResult Customer(string searchby, string search)
        {
            InvoiceCustomerViewModel viewModel = new InvoiceCustomerViewModel()
            {
                Customers = customerLogic.GetAllCustomers()
            };

            if (searchby == "lastname")
            {
                InvoiceCustomerViewModel searchModel = new InvoiceCustomerViewModel()
                {
                    Customers = customerLogic.GetCustomersByLastName(search)
                };

                return(View(searchModel));
            }
            else if (searchby == "zipcode") //de zipcode search functie nog maken in de database
            {
                InvoiceCustomerViewModel searchModel = new InvoiceCustomerViewModel()
                {
                    Customers = customerLogic.GetCustomersByZipcode(search)
                };

                return(View(searchModel));
            }

            return(View(viewModel));
        }
        public ActionResult Invoice()
        {
            InvoiceCustomerViewModel view = new InvoiceCustomerViewModel()
            {
                InvoicesPerCustomer = invoiceLogic.GetAllInvoices()
            };

            return(View(view));
        }
示例#3
0
        // GET: SalesController/Details/5
        public ActionResult Details(string id)
        {
            var model = new InvoiceCustomerViewModel
            {
                invoice  = salesRepo.Find(id),
                Details  = detailrepo.List().Where(i => i.InvoiceId == id).ToList(),
                Products = productRepo.List().ToList()
            };

            return(View(model));
        }
示例#4
0
        // GET: SalesController
        public ActionResult Index()
        {
            var invoices = new InvoiceCustomerViewModel
            {
                Products  = productRepo.List().ToList(),
                Customers = CustomerRepo.List().ToList(),
                Invoices  = salesRepo.List().ToList(),
                Details   = detailrepo.List().ToList()
            };

            return(View(invoices));
        }
示例#5
0
 public ActionResult UpdateCustomer(InvoiceCustomerViewModel customerViewModel)
 {
     if (customerViewModel.Id != 0)
     {
         var customer = customerLogic.GetById(customerViewModel.Id);
         customerViewModel.Customer = customer;
         return(View(customerViewModel));
     }
     else
     {
         return(RedirectToAction("Customer"));
     }
 }
示例#6
0
        public ActionResult Create()
        {
            var id = int.Parse(salesRepo.MaxId());

            ViewBag.InvoiceId = (id + 1).ToString();
            var model = new InvoiceCustomerViewModel
            {
                Products  = productRepo.List().ToList(),
                Customers = CustomerRepo.List().ToList()
            };

            return(View(model));
        }
示例#7
0
 public ActionResult CreateNewCustomer(InvoiceCustomerViewModel customerViewModel)
 {
     return(PartialView("CreateNewCustomer"));
 }
示例#8
0
        public IActionResult Create([Bind("InvoiceNo,downdetails,ProductID,InvoiceDate,InvoiceType,CustID,InvoiceTotal,InvoiceDiscount,InvoiceNetTotal,InvoicePaid,InvoiceChange")]
                                    InvoiceCustomerViewModel Modeldetails)
        {
            try
            {
                string       totaljson = Modeldetails.downdetails.ToString();
                SalesInvoice hh        = (SalesInvoice)totals(totaljson);
                if (Modeldetails.InvoiceType == 1)//update customer balance
                {
                    var customer    = CustomerRepo.Find(Modeldetails.CustID);
                    var newcustomer = new Customer
                    {
                        CustID          = customer.CustID,
                        CustArName      = customer.CustArName,
                        CustEnName      = customer.CustEnName,
                        AccountNo       = customer.AccountNo,
                        CustAdress      = customer.CustAdress,
                        CustMobileNo    = customer.CustMobileNo,
                        CustBalance     = (double)(returnzero(customer.CustBalance.ToString()) + returnzero(hh.InvoiceChange.ToString())),
                        CustOpenBalance = customer.CustOpenBalance
                    };
                    CustomerRepo.Update(Modeldetails.CustID, newcustomer);
                }
                var smodel = new SalesInvoice//insert invoice details
                {
                    InvoiceNo       = Modeldetails.InvoiceNo,
                    InvoiceDate     = Modeldetails.InvoiceDate,
                    InvoiceType     = Modeldetails.InvoiceType,
                    InvoiceTotal    = (double)returnzero(hh.InvoiceTotal.ToString()),
                    InvoiceDiscount = (double)returnzero(hh.InvoiceDiscount.ToString()),
                    InvoiceNetTotal = (double)returnzero(hh.InvoiceNetTotal.ToString()),
                    InvoicePaid     = (double)returnzero(hh.InvoicePaid.ToString()),
                    CustID          = Modeldetails.CustID,
                    InvoiceChange   = (double)returnzero(hh.InvoiceChange.ToString())
                };
                salesRepo.Add(smodel);

                string h = Modeldetails.ProductID.ToString();
                List <SalesDetails> items = JsonConvert.DeserializeObject <List <SalesDetails> >(h.ToString());
                foreach (var item in items)
                {
                    var model = new SalesDetails//insert invoice product details
                    {
                        InvoiceId    = Modeldetails.InvoiceNo,
                        ProductID    = item.ProductID,
                        Quantity     = item.Quantity,
                        SalesPrice   = item.SalesPrice,
                        Total        = item.Total,
                        discount     = returnzero(item.discount.ToString()),
                        VatAmount    = item.VatAmount,
                        TotalWithVat = item.TotalWithVat,
                        Cost         = productRepo.Find(item.ProductID).Cost,//get cost of product
                    };
                    var pro           = productRepo.Find(item.ProductID);
                    var productupdate = new Product//update products balnce
                    {
                        ProductId   = pro.ProductId,
                        Balance     = (double)(pro.Balance - item.Quantity),
                        ArabicName  = pro.ArabicName,
                        EnglishName = pro.EnglishName,
                        Model       = pro.Model,
                        Desc        = pro.Desc,
                        Cost        = pro.Cost,
                        SalePrice   = pro.SalePrice,
                        OpenBalance = pro.OpenBalance,
                        OpenCost    = pro.OpenCost
                    };
                    productRepo.Update(item.ProductID, productupdate);
                    detailrepo.Add(model);
                }
                return(RedirectToAction(nameof(Create)));
            }
            catch (Exception e)
            {
                throw;
            }
        }
示例#9
0
        public ActionResult Edit(InvoiceCustomerViewModel collection)
        {
            try
            {
                string       totaljson = collection.downdetails.ToString();
                SalesInvoice hh        = (SalesInvoice)totals(totaljson);
                var          smodel    = new SalesInvoice
                {
                    InvoiceNo       = collection.invoice.InvoiceNo,
                    InvoiceDate     = collection.invoice.InvoiceDate,
                    InvoiceType     = collection.invoice.InvoiceType,
                    InvoiceTotal    = (double)returnzero(hh.InvoiceTotal.ToString()),
                    InvoiceDiscount = (double)returnzero(hh.InvoiceDiscount.ToString()),
                    InvoiceNetTotal = (double)returnzero(hh.InvoiceNetTotal.ToString()),
                    InvoicePaid     = (double)returnzero(hh.InvoicePaid.ToString()),
                    CustID          = collection.invoice.CustID,
                    InvoiceChange   = (double)returnzero(hh.InvoiceChange.ToString())
                };
                salesRepo.Update(smodel.InvoiceNo, smodel);
                if (collection.invoice.InvoiceType == 1)
                {
                    var customer    = CustomerRepo.Find(collection.invoice.CustID);
                    var newcustomer = new Customer
                    {
                        CustID          = customer.CustID,
                        CustArName      = customer.CustArName,
                        CustEnName      = customer.CustEnName,
                        AccountNo       = customer.AccountNo,
                        CustAdress      = customer.CustAdress,
                        CustMobileNo    = customer.CustMobileNo,
                        CustBalance     = (double)(customer.CustBalance + hh.InvoiceChange),
                        CustOpenBalance = customer.CustOpenBalance
                    };
                    CustomerRepo.Update(collection.invoice.CustID, newcustomer);
                }
                string h = collection.ProductID.ToString();
                List <SalesDetails> items = JsonConvert.DeserializeObject <List <SalesDetails> >(h.ToString());
                foreach (var item in items)
                {
                    var model = new SalesDetails
                    {
                        InvoiceId    = collection.invoice.InvoiceNo,
                        ProductID    = item.ProductID,
                        Quantity     = item.Quantity,
                        SalesPrice   = item.SalesPrice,
                        Total        = item.Total,
                        discount     = returnzero(item.discount.ToString()),
                        VatAmount    = item.VatAmount,
                        TotalWithVat = item.TotalWithVat,
                        Cost         = productRepo.Find(item.ProductID).Cost,//get cost of product
                    };
                    var pro           = productRepo.Find(item.ProductID);
                    var exsist        = detailrepo.Find(model);
                    var newquantity   = item.Quantity - exsist.Quantity;
                    var productupdate = new Product
                    {
                        ProductId   = pro.ProductId,
                        Balance     = (double)(pro.Balance - newquantity),
                        ArabicName  = pro.ArabicName,
                        EnglishName = pro.EnglishName,
                        Model       = pro.Model,
                        Desc        = pro.Desc,
                        Cost        = pro.Cost,
                        SalePrice   = pro.SalePrice,
                        OpenBalance = pro.OpenBalance,
                        OpenCost    = pro.OpenCost
                    };

                    detailrepo.Update(collection.invoice.InvoiceNo, model);
                    productRepo.Update(item.ProductID, productupdate);
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                throw;
            }
        }