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 ActionResult _AjaxNewList(GridCommand command, ReceiptMasterSearchModel searchModel) { if (command.SortDescriptors.Count > 0) { if (command.SortDescriptors[0].Member == "ExternalOrderNo") { command.SortDescriptors[0].Member = "ExtNo"; } else if (command.SortDescriptors[0].Member == "OrderedQty") { command.SortDescriptors[0].Member = "OrderQty"; } else if (command.SortDescriptors[0].Member == "MastPartyFrom") { command.SortDescriptors[0].Member = "PartyFrom"; } else if (command.SortDescriptors[0].Member == "MastPartyTo") { command.SortDescriptors[0].Member = "PartyTo"; } else if (command.SortDescriptors[0].Member == "LocationTo") { command.SortDescriptors[0].Member = "LocFrom"; } } SqlParameter[] parameters = new SqlParameter[12]; parameters[0] = new SqlParameter("@OrderNo", System.Data.SqlDbType.VarChar,50); parameters[0].Value = searchModel.OrderNo; parameters[1] = new SqlParameter("@LocFrom", System.Data.SqlDbType.VarChar, 50); parameters[1].Value = searchModel.LocFrom; parameters[2] = new SqlParameter("@Item", System.Data.SqlDbType.VarChar, 50); parameters[2].Value = searchModel.Item; parameters[3] = new SqlParameter("@ExtNo", System.Data.SqlDbType.VarChar, 50); parameters[3].Value = searchModel.ExtNo; parameters[4] = new SqlParameter("@ExtSeq", System.Data.SqlDbType.VarChar, 50); parameters[4].Value = searchModel.ExtSeq; parameters[5] = new SqlParameter("@StartDate", System.Data.SqlDbType.DateTime); parameters[5].Value = searchModel.StartDate; parameters[6] = new SqlParameter("@EndDate", System.Data.SqlDbType.DateTime); parameters[6].Value = searchModel.EndDate; parameters[7] = new SqlParameter("@SortCloumn", System.Data.SqlDbType.VarChar, 50); parameters[7].Value = command.SortDescriptors.Count > 0 ? command.SortDescriptors[0].Member : string.Empty; parameters[8] = new SqlParameter("@SortRule", System.Data.SqlDbType.VarChar, 50); parameters[8].Value = command.SortDescriptors.Count > 0 ? command.SortDescriptors[0].SortDirection == ListSortDirection.Descending ? "desc" : "asc" : string.Empty; parameters[9] = new SqlParameter("@PageSize", SqlDbType.Int); parameters[9].Value = command.PageSize; parameters[10] = new SqlParameter("@Page", SqlDbType.Int); parameters[10].Value = command.Page; parameters[11] = new SqlParameter("@RowCount", System.Data.SqlDbType.VarChar, 50); parameters[11].Direction = ParameterDirection.Output; IList<OrderDetail> returList = new List<OrderDetail>(); try { DataSet dataSet = sqlDao.GetDatasetByStoredProcedure("USP_Search_CreateRequisitionDetail", parameters, false); //det.Id,det.OrderNo,det.ExtNo,det.ExtSeq,det.Item,det.ItemDesc,det.RefItemCode,det.Uom,det.UC,det.LocFrom, // //det.LocTo,det.OrderQty,det.RecQty,det.CreateDate,fm.Code,fm.Desc1,fm.PartyFrom,fm.PartyTo,fd.Container,fd.ContainerDesc if (dataSet.Tables[0] != null && dataSet.Tables[0].Rows.Count > 0) { foreach (DataRow row in dataSet.Tables[0].Rows) { //row.ItemArray[0].ToString() OrderDetail det = new OrderDetail(); det.Id = Convert.ToInt32(row.ItemArray[0].ToString()); det.OrderNo = row.ItemArray[1].ToString(); det.ExternalOrderNo = row.ItemArray[2].ToString(); det.ExternalSequence = row.ItemArray[3].ToString(); det.Item = row.ItemArray[4].ToString(); det.ItemDescription = row.ItemArray[5].ToString(); det.ReferenceItemCode = row.ItemArray[6].ToString(); det.Uom = row.ItemArray[7].ToString(); det.BaseUom = row.ItemArray[7].ToString(); det.UnitCount = Convert.ToDecimal(row.ItemArray[8]); det.MinUnitCount = Convert.ToDecimal(row.ItemArray[8]); det.LocationTo = row.ItemArray[9].ToString(); det.OrderedQty = Convert.ToDecimal(row.ItemArray[11]); det.RejectedQty = Convert.ToDecimal(row.ItemArray[12]); det.CreateDate = Convert.ToDateTime(row.ItemArray[13]); det.Flow = row.ItemArray[14].ToString(); det.FlowDescription = row.ItemArray[15].ToString(); det.MastPartyFrom = row.ItemArray[16].ToString(); det.PartyTo = row.ItemArray[17].ToString(); det.Container = row.ItemArray[18].ToString(); det.ContainerDescription = row.ItemArray[19].ToString(); returList.Add(det); } } } catch (BusinessException be) { SaveBusinessExceptionMessage(be); } catch (Exception ex) { if (ex.InnerException != null) { if (ex.InnerException.InnerException != null) { SaveErrorMessage(ex.InnerException.InnerException.Message); } else { SaveErrorMessage(ex.InnerException.Message); } } else { SaveErrorMessage(ex.Message); } } GridModel<OrderDetail> gridModel = new GridModel<OrderDetail>(); gridModel.Total = string.IsNullOrWhiteSpace(parameters[11].Value.ToString()) ? 0 : Convert.ToInt32(parameters[11].Value); gridModel.Data = returList; TempData["DetailList"] = returList; return PartialView(gridModel); }
private IList<OrderBomDetail> TryLoadOrderBomDetails(OrderDetail orderDetail) { if (orderDetail.Id != 0) { if (orderDetail.OrderBomDetails == null) { string hql = "from OrderBomDetail where OrderDetailId = ? order by Operation, OpReference"; orderDetail.OrderBomDetails = this.genericMgr.FindAll<OrderBomDetail>(hql, orderDetail.Id); } return orderDetail.OrderBomDetails; } else { return null; } }
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 BomMaster FindOrderDetailBom(OrderDetail orderDetail) { //Bom的选取顺序orderDetail.Bom(Copy from 路线明细) --> orderDetail.Item.Bom--> 用orderDetail.Item.Code作为BomCode if (string.IsNullOrWhiteSpace(orderDetail.Bom)) { orderDetail.Bom = bomMgr.FindItemBom(orderDetail.Item); } try { BomMaster bom = genericMgr.FindById<BomMaster>(orderDetail.Bom); orderDetail.Bom = bom.Code; return bom; } catch (ObjectNotFoundException) { throw new BusinessException(Resources.PRD.Bom.Errors_ItemBomNotFound, orderDetail.Item); } }
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); } } }
public string[] CreateEmTransferOrderFromXls(Stream inputStream) { string orderStr = string.Empty; string itemStr = string.Empty; if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); ImportHelper.JumpRows(rows, 11); #region 列定义 int colItem = 1;//物料代码 int colUom = 3;//单位 int colLocTo = 4;// 目的库位 int colQty = 5;//数量 int colWindowTime = 6;//窗口时间 #endregion DateTime dateTimeNow = DateTime.Now; IList<OrderDetail> exactOrderDetailList = new List<OrderDetail>(); while (rows.MoveNext()) { HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 9)) { break;//边界 } string itemCode = string.Empty; decimal qty = 0; string uomCode = string.Empty; string locationCode = string.Empty; DateTime windowTime = DateTime.Now; #region 读取数据 #region 读取物料代码 itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItem)); if (itemCode == null || itemCode.Trim() == string.Empty) { ImportHelper.ThrowCommonError(row.RowNum, colItem, row.GetCell(colItem)); } #endregion #region 读取单位 uomCode = row.GetCell(colUom) != null ? row.GetCell(colUom).StringCellValue : string.Empty; if (uomCode == null || uomCode.Trim() == string.Empty) { throw new BusinessException("Import.Read.Error.Empty", (row.RowNum + 1).ToString(), colUom.ToString()); } #endregion #endregion #region 读取库位 locationCode = row.GetCell(colLocTo) != null ? row.GetCell(colLocTo).StringCellValue : string.Empty; if (locationCode == null || locationCode.Trim() == string.Empty) { throw new BusinessException("Import.Read.Error.Empty", (row.RowNum + 1).ToString(), colLocTo.ToString()); } #endregion #region 读取窗口时间 try { windowTime = row.GetCell(colWindowTime).DateCellValue; } catch { ImportHelper.ThrowCommonError(row.RowNum, colWindowTime, row.GetCell(colWindowTime)); } #endregion #region 读取数量 try { qty = Convert.ToDecimal(row.GetCell(colQty).NumericCellValue); } catch { ImportHelper.ThrowCommonError(row.RowNum, colQty, row.GetCell(colQty)); } #endregion #region 填充数据 OrderDetail od = new OrderDetail(); od.LocationTo = locationCode; od.Item = itemCode; od.Uom = uomCode; od.OrderedQty = qty; od.WindowTime = windowTime; exactOrderDetailList.Add(od); #endregion } #region 创建要货单 //IList<WorkingCalendarView> workView=genericMgr.FindAll <WorkingCalendarView>("select v from WorkingCalendarView as v"); IList<OrderMaster> orderMasterList = new List<OrderMaster>(); var locationList = exactOrderDetailList.Select(b => b.LocationTo).Distinct().ToList(); foreach (string location in locationList) { FlowMaster transferFlow = null; FlowDetail transferFlowDetail = null; FlowStrategy transferFlowStrategy = null; 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 f.FlowStrategy not in (?,?) 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, com.Sconit.CodeMaster.FlowStrategy.KIT, com.Sconit.CodeMaster.FlowStrategy.SEQ, location, location }); var lod = exactOrderDetailList.Where(p => p.LocationTo == location).ToList(); //发到此库位的order明细 var nod = new List<OrderDetail>(); //没找到路线明细的orderdet #region 找到有路线明细的 foreach (OrderDetail od in lod) { transferFlowDetail = transferFlowDetailList.Where(f => f.Item == od.Item).ToList().FirstOrDefault(); if (transferFlowDetail != null) { transferFlow = genericMgr.FindById<FlowMaster>(transferFlowDetail.Flow); transferFlowStrategy = genericMgr.FindById<FlowStrategy>(transferFlow.Code); #region 建订单 OrderMaster transferOrderMaster = orderMasterList.Where(o => o.Flow == transferFlow.Code && o.WindowTime == od.WindowTime).ToList().SingleOrDefault<OrderMaster>(); if (transferOrderMaster == null) { transferOrderMaster = TransferFlow2Order(transferFlow, null); transferOrderMaster.WindowTime = od.WindowTime == null ? DateTime.Now : od.WindowTime.Value; IList<WorkingCalendarView> workingCalendarViewList = this.workingCalendarMgr.GetWorkingCalendarViewList(transferOrderMaster.PartyFrom, transferOrderMaster.Flow, transferOrderMaster.WindowTime.Add(TimeSpan.FromDays(-7)), transferOrderMaster.WindowTime); transferOrderMaster.StartTime = this.workingCalendarMgr.GetStartTimeAtWorkingDate(transferOrderMaster.WindowTime, (double)transferFlowStrategy.EmergencyLeadTime, CodeMaster.TimeUnit.Hour, transferFlow.PartyFrom, transferFlow.Code, workingCalendarViewList); transferOrderMaster.IsAutoRelease = true; if (transferOrderMaster.OrderDetails == null) { transferOrderMaster.OrderDetails = new List<OrderDetail>(); } orderMasterList.Add(transferOrderMaster); //orderStr += string.IsNullOrEmpty(orderStr) ? transferOrderMaster.OrderNo : "," + transferOrderMaster.OrderNo; } OrderDetail orderDetail = Mapper.Map<OrderDetail, OrderDetail>(transferOrderMaster.OrderDetails.Where(d => d.Item == od.Item && (d.LocationTo == od.LocationTo || (d.LocationTo == null && transferOrderMaster.LocationTo == od.LocationTo))).First()); if (orderDetail.Uom != od.Uom) { orderDetail.UnitQty = this.itemMgr.ConvertItemUomQty(od.Item, orderDetail.Uom, 1, od.Uom); orderDetail.OrderedQty = od.OrderedQty / orderDetail.UnitQty; } else { orderDetail.UnitQty = 1; orderDetail.OrderedQty = od.OrderedQty; } transferOrderMaster.OrderDetails.Add(orderDetail); #endregion } else { itemStr += string.IsNullOrEmpty(itemStr) ? od.Item : "," + od.Item; } } #endregion } foreach (OrderMaster om in orderMasterList) { CreateOrder(om); orderStr += string.IsNullOrEmpty(orderStr) ? om.OrderNo : "," + om.OrderNo; } #endregion return new string[] { orderStr, itemStr }; }
public void CreateInspectTransfer(Location location, IList<InspectDetail> inspectDetailList) { var orderMaster = new Entity.ORD.OrderMaster(); var inspectNoList = (from inp in inspectDetailList select inp.InspectNo).Distinct().ToList(); if (inspectNoList.Count() > 1) { throw new BusinessException("多个报验单待验明细不能合并移库。"); } InspectMaster inspectMaster = genericMgr.FindById<InspectMaster>(inspectNoList[0]); var locationFrom = this.genericMgr.FindById<Entity.MD.Location>(inspectDetailList[0].LocationFrom); var partyFrom = this.genericMgr.FindById<Entity.MD.Party>(locationFrom.Region); var partyTo = this.genericMgr.FindById<Entity.MD.Party>(location.Region); orderMaster.LocationFrom = locationFrom.Code; orderMaster.IsShipScanHu = inspectMaster.Type == com.Sconit.CodeMaster.InspectType.Barcode; orderMaster.IsReceiveScanHu = inspectMaster.Type == com.Sconit.CodeMaster.InspectType.Barcode; orderMaster.LocationFromName = locationFrom.Name; orderMaster.LocationTo = location.Code; orderMaster.LocationToName = location.Name; orderMaster.PartyFrom = partyFrom.Code; orderMaster.PartyFromName = partyFrom.Name; orderMaster.PartyTo = partyTo.Code; orderMaster.PartyToName = partyTo.Name; orderMaster.Type = CodeMaster.OrderType.Transfer; orderMaster.StartTime = DateTime.Now; orderMaster.WindowTime = DateTime.Now; orderMaster.EffectiveDate = DateTime.Now; orderMaster.QualityType = com.Sconit.CodeMaster.QualityType.Inspect; orderMaster.IsQuick = true; orderMaster.OrderDetails = new List<OrderDetail>(); int seq = 1; var groupInspectDetailList = from d in inspectDetailList group d by new { d.Item, d.CurrentLocation } into result select result; foreach (var inspectDetail in groupInspectDetailList) { var currentInspectDetailList = inspectDetailList.Where(p => p.Item == inspectDetail.Key.Item && p.CurrentLocation == inspectDetail.Key.CurrentLocation).ToList(); var orderDetail = new OrderDetail(); var orderDetailInputList = new List<OrderDetailInput>(); Mapper.Map(currentInspectDetailList[0], orderDetail); orderDetail.OrderType = com.Sconit.CodeMaster.OrderType.Transfer; orderDetail.QualityType = com.Sconit.CodeMaster.QualityType.Inspect; orderDetail.LocationFrom = inspectDetail.Key.CurrentLocation; orderDetail.LocationFromName = genericMgr.FindById<Location>(inspectDetail.Key.CurrentLocation).Name; orderDetail.LocationTo = location.Code; orderDetail.LocationToName = location.Name; orderDetail.Sequence = seq++; foreach (InspectDetail insp in currentInspectDetailList) { var orderDetailInput = new OrderDetailInput(); if (inspectMaster.Type == com.Sconit.CodeMaster.InspectType.Barcode) { orderDetailInput.HuId = insp.HuId; orderDetailInput.LotNo = insp.LotNo; } orderDetailInput.QualityType = com.Sconit.CodeMaster.QualityType.Inspect; orderDetailInput.OccupyType = com.Sconit.CodeMaster.OccupyType.Inspect; orderDetailInput.OccupyReferenceNo = inspectMaster.InspectNo; orderDetailInput.ReceiveQty = insp.CurrentTransferQty; orderDetail.RequiredQty += insp.CurrentTransferQty; orderDetail.OrderedQty += insp.CurrentTransferQty; orderDetailInputList.Add(orderDetailInput); } orderDetail.OrderDetailInputs = orderDetailInputList; orderMaster.OrderDetails.Add(orderDetail); } CreateOrder(orderMaster); #region 更新检验明细 foreach (InspectDetail insp in inspectDetailList) { insp.CurrentLocation = location.Code; genericMgr.Update(insp); } #endregion }
public IDictionary<string, decimal> GetHuId(OrderDetail orderDetail) { decimal uc = orderDetail.UnitCount; //if (orderDetail.HuQty <= orderDetail.MaxUnitCount) //{ // uc = orderDetail.HuQty; //} var HuIds = GetHuId(orderDetail.LotNo, orderDetail.Item, orderDetail.ManufactureParty, orderDetail.HuQty, uc); return HuIds; }
public IList<Hu> CreateHu(OrderDetail orderDetail, Boolean isRepack, string manufactureParty, string lotNo, decimal totalQty, decimal unitQty, decimal huQty, string oldHus, string binTo, Boolean isRepackForOrder) { IList<Hu> huList = new List<Hu>(); IDictionary<string, decimal> huIdDic = numberControlMgr.GetHuId(lotNo, orderDetail.Item, manufactureParty, totalQty, unitQty); if (huIdDic != null && huIdDic.Count > 0) { Hu hu = new Hu(); hu.HuId = huIdDic.SingleOrDefault().Key; hu.LotNo = lotNo; hu.Item = orderDetail.Item; hu.ItemDescription = orderDetail.ItemDescription; hu.BaseUom = orderDetail.BaseUom; hu.Qty = huQty; hu.ManufactureParty = manufactureParty; hu.ManufactureDate = LotNoHelper.ResolveLotNo(lotNo); hu.PrintCount = 0; hu.ConcessionCount = 0; hu.ReferenceItemCode = orderDetail.ReferenceItemCode; hu.UnitCount = orderDetail.UnitCount; hu.UnitQty = orderDetail.UnitQty; hu.Uom = orderDetail.Uom; hu.IsOdd = huQty != hu.UnitCount; hu.IsChangeUnitCount = orderDetail.IsChangeUnitCount; hu.UnitCountDescription = orderDetail.UnitCountDescription; hu.BinTo = binTo; hu.LocationTo = orderDetail.LocationTo; hu.OldHus = oldHus; var item = this.itemMgr.GetCacheItem(orderDetail.Item); hu.MaterialsGroup = this.GetMaterialsGroupDescrption(item.MaterialsGroup); hu.Direction = orderDetail.Direction; hu.RefId = orderDetail.Id; hu.HuOption = GetHuOption(item); if (item.Warranty > 0) { hu.ExpireDate = hu.ManufactureDate.AddDays(item.Warranty); } if (item.WarnLeadTime > 0) { hu.RemindExpireDate = hu.ManufactureDate.AddDays(item.WarnLeadTime); } this.genericMgr.Create(hu); huList.Add(hu); } return huList; }
public ActionResult _DeleteOrderDetail(string detId, OrderDetail orderDet) { ModelState.Remove("Item"); OrderDetail ordeDetail = this.genericMgr.FindById<OrderDetail>(orderDet.Id); try { ViewBag.DetailId = detId; ordeDetail.Flow = this.genericMgr.FindById<OrderMaster>(ordeDetail.OrderNo).Flow; orderMgr.AllSeqOrderChange(3, ordeDetail); SaveSuccessMessage("删除成功。"); } catch (BusinessException ex) { SaveErrorMessage("删除失败。" + ex.Message); } return PartialView(new GridModel<OrderDetail>(_GetOrderDetail(ordeDetail.OrderNo, ordeDetail.ReserveNo))); }
public ActionResult _UpdateOrderDetail(string detId, OrderDetail orderDet) { ModelState.Remove("Item"); OrderDetail oldDet = this.genericMgr.FindById<OrderDetail>(orderDet.Id); try { oldDet.ICHARG = orderDet.ICHARG; orderDet.Item = orderDet.ItemCode; ViewBag.DetailId = detId; if (string.IsNullOrWhiteSpace(orderDet.Item)) { throw new BusinessException("物料编号不能为空。"); } if (orderDet.OrderedQty < 0) { throw new BusinessException("数量不能小于0。"); } Item item = this.genericMgr.FindById<Item>(orderDet.Item); oldDet.Item = item.Code; oldDet.ItemDescription = item.Description; oldDet.ReferenceItemCode = item.ReferenceCode; oldDet.OrderedQty = orderDet.OrderedQty; oldDet.Flow = this.genericMgr.FindById<OrderMaster>(oldDet.OrderNo).Flow; orderMgr.AllSeqOrderChange(2, oldDet); SaveSuccessMessage("修改成功。"); } catch (BusinessException ex) { SaveErrorMessage("修改失败。" + ex.Message); } return PartialView(new GridModel<OrderDetail>(_GetOrderDetail(oldDet.OrderNo, oldDet.ReserveNo))); }
public ActionResult _InsertOrderDetail(string detId, OrderDetail addOrderDet) { ModelState.Remove("Item"); OrderDetail ordeDetail = this.genericMgr.FindById<OrderDetail>(Convert.ToInt32(detId)); try { ViewBag.DetailId = detId; addOrderDet.Item = addOrderDet.ItemCode; if (string.IsNullOrWhiteSpace(addOrderDet.Item)) { throw new BusinessException("物料编号不能为空。"); } if (addOrderDet.OrderedQty < 0) { throw new BusinessException("数量不能小于0。"); } Item item = this.genericMgr.FindById<Item>(addOrderDet.Item); decimal qty = addOrderDet.OrderedQty; addOrderDet = Mapper.Map<OrderDetail, OrderDetail>(ordeDetail); addOrderDet.OrderNo = ordeDetail.OrderNo; addOrderDet.OrderedQty = qty; addOrderDet.Item = item.Code; addOrderDet.Uom = item.Uom; addOrderDet.BaseUom = item.Uom; addOrderDet.ItemDescription = item.Description; addOrderDet.ReferenceItemCode = item.ReferenceCode; addOrderDet.Flow = this.genericMgr.FindById<OrderMaster>(ordeDetail.OrderNo).Flow; orderMgr.AllSeqOrderChange(1, addOrderDet); SaveSuccessMessage("添加成功。"); } catch (BusinessException ex) { SaveErrorMessage("添加失败。" + ex.Message); } return PartialView(new GridModel<OrderDetail>(_GetOrderDetail(ordeDetail.OrderNo, ordeDetail.ReserveNo))); }
//新方法 //仍然采用一个计划协议+协议行号对应一张les订单 //因为物料切换目的库位时,光改明细上的库位会有问题 //订单头上很多信息打印在单据上都是错误的 private IList<OrderDetail> CreateLesProcOrder(Entity.SAP.ORD.ProcOrder procOrder, FlowMaster flowMaster, object[] flowDetail, OrderMaster orderMaster, IList<OrderDetail> orderDetailList) { IList<OrderDetail> returnOrderDetailList = new List<OrderDetail>(); try { #region 创建订单头 if (orderMaster == null) { orderMaster = this.orderMgr.TransferFlow2Order(flowMaster, null); orderMaster.ExternalOrderNo = procOrder.EBELN; //计划协议号 orderMaster.ReferenceOrderNo = procOrder.EBELP; //采购凭证的项目编号 orderMaster.WindowTime = DateTime.Now; //窗口时间 orderMaster.StartTime = DateTime.Now; //开始日期 orderMaster.IsInspect = procOrder.NOTQC == "Y" ? false : true; //检验标记 orderMaster.Type = com.Sconit.CodeMaster.OrderType.ScheduleLine; orderMaster.OrderNo = numberControlMgr.GetOrderNo(orderMaster); this.orderMgr.CreateOrder(orderMaster); } else { //提升效率 //当les订单显示为需要检验,但sap显示为免检或les显示为免检,但sap显示为检验时才更新 if (procOrder.NOTQC == "Y" && orderMaster.IsInspect || procOrder.NOTQC == "N" && !orderMaster.IsInspect) { orderMaster.IsInspect = procOrder.NOTQC == "Y" ? false : true; genericMgr.Update(orderMaster); this.genericMgr.FlushSession(); } //if (orderMaster.Flow == flowMaster.Code) //{ // //提升效率 // //当les订单显示为需要检验,但sap显示为免检或les显示为免检,但sap显示为检验时才更新 // if (procOrder.NOTQC == "Y" && orderMaster.IsInspect || procOrder.NOTQC == "N" && !orderMaster.IsInspect) // { // orderMaster.IsInspect = procOrder.NOTQC == "Y" ? false : true; // genericMgr.Update(orderMaster); // } //} //如果路线发生变化,则更新订单头和订单明细的主要信息 //为了避免不必要的错误,路线变化后其他选项信息暂时不copy //切记新维护采购路线时一定要设置允许超发,允许超收,允许asn多次收货 //else //{ //更新订单 //orderMaster.Flow = flowMaster.Code; //orderMaster.FlowDescription = flowMaster != null ? flowMaster.Description : null; //orderMaster.PartyTo = flowMaster != null ? flowMaster.PartyTo : null; //Party partyTo = flowMaster != null ? this.genericMgr.FindById<Party>(flowMaster.PartyTo) : null; //orderMaster.PartyToName = flowMaster != null ? partyTo.Name : null; //orderMaster.ShipTo = flowMaster != null ? flowMaster.ShipTo : null; //Address address = flowMaster != null ? this.genericMgr.FindById<Address>(flowMaster.ShipTo) : null; //orderMaster.ShipToAddress = flowMaster != null ? address.AddressContent : null; //orderMaster.ShipToCell = flowMaster != null ? address.MobilePhone : null; ; //orderMaster.ShipToTel = flowMaster != null ? address.TelPhone : null; //orderMaster.ShipToContact = flowMaster != null ? address.ContactPersonName : null; //orderMaster.ShipToFax = flowMaster != null ? address.Fax : null; //orderMaster.LocationTo = flowMaster != null ? flowMaster.LocationTo : null; //Location location = flowMaster != null ? this.genericMgr.FindById<Location>(flowMaster.LocationTo) : null; //orderMaster.LocationToName = flowMaster != null ? location.Name : null; //orderMaster.IsInspect = procOrder.NOTQC == "Y" ? false : true; //genericMgr.Update(orderMaster); //取最新路线明细数据更新订单明细 //OrderDetail orderDetail = (from o in orderDetailList // where o.ExternalOrderNo == orderMaster.ExternalOrderNo && o.ExternalSequence == orderMaster.ReferenceOrderNo // select o).ToList()[0]; //FlowDetail flowDetail = this.genericMgr.FindAll<FlowDetail>("from FlowDetail where Flow = ? and Item = ?", new object[] { orderMaster.Flow, orderDetail.Item })[0]; //orderDetail.UnitCount = flowDetail.UnitCount; //orderDetail.Uom = flowDetail.Uom; //orderDetail.BaseUom = flowDetail.BaseUom; ////库位取路线头上的 //orderDetail.LocationTo = flowMaster.LocationTo; //orderDetail.LocationToName = genericMgr.FindById<Location>(flowMaster.LocationTo).Name; //genericMgr.Update(orderDetail); //} } #endregion #region 创建订单明细 //int id = 0; //提升效率,但存在风险 IList<OrderDetail> existedOrderDetail = (from o in orderDetailList where o.ExternalOrderNo == procOrder.EBELN && o.ExternalSequence == procOrder.EBELP select o).ToList(); //先更新原有订单 if (existedOrderDetail != null && existedOrderDetail.Count > 0) { //目前来说只有单位和单位换算会更新 decimal sapUnitQty = (procOrder.UMREN == 0 || procOrder.UMREZ == 0) ? 1 : (procOrder.UMREZ / procOrder.UMREN); if (existedOrderDetail[0].Uom != procOrder.MEINS || existedOrderDetail[0].BaseUom != procOrder.LMEIN || existedOrderDetail[0].UnitQty != sapUnitQty) { //PrepareOrderDetail(existedOrderDetail[0], orderMaster, procOrder.ProcOrderDetails[0], procOrder, DateTime.Now); existedOrderDetail[0].Uom = procOrder.MEINS; existedOrderDetail[0].BaseUom = procOrder.LMEIN; existedOrderDetail[0].UnitQty = sapUnitQty; genericMgr.Update(existedOrderDetail[0]); this.genericMgr.FlushSession(); } } //定义宿主订单明细用来copy,一旦首次插入失败,宿主订单将无法赋值可能引起出错 OrderDetail hostOrderDetail = new OrderDetail(); for (int i = 0; i < procOrder.ProcOrderDetails.Count(); i++) { try { #region 只在第一次执行插入,如果失败会存在风险 if (i == 0 && (existedOrderDetail == null || existedOrderDetail.Count == 0)) { //if (flowDetailList == null || flowDetailList.Count == 0) //{ // throw new BusinessException("和计划协议匹配的采购路线{0}物料代码{1}不存在,请联系计划员。", flowMaster.Code, procOrder.ProcOrderDetails[i].MATNR); //} //object[] flowDetail = flowDetailList[0]; OrderDetail orderDetail = new OrderDetail(); orderDetail.UnitCount = (decimal)flowDetail[3]; //orderDetail.IsInspect = flowDetail.IsInspect; //if (!string.IsNullOrEmpty(flowDetail.LocationTo)) //{ // orderDetail.LocationTo = flowDetail.LocationTo; // orderDetail.LocationToName = lesMgr.FindById<Location>(flowDetailList[0].LocationTo).Name; //} PrepareOrderDetail(orderDetail, orderMaster, procOrder.ProcOrderDetails[i], procOrder, DateTime.Now); if (string.IsNullOrWhiteSpace(orderDetail.Uom)) { orderDetail.Uom = (string)flowDetail[4]; } if (string.IsNullOrWhiteSpace(orderDetail.BaseUom)) { orderDetail.BaseUom = (string)flowDetail[5]; } if (string.IsNullOrWhiteSpace(orderDetail.ItemDescription)) { orderDetail.ItemDescription = (string)flowDetail[7]; } if (string.IsNullOrWhiteSpace(orderDetail.ReferenceItemCode)) { orderDetail.ReferenceItemCode = (string)flowDetail[6]; } if (string.IsNullOrWhiteSpace(orderDetail.BillAddress) && !string.IsNullOrWhiteSpace(orderMaster.BillAddress)) { orderDetail.BillAddress = orderMaster.BillAddress; orderDetail.BillAddressDescription = orderMaster.BillAddressDescription; } genericMgr.Create(orderDetail); this.genericMgr.FlushSession(); #region 自己拼Orderdetail,显示用不更新数据库 DateTime EINDT = DateTime.Parse(procOrder.ProcOrderDetails[0].EINDT); //orderDetail.Id = orderDetail.Id + id; orderDetail.StartDate = EINDT; orderDetail.EndDate = EINDT; orderDetail.OrderedQty = procOrder.ProcOrderDetails[0].MENGE; orderDetail.FreezeDays = Convert.ToInt32(procOrder.ETFZ1); orderDetail.Flow = flowMaster.Code; orderDetail.ManufactureParty = flowMaster != null ? flowMaster.PartyFrom : null; //sap的收货数,仅仅是用于需求预测报表,和计划协议的已收数可能有误差 orderDetail.ReceivedQty = procOrder.ProcOrderDetails[i].WEMNG.HasValue ? procOrder.ProcOrderDetails[i].WEMNG.Value : decimal.Zero; returnOrderDetailList.Add(orderDetail); //记录到宿主订单用于复制 hostOrderDetail = orderDetail; //id++; #endregion } else if (existedOrderDetail != null && existedOrderDetail.Count > 0) { OrderDetail newOrderDetail = new OrderDetail(); #region 自己拼Orderdetail,显示用不更新数据库 newOrderDetail.Id = existedOrderDetail[0].Id; newOrderDetail.Item = existedOrderDetail[0].Item; newOrderDetail.ReferenceItemCode = existedOrderDetail[0].ReferenceItemCode; newOrderDetail.ItemDescription = existedOrderDetail[0].ItemDescription; newOrderDetail.ExternalOrderNo = existedOrderDetail[0].ExternalOrderNo; newOrderDetail.ExternalSequence = existedOrderDetail[0].ExternalSequence; newOrderDetail.OrderNo = existedOrderDetail[0].OrderNo; DateTime EINDT = DateTime.Parse(procOrder.ProcOrderDetails[i].EINDT); newOrderDetail.OrderType = CodeMaster.OrderType.ScheduleLine; newOrderDetail.LocationTo = flowMaster.LocationTo; newOrderDetail.ShippedQty = existedOrderDetail[0].ShippedQty; newOrderDetail.ReceivedQty = existedOrderDetail[0].ReceivedQty; newOrderDetail.UnitCount = (decimal)flowDetail[3]; newOrderDetail.Uom = existedOrderDetail[0].Uom; newOrderDetail.StartDate = EINDT; newOrderDetail.EndDate = EINDT; newOrderDetail.OrderedQty = procOrder.ProcOrderDetails[i].MENGE; newOrderDetail.FreezeDays = Convert.ToInt32(procOrder.ETFZ1); newOrderDetail.Flow = flowMaster.Code; newOrderDetail.ManufactureParty = flowMaster != null ? flowMaster.PartyFrom : null; newOrderDetail.BillTerm = existedOrderDetail[0].BillTerm; //sap的收货数,仅仅是用于需求预测报表,和计划协议的已收数可能有误差 newOrderDetail.ReceivedQty = procOrder.ProcOrderDetails[i].WEMNG.HasValue ? procOrder.ProcOrderDetails[i].WEMNG.Value : decimal.Zero; returnOrderDetailList.Add(newOrderDetail); //id++; #endregion } else if (existedOrderDetail == null || existedOrderDetail.Count == 0) { OrderDetail newOrderDetail = new OrderDetail(); //OrderDetail existedDetail = (from o in lesOrderDetailList // where o.ExternalOrderNo == procOrderDetail.EBELN && o.ExternalSequence == procOrderDetail.EBELP // select o).ToList()[0]; #region 自己拼Orderdetail,显示用不更新数据库 newOrderDetail.Id = 0; newOrderDetail.Item = hostOrderDetail.Item; newOrderDetail.ReferenceItemCode = hostOrderDetail.ReferenceItemCode; newOrderDetail.ItemDescription = hostOrderDetail.ItemDescription; newOrderDetail.ExternalOrderNo = hostOrderDetail.ExternalOrderNo; newOrderDetail.ExternalSequence = hostOrderDetail.ExternalSequence; newOrderDetail.OrderNo = hostOrderDetail.OrderNo; DateTime EINDT = DateTime.Parse(procOrder.ProcOrderDetails[i].EINDT); newOrderDetail.OrderType = CodeMaster.OrderType.ScheduleLine; newOrderDetail.LocationTo = flowMaster.LocationTo; newOrderDetail.ShippedQty = 0; newOrderDetail.ReceivedQty = 0; newOrderDetail.UnitCount = hostOrderDetail.UnitCount; newOrderDetail.Uom = hostOrderDetail.Uom; newOrderDetail.StartDate = EINDT; newOrderDetail.EndDate = EINDT; newOrderDetail.OrderedQty = procOrder.ProcOrderDetails[i].MENGE; newOrderDetail.FreezeDays = Convert.ToInt32(procOrder.ETFZ1); newOrderDetail.Flow = flowMaster.Code; newOrderDetail.ManufactureParty = flowMaster != null ? flowMaster.PartyFrom : null; newOrderDetail.BillTerm = hostOrderDetail.BillTerm; //sap的收货数,仅仅是用于需求预测报表,和计划协议的已收数可能有误差 newOrderDetail.ReceivedQty = procOrder.ProcOrderDetails[i].WEMNG.HasValue ? procOrder.ProcOrderDetails[i].WEMNG.Value : decimal.Zero; returnOrderDetailList.Add(newOrderDetail); //id++; #endregion } #endregion } catch (Exception ex) { string logMessage = string.Format("创建采购路线{0}物料代码{1}计划协议号{2}行号{3}的计划协议明细出现异常,异常信息:{4}", orderMaster.Flow, procOrder.ProcOrderDetails[i].MATNR, procOrder.EBELN, procOrder.EBELP, ex.Message); log.Error(logMessage, ex); this.genericMgr.CleanSession(); throw new BusinessException(logMessage); } } #endregion //明细创建成功后,更新订单状态 if (orderMaster.Status == CodeMaster.OrderStatus.Create) { orderMaster.Status = CodeMaster.OrderStatus.Submit; this.genericMgr.Update(orderMaster); this.genericMgr.FlushSession(); } //返回订单明细用于portal显示 return returnOrderDetailList; } catch (Exception ex) { string logMessage = string.Format("创建协议号{0}行号{1}的计划协议出现异常,异常信息:{2}", procOrder.EBELN, procOrder.EBELP, ex.Message); log.Error(logMessage, ex); this.genericMgr.CleanSession(); throw new BusinessException(logMessage); } }
private void PrepareOrderDetail(OrderDetail orderDetail, OrderMaster orderMaster, Entity.SAP.ORD.ProcOrderDetail procOrderDetail, Entity.SAP.ORD.ProcOrder procOrder, DateTime dateTimeNow) { orderDetail.OrderNo = orderMaster.OrderNo; orderDetail.ExternalOrderNo = procOrder.EBELN; orderDetail.ExternalSequence = procOrder.EBELP; orderDetail.OrderType = orderMaster.Type; orderDetail.OrderSubType = orderMaster.SubType; orderDetail.Item = procOrderDetail.MATNR; orderDetail.ItemDescription = procOrder.TXZ01; orderDetail.ReferenceItemCode = procOrder.BISMT; orderDetail.Uom = procOrder.MEINS; orderDetail.BaseUom = procOrder.LMEIN; orderDetail.UnitQty = (procOrder.UMREN == 0 || procOrder.UMREZ == 0) ? 1 : (procOrder.UMREZ / procOrder.UMREN); orderDetail.QualityType = CodeMaster.QualityType.Qualified; orderDetail.RequiredQty = 1; orderDetail.OrderedQty = 1; //if (orderDetail.LocationTo == null) //{ // orderDetail.LocationTo = orderMaster.LocationTo; //} //计划协议类订单目的库位以订单头为准 orderDetail.LocationTo = orderMaster.LocationTo; orderDetail.LocationToName = orderMaster.LocationToName; if (procOrder.PSTYP == "2") //寄售标识,设置为2的为上线计算,其余的为收货结算 { orderDetail.BillTerm = CodeMaster.OrderBillTerm.OnlineBilling; } else { orderDetail.BillTerm = CodeMaster.OrderBillTerm.ReceivingSettlement; } //临时借用AUFNR暂存PSTYP orderDetail.AUFNR = procOrder.PSTYP; //ZC1:军车 ZC2:出口车 ZC3:特殊车 ZC5:CKD orderDetail.Tax = procOrder.BSART; orderDetail.IsInspect = true; DateTime EINDT = DateTime.Parse(procOrderDetail.EINDT); orderDetail.StartDate = EINDT; orderDetail.EndDate = EINDT; }
private object[] ExpandOrderOperationAndBomDetail(OrderMaster orderMaster, OrderDetail orderDetail) { BeforeExpandOrderOperationAndBomDetail(orderMaster); object[] returnList = new object[2]; returnList[0] = this.ProcessExpandOrderOperation(orderMaster, orderDetail); returnList[1] = this.ProcessExpandOrderBomDetail(orderMaster, orderDetail); return returnList; }
private void AddHuToOrderDetailInput(IList<OrderDetail> orderDetailList, IList<string> huIdList) { IList<HuStatus> huStatusList = huMgr.GetHuStatus(huIdList); IList<HuStatus> notInLocHu = huStatusList.Where(h => h.Status != CodeMaster.HuStatus.Location).ToList(); if (notInLocHu != null && notInLocHu.Count > 0) { string strExeception = string.Empty; foreach (HuStatus hs in notInLocHu) { if (string.IsNullOrEmpty(strExeception)) strExeception = "条码" + hs.HuId; else strExeception += "," + hs.HuId; } strExeception += "不在库存中"; throw new BusinessException(strExeception); } foreach (HuStatus huStatus in huStatusList) { var h = orderDetailList.Where(o => o.Item == huStatus.Item && o.Uom == huStatus.Uom && o.LocationFrom == huStatus.Location).ToList(); if (h == null || h.Count == 0) { OrderDetail od = new OrderDetail(); od.Item = huStatus.Item; od.Uom = huStatus.Uom; od.UnitCount = huStatus.UnitCount; od.ItemDescription = huStatus.ItemDescription; od.ReferenceItemCode = huStatus.ReferenceItemCode; od.LocationFrom = huStatus.Location; od.OrderedQty = huStatus.Qty; IList<OrderDetailInput> orderDetailInputList = new List<OrderDetailInput>(); OrderDetailInput orderDetailInput = new OrderDetailInput(); orderDetailInput.HuId = huStatus.HuId; orderDetailInput.HuQty = huStatus.Qty; orderDetailInput.LotNo = huStatus.LotNo; orderDetailInput.ReceiveQty = huStatus.Qty; orderDetailInputList.Add(orderDetailInput); od.OrderDetailInputs = orderDetailInputList; orderDetailList.Add(od); } else { OrderDetail od = h[0]; od.OrderedQty += huStatus.Qty; OrderDetailInput orderDetailInput = new OrderDetailInput(); orderDetailInput.HuId = huStatus.HuId; orderDetailInput.HuQty = huStatus.Qty; orderDetailInput.LotNo = huStatus.LotNo; orderDetailInput.ReceiveQty = huStatus.Qty; od.OrderDetailInputs.Add(orderDetailInput); } } }
public decimal GetRoundOrderQty(OrderDetail orderDetail, decimal orderQty) { if (orderDetail.MinLotSize > 0 && orderQty < orderDetail.MinLotSize) { orderQty = orderDetail.MinLotSize; } if (orderDetail.UnitCount > 0) { if (orderDetail.RoundUpOption == CodeMaster.RoundUpOption.ToUp) { orderQty = Math.Ceiling(orderQty / orderDetail.UnitCount) * orderDetail.UnitCount; } else if (orderDetail.RoundUpOption == CodeMaster.RoundUpOption.ToDown) { orderQty = Math.Floor(orderQty / orderDetail.UnitCount) * orderDetail.UnitCount; } } int decimalLength = int.Parse(systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.DecimalLength)); return Math.Round(orderQty, decimalLength); }
//返回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 void ProcessAddOrderOperations(OrderDetail orderDetail, IList<OrderOperation> orderOperationList) { if (orderOperationList != null && orderOperationList.Count > 0) { foreach (OrderOperation orderOperation in orderOperationList) { orderOperation.OrderNo = orderDetail.OrderNo; orderOperation.OrderDetId = orderDetail.Id; this.genericMgr.Create(orderOperation); } } }
public string CreateTransferOrderFromXls(Stream inputStream, string regionFromCode, string regionToCode, DateTime effectiveDate) { #region 导入数据 if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); ImportHelper.JumpRows(rows, 11); #region 列定义 int colItem = 1;//物料代码 int colUom = 3;//单位 int colLocFrom = 4;// 来源库位 int colLocTo = 5;// 目的库位 int colQty = 6;//数量 #endregion DateTime dateTimeNow = DateTime.Now; if (string.IsNullOrEmpty(regionToCode)) { regionToCode = regionFromCode; } IList<OrderDetail> exactOrderDetailList = new List<OrderDetail>(); while (rows.MoveNext()) { HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 9)) { break;//边界 } string itemCode = string.Empty; decimal qty = 0; string uomCode = string.Empty; string locationFromCode = string.Empty; string locationToCode = string.Empty; #region 读取数据 #region 读取物料代码 itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItem)); if (itemCode == null || itemCode.Trim() == string.Empty) { ImportHelper.ThrowCommonError(row.RowNum, colItem, row.GetCell(colItem)); } #endregion #region 读取单位 uomCode = row.GetCell(colUom) != null ? row.GetCell(colUom).StringCellValue : string.Empty; if (uomCode == null || uomCode.Trim() == string.Empty) { throw new BusinessException("Import.Read.Error.Empty", (row.RowNum + 1).ToString(), colUom.ToString()); } #endregion #endregion #region 读取来源库位 locationFromCode = row.GetCell(colLocFrom) != null ? row.GetCell(colLocFrom).StringCellValue : string.Empty; if (string.IsNullOrEmpty(locationFromCode)) { throw new BusinessException("Import.Read.Error.Empty", (row.RowNum + 1).ToString(), colLocFrom.ToString()); } IList<Location> locationFromList = genericMgr.FindAll<Location>("select l from Location as l where l.Code=?", locationFromCode); if (locationFromList != null && locationFromList.Count > 0) { if (locationFromList[0].Region != regionFromCode) { throw new BusinessException("指定区域不存在此库位" + locationFromCode, (row.RowNum + 1).ToString(), colLocFrom.ToString()); } } else { throw new BusinessException("指定区域不存在此库位" + regionToCode, (row.RowNum + 1).ToString(), colLocFrom.ToString()); } // Location locationFrom = genericMgr.FindById<Location>(locationFromCode); #endregion #region 读取目的库位 locationToCode = row.GetCell(colLocTo) != null ? row.GetCell(colLocTo).StringCellValue : string.Empty; if (string.IsNullOrEmpty(locationFromCode)) { throw new BusinessException("Import.Read.Error.Empty", (row.RowNum + 1).ToString(), colLocTo.ToString()); } IList<Location> locationToList = genericMgr.FindAll<Location>("select l from Location as l where l.Code=?", locationToCode); if (locationToList != null && locationToList.Count > 0) { if (locationToList[0].Region != regionToCode) { throw new BusinessException("指定区域不存在此库位" + regionToCode, (row.RowNum + 1).ToString(), colLocFrom.ToString()); } } else { throw new BusinessException("指定区域不存在此库位" + regionToCode, (row.RowNum + 1).ToString(), colLocFrom.ToString()); } //Location locationTo = genericMgr.FindById<Location>(locationToCode); //if (locationTo.Region != regionToCode) //{ // throw new BusinessException("指定区域不存在此库位" + locationTo, (row.RowNum + 1).ToString(), colLocFrom.ToString()); //} #endregion #region 读取数量 try { qty = Convert.ToDecimal(row.GetCell(colQty).NumericCellValue); } catch { ImportHelper.ThrowCommonError(row.RowNum, colQty, row.GetCell(colQty)); } #endregion #region 填充数据 OrderDetail od = new OrderDetail(); od.LocationFrom = locationFromCode; od.LocationTo = locationToCode; od.Item = itemCode; od.Uom = uomCode; od.OrderedQty = qty; exactOrderDetailList.Add(od); #endregion } #endregion return CreateFreeTransferOrderMaster(regionFromCode, regionToCode, exactOrderDetailList, effectiveDate); }
private IList<OrderOperation> ExpandOrderOperation(OrderMaster orderMaster, OrderDetail orderDetail) { BeforeExpandOrderOperation(orderMaster); return ProcessExpandOrderOperation(orderMaster, orderDetail); }
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 }
public void BatchUpdateOrderBomDetails(OrderDetail orderDetail, IList<OrderBomDetail> addOrderBomDetailList, IList<OrderBomDetail> updateOrderBomDetailList, IList<OrderBomDetail> deleteOrderBomDetailList) { OrderMaster orderMaster = genericMgr.FindById<OrderMaster>(orderDetail.OrderNo); BeforeBatchUpdateOrderBomDetails(orderMaster); if (addOrderBomDetailList != null && addOrderBomDetailList.Count > 0) { ProcessAddOrderBomDetails(orderDetail, addOrderBomDetailList); } if (updateOrderBomDetailList != null && updateOrderBomDetailList.Count > 0) { ProcessUpdateOrderBomDetails(updateOrderBomDetailList); } if (deleteOrderBomDetailList != null && deleteOrderBomDetailList.Count > 0) { IList<int> deleteOrderBomDetailIds = (from orderBomDet in deleteOrderBomDetailList select orderBomDet.Id).ToList(); ProcessDeleteOrderBomDetails(deleteOrderBomDetailIds); } }
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()); } } }
private void ProcessAddOrderBomDetails(OrderDetail orderDetail, IList<OrderBomDetail> orderBomDetailList) { if (orderBomDetailList != null && orderBomDetailList.Count > 0) { #region 查找最大序号的OrderBomDetail string hql = "select max(Sequence) as MaxSeq from OrderBomDetail where OrderDetailId = ?"; IList<int?> maxSeqList = this.genericMgr.FindAll<int?>(hql, orderDetail.Id); int maxSeq = 0; if (maxSeqList != null && maxSeqList.Count > 0 && maxSeqList[0] != null) { maxSeq = maxSeqList[0].Value; } #endregion foreach (OrderBomDetail orderBomDetail in orderBomDetailList.OrderBy(o => o.Operation).ThenBy(o => o.OpReference)) { orderBomDetail.Sequence = ++maxSeq; orderBomDetail.OrderNo = orderDetail.OrderNo; orderBomDetail.OrderType = orderDetail.OrderType; orderBomDetail.OrderSubType = orderDetail.OrderSubType; orderBomDetail.OrderDetailId = orderDetail.Id; orderBomDetail.OrderDetailSequence = orderDetail.Sequence; this.genericMgr.Create(orderBomDetail); } } }
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<OrderBomDetail> ExpandOrderBomDetail(OrderMaster orderMaster, OrderDetail orderDetail) { BeforeExpandOrderBomDetail(orderMaster); return ProcessExpandOrderBomDetail(orderMaster, orderDetail); }
public void AddOrderDetail(OrderDetail orderDetail) { if (OrderDetails == null) { OrderDetails = new List<OrderDetail>(); } OrderDetails.Add(orderDetail); }
private IList<OrderBomDetail> ProcessExpandOrderBomDetail(OrderMaster orderMaster, OrderDetail orderDetail) { string hql = "from OrderBomDetail where OrderDetailId = ?"; genericMgr.Delete(genericMgr.FindAll<OrderBomDetail>(hql, orderDetail.Id)); GenerateOrderBomDetail(orderDetail, orderMaster); ProcessAddOrderBomDetails(orderDetail, orderDetail.OrderBomDetails); return orderDetail.OrderBomDetails; }