public ActionResult Index()
        {
            PoManager             manager = new PoManager();
            PoCollectionViewModel model   = new PoCollectionViewModel
            {
                SearchDateFrom = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1),
                SearchDateTo   = DateTime.UtcNow,
                SearchCustomer = ""
            };

            model = manager.GetPoList(model);

            return(View(model));
        }
        public ActionResult List(DateTime dateFrom, DateTime dateTo, string customer)
        {
            PoManager manager = new PoManager();

            PoCollectionViewModel model = new PoCollectionViewModel
            {
                SearchDateFrom = dateFrom,
                SearchDateTo   = dateTo,
                SearchCustomer = customer
            };

            model = manager.GetPoList(model);

            return(PartialView("List", model));
        }
Ejemplo n.º 3
0
        public PoCollectionViewModel GetPoList(PoCollectionViewModel model = null)
        {
            if (model == null)
            {
                model = new PoCollectionViewModel();
            }

            var queryDetail = _unitOfWork.GetRepository <Txn_PODetail>().GetQueryable(o => o.Status == 1);

            // Get data
            var query = (from p in _unitOfWork.GetRepository <Txn_PO>().GetQueryable(o => o.Status == 1 && model.SearchDateFrom <= o.PoDate && o.PoDate <= model.SearchDateTo)
                         orderby p.PoDate descending

                         select new PoViewModel
            {
                // Txn_PO
                PoId = p.PoId,
                PoNumber = p.PoNumber,
                PoDate = p.PoDate,
                //PoFilePath = p.PoFilePath,
                //InvoiceFilePath = p.InvoiceFilePath,
                CustomerName = p.CustomerName,

                PoDetailCollection = (
                    from pd in queryDetail
                    where pd.PoId == p.PoId
                    select new PoDetailModel
                {
                    // Txn_PODetail
                    PoDetailId = pd.PoDetailId,
                    ProductName = pd.ProductName,
                    //ProductBrand = pd.ProductBrand,
                    //ProductType = pd.ProductType,
                    //PricePerUnit = pd.PricePerUnit,
                    //ActualPricePerUnit = pd.ActualPricePerUnit,
                    //Amount = pd.Amount,
                    TotalPrice = pd.TotalPrice,
                    //ActualTotalPrice = pd.ActualTotalPrice,
                    //Tax = pd.Tax,
                    //TransportLocation = pd.TransportLocation,
                    //TransportFee = pd.TransportFee,
                    //ParcelFee = pd.ParcelFee,
                    //ServiceFee = pd.ServiceFee,
                    //OtherFee = pd.OtherFee,
                    //CustomerLead = pd.CustomerLead,
                    //CustomerLeadPercentage = pd.CustomerLeadPercentage,
                    TotalCost = pd.TotalCost,
                    Profit = pd.Profit,
                    //ProfitPercentage = pd.ProfitPercentage,
                    //Remark = pd.Remark,
                    //Status = pd.Status,
                }).ToList()
            });

            // Set Where cause
            if (!string.IsNullOrWhiteSpace(model.SearchCustomer))
            {
                query = query.Where(o => o.CustomerName.StartsWith(model.SearchCustomer));
            }

            model.PoCollection = query.ToList();

            // Sum data
            decimal sumAllTotalPrice = decimal.Zero;
            decimal sumAllTotalCost  = decimal.Zero;
            decimal sumAllProfit     = decimal.Zero;

            foreach (PoViewModel po in model.PoCollection)
            {
                decimal sumTotalPrice = decimal.Zero;
                decimal sumTotalCost  = decimal.Zero;
                decimal sumProfit     = decimal.Zero;

                foreach (PoDetailModel det in po.PoDetailCollection)
                {
                    sumTotalPrice += det.TotalPrice;
                    sumTotalCost  += det.TotalCost;
                    sumProfit     += det.Profit;
                }

                po.SumTotalPrice = sumTotalPrice;
                po.SumTotalCost  = sumTotalCost;
                po.SumProfit     = sumProfit;

                // Calculate all
                sumAllTotalPrice += sumTotalPrice;
                sumAllTotalCost  += sumTotalCost;
                sumAllProfit     += sumProfit;
            }

            model.SumAllTotalPrice = sumAllTotalPrice;
            model.SumAllTotalCost  = sumAllTotalCost;
            model.SumAllProfit     = sumAllProfit;

            return(model);
        }