Beispiel #1
0
        public JsonResult LoadGoodsStockGrid(string sidx, string sord, int page, int rows, string customerId, string goodsId, string batchNo, string packing, string warehouse, string location, string productionDate, string enterWarehouseBillId, string consignedDeliveryNo)
        {
            //读取库存数据
            string strErrText;
            StockSystem stock = new StockSystem();
            List<Stock> listStock = stock.LoadGoodsStocksByConditions(customerId, goodsId, batchNo, packing, warehouse, location, productionDate, enterWarehouseBillId, consignedDeliveryNo, LoginAccountId, LoginStaffName, out strErrText);
            if (listStock == null)
            {
                throw new Exception(strErrText);
            }

            //读取已提交未发货数据
            PlanSystem plan = new PlanSystem();
            List<DeliverPlanGoods> listDeliverPlanGoods = plan.LoadDeliverPlanGoodsBalancesByConditions(customerId, goodsId, batchNo, packing, warehouse, location, productionDate, enterWarehouseBillId, consignedDeliveryNo, LoginAccountId, LoginStaffName, out strErrText);
            if (listDeliverPlanGoods == null)
            {
                throw new Exception(strErrText);
            }

            //计算结存数
            foreach (Stock s in listStock)
            {
                foreach (DeliverPlanGoods dpg in listDeliverPlanGoods)
                {
                    if (dpg.GoodsId == s.GoodsId &&
                        dpg.BatchNo == s.BatchNo &&
                        dpg.Packing == s.Packing &&
                        dpg.Warehouse == s.Warehouse &&
                        dpg.Location == s.Location &&
                        dpg.ProductionDate == s.ProductionDate &&
                        dpg.EnterWarehouseBillId == s.EnterWarehouseBillId &&
                        (dpg.Packages > 0 || dpg.Tunnages > 0 || dpg.Piles > 0 || dpg.TenThousands > 0))
                    {
                        if (s.Packages < dpg.Packages)
                        {
                            s.Packages = 0;
                            dpg.Packages -= s.Packages;
                        }
                        else
                        {
                            s.Packages -= dpg.Packages;
                            dpg.Packages = 0;
                        }

                        if (s.Tunnages < dpg.Tunnages)
                        {
                            s.Tunnages = 0;
                            dpg.Tunnages -= s.Tunnages;
                        }
                        else
                        {
                            s.Tunnages -= dpg.Tunnages;
                            dpg.Tunnages = 0;
                        }

                        if (s.Piles < dpg.Piles)
                        {
                            s.Piles = 0;
                            dpg.Piles -= s.Piles;
                        }
                        else
                        {
                            s.Piles -= dpg.Piles;
                            dpg.Piles = 0;
                        }

                        if (s.TenThousands < dpg.TenThousands)
                        {
                            s.TenThousands = 0;
                            dpg.TenThousands -= s.TenThousands;
                        }
                        else
                        {
                            s.TenThousands -= dpg.TenThousands;
                            dpg.TenThousands = 0;
                        }
                    }
                }
            }

            //检查已提交未发货剩余数字
            if (listDeliverPlanGoods.Sum(g => g.Packages) > 0 || listDeliverPlanGoods.Sum(g => g.Tunnages) > 0 || listDeliverPlanGoods.Sum(g => g.Piles) > 0 || listDeliverPlanGoods.Sum(g => g.TenThousands) > 0)
            {
                throw new Exception(InnoSoft.LS.Resources.Strings.SubmitedDeliverPlanGoodsNotCompleteSubtract);
            }

            //剔除结存件数为0的记录
            listStock = listStock.Where(s => s.Packages > 0 || s.Tunnages > 0 || s.Piles > 0 || s.TenThousands > 0).ToList();

            //记录编号
            for (int i = 0; i < listStock.Count; i++)
            {
                listStock[i].Id = i + 1;
            }

            //提取当前页面数据
            int nTotalRows = listStock.Count;
            int nPageIndex = page;
            int nPageSize = rows;
            int nTotalPages = nTotalRows / nPageSize;
            if (nTotalRows % nPageSize > 0)
                nTotalPages++;

            var data = listStock.OrderBy(s => s.BatchNo).Skip((nPageIndex - 1) * nPageSize).Take(nPageSize).ToList();

            //生成表格数据
            var ret = new
            {
                total = nTotalPages,
                page = nPageIndex,
                records = nTotalRows,
                rows = (
                      from s in data
                      select new
                      {
                          id = s.Id,
                          cell = new string[] {
                              s.GoodsId.ToString(),
                              s.GoodsNo,
                              s.GoodsName,
                              s.Brand,
                              s.SpecModel,
                              s.GWeight,
                              s.Grade,
                              s.BatchNo,
                              s.Packing,
                              s.Location,
                              s.Packages.ToString(),
                              s.Packages != 0 ? (s.Tunnages / s.Packages).ToString("#0.######") : s.PieceWeight.ToString("#0.######"),
                              s.Tunnages.ToString("#0.######"),
                              s.Piles.ToString("#0.######"),
                              s.TenThousands.ToString("#0.######"),
                              s.ProductionDate,
                              s.EnterWarehouseBillId.ToString(),
                              s.EnterWarehouseBillNo,
                              "0",
                              "0",
                              "0",
                              "0"
                          }
                      }).ToArray(),
                userdata = new
                {
                    GoodsNo = InnoSoft.LS.Resources.Labels.Total,
                    Packages = data.Sum(s => s.Packages),
                    Tunnages = data.Sum(s => s.Tunnages),
                    Piles = data.Sum(s => s.Piles),
                    TenThousands = data.Sum(s => s.TenThousands),
                    ActualPackages = 0,
                    ActualTunnages = 0,
                    ActualPiles = 0,
                    ActualTenThousands = 0
                }
            };
            return Json(ret, JsonRequestBehavior.AllowGet);
        }