public void MakeupReceiveOrder() { IList<OrderMaster> orderMasterList = this.genericMgr.FindEntityWithNativeSql<OrderMaster>(@"select * from ORD_OrderMstr_2 where OrderNo in ( select ord.OrderNo from ORD_OrderDet_2 as ord left join ORD_RecDet_2 as rec on ord.Id = rec.OrderDetId where ord.RecQty <> 0 and rec.Id is null)"); foreach (OrderMaster orderMaster in orderMasterList) { SecurityContextHolder.Set(this.genericMgr.FindById<User>(orderMaster.CreateUserId)); try { IList<OrderDetail> orderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>(@"select * from ORD_OrderDet_2 where OrderNo = ?", orderMaster.OrderNo); orderMaster.OrderDetails = orderDetailList; #region 发货 #region OrderDetailInput赋发货数量 foreach (OrderDetail orderDetail in orderDetailList) { OrderDetailInput orderDetailInput = new OrderDetailInput(); orderDetailInput.ShipQty = orderDetail.OrderedQty; orderDetailInput.ReceiveQty = orderDetail.OrderedQty; orderDetail.AddOrderDetailInput(orderDetailInput); } #endregion IpMaster ipMaster = null; IList<OrderMaster> omList = new List<OrderMaster>(); omList.Add(orderMaster); ipMaster = this.ipMgr.TransferOrder2Ip(omList); #region 循环发货 foreach (IpDetail ipDetail in ipMaster.IpDetails) { ipDetail.CurrentPartyFrom = ipMaster.PartyFrom; //为了记录库存事务 ipDetail.CurrentPartyFromName = ipMaster.PartyFromName; //为了记录库存事务 ipDetail.CurrentPartyTo = ipMaster.PartyTo; //为了记录库存事务 ipDetail.CurrentPartyToName = ipMaster.PartyToName; //为了记录库存事务 OrderDetail orderDetail = orderDetailList.Where(det => det.Id == ipDetail.OrderDetailId).Single(); #region 建立发货库明细和IpDetailInput的关系 ipDetail.IpLocationDetails = new List<IpLocationDetail>(); IpLocationDetail ipLocationDetail = new IpLocationDetail(); ipLocationDetail.HuId = null; ipLocationDetail.LotNo = null; ipLocationDetail.IsCreatePlanBill = false; ipLocationDetail.IsConsignment = false; ipLocationDetail.PlanBill = null; ipLocationDetail.ActingBill = null; ipLocationDetail.QualityType = CodeMaster.QualityType.Qualified; ipLocationDetail.IsFreeze = false; ipLocationDetail.IsATP = true; ipLocationDetail.OccupyType = CodeMaster.OccupyType.None; ipLocationDetail.OccupyReferenceNo = null; ipLocationDetail.Qty = orderDetail.OrderedQty; ipDetail.AddIpLocationDetail(ipLocationDetail); #endregion } #endregion #region 生成收货的IpInput foreach (OrderDetail orderDetail in orderDetailList) { //订单收货一定是一条订单明细对应一条发货单明细 IpDetail ipDetail = ipMaster.IpDetails.Where(det => det.OrderDetailId == orderDetail.Id).Single(); ipDetail.IpDetailInputs = null; //清空Ip的发货数据,准备添加收货数据 foreach (OrderDetailInput orderDetailInput in orderDetail.OrderDetailInputs) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ReceiveQty = orderDetailInput.ShipQty; ipDetail.AddIpDetailInput(ipDetailInput); } } foreach (IpDetail ipDetail in ipMaster.IpDetails) { CycleMatchIpDetailInput(ipDetail, ipDetail.IpDetailInputs, ipDetail.IpLocationDetails); } #endregion #endregion #region 收货 ReceiptMaster receiptMaster = null; receiptMaster = this.receiptMgr.TransferIp2Receipt(ipMaster); this.receiptMgr.CreateReceipt(receiptMaster, false, orderMaster.CreateDate); #endregion this.genericMgr.FlushSession(); } catch (Exception ex) { this.genericMgr.CleanSession(); log.Error(ex); } } }
private ReceiptMaster ReceiveOrder(IList<OrderDetail> orderDetailList, bool isCheckKitTraceItem, ProductLineMap productLineMap, DateTime effectiveDate, string ipNo) { #region 判断是否全0收货 if (orderDetailList == null || orderDetailList.Count == 0) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveDetailIsEmpty); } IList<OrderDetail> nonZeroOrderDetailList = orderDetailList.Where(o => o.ReceiveQtyInput != 0 || o.ScrapQtyInput != 0).ToList(); if (nonZeroOrderDetailList.Count == 0) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveDetailIsEmpty); } #endregion #region 查询订单头对象 IList<OrderMaster> orderMasterList = LoadOrderMasters(nonZeroOrderDetailList.Select(p => p.OrderNo).Distinct(), true); #endregion #region 获取收货订单类型 IList<com.Sconit.CodeMaster.OrderType> orderTypeList = (from orderMaster in orderMasterList group orderMaster by orderMaster.Type into result select result.Key).ToList(); if (orderTypeList.Count > 1) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_CannotMixOrderTypeReceive); } com.Sconit.CodeMaster.OrderType orderType = orderTypeList.First(); #endregion #region 计划协议不能按收货校验 if (orderType == CodeMaster.OrderType.ScheduleLine) { throw new BusinessException("计划协议不能按订单收货。"); } #endregion #region 排序单不能按订单收货校验 if (orderMasterList.Where(o => o.OrderStrategy == CodeMaster.FlowStrategy.SEQ).Count() > 0) { throw new BusinessException("排序单不能按订单收货。"); } #endregion #region 循环订单头检查 foreach (OrderMaster orderMaster in orderMasterList) { //if (!Utility.SecurityHelper.HasPermission(orderMaster)) //{ // throw new BusinessException("没有此订单{0}的操作权限。", orderMaster.OrderNo); //} orderMaster.OrderDetails = nonZeroOrderDetailList.Where(det => det.OrderNo == orderMaster.OrderNo).ToList(); //如果非生产,把Submit状态改为InProcess if (orderMaster.Status == com.Sconit.CodeMaster.OrderStatus.Submit && orderMaster.Type != com.Sconit.CodeMaster.OrderType.Production && orderMaster.Type != com.Sconit.CodeMaster.OrderType.SubContract) { UpdateOrderMasterStatus2InProcess(orderMaster); } //判断OrderHead状态 if (orderMaster.Status != com.Sconit.CodeMaster.OrderStatus.InProcess) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_StatusErrorWhenReceive, orderMaster.OrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.OrderStatus, ((int)orderMaster.Status).ToString())); } #region 订单、生产线暂停检查 if (orderMaster.IsPause) { if (orderMaster.Type == CodeMaster.OrderType.Production) { throw new BusinessException("生产单{0}已经暂停,不能收货。", orderMaster.OrderNo); } else if (orderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT) { throw new BusinessException("KIT单{0}已经暂停,不能收货。", orderMaster.OrderNo); } else if (orderMaster.OrderStrategy == CodeMaster.FlowStrategy.SEQ) { throw new BusinessException("排序单{0}已经暂停,不能收货。", orderMaster.OrderNo); } else { throw new BusinessException("订单{0}已经暂停,不能收货。", orderMaster.OrderNo); } } //if ((orderMaster.Type == CodeMaster.OrderType.Production // || orderMaster.Type == CodeMaster.OrderType.SubContract // //生产线暂停可以收货 // //|| orderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT // //|| orderMaster.OrderStrategy == CodeMaster.FlowStrategy.SEQ // ) // && !string.IsNullOrWhiteSpace(orderMaster.Flow)) //{ // FlowMaster flowMaster = this.genericMgr.FindById<FlowMaster>(orderMaster.Flow); // if (flowMaster.IsPause) // { // throw new BusinessException("生产线{0}已经暂停,不能收货。", orderMaster.Flow); // } //} #endregion #region 整包装收货判断,快速的不要判断 if (orderMaster.IsReceiveFulfillUC && orderMaster.SubType == com.Sconit.CodeMaster.OrderSubType.Normal && !(orderMaster.IsAutoRelease && orderMaster.IsAutoStart)) { foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { //不合格品不作为收货数 //if (orderDetail.ReceiveQualifiedQtyInput % orderDetail.UnitCount != 0) if (orderDetail.ReceiveQtyInput % orderDetail.UnitCount != 0) { //不是整包装 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyNotFulfillUnitCount, orderDetail.Item); } } } #endregion #region 是否过量发货判断,未发货即收货也要判断是否过量发货 foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { if (!orderMaster.IsOpenOrder && orderMaster.Type != com.Sconit.CodeMaster.OrderType.Production //生产和委外不需要判断 && orderMaster.Type != com.Sconit.CodeMaster.OrderType.SubContract) { if (Math.Abs(orderDetail.ShippedQty) > Math.Abs(orderDetail.OrderedQty)) { //订单的发货数已经大于等于订单数 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ShipQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item); } else if (!orderMaster.IsShipExceed && Math.Abs(orderDetail.ShippedQty + orderDetail.ReceiveQtyInput) > Math.Abs(orderDetail.OrderedQty)) //不允许过量收货 { //订单的发货数 + 本次发货数大于订单数 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ShipQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item); } } } #endregion #region 是否过量收货判断 foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { if (!orderMaster.IsOpenOrder) { var orderDeviationQty = decimal.MaxValue; if (!orderMaster.IsReceiveExceed) { orderDeviationQty = Math.Abs(orderDetail.OrderedQty); } else { if (orderMaster.CurrentFlowMaster.OrderDeviation > 0) { orderDeviationQty = Math.Abs(orderDetail.OrderedQty * (((decimal)orderMaster.CurrentFlowMaster.OrderDeviation / 100) + 1)); } } //订单的收货数已经大于等于订单数 if (Math.Abs(orderDetail.ReceivedQty) >= Math.Abs(orderDetail.OrderedQty)) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item); } else if (Math.Abs(orderDetail.ReceivedQty + orderDetail.RejectedQty + orderDetail.ScrapQty + orderDetail.ReceiveQtyInput + orderDetail.ScrapQtyInput) > orderDeviationQty) //不允许过量收货 { //订单的收货数 + 本次收货数大于订单数 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item); } } } #endregion #region KIT单收货判断 if (orderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT) { CheckKitOrderDetail(orderMaster, isCheckKitTraceItem, false); } #endregion } #endregion #region 校验发货先进先出 CheckShipFiFo(orderMasterList); #endregion #region 循环更新订单明细 foreach (OrderDetail orderDetail in nonZeroOrderDetailList) { //未发货直接收货需要累加已发货数量 if (orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.Production && orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.SubContract) { orderDetail.ShippedQty += orderDetail.ReceiveQtyInput; } if (orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.Production && orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.SubContract) { //orderDetail.ReceivedQty += orderDetail.ReceiveQualifiedQtyInput; orderDetail.ReceivedQty += orderDetail.ReceiveQtyInput; } else { //生产收货更新合格数和不合格数量 //orderDetail.ReceivedQty += orderDetail.ReceiveQualifiedQtyInput; orderDetail.ReceivedQty += orderDetail.ReceiveQtyInput; orderDetail.ScrapQty += orderDetail.ScrapQtyInput; } genericMgr.Update(orderDetail); } #endregion #region 发货 #region OrderDetailInput赋发货数量 foreach (OrderDetail orderDetail in nonZeroOrderDetailList) { foreach (OrderDetailInput orderDetailInput in orderDetail.OrderDetailInputs) { orderDetailInput.ShipQty = orderDetailInput.ReceiveQty; } } #endregion IpMaster ipMaster = null; var subType = orderMasterList.First().SubType; if ((orderType == com.Sconit.CodeMaster.OrderType.Production || orderType == com.Sconit.CodeMaster.OrderType.SubContract) && subType != CodeMaster.OrderSubType.Return) { //生产和委外的非退货单 } else { //物流单 生产和委外的退货单也要创建Ip ipMaster = this.ipMgr.TransferOrder2Ip(orderMasterList); #region 循环发货 foreach (IpDetail ipDetail in ipMaster.IpDetails) { ipDetail.CurrentPartyFrom = ipMaster.PartyFrom; //为了记录库存事务 ipDetail.CurrentPartyFromName = ipMaster.PartyFromName; //为了记录库存事务 ipDetail.CurrentPartyTo = ipMaster.PartyTo; //为了记录库存事务 ipDetail.CurrentPartyToName = ipMaster.PartyToName; //为了记录库存事务 //ipDetail.CurrentOccupyType = com.Sconit.CodeMaster.OccupyType.None; //todo-默认出库未占用库存,除非捡货或检验的出库 IList<InventoryTransaction> inventoryTransactionList = this.locationDetailMgr.InventoryOut(ipDetail, effectiveDate); #region 建立发货库明细和IpDetailInput的关系 if (inventoryTransactionList != null && inventoryTransactionList.Count > 0) { ipDetail.IpLocationDetails = (from trans in inventoryTransactionList group trans by new { HuId = trans.HuId, LotNo = trans.LotNo, IsCreatePlanBill = trans.IsCreatePlanBill, IsConsignment = trans.IsConsignment, PlanBill = trans.PlanBill, ActingBill = trans.ActingBill, QualityType = trans.QualityType, IsFreeze = trans.IsFreeze, IsATP = trans.IsATP, OccupyType = trans.OccupyType, OccupyReferenceNo = trans.OccupyReferenceNo } into g select new IpLocationDetail { HuId = g.Key.HuId, LotNo = g.Key.LotNo, IsCreatePlanBill = g.Key.IsCreatePlanBill, IsConsignment = g.Key.IsConsignment, PlanBill = g.Key.PlanBill, ActingBill = g.Key.ActingBill, QualityType = g.Key.QualityType, IsFreeze = g.Key.IsFreeze, IsATP = g.Key.IsATP, OccupyType = g.Key.OccupyType, OccupyReferenceNo = g.Key.OccupyReferenceNo, Qty = g.Sum(t => -t.Qty), //发货的库存事务为负数,转为收货数应该取负数 //PlanBillQty = g.Sum(t=>-t.PlanBillQty), //ActingBillQty = g.Sum(t=>-t.ActingBillQty) }).ToList(); } #endregion } #endregion #region 生成收货的IpInput foreach (OrderDetail orderDetail in nonZeroOrderDetailList) { OrderMaster orderMaster = orderMasterList.Where(o => o.OrderNo == orderDetail.OrderNo).Single(); //订单收货一定是一条订单明细对应一条发货单明细 IpDetail ipDetail = ipMaster.IpDetails.Where(det => det.OrderDetailId == orderDetail.Id).Single(); ipDetail.IpDetailInputs = null; //清空Ip的发货数据,准备添加收货数据 foreach (OrderDetailInput orderDetailInput in orderDetail.OrderDetailInputs) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ReceiveQty = orderDetailInput.ShipQty; if (orderMaster.IsReceiveScanHu || orderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT) { ipDetailInput.HuId = orderDetailInput.HuId; ipDetailInput.LotNo = orderDetailInput.LotNo; } ipDetail.AddIpDetailInput(ipDetailInput); } } if (orderMasterList.Where(o => o.OrderStrategy == CodeMaster.FlowStrategy.KIT).Count() > 0) { #region Kit单生成收货Input foreach (IpDetail ipDetail in ipMaster.IpDetails) { foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs) { if (!string.IsNullOrEmpty(ipDetailInput.HuId)) { #region 按条码匹配 IpLocationDetail matchedIpLocationDetail = ipDetail.IpLocationDetails.Where(locDet => locDet.HuId == ipDetailInput.HuId).SingleOrDefault(); matchedIpLocationDetail.ReceivedQty = matchedIpLocationDetail.Qty; if (matchedIpLocationDetail != null) { ipDetailInput.AddReceivedIpLocationDetail(matchedIpLocationDetail); } #endregion } else { #region 按数量匹配 IpDetail gapIpDetail = new IpDetail(); MatchIpDetailInput(ipDetail, ipDetailInput, ipDetail.IpLocationDetails, ref gapIpDetail); #endregion } } } #endregion } else { #region 其它订单生成收货Input if (ipMaster.IsShipScanHu && ipMaster.IsReceiveScanHu) { #region 按条码匹配 foreach (IpDetail ipDetail in ipMaster.IpDetails) { foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs) { IpLocationDetail matchedIpLocationDetail = ipDetail.IpLocationDetails.Where(locDet => locDet.HuId == ipDetailInput.HuId).SingleOrDefault(); matchedIpLocationDetail.ReceivedQty = matchedIpLocationDetail.Qty; if (matchedIpLocationDetail != null) { ipDetailInput.AddReceivedIpLocationDetail(matchedIpLocationDetail); } } } #endregion } else { #region 按数量匹配 foreach (IpDetail ipDetail in ipMaster.IpDetails) { CycleMatchIpDetailInput(ipDetail, ipDetail.IpDetailInputs, ipDetail.IpLocationDetails); } #endregion } #endregion } #endregion } #endregion #region 收货 生产和委外退货的逻辑在CreateReceipt中实现 ReceiptMaster receiptMaster = null; if (subType != CodeMaster.OrderSubType.Return && (orderType == com.Sconit.CodeMaster.OrderType.Production || orderType == com.Sconit.CodeMaster.OrderType.SubContract)) { #region 生产和委外正常收货 消耗原材料,收成品 if (orderMasterList.Count > 1 && orderType == com.Sconit.CodeMaster.OrderType.Production) { throw new TechnicalException("生产单不能合并收货。"); } foreach (OrderMaster orderMaster in orderMasterList) { orderMaster.IpNo = ipNo; receiptMaster = this.receiptMgr.TransferOrder2Receipt(orderMaster); this.receiptMgr.CreateReceipt(receiptMaster); #region 回冲物料 if (productLineMap != null) { #region 整车 BackflushVan(productLineMap, nonZeroOrderDetailList, receiptMaster, orderMaster); #endregion } else { #region 非整车 foreach (OrderDetail orderDetail in nonZeroOrderDetailList) { //OrderDetailInput orderDetailInput = orderDetail.OrderDetailInputs[0]; foreach (var orderDetailInput in orderDetail.OrderDetailInputs) { orderDetailInput.ReceiptDetails = receiptMaster.ReceiptDetails.Where(r => r.OrderDetailId == orderDetail.Id).ToList(); } } this.productionLineMgr.BackflushProductOrder(nonZeroOrderDetailList, orderMaster, DateTime.Now); #endregion } #endregion } #endregion } else { #region 物流收货 receiptMaster = this.receiptMgr.TransferIp2Receipt(ipMaster); if (orderMasterList.Where(o => o.OrderStrategy == CodeMaster.FlowStrategy.KIT).Count() > 0) { //kit收货特殊处理 this.receiptMgr.CreateReceipt(receiptMaster, true, effectiveDate); } else { this.receiptMgr.CreateReceipt(receiptMaster, false, effectiveDate); } #endregion } #endregion #region 尝试关闭订单 foreach (OrderMaster orderMaster in orderMasterList) { if (orderMaster.Type == CodeMaster.OrderType.Production) { #region 生产 if (productLineMap != null && productLineMap.ProductLine == orderMaster.Flow) { #region 总装生产单 CloseVanOrder(orderMaster, productLineMap); #endregion } else if (productLineMap != null && (productLineMap.CabFlow == orderMaster.Flow || productLineMap.ChassisFlow == orderMaster.Flow)) { #region 驾驶室和底盘 //驾驶室和底盘下线完工订单,总装下线后一起关闭 CompleteVanSubOrder(orderMaster); #endregion } else { #region 非整车 TryCloseOrder(orderMaster); #endregion } #endregion } else { #region 物流 TryCloseOrder(orderMaster); #endregion } } #endregion return receiptMaster; }
private void MatchIpDetailInput(IpDetail ipDetail, IpDetailInput ipDetailInput, IList<IpLocationDetail> ipLocationDetailList, ref IpDetail gapIpDetail) { decimal remainQty = ipDetailInput.ReceiveQty * ipDetail.UnitQty; //转为库存单位 foreach (IpLocationDetail ipLocationDetail in ipLocationDetailList) { if (ipLocationDetail.IsClose) { continue; } //iplocationdet只可能为正数 if (ipLocationDetail.RemainReceiveQty >= remainQty) { //收货明细匹配完 #region 添加收货记录和IpLocationDetail的映射关系 IpLocationDetail receivedIpLocationDetail = Mapper.Map<IpLocationDetail, IpLocationDetail>(ipLocationDetail); receivedIpLocationDetail.ReceivedQty = remainQty; ipDetailInput.AddReceivedIpLocationDetail(receivedIpLocationDetail); #endregion ipLocationDetail.ReceivedQty += remainQty; remainQty = 0; if (ipLocationDetail.Qty == ipLocationDetail.ReceivedQty) { ipLocationDetail.IsClose = true; } } else { //收货明细未匹配完 #region 添加收货记录和IpLocationDetail的映射关系 IpLocationDetail receivedIpLocationDetail = Mapper.Map<IpLocationDetail, IpLocationDetail>(ipLocationDetail); receivedIpLocationDetail.ReceivedQty = ipLocationDetail.RemainReceiveQty; ipDetailInput.AddReceivedIpLocationDetail(receivedIpLocationDetail); #endregion remainQty -= ipLocationDetail.RemainReceiveQty; ipLocationDetail.ReceivedQty = ipLocationDetail.Qty; ipLocationDetail.IsClose = true; } //更新 if (ipLocationDetail.Id > 0) { genericMgr.Update(ipLocationDetail); } if (remainQty == 0) { //匹配完,跳出循环 break; } } //超收,还有未匹配完的数量 if (remainQty > 0) { #region 记录差异 if (gapIpDetail == null || !gapIpDetail.GapIpDetailId.HasValue) { gapIpDetail = Mapper.Map<IpDetail, IpDetail>(ipDetail); gapIpDetail.Type = com.Sconit.CodeMaster.IpDetailType.Gap; gapIpDetail.GapReceiptNo = string.Empty; gapIpDetail.ReceivedQty = 0; gapIpDetail.IsClose = false; gapIpDetail.GapIpDetailId = ipDetail.Id; } gapIpDetail.Qty += -(remainQty / ipDetail.UnitQty); //多收,数量为负,转为订单单位 IpLocationDetail gapIpLocationDetail = new IpLocationDetail(); gapIpLocationDetail.IpNo = ipDetail.IpNo; gapIpLocationDetail.OrderType = ipDetail.OrderType; gapIpLocationDetail.OrderDetailId = ipDetail.OrderDetailId; gapIpLocationDetail.Item = ipDetail.Item; gapIpLocationDetail.HuId = null; //收货未匹配产生的差异全部为数量(除了条码匹配条码) gapIpLocationDetail.LotNo = null; gapIpLocationDetail.IsCreatePlanBill = false; gapIpLocationDetail.PlanBill = null; gapIpLocationDetail.ActingBill = null; gapIpLocationDetail.IsFreeze = false; gapIpLocationDetail.IsATP = false; //差异不能进行MRP运算 gapIpLocationDetail.QualityType = ipDetail.QualityType; gapIpLocationDetail.OccupyType = com.Sconit.CodeMaster.OccupyType.None; gapIpLocationDetail.OccupyReferenceNo = null; gapIpLocationDetail.Qty = -remainQty; //多收,产生负数的差异 gapIpLocationDetail.ReceivedQty = 0; gapIpLocationDetail.IsClose = false; gapIpDetail.AddIpLocationDetail(gapIpLocationDetail); #endregion } }
public JsonResult AdjustIpGap(string idStr, string qtyStr, com.Sconit.CodeMaster.IpGapAdjustOption gapAdjustOption) { try { IList<IpDetail> ipDetailList = new List<IpDetail>(); if (!string.IsNullOrEmpty(idStr)) { string[] idArray = idStr.Split(','); string[] qtyArray = qtyStr.Split(','); for (int i = 0; i < idArray.Count(); i++) { if (Convert.ToDecimal(qtyArray[i]) > 0) { IpDetail ipDetail = base.genericMgr.FindById<IpDetail>(Convert.ToInt32(idArray[i])); IpDetailInput input = new IpDetailInput(); input.ReceiveQty = Convert.ToDecimal(qtyArray[i]); ipDetail.AddIpDetailInput(input); ipDetailList.Add(ipDetail); } } } if (ipDetailList.Count() == 0) { throw new BusinessException("调整明细不能为空"); } orderMgr.AdjustIpGap(ipDetailList, gapAdjustOption); SaveSuccessMessage(Resources.ORD.IpMaster.IpMaster_AsnTemplate, ipDetailList[0].IpNo); return Json(new { IpNo = ipDetailList[0].IpNo }); } catch (BusinessException ex) { SaveBusinessExceptionMessage(ex); } catch (Exception ex) { SaveErrorMessage(ex); } return Json(null); }
public JsonResult ReceiveIpMaster(string idStr, string qtyStr, string externalIpNo, string ipNo) { try { if (string.IsNullOrWhiteSpace(externalIpNo)) { throw new BusinessException(Resources.EXT.ControllerLan.Con_ExternalOrderNumberCanNotBeEmpty); } if (!string.IsNullOrEmpty(ipNo)) { IpMaster ipMaster = genericMgr.FindById<IpMaster>(ipNo); ipMaster.ExternalIpNo = externalIpNo; genericMgr.Update(ipMaster); } IList<IpDetail> ipDetailList = new List<IpDetail>(); if (!string.IsNullOrEmpty(idStr)) { string[] idArray = idStr.Split(','); string[] qtyArray = qtyStr.Split(','); for (int i = 0; i < idArray.Count(); i++) { if (Convert.ToDecimal(qtyArray[i]) > 0) { IpDetail ipDetail = genericMgr.FindById<IpDetail>(Convert.ToInt32(idArray[i])); IpDetailInput input = new IpDetailInput(); input.ReceiveQty = Convert.ToDecimal(qtyArray[i]); ipDetail.AddIpDetailInput(input); ipDetailList.Add(ipDetail); } } } if (ipDetailList.Count() == 0) { throw new BusinessException(Resources.EXT.ControllerLan.Con_ReceiveDetailCanNotBeEmpty); } ReceiptMaster receiptMaster = orderMgr.ReceiveIp(ipDetailList); object obj = new { SuccessMessage = string.Format(Resources.ORD.IpMaster.IpMaster_Received, ipDetailList[0].IpNo, receiptMaster.ReceiptNo), SuccessData = ipDetailList[0].IpNo }; return Json(obj); } catch (BusinessException ex) { Response.TrySkipIisCustomErrors = true; Response.StatusCode = 500; Response.Write(ex.GetMessages()[0].GetMessageString()); return Json(null); } }
public IpMaster TransferPickList2Ip(PickListMaster pickListMaster) { #region 发货单头 IpMaster ipMaster = Mapper.Map<PickListMaster, IpMaster>(pickListMaster); ipMaster.IsShipScanHu = true; ipMaster.Status = CodeMaster.IpStatus.Submit; #endregion #region 发货单明细 IList<OrderMaster> orderMasterList = this.LoadOrderMasters(pickListMaster.OrderDetails.Select(det => det.OrderNo).ToArray()); foreach (OrderDetail orderDetail in pickListMaster.OrderDetails) { IList<PickListResult> pickListResultList = pickListMaster.PickListResults.Where(p => p.OrderDetailId == orderDetail.Id).ToList(); if (pickListResultList.Count > 0) { IpDetail ipDetail = Mapper.Map<OrderDetail, IpDetail>(orderDetail); ipDetail.Flow = orderMasterList.Where(mstr => mstr.OrderNo == orderDetail.OrderNo).Single().Flow; //ipDetail.EffectiveDate = orderMaster.EffectiveDate; PickListDetail pickListDetail = pickListMaster.PickListDetails.Where(p => p.OrderDetailId == orderDetail.Id).First(); ipDetail.IsInspect = pickListDetail.IsInspect; ipDetail.StartTime = pickListDetail.StartTime; ipDetail.WindowTime = pickListDetail.WindowTime; foreach (PickListResult pickListResult in pickListResultList) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ShipQty = pickListResult.Qty; ipDetailInput.HuId = pickListResult.HuId; ipDetailInput.LotNo = pickListResult.LotNo; ipDetailInput.OccupyType = CodeMaster.OccupyType.Pick; ipDetailInput.OccupyReferenceNo = pickListMaster.PickListNo; ipDetail.AddIpDetailInput(ipDetailInput); } ipMaster.AddIpDetail(ipDetail); } } #endregion return ipMaster; }
public IpMaster TransferReceipt2Ip(ReceiptMaster receiptMaster) { IpMaster ipMaster = Mapper.Map<ReceiptMaster, IpMaster>(receiptMaster); foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { IpDetail ipDetail = Mapper.Map<ReceiptDetail, IpDetail>(receiptDetail); foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ShipQty = receiptLocationDetail.Qty / receiptDetail.UnitQty; ipDetailInput.HuId = receiptLocationDetail.HuId; ipDetailInput.LotNo = receiptLocationDetail.LotNo; ipDetail.AddIpDetailInput(ipDetailInput); } ipMaster.AddIpDetail(ipDetail); } return ipMaster; }
public void CancelIp(IpMaster ipMaster, DateTime effectiveDate) { if (!Utility.SecurityHelper.HasPermission(ipMaster)) { //throw new BusinessException("没有此送货单{0}的操作权限。", ipMaster.IpNo); } #region 获取送货单库存明细 string selectIpLocationDetailStatement = "from IpLocationDetail where IpNo = ? and IsClose = ?"; IList<IpLocationDetail> ipLocationDetailList = this.genericMgr.FindAll<IpLocationDetail>(selectIpLocationDetailStatement, new object[] { ipMaster.IpNo, false }); #endregion #region 获取送货单明细 if (ipMaster.IpDetails == null) { string selectIpDetailStatement = "from IpDetail where IpNo = ? and IsClose = ?"; ipMaster.IpDetails = this.genericMgr.FindAll<IpDetail>(selectIpDetailStatement, new object[] { ipMaster.IpNo, false }); } #endregion #region 一点货都没有收的才能冲销 var recIpDetails = ipMaster.IpDetails.Count(i => i.ReceivedQty > 0); if (recIpDetails > 0) { throw new BusinessException("已收过货的送货单不能冲销。", ipMaster.IpNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.IpStatus, ((int)ipMaster.Status).ToString())); } #endregion #region 关闭送货单库存明细 foreach (IpLocationDetail ipLocationDetail in ipLocationDetailList) { ipLocationDetail.IsClose = true; this.genericMgr.Update(ipLocationDetail); } #endregion #region 关闭送货单明细 foreach (IpDetail ipDetail in ipMaster.IpDetails) { ipDetail.IsClose = true; this.genericMgr.Update(ipDetail); } #endregion #region 更新发货单状态 ipMaster.Status = com.Sconit.CodeMaster.IpStatus.Cancel; this.genericMgr.Update(ipMaster); #endregion #region 更新订单明细 if (ipMaster.OrderType != CodeMaster.OrderType.ScheduleLine) { #region 非计划协议 #region 获取订单明细 string selectOrderDetailDetailStatement = "from OrderDetail where Id in (select OrderDetailId from IpDetail where IpNo = ? and IsClose = ?)"; IList<OrderDetail> orderDetailList = this.genericMgr.FindAll<OrderDetail>(selectOrderDetailDetailStatement, new object[] { ipMaster.IpNo, false }); #endregion foreach (OrderDetail orderDetail in orderDetailList) { #region 更新订单数量 orderDetail.ShippedQty -= ipMaster.IpDetails.Where(det => det.OrderDetailId == orderDetail.Id).Sum(det => det.Qty); this.genericMgr.Update(orderDetail); #endregion } #endregion } else { #region 计划协议 BusinessException businessException = new BusinessException(); foreach (IpDetail ipDetail in ipMaster.IpDetails) { decimal remainQty = ipDetail.Qty; IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and ShipQty > RecQty order by EndDate desc", new object[] { ipDetail.ExternalOrderNo, ipDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm }); if (scheduleOrderDetailList != null && scheduleOrderDetailList.Count > 0) { foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { //更新订单的发货数 if (remainQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { remainQty -= (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty); scheduleOrderDetail.ShippedQty = scheduleOrderDetail.ReceivedQty; } else { scheduleOrderDetail.ShippedQty -= remainQty; remainQty = 0; break; } this.genericMgr.Update(scheduleOrderDetail); } } if (remainQty > 0) { businessException.AddMessage(Resources.ORD.IpMaster.Errors_ReceiveQtyExcceedOrderQty, ipMaster.IpNo, ipDetail.Item); } } #endregion } #endregion #region 退回排序单状态 if (!string.IsNullOrEmpty(ipMaster.SequenceNo)) { #region 更新排序单头 SequenceMaster sequenceMaster = this.genericMgr.FindById<SequenceMaster>(ipMaster.SequenceNo); sequenceMaster.Status = CodeMaster.SequenceStatus.Pack; sequenceMaster.ShipDate = null; sequenceMaster.ShipUserId = 0; sequenceMaster.ShipUserName = null; this.genericMgr.Update(sequenceMaster); #endregion } #endregion this.genericMgr.FlushSession(); #region 更新库存 委外/生产退回不更新库存 if (ipMaster.OrderType != CodeMaster.OrderType.SubContract && ipMaster.OrderType != CodeMaster.OrderType.Production) { foreach (IpDetail ipDetail in ipMaster.IpDetails) { ipDetail.IsVoid = true; //ipDetail.OrderSubType = com.Sconit.CodeMaster.OrderSubType.Return; var targetIpLocationDetail = from locDet in ipLocationDetailList where locDet.IpDetailId == ipDetail.Id select locDet; ipDetail.CurrentPartyFrom = ipMaster.PartyFrom; //为了记录库存事务 ipDetail.CurrentPartyFromName = ipMaster.PartyFromName; //为了记录库存事务 ipDetail.CurrentPartyTo = ipMaster.PartyTo; //为了记录库存事务 ipDetail.CurrentPartyToName = ipMaster.PartyToName; //为了记录库存事务 foreach (IpLocationDetail ipLocationDetail in targetIpLocationDetail) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.HuId = ipLocationDetail.HuId; ipDetailInput.ShipQty = -ipLocationDetail.Qty / ipDetail.UnitQty; //转为订单单位 ipDetailInput.LotNo = ipLocationDetail.LotNo; ipDetailInput.IsCreatePlanBill = ipLocationDetail.IsCreatePlanBill; ipDetailInput.IsConsignment = ipLocationDetail.IsConsignment; ipDetailInput.PlanBill = ipLocationDetail.PlanBill; ipDetailInput.ActingBill = ipLocationDetail.ActingBill; ipDetailInput.IsATP = ipLocationDetail.IsATP; ipDetailInput.IsFreeze = ipLocationDetail.IsFreeze; ipDetailInput.OccupyType = ipLocationDetail.OccupyType; ipDetailInput.OccupyReferenceNo = ipLocationDetail.OccupyReferenceNo; ipDetail.AddIpDetailInput(ipDetailInput); } #region 更新库存、记库存事务 this.locationDetailMgr.InventoryOut(ipDetail, effectiveDate); #endregion } } #endregion //string loc = systemMgr.GetEntityPreferenceValue(Entity.SYS.EntityPreference.CodeEnum.WMSAnjiRegion); //if (ipMaster.PartyTo.Equals(loc, StringComparison.OrdinalIgnoreCase)) //{ // //this.genericMgr.FlushSession(); // //AsyncRecourdMessageQueue(MethodNameType.CancelIp, ipMaster.IpNo); // this.CreateMessageQueue("CancelIp", ipMaster.IpNo); //} }
public JsonResult AdjustIpGap(string idStr, string qtyStr, com.Sconit.CodeMaster.IpGapAdjustOption gapAdjustOption) { try { IList<IpDetail> ipDetailList = new List<IpDetail>(); if (!string.IsNullOrEmpty(idStr)) { string[] idArray = idStr.Split(','); string[] qtyArray = qtyStr.Split(','); for (int i = 0; i < idArray.Count(); i++) { if (Convert.ToDecimal(qtyArray[i]) > 0) { IpDetail ipDetail = genericMgr.FindById<IpDetail>(Convert.ToInt32(idArray[i])); IpDetailInput input = new IpDetailInput(); input.ReceiveQty = Convert.ToDecimal(qtyArray[i]); ipDetail.AddIpDetailInput(input); ipDetailList.Add(ipDetail); } } } if (ipDetailList.Count() == 0) { throw new BusinessException(Resources.EXT.ControllerLan.Con_AdjustDetailCanNotBeEmpty); } orderMgr.AdjustIpGap(ipDetailList, gapAdjustOption); object obj = new { SuccessMessage = string.Format(Resources.ORD.IpMaster.IpMaster_AsnTemplate, ipDetailList[0].IpNo), SuccessData = ipDetailList[0].IpNo }; return Json(obj); } catch (BusinessException ex) { Response.TrySkipIisCustomErrors = true; Response.StatusCode = 500; Response.Write(ex.GetMessages()[0].GetMessageString()); return Json(null); } }
public IpMaster TransferOrder2Ip(IList<OrderMaster> orderMasterList) { #region 发货单头 IpMaster ipMaster = MergeOrderMaster2IpMaster(orderMasterList); string WMSNo = string.Empty; foreach (OrderMaster orderMaster in orderMasterList) { foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { if (orderDetail.OrderDetailInputs.Select(i => i.WMSIpNo).Distinct().Count() > 1) { throw new TechnicalException("WMS发货单号不一致。"); } if (string.IsNullOrWhiteSpace(WMSNo)) { WMSNo = orderDetail.OrderDetailInputs.First().WMSIpNo; } else if (WMSNo != orderDetail.OrderDetailInputs.First().WMSIpNo) { throw new TechnicalException("WMS发货单号不一致。"); } } } ipMaster.WMSNo = WMSNo; #endregion #region 发货单明细 foreach (OrderMaster orderMaster in orderMasterList) { if (orderMaster.Type != CodeMaster.OrderType.ScheduleLine) { #region 非计划协议 if (orderMaster.OrderDetails != null && orderMaster.OrderDetails.Count > 0) { foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { IpDetail ipDetail = Mapper.Map<OrderDetail, IpDetail>(orderDetail); ipDetail.Flow = orderMaster.Flow; #region 采购送货单明细需要合同号。 if (orderMaster.Type == CodeMaster.OrderType.Procurement || orderMaster.Type == CodeMaster.OrderType.ScheduleLine) { ipDetail.ExternalOrderNo = orderMaster.ExternalOrderNo; } #endregion //ipDetail.EffectiveDate = orderMaster.EffectiveDate; ipDetail.IsInspect = orderMaster.IsInspect && ipDetail.IsInspect; //头和明细都选择报验才报验 if (orderDetail.StartDate.HasValue) { ipDetail.StartTime = orderDetail.StartDate; } else { ipDetail.StartTime = orderMaster.StartTime; } if (orderDetail.EndDate.HasValue) { ipDetail.WindowTime = orderDetail.EndDate; } else { ipDetail.WindowTime = orderMaster.WindowTime; } foreach (OrderDetailInput orderDetailInput in orderDetail.OrderDetailInputs) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ShipQty = orderDetailInput.ShipQty; if (orderMaster.IsShipScanHu || orderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT) { ipDetailInput.HuId = orderDetailInput.HuId; ipDetailInput.LotNo = orderDetailInput.LotNo; } ipDetailInput.WMSIpSeq = orderDetailInput.WMSIpSeq; ipDetailInput.ManufactureParty = orderDetailInput.ManufactureParty; ipDetailInput.OccupyType = orderDetailInput.OccupyType; ipDetailInput.OccupyReferenceNo = orderDetailInput.OccupyReferenceNo; ipDetail.AddIpDetailInput(ipDetailInput); } ipMaster.AddIpDetail(ipDetail); } } #endregion } else { #region 计划协议 if (orderMaster.OrderDetails != null && orderMaster.OrderDetails.Count > 0) { var groupedOrderDetailList = from det in orderMaster.OrderDetails group det by new { Item = det.Item, EBELN = det.ExternalOrderNo, EBELP = det.ExternalSequence.Split('-')[0], } into gj select new { Item = gj.Key.Item, EBELN = gj.Key.EBELN, EBELP = gj.Key.EBELP, List = gj.ToList(), }; foreach (var groupdOrderDetail in groupedOrderDetailList) { OrderDetail orderDetail = groupdOrderDetail.List.First(); IpDetail ipDetail = Mapper.Map<OrderDetail, IpDetail>(orderDetail); ipDetail.Flow = orderMaster.Flow; ipDetail.ExternalOrderNo = groupdOrderDetail.EBELN; ipDetail.ExternalSequence = groupdOrderDetail.EBELP; //ipDetail.EffectiveDate = orderMaster.EffectiveDate; ipDetail.IsInspect = orderMaster.IsInspect && ipDetail.IsInspect; //头和明细都选择报验才报验 if (orderDetail.StartDate.HasValue) { ipDetail.StartTime = orderDetail.StartDate; } else { ipDetail.StartTime = orderMaster.StartTime; } if (orderDetail.EndDate.HasValue) { ipDetail.WindowTime = orderDetail.EndDate; } else { ipDetail.WindowTime = orderMaster.WindowTime; } foreach (OrderDetail eachOrderDetail in groupdOrderDetail.List) { foreach (OrderDetailInput orderDetailInput in eachOrderDetail.OrderDetailInputs) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ShipQty = orderDetailInput.ShipQty; if (orderMaster.IsShipScanHu || orderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT) { ipDetailInput.HuId = orderDetailInput.HuId; ipDetailInput.LotNo = orderDetailInput.LotNo; } ipDetailInput.WMSIpSeq = orderDetailInput.WMSIpSeq; ipDetailInput.ManufactureParty = orderDetailInput.ManufactureParty; ipDetailInput.OccupyType = orderDetailInput.OccupyType; ipDetailInput.OccupyReferenceNo = orderDetailInput.OccupyReferenceNo; ipDetail.AddIpDetailInput(ipDetailInput); } } //计划协议发货检验整包装 if (orderMaster.IsReceiveFulfillUC && ipDetail.ShipQtyInput % ipDetail.UnitCount != 0) { //不是整包装 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ShipQtyNotFulfillUnitCount, orderDetail.Item, orderDetail.UnitCount.ToString("0.##")); } ipMaster.AddIpDetail(ipDetail); } } #endregion } } #endregion return ipMaster; }
public IpMaster TransferSequenceMaster2Ip(SequenceMaster sequenceMaster) { #region 发货单头 IpMaster ipMaster = Mapper.Map<SequenceMaster, IpMaster>(sequenceMaster); ipMaster.IsShipScanHu = true; ipMaster.IsReceiveScanHu = true; ipMaster.IsReceiveExceed = false; ipMaster.IsReceiveFulfillUC = true; ipMaster.IsReceiveFifo = false; ipMaster.IsAsnUniqueReceive = true; ipMaster.CreateHuOption = CodeMaster.CreateHuOption.None; ipMaster.ReceiveGapTo = CodeMaster.ReceiveGapTo.RecordIpGap; ipMaster.Status = CodeMaster.IpStatus.Submit; ipMaster.WMSNo = sequenceMaster.WMSIpNo; #endregion #region 发货单明细 foreach (SequenceDetail sequenceDetail in sequenceMaster.SequenceDetails.OrderBy(s => s.Sequence)) { OrderDetail orderDetail = sequenceMaster.OrderDetails.Where(o => o.Id == sequenceDetail.OrderDetailId).Single(); IpDetail ipDetail = Mapper.Map<OrderDetail, IpDetail>(orderDetail); ipDetail.Flow = sequenceMaster.Flow; ipDetail.IsInspect = false; ipDetail.StartTime = sequenceDetail.StartTime; ipDetail.WindowTime = sequenceDetail.WindowTime; IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ShipQty = sequenceDetail.Qty / sequenceDetail.UnitQty; ipDetailInput.HuId = sequenceDetail.HuId; ipDetailInput.LotNo = sequenceDetail.LotNo; if (!string.IsNullOrWhiteSpace(ipDetailInput.HuId)) { ipDetailInput.OccupyType = CodeMaster.OccupyType.Sequence; ipDetailInput.OccupyReferenceNo = sequenceMaster.SequenceNo; } ipDetailInput.SequenceNo = sequenceDetail.SequenceNo; ipDetailInput.WMSIpSeq = sequenceDetail.WMSIpSeq; ipDetail.AddIpDetailInput(ipDetailInput); ipMaster.AddIpDetail(ipDetail); } #endregion return ipMaster; }
public void ReceiveWMSIpMaster(WMSDatFile wMSDatFile, DateTime effectiveDate) { try { LesINLog lesInLog = new LesINLog(); #region 获得orderdetail IList<OrderDetail> orderDetailList = new List<OrderDetail>(); OrderDetail orderDetail = this.genericMgr.FindById<OrderDetail>(Convert.ToInt32(wMSDatFile.WmsLine)); if (orderDetail.ReceiveLotSize == 1) { throw new BusinessException(string.Format("单号{0}中物料{1}明细行已经关闭,不能收货。", orderDetail.OrderNo, orderDetail.Item)); } //#region 订单头要配置成自动收货 //OrderMaster ordermaster = this.genericMgr.FindById<OrderMaster>(orderDetail.OrderNo); //if (!ordermaster.IsAutoReceive) //{ // throw new BusinessException(); //} //#endregion orderDetail.WmsFileID = wMSDatFile.WMSId; orderDetail.ManufactureParty = wMSDatFile.LIFNR; orderDetail.ExternalOrderNo = wMSDatFile.WMSId; //orderDetail.ExternalSequence = wMSDatFile.WBS;//项目代码 OrderDetailInput orderDetailInput = new OrderDetailInput(); orderDetailInput.ShipQty = wMSDatFile.CurrentReceiveQty; orderDetailInput.WMSIpNo = wMSDatFile.WMSId;//先记录WMSId号,目前安吉拣货单号只用在接口日志查询中 orderDetailInput.WMSIpSeq = wMSDatFile.HuId;//WMS行 orderDetailInput.MoveType = wMSDatFile.MoveType + wMSDatFile.SOBKZ;//移动类型 //只有311K才传寄售供应商,如果是411K也不传,防止两边库位结算方式设置不一致造成差异 if (wMSDatFile.SOBKZ.ToUpper() == "K" && wMSDatFile.MoveType == "311") orderDetailInput.ConsignmentParty = wMSDatFile.LIFNR;//厂商代码 orderDetail.AddOrderDetailInput(orderDetailInput); orderDetailList.Add(orderDetail); #endregion #region 调用发货 var ipMstr = this.ShipOrder(orderDetailList, effectiveDate); if (!ipMstr.IsAutoReceive) { foreach (IpDetail ipDetail in ipMstr.IpDetails) { if (ipDetail.IpDetailInputs != null && ipDetail.IpDetailInputs.Count > 0) { foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs) { ipDetailInput.ReceiveQty = ipDetailInput.ShipQty; } } else { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ReceiveQty = ipDetail.Qty; ipDetail.AddIpDetailInput(ipDetailInput); } } this.genericMgr.FlushSession(); ReceiveIp(ipMstr.IpDetails, effectiveDate); } //var ipDetList = base.genericMgr.FindAll<IpDetail>("from IpDetail as d where d.IpNo=?", ipMstr.IpNo); //if (ipDetList != null && ipDetList.Count > 0) //{ // lesInLog.Qty = ipDetList.FirstOrDefault().ReceivedQty; // lesInLog.QtyMark = true; //} lesInLog.Qty = wMSDatFile.CurrentReceiveQty; lesInLog.QtyMark = true; #endregion #region 新建Log记录 lesInLog.Type = "MB1B"; lesInLog.MoveType = wMSDatFile.MoveType + wMSDatFile.SOBKZ; lesInLog.Sequense = ""; lesInLog.WMSNo = wMSDatFile.WMSId; lesInLog.WMSLine = wMSDatFile.WmsLine; lesInLog.Item = wMSDatFile.Item; lesInLog.HandResult = "S"; lesInLog.FileName = wMSDatFile.FileName; lesInLog.HandTime = System.DateTime.Now; lesInLog.IsCreateDat = false; lesInLog.ASNNo = wMSDatFile.WmsNo; this.genericMgr.Create(lesInLog); #endregion #region 修改中间表 wMSDatFile.ReceiveTotal = wMSDatFile.ReceiveTotal + wMSDatFile.CurrentReceiveQty; this.genericMgr.Update(wMSDatFile); #endregion this.genericMgr.FlushSession(); } catch (BusinessException ex) { throw new BusinessException(ex.GetMessages()[0].GetMessageString()); } }
public void ManualCloseIp(IpMaster ipMaster) { #region 查找未关闭IpDetail IList<IpDetail> openIpDetailList = this.genericMgr.FindAll<IpDetail>( "from IpDetail where IpNo = ? and Type = ? and IsClose = ?", new Object[] { ipMaster.IpNo, CodeMaster.IpDetailType.Normal, false }); #endregion #region 记录未收货差异 if (openIpDetailList != null && openIpDetailList.Count > 0) { #region 查找未关闭ASN库存对象 string hql = string.Empty; IList<object> paras = new List<object>(); foreach (IpDetail ipDetail in openIpDetailList) { if (hql == string.Empty) { hql = "from IpLocationDetail where IsClose = 0 and IpDetailId in (?"; } else { hql += ", ?"; } paras.Add(ipDetail.Id); } hql += ")"; IList<IpLocationDetail> openIpLocationDetailList = this.genericMgr.FindAll<IpLocationDetail>(hql, paras.ToArray()); #endregion #region 生成未收货差异 IList<IpDetail> gapIpDetailList = new List<IpDetail>(); if (openIpDetailList != null && openIpDetailList.Count > 0) { foreach (IpDetail openIpDetail in openIpDetailList) { var targetOpenIpLocationDetailList = openIpLocationDetailList.Where(o => o.IpDetailId == openIpDetail.Id); IpDetail gapIpDetail = Mapper.Map<IpDetail, IpDetail>(openIpDetail); gapIpDetail.Type = com.Sconit.CodeMaster.IpDetailType.Gap; gapIpDetail.GapReceiptNo = string.Empty; //todo 记录产生差异的收货单号 gapIpDetail.Qty = targetOpenIpLocationDetailList.Sum(o => o.RemainReceiveQty / openIpDetail.UnitQty); gapIpDetail.ReceivedQty = 0; gapIpDetail.IsClose = false; gapIpDetail.GapIpDetailId = openIpDetail.Id; gapIpDetail.IpLocationDetails = (from locDet in targetOpenIpLocationDetailList select new IpLocationDetail { IpNo = locDet.IpNo, OrderType = locDet.OrderType, OrderDetailId = locDet.OrderDetailId, Item = locDet.Item, HuId = locDet.HuId, LotNo = locDet.LotNo, IsCreatePlanBill = locDet.IsCreatePlanBill, PlanBill = locDet.PlanBill, ActingBill = locDet.ActingBill, IsFreeze = locDet.IsFreeze, //IsATP = locDet.IsATP, IsATP = false, QualityType = locDet.QualityType, OccupyType = locDet.OccupyType, OccupyReferenceNo = locDet.OccupyReferenceNo, Qty = locDet.RemainReceiveQty, ReceivedQty = 0, IsClose = false }).ToList(); gapIpDetailList.Add(gapIpDetail); } } #endregion #region 关闭未收货ASN明细和库存明细 if (openIpDetailList != null && openIpDetailList.Count > 0) { foreach (IpDetail openIpDetail in openIpDetailList) { openIpDetail.IsClose = true; this.genericMgr.Update(openIpDetail); } } if (openIpLocationDetailList != null && openIpLocationDetailList.Count > 0) { foreach (IpLocationDetail openIpLocationDetail in openIpLocationDetailList) { openIpLocationDetail.IsClose = true; this.genericMgr.Update(openIpLocationDetail); } } //string batchupdateipdetailstatement = "update from ipdetail set isclose = true where ipno = ? and isclose = false"; //genericmgr.update(batchupdateipdetailstatement, ipmaster.ipno); //string batchUpdateIpLocationDetailStatement = "update from IpLocationDetail set IsClose = True where IpNo = ? and IsClose = False"; //genericMgr.Update(batchUpdateIpLocationDetailStatement, ipMaster.IpNo); #endregion #region 记录收货差异 if (gapIpDetailList != null && gapIpDetailList.Count > 0) { foreach (IpDetail gapIpDetail in gapIpDetailList) { // gapIpDetail.GapReceiptNo = receiptMaster.ReceiptNo; this.genericMgr.Create(gapIpDetail); foreach (IpLocationDetail gapIpLocationDetail in gapIpDetail.IpLocationDetails) { gapIpLocationDetail.IpDetailId = gapIpDetail.Id; this.genericMgr.Create(gapIpLocationDetail); } } } #endregion #region 关闭差异ASN,对于ASN多次收货的,手工关闭ASN默认按调整发货方库存处理 foreach (IpDetail gapIpDetail in gapIpDetailList) { gapIpDetail.IpDetailInputs = null; foreach (IpLocationDetail gapIpLocationDetail in gapIpDetail.IpLocationDetails) { IpDetailInput input = new IpDetailInput(); input.ReceiveQty = gapIpLocationDetail.Qty / gapIpDetail.UnitQty; //转为订单单位 input.HuId = gapIpLocationDetail.HuId; input.LotNo = gapIpLocationDetail.LotNo; gapIpDetail.AddIpDetailInput(input); } } this.AdjustIpGap(gapIpDetailList, CodeMaster.IpGapAdjustOption.GI); #endregion ipMaster.Status = com.Sconit.CodeMaster.IpStatus.Close; ipMaster.CloseDate = DateTime.Now; ipMaster.CloseUserId = SecurityContextHolder.Get().Id; ipMaster.CloseUserName = SecurityContextHolder.Get().FullName; this.genericMgr.Update(ipMaster); } else { ipMaster.Status = com.Sconit.CodeMaster.IpStatus.Close; ipMaster.CloseDate = DateTime.Now; ipMaster.CloseUserId = SecurityContextHolder.Get().Id; ipMaster.CloseUserName = SecurityContextHolder.Get().FullName; this.genericMgr.Update(ipMaster); } #endregion }
public ReceiptMaster ReceiveIp(IList<IpDetail> ipDetailList, bool isCheckKitTraceItem, DateTime effectiveDate) { #region 判断送货单是否合并收货 if ((from det in ipDetailList select det.IpNo).Distinct().Count() > 1) { throw new TechnicalException("送货单不能合并收货。"); } #endregion #region 判断是否全0发货 if (ipDetailList == null || ipDetailList.Count == 0) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveDetailIsEmpty); } IList<IpDetail> nonZeroIpDetailList = ipDetailList.Where(o => o.ReceiveQtyInput != 0).ToList(); if (nonZeroIpDetailList.Count == 0) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveDetailIsEmpty); } #endregion #region 查询送货单头对象 计划协议步允许超收 string ipNo = (from det in nonZeroIpDetailList select det.IpNo).Distinct().Single(); IpMaster ipMaster = this.genericMgr.FindById<IpMaster>(ipNo); ipMaster.IpDetails = nonZeroIpDetailList; if (ipMaster.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine) { if (ipMaster.IpDetails.Where(det => det.ReceiveQtyInput + det.ReceivedQty > det.Qty).Count() > 0) { var ipdet = ipMaster.IpDetails.Where(det => det.ReceiveQtyInput + det.ReceivedQty > det.Qty).First(); throw new BusinessException(string.Format("物料{0}本次收收货数{1}+已收货数{2}大于发货数{3}。", ipdet.Item, ipdet.ReceiveQtyInput.ToString("0.##"), ipdet.ReceivedQty.ToString("0.##"), ipdet.Qty.ToString("0.##"))); } } #endregion #region 查询订单头对象 IList<OrderMaster> orderMasterList = LoadOrderMasters((from det in nonZeroIpDetailList select det.OrderNo).Distinct().ToArray()); #endregion #region 获取收货订单类型 IList<com.Sconit.CodeMaster.OrderType> orderTypeList = (from orderMaster in orderMasterList group orderMaster by orderMaster.Type into result select result.Key).ToList(); if (orderTypeList.Count > 1) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_CannotMixOrderTypeReceive); } com.Sconit.CodeMaster.OrderType orderType = orderTypeList.First(); #endregion #region 查询订单明细对象 IList<OrderDetail> orderDetailList = LoadOrderDetails((from det in nonZeroIpDetailList where det.OrderDetailId.HasValue select det.OrderDetailId.Value).Distinct().ToArray()); #endregion #region 查询送货单库存对象 IList<IpLocationDetail> ipLocationDetailList = LoadIpLocationDetails((from det in nonZeroIpDetailList select det.Id).ToArray()); #endregion #region 循环检查发货明细 foreach (IpDetail ipDetail in nonZeroIpDetailList) { #region 整包装收货判断 if (ipMaster.IsReceiveFulfillUC) { //不合格品不作为收货数 if (ipDetail.ReceiveQtyInput % ipDetail.UnitCount != 0) { //不是整包装 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyNotFulfillUnitCount, ipDetail.Item, ipDetail.UnitCount.ToString()); } } #endregion #region 是否过量收货判断 if (orderType != CodeMaster.OrderType.ScheduleLine) { if (Math.Abs(ipDetail.ReceivedQty) >= Math.Abs(ipDetail.Qty)) { //送货单的收货数已经大于等于发货数 throw new BusinessException(Resources.ORD.IpMaster.Errors_ReceiveQtyExcceedOrderQty, ipMaster.IpNo, ipDetail.Item); } else if (!ipMaster.IsReceiveExceed && Math.Abs(ipDetail.ReceivedQty + ipDetail.ReceiveQtyInput) > Math.Abs(ipDetail.Qty)) { //送货单的收货数 + 本次收货数大于发货数 throw new BusinessException(Resources.ORD.IpMaster.Errors_ReceiveQtyExcceedOrderQty, ipMaster.IpNo, ipDetail.Item); } } #endregion #region 计划协议送货单即使设置asn多次收货,但对于每一行还是只能收一次货,否则安吉进行收货冲销会有问题 //2013-09-11 条码收货 可以每一行还多次收货 //if (orderType == CodeMaster.OrderType.ScheduleLine) //{ // if (ipDetail.ReceivedQty > 0) // throw new BusinessException("送货单{0}中计划协议号{1}行号{2}已经收过货物,不能再次收货", ipDetail.IpNo, ipDetail.ExternalOrderNo, ipDetail.ExternalSequence); //} #endregion #region 发货明细是否已经关闭 if (ipDetail.IsClose) { throw new BusinessException("送货单{0}零件{1}已经关闭,不能进行收货。", ipMaster.IpNo, ipDetail.Item); } #endregion //可能发货时计划协议反写未成功但仍可以发货,收货时计划协议反写成功 //但asn上没有更新到计划协议号和行号,且结算方式可能会错 if (orderType == CodeMaster.OrderType.Procurement) { if (string.IsNullOrWhiteSpace(ipDetail.ExternalOrderNo) || string.IsNullOrWhiteSpace(ipDetail.ExternalSequence)) { throw new BusinessException("采购送货单{0}物料号{1}的计划协议号或PO号不能为空。", ipDetail.IpNo, ipDetail.Item); } } #region 采购收货是否有价格单判断 //if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT // && !bool.Parse(entityPreference.Value)) //{ // if (orderDetail.UnitPrice == Decimal.Zero) // { // //重新查找一次价格 // PriceListDetail priceListDetail = priceListDetailMgrE.GetLastestPriceListDetail( // orderDetail.DefaultPriceList, // orderDetail.Item, // orderHead.StartTime, // orderHead.Currency, // orderDetail.Uom); // if (priceListDetail != null) // { // orderDetail.UnitPrice = priceListDetail.UnitPrice; // orderDetail.IsProvisionalEstimate = priceListDetail.IsProvisionalEstimate; // orderDetail.IsIncludeTax = priceListDetail.IsIncludeTax; // orderDetail.TaxCode = priceListDetail.TaxCode; // } // else // { // throw new BusinessErrorException("Order.Error.NoPriceListReceipt", orderDetail.Item.Code); // } // } //} #endregion } #endregion #region KIT单收货判断 //if (ipMaster.Type == CodeMaster.IpType.KIT) //{ // string anjiRegion = systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.WMSAnjiRegion); // if (ipMaster.PartyFrom != anjiRegion) // { // CheckKitIpDetail(ipMaster, isCheckKitTraceItem); // } //} #endregion #region 循环更新订单明细 if (orderType != CodeMaster.OrderType.ScheduleLine) { foreach (OrderDetail orderDetail in orderDetailList) { #region 采购收货是否有计划协议号或PO号 OrderMaster orderMaster = orderMasterList.Where(om => om.OrderNo == orderDetail.OrderNo).Single(); if (orderMaster.Type == com.Sconit.CodeMaster.OrderType.Procurement) { if (string.IsNullOrWhiteSpace(orderDetail.ExternalOrderNo) || string.IsNullOrWhiteSpace(orderDetail.ExternalSequence)) { throw new BusinessException("供应商直供要货单{0}物料号{1}的计划协议号或PO号不能为空。", orderDetail.OrderNo, orderDetail.Item); } } #endregion IList<IpDetail> targetIpDetailList = (from det in nonZeroIpDetailList where det.OrderDetailId == orderDetail.Id select det).ToList(); //更新订单的收货数 orderDetail.ReceivedQty += targetIpDetailList.Sum(det => det.ReceiveQtyInput); genericMgr.Update(orderDetail); } } else { //foreach (IpDetail ipDetail in nonZeroIpDetailList) //{ // decimal remainReceiveQty = ipDetail.ReceiveQtyInput; // IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq = ? and ScheduleType = ? and ShipQty > RecQty order by EndDate", // new object[] { ipDetail.ExternalOrderNo, ipDetail.ExternalSequence, CodeMaster.ScheduleType.Firm }); // if (scheduleOrderDetailList != null && scheduleOrderDetailList.Count > 0) // { // foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) // { // if (remainReceiveQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) // { // remainReceiveQty -= (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty); // scheduleOrderDetail.ReceivedQty = scheduleOrderDetail.ShippedQty; // } // else // { // scheduleOrderDetail.ReceivedQty += remainReceiveQty; // remainReceiveQty = 0; // break; // } // this.genericMgr.Update(scheduleOrderDetail); // } // } // if (remainReceiveQty > 0) // { // throw new BusinessException(Resources.ORD.IpMaster.Errors_ReceiveQtyExcceedOrderQty, ipMaster.IpNo, ipDetail.Item); // } //} } #endregion #region 循环IpDetail,处理超收差异 IList<IpDetail> gapIpDetailList = new List<IpDetail>(); foreach (IpDetail targetIpDetail in nonZeroIpDetailList) { #region 收货输入和送货单库存明细匹配 IList<IpLocationDetail> targetIpLocationDetailList = (from ipLocDet in ipLocationDetailList where ipLocDet.IpDetailId == targetIpDetail.Id select ipLocDet).OrderByDescending(d => d.IsConsignment).ToList(); //排序为了先匹配寄售的 bool isContainHu = targetIpLocationDetailList.Where(ipLocDet => !string.IsNullOrWhiteSpace(ipLocDet.HuId)).Count() > 0; if (ipMaster.IsReceiveScanHu) { #region 收货扫描条码 if (isContainHu) { #region 条码匹配条码 #region 匹配到的条码 IList<IpLocationDetail> matchedIpLocationDetailList = new List<IpLocationDetail>(); foreach (IpDetailInput ipDetailInput in targetIpDetail.IpDetailInputs) { IpLocationDetail matchedIpLocationDetail = targetIpLocationDetailList.Where(locDet => locDet.HuId == ipDetailInput.HuId).SingleOrDefault(); if (matchedIpLocationDetail != null) { ipDetailInput.AddReceivedIpLocationDetail(matchedIpLocationDetail); matchedIpLocationDetailList.Add(matchedIpLocationDetail); #region 更新库存状态 matchedIpLocationDetail.ReceivedQty = matchedIpLocationDetail.Qty; matchedIpLocationDetail.IsClose = true; genericMgr.Update(matchedIpLocationDetail); #endregion } } #endregion #region 未匹配到的条码,记录差异 var matchedHuIdList = matchedIpLocationDetailList.Select(locDet => locDet.HuId); var gapIpDetailInputList = targetIpDetail.IpDetailInputs.Where(input => !matchedHuIdList.Contains(input.HuId)); #region 记录差异 if (gapIpDetailInputList != null && gapIpDetailInputList.Count() > 0) { IpDetail gapIpDetail = Mapper.Map<IpDetail, IpDetail>(targetIpDetail); gapIpDetail.Type = com.Sconit.CodeMaster.IpDetailType.Gap; gapIpDetail.GapReceiptNo = string.Empty; //todo 记录产生差异的收货单号 //gapIpDetail.Qty = gapIpDetailInputList.Sum(gap => -gap.ReceiveQty / targetIpDetail.UnitQty); //多收的条码,数量为负,转为订单单位 gapIpDetail.Qty = gapIpDetailInputList.Sum(gap => -gap.ReceiveQty); //多收的条码,数量为负 gapIpDetail.ReceivedQty = 0; gapIpDetail.IsClose = false; gapIpDetail.GapIpDetailId = targetIpDetail.Id; gapIpDetail.IpLocationDetails = (from gap in gapIpDetailInputList select new IpLocationDetail { IpNo = ipMaster.IpNo, OrderType = targetIpDetail.OrderType, OrderDetailId = targetIpDetail.OrderDetailId, Item = targetIpDetail.Item, //HuId = gap.HuId, //多收的条码按数量记录差异 //LotNo = gap.LotNo, IsCreatePlanBill = false, PlanBill = null, ActingBill = null, IsFreeze = false, IsATP = false, //差异不能进行MRP运算 QualityType = targetIpDetail.QualityType, OccupyType = com.Sconit.CodeMaster.OccupyType.None, OccupyReferenceNo = null, Qty = -gap.ReceiveQty * gapIpDetail.UnitQty, //多收,产生负数的差异 ReceivedQty = 0, IsClose = false }).ToList(); gapIpDetailList.Add(gapIpDetail); } #endregion #endregion #endregion } else { #region 数量匹配条码 IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList); if (gapIpDetail != null) { gapIpDetailList.Add(gapIpDetail); } #endregion } #endregion } else { #region 收货不扫描条码 if (isContainHu) { #region 条码匹配数量 IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList); if (gapIpDetail != null) { gapIpDetailList.Add(gapIpDetail); } #endregion } else { #region 数量匹配数量 IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList); if (gapIpDetail != null) { gapIpDetailList.Add(gapIpDetail); } #endregion } #endregion } #endregion #region 更新IpDetail上的收货数 targetIpDetail.ReceivedQty += targetIpDetail.ReceiveQtyInput; if (targetIpLocationDetailList.Where(i => !i.IsClose).Count() == 0) { //只有所有的IpLocationDetail关闭才能关闭 targetIpDetail.IsClose = true; } genericMgr.Update(targetIpDetail); #endregion } #endregion #region 送货单一次性收货,未收货差异 if (ipMaster.IsAsnUniqueReceive) { #region 查找未关闭送货单明细 List<IpDetail> openIpDetailList = (from det in nonZeroIpDetailList where !det.IsClose select det).ToList(); #region 查询剩余的未关闭送货单明细 IList<IpDetail> exceptIpDetailList = LoadExceptIpDetails(ipMaster.IpNo, (nonZeroIpDetailList.Select(det => det.Id)).ToArray()); #endregion #region 合并未关闭送货单明细 if (exceptIpDetailList != null && exceptIpDetailList.Count > 0) { openIpDetailList.AddRange(exceptIpDetailList); } #endregion #endregion #region 查找未关闭送货单库存对象 List<IpLocationDetail> openIpLocationDetailList = (from det in ipLocationDetailList where !det.IsClose select det).ToList(); #region 查询剩余未关闭送货单库存对象 IList<IpLocationDetail> expectIpLocationDetailList = LoadExceptIpLocationDetails(ipMaster.IpNo, (nonZeroIpDetailList.Select(det => det.Id)).ToArray()); #endregion #region 合并未关闭送货单库存对象 if (expectIpLocationDetailList != null && expectIpLocationDetailList.Count > 0) { openIpLocationDetailList.AddRange(expectIpLocationDetailList); } #endregion #endregion #region 生成未收货差异 if (openIpDetailList != null && openIpDetailList.Count > 0) { foreach (IpDetail openIpDetail in openIpDetailList) { var targetOpenIpLocationDetailList = openIpLocationDetailList.Where(o => o.IpDetailId == openIpDetail.Id); IpDetail gapIpDetail = Mapper.Map<IpDetail, IpDetail>(openIpDetail); gapIpDetail.Type = com.Sconit.CodeMaster.IpDetailType.Gap; gapIpDetail.GapReceiptNo = string.Empty; //todo 记录产生差异的收货单号 gapIpDetail.Qty = targetOpenIpLocationDetailList.Sum(o => o.RemainReceiveQty / openIpDetail.UnitQty); gapIpDetail.ReceivedQty = 0; gapIpDetail.IsClose = false; gapIpDetail.GapIpDetailId = openIpDetail.Id; gapIpDetail.IpLocationDetails = (from locDet in targetOpenIpLocationDetailList select new IpLocationDetail { IpNo = locDet.IpNo, OrderType = locDet.OrderType, OrderDetailId = locDet.OrderDetailId, Item = locDet.Item, HuId = locDet.HuId, LotNo = locDet.LotNo, IsCreatePlanBill = locDet.IsCreatePlanBill, IsConsignment = locDet.IsConsignment, PlanBill = locDet.PlanBill, ActingBill = locDet.ActingBill, IsFreeze = locDet.IsFreeze, //IsATP = locDet.IsATP, IsATP = false, QualityType = locDet.QualityType, OccupyType = locDet.OccupyType, OccupyReferenceNo = locDet.OccupyReferenceNo, Qty = locDet.RemainReceiveQty, ReceivedQty = 0, IsClose = false }).ToList(); gapIpDetailList.Add(gapIpDetail); } } #endregion #region 关闭未收货送货单明细和库存明细 if (openIpDetailList != null && openIpDetailList.Count > 0) { foreach (IpDetail openIpDetail in openIpDetailList) { openIpDetail.IsClose = true; this.genericMgr.Update(openIpDetail); } } if (openIpLocationDetailList != null && openIpLocationDetailList.Count > 0) { foreach (IpLocationDetail openIpLocationDetail in openIpLocationDetailList) { openIpLocationDetail.IsClose = true; this.genericMgr.Update(openIpLocationDetail); } } //string batchupdateipdetailstatement = "update from ipdetail set isclose = true where ipno = ? and isclose = false"; //genericmgr.update(batchupdateipdetailstatement, ipmaster.ipno); //string batchUpdateIpLocationDetailStatement = "update from IpLocationDetail set IsClose = True where IpNo = ? and IsClose = False"; //genericMgr.Update(batchUpdateIpLocationDetailStatement, ipMaster.IpNo); #endregion } #endregion #region 发货确认 //if (!string.IsNullOrEmpty(ipMaster.SequenceNo) //ASN确认传给SAP的移动类型 // || ipMaster.IsCheckPartyToAuthority) //{ // ipMgr.ConfirmIpDetail(nonZeroIpDetailList.Select(s => s.Id).ToList()); //} #endregion #region 收货 ReceiptMaster receiptMaster = this.receiptMgr.TransferIp2Receipt(ipMaster); this.receiptMgr.CreateReceipt(receiptMaster, effectiveDate); #endregion #region 记录收货差异 if (gapIpDetailList != null && gapIpDetailList.Count > 0) { if (!string.IsNullOrWhiteSpace(ipMaster.SequenceNo)) { throw new BusinessException("排序单装箱单{0}的收货数和发货数不一致。", ipMaster.SequenceNo); } foreach (IpDetail gapIpDetail in gapIpDetailList) { gapIpDetail.GapReceiptNo = receiptMaster.ReceiptNo; this.genericMgr.Create(gapIpDetail); foreach (IpLocationDetail gapIpLocationDetail in gapIpDetail.IpLocationDetails) { gapIpLocationDetail.IpDetailId = gapIpDetail.Id; this.genericMgr.Create(gapIpLocationDetail); } } #region 调整发货方库存 if (ipMaster.ReceiveGapTo == CodeMaster.ReceiveGapTo.AdjectLocFromInv) { foreach (IpDetail gapIpDetail in gapIpDetailList) { gapIpDetail.IpDetailInputs = null; foreach (IpLocationDetail gapIpLocationDetail in gapIpDetail.IpLocationDetails) { IpDetailInput input = new IpDetailInput(); input.ReceiveQty = gapIpLocationDetail.Qty / gapIpDetail.UnitQty; //转为订单单位 input.HuId = gapIpLocationDetail.HuId; input.LotNo = gapIpLocationDetail.LotNo; gapIpDetail.AddIpDetailInput(input); } } this.AdjustIpGap(gapIpDetailList, CodeMaster.IpGapAdjustOption.GI); } #endregion } #endregion #region 更新送货单状态 ipMaster.Status = CodeMaster.IpStatus.InProcess; this.genericMgr.Update(ipMaster); #endregion #region 尝试关闭送货单 this.ipMgr.TryCloseIp(ipMaster); #endregion #region 尝试关闭订单 foreach (OrderMaster orderMaster in orderMasterList) { TryCloseOrder(orderMaster); } #endregion return receiptMaster; }
public IpMaster TransferOrder2Ip(IList<OrderMaster> orderMasterList) { #region 发货单头 IpMaster ipMaster = MergeOrderMaster2IpMaster(orderMasterList); string WMSNo = string.Empty; foreach (OrderMaster orderMaster in orderMasterList) { foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { if (orderDetail.OrderDetailInputs.Select(i => i.WMSIpNo).Distinct().Count() > 1) { throw new TechnicalException("WMS发货单号不一致。"); } if (string.IsNullOrWhiteSpace(WMSNo)) { WMSNo = orderDetail.OrderDetailInputs.First().WMSIpNo; } else if (WMSNo != orderDetail.OrderDetailInputs.First().WMSIpNo) { throw new TechnicalException("WMS发货单号不一致。"); } } } ipMaster.WMSNo = WMSNo; #endregion #region 发货单明细 foreach (OrderMaster orderMaster in orderMasterList) { if (orderMaster.Type != CodeMaster.OrderType.ScheduleLine) { #region 非计划协议 if (orderMaster.OrderDetails != null && orderMaster.OrderDetails.Count > 0) { foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { IpDetail ipDetail = Mapper.Map<OrderDetail, IpDetail>(orderDetail); ipDetail.Flow = orderMaster.Flow; //针对同一个订单明细转成送货单明细,其移动类型默认只有一个 //不支持如下情况:订单需求100,本次发货50,其中40个移动类型为311,还有10个为411k ipDetail.BWART = orderDetail.OrderDetailInputs[0].MoveType; #region 采购送货单明细需要合同号。 //if (orderMaster.Type == CodeMaster.OrderType.Procurement // || orderMaster.Type == CodeMaster.OrderType.ScheduleLine) //{ // ipDetail.ExternalOrderNo = orderMaster.ExternalOrderNo; //} ipDetail.ExternalOrderNo = orderDetail.ExternalOrderNo; ipDetail.ExternalSequence = orderDetail.ExternalSequence; #endregion //ipDetail.EffectiveDate = orderMaster.EffectiveDate; ipDetail.IsInspect = orderMaster.IsInspect && ipDetail.IsInspect; //头和明细都选择报验才报验 if (orderDetail.StartDate.HasValue) { ipDetail.StartTime = orderDetail.StartDate; } else { ipDetail.StartTime = orderMaster.StartTime; } if (orderDetail.EndDate.HasValue) { ipDetail.WindowTime = orderDetail.EndDate; } else { ipDetail.WindowTime = orderMaster.WindowTime; } foreach (OrderDetailInput orderDetailInput in orderDetail.OrderDetailInputs) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ShipQty = orderDetailInput.ShipQty; if (orderMaster.IsShipScanHu) { ipDetailInput.HuId = orderDetailInput.HuId; ipDetailInput.LotNo = orderDetailInput.LotNo; } ipDetailInput.WMSIpSeq = orderDetailInput.WMSIpSeq; ipDetailInput.WMSRecNo = WMSNo;//把安吉的wmsId记录到收货单头的WMSNo字段 ipDetailInput.ConsignmentParty = orderDetailInput.ConsignmentParty; if (string.IsNullOrWhiteSpace(ipDetailInput.ConsignmentParty)) { //如果orderDetailInput没有指定寄售供应商,取orderDetail上的指定寄售供应商 ipDetailInput.ConsignmentParty = orderDetail.ICHARG; } ipDetailInput.OccupyType = orderDetailInput.OccupyType; ipDetailInput.OccupyReferenceNo = orderDetailInput.OccupyReferenceNo; ipDetail.AddIpDetailInput(ipDetailInput); } ipMaster.AddIpDetail(ipDetail); } } #endregion } else { #region 计划协议 if (orderMaster.OrderDetails != null && orderMaster.OrderDetails.Count > 0) { var groupedOrderDetailList = from det in orderMaster.OrderDetails group det by new { Item = det.Item, EBELN = det.ExternalOrderNo, EBELP = det.ExternalSequence.Split('-')[0], } into gj select new { Item = gj.Key.Item, EBELN = gj.Key.EBELN, EBELP = gj.Key.EBELP, List = gj.ToList(), }; foreach (var groupdOrderDetail in groupedOrderDetailList) { OrderDetail orderDetail = groupdOrderDetail.List.First(); IpDetail ipDetail = Mapper.Map<OrderDetail, IpDetail>(orderDetail); ipDetail.Flow = orderMaster.Flow; ipDetail.ExternalOrderNo = groupdOrderDetail.EBELN; ipDetail.ExternalSequence = groupdOrderDetail.EBELP; //记录sap采购类型 ipDetail.PSTYP = orderDetail.AUFNR; //ipDetail.EffectiveDate = orderMaster.EffectiveDate; ipDetail.IsInspect = orderMaster.IsInspect && ipDetail.IsInspect; //头和明细都选择报验才报验 if (orderDetail.StartDate.HasValue) { ipDetail.StartTime = orderDetail.StartDate; } else { ipDetail.StartTime = orderMaster.StartTime; } if (orderDetail.EndDate.HasValue) { ipDetail.WindowTime = orderDetail.EndDate; } else { ipDetail.WindowTime = orderMaster.WindowTime; } foreach (OrderDetail eachOrderDetail in groupdOrderDetail.List) { foreach (OrderDetailInput orderDetailInput in eachOrderDetail.OrderDetailInputs) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ShipQty = orderDetailInput.ShipQty; if (orderMaster.IsShipScanHu) { ipDetailInput.HuId = orderDetailInput.HuId; ipDetailInput.LotNo = orderDetailInput.LotNo; } ipDetailInput.WMSIpSeq = orderDetailInput.WMSIpSeq; ipDetailInput.WMSRecNo = WMSNo;//把安吉的wmsId记录到收货单头的WMSNo字段 ipDetailInput.ConsignmentParty = orderDetailInput.ConsignmentParty; if (string.IsNullOrWhiteSpace(ipDetailInput.ConsignmentParty)) { //如果orderDetailInput没有指定寄售供应商,取orderDetail上的指定寄售供应商 ipDetailInput.ConsignmentParty = eachOrderDetail.ICHARG; } ipDetailInput.OccupyType = orderDetailInput.OccupyType; ipDetailInput.OccupyReferenceNo = orderDetailInput.OccupyReferenceNo; ipDetail.AddIpDetailInput(ipDetailInput); } } //计划协议发货检验整包装 if (orderMaster.IsReceiveFulfillUC && ipDetail.ShipQtyInput % ipDetail.UnitCount != 0) { //不是整包装 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ShipQtyNotFulfillUnitCount, orderDetail.Item, orderDetail.UnitCount.ToString("0.##")); } ipMaster.AddIpDetail(ipDetail); } } #endregion } } #endregion return ipMaster; }
public JsonResult AdjustHuIpGap(string idStr, com.Sconit.CodeMaster.IpGapAdjustOption gapAdjustOption) { try { IList<IpDetail> ipDetailList = new List<IpDetail>(); if (!string.IsNullOrEmpty(idStr)) { string[] idArray = idStr.Split(','); for (int i = 0; i < idArray.Count(); i++) { IpLocationDetail ipLocationDetail = genericMgr.FindById<IpLocationDetail>(Convert.ToInt32(idArray[i])); var existIpDetail = ipDetailList.Where(d => d.Id == ipLocationDetail.IpDetailId).ToList(); if (existIpDetail != null && existIpDetail.Count > 0) { IpDetail ipDetail = existIpDetail[0]; IpDetailInput input = new IpDetailInput(); input.ReceiveQty = ipLocationDetail.Qty / existIpDetail[0].UnitQty; //转为订单单位 input.HuId = ipLocationDetail.HuId; input.LotNo = ipLocationDetail.LotNo; existIpDetail[0].AddIpDetailInput(input); } else { IpDetail ipDetail = genericMgr.FindById<IpDetail>(ipLocationDetail.IpDetailId); IpDetailInput input = new IpDetailInput(); input.ReceiveQty = ipLocationDetail.Qty / ipDetail.UnitQty; //转为订单单位 input.HuId = ipLocationDetail.HuId; input.LotNo = ipLocationDetail.LotNo; ipDetail.AddIpDetailInput(input); ipDetailList.Add(ipDetail); } } } if (ipDetailList.Count() == 0) { throw new BusinessException(Resources.EXT.ControllerLan.Con_AdjustDetailCanNotBeEmpty); } orderMgr.AdjustIpGap(ipDetailList, gapAdjustOption); object obj = new { SuccessMessage = string.Format(Resources.ORD.IpMaster.IpMaster_Adjusted, ipDetailList[0].IpNo), SuccessData = ipDetailList[0].IpNo }; return Json(obj); } catch (BusinessException ex) { Response.TrySkipIisCustomErrors = true; Response.StatusCode = 500; Response.Write(ex.GetMessages()[0].GetMessageString()); return Json(null); } }
//public IOrderMgr orderMgr { get; set; } #endregion public IpMaster TransferFlow2Ip(FlowMaster flowMaster, IList<OrderDetail> orderDetailList) { IpMaster ipMaster = Mapper.Map<FlowMaster, IpMaster>(flowMaster); ipMaster.OrderType = CodeMaster.OrderType.ScheduleLine; ipMaster.OrderSubType = CodeMaster.OrderSubType.Normal; ipMaster.QualityType = CodeMaster.QualityType.Qualified; ipMaster.Status = CodeMaster.IpStatus.Submit; #region 查找IpMaster相关对象 #region 查找Party string selectPartyStatement = "from Party where Code in (?"; IList<object> selectPartyPara = new List<object>(); selectPartyPara.Add(flowMaster.PartyFrom); if (flowMaster.PartyFrom != flowMaster.PartyTo) { selectPartyStatement += ", ?"; selectPartyPara.Add(flowMaster.PartyTo); } selectPartyStatement += ")"; IList<Party> partyList = this.genericMgr.FindAll<Party>(selectPartyStatement, selectPartyPara.ToArray()); #endregion #region 查找Location #region 收集所有Location代码 IList<string> locationCodeList = new List<string>(); if (!string.IsNullOrEmpty(flowMaster.LocationFrom)) { locationCodeList.Add(flowMaster.LocationFrom); } if (!string.IsNullOrEmpty(flowMaster.LocationTo)) { locationCodeList.Add(flowMaster.LocationTo); } if (flowMaster.FlowDetails != null) { foreach (string locationFromCode in flowMaster.FlowDetails.Where(d => !string.IsNullOrEmpty(d.LocationFrom)).Select(d => d.LocationFrom).Distinct()) { locationCodeList.Add(locationFromCode); } foreach (string locationToCode in flowMaster.FlowDetails.Where(d => !string.IsNullOrEmpty(d.LocationTo)).Select(d => d.LocationTo).Distinct()) { locationCodeList.Add(locationToCode); } } #endregion #region 查找Location IList<Location> locationList = null; if (locationCodeList.Count > 0) { string selectLocationStatement = string.Empty; IList<object> selectLocationPara = new List<object>(); foreach (string locationCode in locationCodeList.Distinct()) { if (selectLocationStatement == string.Empty) { selectLocationStatement = "from Location where Code in (?"; } else { selectLocationStatement += ",?"; } selectLocationPara.Add(locationCode); } selectLocationStatement += ")"; locationList = this.genericMgr.FindAll<Location>(selectLocationStatement, selectLocationPara.ToArray()); } #endregion #endregion #region 查找Address #region 收集所有地址代码 IList<string> addressCodeList = new List<string>(); if (!string.IsNullOrEmpty(flowMaster.ShipFrom)) { addressCodeList.Add(flowMaster.ShipFrom); } if (!string.IsNullOrEmpty(flowMaster.ShipTo)) { addressCodeList.Add(flowMaster.ShipTo); } if (flowMaster.FlowDetails != null) { foreach (string billAddress in flowMaster.FlowDetails.Where(d => !string.IsNullOrEmpty(d.BillAddress)).Select(d => d.BillAddress).Distinct()) { addressCodeList.Add(billAddress); } } #endregion #region 查找Address IList<Address> addressList = null; if (addressCodeList.Count > 0) { string selectAddressStatement = string.Empty; IList<object> selectAddressPara = new List<object>(); foreach (string addressCode in addressCodeList.Distinct()) { if (selectAddressStatement == string.Empty) { selectAddressStatement = "from Address where Code in (?"; } else { selectAddressStatement += ",?"; } selectAddressPara.Add(addressCode); } selectAddressStatement += ")"; addressList = this.genericMgr.FindAll<Address>(selectAddressStatement, selectAddressPara.ToArray()); } #endregion #endregion #endregion #region PartyFrom和PartyTo赋值 ipMaster.PartyFromName = partyList.Where(p => p.Code == ipMaster.PartyFrom).Single().Name; ipMaster.PartyToName = partyList.Where(p => p.Code == ipMaster.PartyTo).Single().Name; #endregion #region ShipFrom赋值 if (!string.IsNullOrEmpty(flowMaster.ShipFrom)) { Address shipFrom = addressList.Where(a => a.Code == flowMaster.ShipFrom).Single(); ipMaster.ShipFromAddress = shipFrom.AddressContent; ipMaster.ShipFromCell = shipFrom.MobilePhone; ipMaster.ShipFromTel = shipFrom.TelPhone; ipMaster.ShipFromFax = shipFrom.Fax; ipMaster.ShipFromContact = shipFrom.ContactPersonName; } #endregion #region ShipTo赋值 if (!string.IsNullOrEmpty(flowMaster.ShipTo)) { Address shipTo = addressList.Where(a => a.Code == flowMaster.ShipTo).Single(); ipMaster.ShipToAddress = shipTo.AddressContent; ipMaster.ShipToCell = shipTo.MobilePhone; ipMaster.ShipToTel = shipTo.TelPhone; ipMaster.ShipToFax = shipTo.Fax; ipMaster.ShipToContact = shipTo.ContactPersonName; } #endregion #region 状态 ipMaster.Status = com.Sconit.CodeMaster.IpStatus.Submit; #endregion #region 发出时间 ipMaster.DepartTime = DateTime.Now; #endregion #region 到达时间 ipMaster.ArriveTime = DateTime.Now; #endregion #region 发货单明细 foreach (OrderDetail orderDetail in orderDetailList) { OrderMaster orderMaster = orderDetail.CurrentOrderMaster; FlowDetail flowDetail = flowMaster.FlowDetails.Where(det => det.Item == orderDetail.Item).Single(); IpDetail ipDetail = Mapper.Map<FlowDetail, IpDetail>(flowDetail); ipDetail.Type = CodeMaster.IpDetailType.Normal; ipDetail.OrderNo = orderDetail.OrderNo; ipDetail.OrderType = orderDetail.OrderType; ipDetail.OrderSubType = orderDetail.OrderSubType; ipDetail.OrderDetailId = orderDetail.Id; ipDetail.OrderDetailSequence = orderDetail.Sequence; ipDetail.ItemDescription = orderDetail.ItemDescription; ipDetail.ReferenceItemCode = orderDetail.ReferenceItemCode; ipDetail.ExternalOrderNo = orderDetail.ExternalOrderNo; ipDetail.ExternalSequence = orderDetail.ExternalSequence; if (ipDetail.LocationFrom == null) { ipDetail.LocationFrom = flowMaster.LocationFrom; } if (ipDetail.LocationFrom != null) { ipDetail.LocationFromName = locationList.Where(l => l.Code == ipDetail.LocationFrom).Single().Name; } if (ipDetail.LocationTo == null) { ipDetail.LocationTo = flowMaster.LocationTo; } if (ipDetail.LocationTo != null) { ipDetail.LocationToName = locationList.Where(l => l.Code == ipDetail.LocationTo).Single().Name; } if (orderDetail.StartDate.HasValue) { ipDetail.StartTime = orderDetail.StartDate; } else { ipDetail.StartTime = orderMaster.StartTime; } if (orderDetail.EndDate.HasValue) { ipDetail.WindowTime = orderDetail.EndDate; } else { ipDetail.WindowTime = orderMaster.WindowTime; } ipDetail.Flow = flowMaster.Code; //记录sap采购类型 ipDetail.PSTYP = orderDetail.AUFNR; //ZC1:军车 ZC2:出口车 ZC3:特殊车 ZC5:CKD ipDetail.Tax = orderDetail.Tax; //ipDetail.EffectiveDate = orderMaster.EffectiveDate; ipDetail.IsInspect = orderMaster.IsInspect; ipDetail.UnitQty = orderDetail.UnitQty; //2013-9-22,单位换算出错,此处要去订单中的单位 ipDetail.Uom = orderDetail.Uom; ipDetail.BillTerm = orderDetail.BillTerm; ipDetail.BillAddress = orderDetail.BillAddress; //ASN确认发货的发货库位 ipDetail.Tax = flowDetail.ShipLocation; foreach (OrderDetailInput orderDetailInput in orderDetail.OrderDetailInputs) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ShipQty = orderDetailInput.ShipQty; ipDetailInput.WMSIpSeq = orderDetailInput.WMSIpSeq; ipDetailInput.ConsignmentParty = orderDetailInput.ConsignmentParty; if (string.IsNullOrWhiteSpace(ipDetailInput.ConsignmentParty)) { //如果orderDetailInput没有指定寄售供应商,取orderDetail上的指定寄售供应商 ipDetailInput.ConsignmentParty = orderDetail.ICHARG; } ipDetailInput.OccupyType = orderDetailInput.OccupyType; ipDetailInput.OccupyReferenceNo = orderDetailInput.OccupyReferenceNo; ipDetail.AddIpDetailInput(ipDetailInput); } //计划协议发货检验整包装 if (orderMaster.IsReceiveFulfillUC && ipDetail.ShipQtyInput % ipDetail.UnitCount != 0) { //不是整包装 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ShipQtyNotFulfillUnitCount, orderDetail.Item, orderDetail.UnitCount.ToString("0.##")); } ipMaster.AddIpDetail(ipDetail); } #endregion return ipMaster; }
public void CancelReceipt(ReceiptMaster receiptMaster, DateTime effectiveDate) { #region 判断收货单状态,只有Close才能冲销 if (receiptMaster.Status == CodeMaster.ReceiptStatus.Cancel) { throw new BusinessException("收货单{0}已经冲销。", receiptMaster.ReceiptNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.ReceiptStatus, ((int)receiptMaster.Status).ToString())); } #endregion #region 加载收货单明细及收货单库存明细 // TryLoadReceiptDetails(receiptMaster); IList<ReceiptLocationDetail> receiptLocationDetailList = TryLoadReceiptLocationDetails(receiptMaster); #endregion #region 加载订单头和明细 //GAP收货取消不用调整订单数据 IList<OrderMaster> orderMasterList = null; IList<OrderDetail> orderDetialList = null; //if (receiptMaster.Type == CodeMaster.IpDetailType.Normal) //{ #region 获取订单头 orderMasterList = LoadOrderMasters(receiptMaster.ReceiptDetails.Select(det => det.OrderNo).Distinct().ToArray()); #endregion #region 获取订单明细 orderDetialList = LoadOrderDetails(receiptMaster.ReceiptDetails.Where(det => det.OrderDetailId.HasValue).Select(det => det.OrderDetailId.Value).Distinct().ToArray()); #endregion //} #endregion //小数保留位数 int decimalLength = int.Parse(systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.DecimalLength)); #region 回滚送货单 if (!string.IsNullOrWhiteSpace(receiptMaster.IpNo)) { IpMaster ipMaster = this.genericMgr.FindById<IpMaster>(receiptMaster.IpNo); #region 查找送货单明细 string selectIpDetailStatement = string.Empty; IList<object> selectIpDetailPram = new List<object>(); foreach (int ipDetailId in receiptMaster.ReceiptDetails.Select(recDet => recDet.IpDetailId).Distinct()) { if (selectIpDetailStatement == string.Empty) { selectIpDetailStatement = "from IpDetail where Id in (?"; } else { selectIpDetailStatement += ",?"; } selectIpDetailPram.Add(ipDetailId); } selectIpDetailStatement += ")"; IList<IpDetail> ipDetailList = this.genericMgr.FindAll<IpDetail>(selectIpDetailStatement, selectIpDetailPram.ToArray()); #endregion #region 查找送货单库存明细 IList<IpLocationDetail> ipLocationDetailList = LoadIpLocationDetails(ipDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion #region 查找差异送货单明细 IList<IpDetail> gapIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where GapReceiptNo = ?", receiptMaster.ReceiptNo); #endregion #region 差异全部关闭 if (gapIpDetailList != null && gapIpDetailList.Count > 0) { #region 查找差异送货单库存明细 IList<IpLocationDetail> gapIpLocationDetailList = LoadIpLocationDetails(gapIpDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion foreach (IpDetail gapIpDetail in gapIpDetailList) { if (gapIpDetail.ReceivedQty != 0) { throw new BusinessException("收货单{0}的收货差异已经调整,不能冲销。", receiptMaster.ReceiptNo); } gapIpDetail.IsClose = true; this.genericMgr.Update(gapIpDetail); } foreach (IpLocationDetail gapIpLocationDetail in gapIpLocationDetailList) { gapIpLocationDetail.IsClose = true; this.genericMgr.Update(gapIpLocationDetail); } } #endregion #region 打开未收货的发货明细 //只有ASN一次性收货才打开未收货的发货明细 if (ipMaster.IsAsnUniqueReceive) { //只有正常收货才能打开未收货的发货明细。 int isGapRec = receiptMaster.ReceiptDetails.Where(recDet => recDet.IpDetailType == CodeMaster.IpDetailType.Gap).Count(); if (isGapRec == 0) { IList<IpDetail> unReceivedIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where IpNo = ? and Type = ?", new object[] { ipMaster.IpNo, CodeMaster.IpDetailType.Normal }); if (unReceivedIpDetailList != null && unReceivedIpDetailList.Count > 0) { #region 查找差异送货单库存明细 IList<IpLocationDetail> unReceivedIpLocationDetailList = LoadIpLocationDetails(unReceivedIpDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion foreach (IpDetail unReceivedIpDetail in unReceivedIpDetailList) { if (unReceivedIpDetail.IsClose) { unReceivedIpDetail.IsClose = false; this.genericMgr.Update(unReceivedIpDetail); } } foreach (IpLocationDetail unReceivedIpLocationDetail in unReceivedIpLocationDetailList) { if (unReceivedIpLocationDetail.IsClose) { unReceivedIpLocationDetail.IsClose = false; this.genericMgr.Update(unReceivedIpLocationDetail); } } } } } #endregion #region 收货库存明细和送货库存明细匹配 foreach (ReceiptLocationDetail receiptLocationDetail in receiptLocationDetailList) { ReceiptDetail receiptDetail = receiptMaster.ReceiptDetails.Where(recDet => recDet.Id == receiptLocationDetail.ReceiptDetailId).Single(); decimal remainBaseQty = receiptLocationDetail.Qty; //基本单位 decimal remainQty = receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位 if (!string.IsNullOrWhiteSpace(receiptLocationDetail.HuId) && ipLocationDetailList.Where(ipLocDet => !string.IsNullOrWhiteSpace(ipLocDet.HuId)).Count() > 0) { #region 条码和条码匹配 IpLocationDetail ipLocationDetail = ipLocationDetailList.Where(ipLocDet => ipLocDet.HuId == receiptLocationDetail.HuId).SingleOrDefault(); IpDetail ipDetail = ipDetailList.Where(ipDet => ipDet.Id == receiptDetail.IpDetailId).Single(); if (ipDetail.Id != receiptDetail.IpDetailId) { throw new TechnicalException("收货单明细和发货单明细ID不匹配。"); } if (ipDetail.Type != receiptDetail.IpDetailType) { throw new TechnicalException("收货单明细和发货单明细类型不匹配。"); } #region 扣减发货单的收货数 if (ipLocationDetail != null) { ipLocationDetail.ReceivedQty -= remainBaseQty; ipLocationDetail.IsClose = false; } ipDetail.ReceivedQty -= remainQty; //转为订单单位 ipDetail.IsClose = false; remainBaseQty = 0; remainQty = 0; #endregion if (ipLocationDetail != null) { this.genericMgr.Update(ipLocationDetail); } this.genericMgr.Update(ipDetail); #endregion } else { #region 按数量匹配 IList<IpDetail> thisIpDetailList = ipDetailList.Where(ipDet => ipDet.ReceivedQty != 0 //过滤掉已经扣完的明细 && ipDet.Id == receiptDetail.IpDetailId).ToList(); if (thisIpDetailList != null && thisIpDetailList.Count > 0) { IList<IpLocationDetail> thisIpLocationDetailList = null; foreach (IpDetail thisIpDetail in thisIpDetailList) { if (thisIpDetail.ReceivedQty > 0) { thisIpLocationDetailList = ipLocationDetailList.Where( ipLocDet => ipLocDet.ReceivedQty > 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList(); } else if (thisIpDetail.ReceivedQty < 0) { thisIpLocationDetailList = ipLocationDetailList.Where( ipLocDet => ipLocDet.ReceivedQty < 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList(); } if (thisIpLocationDetailList != null && thisIpLocationDetailList.Count > 0) { foreach (IpLocationDetail thisIpLocationDetail in thisIpLocationDetailList) { if (thisIpLocationDetail.ReceivedQty > remainBaseQty) { thisIpDetail.ReceivedQty -= remainQty; remainQty = 0; thisIpLocationDetail.ReceivedQty -= remainBaseQty; remainBaseQty = 0; thisIpDetail.IsClose = false; thisIpLocationDetail.IsClose = false; } else { decimal thisBackflushQty = thisIpLocationDetail.ReceivedQty / thisIpDetail.UnitQty; //转为订单单位 remainQty -= thisBackflushQty; thisIpDetail.ReceivedQty -= thisBackflushQty; remainBaseQty -= thisIpLocationDetail.ReceivedQty; thisIpLocationDetail.ReceivedQty = 0; thisIpDetail.IsClose = false; thisIpLocationDetail.IsClose = false; } this.genericMgr.Update(thisIpLocationDetail); this.genericMgr.Update(thisIpDetail); } } else { //throw new TechnicalException("差异送货单明细和送货单库存明细不匹配。"); } } } #endregion } if (remainBaseQty != 0) { throw new TechnicalException("收货单的收货数没有回冲完。"); } } #endregion #region 更新订单明细 if (receiptMaster.OrderType != CodeMaster.OrderType.ScheduleLine) { #region 非计划协议 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single(); if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal) { matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; if (matchedOrderDetial.ReceivedQty < 0) { throw new TechnicalException("订单收货数小于0。"); } } else { //差异收货冲销 #region 调整发货方库存 if (receiptMaster.PartyFrom == ipMaster.PartyTo) //发货方等于收货方 { //更新订单的发货数 matchedOrderDetial.ShippedQty += receiptDetail.ReceivedQty; } #endregion #region 调整收货方库存 else { //更新订单的收货数 matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; } #endregion } genericMgr.Update(matchedOrderDetial); } #endregion } else { foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { decimal receivedQty = receiptDetail.ReceivedQty; if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal) { #region 调整收货方库存 IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq = ? and ScheduleType = ? and RecQty > 0 order by EndDate desc", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence, CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty; scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty; } else { scheduleOrderDetail.ReceivedQty -= receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } #endregion } else { //差异收货冲销 #region 调整发货方库存 if (receiptMaster.PartyFrom == ipMaster.PartyTo) //发货方等于收货方 { IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq = ? and ScheduleType = ? and OrderQty > ShipQty order by EndDate", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence, CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty)) { receivedQty -= scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty; scheduleOrderDetail.ShippedQty = scheduleOrderDetail.OrderedQty; } else { scheduleOrderDetail.ShippedQty += receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } } #endregion #region 调整收货方库存 else { IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq = ? and ScheduleType = ? and RecQty > 0 order by EndDate desc", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence, CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty; scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty; } else { scheduleOrderDetail.ReceivedQty -= receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } } #endregion } } } #endregion #region 回滚送货单状态 //1. 普通状态的送货明细没有收过货 //2. 差异状态的送货明细全部关闭 if (ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Normal && ipDet.ReceivedQty != 0).Count() == 0 && ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Gap && !ipDet.IsClose).Count() == 0) { ipMaster.Status = CodeMaster.IpStatus.Submit; this.genericMgr.Update(ipMaster); } else if (ipMaster.Status != CodeMaster.IpStatus.InProcess) { ipMaster.Status = CodeMaster.IpStatus.InProcess; this.genericMgr.Update(ipMaster); } #endregion } else { #region 更新订单明细 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail != null) { OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single(); matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; matchedOrderDetial.ScrapQty -= receiptDetail.ScrapQty; if (matchedOrderDetial.OrderType != CodeMaster.OrderType.Production && matchedOrderDetial.OrderType != CodeMaster.OrderType.SubContract) { matchedOrderDetial.ShippedQty -= receiptDetail.ReceivedQty; if (matchedOrderDetial.ShippedQty < 0) { throw new TechnicalException("订单发货数小于0。"); } } if (matchedOrderDetial.ReceivedQty < 0) { throw new TechnicalException("订单收货数小于0。"); } this.genericMgr.Update(matchedOrderDetial); } } #endregion } #endregion #region 更新订单 foreach (OrderMaster orderMaster in orderMasterList) { if (orderMaster.Status != CodeMaster.OrderStatus.InProcess) { orderMaster.Status = CodeMaster.OrderStatus.InProcess; orderMaster.CloseDate = null; orderMaster.CloseUserId = null; orderMaster.CompleteUserName = null; this.genericMgr.Update(orderMaster); } } #endregion #region 更新收货单 receiptMaster.Status = CodeMaster.ReceiptStatus.Cancel; this.genericMgr.Update(receiptMaster); #endregion #region 冲销收货记录 List<IpDetail> cancelIpDetailList = new List<IpDetail>(); foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail.ReceivedQty != 0) { receiptDetail.CurrentPartyFrom = receiptMaster.PartyFrom; //为了记录库存事务 receiptDetail.CurrentPartyFromName = receiptMaster.PartyFromName; receiptDetail.CurrentPartyTo = receiptMaster.PartyTo; receiptDetail.CurrentPartyToName = receiptMaster.PartyToName; receiptDetail.CurrentExternalReceiptNo = receiptMaster.ExternalReceiptNo; receiptDetail.CurrentIsReceiveScanHu = receiptMaster.IsReceiveScanHu; receiptDetail.IsVoid = true; foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails) { ReceiptDetailInput receiptDetailInput = new ReceiptDetailInput(); receiptDetailInput.HuId = receiptLocationDetail.HuId; receiptDetailInput.ReceiveQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位 receiptDetailInput.LotNo = receiptLocationDetail.LotNo; receiptDetailInput.IsCreatePlanBill = receiptLocationDetail.IsCreatePlanBill; receiptDetailInput.IsConsignment = receiptLocationDetail.IsConsignment; receiptDetailInput.PlanBill = receiptLocationDetail.PlanBill; receiptDetailInput.ActingBill = receiptLocationDetail.ActingBill; receiptDetailInput.IsATP = receiptLocationDetail.IsATP; receiptDetailInput.IsFreeze = receiptLocationDetail.IsFreeze; receiptDetailInput.OccupyType = receiptLocationDetail.OccupyType; receiptDetailInput.OccupyReferenceNo = receiptLocationDetail.OccupyReferenceNo; receiptDetailInput.QualityType = receiptLocationDetail.QualityType; receiptDetail.AddReceiptDetailInput(receiptDetailInput); } #region 更新库存、记库存事务 IList<InventoryTransaction> rctInventoryTransactionList = this.locationDetailMgr.InventoryIn(receiptDetail, effectiveDate); #endregion #region 订单直接收货创建发货明细对象 if (string.IsNullOrWhiteSpace(receiptMaster.IpNo) && receiptMaster.Type != CodeMaster.IpDetailType.Gap && receiptMaster.OrderType != CodeMaster.OrderType.Production && receiptMaster.OrderType != CodeMaster.OrderType.SubContract) { IpDetail ipdetail = new IpDetail(); ipdetail.OrderNo = receiptDetail.OrderNo; ipdetail.OrderType = receiptDetail.OrderType; ipdetail.OrderSubType = receiptDetail.OrderSubType; ipdetail.OrderDetailId = receiptDetail.OrderDetailId; ipdetail.OrderDetailSequence = receiptDetail.OrderDetailSequence; ipdetail.Item = receiptDetail.Item; ipdetail.ItemDescription = receiptDetail.ItemDescription; ipdetail.ReferenceItemCode = receiptDetail.ReferenceItemCode; ipdetail.BaseUom = receiptDetail.BaseUom; ipdetail.Uom = receiptDetail.Uom; ipdetail.UnitCount = receiptDetail.UnitCount; //ipdetail.UnitCountDescription = receiptDetail.UnitCountDescription; //ipdetail.Container = receiptDetail.Container; //ipdetail.ContainerDescription = receiptDetail.ContainerDescription; ipdetail.QualityType = receiptDetail.QualityType; //ipdetail.ManufactureParty = receiptDetail.ManufactureParty; ipdetail.Qty = receiptDetail.ReceivedQty; //ipdetail.ReceivedQty = ipdetail.UnitQty = receiptDetail.UnitQty; ipdetail.LocationFrom = receiptDetail.LocationFrom; ipdetail.LocationFromName = receiptDetail.LocationFromName; ipdetail.LocationTo = receiptDetail.LocationTo; ipdetail.LocationToName = receiptDetail.LocationToName; ipdetail.IsInspect = false; //ipdetail.BillTerm = receiptDetail.BillTerm; ipdetail.IsVoid = true; cancelIpDetailList.Add(ipdetail); foreach (InventoryTransaction inventoryTransaction in rctInventoryTransactionList) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.HuId = inventoryTransaction.HuId; ipDetailInput.ShipQty = inventoryTransaction.Qty / ipdetail.UnitQty; ipDetailInput.LotNo = inventoryTransaction.LotNo; ipDetailInput.IsCreatePlanBill = inventoryTransaction.IsCreatePlanBill; if (inventoryTransaction.ActingBill.HasValue) { int planBill = this.genericMgr.FindAllWithNativeSql<Int32>("select PlanBill from BIL_ActBill where Id = ?", inventoryTransaction.ActingBill.Value).Single(); ipDetailInput.IsConsignment = true; ipDetailInput.PlanBill = planBill; ipDetailInput.ActingBill = null; } else { ipDetailInput.IsConsignment = inventoryTransaction.IsConsignment; ipDetailInput.PlanBill = inventoryTransaction.PlanBill; ipDetailInput.ActingBill = inventoryTransaction.ActingBill; } ipDetailInput.OccupyType = inventoryTransaction.OccupyType; ipDetailInput.OccupyReferenceNo = inventoryTransaction.OccupyReferenceNo; ipdetail.AddIpDetailInput(ipDetailInput); } } #endregion } #region 来源区域是LOC、SQC 的冲销后更新 读取安吉文件中间表的冲销数 if ((receiptMaster.PartyFrom == systemMgr.GetEntityPreferenceValue(Entity.SYS.EntityPreference.CodeEnum.WMSAnjiRegion) || receiptMaster.PartyFrom == "SQC") && receiptMaster.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal && !string.IsNullOrWhiteSpace(receiptDetail.ExternalOrderNo)) { var wmsDatfileById = this.genericMgr.FindAll<WMSDatFile>(" select w from WMSDatFile as w where w.WMSId=? ", receiptDetail.ExternalOrderNo, NHibernate.NHibernateUtil.String); if (wmsDatfileById != null && wmsDatfileById.Count > 0) { wmsDatfileById.First().CancelQty += receiptDetail.ReceivedQty; this.genericMgr.Update(wmsDatfileById.First()); } //this.genericMgr.UpdateWithNativeQuery(" update FIS_WMSDatFile set CancelQty=CancelQty+? where WMSId=? ",new object[]{ receiptDetail.ReceivedQty, receiptDetail.ExternalOrderNo},new IType[]{NHibernate.NHibernateUtil.Decimal,NHibernate.NHibernateUtil.String}); #region 冲销的写入中间表传给安吉 this.genericMgr.Create(new CancelReceiptMasterDAT { WMSNo = receiptDetail.ExternalOrderNo, WMSSeq = receiptDetail.OrderDetailId, ReceivedQty = receiptDetail.ReceivedQty, CreateDate = System.DateTime.Now }); #endregion } #endregion } #endregion #region 订单直接收货,冲销发货记录 if (cancelIpDetailList != null && cancelIpDetailList.Count > 0) { foreach (IpDetail cancelIpDetail in cancelIpDetailList) { cancelIpDetail.CurrentPartyFrom = receiptMaster.PartyFrom; //为了记录库存事务 cancelIpDetail.CurrentPartyFromName = receiptMaster.PartyFromName; //为了记录库存事务 cancelIpDetail.CurrentPartyTo = receiptMaster.PartyTo; //为了记录库存事务 cancelIpDetail.CurrentPartyToName = receiptMaster.PartyToName; //为了记录库存事务 this.locationDetailMgr.InventoryOut(cancelIpDetail); } } #endregion #region 生产单冲销退回原材料 //if (receiptMaster.OrderType == CodeMaster.OrderType.Production // || receiptMaster.OrderType == CodeMaster.OrderType.SubContract) //{ // DateTime dateTimeNow = DateTime.Now; // User currentUser = SecurityContextHolder.Get(); // IList<OrderBackflushDetail> orderBackflushDetailList = new List<OrderBackflushDetail>(); // FlowMaster productLine = this.genericMgr.FindById<FlowMaster>(receiptMaster.Flow); // foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) // { // OrderMaster orderMaster = orderMasterList.Where(mstr => mstr.OrderNo == receiptDetail.OrderNo).Single(); // OrderDetail orderDetail = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId).Single(); // IList<OrderBomDetail> orderBomDetailList = this.genericMgr.FindAll<OrderBomDetail>("from OrderBomDetail where OrderDetailId = ?", receiptDetail.OrderDetailId); // IList<BackflushInput> backflushInputList = (from bom in orderBomDetailList // where bom.OrderedQty != 0 // select new BackflushInput // { // OrderNo = orderMaster.OrderNo, // OrderType = orderMaster.Type, // OrderSubType = orderMaster.SubType, // OrderDetailSequence = orderDetail.Sequence, // OrderDetailId = orderDetail.Id, // OrderBomDetail = bom, // ReceiptNo = receiptMaster.ReceiptNo, // ReceiptDetailId = receiptDetail.Id, // ReceiptDetailSequence = receiptDetail.Sequence, // TraceCode = orderMaster.TraceCode, // Item = bom.Item, // ItemDescription = bom.ItemDescription, // ReferenceItemCode = bom.ReferenceItemCode, // Uom = bom.Uom, // BaseUom = bom.BaseUom, // Qty = bom.BomUnitQty * (receiptDetail.ReceivedQty + receiptDetail.ScrapQty), // UnitQty = bom.UnitQty, // Location = string.IsNullOrWhiteSpace(bom.Location) ? (string.IsNullOrWhiteSpace(orderDetail.LocationFrom) ? orderMaster.LocationFrom : orderDetail.LocationFrom) : bom.Location, // CurrentProductLine = productLine, // ProductLine = productLine.Code, // FGItem = orderDetail.Item, // FGQualityType = CodeMaster.QualityType.Qualified, // Operation = bom.Operation, // OpReference = bom.OpReference, // }).ToList(); // IList<InventoryTransaction> inventoryTransactionList = this.locationDetailMgr.CancelBackflushProductMaterial(backflushInputList, effectiveDate); // foreach (BackflushInput backflushInput in backflushInputList) // { // ((List<OrderBackflushDetail>)orderBackflushDetailList).AddRange(from trans in backflushInput.InventoryTransactionList // group trans by trans.PlanBill into g // select new OrderBackflushDetail // { // OrderNo = backflushInput.OrderNo, // OrderDetailId = backflushInput.OrderDetailId, // OrderDetailSequence = backflushInput.OrderDetailSequence, // OrderBomDetailId = backflushInput.OrderBomDetail.Id, // OrderBomDetailSequence = backflushInput.OrderBomDetail.Sequence, // ReceiptNo = backflushInput.ReceiptNo, // ReceiptDetailId = backflushInput.ReceiptDetailId, // ReceiptDetailSequence = backflushInput.ReceiptDetailSequence, // Bom = backflushInput.OrderBomDetail.Bom, // FGItem = backflushInput.FGItem, // Item = backflushInput.Item, // ItemDescription = backflushInput.ItemDescription, // ReferenceItemCode = backflushInput.ReferenceItemCode, // Uom = backflushInput.Uom, // BaseUom = backflushInput.BaseUom, // UnitQty = backflushInput.UnitQty, // ManufactureParty = backflushInput.OrderBomDetail.ManufactureParty, // TraceCode = backflushInput.TraceCode, // //HuId = result.Key.HuId, // //LotNo = result.Key.LotNo, // Operation = backflushInput.Operation, // OpReference = backflushInput.OpReference, // BackflushedQty = backflushInput.FGQualityType == CodeMaster.QualityType.Qualified ? g.Sum(trans => trans.Qty) / backflushInput.UnitQty : 0, //根据收货成品的质量状态记录至不同的回冲数量中 // BackflushedRejectQty = backflushInput.FGQualityType == CodeMaster.QualityType.Reject ? g.Sum(trans => trans.Qty) / backflushInput.UnitQty : 0, // //BackflushedScrapQty = input.BackflushedQty, // LocationFrom = backflushInput.OrderBomDetail.Location, // ProductLine = backflushInput.ProductLine, // ProductLineFacility = backflushInput.ProductLineFacility, // PlanBill = g.Key, // EffectiveDate = effectiveDate, // CreateUserId = currentUser.Id, // CreateUserName = currentUser.FullName, // CreateDate = dateTimeNow, // IsVoid = true, // ReserveNo = backflushInput.OrderBomDetail.ReserveNo, // ReserveLine = backflushInput.OrderBomDetail.ReserveLine, // AUFNR = backflushInput.OrderBomDetail.AUFNR, // ICHARG = backflushInput.OrderBomDetail.ICHARG, // BWART = (int.Parse(backflushInput.OrderBomDetail.BWART) + 1).ToString(), // }); // } // } // foreach (OrderBackflushDetail orderBackflushDetail in orderBackflushDetailList) // { // this.genericMgr.Create(orderBackflushDetail); // } //} #endregion }
public void CreateIp(IpMaster ipMaster, DateTime effectiveDate) { #region 发货明细不能为空 if (ipMaster.IpDetails == null || ipMaster.IpDetails.Count == 0) { throw new BusinessException(Resources.ORD.IpMaster.Errors_IpDetailIsEmpty); } #endregion #region 保存发货单头 ipMaster.IpNo = numberControlMgr.GetIpNo(ipMaster); ipMaster.EffectiveDate = effectiveDate; this.genericMgr.Create(ipMaster); #endregion //#region 按订单明细汇总发货数,按条码发货一条订单明细会对应多条发货记录 //var summaryIpDet = from det in ipMaster.IpDetails // group det by det.OrderDetailId into g // select new // { // OrderDetailId = g.Key, // List = g.ToList() // }; //#endregion #region 保存发货单明细 int seqCount = 1; foreach (IpDetail ipDetail in ipMaster.IpDetails.OrderBy(i => i.OrderNo).ThenBy(i => i.OrderDetailSequence)) { ipDetail.Qty = ipDetail.ShipQtyInput; ipDetail.Sequence = seqCount++; ipDetail.IpNo = ipMaster.IpNo; ipDetail.IsIncludeTax = ipMaster.IsCheckPartyFromAuthority; //ASN确认发货 if (ipDetail.IsIncludeTax && !string.IsNullOrWhiteSpace(ipMaster.SequenceNo)) { //todo创建传SAP的移动类型 } this.genericMgr.Create(ipDetail); } #endregion #region 发货创建条码 if ((ipMaster.OrderType == CodeMaster.OrderType.Procurement || ipMaster.OrderType == CodeMaster.OrderType.CustomerGoods) && ipMaster.CreateHuOption == CodeMaster.CreateHuOption.Ship) { foreach (IpDetail ipDetail in ipMaster.IpDetails) { IList<IpDetail> ipDetailList = new List<IpDetail>(); ipDetail.ManufactureParty = ipMaster.PartyFrom; ipDetail.HuQty = ipDetail.ShipQtyInput; ipDetail.LotNo = LotNoHelper.GenerateLotNo(); ipDetailList.Add(ipDetail); IList<Hu> huList = huMgr.CreateHu(ipMaster, ipDetailList); ipDetail.IpDetailInputs = (from hu in huList select new IpDetailInput { ShipQty = hu.Qty, //订单单位 HuId = hu.HuId, LotNo = hu.LotNo, IsCreatePlanBill = false, IsConsignment = false, PlanBill = null, ActingBill = null, IsFreeze = false, IsATP = true, OccupyType = com.Sconit.CodeMaster.OccupyType.None, OccupyReferenceNo = null }).ToList(); } } #endregion #region 销售出库的需要先检查库存(寄售+非寄售)是否满足,再非寄售数是否满足,不满足,否则拆分IpDetInput if (ipMaster.OrderType == CodeMaster.OrderType.Distribution) { foreach (var ipDetail in ipMaster.IpDetails) { var csIpDetailInputs = new List<IpDetailInput>(); foreach (var ipDetailInput in ipDetail.IpDetailInputs) { var locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetAvailableInventory", new Object[] { ipDetail.LocationFrom, ipDetail.Item }); if (ipDetailInput.ShipQty <= locationLotDetailList.Sum(o => o.Qty)) { //非寄售数 var nCSQty = locationLotDetailList.Where(o => o.IsConsignment == false).Sum(o => o.Qty); if (ipDetailInput.ShipQty > nCSQty) { //发货数大于非寄售数量的,需要根据先进先出取寄售库存 var csQty = ipDetailInput.ShipQty - nCSQty; foreach (var locationLotDetail in locationLotDetailList.Where(o => o.IsConsignment == true).OrderBy(o => o.LotNo).OrderBy(o => o.Qty)) { if (csQty - locationLotDetail.Qty > 0) { IpDetailInput csIpDetInput = new IpDetailInput(); //csIpDetInput = ipDetailInput; csIpDetInput.ShipQty = locationLotDetail.Qty; csIpDetInput.PlanBill = locationLotDetail.PlanBill; csIpDetInput.WMSIpSeq = ipDetailInput.WMSIpSeq; csIpDetInput.WMSRecNo = ipDetailInput.WMSRecNo; csIpDetInput.IsConsignment = true; csIpDetInput.OccupyType = ipDetailInput.OccupyType; csIpDetInput.OccupyReferenceNo = ipDetailInput.OccupyReferenceNo; csIpDetailInputs.Add(csIpDetInput); csQty = csQty - locationLotDetail.Qty; } else { IpDetailInput csIpDetInput = new IpDetailInput(); //csIpDetInput = ipDetailInput; csIpDetInput.ShipQty = csQty; csIpDetInput.PlanBill = locationLotDetail.PlanBill; csIpDetInput.WMSIpSeq = ipDetailInput.WMSIpSeq; csIpDetInput.WMSRecNo = ipDetailInput.WMSRecNo; csIpDetInput.IsConsignment = true; csIpDetInput.OccupyType = ipDetailInput.OccupyType; csIpDetInput.OccupyReferenceNo = ipDetailInput.OccupyReferenceNo; csIpDetailInputs.Add(csIpDetInput); break; } } //先发非寄售数量 ipDetailInput.ShipQty = nCSQty; } } else { throw new BusinessException(Resources.INV.LocationLotDetail.Errors_NotEnoughInventory, ipDetail.Item, ipDetail.LocationFrom); } } foreach (var csIpDetailInput in csIpDetailInputs) { ipDetail.IpDetailInputs.Add(csIpDetailInput); } //ipDetail.IpDetailInputs.ToList().AddRange(csIpDetailInputs); } } #endregion #region 出库 //条码上不带状态库位等信息,状态全部通过查找库存明细来获得。 //暂不支持发货创建条码 foreach (IpDetail ipDetail in ipMaster.IpDetails.OrderByDescending(det => det.ManufactureParty)) { ipDetail.CurrentPartyFrom = ipMaster.PartyFrom; //为了记录库存事务 ipDetail.CurrentPartyFromName = ipMaster.PartyFromName; //为了记录库存事务 ipDetail.CurrentPartyTo = ipMaster.PartyTo; //为了记录库存事务 ipDetail.CurrentPartyToName = ipMaster.PartyToName; //为了记录库存事务 //inputIpDetail.CurrentIsATP = inputIpDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified; //inputIpDetail.CurrentIsFreeze = false; //默认只出库未冻结库存 //ipDetail.CurrentOccupyType = com.Sconit.CodeMaster.OccupyType.None; //todo-默认出库未占用库存,除非拣货或检验的出库 IList<InventoryTransaction> inventoryTransactionList = this.locationDetailMgr.InventoryOut(ipDetail); if (inventoryTransactionList != null && inventoryTransactionList.Count > 0) { IList<IpLocationDetail> ipLocationDetailList = (from trans in inventoryTransactionList group trans by new { HuId = trans.HuId, LotNo = trans.LotNo, IsCreatePlanBill = trans.IsCreatePlanBill, IsConsignment = trans.IsConsignment, PlanBill = trans.PlanBill, ActingBill = trans.ActingBill, IsFreeze = trans.IsFreeze, IsATP = trans.IsATP, OccupyType = trans.OccupyType, OccupyReferenceNo = trans.OccupyReferenceNo, WMSSeq = trans.WMSIpSeq, } into g select new IpLocationDetail { Item = ipDetail.Item, HuId = g.Key.HuId, LotNo = g.Key.LotNo, IsCreatePlanBill = g.Key.IsCreatePlanBill, IsConsignment = g.Key.IsConsignment, PlanBill = g.Key.PlanBill, ActingBill = g.Key.ActingBill, QualityType = ipDetail.QualityType, IsFreeze = g.Key.IsFreeze, IsATP = g.Key.IsATP, OccupyType = g.Key.OccupyType == CodeMaster.OccupyType.Inspect ? g.Key.OccupyType : CodeMaster.OccupyType.None, //只有检验才保留占用状态 OccupyReferenceNo = g.Key.OccupyType == CodeMaster.OccupyType.Inspect ? g.Key.OccupyReferenceNo : null, Qty = g.Sum(t => -t.Qty), //出库的inventoryTrans为负数,转为ipLocationDetail需要为正数 WMSSeq = g.Key.WMSSeq, }).ToList(); ipDetail.AddIpLocationDetail(ipLocationDetailList); } } #endregion #region 保存发货单库存明细 foreach (IpDetail ipDetail in ipMaster.IpDetails) { //if (!string.IsNullOrWhiteSpace(ipDetail.LocationFrom)) //{ if (ipDetail.IpLocationDetails == null || ipDetail.IpLocationDetails.Count == 0) { throw new TechnicalException("IpLocationDetails is empty."); } foreach (IpLocationDetail ipLocationDetail in ipDetail.IpLocationDetails) { ipLocationDetail.IpNo = ipMaster.IpNo; ipLocationDetail.IpDetailId = ipDetail.Id; ipLocationDetail.OrderType = ipDetail.OrderType; ipLocationDetail.OrderDetailId = ipDetail.OrderDetailId; genericMgr.Create(ipLocationDetail); } //} } #endregion this.AsyncSendPrintData(ipMaster); }
private void RecordLocationTransaction(IpDetail ipDetail, IpDetailInput ipDetailInput, DateTime effectiveDate, com.Sconit.CodeMaster.TransactionType transType, IList<InventoryTransaction> inventoryTransactionList) { DateTime dateTimeNow = DateTime.Now; //根据PlanBill和ActingBill分组,为了不同供应商的库存事务分开 var groupedInventoryTransactionList = from trans in inventoryTransactionList group trans by new { IsConsignment = trans.IsConsignment, PlanBill = trans.PlanBill, ActingBill = trans.ActingBill } into result select new { IsConsignment = result.Key.IsConsignment, PlanBill = result.Key.PlanBill, ActingBill = result.Key.ActingBill, Qty = result.Sum(trans => trans.Qty), PlanBillQty = result.Sum(trans => trans.PlanBillQty), ActingBillQty = result.Sum(trans => trans.ActingBillQty), InventoryTransactionList = result.ToList() }; foreach (var groupedInventoryTransaction in groupedInventoryTransactionList) { LocationTransaction locationTransaction = new LocationTransaction(); locationTransaction.OrderNo = ipDetail.OrderNo; locationTransaction.OrderType = ipDetail.OrderType; locationTransaction.OrderSubType = ipDetail.OrderSubType; locationTransaction.OrderDetailSequence = ipDetail.OrderDetailSequence; locationTransaction.OrderDetailId = ipDetail.OrderDetailId.Value; //locationTransaction.OrderBomDetId = locationTransaction.IpNo = ipDetail.IpNo; locationTransaction.IpDetailId = ipDetail.Id; locationTransaction.IpDetailSequence = ipDetail.Sequence; locationTransaction.ReceiptNo = string.Empty; //locationTransaction.RecDetSeq = locationTransaction.SequenceNo = ipDetailInput.SequenceNo; //locationTransaction.TraceCode = locationTransaction.Item = ipDetail.Item; locationTransaction.Uom = ipDetail.Uom; locationTransaction.BaseUom = ipDetail.BaseUom; locationTransaction.Qty = groupedInventoryTransaction.Qty / ipDetail.UnitQty; locationTransaction.UnitQty = ipDetail.UnitQty; locationTransaction.IsConsignment = groupedInventoryTransaction.IsConsignment; if (groupedInventoryTransaction.IsConsignment && groupedInventoryTransaction.PlanBill.HasValue) { locationTransaction.PlanBill = groupedInventoryTransaction.PlanBill.Value; } locationTransaction.PlanBillQty = groupedInventoryTransaction.PlanBillQty / ipDetail.UnitQty; if (groupedInventoryTransaction.ActingBill.HasValue) { locationTransaction.ActingBill = groupedInventoryTransaction.ActingBill.Value; } locationTransaction.ActingBillQty = groupedInventoryTransaction.ActingBillQty / ipDetail.UnitQty; locationTransaction.QualityType = ipDetail.QualityType; locationTransaction.HuId = ipDetailInput.HuId; locationTransaction.LotNo = ipDetailInput.LotNo; locationTransaction.TransactionType = transType; locationTransaction.IOType = CodeMaster.TransactionIOType.Out; locationTransaction.PartyFrom = ipDetail.CurrentPartyFrom; locationTransaction.PartyTo = ipDetail.CurrentPartyTo; locationTransaction.LocationFrom = ipDetail.LocationFrom; locationTransaction.LocationTo = ipDetail.LocationTo; locationTransaction.LocationIOReason = string.Empty; locationTransaction.EffectiveDate = effectiveDate; locationTransaction.CreateUserId = SecurityContextHolder.Get().Id; locationTransaction.CreateDate = dateTimeNow; this.genericMgr.Create(locationTransaction); RecordLocationTransactionDetail(locationTransaction, groupedInventoryTransaction.InventoryTransactionList); } }
public void CancelReceipt(ReceiptMaster receiptMaster, DateTime effectiveDate) { if (!Utility.SecurityHelper.HasPermission(receiptMaster)) { //throw new BusinessException("没有此收货单{0}的操作权限。", receiptMaster.ReceiptNo); } #region 判断收货单状态,只有Close才能冲销 if (receiptMaster.Status == CodeMaster.ReceiptStatus.Cancel) { throw new BusinessException("收货单{0}已经冲销。", receiptMaster.ReceiptNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.ReceiptStatus, ((int)receiptMaster.Status).ToString())); } #endregion #region 加载收货单明细及收货单库存明细 // TryLoadReceiptDetails(receiptMaster); IList<ReceiptLocationDetail> receiptLocationDetailList = TryLoadReceiptLocationDetails(receiptMaster); #endregion #region 加载订单头和明细 //GAP收货取消不用调整订单数据 IList<OrderMaster> orderMasterList = null; IList<OrderDetail> orderDetialList = null; //if (receiptMaster.Type == CodeMaster.IpDetailType.Normal) //{ #region 获取订单头 orderMasterList = LoadOrderMasters(receiptMaster.ReceiptDetails.Select(det => det.OrderNo).Distinct().ToArray()); #endregion #region 获取订单明细 orderDetialList = LoadOrderDetails(receiptMaster.ReceiptDetails.Where(det => det.OrderDetailId.HasValue).Select(det => det.OrderDetailId.Value).Distinct().ToArray()); #endregion //} #endregion //小数保留位数 int decimalLength = int.Parse(systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.DecimalLength)); #region 回滚送货单 if (!string.IsNullOrWhiteSpace(receiptMaster.IpNo)) { IpMaster ipMaster = this.genericMgr.FindById<IpMaster>(receiptMaster.IpNo); #region 查找送货单明细 string selectIpDetailStatement = string.Empty; IList<object> selectIpDetailPram = new List<object>(); foreach (int ipDetailId in receiptMaster.ReceiptDetails.Select(recDet => recDet.IpDetailId).Distinct()) { if (selectIpDetailStatement == string.Empty) { selectIpDetailStatement = "from IpDetail where Id in (?"; } else { selectIpDetailStatement += ",?"; } selectIpDetailPram.Add(ipDetailId); } selectIpDetailStatement += ")"; IList<IpDetail> ipDetailList = this.genericMgr.FindAll<IpDetail>(selectIpDetailStatement, selectIpDetailPram.ToArray()); #endregion #region 查找送货单库存明细 IList<IpLocationDetail> ipLocationDetailList = LoadIpLocationDetails(ipDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion #region 查找差异送货单明细 IList<IpDetail> gapIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where GapReceiptNo = ?", receiptMaster.ReceiptNo); #endregion #region 差异全部关闭 if (gapIpDetailList != null && gapIpDetailList.Count > 0) { #region 查找差异送货单库存明细 IList<IpLocationDetail> gapIpLocationDetailList = LoadIpLocationDetails(gapIpDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion foreach (IpDetail gapIpDetail in gapIpDetailList) { if (gapIpDetail.ReceivedQty != 0) { throw new BusinessException("收货单{0}的收货差异已经调整,不能冲销。", receiptMaster.ReceiptNo); } gapIpDetail.IsClose = true; this.genericMgr.Update(gapIpDetail); } foreach (IpLocationDetail gapIpLocationDetail in gapIpLocationDetailList) { gapIpLocationDetail.IsClose = true; this.genericMgr.Update(gapIpLocationDetail); } } #endregion #region 打开未收货的发货明细 //只有正常收货才能打开未收货的发货明细。 int isGapRec = receiptMaster.ReceiptDetails.Where(recDet => recDet.IpDetailType == CodeMaster.IpDetailType.Gap).Count(); if (isGapRec == 0) { IList<IpDetail> unReceivedIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where IpNo = ? and Type = ?", new object[] { ipMaster.IpNo, CodeMaster.IpDetailType.Normal }); if (unReceivedIpDetailList != null && unReceivedIpDetailList.Count > 0) { #region 查找差异送货单库存明细 IList<IpLocationDetail> unReceivedIpLocationDetailList = LoadIpLocationDetails(unReceivedIpDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion foreach (IpDetail unReceivedIpDetail in unReceivedIpDetailList) { if (unReceivedIpDetail.IsClose && receiptMaster.ReceiptDetails.Select(p => p.IpDetailId).Contains(unReceivedIpDetail.Id)) { unReceivedIpDetail.IsClose = false; this.genericMgr.Update(unReceivedIpDetail); } } //foreach (IpLocationDetail unReceivedIpLocationDetail in unReceivedIpLocationDetailList) //{ // if (unReceivedIpLocationDetail.IsClose && receiptMaster.ReceiptDetails.Select(p => p.IpDetailId).Contains(unReceivedIpLocationDetail.IpDetailId)) // { // unReceivedIpLocationDetail.IsClose = false; // this.genericMgr.Update(unReceivedIpLocationDetail); // } //} } } #endregion #region 收货库存明细和送货库存明细匹配 foreach (ReceiptLocationDetail receiptLocationDetail in receiptLocationDetailList) { ReceiptDetail receiptDetail = receiptMaster.ReceiptDetails.Where(recDet => recDet.Id == receiptLocationDetail.ReceiptDetailId).Single(); decimal remainBaseQty = receiptLocationDetail.Qty; //基本单位 decimal remainQty = receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位 if (!string.IsNullOrWhiteSpace(receiptLocationDetail.HuId) && ipLocationDetailList.Where(ipLocDet => !string.IsNullOrWhiteSpace(ipLocDet.HuId)).Count() > 0) { #region 条码和条码匹配 IpLocationDetail ipLocationDetail = ipLocationDetailList.Where(ipLocDet => ipLocDet.HuId == receiptLocationDetail.HuId).SingleOrDefault(); IpDetail ipDetail = ipDetailList.Where(ipDet => ipDet.Id == receiptDetail.IpDetailId).Single(); if (ipDetail.Id != receiptDetail.IpDetailId) { throw new TechnicalException("收货单明细和发货单明细ID不匹配。"); } if (ipDetail.Type != receiptDetail.IpDetailType) { throw new TechnicalException("收货单明细和发货单明细类型不匹配。"); } #region 扣减发货单的收货数 if (ipLocationDetail != null) { ipLocationDetail.ReceivedQty -= remainBaseQty; ipLocationDetail.IsClose = false; } ipDetail.ReceivedQty -= remainQty; //转为订单单位 ipDetail.IsClose = false; remainBaseQty = 0; remainQty = 0; #endregion if (ipLocationDetail != null) { this.genericMgr.Update(ipLocationDetail); } this.genericMgr.Update(ipDetail); #endregion } else { #region 按数量匹配 IList<IpDetail> thisIpDetailList = ipDetailList.Where(ipDet => ipDet.ReceivedQty != 0 //过滤掉已经扣完的明细 && ipDet.Id == receiptDetail.IpDetailId).ToList(); if (thisIpDetailList != null && thisIpDetailList.Count > 0) { IList<IpLocationDetail> thisIpLocationDetailList = null; foreach (IpDetail thisIpDetail in thisIpDetailList) { if (thisIpDetail.ReceivedQty > 0) { thisIpLocationDetailList = ipLocationDetailList.Where( ipLocDet => ipLocDet.ReceivedQty > 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList(); } else if (thisIpDetail.ReceivedQty < 0) { thisIpLocationDetailList = ipLocationDetailList.Where( ipLocDet => ipLocDet.ReceivedQty < 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList(); } if (thisIpLocationDetailList != null && thisIpLocationDetailList.Count > 0) { foreach (IpLocationDetail thisIpLocationDetail in thisIpLocationDetailList) { if (thisIpLocationDetail.ReceivedQty > remainBaseQty) { //如果剩余冲销数量为0则不打开送货单 if (remainBaseQty != 0) { thisIpDetail.IsClose = false; thisIpLocationDetail.IsClose = false; } thisIpDetail.ReceivedQty -= remainQty; remainQty = 0; thisIpLocationDetail.ReceivedQty -= remainBaseQty; remainBaseQty = 0; } else { decimal thisBackflushQty = thisIpLocationDetail.ReceivedQty / thisIpDetail.UnitQty; //转为订单单位 remainQty -= thisBackflushQty; thisIpDetail.ReceivedQty -= thisBackflushQty; remainBaseQty -= thisIpLocationDetail.ReceivedQty; thisIpLocationDetail.ReceivedQty = 0; thisIpDetail.IsClose = false; thisIpLocationDetail.IsClose = false; } this.genericMgr.Update(thisIpLocationDetail); this.genericMgr.Update(thisIpDetail); } } else { //throw new TechnicalException("差异送货单明细和送货单库存明细不匹配。"); } } } #endregion } if (remainBaseQty != 0) { throw new TechnicalException("收货单的收货数没有回冲完。"); } } #endregion #region 更新订单明细 if (receiptMaster.OrderType != CodeMaster.OrderType.ScheduleLine) { #region 非计划协议 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single(); if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal) { matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; if (matchedOrderDetial.ReceivedQty < 0) { throw new TechnicalException("订单收货数小于0。"); } } else { //差异收货冲销 #region 调整发货方库存 if (receiptMaster.PartyFrom == ipMaster.PartyTo) //发货方等于收货方 { //更新订单的发货数 matchedOrderDetial.ShippedQty += receiptDetail.ReceivedQty; } #endregion #region 调整收货方库存 else { //更新订单的收货数 matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; } #endregion } genericMgr.Update(matchedOrderDetial); } #endregion } else { foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { decimal receivedQty = receiptDetail.ReceivedQty; if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal) { #region 调整收货方库存 IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and RecQty > 0 order by EndDate desc", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty; scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty; } else { scheduleOrderDetail.ReceivedQty -= receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } #endregion } else { //差异收货冲销 #region 调整发货方库存 if (receiptMaster.PartyFrom == ipMaster.PartyTo) //发货方等于收货方 { IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and OrderQty > ShipQty order by EndDate", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty)) { receivedQty -= scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty; scheduleOrderDetail.ShippedQty = scheduleOrderDetail.OrderedQty; } else { scheduleOrderDetail.ShippedQty += receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } } #endregion #region 调整收货方库存 else { IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and RecQty > 0 order by EndDate desc", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty; scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty; } else { scheduleOrderDetail.ReceivedQty -= receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } } #endregion } } } #endregion #region 回滚送货单状态 //1. 普通状态的送货明细没有收过货 //2. 差异状态的送货明细全部关闭 if (ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Normal && ipDet.ReceivedQty != 0).Count() == 0 && ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Gap && !ipDet.IsClose).Count() == 0) { ipMaster.Status = CodeMaster.IpStatus.Submit; this.genericMgr.Update(ipMaster); #region 回滚排序单状态 if (!string.IsNullOrWhiteSpace(ipMaster.SequenceNo)) { SequenceMaster sequenceMaster = this.genericMgr.FindById<SequenceMaster>(ipMaster.SequenceNo); sequenceMaster.Status = CodeMaster.SequenceStatus.Ship; this.genericMgr.Update(sequenceMaster); } #endregion } else if (ipMaster.Status != CodeMaster.IpStatus.InProcess) { ipMaster.Status = CodeMaster.IpStatus.InProcess; this.genericMgr.Update(ipMaster); } #endregion #region 退回排序单状态 if (!string.IsNullOrEmpty(ipMaster.SequenceNo)) { #region 更新排序单头 SequenceMaster sequenceMaster = this.genericMgr.FindById<SequenceMaster>(ipMaster.SequenceNo); sequenceMaster.Status = CodeMaster.SequenceStatus.Ship; sequenceMaster.CloseDate = null; sequenceMaster.CloseUserId = 0; sequenceMaster.CloseUserName = null; this.genericMgr.Update(sequenceMaster); #endregion foreach (SequenceDetail sequenceDetail in TryLoadSequenceDetails(sequenceMaster)) { //对于调整计划关闭的排序明细也有可能打开了,会有Bug if (orderDetialList.Select(i => i.Id).Contains(sequenceDetail.OrderDetailId)) { sequenceDetail.IsClose = false; this.genericMgr.Update(sequenceDetail); } } } #endregion } else { #region 更新订单明细 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail != null) { OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single(); matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; matchedOrderDetial.ScrapQty -= receiptDetail.ScrapQty; if (matchedOrderDetial.OrderType != CodeMaster.OrderType.Production && matchedOrderDetial.OrderType != CodeMaster.OrderType.SubContract) { matchedOrderDetial.ShippedQty -= receiptDetail.ReceivedQty; if (matchedOrderDetial.ShippedQty < 0) { throw new TechnicalException("订单发货数小于0。"); } } if (matchedOrderDetial.ReceivedQty < 0) { throw new TechnicalException("订单收货数小于0。"); } this.genericMgr.Update(matchedOrderDetial); } } #endregion } #endregion #region 更新订单 foreach (OrderMaster orderMaster in orderMasterList) { if (orderMaster.Status != CodeMaster.OrderStatus.InProcess) { orderMaster.Status = CodeMaster.OrderStatus.InProcess; orderMaster.CloseDate = null; orderMaster.CloseUserId = null; orderMaster.CloseUserName = null; this.genericMgr.Update(orderMaster); } } #endregion #region 更新收货单 receiptMaster.Status = CodeMaster.ReceiptStatus.Cancel; this.genericMgr.Update(receiptMaster); #endregion #region 冲销收货记录 List<IpDetail> cancelIpDetailList = new List<IpDetail>(); foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail.ReceivedQty != 0) { receiptDetail.CurrentPartyFrom = receiptMaster.PartyFrom; //为了记录库存事务 receiptDetail.CurrentPartyFromName = receiptMaster.PartyFromName; receiptDetail.CurrentPartyTo = receiptMaster.PartyTo; receiptDetail.CurrentPartyToName = receiptMaster.PartyToName; receiptDetail.CurrentExternalReceiptNo = receiptMaster.ExternalReceiptNo; receiptDetail.CurrentIsReceiveScanHu = receiptMaster.IsReceiveScanHu || orderMasterList.Where(o => o.OrderStrategy == CodeMaster.FlowStrategy.KIT).Count() > 0; receiptDetail.IsVoid = true; foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails) { ReceiptDetailInput receiptDetailInput = new ReceiptDetailInput(); receiptDetailInput.HuId = receiptLocationDetail.HuId; receiptDetailInput.ReceiveQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位 receiptDetailInput.LotNo = receiptLocationDetail.LotNo; receiptDetailInput.IsCreatePlanBill = receiptLocationDetail.IsCreatePlanBill; receiptDetailInput.IsConsignment = receiptLocationDetail.IsConsignment; receiptDetailInput.PlanBill = receiptLocationDetail.PlanBill; receiptDetailInput.ActingBill = receiptLocationDetail.ActingBill; receiptDetailInput.IsATP = receiptLocationDetail.IsATP; receiptDetailInput.IsFreeze = receiptLocationDetail.IsFreeze; receiptDetailInput.OccupyType = receiptLocationDetail.OccupyType; receiptDetailInput.OccupyReferenceNo = receiptLocationDetail.OccupyReferenceNo; receiptDetailInput.QualityType = receiptLocationDetail.QualityType; receiptDetail.AddReceiptDetailInput(receiptDetailInput); } #region 更新库存、记库存事务 IList<InventoryTransaction> rctInventoryTransactionList = this.locationDetailMgr.InventoryIn(receiptDetail, effectiveDate); #endregion #region 订单直接收货创建发货明细对象 if (!string.IsNullOrWhiteSpace(receiptMaster.IpNo)) { //nothing todo } else if (receiptMaster.Type == CodeMaster.IpDetailType.Gap) { //nothing todo } else if (receiptMaster.OrderType == CodeMaster.OrderType.Production) { //nothing todo } else if (receiptMaster.OrderType == CodeMaster.OrderType.SubContract && receiptMaster.OrderSubType == CodeMaster.OrderSubType.Normal) { //nothing todo } else //if (string.IsNullOrWhiteSpace(receiptMaster.IpNo) // && receiptMaster.Type != CodeMaster.IpDetailType.Gap // && receiptMaster.OrderType != CodeMaster.OrderType.Production // && (receiptMaster.OrderType != CodeMaster.OrderType.SubContract)) { IpDetail ipdetail = new IpDetail(); ipdetail.OrderNo = receiptDetail.OrderNo; ipdetail.OrderType = receiptDetail.OrderType; ipdetail.OrderSubType = receiptDetail.OrderSubType; ipdetail.OrderDetailId = receiptDetail.OrderDetailId; ipdetail.OrderDetailSequence = receiptDetail.OrderDetailSequence; ipdetail.Item = receiptDetail.Item; ipdetail.ItemDescription = receiptDetail.ItemDescription; ipdetail.ReferenceItemCode = receiptDetail.ReferenceItemCode; ipdetail.BaseUom = receiptDetail.BaseUom; ipdetail.Uom = receiptDetail.Uom; ipdetail.UnitCount = receiptDetail.UnitCount; //ipdetail.UnitCountDescription = receiptDetail.UnitCountDescription; //ipdetail.Container = receiptDetail.Container; //ipdetail.ContainerDescription = receiptDetail.ContainerDescription; ipdetail.QualityType = receiptDetail.QualityType; //ipdetail.ManufactureParty = receiptDetail.ManufactureParty; if ((ipdetail.OrderType == CodeMaster.OrderType.Procurement || ipdetail.OrderType == CodeMaster.OrderType.SubContract) && ipdetail.OrderSubType == CodeMaster.OrderSubType.Return) { //退货的订单需要入库y ipdetail.Qty = receiptDetail.ReceivedQty; } else { ipdetail.Qty = -receiptDetail.ReceivedQty; } //ipdetail.ReceivedQty = ipdetail.UnitQty = receiptDetail.UnitQty; ipdetail.LocationFrom = receiptDetail.LocationFrom; ipdetail.LocationFromName = receiptDetail.LocationFromName; ipdetail.LocationTo = receiptDetail.LocationTo; ipdetail.LocationToName = receiptDetail.LocationToName; ipdetail.IsInspect = false; //ipdetail.BillTerm = receiptDetail.BillTerm; ipdetail.IsVoid = true; cancelIpDetailList.Add(ipdetail); foreach (InventoryTransaction inventoryTransaction in rctInventoryTransactionList) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.HuId = inventoryTransaction.HuId; if ((ipdetail.OrderType == CodeMaster.OrderType.Procurement || ipdetail.OrderType == CodeMaster.OrderType.SubContract) && ipdetail.OrderSubType == CodeMaster.OrderSubType.Return) { ipDetailInput.ShipQty = -inventoryTransaction.Qty / ipdetail.UnitQty; } else { ipDetailInput.ShipQty = inventoryTransaction.Qty / ipdetail.UnitQty; } ipDetailInput.LotNo = inventoryTransaction.LotNo; ipDetailInput.IsCreatePlanBill = inventoryTransaction.IsCreatePlanBill; if (inventoryTransaction.ActingBill.HasValue) { int planBill = this.genericMgr.FindAllWithNativeSql<Int32>("select PlanBill from BIL_ActBill where Id = ?", inventoryTransaction.ActingBill.Value).Single(); ipDetailInput.IsConsignment = true; ipDetailInput.PlanBill = planBill; ipDetailInput.ActingBill = null; } else { ipDetailInput.IsConsignment = inventoryTransaction.IsConsignment; ipDetailInput.PlanBill = inventoryTransaction.PlanBill; ipDetailInput.ActingBill = inventoryTransaction.ActingBill; } ipDetailInput.OccupyType = inventoryTransaction.OccupyType; ipDetailInput.OccupyReferenceNo = inventoryTransaction.OccupyReferenceNo; ipdetail.AddIpDetailInput(ipDetailInput); } } #endregion } } #endregion #region 订单直接收货,冲销发货记录 if (cancelIpDetailList != null && cancelIpDetailList.Count > 0) { foreach (IpDetail cancelIpDetail in cancelIpDetailList) { cancelIpDetail.CurrentPartyFrom = receiptMaster.PartyFrom; //为了记录库存事务 cancelIpDetail.CurrentPartyFromName = receiptMaster.PartyFromName; //为了记录库存事务 cancelIpDetail.CurrentPartyTo = receiptMaster.PartyTo; //为了记录库存事务 cancelIpDetail.CurrentPartyToName = receiptMaster.PartyToName; //为了记录库存事务 this.locationDetailMgr.InventoryOut(cancelIpDetail); } } #endregion #region 生产单,委外冲销退回原材料 if (receiptMaster.OrderType == CodeMaster.OrderType.Production || receiptMaster.OrderType == CodeMaster.OrderType.SubContract) { var backflushInputList = ReceiptMaster2BackflushInputList(receiptMaster); locationDetailMgr.CancelBackflushProductMaterial(backflushInputList, effectiveDate); var orderBackflushDetailList = BackflushInputList2OrderBackflushDetailList(backflushInputList); DateTime dateTimeNow = DateTime.Now; User currentUser = SecurityContextHolder.Get(); foreach (OrderBackflushDetail orderBackflushDetail in orderBackflushDetailList) { orderBackflushDetail.EffectiveDate = effectiveDate; orderBackflushDetail.CreateUserId = currentUser.Id; orderBackflushDetail.CreateUserName = currentUser.FullName; orderBackflushDetail.CreateDate = dateTimeNow; orderBackflushDetail.IsVoid = true; this.genericMgr.Create(orderBackflushDetail); } } #endregion }
public void AddIpDetailInput(IpDetailInput ipDetailInput) { if (IpDetailInputs == null) { IpDetailInputs = new List<IpDetailInput>(); } IpDetailInputs.Add(ipDetailInput); }
public JsonResult AdjustHuIpGap(string idStr, com.Sconit.CodeMaster.IpGapAdjustOption gapAdjustOption) { try { IList<IpDetail> ipDetailList = new List<IpDetail>(); if (!string.IsNullOrEmpty(idStr)) { string[] idArray = idStr.Split(','); for (int i = 0; i < idArray.Count(); i++) { IpLocationDetail ipLocationDetail = base.genericMgr.FindById<IpLocationDetail>(Convert.ToInt32(idArray[i])); var existIpDetail = ipDetailList.Where(d => d.Id == ipLocationDetail.IpDetailId).ToList(); if (existIpDetail != null && existIpDetail.Count > 0) { IpDetail ipDetail = existIpDetail[0]; IpDetailInput input = new IpDetailInput(); input.ReceiveQty = ipLocationDetail.Qty / existIpDetail[0].UnitQty; //转为订单单位 input.HuId = ipLocationDetail.HuId; input.LotNo = ipLocationDetail.LotNo; existIpDetail[0].AddIpDetailInput(input); } else { IpDetail ipDetail = base.genericMgr.FindById<IpDetail>(ipLocationDetail.IpDetailId); IpDetailInput input = new IpDetailInput(); input.ReceiveQty = ipLocationDetail.Qty / ipDetail.UnitQty; //转为订单单位 input.HuId = ipLocationDetail.HuId; input.LotNo = ipLocationDetail.LotNo; ipDetail.AddIpDetailInput(input); ipDetailList.Add(ipDetail); } } } if (ipDetailList.Count() == 0) { throw new BusinessException("调整明细不能为空"); } orderMgr.AdjustIpGap(ipDetailList, gapAdjustOption); SaveSuccessMessage(Resources.ORD.IpMaster.IpMaster_Adjusted, ipDetailList[0].IpNo); return Json(new { IpNo = ipDetailList[0].IpNo }); } catch (BusinessException ex) { SaveBusinessExceptionMessage(ex); } catch (Exception ex) { SaveErrorMessage(ex); } return Json(null); }
public ActionResult ReceiveIpMaster(int[] id, decimal[] currentReceiveQty) { IList<IpDetail> ipDetailList = new List<IpDetail>(); for (int i = 0; i < currentReceiveQty.Count(); i++) { if (currentReceiveQty[i] > 0) { IpDetail ipDet = genericMgr.FindById<IpDetail>(id[i]); IpDetailInput input = new IpDetailInput(); input.ReceiveQty = currentReceiveQty[i]; ipDet.AddIpDetailInput(input); //校验还没发 ipDetailList.Add(ipDet); } } if (ipDetailList.Count() == 0) { return HttpNotFound(); } else { try { orderMgr.ReceiveIp(ipDetailList); SaveSuccessMessage(Resources.ORD.OrderMaster.OrderMaster_Received); return RedirectToAction("ReceiveIndex"); } catch (BusinessException ex) { SaveBusinessExceptionMessage(ex); return View(); } } }
public JsonResult ReceiveHuIpMaster(string idStr, string externalIpNo, string ipNo) { IList<IpDetail> ipDetailList = new List<IpDetail>(); try { if (!string.IsNullOrEmpty(ipNo)) { IpMaster ipMaster = genericMgr.FindById<IpMaster>(ipNo); ipMaster.ExternalIpNo = externalIpNo; genericMgr.Update(ipMaster); } if (!string.IsNullOrEmpty(idStr)) { string[] idArr = idStr.Split(','); foreach (string id in idArr) { IpLocationDetail ipLocationDetail = genericMgr.FindById<IpLocationDetail>(int.Parse(id)); IpDetail ipDetail = genericMgr.FindById<IpDetail>(ipLocationDetail.IpDetailId); IpDetailInput input = new IpDetailInput(); input.ReceiveQty = ipLocationDetail.Qty / ipDetail.UnitQty; //转为订单单位 ipDetail.AddIpDetailInput(input); ipDetailList.Add(ipDetail); } } if (ipDetailList.Count() == 0) { throw new BusinessException(Resources.EXT.ControllerLan.Con_ReceiveDetailCanNotBeEmpty); } ReceiptMaster receiptMaster = orderMgr.ReceiveIp(ipDetailList); object obj = new { SuccessMessage = string.Format(Resources.ORD.IpMaster.IpMaster_Received, ipDetailList[0].IpNo, receiptMaster.ReceiptNo), SuccessData = ipDetailList[0].IpNo }; return Json(obj); } catch (BusinessException ex) { Response.TrySkipIisCustomErrors = true; Response.StatusCode = 500; Response.Write(ex.GetMessages()[0].GetMessageString()); return Json(null); } }
public JsonResult ReceiveHuIpMaster(string idStr) { IList<IpDetail> ipDetailList = new List<IpDetail>(); try { if (!string.IsNullOrEmpty(idStr)) { string[] idArr = idStr.Split(','); foreach (string id in idArr) { IpLocationDetail ipLocationDetail = base.genericMgr.FindById<IpLocationDetail>(int.Parse(id)); IpDetail ipDetail = base.genericMgr.FindById<IpDetail>(ipLocationDetail.IpDetailId); IpDetailInput input = new IpDetailInput(); input.ReceiveQty = ipLocationDetail.Qty / ipDetail.UnitQty; //转为订单单位 ipDetail.AddIpDetailInput(input); ipDetailList.Add(ipDetail); } } if (ipDetailList.Count() == 0) { throw new BusinessException("收货明细不能为空"); } orderMgr.ReceiveIp(ipDetailList); SaveSuccessMessage(Resources.ORD.IpMaster.IpMaster_Received, ipDetailList[0].IpNo); return Json(new { IpNo = ipDetailList[0].IpNo }); } catch (BusinessException ex) { SaveBusinessExceptionMessage(ex); } catch (Exception ex) { SaveErrorMessage(ex); } return Json(null); }
public ReceiptMaster ReceiveIp(IList<IpDetail> ipDetailList, bool isCheckKitTraceItem, DateTime effectiveDate) { #region 判断送货单是否合并收货 if ((from det in ipDetailList select det.IpNo).Distinct().Count() > 1) { throw new TechnicalException("送货单不能合并收货。"); } #endregion #region 判断是否全0发货 if (ipDetailList == null || ipDetailList.Count == 0) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveDetailIsEmpty); } IList<IpDetail> nonZeroIpDetailList = ipDetailList.Where(o => o.ReceiveQtyInput != 0).ToList(); if (nonZeroIpDetailList.Count == 0) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveDetailIsEmpty); } #endregion #region 查询送货单头对象 string ipNo = (from det in nonZeroIpDetailList select det.IpNo).Distinct().Single(); IpMaster ipMaster = this.genericMgr.FindById<IpMaster>(ipNo); ipMaster.IpDetails = nonZeroIpDetailList; #endregion #region 查询订单头对象 IList<OrderMaster> orderMasterList = LoadOrderMasters((from det in nonZeroIpDetailList select det.OrderNo).Distinct().ToArray()); //foreach (var orderMaster in orderMasterList) //{ // if (!Utility.SecurityHelper.HasPermission(orderMaster)) // { // throw new BusinessException("没有此订单{0}的操作权限。", orderMaster.OrderNo); // } //} #endregion #region 获取收货订单类型 IList<com.Sconit.CodeMaster.OrderType> orderTypeList = (from orderMaster in orderMasterList group orderMaster by orderMaster.Type into result select result.Key).ToList(); if (orderTypeList.Count > 1) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_CannotMixOrderTypeReceive); } com.Sconit.CodeMaster.OrderType orderType = orderTypeList.First(); #endregion #region 排序单/KIT收货顺序判断 //没有考虑多个路线的排序单/Kit单同时发货 //var groupedSeqOrderMaster = from mstr in orderMasterList // where !string.IsNullOrWhiteSpace(mstr.Flow) // && (mstr.OrderStrategy == CodeMaster.FlowStrategy.KIT // || mstr.OrderStrategy == CodeMaster.FlowStrategy.SEQ) // group mstr by new { Flow = mstr.Flow, OrderStrategy = mstr.OrderStrategy } into result // select new // { // Flow = result.Key.Flow, // OrderStrategy = result.Key.OrderStrategy, // List = result.ToList() // }; //if (groupedSeqOrderMaster != null && groupedSeqOrderMaster.Count() > 0) //{ // BusinessException businessException = new BusinessException(); // foreach (var seqOrderMaster in groupedSeqOrderMaster) // { // OrderMaster biggestSeqOrderMaster = seqOrderMaster.List.OrderBy(o => o.Sequence).LastOrDefault(); // if (this.GetSpecifiedStatusOrderCount(biggestSeqOrderMaster, CodeMaster.OrderStatus.InProcess) //小与等于最大序号的待收货排序单/Kit单的总数,状态为InProcess // > seqOrderMaster.List.Count()) //当前待收货排序单/Kit单的总数 // { // if (biggestSeqOrderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT) // { // businessException.AddMessage("KIT路线{0}没有按顺序进行收货。", biggestSeqOrderMaster.Flow); // } // else // { // businessException.AddMessage("排序路线{0}没有按顺序进行收货。", biggestSeqOrderMaster.Flow); // } // } // } // if (businessException.HasMessage) // { // throw businessException; // } //} #endregion #region 查询订单明细对象 IList<OrderDetail> orderDetailList = LoadOrderDetails((from det in nonZeroIpDetailList where det.OrderDetailId.HasValue select det.OrderDetailId.Value).Distinct().ToArray()); #endregion #region 查询送货单库存对象 IList<IpLocationDetail> ipLocationDetailList = LoadIpLocationDetails((from det in nonZeroIpDetailList select det.Id).ToArray()); #endregion //FlowMaster flowMaster = null; //if (ipMaster.OrderType == CodeMaster.OrderType.Procurement) //{ // flowMaster = this.genericMgr.FindById<FlowMaster>(ipMaster.Flow); //} #region 循环检查发货明细 foreach (IpDetail ipDetail in nonZeroIpDetailList) { #region 整包装收货判断 if (ipMaster.IsReceiveFulfillUC) { //不合格品不作为收货数 if (ipDetail.ReceiveQtyInput % ipDetail.UnitCount != 0) { //不是整包装 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyNotFulfillUnitCount, ipDetail.Item, ipDetail.UnitCount.ToString()); } } #endregion #region 是否过量收货判断 if (orderType != CodeMaster.OrderType.ScheduleLine) { if (Math.Abs(ipDetail.ReceivedQty) >= Math.Abs(ipDetail.Qty)) { //送货单的收货数已经大于等于发货数 throw new BusinessException(Resources.ORD.IpMaster.Errors_ReceiveQtyExcceedOrderQty, ipMaster.IpNo, ipDetail.Item); } else if (!ipMaster.IsReceiveExceed && Math.Abs(ipDetail.ReceivedQty + ipDetail.ReceiveQtyInput) > Math.Abs(ipDetail.Qty)) { //送货单的收货数 + 本次收货数大于发货数 throw new BusinessException(Resources.ORD.IpMaster.Errors_ReceiveQtyExcceedOrderQty, ipMaster.IpNo, ipDetail.Item); } } #endregion #region 发货明细是否已经关闭 if (ipDetail.IsClose) { throw new BusinessException("送货单{0}零件{1}已经关闭,不能进行收货。", ipMaster.IpNo, ipDetail.Item); } #endregion #region 采购收货是否有价格单判断 //if (ipMaster.OrderType == CodeMaster.OrderType.Procurement) //{ // if (!flowMaster.IsAllowProvEstRec) // { // if (ipDetail.IsProvisionalEstimate || ipDetail.UnitPrice == 0M) // { // throw new BusinessException("此采购路线{0}不允许暂估价收货", ipMaster.Flow); // } // } //} //if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT // && !bool.Parse(entityPreference.Value)) //{ // if (orderDetail.UnitPrice == Decimal.Zero) // { // //重新查找一次价格 // PriceListDetail priceListDetail = priceListDetailMgrE.GetLastestPriceListDetail( // orderDetail.DefaultPriceList, // orderDetail.Item, // orderHead.StartTime, // orderHead.Currency, // orderDetail.Uom); // if (priceListDetail != null) // { // orderDetail.UnitPrice = priceListDetail.UnitPrice; // orderDetail.IsProvisionalEstimate = priceListDetail.IsProvisionalEstimate; // orderDetail.IsIncludeTax = priceListDetail.IsIncludeTax; // orderDetail.TaxCode = priceListDetail.TaxCode; // } // else // { // throw new BusinessErrorException("Order.Error.NoPriceListReceipt", orderDetail.Item.Code); // } // } //} #endregion } #endregion #region KIT单收货判断 //if (ipMaster.Type == CodeMaster.IpType.KIT) //{ // string anjiRegion = systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.WMSAnjiRegion); // if (ipMaster.PartyFrom != anjiRegion) // { // CheckKitIpDetail(ipMaster, isCheckKitTraceItem); // } //} #endregion #region 关闭排序装箱单 if (ipMaster.Type == CodeMaster.IpType.SEQ && !string.IsNullOrWhiteSpace(ipMaster.SequenceNo)) { SequenceMaster sequenceMaster = this.genericMgr.FindById<SequenceMaster>(ipMaster.SequenceNo); sequenceMaster.Status = CodeMaster.SequenceStatus.Close; sequenceMaster.CloseDate = DateTime.Now; sequenceMaster.CloseUserId = SecurityContextHolder.Get().Id; sequenceMaster.CloseUserName = SecurityContextHolder.Get().FullName; this.genericMgr.Update(sequenceMaster); foreach (SequenceDetail sequenceDetail in TryLoadSequenceDetails(sequenceMaster).Where(s => !s.IsClose)) { sequenceDetail.IsClose = true; this.genericMgr.Update(sequenceDetail); } } #endregion #region 循环更新订单明细 if (orderType == CodeMaster.OrderType.Production || orderType == CodeMaster.OrderType.SubContract) { //nothing todo } else if (orderType != CodeMaster.OrderType.ScheduleLine) { foreach (OrderDetail orderDetail in orderDetailList) { IList<IpDetail> targetIpDetailList = (from det in nonZeroIpDetailList where det.OrderDetailId == orderDetail.Id select det).ToList(); //更新订单的收货数 orderDetail.ReceivedQty += targetIpDetailList.Sum(det => det.ReceiveQtyInput); genericMgr.Update(orderDetail); } } else { foreach (IpDetail ipDetail in nonZeroIpDetailList) { decimal remainReceiveQty = ipDetail.ReceiveQtyInput; IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and ShipQty > RecQty order by EndDate", new object[] { ipDetail.ExternalOrderNo, ipDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm }); if (scheduleOrderDetailList != null && scheduleOrderDetailList.Count > 0) { foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (remainReceiveQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { remainReceiveQty -= (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty); scheduleOrderDetail.ReceivedQty = scheduleOrderDetail.ShippedQty; } else { scheduleOrderDetail.ReceivedQty += remainReceiveQty; remainReceiveQty = 0; break; } this.genericMgr.Update(scheduleOrderDetail); } } if (remainReceiveQty > 0) { throw new BusinessException(Resources.ORD.IpMaster.Errors_ReceiveQtyExcceedOrderQty, ipMaster.IpNo, ipDetail.Item); } } } #endregion #region 循环IpDetail,处理超收差异 IList<IpDetail> gapIpDetailList = new List<IpDetail>(); foreach (IpDetail targetIpDetail in nonZeroIpDetailList) { #region 收货输入和送货单库存明细匹配 IList<IpLocationDetail> targetIpLocationDetailList = (from ipLocDet in ipLocationDetailList where ipLocDet.IpDetailId == targetIpDetail.Id select ipLocDet).OrderByDescending(d => d.IsConsignment).ToList(); //排序为了先匹配寄售的 bool isContainHu = targetIpLocationDetailList.Where(ipLocDet => !string.IsNullOrWhiteSpace(ipLocDet.HuId)).Count() > 0; if (ipMaster.IsReceiveScanHu) { #region 收货扫描条码 if (isContainHu) { #region 条码匹配条码 #region 匹配到的条码 IList<IpLocationDetail> matchedIpLocationDetailList = new List<IpLocationDetail>(); foreach (IpDetailInput ipDetailInput in targetIpDetail.IpDetailInputs) { IpLocationDetail matchedIpLocationDetail = targetIpLocationDetailList.Where(locDet => locDet.HuId == ipDetailInput.HuId).SingleOrDefault(); if (matchedIpLocationDetail != null) { ipDetailInput.AddReceivedIpLocationDetail(matchedIpLocationDetail); matchedIpLocationDetailList.Add(matchedIpLocationDetail); #region 更新库存状态 matchedIpLocationDetail.ReceivedQty = matchedIpLocationDetail.Qty; matchedIpLocationDetail.IsClose = true; genericMgr.Update(matchedIpLocationDetail); #endregion } } #endregion #region 未匹配到的条码,记录差异 var matchedHuIdList = matchedIpLocationDetailList.Select(locDet => locDet.HuId); var gapIpDetailInputList = targetIpDetail.IpDetailInputs.Where(input => !matchedHuIdList.Contains(input.HuId)); #region 记录差异 if (gapIpDetailInputList != null && gapIpDetailInputList.Count() > 0) { IpDetail gapIpDetail = Mapper.Map<IpDetail, IpDetail>(targetIpDetail); gapIpDetail.Type = com.Sconit.CodeMaster.IpDetailType.Gap; gapIpDetail.GapReceiptNo = string.Empty; //todo 记录产生差异的收货单号 //gapIpDetail.Qty = gapIpDetailInputList.Sum(gap => -gap.ReceiveQty / targetIpDetail.UnitQty); //多收的条码,数量为负,转为订单单位 gapIpDetail.Qty = gapIpDetailInputList.Sum(gap => -gap.ReceiveQty); //多收的条码,数量为负 gapIpDetail.ReceivedQty = 0; gapIpDetail.IsClose = false; gapIpDetail.GapIpDetailId = targetIpDetail.Id; gapIpDetail.IpLocationDetails = (from gap in gapIpDetailInputList select new IpLocationDetail { IpNo = ipMaster.IpNo, OrderType = targetIpDetail.OrderType, OrderDetailId = targetIpDetail.OrderDetailId, Item = targetIpDetail.Item, //HuId = gap.HuId, //多收的条码按数量记录差异 //LotNo = gap.LotNo, IsCreatePlanBill = false, PlanBill = null, ActingBill = null, IsFreeze = false, IsATP = false, //差异不能进行MRP运算 QualityType = targetIpDetail.QualityType, OccupyType = com.Sconit.CodeMaster.OccupyType.None, OccupyReferenceNo = null, Qty = -gap.ReceiveQty * gapIpDetail.UnitQty, //多收,产生负数的差异 ReceivedQty = 0, IsClose = false }).ToList(); gapIpDetailList.Add(gapIpDetail); } #endregion #endregion #endregion } else { #region 数量匹配条码 IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList); if (gapIpDetail != null) { gapIpDetailList.Add(gapIpDetail); } #endregion } #endregion } else { #region 收货不扫描条码 if (isContainHu) { #region 条码匹配数量 IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList); if (gapIpDetail != null) { gapIpDetailList.Add(gapIpDetail); } #endregion } else { //采购数量超收,用收货输入数补发货数 if (ipMaster.OrderType == CodeMaster.OrderType.Procurement) { var remainSum = targetIpLocationDetailList.Sum(t => t.RemainReceiveQty); var receiveSum = targetIpDetail.IpDetailInputs.Sum(t => t.ReceiveQty); if (remainSum < receiveSum) { var firstIpLocationDetail = targetIpLocationDetailList.FirstOrDefault(); firstIpLocationDetail.Qty = firstIpLocationDetail.Qty + (receiveSum - remainSum); this.genericMgr.Update(firstIpLocationDetail); } } #region 数量匹配数量 IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList); if (gapIpDetail != null) { gapIpDetailList.Add(gapIpDetail); } #endregion } #endregion } #endregion #region 更新IpDetail上的收货数 targetIpDetail.ReceivedQty += targetIpDetail.ReceiveQtyInput; if (targetIpLocationDetailList.Where(i => !i.IsClose).Count() == 0) { //只有所有的IpLocationDetail关闭才能关闭 targetIpDetail.IsClose = true; } genericMgr.Update(targetIpDetail); #endregion } #endregion #region 送货单一次性收货,未收货差异 if (ipMaster.IsAsnUniqueReceive) { #region 查找未关闭送货单明细 List<IpDetail> openIpDetailList = (from det in nonZeroIpDetailList where !det.IsClose select det).ToList(); #region 查询剩余的未关闭送货单明细 IList<IpDetail> exceptIpDetailList = LoadExceptIpDetails(ipMaster.IpNo, (nonZeroIpDetailList.Select(det => det.Id)).ToArray()); #endregion #region 合并未关闭送货单明细 if (exceptIpDetailList != null && exceptIpDetailList.Count > 0) { openIpDetailList.AddRange(exceptIpDetailList); } #endregion #endregion #region 查找未关闭送货单库存对象 List<IpLocationDetail> openIpLocationDetailList = (from det in ipLocationDetailList where !det.IsClose select det).ToList(); #region 查询剩余未关闭送货单库存对象 IList<IpLocationDetail> expectIpLocationDetailList = LoadExceptIpLocationDetails(ipMaster.IpNo, (nonZeroIpDetailList.Select(det => det.Id)).ToArray()); #endregion #region 合并未关闭送货单库存对象 if (expectIpLocationDetailList != null && expectIpLocationDetailList.Count > 0) { openIpLocationDetailList.AddRange(expectIpLocationDetailList); } #endregion #endregion #region 生成未收货差异 if (openIpDetailList != null && openIpDetailList.Count > 0) { foreach (IpDetail openIpDetail in openIpDetailList) { var targetOpenIpLocationDetailList = openIpLocationDetailList.Where(o => o.IpDetailId == openIpDetail.Id); IpDetail gapIpDetail = Mapper.Map<IpDetail, IpDetail>(openIpDetail); gapIpDetail.Type = com.Sconit.CodeMaster.IpDetailType.Gap; gapIpDetail.GapReceiptNo = string.Empty; //todo 记录产生差异的收货单号 gapIpDetail.Qty = targetOpenIpLocationDetailList.Sum(o => o.RemainReceiveQty / openIpDetail.UnitQty); gapIpDetail.ReceivedQty = 0; gapIpDetail.IsClose = false; gapIpDetail.GapIpDetailId = openIpDetail.Id; gapIpDetail.IpLocationDetails = (from locDet in targetOpenIpLocationDetailList select new IpLocationDetail { IpNo = locDet.IpNo, OrderType = locDet.OrderType, OrderDetailId = locDet.OrderDetailId, Item = locDet.Item, HuId = locDet.HuId, LotNo = locDet.LotNo, IsCreatePlanBill = locDet.IsCreatePlanBill, IsConsignment = locDet.IsConsignment, PlanBill = locDet.PlanBill, ActingBill = locDet.ActingBill, IsFreeze = locDet.IsFreeze, //IsATP = locDet.IsATP, IsATP = false, QualityType = locDet.QualityType, OccupyType = locDet.OccupyType, OccupyReferenceNo = locDet.OccupyReferenceNo, Qty = locDet.RemainReceiveQty, ReceivedQty = 0, IsClose = false }).ToList(); gapIpDetailList.Add(gapIpDetail); } } #endregion #region 关闭未收货送货单明细和库存明细 if (openIpDetailList != null && openIpDetailList.Count > 0) { foreach (IpDetail openIpDetail in openIpDetailList) { openIpDetail.IsClose = true; this.genericMgr.Update(openIpDetail); } } if (openIpLocationDetailList != null && openIpLocationDetailList.Count > 0) { foreach (IpLocationDetail openIpLocationDetail in openIpLocationDetailList) { openIpLocationDetail.IsClose = true; this.genericMgr.Update(openIpLocationDetail); } } //string batchupdateipdetailstatement = "update from ipdetail set isclose = true where ipno = ? and isclose = false"; //genericmgr.update(batchupdateipdetailstatement, ipmaster.ipno); //string batchUpdateIpLocationDetailStatement = "update from IpLocationDetail set IsClose = True where IpNo = ? and IsClose = False"; //genericMgr.Update(batchUpdateIpLocationDetailStatement, ipMaster.IpNo); #endregion } else { ipMaster.Status = CodeMaster.IpStatus.InProcess; } #endregion #region 收货 ReceiptMaster receiptMaster = null; if (orderType == CodeMaster.OrderType.Production || orderType == CodeMaster.OrderType.SubContract) { foreach (var orderDetail in orderDetailList) { var _ipDetail = nonZeroIpDetailList.First(i => i.OrderDetailId == orderDetail.Id); foreach (var ipDetailInput in _ipDetail.IpDetailInputs) { OrderDetailInput orderDetailInput = new OrderDetailInput(); orderDetailInput.Bin = ipDetailInput.Bin; orderDetailInput.HuId = ipDetailInput.HuId; orderDetailInput.LotNo = ipDetailInput.LotNo; orderDetailInput.ManufactureParty = ipDetailInput.ManufactureParty; orderDetailInput.OccupyReferenceNo = ipDetailInput.OccupyReferenceNo; orderDetailInput.OccupyType = ipDetailInput.OccupyType; orderDetailInput.ReceiveQty = ipDetailInput.ReceiveQty; if (_ipDetail.Id != 0) { orderDetailInput.IpNo = _ipDetail.IpNo; orderDetailInput.IpDetId = _ipDetail.Id; } orderDetail.AddOrderDetailInput(orderDetailInput); } } receiptMaster = this.ReceiveOrder(orderDetailList, ipNo); } else { receiptMaster = this.receiptMgr.TransferIp2Receipt(ipMaster); this.receiptMgr.CreateReceipt(receiptMaster, effectiveDate); #region 尝试关闭订单 foreach (OrderMaster orderMaster in orderMasterList) { TryCloseOrder(orderMaster); } #endregion } #endregion #region 记录收货差异 if (gapIpDetailList != null && gapIpDetailList.Count > 0) { if (!string.IsNullOrWhiteSpace(ipMaster.SequenceNo)) { throw new BusinessException("排序单装箱单{0}的收货数和发货数不一致。", ipMaster.SequenceNo); } foreach (IpDetail gapIpDetail in gapIpDetailList) { gapIpDetail.GapReceiptNo = receiptMaster.ReceiptNo; this.genericMgr.Create(gapIpDetail); foreach (IpLocationDetail gapIpLocationDetail in gapIpDetail.IpLocationDetails) { gapIpLocationDetail.IpDetailId = gapIpDetail.Id; this.genericMgr.Create(gapIpLocationDetail); } } #region 调整发货方库存 if (ipMaster.ReceiveGapTo == CodeMaster.ReceiveGapTo.AdjectLocFromInv) { foreach (IpDetail gapIpDetail in gapIpDetailList) { gapIpDetail.IpDetailInputs = null; foreach (IpLocationDetail gapIpLocationDetail in gapIpDetail.IpLocationDetails) { IpDetailInput input = new IpDetailInput(); input.ReceiveQty = gapIpLocationDetail.Qty / gapIpDetail.UnitQty; //转为订单单位 if (ipMaster.IsReceiveScanHu) { input.HuId = gapIpLocationDetail.HuId; input.LotNo = gapIpLocationDetail.LotNo; } gapIpDetail.AddIpDetailInput(input); } } this.AdjustIpGap(gapIpDetailList, CodeMaster.IpGapAdjustOption.GI); } #endregion } #endregion #region 更新送货单状态 ipMaster.Status = CodeMaster.IpStatus.InProcess; this.genericMgr.Update(ipMaster); #endregion #region 尝试关闭送货单 this.ipMgr.TryCloseIp(ipMaster); #endregion return receiptMaster; }
public void CancelIp(IpMaster ipMaster, DateTime effectiveDate) { #region 判断发货单状态,只有Submit,一点货都没有收的才能冲销 if (ipMaster.Status != com.Sconit.CodeMaster.IpStatus.Submit) { throw new BusinessException("状态为{1}的送货单{0}不能冲销。", ipMaster.IpNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.IpStatus, ((int)ipMaster.Status).ToString())); } #endregion #region 获取送货单库存明细 string selectIpLocationDetailStatement = "from IpLocationDetail where IpNo = ? and IsClose = ?"; IList<IpLocationDetail> ipLocationDetailList = this.genericMgr.FindAll<IpLocationDetail>(selectIpLocationDetailStatement, new object[] { ipMaster.IpNo, false }); #endregion #region 获取送货单明细 if (ipMaster.IpDetails == null) { string selectIpDetailStatement = "from IpDetail where IpNo = ? and IsClose = ?"; ipMaster.IpDetails = this.genericMgr.FindAll<IpDetail>(selectIpDetailStatement, new object[] { ipMaster.IpNo, false }); } #endregion #region 一点货都没有收的才能冲销 var recIpDetails = ipMaster.IpDetails.Count(i => i.ReceivedQty > 0); if (recIpDetails > 0) { throw new BusinessException("已收过货的送货单不能冲销。", ipMaster.IpNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.IpStatus, ((int)ipMaster.Status).ToString())); } #endregion #region 关闭送货单库存明细 foreach (IpLocationDetail ipLocationDetail in ipLocationDetailList) { ipLocationDetail.IsClose = true; this.genericMgr.Update(ipLocationDetail); } #endregion #region 关闭送货单明细 foreach (IpDetail ipDetail in ipMaster.IpDetails) { ipDetail.IsClose = true; this.genericMgr.Update(ipDetail); } #endregion #region 更新发货单状态 ipMaster.Status = com.Sconit.CodeMaster.IpStatus.Cancel; this.genericMgr.Update(ipMaster); #endregion #region 更新订单明细 if (ipMaster.OrderType != CodeMaster.OrderType.ScheduleLine) { #region 非计划协议 #region 获取订单明细 string selectOrderDetailDetailStatement = "from OrderDetail where Id in (select OrderDetailId from IpDetail where IpNo = ? and IsClose = ?)"; IList<OrderDetail> orderDetailList = this.genericMgr.FindAll<OrderDetail>(selectOrderDetailDetailStatement, new object[] { ipMaster.IpNo, false }); #endregion foreach (OrderDetail orderDetail in orderDetailList) { #region 更新订单数量 orderDetail.ShippedQty -= ipMaster.IpDetails.Where(det => det.OrderDetailId == orderDetail.Id).Sum(det => det.Qty); this.genericMgr.Update(orderDetail); #endregion } #endregion } else { #region 计划协议 BusinessException businessException = new BusinessException(); foreach (IpDetail ipDetail in ipMaster.IpDetails) { decimal remainQty = ipDetail.Qty; IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq = ? and ScheduleType = ? and ShipQty > RecQty order by EndDate desc", new object[] { ipDetail.ExternalOrderNo, ipDetail.ExternalSequence, CodeMaster.ScheduleType.Firm }); if (scheduleOrderDetailList != null && scheduleOrderDetailList.Count > 0) { foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { //更新订单的发货数 if (remainQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { remainQty -= (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty); scheduleOrderDetail.ShippedQty = scheduleOrderDetail.ReceivedQty; } else { scheduleOrderDetail.ShippedQty -= remainQty; remainQty = 0; break; } this.genericMgr.Update(scheduleOrderDetail); } } if (remainQty > 0) { businessException.AddMessage(Resources.ORD.IpMaster.Errors_ReceiveQtyExcceedOrderQty, ipMaster.IpNo, ipDetail.Item); } } #endregion } #endregion this.genericMgr.FlushSession(); #region 更新库存 foreach (IpDetail ipDetail in ipMaster.IpDetails) { ipDetail.IsVoid = true; //???????ipDetail.OrderSubType = com.Sconit.CodeMaster.OrderSubType.Return; var targetIpLocationDetail = from locDet in ipLocationDetailList where locDet.IpDetailId == ipDetail.Id select locDet; ipDetail.CurrentPartyFrom = ipMaster.PartyFrom; //为了记录库存事务 ipDetail.CurrentPartyFromName = ipMaster.PartyFromName; //为了记录库存事务 ipDetail.CurrentPartyTo = ipMaster.PartyTo; //为了记录库存事务 ipDetail.CurrentPartyToName = ipMaster.PartyToName; //为了记录库存事务 foreach (IpLocationDetail ipLocationDetail in targetIpLocationDetail) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.HuId = ipLocationDetail.HuId; ipDetailInput.ShipQty = -ipLocationDetail.Qty / ipDetail.UnitQty; //转为订单单位 ipDetailInput.LotNo = ipLocationDetail.LotNo; ipDetailInput.IsCreatePlanBill = ipLocationDetail.IsCreatePlanBill; ipDetailInput.IsConsignment = ipLocationDetail.IsConsignment; ipDetailInput.PlanBill = ipLocationDetail.PlanBill; ipDetailInput.ActingBill = ipLocationDetail.ActingBill; ipDetailInput.IsATP = ipLocationDetail.IsATP; ipDetailInput.IsFreeze = ipLocationDetail.IsFreeze; ipDetailInput.OccupyType = ipLocationDetail.OccupyType; ipDetailInput.OccupyReferenceNo = ipLocationDetail.OccupyReferenceNo; ipDetail.AddIpDetailInput(ipDetailInput); } #region 更新库存、记库存事务 this.locationDetailMgr.InventoryOut(ipDetail, effectiveDate); #endregion } #endregion }
//private void CreateOrderOperation(OrderDetail orderDetail) //{ // if (orderDetail.OrderOperations != null && orderDetail.OrderOperations.Count() > 0) // { // foreach (OrderOperation orderOperation in orderDetail.OrderOperations) // { // orderOperation.OrderDetailId = orderDetail.Id; // orderOperation.OrderNo = orderDetail.OrderNo; // genericMgr.Create(orderOperation); // } // } //} //private void CreateOrderBomDetail(OrderDetail orderDetail) //{ // if (orderDetail.OrderBomDetails != null && orderDetail.OrderBomDetails.Count() > 0) // { // foreach (OrderBomDetail orderBomDetail in orderDetail.OrderBomDetails) // { // orderBomDetail.OrderNo = orderDetail.OrderNo; // orderBomDetail.OrderType = orderDetail.OrderType; // orderBomDetail.OrderSubType = orderDetail.OrderSubType; // orderBomDetail.OrderDetailId = orderDetail.Id; // orderBomDetail.OrderDetailSequence = orderDetail.Sequence; // genericMgr.Create(orderBomDetail); // } // } //} private void AutoReceiveIp(IpMaster ipMaster, DateTime effectiveDate) { if (ipMaster.IsAutoReceive) { foreach (IpDetail ipDetail in ipMaster.IpDetails) { if (ipDetail.IpDetailInputs != null && ipDetail.IpDetailInputs.Count > 0) { foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs) { ipDetailInput.ReceiveQty = ipDetailInput.ShipQty; } } else { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ReceiveQty = ipDetail.Qty; ipDetail.AddIpDetailInput(ipDetailInput); } } this.genericMgr.FlushSession(); ReceiveIp(ipMaster.IpDetails, effectiveDate); } }
public ReceiptMaster ReceiveOrder(IList<OrderDetail> orderDetailList, DateTime effectiveDate) { #region 判断是否全0收货 if (orderDetailList == null || orderDetailList.Count == 0) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveDetailIsEmpty); } IList<OrderDetail> nonZeroOrderDetailList = orderDetailList.Where(o => o.ReceiveQtyInput != 0 || o.ScrapQtyInput != 0).ToList(); if (nonZeroOrderDetailList.Count == 0) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveDetailIsEmpty); } #endregion #region 查询订单头对象 IList<OrderMaster> orderMasterList = LoadOrderMasters((from det in nonZeroOrderDetailList //where !string.IsNullOrWhiteSpace(det.OrderNo) todo支持无订单收货 select det.OrderNo).Distinct().ToArray()); #endregion foreach (var oMaster in orderMasterList) { if (oMaster.Type == com.Sconit.CodeMaster.OrderType.Transfer) { CheckInventory(orderDetailList.Where(ol => ol.OrderNo == oMaster.OrderNo).ToList(), oMaster); } } //#region 按订单明细汇总发货数,按条码发货一条订单明细会对应多条发货记录 //var summaryOrderDet = from det in orderDetailList // group det by new { Id = det.Id, OrderNo = det.OrderNo } into g // select new // { // Id = g.Key.Id, // OrderNo = g.Key.OrderNo, // ReceiveQty = g.Sum(det => det.CurrentReceiveQty), // RejectQty = g.Sum(det => det.CurrentRejectQty) // }; //#endregion #region 获取收货订单类型 IList<com.Sconit.CodeMaster.OrderType> orderTypeList = (from orderMaster in orderMasterList group orderMaster by orderMaster.Type into result select result.Key).ToList(); if (orderTypeList.Count > 1) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_CannotMixOrderTypeReceive); } com.Sconit.CodeMaster.OrderType orderType = orderTypeList.First(); #endregion #region 计划协议不能按收货校验 if (orderType == CodeMaster.OrderType.ScheduleLine) { throw new BusinessException("计划协议不能按订单收货。"); } #endregion #region 循环订单头检查 foreach (OrderMaster orderMaster in orderMasterList) { orderMaster.OrderDetails = nonZeroOrderDetailList.Where(det => det.OrderNo == orderMaster.OrderNo).ToList(); //如果非生产,把Submit状态改为InProcess if (orderMaster.Status == com.Sconit.CodeMaster.OrderStatus.Submit && orderMaster.Type != com.Sconit.CodeMaster.OrderType.Production && orderMaster.Type != com.Sconit.CodeMaster.OrderType.SubContract) { UpdateOrderMasterStatus2InProcess(orderMaster); } //判断OrderHead状态 if (orderMaster.Status != com.Sconit.CodeMaster.OrderStatus.InProcess) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_StatusErrorWhenReceive, orderMaster.OrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.OrderStatus, ((int)orderMaster.Status).ToString())); } #region 订单、生产线暂停检查 if (orderMaster.PauseStatus == CodeMaster.PauseStatus.Paused) { if (orderMaster.Type == CodeMaster.OrderType.Production) { throw new BusinessException("生产单{0}已经暂停,不能收货。", orderMaster.OrderNo); } else { throw new BusinessException("订单{0}已经暂停,不能收货。", orderMaster.OrderNo); } } if ((orderMaster.Type == CodeMaster.OrderType.Production || orderMaster.Type == CodeMaster.OrderType.SubContract ) && !string.IsNullOrWhiteSpace(orderMaster.Flow)) { FlowMaster flowMaster = this.genericMgr.FindById<FlowMaster>(orderMaster.Flow); if (flowMaster.IsPause) { throw new BusinessException("生产线{0}已经暂停,不能收货。", orderMaster.Flow); } } #endregion #region 整包装收货判断,快速的不要判断 if (orderMaster.IsReceiveFulfillUC && orderMaster.SubType == com.Sconit.CodeMaster.OrderSubType.Normal && !(orderMaster.IsAutoRelease && orderMaster.IsAutoStart)) { foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { //不合格品不作为收货数 //if (orderDetail.ReceiveQualifiedQtyInput % orderDetail.UnitCount != 0) if (orderDetail.ReceiveQtyInput % orderDetail.UnitCount != 0) { //不是整包装 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyNotFulfillUnitCount, orderDetail.Item); } } } #endregion #region 是否过量发货判断,未发货即收货也要判断是否过量发货 foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { if (!orderMaster.IsOpenOrder) { if (Math.Abs(orderDetail.ShippedQty) > Math.Abs(orderDetail.OrderedQty)) { //订单的发货数已经大于等于订单数 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ShipQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item); } else if (orderMaster.Type != com.Sconit.CodeMaster.OrderType.Production //生产和委外不需要判断 && orderMaster.Type != com.Sconit.CodeMaster.OrderType.SubContract && !orderMaster.IsShipExceed && Math.Abs(orderDetail.ShippedQty + orderDetail.ReceiveQtyInput) > Math.Abs(orderDetail.OrderedQty)) //不允许过量收货 { //订单的发货数 + 本次发货数大于订单数 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ShipQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item); } } } #endregion #region 是否过量收货判断 foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { if (!orderMaster.IsOpenOrder) { //订单的收货数已经大于等于订单数 if (Math.Abs(orderDetail.ReceivedQty) >= Math.Abs(orderDetail.OrderedQty)) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item); } //sih要求,废品数和不合格品数不占用入库数量 else if (!orderMaster.IsReceiveExceed && Math.Abs(orderDetail.ReceivedQty + orderDetail.ReceiveQtyInput) > Math.Abs(orderDetail.OrderedQty)) //不允许过量收货 { //订单的收货数 + 本次收货数大于订单数 throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item); } //else if (!orderMaster.IsReceiveExceed && Math.Abs(orderDetail.ReceivedQty + orderDetail.RejectedQty + orderDetail.ScrapQty + orderDetail.ReceiveQtyInput + orderDetail.ScrapQtyInput) > Math.Abs(orderDetail.OrderedQty)) //不允许过量收货 //{ // //订单的收货数 + 本次收货数大于订单数 // throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item); //} } } #endregion #region 采购收货是否有价格单判断 //if (orderHead.Type == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT // && !bool.Parse(entityPreference.Value)) //{ // if (orderDetail.UnitPrice == Decimal.Zero) // { // //重新查找一次价格 // PriceListDetail priceListDetail = priceListDetailMgrE.GetLastestPriceListDetail( // orderDetail.DefaultPriceList, // orderDetail.Item, // orderHead.StartTime, // orderHead.Currency, // orderDetail.Uom); // if (priceListDetail != null) // { // orderDetail.UnitPrice = priceListDetail.UnitPrice; // orderDetail.IsProvisionalEstimate = priceListDetail.IsProvisionalEstimate; // orderDetail.IsIncludeTax = priceListDetail.IsIncludeTax; // orderDetail.TaxCode = priceListDetail.TaxCode; // } // else // { // throw new BusinessErrorException("Order.Error.NoPriceListReceipt", orderDetail.Item.Code); // } // } //} #endregion #region 采购收货是否有计划协议行或PO号 if (orderMaster.Type == com.Sconit.CodeMaster.OrderType.Procurement) { foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { if (string.IsNullOrWhiteSpace(orderDetail.ExternalOrderNo) || string.IsNullOrWhiteSpace(orderDetail.ExternalSequence)) { throw new BusinessException("供应商直供要货单{0}物料号{1}的计划协议号或PO号不能为空。", orderDetail.OrderNo, orderDetail.Item); } } } #endregion } #endregion #region 循环更新订单明细 foreach (OrderDetail orderDetail in nonZeroOrderDetailList) { //未发货直接收货需要累加已发货数量 if (orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.Production && orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.SubContract) { orderDetail.ShippedQty += orderDetail.ReceiveQtyInput; } if (orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.Production && orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.SubContract) { //orderDetail.ReceivedQty += orderDetail.ReceiveQualifiedQtyInput; orderDetail.ReceivedQty += orderDetail.ReceiveQtyInput; } else { //生产收货更新合格数和不合格数量 //orderDetail.ReceivedQty += orderDetail.ReceiveQualifiedQtyInput; orderDetail.ReceivedQty += orderDetail.ReceiveQtyInput; orderDetail.ScrapQty += orderDetail.ScrapQtyInput; } genericMgr.Update(orderDetail); } #endregion #region 发货 #region OrderDetailInput赋发货数量 foreach (OrderDetail orderDetail in nonZeroOrderDetailList) { foreach (OrderDetailInput orderDetailInput in orderDetail.OrderDetailInputs) { orderDetailInput.ShipQty = orderDetailInput.ReceiveQty; } } #endregion IpMaster ipMaster = null; if (orderType != com.Sconit.CodeMaster.OrderType.Production && orderType != com.Sconit.CodeMaster.OrderType.SubContract) { ipMaster = this.ipMgr.TransferOrder2Ip(orderMasterList); #region 循环发货 foreach (IpDetail ipDetail in ipMaster.IpDetails) { ipDetail.CurrentPartyFrom = ipMaster.PartyFrom; //为了记录库存事务 ipDetail.CurrentPartyFromName = ipMaster.PartyFromName; //为了记录库存事务 ipDetail.CurrentPartyTo = ipMaster.PartyTo; //为了记录库存事务 ipDetail.CurrentPartyToName = ipMaster.PartyToName; //为了记录库存事务 //ipDetail.CurrentOccupyType = com.Sconit.CodeMaster.OccupyType.None; //todo-默认出库未占用库存,除非捡货或检验的出库 IList<InventoryTransaction> inventoryTransactionList = this.locationDetailMgr.InventoryOut(ipDetail, effectiveDate); #region 建立发货库明细和IpDetailInput的关系 if (inventoryTransactionList != null && inventoryTransactionList.Count > 0) { ipDetail.IpLocationDetails = (from trans in inventoryTransactionList group trans by new { HuId = trans.HuId, LotNo = trans.LotNo, IsCreatePlanBill = trans.IsCreatePlanBill, IsConsignment = trans.IsConsignment, PlanBill = trans.PlanBill, ActingBill = trans.ActingBill, QualityType = trans.QualityType, IsFreeze = trans.IsFreeze, IsATP = trans.IsATP, OccupyType = trans.OccupyType, OccupyReferenceNo = trans.OccupyReferenceNo } into g select new IpLocationDetail { HuId = g.Key.HuId, LotNo = g.Key.LotNo, IsCreatePlanBill = g.Key.IsCreatePlanBill, IsConsignment = g.Key.IsConsignment, PlanBill = g.Key.PlanBill, ActingBill = g.Key.ActingBill, QualityType = g.Key.QualityType, IsFreeze = g.Key.IsFreeze, IsATP = g.Key.IsATP, OccupyType = g.Key.OccupyType, OccupyReferenceNo = g.Key.OccupyReferenceNo, Qty = g.Sum(t => -t.Qty), //发货的库存事务为负数,转为收货数应该取负数 //PlanBillQty = g.Sum(t=>-t.PlanBillQty), //ActingBillQty = g.Sum(t=>-t.ActingBillQty) }).ToList(); } #endregion } #endregion #region 生成收货的IpInput foreach (OrderDetail orderDetail in nonZeroOrderDetailList) { OrderMaster orderMaster = orderMasterList.Where(o => o.OrderNo == orderDetail.OrderNo).Single(); //订单收货一定是一条订单明细对应一条发货单明细 IpDetail ipDetail = ipMaster.IpDetails.Where(det => det.OrderDetailId == orderDetail.Id).Single(); ipDetail.IpDetailInputs = null; //清空Ip的发货数据,准备添加收货数据 foreach (OrderDetailInput orderDetailInput in orderDetail.OrderDetailInputs) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ReceiveQty = orderDetailInput.ShipQty; if (orderMaster.IsReceiveScanHu) { ipDetailInput.HuId = orderDetailInput.HuId; ipDetailInput.LotNo = orderDetailInput.LotNo; } ipDetail.AddIpDetailInput(ipDetailInput); } } #region 订单生成收货Input if (ipMaster.IsShipScanHu && ipMaster.IsReceiveScanHu) { #region 按条码匹配 foreach (IpDetail ipDetail in ipMaster.IpDetails) { foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs) { IpLocationDetail matchedIpLocationDetail = ipDetail.IpLocationDetails.Where(locDet => locDet.HuId == ipDetailInput.HuId).SingleOrDefault(); matchedIpLocationDetail.ReceivedQty = matchedIpLocationDetail.Qty; if (matchedIpLocationDetail != null) { ipDetailInput.AddReceivedIpLocationDetail(matchedIpLocationDetail); } } } #endregion } else { #region 按数量匹配 foreach (IpDetail ipDetail in ipMaster.IpDetails) { CycleMatchIpDetailInput(ipDetail, ipDetail.IpDetailInputs, ipDetail.IpLocationDetails); } #endregion } #endregion #endregion } #endregion #region 收货 ReceiptMaster receiptMaster = null; if (orderType == com.Sconit.CodeMaster.OrderType.Production || orderType == com.Sconit.CodeMaster.OrderType.SubContract) { #region 生产收货 if (orderMasterList.Count > 1) { throw new TechnicalException("生产单不能合并收货。"); } foreach (OrderMaster orderMaster in orderMasterList) { receiptMaster = this.receiptMgr.TransferOrder2Receipt(orderMaster); this.receiptMgr.CreateReceipt(receiptMaster); //在报工的时候反冲物料,收货时不反冲 //foreach (OrderDetail orderDetail in nonZeroOrderDetailList) //{ // OrderDetailInput orderDetailInput = orderDetail.OrderDetailInputs[0]; // orderDetailInput.ReceiptDetail = receiptMaster.ReceiptDetails.Where(r => r.OrderDetailId == orderDetail.Id).Single(); //} //this.productionLineMgr.BackflushProductOrder(nonZeroOrderDetailList); } #endregion } else if (orderType != com.Sconit.CodeMaster.OrderType.Production && orderType != com.Sconit.CodeMaster.OrderType.SubContract) { #region 物流收货 receiptMaster = this.receiptMgr.TransferIp2Receipt(ipMaster); this.receiptMgr.CreateReceipt(receiptMaster, false, effectiveDate); #endregion } #endregion #region 尝试关闭订单 foreach (OrderMaster orderMaster in orderMasterList) { if (orderMaster.Type == CodeMaster.OrderType.Production) { #region 生产 TryCloseOrder(orderMaster); #endregion } else { #region 物流 TryCloseOrder(orderMaster); #endregion } } #endregion return receiptMaster; }