/// <summary> /// 自动生成采购计划 /// </summary> /// <param name="oprCode"> </param> /// <returns> </returns> public TPurchasePlan GeneralPurchasePlan(string oprCode) { TPurchasePlan tplan = new TPurchasePlan(); //创建采购计划单 //设置采购计划主信息操作类型为插入以在调用数据访问层做添加处理 tplan.OprType = OperateType.otInsert; tplan.Content = new MMS_PurchasePlanContent(); //创建采购计划单主信息 //生成采购计划单号 tplan.Content.PurchaseBillCode = BatchEvaluate.GeneralCode(); tplan.Content.PurchaseDate = DateTime.Now; //设置采购日期 tplan.Content.Provider = ""; //采购供应商 tplan.Content.PurchaseMan = ""; //采购经办人 tplan.Content.AuditFlag = false; //采购计划确认标志 //取允许采购的货品信息列表 List <MMS_ProductInfo> productList = ProductInfoService.Instance.GetAllInfo().Where(itm => itm.IsStop == null || itm.IsStop == false).ToList(); //取所有库存信息列表 List <MMS_Store> storeList = StoreService.Instance.GetAllInfo(); //用LINQ将库存信息按货品代码进行分组汇总 var query = from store in storeList group store by store.ProductCode into g orderby g.Key select new { ProductCode = g.Key, Quantity = g.Sum(itm => itm.Quantity) }; //循环遍历货品信息列表 foreach (var product in productList) { int qty = 0; if (query.Count() != 0) //取该货品的库存汇总数量 { var store = query.FirstOrDefault(itm => itm.ProductCode == product.ProductCode); if (store != null) { qty = store.Quantity; } } if (qty < product.MinStore) //如果该货品的库存汇总数量小于最低库存 { //创建采购计划货品实例 TPurchasePlanDetail tDetail = new TPurchasePlanDetail(); //设置为插入操作以便数据访问层处理 tDetail.OprType = OperateType.otInsert; tDetail.DetDetail = new MMS_PurchasePlanDetail(); tDetail.DetDetail.PurchaseBillCode = tplan.Content.PurchaseBillCode; //计划单号 tDetail.DetDetail.ProductCode = product.ProductCode; //货品代码 tDetail.DetDetail.Quantity = (product.MinStore ?? 0) - qty; //货品数量 //调用入库单服务类的GetLastPurchasePrice方法取货品单价 tDetail.DetDetail.Price = daoPur.GetLastPurchasePrice(tplan.Content.Provider, product.ProductCode); tDetail.DetDetail.Memo = ""; //注备 tplan.Detail.Add(tDetail); //将采购计划货品实体添加到采购计划单中 } } int cnt = dao.SavePurchasePlan(tplan); //调用数据访问层的保存采购计划单方法 tplan.Content.ID = cnt; //返回新生成计划单的主键值 return(tplan); }
/// <summary> /// 获得货品的采购单价 /// </summary> /// <param name="clientCode"> </param> /// <param name="productCode"> </param> /// <returns> </returns> public double GetLastPurchasePrice(string clientCode, string productCode) { //获得该客户最后一次采购单价,如无此客户则取所有客户最后一次的,如无则取货品最低价 return(dao.GetLastPurchasePrice(clientCode, productCode)); }