示例#1
0
        public SoWithItems GetOrderWithItems(int givenId)
        {
            var ansSo        = iSaleService.GetSales().SingleOrDefault(x => x.SaleId == givenId);
            var ansList      = iSaleItem.GetAll().Where(x => x.SaleId == givenId);
            int currLineItem = 0;
            var saleItems    = ansList.ToList();

            foreach (var each in saleItems)
            {
                var    a            = inventoryService.GetById(each.ProductId).SalePrice;
                double currLineCost = each.Quantity * (double)a;
                currLineItem     += each.Quantity;
                each.TotalSiPrice = currLineCost;
                each.TotalSI      = currLineItem;
                each.Returned     = 0;
            }
            iSaleService.Save();
            iSaleItem.Save();
            var ans = new SoWithItems(ansSo, saleItems);

            SoTotalSet(ans);
            iSaleService.Save();
            iSaleItem.Save();
            return(ans);
        }
示例#2
0
        public async Task <IActionResult> ReturnTransaction(int?id)
        {
            SoWithItems     saleOrder       = GetOrderWithItems((int)id);
            ApplicationUser applicationUser = await _userManager.GetUserAsync(User);

            string userEmail = applicationUser?.Email;

            foreach (var item in saleOrder.ItemList)
            {
                var i = iSaleItem.GetSaleItem().FirstOrDefault(x => x.SaleItemId == item.SaleItemId);
                inventoryService.GetById(item.ProductId).RestQuantity += i.Quantity;
                i.Quantity     = 0;
                i.TotalSI      = 0;
                i.TotalSiPrice = 0;
                i.Returned     = 1;
                i.UpdatedBy    = userEmail;
                i.UpdatedDate  = DateTime.Now;
                await iSaleItem.UpdateAsync(i);
            }
            await iSaleService.Save();

            await iSaleItem.Save();

            return(RedirectToAction("TransactionLookup"));
        }
        public ActionResult <List <BarModel> > GetBarData2()
        {
            Random rnd             = new Random();
            var    thu             = new string[] { "Thứ 2", "Thứ 3", "Thứ 4", "Thứ 5", "Thứ 6", "Thứ 7", "Chủ nhật" };
            var    ArrayWeeklySell = new int[] { 0, 0, 0, 0, 0, 0, 0 };
            var    beginDate       = kiemtra.GetFirstDayOfWeek(DateTime.Today); //Hàm GetFirstDayOfWeek,lấy thứ 2 datetime

            beginDate = new DateTime(beginDate.Year, beginDate.Month, beginDate.Day);
            var NextDay = beginDate.AddDays(1);
            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 <BarModel> chart = new List <BarModel>();

            for (int i = 0; i < 7; i++)
            {
                var tuantruoc = beginDate.AddDays(-7);
                var value2    = soListComplete.Where(s => s.S.SaleDate == tuantruoc).ToList();
                if (value2.Count > 0)
                {
                    ArrayWeeklySell[i] = value2.Sum(x => x.S.items);
                }
                beginDate = beginDate.AddDays(1);
                NextDay   = beginDate.AddDays(1);
                chart.Add(new BarModel()
                {
                    Count = ArrayWeeklySell[i],
                    Month = thu[i]
                });
            }
            return(chart);
        }
        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));
        }
示例#5
0
        public IActionResult Cancel(int?id)
        {
            SoWithItems saleOrder = GetOrderWithItems((int)id);

            foreach (var item in saleOrder.ItemList)
            {
                iSaleItem.Delete(item);
            }
            iSaleService.Delete(saleOrder.S);
            iSaleItem.Save();
            iSaleService.Save();

            return(RedirectToAction("Index"));
        }
示例#6
0
        public void SoTotalSet(SoWithItems x)
        {
            var    allItems = x.ItemList;
            double ans      = 0;
            int    items    = 0;

            foreach (var line in allItems)
            {
                ans  += line.TotalSiPrice;
                items = line.TotalSI;
            }
            x.S.TotalSalePrice = ans;
            x.S.TotalSaleItems = items;
            x.S.Status         = 0;
            return;
        }
示例#7
0
        public string GetStatus(int id)
        {
            SoWithItems x = GetOrderWithItems(id);

            if (!x.ItemList.Any())
            {
                return("SOLD");
            }
            if (x.ItemList.First().Returned == 0)
            {
                return("SOLD");
            }
            if (x.ItemList.First().Returned == 1)
            {
                return("RETURNED");
            }

            return("RETURNED");
        }
示例#8
0
        public IActionResult TransactionLookup(string option, string search)
        {
            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.HoatDong = ansList == 1 ? "RETURNED" : GetStatus(variable.S.SaleId);
                }
                variable.S.items        = GetTotalSaleItems(variable.S.SaleId);
                variable.S.price        = GetTotalSalePrice(variable.S.SaleId);
                variable.S.TenNhanVien  = iEmployeeService.GetById(variable.S.EmployeeId).FullName;
                variable.S.TenKhachHang = iCustomerService.GetById((int)variable.S.CustomerId).FullName;
            }
            //string cacheKey = "Searchfields";
            //bool cacheExists = _cache.TryGetItem(cacheKey, _lastUpdated, out List<SoWithItems> fields);
            //if (!cacheExists)
            //{
            //    fields = soListComplete;
            //    _cache.AddItem(cacheKey, _lastUpdated, fields);
            //}

            if (option == "Tên nhân viên")
            {
                if (search == null)
                {
                    return(View(soListComplete.OrderByDescending(x => x.S.SaleDateString).ThenBy(q => q.S.price).ThenBy(m => m.S.items).Take(15).ToList()));
                }
                var searchcus = soListComplete.Where(x => x.S.TenNhanVien.ToLower().ToString().Contains(search.ToLower())).ToList();
                if (searchcus.Count == 0)
                {
                    return(View(new List <SoWithItems>()));
                }
                return(View(searchcus));
            }
            else if (option == "Tên khách hàng")
            {
                if (search == null)
                {
                    return(View(soListComplete.OrderByDescending(x => x.S.SaleDateString).ThenBy(q => q.S.price).ThenBy(m => m.S.items).Take(15).ToList()));
                }

                var searchcus = soListComplete.Where(x => x.S.TenKhachHang.ToLower().ToString().Contains(search.ToLower())).ToList();
                if (searchcus.Count != 0)
                {
                    return(View(searchcus));
                }
                return(View(new List <SoWithItems>()));
            }
            else
            {
                return(View(soListComplete.OrderByDescending(x => x.S.SaleDateString).ThenBy(q => q.S.price).ThenBy(m => m.S.items).Take(15).ToList()));
            }
        }
示例#9
0
        public int GetTotalSaleItems(int id)
        {
            SoWithItems x = GetOrderWithItems(id);

            return(x.S.TotalSaleItems);
        }
示例#10
0
        public double GetTotalSalePrice(int id)
        {
            SoWithItems x = GetOrderWithItems(id);

            return(x.S.TotalSalePrice);
        }
        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));
        }