public void CreatePickTask(OrderMaster orderMaster) { if (orderMaster.Status == CodeMaster.OrderStatus.Submit || orderMaster.Status == CodeMaster.OrderStatus.InProcess) { IList<OrderDetail> ods = this.genericMgr.FindAll<OrderDetail>("from OrderDetail where OrderNo = ? ", orderMaster.OrderNo); if (ods != null) { foreach (OrderDetail od in ods) { if (od.IsCreatePickList) { PickTask task = this.genericMgr.FindAll<PickTask>("from PickTask where OrderNo = ? and OrdDetId = ? ", new object[] { od.OrderNo, od.Id }).SingleOrDefault(); if (task == null) { CreatePickTaskFromOrder(orderMaster, od); } else { throw new BusinessException("task already exists!"); } } } } } else { throw new BusinessException("bad status!"); } }
public OrderMaster CreateExScrapOrder(MrpExScrap mrpExScrap) { var newOrder = new OrderMaster(); Item item = this.itemMgr.GetCacheItem(mrpExScrap.Item); mrpExScrap.ItemDescription = item.Description; this.genericMgr.Create(mrpExScrap); if(mrpExScrap.Item == BusinessConstants.VIRTUALSECTION) { //nothing todo } else if(mrpExScrap.ScrapType == CodeMaster.ScheduleType.MES24 || mrpExScrap.ScrapType == CodeMaster.ScheduleType.MES25) { //只记录废品数,无材料消耗 DateTime startTime = mrpExScrap.EffectDate; DateTime windowTime = mrpExScrap.EffectDate; workingCalendarMgr.GetStartTimeAndWindowTime(mrpExScrap.Shift, mrpExScrap.EffectDate, out startTime, out windowTime); FlowMaster flowMaster = this.genericMgr.FindById<FlowMaster>(mrpExScrap.Flow); newOrder = orderMgr.TransferFlow2Order(flowMaster, false); newOrder.Shift = mrpExScrap.Shift; newOrder.StartTime = startTime; newOrder.WindowTime = windowTime; newOrder.EffectiveDate = mrpExScrap.EffectDate; newOrder.ReferenceOrderNo = mrpExScrap.Id.ToString(); newOrder.Priority = CodeMaster.OrderPriority.Normal; OrderDetail newOrderDetail = new OrderDetail(); newOrderDetail.Item = item.Code; newOrderDetail.UnitCount = (decimal)item.UnitCount; newOrderDetail.Uom = "KG"; newOrderDetail.BaseUom = item.Uom; newOrderDetail.ItemDescription = item.Description; newOrderDetail.Sequence = 10; newOrderDetail.MinUnitCount = item.UnitCount; newOrderDetail.OrderedQty = (decimal)mrpExScrap.ScrapQty; newOrderDetail.LocationFrom = flowMaster.LocationFrom; newOrderDetail.LocationTo = flowMaster.LocationTo; newOrderDetail.CurrentScrapQty = newOrderDetail.OrderedQty; newOrderDetail.ScheduleType = mrpExScrap.ScrapType; newOrder.ExternalOrderNo = newOrderDetail.ScheduleType.ToString(); newOrder.AddOrderDetail(newOrderDetail); newOrder.SubType = CodeMaster.OrderSubType.Other; newOrder.IsQuick = true; newOrder.IsShipScanHu = false; newOrder.IsReceiveScanHu = false; newOrder.CreateHuOption = CodeMaster.CreateHuOption.None; orderMgr.CreateOrder(newOrder, true); mrpExScrap.OrderNo = newOrder.OrderNo; } return newOrder; }
public string GetOrderNo(OrderMaster orderMaster) { SqlParameter[] parm = new SqlParameter[13]; parm[0] = new SqlParameter("@Flow", SqlDbType.VarChar, 50); parm[0].Value = orderMaster.Flow; parm[1] = new SqlParameter("@OrderStrategy", SqlDbType.TinyInt); parm[1].Value = orderMaster.OrderStrategy; parm[2] = new SqlParameter("@Type", SqlDbType.TinyInt); parm[2].Value = orderMaster.Type; parm[3] = new SqlParameter("@SubType", SqlDbType.TinyInt); parm[3].Value = orderMaster.SubType; parm[4] = new SqlParameter("@QualityType", SqlDbType.TinyInt); parm[4].Value = orderMaster.QualityType; parm[5] = new SqlParameter("@Priority", SqlDbType.TinyInt); parm[5].Value = orderMaster.Priority; parm[6] = new SqlParameter("@PartyFrom", SqlDbType.VarChar, 50); parm[6].Value = orderMaster.PartyFrom; parm[7] = new SqlParameter("@PartyTo", SqlDbType.VarChar, 50); parm[7].Value = orderMaster.PartyTo; parm[8] = new SqlParameter("@LocTo", SqlDbType.VarChar, 50); parm[8].Value = orderMaster.LocationTo; parm[9] = new SqlParameter("@LocFrom", SqlDbType.VarChar, 50); parm[9].Value = orderMaster.LocationFrom; parm[10] = new SqlParameter("@Dock", SqlDbType.VarChar, 50); parm[10].Value = orderMaster.Dock; parm[11] = new SqlParameter("@IsQuick", SqlDbType.Bit); parm[11].Value = orderMaster.IsQuick; parm[12] = new SqlParameter("@OrderNo", SqlDbType.VarChar, 100); parm[12].Direction = ParameterDirection.InputOutput; sqlDao.ExecuteStoredProcedure("USP_GetDocNo_ORD", parm); return parm[12].Value.ToString(); }
public void DistributionReceiveOrder(OrderMaster orderMaster) { #region 检查交货单明细是否一起过账 IList<OrderDetail> selectOrderDetailList = this.genericMgr.FindAll<OrderDetail>("select d from OrderDetail as d where d.OrderNo='" + orderMaster.OrderNo + "'"); foreach (OrderDetail orderDetail in selectOrderDetailList) { bool b = false; foreach (OrderDetail item in orderMaster.OrderDetails) { if (orderDetail.Id == item.Id) { b = true; break; } } if (b == false) { string externalNo = this.genericMgr.FindById<OrderMaster>(orderDetail.OrderNo).ExternalOrderNo; throw new BusinessException("交货单的明细必须一起过账。订单号为" + orderDetail.OrderNo); } } #endregion #region 把创建状态的OrderMaster释放 this.genericMgr.CleanSession(); if (orderMaster.Status == com.Sconit.CodeMaster.OrderStatus.Create) { this.ReleaseOrder(orderMaster); } #endregion #region 过账 this.ReceiveOrder(orderMaster.OrderDetails); #endregion #region 把OrderMaster的状态关闭 if (orderMaster.Status != com.Sconit.CodeMaster.OrderStatus.Close) { this.ManualCloseOrder(orderMaster); } #endregion }
private void BeforeUpdateOrderDetails(OrderMaster orderMaster) { if (orderMaster.Status != com.Sconit.CodeMaster.OrderStatus.Create) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_StatusErrorWhenModifyOrderDetail, orderMaster.OrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.OrderStatus, int.Parse(((int)orderMaster.Status).ToString()))); } }
private IList<OrderBomDetail> TryLoadOrderBomDetails(OrderMaster orderMaster) { if (orderMaster.OrderNo != null) { TryLoadOrderDetails(orderMaster); IList<OrderBomDetail> orderBomDetailList = new List<OrderBomDetail>(); string hql = string.Empty; IList<object> para = new List<object>(); foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { if (orderDetail.OrderBomDetails != null && orderDetail.OrderBomDetails.Count > 0) { ((List<OrderBomDetail>)orderBomDetailList).AddRange(orderDetail.OrderBomDetails); } else { if (hql == string.Empty) { hql = "from OrderBomDetail where OrderDetailId in (?"; } else { hql += ",?"; } para.Add(orderDetail.Id); } } if (hql != string.Empty) { hql += ") order by OrderDetailId, Operation, OpReference"; ((List<OrderBomDetail>)orderBomDetailList).AddRange(this.genericMgr.FindAll<OrderBomDetail>(hql, para.ToArray())); } foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { if (orderDetail.OrderBomDetails == null || orderDetail.OrderBomDetails.Count == 0) { orderDetail.OrderBomDetails = orderBomDetailList.Where(o => o.OrderDetailId == orderDetail.Id).ToList(); } } return orderBomDetailList; } else { return null; } }
private IList<OrderBinding> TryLoadOrderBindings(OrderMaster orderMaster) { if (!string.IsNullOrWhiteSpace(orderMaster.OrderNo)) { if (orderMaster.OrderBindings == null) { string hql = "from OrderBinding where OrderNo = ?"; orderMaster.OrderBindings = this.genericMgr.FindAll<OrderBinding>(hql, orderMaster.OrderNo); } return orderMaster.OrderBindings; } else { return null; } }
private void CalculateOrderDetailPrice(OrderDetail orderDetail, OrderMaster orderMaster, DateTime? effectiveDate) { string priceList = !string.IsNullOrWhiteSpace(orderDetail.PriceList) ? orderDetail.PriceList : orderMaster.PriceList; if (string.IsNullOrWhiteSpace(priceList)) { bool isAllowCreateOrderWithNoPrice = true; if (orderMaster.Type == com.Sconit.CodeMaster.OrderType.Distribution) { isAllowCreateOrderWithNoPrice = bool.Parse(systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.IsAllowCreateSalesOrderWithNoPrice)); } else { isAllowCreateOrderWithNoPrice = bool.Parse(systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.IsAllowCreatePurchaseOrderWithNoPrice)); } if (isAllowCreateOrderWithNoPrice) { return; } else { throw new BusinessException("没有指定价格单。"); } } #region 币种 PriceListMaster priceListMaster = orderDetail.CurrentPriceListMaster != null ? orderDetail.CurrentPriceListMaster : orderMaster.CurrentPriceListMaster; if (priceListMaster == null) { if (!string.IsNullOrWhiteSpace(orderDetail.PriceList)) { orderDetail.CurrentPriceListMaster = this.genericMgr.FindById<PriceListMaster>(orderDetail.PriceList); priceListMaster = orderDetail.CurrentPriceListMaster; } else if (!string.IsNullOrWhiteSpace(orderMaster.PriceList)) { orderMaster.CurrentPriceListMaster = this.genericMgr.FindById<PriceListMaster>(orderMaster.PriceList); priceListMaster = orderMaster.CurrentPriceListMaster; } } orderDetail.Currency = priceListMaster.Currency; #endregion #region 价格 PriceListDetail priceListDetail = itemMgr.GetItemPrice(orderDetail.Item, orderDetail.Uom, priceList, orderMaster.Currency, effectiveDate); if (priceListDetail != null) { orderDetail.UnitPrice = priceListDetail.UnitPrice; orderDetail.IsProvisionalEstimate = priceListDetail.IsProvisionalEstimate; orderDetail.Tax = priceListDetail.PriceList.Tax; orderDetail.IsIncludeTax = priceListDetail.PriceList.IsIncludeTax; } #endregion }
private IList<OrderDetail> ProcessNewOrderDetail(OrderDetail orderDetail, OrderMaster orderMaster, ref int seq) { IList<OrderDetail> activeOrderDetails = new List<OrderDetail>(); if (orderDetail.OrderedQty != 0) //过滤数量为0的明细 { #region 整包校验 CheckOrderedQtyFulfillment(orderMaster, orderDetail); #endregion Item item = orderDetail.CurrentItem != null ? orderDetail.CurrentItem : genericMgr.FindById<Item>(orderDetail.Item); if (item.IsKit && false) //暂时不支持套件 { #region 分解套件 //没有考虑套件下面还是套件的情况 IList<ItemKit> itemKitList = itemMgr.GetKitItemChildren(item.Code); if (itemKitList != null && itemKitList.Count() > 0) { foreach (ItemKit kit in itemKitList) { //检查订单明细的零件类型 CheckOrderDetailItemType(kit.ChildItem, (com.Sconit.CodeMaster.OrderType)orderMaster.Type); OrderDetail activeOrderDetail = new OrderDetail(); activeOrderDetail.OrderType = orderMaster.Type; activeOrderDetail.OrderSubType = orderMaster.SubType; activeOrderDetail.Sequence = ++seq; activeOrderDetail.Item = kit.ChildItem.Code; activeOrderDetail.ItemDescription = kit.ChildItem.Description; activeOrderDetail.Uom = orderDetail.Uom; activeOrderDetail.BaseUom = kit.ChildItem.Uom; activeOrderDetail.UnitCount = orderDetail.UnitCount; activeOrderDetail.RequiredQty = orderDetail.RequiredQty * kit.Qty; activeOrderDetail.OrderedQty = orderDetail.OrderedQty * kit.Qty; if (activeOrderDetail.Uom != kit.ChildItem.Uom) { activeOrderDetail.UnitQty = kit.Qty; } else { activeOrderDetail.UnitQty = itemMgr.ConvertItemUomQty(kit.ChildItem.Code, kit.ChildItem.Uom, kit.Qty, activeOrderDetail.Uom); } activeOrderDetail.ReceiveLotSize = orderDetail.ReceiveLotSize * kit.Qty; activeOrderDetail.LocationFrom = orderDetail.LocationFrom; activeOrderDetail.LocationFromName = orderDetail.LocationFromName; activeOrderDetail.LocationTo = orderDetail.LocationTo; activeOrderDetail.LocationToName = orderDetail.LocationToName; activeOrderDetail.IsInspect = orderDetail.IsInspect; //activeOrderDetail.InspectLocation = orderDetail.InspectLocation; //activeOrderDetail.InspectLocationName = orderDetail.InspectLocationName; //activeOrderDetail.RejectLocation = orderDetail.RejectLocation; //activeOrderDetail.RejectLocationName = orderDetail.RejectLocationName; activeOrderDetail.BillAddress = orderDetail.BillAddress; activeOrderDetail.BillAddressDescription = orderDetail.BillAddressDescription; activeOrderDetail.PriceList = orderDetail.PriceList; activeOrderDetail.Routing = activeOrderDetail.Routing; //activeOrderDetail.HuLotSize = activeOrderDetail.HuLotSize * kit.Qty; activeOrderDetail.BillTerm = activeOrderDetail.BillTerm; //activeOrderDetail.OldOption = CodeMaster.HuOption. activeOrderDetails.Add(activeOrderDetail); } } else { throw new BusinessException(Resources.MD.Item.Errors_ItemKit_ChildrenItemNotFound, orderDetail.Item); } #endregion } else { orderDetail.Sequence = ++seq; orderDetail.OrderType = orderMaster.Type; orderDetail.OrderSubType = orderMaster.SubType; orderDetail.BaseUom = item.Uom; orderDetail.ItemDescription = item.Description; #region 零件类型校验 CheckOrderDetailItemType(item, (com.Sconit.CodeMaster.OrderType)orderMaster.Type); activeOrderDetails.Add(orderDetail); #endregion #region 设置和库存单位的转换 if (string.Compare(orderDetail.Uom, item.Uom) != 0) { orderDetail.UnitQty = itemMgr.ConvertItemUomQty(orderDetail.Item, orderDetail.Uom, 1, item.Uom); } else { orderDetail.UnitQty = 1; } #endregion } } return activeOrderDetails; }
private void DoPauseOrder(OrderMaster orderMaster, IList<SequenceMaster> sequenceMasterList, IList<SequenceDetail> sequenceDetailList, IList<string> pausedOrderNoList, DateTime dateTimeNow) { if (orderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT) { orderMaster.IsPause = true; orderMaster.PauseTime = dateTimeNow; this.genericMgr.Update(orderMaster); pausedOrderNoList.Add(orderMaster.OrderNo); log.Debug("Success pause kit order, orderNo[" + orderMaster.OrderNo + "]."); } else if (orderMaster.OrderStrategy == CodeMaster.FlowStrategy.SEQ && sequenceDetailList != null && sequenceDetailList.Count > 0) { //如果排序装箱单已经收货,sequenceDetail为空。 SequenceDetail sequenceDetail = sequenceDetailList.Where(s => s.OrderNo == orderMaster.OrderNo).SingleOrDefault(); if (sequenceDetail != null) { SequenceMaster sequenceMaster = sequenceMasterList.Where(s => s.SequenceNo == sequenceDetail.SequenceNo).Single(); if (sequenceMaster.Status == CodeMaster.SequenceStatus.Submit || sequenceMaster.Status == CodeMaster.SequenceStatus.Pack) //没有发货前都可以取消 { //先取消排序装箱单明细 sequenceDetail.IsClose = true; this.genericMgr.Update(sequenceDetail); //再暂停排序单 //orderMaster.Status = CodeMaster.OrderStatus.Submit; //可能一个零件有多个排序件,即多张排序装箱单对应一张排序单 if (!orderMaster.IsPause) { orderMaster.IsPause = true; orderMaster.PauseTime = dateTimeNow; this.genericMgr.Update(orderMaster); pausedOrderNoList.Add(orderMaster.OrderNo); log.Debug("Success pause sequence order, orderNo[" + orderMaster.OrderNo + "]."); } else { log.Debug("Sequence order already paused, orderNo[" + orderMaster.OrderNo + "]."); } //string loc = systemMgr.GetEntityPreferenceValue(Entity.SYS.EntityPreference.CodeEnum.WMSAnjiRegion); //if (sequenceMaster.PartyFrom.Equals(loc, StringComparison.OrdinalIgnoreCase)) //{ // //this.genericMgr.FlushSession(); // //AsyncRecourdMessageQueue(MethodNameType.CancelSequenceDetail, sequenceDetail.Id.ToString()); // this.CreateMessageQueue("CancelSequenceDetail", sequenceDetail.Id.ToString()); //} } } else { orderMaster.IsPause = true; orderMaster.PauseTime = dateTimeNow; this.genericMgr.Update(orderMaster); log.Debug("Success pause sequence order, orderNo[" + orderMaster.OrderNo + "]."); } } }
private void PauseSequenceAndKitOrder(OrderMaster productOrder, int? pauseOperation) { //todo:发送暂停通知邮件 DateTime dateTimeNow = DateTime.Now; #region 查找需要暂停的工位 string selectPauseLocationStatement = "select distinct Location from OrderBomDetail where OrderNo = ?"; IList<object> selectPauseLocationParm = new List<object>(); selectPauseLocationParm.Add(productOrder.OrderNo); if (pauseOperation.HasValue) { selectPauseLocationStatement += " and Operation > ?"; //在指定工序之后暂停,大于工序后的排序单/Kit单全部暂停 selectPauseLocationParm.Add(pauseOperation.Value); } IList<string> pauseLocationList = this.genericMgr.FindAll<string>(selectPauseLocationStatement, selectPauseLocationParm.ToArray()); ProductLineMap productLineMap = genericMgr.FindAll<ProductLineMap>(@"from ProductLineMap as p where (p.ProductLine = ? or p.CabFlow = ? or p.ChassisFlow = ?) and p.ProductLine is not null and p.CabFlow is not null and p.ChassisFlow is not null", new object[] { productOrder.Flow, productOrder.Flow, productOrder.Flow }).Single(); #region 添加生产线的虚拟库位 if (productLineMap.ProductLine == productOrder.Flow) { pauseLocationList.Add(productLineMap.VanLocation); } else if (productLineMap.CabFlow == productOrder.Flow) { pauseLocationList.Add(productLineMap.CabLocation); } else if (productLineMap.ChassisFlow == productOrder.Flow) { pauseLocationList.Add(productLineMap.ChassisLocation); } #endregion #endregion #region 循环查找OrderBinding IList<OrderBinding> orderBindingList = NestGetOrderBinding(productOrder.OrderNo); if (orderBindingList == null || orderBindingList.Count == 0) { log.Debug("No order binding."); return; } #endregion #region 查询Kit单和排序单 string selectKitOrderStatement = string.Empty; string selectSeqOrderStatement = string.Empty; IList<object> selectKitOrderParm = new List<object>(); IList<object> selectSeqOrderParm = new List<object>(); foreach (OrderBinding orderBinding in orderBindingList) { if (selectKitOrderStatement == string.Empty) { selectKitOrderStatement = "from OrderMaster where OrderStrategy = ? and Status = ? and IsPause = ? and OrderNo in (?"; selectSeqOrderStatement = "from OrderMaster where OrderStrategy = ? and Status in (?, ?) and IsPause = ? and OrderNo in (?"; selectKitOrderParm.Add(CodeMaster.FlowStrategy.KIT); selectKitOrderParm.Add(CodeMaster.OrderStatus.Submit); selectKitOrderParm.Add(false); selectSeqOrderParm.Add(CodeMaster.FlowStrategy.SEQ); selectSeqOrderParm.Add(CodeMaster.OrderStatus.Submit); selectSeqOrderParm.Add(CodeMaster.OrderStatus.InProcess); selectSeqOrderParm.Add(false); } else { selectKitOrderStatement += ", ?"; selectSeqOrderStatement += ", ?"; } selectKitOrderParm.Add(orderBinding.BindOrderNo); selectSeqOrderParm.Add(orderBinding.BindOrderNo); } selectKitOrderStatement += ")"; selectSeqOrderStatement += ")"; IList<OrderMaster> kitOrderList = this.genericMgr.FindAll<OrderMaster>(selectKitOrderStatement, selectKitOrderParm.ToArray()); IList<OrderMaster> seqOrderList = this.genericMgr.FindAll<OrderMaster>(selectSeqOrderStatement, selectSeqOrderParm.ToArray()); if ((kitOrderList == null || kitOrderList.Count == 0) && (seqOrderList == null || seqOrderList.Count == 0)) { log.Debug("No sequence and kit order to pause."); return; } #endregion #region 查询排序装箱单 #region 查询排序装箱单头 IList<SequenceMaster> sequenceMasterList = null; if (seqOrderList != null && seqOrderList.Count > 0) { string selectSequenceMasterStatement = string.Empty; IList<object> selectSequenceMasterParas = new List<object>(); foreach (OrderMaster seqOrder in seqOrderList) { if (selectSequenceMasterStatement == string.Empty) { selectSequenceMasterStatement = "from SequenceMaster where Status in (?, ?) and SequenceNo in (select distinct SequenceNo from SequenceDetail where IsClose = ? and OrderNo in (?"; selectSequenceMasterParas.Add(CodeMaster.SequenceStatus.Submit); selectSequenceMasterParas.Add(CodeMaster.SequenceStatus.Pack); selectSequenceMasterParas.Add(false); } else { selectSequenceMasterStatement += ", ?"; } selectSequenceMasterParas.Add(seqOrder.OrderNo); } selectSequenceMasterStatement += "))"; sequenceMasterList = this.genericMgr.FindAll<SequenceMaster>(selectSequenceMasterStatement, selectSequenceMasterParas.ToArray()); } #endregion #region 查询排序装箱单明细 IList<SequenceDetail> sequenceDetailList = null; if (sequenceMasterList != null && sequenceMasterList.Count > 0) { string selectSequenceDetailStatement = string.Empty; IList<object> selectSequenceDetailParas = new List<object>(); foreach (SequenceMaster sequenceMaster in sequenceMasterList) { if (selectSequenceDetailStatement == string.Empty) { selectSequenceDetailStatement = "from SequenceDetail where IsClose = ? and SequenceNo in (?"; selectSequenceDetailParas.Add(false); } else { selectSequenceDetailStatement += ", ?"; } selectSequenceDetailParas.Add(sequenceMaster.SequenceNo); } selectSequenceDetailStatement += "))"; sequenceDetailList = this.genericMgr.FindAll<SequenceDetail>(selectSequenceDetailStatement, selectSequenceDetailParas.ToArray()); } #endregion #endregion #region 直接绑定的Kit/SEQ单处理 IList<string> pausedOrderNoList = new List<string>(); #region KIT单处理 if (kitOrderList != null && kitOrderList.Count > 0) { //没有指定暂停的工位则全部暂停 //kit单的目的库位等于需要暂停的工位 foreach (OrderMaster kitOrder in kitOrderList.Where(k => pauseLocationList.Contains(k.LocationTo))) { DoPauseOrder(kitOrder, null, null, pausedOrderNoList, dateTimeNow); } } #endregion #region SEQ单处理 if (seqOrderList != null && seqOrderList.Count > 0) { //已创建排序装箱单,并且被生产单直接绑定的排序单列表 IList<OrderMaster> startedInLocationSeqOrderList = seqOrderList.Where(s => pauseLocationList.Contains(s.LocationTo)).ToList(); if (startedInLocationSeqOrderList != null && startedInLocationSeqOrderList.Count > 0) { foreach (OrderMaster startedInLocationSeqOrder in startedInLocationSeqOrderList) { DoPauseOrder(startedInLocationSeqOrder, sequenceMasterList, sequenceDetailList, pausedOrderNoList, dateTimeNow); } } } #endregion #endregion #region 不是直接绑定的Kit/SEQ单处理 IList<OrderMaster> unDirectBindOrderList = new List<OrderMaster>(); //不是直接绑定的Kit列表 IList<OrderMaster> unDirectBindKitOrderList = kitOrderList != null && kitOrderList.Count > 0 ? kitOrderList.Where(k => !pauseLocationList.Contains(k.LocationTo)).ToList() : null; if (unDirectBindKitOrderList != null) { ((List<OrderMaster>)unDirectBindOrderList).AddRange(unDirectBindKitOrderList); } //不是直接绑定的Seq列表 IList<OrderMaster> unDirectBindReleasedSeqOrderList = seqOrderList != null && seqOrderList.Count > 0 ? seqOrderList.Where(s => !pauseLocationList.Contains(s.LocationTo)).ToList() : null; if (unDirectBindReleasedSeqOrderList != null) { ((List<OrderMaster>)unDirectBindOrderList).AddRange(unDirectBindReleasedSeqOrderList); } #region 递归处理没有被直接绑定的订单绑定 //一层层查找没有被直接绑定的订单是否被已经暂停的订单绑定 while (pausedOrderNoList != null && pausedOrderNoList.Count > 0) { pausedOrderNoList = NestPauseUnDirectBindOrder(unDirectBindOrderList.Where(o => !o.IsPause).ToList(), pausedOrderNoList, orderBindingList, sequenceMasterList, sequenceDetailList, dateTimeNow); } #endregion #endregion #region 判断排序装箱单是否要关闭 if (sequenceMasterList != null && sequenceMasterList.Count > 0) { foreach (SequenceMaster sequenceMaster in sequenceMasterList) { if (sequenceDetailList.Where(s => s.SequenceNo == sequenceMaster.SequenceNo && !s.IsClose).Count() == 0) { //排序装箱单的排序明细全部关闭 if (sequenceMaster.Status == CodeMaster.SequenceStatus.Pack) { //自动取消装箱 UnPackSequenceOrder(sequenceMaster); } sequenceMaster.Status = CodeMaster.SequenceStatus.Cancel; sequenceMaster.CancelDate = dateTimeNow; sequenceMaster.CancelUserId = SecurityContextHolder.Get().Id; sequenceMaster.CancelUserName = SecurityContextHolder.Get().FullName; this.genericMgr.Update(sequenceMaster); } } } #endregion }
public void PauseProductOrder(OrderMaster orderMaster, int? pauseOperation) //在指定工序之后暂停 { log.Debug("Start pause product order, orderNo[" + orderMaster.OrderNo + "], operation[" + pauseOperation + "]."); try { #region 检查 if (orderMaster.Status != CodeMaster.OrderStatus.Submit && orderMaster.Status != CodeMaster.OrderStatus.InProcess) { throw new BusinessException("生产单{0}的状态为{1},不能暂停。", orderMaster.OrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.OrderStatus, ((int)orderMaster.Status).ToString())); } if (orderMaster.IsPause || orderMaster.IsPlanPause) { throw new BusinessException("生产单{0}已经暂停。", orderMaster.OrderNo); } if (orderMaster.IsProductLinePause) { throw new BusinessException("生产线{0}已经暂停。", orderMaster.Flow); } if (orderMaster.Status == CodeMaster.OrderStatus.InProcess) { if (!pauseOperation.HasValue) { throw new BusinessException("没有指定暂停的工序。"); } else { #region 检查工序合法性 IList<OrderOperation> orderOperationList = this.genericMgr.FindAll<OrderOperation>("from OrderOperation where OrderNo = ? and Operation = ?", new object[] { orderMaster.OrderNo, pauseOperation.Value }); if (orderOperationList == null || orderOperationList.Count == 0) { throw new BusinessException("生产单{0}没有工序{1}。", orderMaster.OrderNo, pauseOperation.Value.ToString()); } //if (orderOperationList.Where(o => o.IsBackflush).Count() > 0) //{ // throw new BusinessException("生产单{0}的工序{1}已经回冲物料,不能选择该工序暂停。", orderMaster.OrderNo, pauseOperation.Value.ToString()); //} #endregion } } #endregion #region 更新生产单 if (orderMaster.Status == CodeMaster.OrderStatus.Submit) { orderMaster.IsPause = true; orderMaster.PauseTime = DateTime.Now; } else { orderMaster.IsPlanPause = true; orderMaster.PauseSequence = pauseOperation.Value; } this.genericMgr.Update(orderMaster); log.Debug("Success pause main product order, orderNo[" + orderMaster.OrderNo + "]"); #endregion #region 暂停排序单和KIT PauseSequenceAndKitOrder(orderMaster, pauseOperation); #endregion } catch (Exception ex) { log.Error("Fail pause product order, orderNo[" + orderMaster.OrderNo + "], operation[" + pauseOperation + "].", ex); throw ex; } log.Debug("Success pause product order, orderNo[" + orderMaster.OrderNo + "], operation[" + pauseOperation + "]."); }
private BusinessException VerifyVanOrderClose(OrderMaster orderMaster, ProductLineMap productLineMap) { BusinessException businessException = new BusinessException(); #region 生产单关闭校验 #region 条件5生产单的PlanBackflush全部关闭 if (orderMaster.Type == CodeMaster.OrderType.Production || orderMaster.Type == CodeMaster.OrderType.SubContract) { #region 总装生产要校验总装、驾驶室和底盘的PlanBackflush string hql = "select count(*) as counter from PlanBackflush where OrderNo in (?, ?, ?) and IsClose = ?"; long counter = this.genericMgr.FindAll<long>(hql, new Object[] { productLineMap.ProductLine, productLineMap.CabFlow, productLineMap.ChassisFlow, false })[0]; if (counter > 0) { businessException.AddMessage("加权平均扣料的零件还没有进行回冲,不能关闭订单{0}。", orderMaster.OrderNo); } #endregion } #endregion #region 条件6生产线上没有订单的投料 if (orderMaster.Type == CodeMaster.OrderType.Production || orderMaster.Type == CodeMaster.OrderType.SubContract) { #region 总装生产要校验总装、驾驶室和底盘的订单投料 string hql = "select count(*) as counter from ProductLineLocationDetail where OrderNo in (?, ?, ?) and IsClose = ?"; long counter = this.genericMgr.FindAll<long>(hql, new Object[] { productLineMap.ProductLine, productLineMap.CabFlow, productLineMap.ChassisFlow, false })[0]; if (counter > 0) { businessException.AddMessage("生产线上还有投料的零件没有回冲,不能关闭订单{0}。", orderMaster.OrderNo); } #endregion } #endregion #region 条件7和TraceCode所有的失效模式关闭 if ((orderMaster.Type == CodeMaster.OrderType.Production || orderMaster.Type == CodeMaster.OrderType.SubContract) && !string.IsNullOrWhiteSpace(orderMaster.TraceCode)) { #region 只有总装的生产单关闭才需要校验,驾驶室和底盘的不需要 string hql = "select count(*) as counter from IssueMaster where BackYards = ? and Status in (?,?,?)"; long issueCounter = this.genericMgr.FindAll<long>(hql, new Object[] { orderMaster.TraceCode, CodeMaster.IssueStatus.Create, CodeMaster.IssueStatus.Submit, CodeMaster.IssueStatus.InProcess })[0]; if (issueCounter > 0) { businessException.AddMessage("失效模式没有全部关闭,不能关闭订单{0}。", orderMaster.OrderNo); } #endregion } #endregion #region 条件8生产单上的所有关键件全部投料,考虑到搭错的关键件Bom,不需要校验这条,可以给出警告信息 if ((orderMaster.Type == CodeMaster.OrderType.Production || orderMaster.Type == CodeMaster.OrderType.SubContract)) { //throw new NotImplementedException(); } #endregion #endregion return businessException; }
private void CloseVanOrder(OrderMaster vanOrder, ProductLineMap productLineMap) { DateTime dateTimeNow = DateTime.Now; User user = SecurityContextHolder.Get(); #region 总装生产单关闭时,关闭所有子生产单 IList<OrderMaster> subOrderMasterList = this.genericMgr.FindAll<OrderMaster>("from OrderMaster where Type = ? and Flow in (?,?) and Status <> ?", new object[] { CodeMaster.OrderType.Production, productLineMap.CabFlow, productLineMap.ChassisFlow, CodeMaster.OrderStatus.Close }); if (subOrderMasterList != null && subOrderMasterList.Count > 0) { foreach (OrderMaster subOrderMaster in subOrderMasterList) { if (subOrderMaster.Status != CodeMaster.OrderStatus.Complete) { throw new BusinessException("子生产单{0}的状态为{1},整车生产单{2}不能关闭。", subOrderMaster.OrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.OrderStatus, ((int)subOrderMaster.Status).ToString()), vanOrder.OrderNo); } else { subOrderMaster.Status = CodeMaster.OrderStatus.Close; subOrderMaster.CloseDate = dateTimeNow; subOrderMaster.CloseUserId = user.Id; subOrderMaster.CloseUserName = user.FullName; this.genericMgr.Update(subOrderMaster); } } } #endregion #region 关闭总装生产单 vanOrder.Status = CodeMaster.OrderStatus.Close; vanOrder.CloseDate = dateTimeNow; vanOrder.CloseUserId = user.Id; vanOrder.CloseUserName = user.FullName; this.genericMgr.Update(vanOrder); #endregion }
private void CompleteVanSubOrder(OrderMaster vanSubOrder) { DateTime dateTimeNow = DateTime.Now; User user = SecurityContextHolder.Get(); vanSubOrder.Status = CodeMaster.OrderStatus.Complete; vanSubOrder.CompleteDate = dateTimeNow; vanSubOrder.CompleteUserId = user.Id; vanSubOrder.CompleteUserName = user.FullName; this.genericMgr.Update(vanSubOrder); }
private void GenerateOrderBomDetail(OrderDetail orderDetail, OrderMaster orderMaster) { if (orderDetail.ScheduleType == CodeMaster.ScheduleType.MES21 || orderDetail.ScheduleType == CodeMaster.ScheduleType.MES22 || orderDetail.ScheduleType == CodeMaster.ScheduleType.MES23) { //只记录废品数,无材料消耗 return; } if (orderMaster.ProductLineFacility == "EXV") { //不消耗材料 return; } //if (orderMaster.SubType == com.Sconit.CodeMaster.OrderSubType.Return) //{ // //直接退成品 //} #region 查找成品单位和Bom单位的转换关系 //把OrderDetail的收货单位和单位用量转换为BOM单位和单位用量 //fgUom,fgUnityQty代表接收一个orderDetail.Uom单位(等于订单的收货单位)的FG,等于单位(fgUom)有多少(fgUnityQty)值 string fgUom = orderDetail.Uom; //如果和Bom上的单位不一致,转化为Bom上的单位,不然会导致物料回冲不正确。 //查找Bom BomMaster bomMaster = FindOrderDetailBom(orderDetail); decimal fgUnityQty = 1; #region 判断Bom是否有效 if (!bomMaster.IsActive) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_BomInActive, orderDetail.Bom); } #endregion //订单单位和Bom单位不一致,需要做单位转换 if (string.Compare(orderDetail.Uom, bomMaster.Uom) != 0) { fgUom = bomMaster.Uom; fgUnityQty = itemMgr.ConvertItemUomQty(orderDetail.Item, orderDetail.Uom, fgUnityQty, fgUom); } #endregion #region 创建OrderBomDetail //Item fgItem = genericMgr.FindById<Item>(orderDetail.Item); #region 查询Bom明细 IList<BomDetail> bomDetailList = bomMgr.GetFlatBomDetail(bomMaster, orderMaster.StartTime); #endregion var itemCodes = bomDetailList.Select(b => b.Item).Distinct(); #region 查询Bom Item IList<Item> bomItemList = this.genericMgr.FindAllIn<Item>("from Item where Code in(?", itemCodes); #endregion #region 查询工艺流程明细 //IList<RoutingDetail> routingDetailList = null; //if (!string.IsNullOrEmpty(orderDetail.Routing)) //{ // RoutingMaster routing = this.genericMgr.FindById<RoutingMaster>(orderDetail.Routing); // if (!routing.IsActive) // { // throw new BusinessErrorException(Resources.ORD.OrderMaster.Errors_RoutingInActive, orderDetail.Routing); // } // routingDetailList = routingMgr.GetRoutingDetails(orderDetail.Routing, orderMaster.StartTime); //} #endregion #region 查询生产防错明细 SIH客户化是从零件追溯表中取需要扫描的零件。 IList<string> itemTraceList = this.genericMgr.FindAllIn<string> ("select it.Item From ItemTrace as it where it.Item in (?", itemCodes); #endregion foreach (BomDetail bomDetail in bomDetailList) { #region 查找物料的来源库位和提前期 string bomLocFrom = string.Empty; //来源库位查找逻辑RoutingDetail-->OrderDetail-->Order-->BomDetail //工序的优先级最大,因为同一个OrderMaster可以有不同的工艺流程,其次OrderMaster,最后BomDetail TryLoadOrderOperations(orderDetail); if (orderDetail.OrderOperations != null && orderDetail.OrderOperations.Count > 0) { //取RoutingDetail上的 OrderOperation orderOperation = orderDetail.OrderOperations.Where( p => p.Op == bomDetail.Operation && p.OpReference == bomDetail.OpReference).SingleOrDefault(); if (orderOperation != null) { bomLocFrom = orderOperation.Location; } } if (string.IsNullOrEmpty(bomLocFrom)) { //在取OrderDetail上,然后是OrderHead上取 //取默认库位FlowDetail-->Flow if (orderDetail.OrderSubType == CodeMaster.OrderSubType.Normal) { if (!string.IsNullOrEmpty(orderDetail.LocationFrom)) { bomLocFrom = orderDetail.LocationFrom; } else { bomLocFrom = orderMaster.LocationFrom; } } else { if (!string.IsNullOrEmpty(orderDetail.LocationTo)) { bomLocFrom = orderDetail.LocationTo; } else { bomLocFrom = orderMaster.LocationTo; } } } if (string.IsNullOrEmpty(bomLocFrom)) { //最后取BomDetail上的Location bomLocFrom = bomDetail.Location; } #endregion #region 创建生产单物料明细 OrderBomDetail orderBomDetail = new OrderBomDetail(); Item bomItem = bomItemList.Where(i => i.Code == bomDetail.Item).Single(); orderBomDetail.Bom = bomDetail.Bom; orderBomDetail.Item = bomDetail.Item; orderBomDetail.ItemDescription = bomItem.Description; orderBomDetail.Uom = bomDetail.Uom; //Bom单位 //todo 检查Bom Operation和Routing Operation 不匹配的情况 orderBomDetail.Operation = bomDetail.Operation; orderBomDetail.OpReference = bomDetail.OpReference; if (orderMaster.IsListPrice) { orderBomDetail.BomUnitQty = bomDetail.UnitBomQty * fgUnityQty; //单位成品(订单单位),需要消耗物料数量(Bom单位)。 } else { orderBomDetail.BomUnitQty = bomDetail.CalculatedQty * fgUnityQty; //单位成品(订单单位),需要消耗物料数量(Bom单位)。 } orderBomDetail.OrderedQty = orderDetail.OrderedQty * orderBomDetail.BomUnitQty; orderBomDetail.Location = bomLocFrom; orderBomDetail.IsPrint = bomDetail.IsPrint; orderBomDetail.IsScanHu = itemTraceList.Contains(orderBomDetail.Item); //生产防错标记 orderBomDetail.BackFlushMethod = bomDetail.BackFlushMethod; orderBomDetail.FeedMethod = bomDetail.FeedMethod; orderBomDetail.IsAutoFeed = bomDetail.IsAutoFeed; //orderBomDetail.BackFlushInShortHandle = bomDetail.BackFlushInShortHandle; orderBomDetail.EstimateConsumeTime = orderMaster.StartTime; //BomDetail的基本单位 orderBomDetail.BaseUom = bomItem.Uom; if (orderBomDetail.BaseUom != orderBomDetail.Uom) { orderBomDetail.UnitQty = this.itemMgr.ConvertItemUomQty(orderBomDetail.Item, orderBomDetail.Uom, 1, orderBomDetail.BaseUom); } else { orderBomDetail.UnitQty = 1; } orderDetail.AddOrderBomDetail(orderBomDetail); #endregion #region 查找零件消耗提前期,累加所有工序小于等于当前工序的提前期 if (orderDetail.OrderOperations != null) { IList<OrderOperation> orderOperationList = orderDetail.OrderOperations.Where( p => p.Op < bomDetail.Operation //每道工序对应一个工位,不考虑一道工序多工位的情况 //|| (p.Operation == bomDetail.Operation //同道工序多工位的情况 //&& string.Compare(p.OpReference, bomDetail.OpReference) <= 0) ).ToList(); if (orderOperationList != null && orderOperationList.Count > 0) { foreach (OrderOperation orderOperation in orderOperationList) { //switch (orderOperation.TimeUnit) //{ // case com.Sconit.CodeMaster.TimeUnit.Day: // orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromDays(orderOperation.LeadTime)); // break; // case com.Sconit.CodeMaster.TimeUnit.Hour: // orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromHours(orderOperation.LeadTime)); // break; // case com.Sconit.CodeMaster.TimeUnit.Minute: // orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromMinutes(orderOperation.LeadTime)); // break; // case com.Sconit.CodeMaster.TimeUnit.Second: // orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromSeconds(orderOperation.LeadTime)); // break; //}; } } } #endregion #region 更新生产防错标记 //if (productionScanDetailList != null && productionScanDetailList.Count > 0) //{ // ProductionScanDetail productionScanDetail = productionScanDetailList.Where( // p => p.Operation == orderBomDetail.Operation // && p.OpReference == orderBomDetail.OpReference // && p.Item == orderBomDetail.Item).SingleOrDefault(); // if (productionScanDetail != null) // { // orderBomDetail.IsScanHu = true; // } // else // { // orderBomDetail.IsScanHu = false; // } //} #endregion } #region 委外退货 if (orderMaster.SubType == com.Sconit.CodeMaster.OrderSubType.Return) { //更改原材料库位,材料增加 //OrderBomDetail orderBomDetail = new OrderBomDetail(); //orderBomDetail.Item = orderDetail.Item; //orderBomDetail.ItemDescription = orderDetail.ItemDescription; //orderBomDetail.Uom = orderDetail.Uom; //#region 取工序,先取RoutingDetail上最小工序,如果没有取BomDetail的最小工序 //if (orderDetail.OrderOperations != null && orderDetail.OrderOperations.Count() > 0) //{ // //先根据工序排序,在根据工位排序 // OrderOperation orderOperation = orderDetail.OrderOperations // .OrderBy(op => op.Operation) // .ThenBy(op => op.OpReference) // .First(); // orderBomDetail.Operation = orderOperation.Operation; // orderBomDetail.OpReference = orderOperation.OpReference; //} //else //{ // BomDetail bomDetail = bomDetailList.OrderBy(det => det.Operation).ThenBy(det => det.OpReference).First(); // orderBomDetail.Operation = bomDetail.Operation; // orderBomDetail.OpReference = bomDetail.OpReference; //} //#endregion //orderBomDetail.BaseUom = orderDetail.BaseUom; //orderBomDetail.BomUnitQty = 1; //orderBomDetail.OrderedQty = orderDetail.OrderedQty; //orderBomDetail.Location = !string.IsNullOrWhiteSpace(orderDetail.LocationTo) ? orderDetail.LocationTo : orderMaster.LocationTo; //orderBomDetail.IsPrint = false; //orderBomDetail.IsScanHu = orderMaster.IsReceiveScanHu || orderMaster.CreateHuOption == com.Sconit.CodeMaster.CreateHuOption.Receive; //收获扫描Hu或者收货时创建条码,返工时要扫描成品条码 //orderBomDetail.BackFlushMethod = com.Sconit.CodeMaster.BackFlushMethod.GoodsReceive; //orderBomDetail.FeedMethod = com.Sconit.CodeMaster.FeedMethod.None; //orderBomDetail.IsAutoFeed = false; ////orderBomDetail.BackFlushInShortHandle = BomDetail.BackFlushInShortHandleEnum.Nothing; //orderBomDetail.EstimateConsumeTime = orderMaster.StartTime; //预计消耗时间等于开始时间 //orderDetail.AddOrderBomDetail(orderBomDetail); } #endregion #endregion }
private void CheckOrderedQtyFulfillment(OrderMaster orderMaster, OrderDetail orderDetail) { if (orderMaster.IsOrderFulfillUC && !(orderMaster.IsAutoRelease && orderMaster.IsAutoStart) //快速的不考虑 && orderMaster.SubType == com.Sconit.CodeMaster.OrderSubType.Normal) //只考虑正常订单,退货/返工等不考虑 { if (orderDetail.OrderedQty % orderDetail.UnitCount != 0) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_OrderQtyNotFulfillUnitCount, orderDetail.Item, orderDetail.UnitCount.ToString()); } } }
public void ReStartProductOrder(OrderMaster productOrder, Int64 orderSequence) { ReStartProductOrder(productOrder, orderSequence, false); }
private void BeforeBatchUpdateOrderDetails(OrderMaster orderMaster) { BeforeUpdateOrderDetails(orderMaster); }
public void ReStartProductOrder(OrderMaster productOrder, Int64 orderSequence, bool isForce) //暂不支持恢复至另外一条生产线 { //todo:发送恢复通知邮件 #region 检查 if (!productOrder.IsPause) { throw new BusinessException("生产单{0}没有暂停。", productOrder.OrderNo); } if (productOrder.Sequence > orderSequence) { throw new BusinessException("生产单{0}恢复之后的顺序号{1}小于原顺序号。", productOrder.OrderNo, orderSequence.ToString()); } #region 查询插入点之前的生产单 IList<OrderMaster> beforeProductOrderList = this.genericMgr.FindAll<OrderMaster>("from OrderMaster where Type = ? and Flow = ? and Sequence < ? and IsPause = ? order by Sequence", new object[] { productOrder.Type, productOrder.Flow, orderSequence, false }, 0, 1); OrderMaster beforeProductOrder = beforeProductOrderList[0]; #endregion if (beforeProductOrder.Status == CodeMaster.OrderStatus.Create) { throw new BusinessException("小于顺序号{0}的生产单{1}未释放。", orderSequence.ToString(), beforeProductOrder.OrderNo); } #region 查询插入点之后的生产单 IList<OrderMaster> afterProductOrderList = this.genericMgr.FindAll<OrderMaster>("from OrderMaster where Type = ? and Flow = ? and Sequence >= ? and IsPause = ? and Status <> ? order by Sequence", new object[] { productOrder.Type, productOrder.Flow, orderSequence, false, CodeMaster.OrderStatus.Cancel }, 0, 1); OrderMaster afterProductOrder = null; if (afterProductOrderList != null && afterProductOrderList.Count > 0) { afterProductOrder = afterProductOrderList[0]; } #endregion if (afterProductOrder != null) { if (afterProductOrder.Status == CodeMaster.OrderStatus.InProcess && productOrder.Status == CodeMaster.OrderStatus.Submit) { throw new BusinessException("生产单{0}未上线,而大于顺序号{1}的生产单{2}已经上线。", productOrder.OrderNo, orderSequence.ToString(), afterProductOrder.OrderNo); } else if (afterProductOrder.Status == CodeMaster.OrderStatus.Complete) { throw new BusinessException("大于顺序号{0}的生产单{1}已经完工。", orderSequence.ToString(), afterProductOrder.OrderNo); } else if (afterProductOrder.Status == CodeMaster.OrderStatus.Close) { throw new BusinessException("大于顺序号{0}的生产单{1}已经关闭。", orderSequence.ToString(), afterProductOrder.OrderNo); } } #endregion #region 检查生产单恢复后是否能够及时配送 #region 查找工艺流程 OrderDetail orderDetail = TryLoadOrderDetails(productOrder)[0]; string routingCode = !string.IsNullOrWhiteSpace(orderDetail.Routing) ? orderDetail.Routing : productOrder.Routing; if (string.IsNullOrEmpty(routingCode)) { throw new BusinessException("物料{0}没有找到对应的工艺流程。", orderDetail.Item); } RoutingMaster routingMaster = this.genericMgr.FindById<RoutingMaster>(routingCode); #endregion //#region 查询待恢复的Kit单和排序单 //IList<OrderMaster> bindOrderList = this.genericMgr.FindAll<OrderMaster>("from OrderMaster where TraceCode = ? and OrderStrategy in {?, ?} and Status = ? and IsPause = ?", // new object[] { productOrder.TraceCode, CodeMaster.FlowStrategy.KIT, CodeMaster.FlowStrategy.SEQ, CodeMaster.OrderStatus.Submit, true }); //#endregion #region 查询待恢复订单(Kit单、排序单和底盘/驾驶室生产单) IList<OrderMaster> bindOrderList = this.genericMgr.FindAll<OrderMaster>("from OrderMaster where Type = ? and TraceCode = ? and IsPause = ? and OrderNo <> ?", new object[] { productOrder.Type, productOrder.TraceCode, true, productOrder.OrderNo }); #endregion IList<OrderMaster> relativeBindOrderList = null; if (bindOrderList != null && bindOrderList.Count > 0) { #region 查询大于等于或小于顺序号的绑定订单 string hql = string.Empty; IList<object> paras = new List<object>(); foreach (OrderMaster bindOrder in bindOrderList) { if (hql == string.Empty) { hql = "from OrderMaster where Type = ? and Sequence = ? and Flow in (?"; if (afterProductOrder != null && afterProductOrder.Status != CodeMaster.OrderStatus.Create) { paras.Add(afterProductOrder.Type); paras.Add(afterProductOrder.Sequence); } else { paras.Add(beforeProductOrder.Type); paras.Add(beforeProductOrder.Sequence); } } else { hql += ",?"; } paras.Add(bindOrder.Flow); } hql += ")"; relativeBindOrderList = this.genericMgr.FindAll<OrderMaster>(hql, paras); #endregion #region 循环校验KIT件和排序件能否及时配送 foreach (OrderMaster bindOrder in bindOrderList) { OrderMaster relativeBindOrder = relativeBindOrderList.Where(r => r.Flow == bindOrder.Flow).Single(); //一定能够找到匹配的KIT件或排序件 if (afterProductOrder != null && afterProductOrder.Status != CodeMaster.OrderStatus.Create) { #region 大于顺序号的排序件已经生成排序装箱单 if (relativeBindOrder.OrderStrategy == CodeMaster.FlowStrategy.SEQ && relativeBindOrder.Status != CodeMaster.OrderStatus.Submit) { throw new BusinessException("大于顺序号{0}的排序单{1}已经在排序路线{2}生成排序装配单。", orderSequence.ToString(), relativeBindOrder.OrderNo, relativeBindOrder.Flow); } #endregion #region 开始时间检查 //因为生产单恢复后将会替代后面一张生产单的位置,所有后面一张生产单排序件的开始时间就是本生产单恢复后的开始时间 if (!isForce && relativeBindOrder.StartTime < DateTime.Now) { if (relativeBindOrder.OrderStrategy == CodeMaster.FlowStrategy.KIT) { throw new BusinessException("生产单{0}调整至顺序号{1}后KIT路线{2}不能及时配送。", productOrder.OrderNo, orderSequence.ToString(), relativeBindOrder.Flow); } else { throw new BusinessException("生产单{0}调整至顺序号{1}后排序路线{2}不能及时配送。", productOrder.OrderNo, orderSequence.ToString(), relativeBindOrder.Flow); } } #endregion } } #endregion } #endregion #region 恢复生产单及KIT单和排序单顺序 productOrder.IsPause = false; productOrder.PauseTime = null; productOrder.Sequence = orderSequence; #region 重新计算生产单开始时间和窗口时间和当前工位 if (afterProductOrder != null && afterProductOrder.Status != CodeMaster.OrderStatus.Create) { //暂时不考虑把后续订单的窗口时间和当前工位往后递减 productOrder.StartTime = afterProductOrder.StartTime; productOrder.WindowTime = afterProductOrder.WindowTime; productOrder.CurrentOperation = afterProductOrder.CurrentOperation; } else { //加节拍时间 switch (routingMaster.TaktTimeUnit) { case CodeMaster.TimeUnit.Second: productOrder.StartTime = beforeProductOrder.StartTime.AddSeconds(routingMaster.TaktTime); productOrder.WindowTime = beforeProductOrder.WindowTime.AddSeconds(routingMaster.TaktTime); break; case CodeMaster.TimeUnit.Minute: productOrder.StartTime = beforeProductOrder.StartTime.AddMinutes(routingMaster.TaktTime); productOrder.WindowTime = beforeProductOrder.WindowTime.AddMinutes(routingMaster.TaktTime); break; case CodeMaster.TimeUnit.Hour: productOrder.StartTime = beforeProductOrder.StartTime.AddHours(routingMaster.TaktTime); productOrder.WindowTime = beforeProductOrder.WindowTime.AddHours(routingMaster.TaktTime); break; case CodeMaster.TimeUnit.Day: productOrder.StartTime = beforeProductOrder.StartTime.AddDays(routingMaster.TaktTime); productOrder.WindowTime = beforeProductOrder.WindowTime.AddDays(routingMaster.TaktTime); break; }; if (beforeProductOrder.Status == CodeMaster.OrderStatus.Submit) { productOrder.CurrentOperation = null; } else { //查询已经回冲的最大工位 IList maxOpList = this.genericMgr.FindAll("select Max(Operation) as maxOp from OrderOperation where IsBackflush = ? and OrderNo = ?", new object[] { true, beforeProductOrder.OrderNo }); if (maxOpList != null && maxOpList.Count > 0 && maxOpList[0] != null) { productOrder.CurrentOperation = (int)maxOpList[0]; } } } #endregion this.genericMgr.Update(productOrder); foreach (OrderMaster bindOrder in bindOrderList) { bindOrder.IsPause = false; bindOrder.PauseTime = null; bindOrder.Sequence = orderSequence; OrderMaster relativeBindOrder = relativeBindOrderList.Where(r => r.Flow == bindOrder.Flow).Single(); //一定能够找到匹配的KIT件或排序件 if (afterProductOrder != null && afterProductOrder.Status != CodeMaster.OrderStatus.Create) { #region 根据大于等于指定顺序号的生产单恢复 bindOrder.StartTime = relativeBindOrder.StartTime; bindOrder.WindowTime = relativeBindOrder.WindowTime; #endregion } else { #region 根据小于指定顺序号的生产单恢复 //加节拍时间 switch (routingMaster.TaktTimeUnit) { case CodeMaster.TimeUnit.Second: bindOrder.StartTime = relativeBindOrder.StartTime.AddSeconds(routingMaster.TaktTime); bindOrder.WindowTime = relativeBindOrder.WindowTime.AddSeconds(routingMaster.TaktTime); break; case CodeMaster.TimeUnit.Minute: bindOrder.StartTime = relativeBindOrder.StartTime.AddMinutes(routingMaster.TaktTime); bindOrder.WindowTime = relativeBindOrder.WindowTime.AddMinutes(routingMaster.TaktTime); break; case CodeMaster.TimeUnit.Hour: bindOrder.StartTime = relativeBindOrder.StartTime.AddHours(routingMaster.TaktTime); bindOrder.WindowTime = relativeBindOrder.WindowTime.AddHours(routingMaster.TaktTime); break; case CodeMaster.TimeUnit.Day: bindOrder.StartTime = relativeBindOrder.StartTime.AddDays(routingMaster.TaktTime); bindOrder.WindowTime = relativeBindOrder.WindowTime.AddDays(routingMaster.TaktTime); break; }; #endregion } this.genericMgr.Update(bindOrder); } #endregion #region 更新后续生产单的顺序 if (afterProductOrder != null && afterProductOrder.Sequence == productOrder.Sequence) { this.genericMgr.FlushSession(); User user = SecurityContextHolder.Get(); this.genericMgr.FindAllWithNamedQuery("USP_Busi_UpdateSeq4RestoreVanOrder", new object[] { productOrder.TraceCode, productOrder.OrderNo, orderSequence, user.Id, user.FullName }); this.genericMgr.FlushSession(); } #endregion throw new BusinessException(); }
private IList<OrderDetail> TryLoadOrderDetails(OrderMaster orderMaster) { if (!string.IsNullOrWhiteSpace(orderMaster.OrderNo)) { if (orderMaster.OrderDetails == null) { string hql = "from OrderDetail where OrderNo = ? order by Sequence"; orderMaster.OrderDetails = this.genericMgr.FindAll<OrderDetail>(hql, orderMaster.OrderNo); } return orderMaster.OrderDetails; } else { return null; } }
public void CheckOrder(OrderMaster orderMaster) { BusinessException ex = new BusinessException(); if (orderMaster.Type == com.Sconit.CodeMaster.OrderType.CustomerGoods || orderMaster.Type == com.Sconit.CodeMaster.OrderType.Procurement) { ex.AddMessage("订单" + orderMaster.OrderNo + "无需检查库存"); } else { var paramList = new List<object>(); string sql = string.Empty; paramList.Add(orderMaster.LocationFrom); var itemQtyDic = new Dictionary<string, decimal>(); if (orderMaster.Type == CodeMaster.OrderType.Production) { TryLoadOrderBomDetails(orderMaster); if (orderMaster.OrderDetails != null) { itemQtyDic = orderMaster.OrderDetails .SelectMany(p => p.OrderBomDetails) .GroupBy(p => p.Item).ToDictionary(d => d.Key, d => d.Sum(q => q.OrderedQty)); } string hql = @"select distinct(isnull(d.LocFrom,f.LocFrom)) from Scm_FlowDet as d join SCM_FlowMstr f on d.Flow = f.Code where f.IsActive = ? and (d.LocTo =? or (d.LocTo is null and f.LocTo = ? )) and d.Item in(? "; var locations = genericMgr.FindAllWithNativeSqlIn<string> (hql, itemQtyDic.Select(p => p.Key), new object[] { true, orderMaster.LocationFrom, orderMaster.LocationFrom }); foreach (var location in locations) { if (sql == string.Empty) { sql = @" select l.* from VIEW_LocationDet as l with(nolock) where l.ATPQty>0 and l.Location in(?,? "; } else { sql += ",?"; } } paramList.AddRange(locations); } else { TryLoadOrderDetails(orderMaster); if (orderMaster.OrderDetails != null) { itemQtyDic = orderMaster.OrderDetails .GroupBy(p => p.Item).ToDictionary(d => d.Key, d => d.Sum(q => q.OrderedQty)); } sql = @" select l.* from VIEW_LocationDet as l with(nolock) where l.ATPQty>0 and (l.Location =? "; } sql += @" ) and l.Item in(? "; IList<LocationDetailView> locationDetailViewList = this.genericMgr.FindEntityWithNativeSqlIn<LocationDetailView> (sql, itemQtyDic.Select(p => p.Key), paramList); var invDic = (from p in locationDetailViewList group p by p.Item into g select new { Item = g.Key, Qty = g.Sum(q => q.ATPQty) }).ToDictionary(d => d.Item, d => d.Qty); foreach (var itemQty in itemQtyDic) { var diffQty = itemQty.Value - invDic.ValueOrDefault(itemQty.Key); if (diffQty > 0) { ex.AddMessage(string.Format("物料:{0}[{1}]没有足够的库存,缺口:{2}", itemQty.Key, itemMgr.GetCacheItem(itemQty.Key).FullDescription, diffQty.ToString("0.##"))); } } } if (ex.GetMessages() != null && ex.GetMessages().Count > 0) { throw ex; } }
private IList<OrderDetail> ProcessAddOrderDetails(OrderMaster orderMaster, IList<OrderDetail> orderDetailList) { #region 获取最大订单明细序号 string hql = "select max(Sequence) as seq from OrderDetail where OrderNo = ?"; IList<int?> maxSeqList = genericMgr.FindAll<int?>(hql, orderMaster.OrderNo); int maxSeq = maxSeqList[0] != null ? maxSeqList[0].Value : 0; #endregion IList<OrderDetail> returnOrderDetailList = new List<OrderDetail>(); IList<Item> itemList = new List<Item>(); if ((orderMaster.OrderDetails != null && orderMaster.OrderDetails.Count > 0) || (orderDetailList != null && orderDetailList.Count > 0)) { //新增的订单明细的Item要加进来 itemList = this.itemMgr.GetItems(orderMaster.OrderDetails.Union(orderDetailList).Select(det => det.Item).Distinct().ToList()); foreach (OrderDetail orderDetail in orderDetailList) { #region 处理订单明细 //新增的话物料不在itemList中,重新查一把吧 var item = itemList.Where(a => a.Code == orderDetail.Item).FirstOrDefault(); orderDetail.CurrentItem = itemList.Where(a => a.Code == orderDetail.Item).Single(); IList<OrderDetail> newOrderDetailList = ProcessNewOrderDetail(orderDetail, orderMaster, ref maxSeq); #endregion #region 计算价格 //if (orderMaster.Type == com.Sconit.CodeMaster.OrderType.Procurement // || orderMaster.Type == com.Sconit.CodeMaster.OrderType.ScheduleLine // || orderMaster.Type == com.Sconit.CodeMaster.OrderType.Distribution // || orderMaster.Type == com.Sconit.CodeMaster.OrderType.SubContract) //{ // foreach (OrderDetail newOrderDetail in newOrderDetailList) // { // //没有指定价格才需要计价 // if (!newOrderDetail.UnitPrice.HasValue || string.IsNullOrWhiteSpace(newOrderDetail.Currency)) // { // CalculateOrderDetailPrice(newOrderDetail, orderMaster, orderMaster.EffectiveDate); // } // } //} #endregion #region 生成OrderOperation和OrderBomDetail if (orderMaster.Type == com.Sconit.CodeMaster.OrderType.Production || orderMaster.Type == com.Sconit.CodeMaster.OrderType.SubContract) { foreach (OrderDetail newOrderDetail in newOrderDetailList) { GenerateOrderOperation(newOrderDetail, orderMaster); GenerateOrderBomDetail(newOrderDetail, orderMaster); } } #endregion #region 创建OrderDetail foreach (OrderDetail newOrderDetail in newOrderDetailList) { newOrderDetail.OrderNo = orderMaster.OrderNo; newOrderDetail.QualityType = orderMaster.QualityType; genericMgr.Create(newOrderDetail); ProcessAddOrderOperations(orderDetail, orderDetail.OrderOperations); ProcessAddOrderBomDetails(newOrderDetail, newOrderDetail.OrderBomDetails); } #endregion ((List<OrderDetail>)returnOrderDetailList).AddRange(newOrderDetailList); } } return returnOrderDetailList; }
//返回2个列表,1是生成的订单,2是没拉出来的物料 public string[] CreateRequisitionList(OrderMaster orderMaster) { string orderString = string.Empty; string itemString = string.Empty; if (orderMaster.Status != com.Sconit.CodeMaster.OrderStatus.Submit && orderMaster.Status != com.Sconit.CodeMaster.OrderStatus.InProcess) { throw new BusinessException("状态为{1}的试制生产单{0}不能产生拉料单。", orderMaster.OrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.OrderStatus, (int)orderMaster.Status)); } #region 去掉KB件,保存到表里,供查询 string kbCountSql = "select count(*) as count from ORD_OrderBomdet as b inner join ORD_KBOrderBomDet as k on b.Id = k.OrderBomDetId where b.OrderNo = ?"; IList<object> kbBomDetailCount = genericMgr.FindAllWithNativeSql<object>(kbCountSql, new object[] { orderMaster.OrderNo }); if ((int)kbBomDetailCount[0] == 0) { string kbSql = "select d.Id,A.Flow from ORD_OrderBomdet as d inner join (select f.Item,f.Flow,case when f.LocTo is null then m.LocTo else f.LocTo end as LocTo from SCM_FlowDet as f inner join SCM_FlowMstr as m on f.Flow = m.Code where m.FlowStrategy = ? and f.StartDate < ? and (f.EndDate is null or f.EndDate > ?))A on d.Item = A.Item and d.Location = A.LocTo where d.OrderNo = ?"; IList<object[]> kbBomDetailList = genericMgr.FindAllWithNativeSql<object[]>(kbSql, new object[] { (int)com.Sconit.CodeMaster.FlowStrategy.KB, DateTime.Now, DateTime.Now, orderMaster.OrderNo }); if (kbBomDetailList.Count > 0) { foreach (object[] ob in kbBomDetailList) { KBOrderBomDetail kbOrderBomDetail = new KBOrderBomDetail(); kbOrderBomDetail.OrderBomDetId = (int)ob[0]; kbOrderBomDetail.Flow = (string)ob[1]; genericMgr.Create(kbOrderBomDetail); } } } #endregion #region 得出去掉KB件的其他件 string bomDetailSql = "select d.Item,d.Location,d.Uom,d.OrderQty from ORD_OrderBomdet as d where d.OrderNo = ? and not exists (select 1 from SCM_FlowDet as f inner join SCM_FlowMstr as m on f.Flow = m.Code where d.Item = f.Item and ((f.LocTo is not null and d.Location = f.LocTo) or (f.LocTo is null and d.Location = m.LocTo)) and m.FlowStrategy = ?)"; IList<object[]> orderBomDetailList = genericMgr.FindAllWithNativeSql<object[]>(bomDetailSql, new object[] { orderMaster.OrderNo, (int)com.Sconit.CodeMaster.FlowStrategy.KB }); // IList<OrderBomDetail> orderBomDetailList = TryLoadOrderBomDetails(orderMaster); #endregion #region 过滤掉负的 var groupOrderBomDetailList = (from det in orderBomDetailList where (decimal)det[3] > 0 group det by new { Item = (string)det[0], Location = (string)det[1], Uom = (string)det[2] } into result select new OrderBomDetail { Item = result.Key.Item, Location = result.Key.Location, Uom = result.Key.Uom, OrderedQty = result.Sum(t => (decimal)t[3]) }).ToList(); #endregion #region 已经拉过料的 IList<OrderDetail> orderDetailList = genericMgr.FindAll<OrderDetail>("from OrderDetail as d where exists (select 1 from OrderMaster as m where m.OrderNo = d.OrderNo and m.Type = ? and m.ReferenceOrderNo = ?)", new object[] { (int)com.Sconit.CodeMaster.OrderType.Transfer, orderMaster.OrderNo }); var groupOrderDetailList = (from det in orderDetailList group det by new { Item = det.Item, Location = det.LocationTo, Uom = det.Uom } into result select new OrderBomDetail { Item = result.Key.Item, Location = result.Key.Location, OrderedQty = result.Sum(t => (t.OrderedQty * t.UnitQty)) }).ToList(); #endregion #region 求出实际需求 var exactOrderBomDetailList = (from b in groupOrderBomDetailList join d in groupOrderDetailList on new { Location = b.Location, Item = b.Item } equals new { Location = d.Location, Item = d.Item } into bd from result in bd.DefaultIfEmpty() select new OrderBomDetail { Location = b.Location, Item = b.Item, Uom = b.Uom, OrderedQty = b.OrderedQty - (result != null ? result.OrderedQty * itemMgr.ConvertItemUomQty(b.Item, genericMgr.FindById<Item>(result.Item).Uom, 1, b.Uom) : 0) }).ToList().Where(p => p.OrderedQty > 0); if (exactOrderBomDetailList == null || exactOrderBomDetailList.Count() == 0) { throw new BusinessException("试制车生产单{0}物料清单为空。", orderMaster.OrderNo); } #endregion #region 把需求按库位分一下,应该会少一些 IList<OrderMaster> orderMasterList = new List<OrderMaster>(); var locationList = exactOrderBomDetailList.Select(b => b.Location).Distinct().ToList(); foreach (string location in locationList) { FlowMaster transferFlow = null; FlowDetail transferFlowDetail = null; bool isShipScanHu = false; bool isReceiveScanHu = false; string hql = "from FlowDetail as d where exists (select 1 from FlowMaster as f where f.Code = d.Flow and f.Type = ? and f.IsActive = ? and (d.LocationTo = ? or (d.LocationTo is null and f.LocationTo = ?)))"; IList<FlowDetail> transferFlowDetailList = genericMgr.FindAll<FlowDetail>(hql, new object[] { com.Sconit.CodeMaster.OrderType.Transfer, true, location, location }); var lob = exactOrderBomDetailList.Where(p => p.Location == location).ToList(); //发到此库位的bom明细 var nlob = new List<OrderBomDetail>(); //没找到路线明细的orderbomdet #region 找到有路线明细的 foreach (OrderBomDetail orderBomDetail in lob) { transferFlowDetail = transferFlowDetailList.Where(f => f.Item == orderBomDetail.Item).ToList().FirstOrDefault(); if (transferFlowDetail != null) { transferFlow = genericMgr.FindById<FlowMaster>(transferFlowDetail.Flow); isShipScanHu = transferFlow.IsShipScanHu; isReceiveScanHu = transferFlow.IsReceiveScanHu; if (transferFlow.IsAutoCreate && transferFlowDetail.IsAutoCreate) { #region 自动拉料的不需要拉 continue; #endregion } #region 建订单 OrderMaster transferOrderMaster = orderMasterList.Where(o => o.Flow == transferFlow.Code && o.IsShipScanHu == isShipScanHu && o.IsReceiveScanHu == isReceiveScanHu).ToList().SingleOrDefault<OrderMaster>(); if (transferOrderMaster == null) { OrderMaster productionOrder = genericMgr.FindById<OrderMaster>(orderMaster.OrderNo); transferOrderMaster = TransferFlow2Order(transferFlow, null); transferOrderMaster.ReferenceOrderNo = orderMaster.OrderNo; transferOrderMaster.StartTime = DateTime.Now; transferOrderMaster.WindowTime = DateTime.Now; transferOrderMaster.TraceCode = productionOrder.TraceCode; transferOrderMaster.IsShipScanHu = isShipScanHu; transferOrderMaster.IsReceiveScanHu = isReceiveScanHu; transferOrderMaster.IsOrderFulfillUC = false; transferOrderMaster.IsShipFulfillUC = false; transferOrderMaster.IsReceiveFulfillUC = false; if (transferOrderMaster.OrderDetails == null) { transferOrderMaster.OrderDetails = new List<OrderDetail>(); } orderMasterList.Add(transferOrderMaster); } OrderDetail orderDetail = Mapper.Map<OrderDetail, OrderDetail>(transferOrderMaster.OrderDetails.Where(d => d.Item == orderBomDetail.Item && (d.LocationTo == orderBomDetail.Location || (d.LocationTo == null && transferOrderMaster.LocationTo == orderBomDetail.Location))).First()); if (orderDetail.Uom != orderBomDetail.Uom) { orderDetail.UnitQty = this.itemMgr.ConvertItemUomQty(orderBomDetail.Item, orderDetail.Uom, 1, orderBomDetail.Uom); orderDetail.OrderedQty = orderBomDetail.OrderedQty / orderDetail.UnitQty; } else { orderDetail.UnitQty = 1; orderDetail.OrderedQty = orderBomDetail.OrderedQty; } transferOrderMaster.OrderDetails.Add(orderDetail); #endregion } else { nlob.Add(orderBomDetail); } } #endregion #region 没有路线明细的 if (nlob.Count > 0) { #region //根据采购路线查找生产单BOM物料的采购入库地点,作为来源库位,取生产单BOM的库位为目的库位,生成要货单。 //因为一条路线上可能包含关键件和非关键件,收货入库可能条码也可能数量 //发货是否扫描条码要跟据采购路线的收货扫描条码选项 //收货是否扫描条码要根据是否关键件(itemtrace) foreach (OrderBomDetail orderBomDetail in nlob) { //采购的以头上的为准 string procuremenSql = "select case when d.LocTo is null then m.LocTo else d.LocTo end as LocTo,m.IsRecScanHu from SCM_FlowDet as d inner join SCM_FlowMstr as m on d.Flow = m.Code where m.Type = ? and m.IsActive = ? and d.Item = ?"; IList<object[]> procurementFlowList = genericMgr.FindAllWithNativeSql<object[]>(procuremenSql, new object[] { com.Sconit.CodeMaster.OrderType.Procurement, true, orderBomDetail.Item }); if (procurementFlowList == null || procurementFlowList.Count == 0) { // throw new BusinessException("找不到物料{0}对应的采购路线", orderBomDetail.Item); itemString += string.IsNullOrEmpty(itemString) ? orderBomDetail.Item : "," + orderBomDetail.Item; continue; } object[] procurementFlow = procurementFlowList[0]; hql = "from FlowMaster as f where f.Type = ? and f.LocationFrom = ? and f.LocationTo = ? and f.IsActive = ? and f.IsAutoCreate = ?"; IList<FlowMaster> transferFlowList = genericMgr.FindAll<FlowMaster>(hql, new object[] { com.Sconit.CodeMaster.OrderType.Transfer, (string)procurementFlow[0], orderBomDetail.Location, true, false }); if (transferFlowList == null || transferFlowList.Count == 0) { // throw new BusinessException("找不到物料{0}对应的来源库位{1},目的库位{2}的移库路线", orderBomDetail.Item); itemString += string.IsNullOrEmpty(itemString) ? (string)procurementFlow[0] + ":" + orderBomDetail.Item : "," + (string)procurementFlow[0] + ":" + orderBomDetail.Item; continue; } transferFlow = transferFlowList[0]; isShipScanHu = (bool)procurementFlow[1]; //IList<ItemTrace> itemTraceList = genericMgr.FindAll<ItemTrace>("from ItemTrace as i where i.Item = ?", orderBomDetail.Item); //isReceiveScanHu = (itemTraceList == null || itemTraceList.Count() == 0) ? false : true; #region 建订单 OrderMaster transferOrderMaster = orderMasterList.Where(o => o.Flow == transferFlow.Code && o.IsShipScanHu == isShipScanHu && o.IsReceiveScanHu == isReceiveScanHu).ToList().SingleOrDefault<OrderMaster>(); if (transferOrderMaster == null) { OrderMaster productionOrder = genericMgr.FindById<OrderMaster>(orderMaster.OrderNo); transferOrderMaster = TransferFlow2Order(transferFlow, null); transferOrderMaster.ReferenceOrderNo = orderMaster.OrderNo; transferOrderMaster.StartTime = DateTime.Now; transferOrderMaster.WindowTime = DateTime.Now; transferOrderMaster.TraceCode = productionOrder.TraceCode; transferOrderMaster.IsShipScanHu = isShipScanHu; transferOrderMaster.IsReceiveScanHu = isReceiveScanHu; transferOrderMaster.IsOrderFulfillUC = false; transferOrderMaster.IsShipFulfillUC = false; transferOrderMaster.IsReceiveFulfillUC = false; if (transferOrderMaster.OrderDetails == null) { transferOrderMaster.OrderDetails = new List<OrderDetail>(); } orderMasterList.Add(transferOrderMaster); } OrderDetail orderDetail = new OrderDetail(); Mapper.Map(orderBomDetail, orderDetail); Item item = genericMgr.FindById<Item>(orderBomDetail.Item); orderDetail.ItemDescription = item.Description; orderDetail.UnitCount = item.UnitCount; orderDetail.BaseUom = item.Uom; orderDetail.LocationFrom = transferOrderMaster.LocationFrom; orderDetail.LocationTo = transferOrderMaster.LocationTo; orderDetail.LocationFromName = transferOrderMaster.LocationFromName; orderDetail.LocationToName = transferOrderMaster.LocationToName; transferOrderMaster.OrderDetails.Add(orderDetail); #endregion } #endregion } #endregion #region 老代码 //foreach (OrderBomDetail orderBomDetail in exactOrderBomDetailList) //{ // //如果根据bom中的子物料以及库位能够对应到路线明细,则以该路线明细来生成要货单 // //如果根据以上无法得到路线明细,则根据采购路线查找生产单BOM物料的采购入库地点,作为来源库位,取生产单BOM的库位为目的库位,生成要货单。 // FlowMaster transferFlow = null; // FlowDetail transferFlowDetail = null; // string hql = "from FlowDetail as d where d.Item = ? and exists (select 1 from FlowMaster as f where f.Code = d.Flow and f.Type = ? and f.IsActive = ? and (d.LocationTo = ? or (d.LocationTo is null and f.LocationTo = ?))) order by d.IsAutoCreate desc"; // IList<FlowDetail> transferFlowDetailList = genericMgr.FindAll<FlowDetail>(hql, new object[] { orderBomDetail.Item, com.Sconit.CodeMaster.OrderType.Transfer, true, orderBomDetail.Location, orderBomDetail.Location }); // bool isShipScanHu = false; // bool isReceiveScanHu = false; // if (transferFlowDetailList != null && transferFlowDetailList.Count > 0) // { // transferFlow = genericMgr.FindById<FlowMaster>(transferFlowDetailList[0].Flow); // isShipScanHu = transferFlow.IsShipScanHu; // isReceiveScanHu = transferFlow.IsReceiveScanHu; // transferFlowDetail = transferFlowDetailList[0]; // if (transferFlow.IsAutoCreate && transferFlowDetail.IsAutoCreate) // { // #region 自动拉料的不需要拉 // continue; // #endregion // } // } // else // { // #region 则根据采购路线查找生产单BOM物料的采购入库地点,作为来源库位,取生产单BOM的库位为目的库位,生成要货单。 // //因为一条路线上可能包含关键件和非关键件,收货入库可能条码也可能数量 // //发货是否扫描条码要跟据采购路线的收货扫描条码选项 // //收货是否扫描条码要根据是否关键件(itemtrace) // FlowMaster procurementFlow = GetSourceFlow(orderBomDetail.Item, orderBomDetail.Location, new List<string>()); // if (procurementFlow == null) // { // // throw new BusinessException("找不到物料{0}对应的采购路线", orderBomDetail.Item); // itemString += string.IsNullOrEmpty(itemString) ? orderBomDetail.Item : "," + orderBomDetail.Item; // continue; // } // hql = "from FlowMaster as f where f.Type = ? and f.LocationFrom = ? and f.LocationTo = ? and f.IsActive = ?"; // IList<FlowMaster> transferFlowList = genericMgr.FindAll<FlowMaster>(hql, new object[] { com.Sconit.CodeMaster.OrderType.Transfer, procurementFlow.LocationTo, orderBomDetail.Location, true }); // if (transferFlowList == null || transferFlowList.Count == 0) // { // // throw new BusinessException("找不到物料{0}对应的来源库位{1},目的库位{2}的移库路线", orderBomDetail.Item); // itemString += string.IsNullOrEmpty(itemString) ? orderBomDetail.Item : "," + orderBomDetail.Item; // continue; // } // #endregion // transferFlow = transferFlowList[0]; // isShipScanHu = procurementFlow.IsReceiveScanHu; // IList<ItemTrace> itemTraceList = genericMgr.FindAll<ItemTrace>("from ItemTrace as i where i.Item = ?", orderBomDetail.Item); // isReceiveScanHu = (itemTraceList == null || itemTraceList.Count() == 0) ? false : true; // } #endregion } #endregion foreach (OrderMaster om in orderMasterList) { CreateOrder(om); orderString += string.IsNullOrEmpty(orderString) ? om.OrderNo : "," + om.OrderNo; } return new string[2] { orderString, itemString }; }
private IList<OrderDetail> LoadExceptOrderDetail(OrderMaster orderMaster) { if (orderMaster.OrderDetails != null && orderMaster.OrderDetails.Count > 0) { string hql = string.Empty; IList<object> paras = new List<object>(); foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { if (hql == string.Empty) { hql = "from OrderDetail where OrderNo = ? and Id not in (?"; paras.Add(orderMaster.OrderNo); } else { hql += ",?"; } paras.Add(orderDetail.Id); } hql += ")"; return this.genericMgr.FindAll<OrderDetail>(hql, paras.ToArray()); } else { return this.TryLoadOrderDetails(orderMaster); } }
public void UpdateOrder(OrderMaster orderMaster) { if (!Utility.SecurityHelper.HasPermission(orderMaster)) { throw new BusinessException("没有此订单{0}的操作权限。", orderMaster.OrderNo); } if (orderMaster.OrderNo == null) { throw new TechnicalException("OrderNo not specified for OrderMaster."); } if (orderMaster.Status == com.Sconit.CodeMaster.OrderStatus.Create) { this.genericMgr.Update(orderMaster); var orderDetails = this.genericMgr.FindAll<OrderDetail> (" from OrderDetail where OrderNo =? ", orderMaster.OrderNo); foreach (var orderDetail in orderDetails) { orderDetail.QualityType = orderMaster.QualityType; this.genericMgr.Update(orderDetail); } } else { throw new BusinessException(Resources.ORD.OrderMaster.Errors_StatusErrorWhenModify, orderMaster.OrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.OrderStatus, ((int)orderMaster.Status).ToString())); } }
private IList<OrderDetail> ProcessUpdateOrderDetails(OrderMaster orderMaster, IList<OrderDetail> orderDetailList) { IList<OrderDetail> returnOrderDetailList = new List<OrderDetail>(); IList<OrderDetail> destinationOrderDetailList = this.LoadOrderDetails(orderDetailList.Select(det => det.Id).ToArray()); IList<Item> itemList = this.itemMgr.GetItems(destinationOrderDetailList.Select(det => det.Item).Distinct().ToList()); foreach (OrderDetail orderDetail in orderDetailList) { OrderDetail destinationOrderDetail = destinationOrderDetailList.Where(det => det.Id == orderDetail.Id).Single(); //最好不要支持修改零件,如果改为Kit就不好办了 string oldDetItem = destinationOrderDetail.Item; string oldDetUom = destinationOrderDetail.Uom; string oldDetRouting = destinationOrderDetail.Routing; string oldDetBom = destinationOrderDetail.Bom; //string oldProductionScan = destinationOrderDetail.ProductionScan; decimal oldDetOrderedQty = destinationOrderDetail.OrderedQty; Mapper.Map<OrderDetail, OrderDetail>(orderDetail, destinationOrderDetail); #region 整包校验 CheckOrderedQtyFulfillment(orderMaster, destinationOrderDetail); #endregion #region 单位改变或者零件改变,重新生成UnitQty if (string.Compare(oldDetUom, destinationOrderDetail.Uom) != 0 || string.Compare(oldDetItem, destinationOrderDetail.Item) != 0) { Item item = itemList.Where(a => a.Code == orderDetail.Item).Single(); if (destinationOrderDetail.Uom != item.Uom) { destinationOrderDetail.UnitQty = itemMgr.ConvertItemUomQty(destinationOrderDetail.Item, item.Uom, 1, destinationOrderDetail.Uom); } else { destinationOrderDetail.UnitQty = 1; } } #endregion #region 判断是否需要重新生成OrderOperation和OrderBomDetail if (orderMaster.Type == com.Sconit.CodeMaster.OrderType.Production || orderMaster.Type == com.Sconit.CodeMaster.OrderType.SubContract) { //明细的Routing改变了,或者零件改变了 //重新计算OrderOperation if (string.Compare(oldDetItem, destinationOrderDetail.Item) != 0 || string.Compare(oldDetRouting, destinationOrderDetail.Routing) != 0) { ExpandOrderOperation(orderMaster, destinationOrderDetail); } //明细的Bom改变了,或者订单单位改变了,或者明细的Routing改变了,,或者零件改变了, //或者明细的防错扫描改变了 //重新计算OrderBomDetail if (string.Compare(oldDetItem, destinationOrderDetail.Item) != 0 || string.Compare(oldDetBom, destinationOrderDetail.Bom) != 0 || string.Compare(oldDetUom, destinationOrderDetail.Uom) != 0 || string.Compare(oldDetRouting, destinationOrderDetail.Routing) != 0 //|| destinationOrderDetail.ProductionScan != oldProductionScan ) { ExpandOrderBomDetail(orderMaster, destinationOrderDetail); } else if (destinationOrderDetail.OrderedQty != oldDetOrderedQty) { //如果订单量发生变化,需要重新计算Bom用量 TryLoadOrderBomDetails(destinationOrderDetail); foreach (OrderBomDetail orderBomDetail in destinationOrderDetail.OrderBomDetails) { orderBomDetail.OrderedQty = destinationOrderDetail.OrderedQty * orderBomDetail.BomUnitQty; genericMgr.Update(orderBomDetail); } } } #endregion this.genericMgr.Update(destinationOrderDetail); returnOrderDetailList.Add(destinationOrderDetail); } return returnOrderDetailList; }
public string CreateFreeTransferOrderMaster(string regionFromCode, string regionToCode, IList<OrderDetail> orderDetailList, DateTime effectiveDate) { if (orderDetailList == null || orderDetailList.Count == 0) { throw new BusinessException("移库明细不能为空"); } var orderMaster = new OrderMaster(); var regionFrom = genericMgr.FindById<Region>(regionFromCode); var regionTo = genericMgr.FindById<Region>(regionToCode); Location locFrom = genericMgr.FindById<Location>(orderDetailList[0].LocationFrom); Location locTo = genericMgr.FindById<Location>(orderDetailList[0].LocationTo); orderMaster.LocationFrom = locFrom.Code; orderMaster.IsShipScanHu = false; orderMaster.IsReceiveScanHu = false; orderMaster.LocationFromName = locFrom.Name; orderMaster.LocationTo = locTo.Code; orderMaster.LocationToName = locTo.Name; orderMaster.PartyFrom = regionFrom.Code; orderMaster.PartyFromName = regionFrom.Name; orderMaster.PartyTo = regionTo.Code; orderMaster.PartyToName = regionTo.Name; orderMaster.Type = CodeMaster.OrderType.Transfer; orderMaster.StartTime = DateTime.Now; orderMaster.WindowTime = DateTime.Now; orderMaster.EffectiveDate = effectiveDate; orderMaster.IsQuick = true; foreach (OrderDetail od in orderDetailList) { Item item = genericMgr.FindById<Item>(od.Item); Location dLocFrom = genericMgr.FindById<Location>(od.LocationFrom); Location dLocTo = genericMgr.FindById<Location>(od.LocationTo); //Location dLocFrom = genericMgr.FindById<Location>(od.LocationFrom); od.Uom = item.Uom; od.ItemDescription = item.Description; od.ReferenceItemCode = item.ReferenceCode; od.LocationFromName = dLocFrom.Name; od.LocationToName = dLocTo.Name; od.UnitCount = item.UnitCount; } orderMaster.OrderDetails = orderDetailList; this.CreateOrder(orderMaster); return orderMaster.OrderNo; }
//public void SendPrintData(OrderMaster orderMaster) private void AsyncSendPrintData(OrderMaster orderMaster) { if (orderMaster.SubType == CodeMaster.OrderSubType.Return) { return; } //AsyncSend asyncSend = new AsyncSend(this.SendPrintData); //asyncSend.BeginInvoke(masterData, isOrder, null, null); if (orderMaster.IsPrintOrder) { try { var subPrintOrderList = this.genericMgr.FindAll<SubPrintOrder>(); var pubPrintOrders = subPrintOrderList.Where(p => (p.Flow == orderMaster.Flow || string.IsNullOrWhiteSpace(p.Flow)) && (p.UserId == orderMaster.ReleaseUserId || p.UserId == 0) && (p.Region == orderMaster.PartyFrom || string.IsNullOrWhiteSpace(p.Region)) && (p.Location == orderMaster.LocationFrom || string.IsNullOrWhiteSpace(p.Location)) && p.ExcelTemplate == orderMaster.OrderTemplate) .Select(p => new PubPrintOrder { Client = p.Client, ExcelTemplate = p.ExcelTemplate, Code = orderMaster.OrderNo, Printer = p.Printer }); foreach (var pubPrintOrder in pubPrintOrders) { this.genericMgr.Create(pubPrintOrder); } } catch (Exception ex) { pubSubLog.Error("Send data to print sevrer error:", ex); } } }
private void GenerateOrderOperation(OrderDetail orderDetail, OrderMaster orderMaster) { string routingCode = !string.IsNullOrWhiteSpace(orderDetail.Routing) ? orderDetail.Routing : orderMaster.Routing; if (!string.IsNullOrWhiteSpace(routingCode)) { RoutingMaster routing = this.genericMgr.FindById<RoutingMaster>(routingCode); IList<RoutingDetail> routingDetailList = routingMgr.GetRoutingDetails(routingCode, orderMaster.StartTime); if (routingDetailList != null && routingDetailList.Count() > 0) { IList<OrderOperation> orderOperationList = (from det in routingDetailList select new OrderOperation { Op = det.Operation, OpReference = det.OpReference, Location = det.Location }).OrderBy(det => det.Op).ThenBy(det => det.OpReference).ToList(); orderDetail.OrderOperations = orderOperationList; } else { throw new BusinessException(Resources.PRD.Routing.Errors_RoutingDetailNotFound, routingCode); } } }