public virtual void DeleteOrderPlannedBackflush(OrderPlannedBackflush entity) { Delete(entity); }
public virtual void CreateOrderPlannedBackflush(OrderPlannedBackflush entity) { Create(entity); }
public virtual void UpdateOrderPlannedBackflush(OrderPlannedBackflush entity) { Update(entity); }
private void DoShipOrder(InProcessLocation inProcessLocation, User user, bool checkOrderStatus) { #region 变量定义 IDictionary<string, OrderHead> cachedOrderHead = new Dictionary<string, OrderHead>(); //缓存用到的OrderHead IList<InProcessLocationDetail> batchFeedInProcessLocationDetailList = new List<InProcessLocationDetail>(); #endregion #region 更新订单信息 foreach (InProcessLocationDetail inProcessLocationDetail in inProcessLocation.InProcessLocationDetails) { OrderLocationTransaction orderLocationTransaction = inProcessLocationDetail.OrderLocationTransaction; OrderDetail orderDetail = orderLocationTransaction.OrderDetail; OrderHead orderHead = orderDetail.OrderHead; if (orderLocationTransaction.BackFlushMethod != BusinessConstants.CODE_MASTER_BACKFLUSH_METHOD_VALUE_BATCH_FEED) { #region 判断OrderHead状态并缓存 if (!cachedOrderHead.ContainsKey(orderHead.OrderNo)) { //检查权限 //if (!OrderHelper.CheckOrderOperationAuthrize(orderHead, user, BusinessConstants.ORDER_OPERATION_SHIP_ORDER)) //{ // throw new BusinessErrorException("Order.Error.NoShipPermission", orderHead.OrderNo); //} //判断OrderHead状态 if (checkOrderStatus && orderHead.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS) { throw new BusinessErrorException("Order.Error.StatusErrorWhenShip", orderHead.Status, orderHead.OrderNo); } #region 整包装收货判断,快速的不要判断 if (orderHead.FulfillUnitCount && orderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION && orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML && !(orderHead.IsAutoRelease && orderHead.IsAutoStart)) { if (inProcessLocationDetail.Qty % orderDetail.UnitCount != 0) { //不是整包装 throw new BusinessErrorException("Order.Error.NotFulfillUnitCountGrGi", orderDetail.Item.Code); } } #endregion //缓存OrderHead cachedOrderHead.Add(orderHead.OrderNo, orderHead); } #endregion #region 更新OrderLocationTransaction、OrderDetail数量 this.orderDetailMgrE.RecordOrderShipQty(orderLocationTransaction, inProcessLocationDetail, true); #endregion } else { //只有普通的工单才记录待回冲表,返工不记录。 if (orderHead.SubType == BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML) { batchFeedInProcessLocationDetailList.Add(inProcessLocationDetail); } } } #endregion #region 创建ASN this.inProcessLocationMgrE.CreateInProcessLocation(inProcessLocation, user); #endregion #region 新增投料回冲计划数 if (batchFeedInProcessLocationDetailList.Count > 0) { foreach (InProcessLocationDetail inProcessLocationDetail in batchFeedInProcessLocationDetailList) { OrderLocationTransaction orderLocationTransaction = inProcessLocationDetail.OrderLocationTransaction; OrderPlannedBackflush orderPlannedBackflush = new OrderPlannedBackflush(); orderPlannedBackflush.OrderLocationTransaction = orderLocationTransaction; orderPlannedBackflush.InProcessLocation = inProcessLocation; orderPlannedBackflush.IsActive = true; orderPlannedBackflush.PlannedQty = orderLocationTransaction.UnitQty * inProcessLocationDetail.Qty; this.orderPlannedBackflushMgrE.CreateOrderPlannedBackflush(orderPlannedBackflush); } } #endregion #region 更新订单头信息 DateTime dateTimeNow = DateTime.Now; foreach (OrderHead orderHead in cachedOrderHead.Values) { orderHead.LastModifyUser = user; orderHead.LastModifyDate = dateTimeNow; this.orderHeadMgrE.UpdateOrderHead(orderHead); } #endregion }
public void RawMaterialBackflush(string prodLineCode, IDictionary <string, decimal> itemQtydic, User user) { if (itemQtydic == null || itemQtydic.Count == 0) { throw new BusinessErrorException("MasterData.Production.Feed.Error.NoSelectFeed"); } Flow flow = this.flowMgr.CheckAndLoadFlow(prodLineCode); DateTime dateTimeNow = DateTime.Now; IList <ProductLineInProcessLocationDetail> productLineInProcessLocationDetailList = this.GetProductLineInProcessLocationDetail(prodLineCode, BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE, itemQtydic.Keys.ToArray <string>()); IList <ProductLineInProcessLocationDetail> targetProductLineInProcessLocationDetailList = new List <ProductLineInProcessLocationDetail>(); #region 根据剩余数量计算回冲零件数量,添加到待处理列表 if (itemQtydic != null && itemQtydic.Count > 0) { foreach (string itemCode in itemQtydic.Keys) { decimal remainQty = itemQtydic[itemCode]; //剩余投料量 decimal inQty = 0; //总投料量 IList <ProductLineInProcessLocationDetail> currentProductLineInProcessLocationDetailList = new List <ProductLineInProcessLocationDetail>(); foreach (ProductLineInProcessLocationDetail productLineInProcessLocationDetail in productLineInProcessLocationDetailList) { if (productLineInProcessLocationDetail.Item.Code == itemCode) { inQty += (productLineInProcessLocationDetail.Qty - productLineInProcessLocationDetail.BackflushQty); currentProductLineInProcessLocationDetailList.Add(productLineInProcessLocationDetail); } } if (remainQty > inQty) { throw new BusinessErrorException("MasterData.Production.Feed.Error.RemainQtyGtFeedQty", itemCode); } decimal backflushQty = inQty - remainQty; //本次回冲量 #region 设定本次回冲数量 if (backflushQty > 0) { foreach (ProductLineInProcessLocationDetail productLineInProcessLocationDetail in currentProductLineInProcessLocationDetailList) { if (backflushQty - (productLineInProcessLocationDetail.Qty - productLineInProcessLocationDetail.BackflushQty) > 0) { productLineInProcessLocationDetail.CurrentBackflushQty = productLineInProcessLocationDetail.Qty - productLineInProcessLocationDetail.BackflushQty; backflushQty -= productLineInProcessLocationDetail.Qty - productLineInProcessLocationDetail.BackflushQty; productLineInProcessLocationDetail.BackflushQty = productLineInProcessLocationDetail.Qty; targetProductLineInProcessLocationDetailList.Add(productLineInProcessLocationDetail); } else { productLineInProcessLocationDetail.CurrentBackflushQty = backflushQty; productLineInProcessLocationDetail.BackflushQty += backflushQty; backflushQty = 0; targetProductLineInProcessLocationDetailList.Add(productLineInProcessLocationDetail); break; } } } #endregion } } #endregion if (targetProductLineInProcessLocationDetailList != null && targetProductLineInProcessLocationDetailList.Count > 0) { #region 更新生产线上的物料 foreach (ProductLineInProcessLocationDetail productLineInProcessLocationDetail in targetProductLineInProcessLocationDetailList) { if (productLineInProcessLocationDetail.Qty == productLineInProcessLocationDetail.BackflushQty) { productLineInProcessLocationDetail.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE; } productLineInProcessLocationDetail.LastModifyDate = dateTimeNow; productLineInProcessLocationDetail.LastModifyUser = user; this.UpdateProductLineInProcessLocationDetail(productLineInProcessLocationDetail); //记录库存事务 //this.locationTransactionMgrE.RecordLocationTransaction(productLineInProcessLocationDetail, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR, user, BusinessConstants.IO_TYPE_OUT); //this.locationTransactionMgrE.RecordLocationTransaction(productLineInProcessLocationDetail, BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT_TR, user, BusinessConstants.IO_TYPE_OUT); } #endregion IList <object[]> orderPlannedBackflushList = this.orderPlannedBackflushMgr.GetActiveOrderPlannedBackflush(prodLineCode); if (orderPlannedBackflushList == null || orderPlannedBackflushList.Count == 0) { throw new BusinessErrorException("MasterData.Production.Feed.Error.NoWO", prodLineCode); } var productLineInProcessLocationDetailDic = from plIp in targetProductLineInProcessLocationDetailList group plIp by new { Item = plIp.Item.Code, Operation = plIp.Operation, HuId = plIp.HuId, LotNo = plIp.LotNo, LocationFrom = plIp.LocationFrom, IsConsignment = plIp.IsConsignment, PlannedBill = plIp.PlannedBill } into result select new { Item = result.Key.Item, Operation = result.Key.Operation, HuId = result.Key.HuId, LotNo = result.Key.LotNo, LocationFrom = result.Key.LocationFrom, IsConsignment = result.Key.IsConsignment, PlannedBill = result.Key.PlannedBill, BackflushQty = result.Sum(plIp => plIp.CurrentBackflushQty) }; foreach (var productLineInProcessLocationDetail in productLineInProcessLocationDetailDic) { var planList = orderPlannedBackflushList.Where(p => (string)p[3] == productLineInProcessLocationDetail.Item && (!productLineInProcessLocationDetail.Operation.HasValue || productLineInProcessLocationDetail.Operation == (int?)p[1])).ToList(); var totalBaseQty = planList.Sum(p => (decimal)p[2]); //回冲分配基数 if (planList.Count > 0) { EntityPreference entityPreference = this.entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_AMOUNT_DECIMAL_LENGTH); int amountDecimalLength = int.Parse(entityPreference.Value); decimal remainTobeBackflushQty = productLineInProcessLocationDetail.BackflushQty; //剩余待回冲数量 decimal unitQty = Math.Round(remainTobeBackflushQty / totalBaseQty, amountDecimalLength); //单位基数的回冲数量 for (int i = 0; i < planList.Count; i++) { #region 物料回冲 #region 更新匹配的OrderLocationTransaction OrderPlannedBackflush matchedOrderPlannedBackflush = orderPlannedBackflushMgr.LoadOrderPlannedBackflush((int)planList[i][0]); OrderLocationTransaction matchedOrderLocationTransaction = matchedOrderPlannedBackflush.OrderLocationTransaction; //InProcessLocation ip = inProcessLocationMgr.LoadInProcessLocation(matchedOrderPlannedBackflush.InProcessLocation); bool isLastestRecord = (i == (planList.Count - 1)); decimal currentTotalBackflushQty = 0; if (!matchedOrderLocationTransaction.AccumulateQty.HasValue) { matchedOrderLocationTransaction.AccumulateQty = 0; } if (!isLastestRecord) { decimal currentBackflushQty = matchedOrderPlannedBackflush.PlannedQty * unitQty; currentTotalBackflushQty += currentBackflushQty; matchedOrderLocationTransaction.AccumulateQty += currentBackflushQty; remainTobeBackflushQty -= currentBackflushQty; } else { currentTotalBackflushQty += remainTobeBackflushQty; matchedOrderLocationTransaction.AccumulateQty += remainTobeBackflushQty; remainTobeBackflushQty = 0; } this.orderLocationTransactionMgr.UpdateOrderLocationTransaction(matchedOrderLocationTransaction); #endregion #region 新增/更新AsnDetail,暂时不更新了 //InProcessLocationDetail inProcessLocationDetail = null; //if (productLineInProcessLocationDetail.HuId == null || productLineInProcessLocationDetail.HuId.Trim() == string.Empty) //{ // inProcessLocationDetail = this.inProcessLocationDetailMgr.GetNoneHuAndIsConsignmentInProcessLocationDetail(ip, matchedOrderPlannedBackflush.OrderLocationTransaction); // if (inProcessLocationDetail != null) // { // inProcessLocationDetail.Qty += currentTotalBackflushQty; // this.inProcessLocationDetailMgr.UpdateInProcessLocationDetail(inProcessLocationDetail); // } //} //if (inProcessLocationDetail == null) //{ // inProcessLocationDetail = new InProcessLocationDetail(); // inProcessLocationDetail.InProcessLocation = ip; // inProcessLocationDetail.OrderLocationTransaction = matchedOrderPlannedBackflush.OrderLocationTransaction; // inProcessLocationDetail.HuId = productLineInProcessLocationDetail.HuId; // inProcessLocationDetail.LotNo = productLineInProcessLocationDetail.LotNo; // inProcessLocationDetail.IsConsignment = productLineInProcessLocationDetail.IsConsignment; // inProcessLocationDetail.PlannedBill = productLineInProcessLocationDetail.PlannedBill; // inProcessLocationDetail.Qty = currentTotalBackflushQty; // this.inProcessLocationDetailMgr.CreateInProcessLocationDetail(inProcessLocationDetail); // ip.AddInProcessLocationDetail(inProcessLocationDetail); //} #endregion #region 新增库存事务 this.locationTransactionMgr.RecordWOBackflushLocationTransaction( matchedOrderPlannedBackflush.OrderLocationTransaction, productLineInProcessLocationDetail.HuId, productLineInProcessLocationDetail.LotNo, currentTotalBackflushQty, matchedOrderPlannedBackflush.InProcessLocation, user, productLineInProcessLocationDetail.LocationFrom); #endregion #endregion #region 关闭OrderPlannedBackflush if (matchedOrderPlannedBackflush.IsActive) { matchedOrderPlannedBackflush.IsActive = false; this.orderPlannedBackflushMgr.UpdateOrderPlannedBackflush(matchedOrderPlannedBackflush); } #endregion } } else { #region 没有匹配的OrderLocationTransaction //退回原库位 throw new BusinessErrorException("MasterData.BackFlush.NotFoundResources", productLineInProcessLocationDetail.Item); //this.locationMgrE.InventoryIn(productLineInProcessLocationDetail, user); #endregion } } } else { throw new BusinessErrorException("MasterData.Production.Feed.Error.NoFeed", prodLineCode); } }