Пример #1
0
        public async Task <IActionResult> Receive(int?id)
        {
            ApplicationUser applicationUser = await _userManager.GetUserAsync(User);

            string userEmail = applicationUser?.Email;

            if (id == null)
            {
                return(NotFound());
            }
            PoWithItems entireOrder = GetOrderWithItems((int)id);

            if (entireOrder == null)
            {
                return(NotFound());
            }
            foreach (var line in entireOrder.ItemList.ToList())
            {
                var purchase = iPurchaseOrderItem.GetPurchaseOrdersItem().FirstOrDefault(x => x.PoItemId == line.PoItemId);
                inventory.GetById(purchase.ProductId).RestQuantity -= purchase.Quantity;
                inventory.GetById(purchase.ProductId).SaleQuantity += purchase.Quantity;
                purchase.Received    = 1;
                purchase.UpdatedBy   = userEmail;
                purchase.UpdatedDate = DateTime.Now;

                await iPurchaseOrderItem.UpdateAsync(purchase);
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = entireOrder.PurchaseOrder.PurchaseOrderId }));
        }
Пример #2
0
        public IActionResult List()
        {
            List <SoWithItems> soListComplete = new List <SoWithItems>();
            List <Sale>        soList         = iSaleService.GetSales().ToList();

            foreach (var item in soList)
            {
                int         currId   = item.SaleId;
                SoWithItems currItem = GetOrderWithItems(currId);
                soListComplete.Add(currItem);
            }

            foreach (var variable in soListComplete)
            {
                if (iSaleItem != null)
                {
                    var ansList = iSaleItem.GetAll().FirstOrDefault(x => x.SaleId == variable.S.SaleId)?.Returned;
                    if (ansList == null)
                    {
                        iSaleService.Delete(variable.S);
                    }
                }
                variable.S.items = GetTotalSaleItems(variable.S.SaleId);
                variable.S.price = GetTotalSalePrice(variable.S.SaleId);
            }
            List <PoWithItems>   poListComplete = new List <PoWithItems>();
            List <PurchaseOrder> poList         = iPurchaseOrderService.GetAll().ToList();

            foreach (var item in poList)
            {
                int         currId   = item.PurchaseOrderId;
                PoWithItems currItem = GetPOrderWithItems(currId);
                poListComplete.Add(currItem);
            }

            var tongtien = 0.0;

            foreach (var variable in poListComplete)
            {
                tongtien += variable.PurchaseOrder.TotalPrice;
            }
            List <ThongKeTheoThang> result = soListComplete
                                             .GroupBy(l => l.S.SaleDate.Month)
                                             .Select(cl => new ThongKeTheoThang
            {
                Thang    = cl.Select(x => x.S.SaleDate.Month).FirstOrDefault(),
                Soluong  = cl.Count(),
                TongTien = cl.Sum(c => c.S.price),
            }).ToList();

            return(PartialView("List", result));
        }
Пример #3
0
        // Returns a string status OPEN or CLOSED
        // depending on the state of a PO(id)
        public string GetStatus(int id)
        {
            PoWithItems x = GetOrderWithItems(id);

            if (!(x.ItemList.Any()))
            {
                return("OPEN");
            }
            if (x.ItemList.First().Received == 0)
            {
                return("OPEN");
            }
            return("CLOSED");
        }
Пример #4
0
        public IActionResult Cancel(int?id)
        {
            if (id != null)
            {
                PoWithItems entireOrder = GetOrderWithItems((int)id);
                foreach (var item in entireOrder.ItemList)
                {
                    iPurchaseOrderItem.Delete(item);
                }
                iPurchaseOrderService.Delete(entireOrder.PurchaseOrder);
            }

            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #5
0
        public void PoTotalSet(PoWithItems x)
        {
            var    allItems   = x.ItemList;
            double ans        = 0;
            int    soluongban = 0;

            foreach (var line in allItems)
            {
                double lineTotal = line.Quantity * (double)line.Inventory.NetPrice;
                ans        += lineTotal;
                soluongban += line.Quantity;
            }

            x.PurchaseOrder.TotalPrice = ans;
            x.PurchaseOrder.SLBan      = soluongban;
            return;
        }
Пример #6
0
        // Get a poWithItems object based on a given purchase order ID and db instance
        public PoWithItems GetOrderWithItems(int givenId)
        {
            var ansPo = iPurchaseOrderService.GetPurchaseOrders().FirstOrDefault(x => x.PurchaseOrderId == givenId);
            IEnumerable <PurchaseOrderItem> ansList = iPurchaseOrderItem.GetAll().Where(x => x.PurchaseOrderId == givenId);
            var e = ansList.ToList();

            foreach (var each in e)
            {
                double currLineCost = each.Quantity * (double)each.Inventory.NetPrice;
                each.TotalPrice = currLineCost;
            }

            _context.SaveChanges();
            var ans = new PoWithItems(ansPo, e);

            PoTotalSet(ans);
            _context.SaveChanges();
            return(ans);
        }
Пример #7
0
        // Method to control search functionality
        public ActionResult Search(string option, string search)
        {
            var session = HttpContext.Session;

            session.SetString("searchdebug", search);
            List <PoWithItems>   poListComplete = new List <PoWithItems>();
            List <PurchaseOrder> poList         = iPurchaseOrderService.GetAll().ToList();

            foreach (var item in poList)
            {
                int         currId   = item.PurchaseOrderId;
                PoWithItems currItem = GetOrderWithItems(currId);
                poListComplete.Add(currItem);
            }
            if (option == "ID")
            {
                try
                {
                    return(View(poListComplete.Where(x => x.PurchaseOrder.PurchaseOrderId == Int32.Parse(search)).ToList()));
                }
                catch
                {
                    return(View(new List <PoWithItems>()));
                }
            }
            else if (option == "Date")
            {
                return(View(poListComplete.Where(x => x.PurchaseOrder.DateStr.Equals(search) || search == null).ToList()));
            }
            else if (option == "Status")
            {
                return(View(poListComplete.Where(x => GetStatus(x.PurchaseOrder.PurchaseOrderId).Equals(search) || search == null).ToList()));
            }
            else
            {
                return(View(new List <PoWithItems>()));
            }
        }
Пример #8
0
        // Returns total price of a purchase order
        // given a purchase order ID
        public double GetTotalPrice(int id)
        {
            PoWithItems x = GetOrderWithItems(id);

            return(x.PurchaseOrder.TotalPrice);
        }
Пример #9
0
        public IActionResult Index()
        {
            List <SoWithItems> soListComplete = new List <SoWithItems>();
            List <Sale>        soList         = iSaleService.GetSales().ToList();

            foreach (var item in soList)
            {
                int         currId   = item.SaleId;
                SoWithItems currItem = GetOrderWithItems(currId);
                soListComplete.Add(currItem);
            }

            foreach (var variable in soListComplete)
            {
                if (iSaleItem != null)
                {
                    var ansList = iSaleItem.GetAll().FirstOrDefault(x => x.SaleId == variable.S.SaleId)?.Returned;
                    if (ansList == null)
                    {
                        iSaleService.Delete(variable.S);
                    }
                }
                variable.S.items = GetTotalSaleItems(variable.S.SaleId);
                variable.S.price = GetTotalSalePrice(variable.S.SaleId);
            }
            List <PoWithItems>   poListComplete = new List <PoWithItems>();
            List <PurchaseOrder> poList         = iPurchaseOrderService.GetAll().ToList();

            foreach (var item in poList)
            {
                int         currId   = item.PurchaseOrderId;
                PoWithItems currItem = GetPOrderWithItems(currId);
                poListComplete.Add(currItem);
            }

            var tongtien = 0.0;

            foreach (var variable in poListComplete)
            {
                tongtien += variable.PurchaseOrder.TotalPrice;
            }
            List <ThongKeTheoThang> result = soListComplete
                                             .GroupBy(l => l.S.SaleDate.Month)
                                             .Select(cl => new ThongKeTheoThang
            {
                Thang    = cl.Select(x => x.S.SaleDate.Month).FirstOrDefault(),
                Soluong  = cl.Count(),
                TongTien = cl.Sum(c => c.S.price),
            }).ToList();
            var DateOfToday = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            var NextDay     = DateOfToday.AddDays(1);
            var listDonHang = soListComplete.Where(s => s.S.SaleDate.CompareTo(DateOfToday) >= 0 && s.S.SaleDate.CompareTo(NextDay) < 0).ToList();

            double totalMoney = 0;
            int    toDay      = 0;

            if (listDonHang.Any())
            {
                toDay      = listDonHang.Sum(x => x.S.items);
                totalMoney = listDonHang.Sum(x => x.S.price);
            }
            var beginDate    = kiemtra.GetFirstDayOfWeek(DateTime.Now);
            var endDate      = beginDate.AddDays(6);
            int sevenDay     = 0;
            var listsevenDay = soListComplete.Where(s => s.S.SaleDate.CompareTo(beginDate) >= 0 && s.S.SaleDate.CompareTo(endDate) <= 0).ToList();

            if (listsevenDay.Any())
            {
                sevenDay = listsevenDay.Sum(x => x.S.items);
            }

            beginDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            endDate   = new DateTime(DateTime.Now.Year, DateTime.Now.Month + 1, 1);
            endDate   = endDate.AddDays(-1);
            int    thisMonth       = 0;
            double totalMoneyMonth = 0;

            var listthisMonth = soListComplete.Where(s => s.S.SaleDate.CompareTo(beginDate) >= 0 && s.S.SaleDate.CompareTo(endDate) <= 0).ToList();

            if (listthisMonth.Any())
            {
                thisMonth       = listthisMonth.Sum(x => x.S.items);
                totalMoneyMonth = listthisMonth.Sum(x => x.S.price);
            }
            double AverageMoney = totalMoneyMonth / DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);

            ViewBag.TongDoanhThuSale   = $"{result.Sum(x => x.TongTien):#,##0.00}";
            ViewBag.TongDoanhThuPaid   = $"{tongtien:#,##0.00}";
            ViewBag.TongDoanhThu       = $"{result.Sum(x => x.TongTien) + tongtien:#,##0.00}";
            ViewBag.ThoiGian           = DateTime.UtcNow.ToString("HH:mm:ss");
            ViewBag.TongDonHangOnline  = ThongKeDonHang();
            ViewBag.TongDonHangOffline = ThongKeGiaoDich();
            ViewBag.TongDonHang        = ThongKeDonHang() + ThongKeGiaoDich();
            ViewBag.ThanhVien          = ThongKeThanhVien();
            ViewBag.KhachHang          = ThongKeKhachHang();
            ViewBag.SanPhamBanDuoc     = ThongKeSanPham();
            ViewBag.Today             = toDay;
            ViewBag.Week              = sevenDay;
            ViewBag.ThisMonth         = thisMonth;
            ViewBag.TotalMoney        = $"{totalMoney:#,##0.00}";
            ViewBag.TotalMoneyMonth   = $"{totalMoney:#,##0.00}";
            ViewBag.AverageMoneyMonth = $"{AverageMoney:#,##0.00}";
            return(View(result));
        }