public static void AddInStorageRecord(InStorageRecord record) //新建补货记录 { string command = "INSERT INTO 补货记录(入库单号,SVW物料号,入库日期,入库数量,填写人,填写日期,备注) " + "VALUES(" + record.InStorageNumber + ",'" + record.SVWNumber + "','" + record.InStorageTime + "','" + record.InStorageCount + "','" + record.writtenby + "','" + DateTime.Now + "','" + record.remark + "')"; ManipulateData(command); }
public Task <Result <int> > add(InStorageRecord t) { throw new NotImplementedException(); }
/// <summary> /// 处理异常,补充收货 /// </summary> /// <param name="supplementList">补充产品list</param> /// <param name="userName">操作人</param> /// <returns></returns> public async Task <Result <int> > supplementReceiveOrder(List <InStorageRecord> supplementList, string userName) { Result <int> result = new Result <int>(); string orderNo = supplementList.First().orderNo; try { using (LayerDbContext context = new LayerDbContext()) { //1.插入入库记录 2.查询本订单下 根据物料group by 应收与实收是否相等,修改订单状态与订单实际总成本 3. 增加库存 var orderModel = context.orderInfo.Where(x => x.orderNo == orderNo).Single(); context.inStorageRecord.AddRange(supplementList); //入库记录中 本订单 各物料的应收实收数量 //DONE: 验证此时的入库记录是否包含补录的记录 不包含 //TODO: left join orderdetailinfo var inStorageRecodes = context.inStorageRecord.Where(x => x.orderNo == orderNo).GroupBy(x => x.materialId).Select(x => new { materialId = x.Key, countReal = x.Sum(item => item.countReal), priceIn = x.Max(item => item.priceIn) }); var inStorageRecodesEntities = (from x in inStorageRecodes join y in context.orderDetailInfo.Where(x => x.orderNo == orderNo) on x.materialId equals y.materialId select new { materialId = x.materialId, priceIn = x.priceIn, countReal = x.countReal, countReference = y.num, }).ToList(); List <InStorageRecord> inStorageRecodeCopy = new List <InStorageRecord>(); InStorageRecord model = null; foreach (var item in inStorageRecodesEntities) { model = new InStorageRecord(); model.materialId = item.materialId; model.priceIn = item.priceIn; model.countReal = item.countReal; model.countReference = item.countReference; inStorageRecodeCopy.Add(model); } //订单状态 OrderStatusEnum status = OrderStatusEnum.completed; //实际进价总和 float sumPriceReal = 0; foreach (var item in supplementList) { inStorageRecodeCopy.Where(x => x.materialId == item.materialId).Single().countReal += item.countReal; } if (inStorageRecodeCopy.Where(x => x.countReal != x.countReference).Count() > 0) { status = OrderStatusEnum.excepted; } sumPriceReal = inStorageRecodeCopy.Sum(x => x.priceIn * x.countReal); orderModel.status = status.ToString(); orderModel.lastUpdatedBy = userName; orderModel.lastUpdatedDate = DateTime.Now; orderModel.sumPriceReal = sumPriceReal; //库存 List <Inventory> inventoryList = new List <Inventory>(); Inventory model1 = null; foreach (var item in supplementList) { model1 = new Inventory() { count = item.countReal, materialId = item.materialId, priceIn = item.priceIn }; inventoryList.Add(model1); } context.inventory.AddRange(inventoryList); await context.SaveChangesAsync(); } } catch (Exception err) { result.addError(err.Message); } return(result); }