//得到基本单位用量 protected List<MrpBom> GetMrpBomList(string fgCode, string bomCode, DateTime effdate, BusinessException businessException, bool isOnlyNext = false) { var mrpBoms = new List<MrpBom>(); try { var bomMaster = this.bomMgr.GetCacheBomMaster(bomCode); if (bomMaster != null) { var fgItem = this.itemMgr.GetCacheItem(fgCode); IList<BomDetail> bomDetails = new List<BomDetail>(); if (isOnlyNext) { bomDetails = bomMgr.GetOnlyNextLevelBomDetail(bomCode, effdate, true); } else { bomDetails = bomMgr.GetFlatBomDetail(bomCode, effdate, true); } foreach (var bomDetail in bomDetails) { var item = this.itemMgr.GetCacheItem(bomDetail.Item); double calculatedQty = 1; //1.将bomMaster的单位转成基本单位 double fgQty = ConvertItemUomQty(fgItem.Code, bomMaster.Uom, 1, fgItem.Uom, businessException); //2.将BomDetail的单位转成基本单位 double itemQty = ConvertItemUomQty(item.Code, bomDetail.Uom, (double)bomDetail.CalculatedQty, item.Uom, businessException); //3.单位成品用量 calculatedQty = itemQty / fgQty; var mrpBom = new MrpBom(); mrpBom.Bom = bomCode; mrpBom.Item = bomDetail.Item; mrpBom.Location = bomDetail.Location; mrpBom.RateQty = calculatedQty; mrpBom.IsSection = item.ItemCategory == "ZHDM"; mrpBom.ScrapPercentage = (double)bomDetail.ScrapPercentage; //if (mrpBom.IsSection) //{ // mrpBom.ScrapPercentage = fgItem.ScrapPercent; //} mrpBoms.Add(mrpBom); } } } catch (Exception ex) { businessException.AddMessage(new Message(CodeMaster.MessageType.Error, string.Format("BomCode {0} Error,{1}", bomCode, ex.Message))); } return mrpBoms; }
public void ReadWeeklyMrpPlanFromXls(Stream inputStream, string startWeek, string endWeek, string flowCode, bool isItemRef) { #region 判断 DateTime? startDate = null; DateTime? endDate = null; if (!string.IsNullOrEmpty(startWeek)) { startDate = DateTimeHelper.GetWeekIndexDateFrom(startWeek); } if (!string.IsNullOrEmpty(endWeek)) { endDate = DateTimeHelper.GetWeekIndexDateFrom(endWeek); } if (startDate.HasValue) { if (startDate.Value.Date < DateTime.Now.Date) { throw new BusinessException("开始日期必须大于当期日期"); } } else { startDate = DateTime.Now.Date; } if (endDate.HasValue) { if (endDate.Value.Date <= DateTime.Now.Date) { throw new BusinessException("结束日期必须大于当期日期"); } } else { endDate = DateTime.MaxValue.Date; } if (startDate.Value > endDate.Value) { throw new BusinessException("开始日期必须小于结束日期"); } if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } #endregion 判断 //var flowDetails = GetFlowDetails(flowCode); List<FlowDetail> flowDetailList = new List<FlowDetail>(); var uomDic = this.genericMgr.FindAll<Uom>().ToDictionary(d => d.Code, d => d); if (string.IsNullOrWhiteSpace(flowCode)) { var flowMasters = this.genericMgr.FindAll<FlowMaster>(" from FlowMaster where Type=?", CodeMaster.OrderType.Distribution).ToList(); foreach (var flowMaster in flowMasters) { flowDetailList.AddRange(GetFlowDetails(flowMaster)); } } else { flowDetailList = GetFlowDetails(flowCode).ToList(); } var flowDetailDic = flowDetailList.GroupBy(p => p.CurrentFlowMaster.Code, (k, g) => new { k, g }).ToDictionary(d => d.k, d => d.g); HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); IRow dateRow = sheet.GetRow(5); ImportHelper.JumpRows(rows, 6); var mrpPlanLogList = new List<MrpPlanLog>(); int days = 7; try { days = (int)sheet.GetRow(4).GetCell(1).NumericCellValue; } catch (Exception) { } #region 列定义 //int colFlow = 0;// int colFlow = 0;// int colItemCode = 1;//物料代码或参考物料号 //int colItemDescription = 2;//物料描述 int colUom = 3;//单位 #endregion BusinessException businessException = new BusinessException(); while (rows.MoveNext()) { string flow = null; Item item = null; string uomCode = null; string itemReference = null; HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 0, 3)) { break;//边界 } string rowIndex = (row.RowNum + 1).ToString(); #region 读取路线 try { string flowCell = ImportHelper.GetCellStringValue(row.GetCell(colFlow)); if (flowCell != null && flowDetailDic.ContainsKey(flowCell)) { flow = flowCell; } } catch (Exception ex) { businessException.AddMessage(string.Format("读取库位出错,第{0}行." + ex.Message, rowIndex)); continue; } var flowDetails = flowDetailDic.ValueOrDefault(flow); #endregion #region 读取物料代码 try { string itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItemCode)); if (itemCode == null) { businessException.AddMessage(string.Format("物料号不存在,第{0}行", rowIndex)); continue; } if (isItemRef) { item = this.genericMgr.FindAll<Item>("from Item as i where i.ReferenceCode = ? ", new object[] { itemCode }, 0, 1).First(); itemReference = itemCode; } else { item = this.genericMgr.FindById<Item>(itemCode); itemReference = item.ReferenceCode; } if (item == null) { businessException.AddMessage(string.Format("物料号{0}不存在,第{1}行", itemCode, rowIndex)); continue; } } catch (Exception ex) { businessException.AddMessage(string.Format("读取物料号出错,第{0}行" + ex.Message, rowIndex)); continue; } #endregion #region 读取单位 try { string uomCell = ImportHelper.GetCellStringValue(row.GetCell(colUom)); uomCode = uomDic.ValueOrDefault(uomCell).Code; } catch (Exception ex) { businessException.AddMessage(string.Format("读取单位出错,第{0}行," + ex.Message, rowIndex)); continue; } #endregion #region 使用flowDetails过滤 string locationCode = string.Empty; var q = flowDetails.Where(f => f.Item == item.Code && f.Uom == uomCode); if (q.Count() > 0) { locationCode = !string.IsNullOrWhiteSpace(q.FirstOrDefault().LocationFrom) ? q.FirstOrDefault().LocationFrom : q.FirstOrDefault().CurrentFlowMaster.LocationFrom; } else { if (flowDetails.First().CurrentFlowMaster.IsManualCreateDetail) { uomCode = uomCode == null ? item.Uom : uomCode; locationCode = flowDetails.First().CurrentFlowMaster.LocationFrom; } else { businessException.AddMessage("没有找到匹配的路线明细,第{0}行.物料号{1},单位{2},库位{3}", rowIndex, item.Code, uomCode, flow); continue; } } #endregion #region 读取数量 try { for (int i = 4; ; i++) { ICell dateCell = dateRow.GetCell(i); string weekOfYear = null; #region 读取计划日期 if (dateCell != null) { weekOfYear = ImportHelper.GetCellStringValue(dateCell); if (string.IsNullOrWhiteSpace(weekOfYear)) { break; } if (weekOfYear.CompareTo(startWeek) < 0) { continue; } if (weekOfYear.CompareTo(endWeek) > 0) { break; } } else { break; } #endregion double qty = 0; if (row.GetCell(i) != null) { if (row.GetCell(i).CellType == CellType.NUMERIC) { qty = row.GetCell(i).NumericCellValue; } else { string qtyValue = ImportHelper.GetCellStringValue(row.GetCell(i)); if (qtyValue != null) { qty = Convert.ToDouble(qtyValue); } } } else { continue; } if (qty < 0) { businessException.AddMessage("导入数量不能小于0,第{0}行", rowIndex); continue; } else { double dayQty = Math.Round(qty / days); DateTime currentDate = DateTimeHelper.GetWeekIndexDateFrom(weekOfYear); for (int j = 0; j < days; j++) { MrpPlanLog mrpPlanLog = new MrpPlanLog(); decimal unitQty = itemMgr.ConvertItemUomQty(item.Code, uomCode, 1, item.Uom); mrpPlanLog.UnitQty = unitQty; mrpPlanLog.ItemDescription = item.CodeDescription; mrpPlanLog.ItemReference = item.ReferenceCode; mrpPlanLog.PlanDate = currentDate; mrpPlanLog.Item = item.Code; mrpPlanLog.Party = flowDetails.First().CurrentFlowMaster.PartyTo; mrpPlanLog.OrderType = flowDetails.First().CurrentFlowMaster.Type; //dailyPlanLog.PlanVersion = dailyPlan.PlanVersion; mrpPlanLog.Flow = flowDetails.First().CurrentFlowMaster.Code; mrpPlanLog.Location = locationCode; mrpPlanLog.Uom = uomCode; if (j == days - 1) { mrpPlanLog.Qty = qty - dayQty * (days - 1); } else { mrpPlanLog.Qty = dayQty; } currentDate = currentDate.AddDays(1); mrpPlanLogList.Add(mrpPlanLog); } } } } catch (Exception ex) { businessException.AddMessage(ex.Message); } #endregion } if (businessException.HasMessage) { throw businessException; } var mrpPlanLogGroups = mrpPlanLogList.GroupBy(p => p.Flow, (k, g) => new { k, g }); foreach (var mrpPlanLogGroup in mrpPlanLogGroups) { CreateMrpPlan(mrpPlanLogGroup.k, mrpPlanLogGroup.g.ToList()); } }
private void DoStartVanOrder(string orderNo, string feedOrderNo, IList<string> feedHuIdList, bool isForce) { #region 上线 OrderMaster orderMaster = this.genericMgr.FindById<OrderMaster>(orderNo); #region 判断是否第一辆上线 IList<long> beforeUnstartVanOrderCount = this.genericMgr.FindAll<long>("select count(*) as counter from OrderMaster where Type = ? and Flow = ? and Status = ? and IsPause = ? and Sequence < ?", new object[] { orderMaster.Type, orderMaster.Flow, CodeMaster.OrderStatus.Submit, false, orderMaster.Sequence }); if (beforeUnstartVanOrderCount != null && beforeUnstartVanOrderCount.Count > 0 && beforeUnstartVanOrderCount[0] > 0) { throw new BusinessException("生产单{0}不是生产线{1}第一张待上线的生产单。", orderNo, orderMaster.Flow); } #endregion this.StartOrder(orderMaster); #endregion #region 子生产单投料 if (!string.IsNullOrWhiteSpace(feedOrderNo)) { this.productionLineMgr.FeedProductOrder(orderNo, feedOrderNo, isForce); } #endregion #region 物料投料 if (feedHuIdList != null && feedHuIdList.Count > 0) { #region 查找投料条码 IList<Hu> huList = this.huMgr.LoadHus(feedHuIdList); #endregion #region 查找投料工位 string hql = string.Empty; IList<object> para = new List<object>(); foreach (string item in huList.Select(h => h.Item).Distinct()) { if (hql == string.Empty) { hql = "from OrderBomDetail where OrderNo = ? and Item in (?"; para.Add(orderNo); } else { hql += ", ?"; } para.Add(item); } hql += ")"; IList<OrderBomDetail> orderBomDetailList = this.genericMgr.FindAll<OrderBomDetail>(hql, para.ToArray()); #region 判断条码是否在OrderBomDetial中存在 if (!isForce) { BusinessException businessException = new BusinessException(); foreach (Hu hu in huList) { if (orderBomDetailList.Where(det => det.Item == hu.Item).Count() == 0) { businessException.AddMessage("投料的条码{0}在生产单的物料清单中不存在。", hu.HuId); } } if (businessException.HasMessage) { throw businessException; } } #endregion #endregion #region 投料 foreach (string huId in feedHuIdList) { Hu hu = huList.Where(h => h.HuId == huId).Single(); OrderBomDetail orderBomDetail = orderBomDetailList.Where(o => o.Item == hu.Item).OrderBy(o => o.Sequence).First(); FeedInput feedInput = new FeedInput(); feedInput.HuId = huId; feedInput.Operation = orderBomDetail.Operation; feedInput.OpReference = orderBomDetail.OpReference; IList<FeedInput> feedInputList = new List<FeedInput>(); feedInputList.Add(feedInput); this.productionLineMgr.FeedRawMaterial(orderNo, feedInputList, isForce); } #endregion } #endregion #region 释放驾驶室生产单 //由后台Job自动释放 #endregion #region 递延扣减 //记录递延扣减需求,由后台Job自动扣减 IList<DeferredFeedCounter> deferredFeedCounterList = this.genericMgr.FindAll<DeferredFeedCounter>("from DeferredFeedCounter where Flow = ?", orderMaster.Flow); if (deferredFeedCounterList != null && deferredFeedCounterList.Count > 0) { deferredFeedCounterList[0].Counter++; this.genericMgr.Update(deferredFeedCounterList[0]); } else { DeferredFeedCounter deferredFeedCounter = new DeferredFeedCounter(); deferredFeedCounter.Flow = orderMaster.Flow; deferredFeedCounter.Counter = 1; this.genericMgr.Create(deferredFeedCounter); } #endregion }
public void PackSequenceOrder(SequenceMaster sequenceMaster, IList<string> huIdList) { #region 检查 if (sequenceMaster.Status != CodeMaster.SequenceStatus.Submit) { throw new BusinessException("状态为{1}的排序装箱单{0}不能装箱。", sequenceMaster.SequenceNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.SequenceStatus, ((int)sequenceMaster.Status).ToString())); } if (huIdList == null || huIdList.Count == 0) { throw new BusinessException("排序装箱单{0}的装箱条码为空。", sequenceMaster.SequenceNo); } #endregion #region 库存占用 IList<InventoryOccupy> inventoryOccupyList = (from huId in huIdList select new InventoryOccupy { HuId = huId, Location = sequenceMaster.LocationFrom, QualityType = CodeMaster.QualityType.Qualified, OccupyType = CodeMaster.OccupyType.Sequence, OccupyReferenceNo = sequenceMaster.SequenceNo }).ToList(); IList<LocationLotDetail> locationLotDetailList = this.locationDetailMgr.InventoryOccupy(inventoryOccupyList); #endregion #region 排序单数量和扫描条码数量匹配 BusinessException businessException = new BusinessException(); TryLoadSequenceDetails(sequenceMaster); if (sequenceMaster.SequenceDetails.Where(d => !d.IsClose).Count() != huIdList.Count) //过滤掉已经Close的排序件,因为已经暂停 { businessException.AddMessage("扫描条码的数量和排序装箱单明细的数量不匹配。"); } #endregion #region 条码匹配检查,按顺序检查排序件条码 int i = 0; foreach (SequenceDetail sequenceDetail in sequenceMaster.SequenceDetails.Where(d => !d.IsClose).OrderBy(d => d.Sequence)) { LocationLotDetail locationLotDetail = locationLotDetailList.Where(l => l.HuId == huIdList[i]).Single(); i++; if (sequenceDetail.Item != locationLotDetail.Item) { businessException.AddMessage("排序装箱单序号{0}所需的零件为{1},扫描的零件为{2}。", sequenceDetail.Sequence.ToString(), sequenceDetail.Item, locationLotDetail.Item); } } if (businessException.HasMessage) { throw businessException; } #endregion #region 更新排序装箱单头 sequenceMaster.Status = CodeMaster.SequenceStatus.Pack; sequenceMaster.PackUserId = SecurityContextHolder.Get().Id; sequenceMaster.PackUserName = SecurityContextHolder.Get().FullName; sequenceMaster.PackDate = DateTime.Now; this.genericMgr.Update(sequenceMaster); #endregion #region 装箱操作 i = 0; foreach (SequenceDetail sequenceDetail in sequenceMaster.SequenceDetails.Where(d => !d.IsClose)) { LocationLotDetail locationLotDetail = locationLotDetailList.Where(l => l.HuId == huIdList[i]).Single(); i++; sequenceDetail.HuId = locationLotDetail.HuId; sequenceDetail.LotNo = locationLotDetail.LotNo; this.genericMgr.Update(sequenceDetail); } #endregion }
private void CloseOrder(OrderMaster orderMaster, bool isForce, bool isThrowException = true) { if (orderMaster.Status == CodeMaster.OrderStatus.InProcess || orderMaster.Status == CodeMaster.OrderStatus.Complete) { DateTime dateTimeNow = DateTime.Now; User user = SecurityContextHolder.Get(); this.genericMgr.FlushSession(); BusinessException businessException = new BusinessException(); #region 强制关闭生产单,先把状态改为Complete if (isForce && orderMaster.Status == CodeMaster.OrderStatus.InProcess && orderMaster.Type == CodeMaster.OrderType.Production) { //生产先做订单完工 orderMaster.Status = CodeMaster.OrderStatus.Complete; orderMaster.CompleteDate = dateTimeNow; orderMaster.CompleteUserId = user.Id; orderMaster.CompleteUserName = user.FullName; this.genericMgr.Update(orderMaster); } #endregion #region 条件1所有订单明细收货数大于等于订单数 //强制关闭不用校验这条 if (!isForce) { string hql = "select count(*) as counter from OrderDetail where OrderNo = ? and (ReceivedQty+ScrapQty) < OrderedQty"; long counter = this.genericMgr.FindAll<long>(hql, new Object[] { orderMaster.OrderNo })[0]; if (counter > 0) { return; } } #endregion #region 条件2所有送货单明细全部关闭 if (orderMaster.Type != CodeMaster.OrderType.Production) { string hql = "select count(*) as counter from IpDetail where OrderNo = ? and IsClose = ?"; long counter = this.genericMgr.FindAll<long>(hql, new Object[] { orderMaster.OrderNo, false })[0]; if (counter > 0) { if (!isForce) { //非强制关闭直接返回 return; } businessException.AddMessage("和订单相关的送货单明细没有全部关闭,不能关闭订单{0}。", orderMaster.OrderNo); } } #endregion #region 条件3所有的拣货单全部关闭 if (orderMaster.Type == CodeMaster.OrderType.Transfer || orderMaster.Type == CodeMaster.OrderType.SubContractTransfer || orderMaster.Type == CodeMaster.OrderType.Distribution) { string hql = "select count(*) as counter from PickListDetail where OrderNo = ? and IsClose = ?"; long counter = this.genericMgr.FindAll<long>(hql, new Object[] { orderMaster.OrderNo, false })[0]; if (counter > 0) { if (!isForce) { //非强制关闭直接返回 return; } businessException.AddMessage("和订单相关的捡货单明细没有全部关闭,不能关闭订单{0}。", orderMaster.OrderNo); } } #endregion if (businessException.HasMessage) { if (isThrowException) { throw businessException; } } else { orderMaster.Status = CodeMaster.OrderStatus.Close; orderMaster.CloseDate = dateTimeNow; orderMaster.CloseUserId = user.Id; orderMaster.CloseUserName = user.FullName; this.genericMgr.Update(orderMaster); } } else if (!isForce) { throw new BusinessException("不能关闭状态为{1}的订单{0}。", orderMaster.OrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.OrderStatus, ((int)orderMaster.Status).ToString())); } }
private void CheckKitIpDetail(IpMaster ipMaster, bool isCheckKitTraceItem) { BusinessException businessException = new BusinessException(); #region 明细行是否收/发货判断 IList<IpDetail> unReceivedIpDetailList = LoadExceptIpDetails(ipMaster.IpNo, ipMaster.IpDetails.Select(det => det.Id).ToArray()); if (unReceivedIpDetailList != null && unReceivedIpDetailList.Count > 0) { foreach (IpDetail unReceivedIpDetail in unReceivedIpDetailList) { businessException.AddMessage("KIT送货单{0}行号{1}零件号{2}没有收货。", ipMaster.IpNo, unReceivedIpDetail.Sequence.ToString(), unReceivedIpDetail.Item); } } #endregion #region 收/发货数是否等于订单数判断 foreach (IpDetail ipDetail in ipMaster.IpDetails) { if (ipDetail.Qty != ipDetail.ReceiveQtyInput) { businessException.AddMessage("KIT送货单{0}行号{1}零件号{2}的收货数和送货数不一致。", ipMaster.IpNo, ipDetail.Sequence.ToString(), ipDetail.Item); } } #endregion #region KIT中的关键件是否扫描 if (isCheckKitTraceItem) { foreach (IpDetail ipDetail in ipMaster.IpDetails.Where(o => o.IsScanHu)) { if (ipDetail.Qty != ipDetail.IpDetailInputs.Where(o => !string.IsNullOrWhiteSpace(o.HuId)).Count()) { businessException.AddMessage("KIT送货单{0}行号{1}的关键零件{1}没有扫描。", ipMaster.IpNo, ipDetail.Sequence.ToString(), ipDetail.Item); } } } #endregion if (businessException.HasMessage) { throw businessException; } }
private void CheckShipFiFo(IList<OrderMaster> orderMasterList) { var orderMaster = orderMasterList.First(); if (!orderMaster.IsShipScanHu || orderMaster.QualityType == CodeMaster.QualityType.Reject) { //如果发货不扫描条码,就不校验发货先进先出 return; } var isShipFiFo = orderMasterList.Select(p => p.IsShipFifo).Distinct(); if (isShipFiFo.Count() > 1) { throw new BusinessException("发货先进先出选项不同不能合并发货。"); } if (!isShipFiFo.First()) { //如果不校验发货先进先出 return; } var locations = orderMasterList .SelectMany(p => p.OrderDetails) .Select(p => p.LocationFrom) .Where(p => !string.IsNullOrWhiteSpace(p)) .Distinct(); if (locations.Count() > 1) { throw new BusinessException("不同的发货库位不能合并发货"); } var distinctItemCodes = orderMasterList .SelectMany(p => p.OrderDetails) .Select(p => p.Item) .Where(p => !string.IsNullOrWhiteSpace(p)) .Distinct(); #region 查找库存 #region 拼SQL string statement = string.Empty; IList<object> detailPara = new List<object>(); foreach (var itemCode in distinctItemCodes) { if (statement == string.Empty) { statement = @"select l.Item,l.HuId, l.LotNo, l.Direction from VIEW_LocationLotDet l where l.HuId is not null and l.Location = ? and l.QualityType = ? and l.OccupyType = ? and l.IsATP = ? and l.IsFreeze = ?"; detailPara.Add(locations.First()); detailPara.Add(orderMaster.QualityType); detailPara.Add(CodeMaster.OccupyType.None); detailPara.Add(true); detailPara.Add(false); statement += " and l.Item in (?"; } else { statement += ", ?"; } detailPara.Add(itemCode); } statement += ") order by l.LotNo Asc "; #endregion var locationDetailsGroup = this.genericMgr.FindAllWithNativeSql<object[]>(statement, detailPara.ToArray()) .Select(p => new { Item = (string)p[0], HuId = (string)p[1], LotNo = (string)p[2], Direction = p[3] == null ? string.Empty : (string)p[3] }) .GroupBy(p => new { p.Item, p.Direction }) .ToDictionary(d => d.Key, d => d.ToList()); #endregion var orderDetailsGroup = orderMasterList.SelectMany(p => p.OrderDetails) .GroupBy(p => new { p.Item, p.Direction }); var bussinessException = new BusinessException(); foreach (var orderDetails in orderDetailsGroup) { var orderDetailInputs = orderDetails.SelectMany(p => p.OrderDetailInputs).ToList(); var maxLotNo = orderDetailInputs.OrderBy(p => p.LotNo).Last().LotNo; var huIds = orderDetailInputs.Select(p => p.HuId).ToList(); var locationDetails = locationDetailsGroup.ValueOrDefault(orderDetails.Key); if (locationDetails == null) { throw new BusinessException("没有找到合适的库存"); } var minLotNoLocationDetail = locationDetails.Where(p => !huIds.Contains(p.HuId)).OrderBy(p => p.LotNo).FirstOrDefault(); string minLotNo = null; if (minLotNoLocationDetail != null) { minLotNo = minLotNoLocationDetail.LotNo; } var directionDesc = string.Empty; if (!string.IsNullOrWhiteSpace(orderDetails.Key.Direction)) { var direction = this.genericMgr.FindById<HuTo>(orderDetails.Key.Direction); directionDesc = string.Format("/方向:{0}", direction.CodeDescription); } var itemDesc = orderDetails.First().ItemDescription; if (minLotNo != null && string.Compare(maxLotNo, minLotNo) > 0) { //throw new BusinessException(string.Format("物料{0}[{1}]{2}违反了先进先出,不能发货", // orderDetails.Key.Item, orderDetails.First().ItemDescription, directionDesc)); } } if (bussinessException.HasMessage) { throw bussinessException; } }
public void CreateInspectMaster(InspectMaster inspectMaster, DateTime effectiveDate) { #region 检查 if (inspectMaster.InspectDetails == null || inspectMaster.InspectDetails.Where(i => i.InspectQty > 0 || !string.IsNullOrWhiteSpace(i.HuId)).Count() == 0) { throw new BusinessException("报验单明细不能为空。"); } inspectMaster.InspectDetails = inspectMaster.InspectDetails.Where(i => i.InspectQty > 0 || !string.IsNullOrWhiteSpace(i.HuId)).OrderBy(det => det.Sequence).ToList(); if (inspectMaster.Type == CodeMaster.InspectType.Barcode) { BusinessException businessException = new BusinessException(); IList<HuStatus> huStatusList = huMgr.GetHuStatus(inspectMaster.InspectDetails.Select(i => i.HuId).ToList()); #region 查找零件 string hql = string.Empty; IList<object> paras = new List<object>(); foreach (string itemCode in huStatusList.Select(i => i.Item).Distinct()) { if (hql == string.Empty) { hql = "from Item where Code in (?"; } else { hql += ", ?"; } paras.Add(itemCode); } hql += ")"; IList<Item> itemList = this.genericMgr.FindAll<Item>(hql, paras.ToArray()); #endregion int seq = 1; //新的序号 foreach (InspectDetail inspectDetail in inspectMaster.InspectDetails) { HuStatus huStatus = huStatusList.Where(h => h.HuId == inspectDetail.HuId).SingleOrDefault(); if (huStatus == null) { businessException.AddMessage("条码{0}不存在。", inspectDetail.HuId); } else if (huStatus.Status == CodeMaster.HuStatus.NA) { businessException.AddMessage("条码{0}不在任何库位中,不能报验。", huStatus.HuId); } else if (huStatus.Status == CodeMaster.HuStatus.Ip) { businessException.AddMessage("条码{0}为库位{1}至库位{2}的在途库存,不能报验。", huStatus.HuId, huStatus.LocationFrom, huStatus.LocationTo); } else if (huStatus.OccupyType != CodeMaster.OccupyType.None) { businessException.AddMessage("条码{0}已经被占用,不能报验", huStatus.HuId); } else { inspectDetail.Sequence = seq++; inspectDetail.Item = huStatus.Item; inspectDetail.ItemDescription = itemList.Where(i => i.Code == huStatus.Item).Single().Description; inspectDetail.ReferenceItemCode = huStatus.ReferenceItemCode; inspectDetail.UnitCount = huStatus.UnitCount; inspectDetail.Uom = huStatus.Uom; inspectDetail.BaseUom = huStatus.BaseUom; inspectDetail.UnitQty = huStatus.UnitQty; inspectDetail.LotNo = huStatus.LotNo; inspectDetail.LocationFrom = huStatus.Location; inspectDetail.CurrentLocation = huStatus.Location; inspectDetail.InspectQty = huStatus.Qty; } } #region 检查报验零件是否在同一个区域中 IList<string> regionList = huStatusList.Select(l => l.Region).Distinct().ToList(); if (regionList != null && regionList.Count > 1) { throw new BusinessException("条码的库位属于不同区域不能合并报验。"); } inspectMaster.Region = regionList.Single(); #endregion if (businessException.HasMessage) { throw businessException; } } #endregion #region 创建报验单头 inspectMaster.InspectNo = this.numberControlMgr.GetInspectNo(inspectMaster); this.genericMgr.Create(inspectMaster); #endregion #region 创建报验单明细 foreach (var inspectDetail in inspectMaster.InspectDetails) { inspectDetail.InspectNo = inspectMaster.InspectNo; inspectDetail.ManufactureParty = inspectMaster.ManufactureParty; this.genericMgr.Create(inspectDetail); } #endregion #region 库存操作 locationDetailMgr.InventoryInspect(inspectMaster, effectiveDate); #endregion }
private void GenPurchaseRccp(DateTime planVersion, CodeMaster.TimeUnit dateType, BusinessException businessException, IList<MrpFlowDetail> mrpFlowDetailList, IEnumerable<RccpTransGroup> rccpTransGroupList, DateTime snapTime, User user) { if(businessException.GetMessages().Where(p => p.MessageType == CodeMaster.MessageType.Error).Count() > 0) { //如果有错误,退出,不产生采购物料需求 return; } var flowDetails = mrpFlowDetailList .Where(p => p.Type == CodeMaster.OrderType.Procurement || p.Type == CodeMaster.OrderType.CustomerGoods || p.Type == CodeMaster.OrderType.SubContract || p.Type == CodeMaster.OrderType.ScheduleLine); var purchasePlanList = new List<PurchasePlan>(); var rccpTransGroupByIndexList = (from p in rccpTransGroupList group p by p.DateIndex into g select new { DateIndex = g.Key, List = g }).OrderBy(p => p.DateIndex).ToList(); foreach(var rccpTransGroupByIndex in rccpTransGroupByIndexList) { DateTime windowTime = DateTime.Now; if(dateType == CodeMaster.TimeUnit.Week) { windowTime = DateTimeHelper.GetWeekIndexDateFrom(rccpTransGroupByIndex.DateIndex); } else if(dateType == CodeMaster.TimeUnit.Month) { windowTime = DateTime.Parse(rccpTransGroupByIndex.DateIndex + "-01"); } var mrpFlowDetailDic = flowDetails.Where(p => p.StartDate <= windowTime && p.EndDate > windowTime) .GroupBy(p => p.Item, (k, g) => new { k, g }) .ToDictionary(d => d.k, d => d.g); foreach(var groupRccpTrans in rccpTransGroupByIndex.List) { var mrpFlowDetails = mrpFlowDetailDic.ValueOrDefault(groupRccpTrans.Item); if(mrpFlowDetails != null) { foreach(var mrpFlowDetail in mrpFlowDetails) { var purchasePlan = new PurchasePlan(); purchasePlan.Item = groupRccpTrans.Item; //purchasePlan.Sequence = mrpFlowDetail.Sequence; purchasePlan.Flow = mrpFlowDetail.Flow; purchasePlan.LocationTo = mrpFlowDetail.LocationTo; purchasePlan.OrderType = mrpFlowDetail.Type; purchasePlan.WindowTime = windowTime; var leadDay = Utility.DateTimeHelper.TimeTranfer((decimal)mrpFlowDetail.LeadTime, CodeMaster.TimeUnit.Hour, CodeMaster.TimeUnit.Day); if(dateType == CodeMaster.TimeUnit.Week) { purchasePlan.StartTime = purchasePlan.WindowTime.AddDays(3).AddDays(-leadDay); purchasePlan.StartTime = Utility.DateTimeHelper.GetWeekStart(purchasePlan.StartTime); } else { purchasePlan.StartTime = purchasePlan.WindowTime.AddDays(15).AddDays(-leadDay); purchasePlan.StartTime = Utility.DateTimeHelper.GetStartTime(CodeMaster.TimeUnit.Month, purchasePlan.StartTime); } purchasePlan.Qty = (mrpFlowDetail.MrpWeight / mrpFlowDetails.Sum(p => p.MrpWeight)) * groupRccpTrans.Qty; purchasePlan.PlanQty = purchasePlan.Qty; purchasePlan.DateType = dateType; purchasePlan.PlanVersion = planVersion; purchasePlanList.Add(purchasePlan); } } else { if(groupRccpTrans.IsLastLevel) { businessException.AddMessage(new Message(CodeMaster.MessageType.Warning, "没有找到物料{0}的采购路线", groupRccpTrans.Item)); } } } } string hql = string.Empty; if(dateType == CodeMaster.TimeUnit.Week) { hql = "from FlowStrategy where IsCheckMrpWeeklyPlan =? and Flow in(?"; } else if(dateType == CodeMaster.TimeUnit.Month) { hql = "from FlowStrategy where IsCheckMrpMonthlyPlan =? and Flow in(?"; } var flowStategys = this.genericMgr.FindAllIn<FlowStrategy> (hql, purchasePlanList.Select(p => p.Flow).Where(p => !string.IsNullOrWhiteSpace(p)).Distinct(), new object[] { true }); var flowMasterDic = this.genericMgr.FindAllIn<FlowMaster> ("from FlowMaster where Code in(?", flowStategys.Select(p => p.Flow).Distinct()) .GroupBy(p => p.Code, (k, g) => new { k, g.First().Description }) .ToDictionary(d => d.k, d => d.Description); foreach(var flowStategy in flowStategys) { PurchasePlanMaster purchasePlanMaster = new PurchasePlanMaster(); purchasePlanMaster.DateType = dateType; purchasePlanMaster.Flow = flowStategy.Flow; purchasePlanMaster.FlowDescription = flowMasterDic[flowStategy.Flow]; purchasePlanMaster.PlanVersion = planVersion; purchasePlanMaster.SnapTime = snapTime; purchasePlanMaster.SourcePlanVersion = snapTime; purchasePlanMaster.CreateUserId = user.Id; purchasePlanMaster.CreateUserName = user.FullName; purchasePlanMaster.CreateDate = DateTime.Now; purchasePlanMaster.LastModifyUserId = user.Id; purchasePlanMaster.LastModifyUserName = user.FullName; purchasePlanMaster.LastModifyDate = DateTime.Now; this.genericMgr.Create(purchasePlanMaster); } purchasePlanList = purchasePlanList.Where(p => flowStategys.Select(q => q.Flow).Contains(p.Flow)).ToList(); this.genericMgr.BulkInsert<PurchasePlan>(purchasePlanList); }
private void GenMiRccp(DateTime planVersion, CodeMaster.TimeUnit dateType, string dateIndex, IList<MrpFlowDetail> mrpFlowDetailList, List<RccpTransGroup> rccpTransGroupList, BusinessException businessException) { var itemDiscontinueList = this.genericMgr.FindAll<ItemDiscontinue>(); var rccpMiPlanList = new List<RccpMiPlan>(); var workCalendars = this.genericMgr.FindAll<WorkCalendar> (@" from WorkCalendar as w where w.DateType =? and w.ResourceGroup=? and w.DateIndex between ? and ? ", new object[] { dateType, CodeMaster.ResourceGroup.MI, dateIndex, rccpTransGroupList.Max(p => p.DateIndex) }); double cleanTime = double.Parse(systemMgr.GetEntityPreferenceValue(Entity.SYS.EntityPreference.CodeEnum.MiCleanTime)); var miFlowDetailList = mrpFlowDetailList.Where(p => p.ResourceGroup == CodeMaster.ResourceGroup.MI); foreach(var groupRccpTrans in rccpTransGroupList) { DateTime dateFrom = DateTime.Now; if(dateType == CodeMaster.TimeUnit.Week) { dateFrom = Utility.DateTimeHelper.GetWeekIndexDateFrom(groupRccpTrans.DateIndex); } else { dateFrom = DateTime.Parse(groupRccpTrans.DateIndex + "-01"); } var mrpFlowDetail = miFlowDetailList.FirstOrDefault(p => p.ResourceGroup == CodeMaster.ResourceGroup.MI && p.Item == groupRccpTrans.Item && p.StartDate <= dateFrom && p.EndDate > dateFrom); if(mrpFlowDetail != null) { var workCalendar = workCalendars.FirstOrDefault(p => p.DateIndex == groupRccpTrans.DateIndex && p.Flow == mrpFlowDetail.Flow); var miPlan = new RccpMiPlan(); DateTime planDate = DateTime.Now; if(workCalendar != null) { miPlan.HaltTime = workCalendar.HaltTime * 24 * 60; miPlan.TrialProduceTime = workCalendar.TrialTime * 24 * 60; miPlan.Holiday = workCalendar.Holiday * 24 * 60; miPlan.UpTime = workCalendar.UpTime * 24 * 60; if(dateType == CodeMaster.TimeUnit.Month) { planDate = DateTime.Parse(groupRccpTrans.DateIndex + "-01"); //miPlan.UpTime = DateTime.DaysInMonth(planDate.Year, planDate.Month) * 24 * 60 * ((8 * 60 - cleanTime) / (8 * 60)); //miPlan.UpTime = workCalendar.UpTime * 24 * 60; } else if(dateType == CodeMaster.TimeUnit.Week) { planDate = Utility.DateTimeHelper.GetWeekIndexDateFrom(groupRccpTrans.DateIndex); //miPlan.HaltTime = (7 - workCalendar.Holiday) * 24 * 60 * (cleanTime / (8 * 60)); //miPlan.UpTime = (7 - workCalendar.Holiday) * 24 * 60 * ((8 * 60 - cleanTime) / (8 * 60)); } } else { //出错 businessException.AddMessage("没有找到炼胶的工作日历"); } miPlan.ProductLine = mrpFlowDetail.Flow; miPlan.Item = groupRccpTrans.Item; miPlan.DateIndex = groupRccpTrans.DateIndex; miPlan.DateType = dateType; miPlan.PlanVersion = planVersion; miPlan.Qty = groupRccpTrans.Qty; var miItem = this.itemMgr.GetCacheItem(groupRccpTrans.Item); if(miItem == null) { businessException.AddMessage(new Message(CodeMaster.MessageType.Error, string.Format("没有找到此物料{0}的对应的工时", groupRccpTrans.Item))); } else { miPlan.WorkHour = miItem.WorkHour; } miPlan.CheRateQty = mrpFlowDetail.UnitCount; //替代物料 var itemDiscontinues = itemDiscontinueList.Where(p => p.Item == miPlan.Item && p.StartDate <= planDate && (!p.EndDate.HasValue || (p.EndDate.HasValue && p.EndDate.Value > planDate))).OrderBy(p => p.Priority).ToList(); var items = new List<string>(); items.Add(miPlan.Item); items.AddRange(itemDiscontinues.Select(p => p.DiscontinueItem)); //可委外的物料 var flowDetail = mrpFlowDetailList.FirstOrDefault(f => f.Type == CodeMaster.OrderType.SubContract && items.Contains(f.Item)); if(flowDetail != null) { miPlan.SubFlowDetail = flowDetail; } rccpMiPlanList.Add(miPlan); //this.genericMgr.Create(miPlan); } } var groupMiPlans = (from p in rccpMiPlanList group p by new { p.ProductLine, p.DateIndex, p.UpTime } into g select new { ProductLine = g.Key.ProductLine, DateIndex = g.Key.DateIndex, UpTime = g.Key.UpTime, List = g }).OrderBy(p => p.DateIndex).ThenBy(p => p.ProductLine); var purchasePlanList = new List<PurchasePlan>(); foreach(var groupMiPlan in groupMiPlans) { double requireTime = groupMiPlan.List.Sum(p => p.RequireTime); double currentTime = requireTime - groupMiPlan.UpTime; if(currentTime > 0) { DateTime dateFrom = DateTime.Now; if(dateType == CodeMaster.TimeUnit.Week) { dateFrom = Utility.DateTimeHelper.GetWeekIndexDateFrom(groupMiPlan.DateIndex); } else { dateFrom = DateTime.Parse(groupMiPlan.DateIndex + "-01"); } foreach(var plan in groupMiPlan.List) { if(plan.SubFlowDetail != null) { double currentQty = (currentTime / plan.WorkHour) * plan.CheRateQty; double subQty = currentQty > plan.Qty ? plan.Qty : currentQty; currentTime = currentTime - (subQty / plan.CheRateQty) * plan.WorkHour; var purchasePlan = new PurchasePlan(); purchasePlan.Item = plan.Item; //purchasePlan.Sequence = plan.SubFlowDetail.Sequence; purchasePlan.Flow = plan.SubFlowDetail.Flow; purchasePlan.LocationTo = plan.SubFlowDetail.LocationTo; purchasePlan.OrderType = plan.SubFlowDetail.Type; purchasePlan.WindowTime = dateFrom; purchasePlan.StartTime = dateFrom.AddHours(-plan.SubFlowDetail.LeadTime); purchasePlan.Qty = subQty; purchasePlan.PlanQty = subQty; purchasePlan.DateType = dateType; purchasePlan.PlanVersion = planVersion; purchasePlanList.Add(purchasePlan); plan.SubQty = subQty; plan.Qty -= subQty; //auto update } } } } #region Create this.genericMgr.BulkInsert<RccpMiPlan>(rccpMiPlanList); this.genericMgr.BulkInsert<PurchasePlan>(purchasePlanList); #endregion Create }
public void MergePlanBill(IList<HuStatus> huStatusList) { BusinessException businessException = new BusinessException(); if (huStatusList.Where(h => h.PlanBill.HasValue == false).Count() > 0) { businessException.AddMessage("所有的条码必须为寄售"); } IList<PlanBill> planBillList = new List<PlanBill>(); var lastOrderNo = string.Empty; var total = 0M; Int32? mergedPlanBill = 0; for (int i = 0; i < huStatusList.Count;i++) { var planBill = this.genericMgr.FindById<PlanBill>(huStatusList[i].PlanBill); if (string.IsNullOrEmpty(lastOrderNo)) { //记录第一个订单号 lastOrderNo = planBill.OrderNo; } else { if (lastOrderNo != planBill.OrderNo) { businessException.AddMessage("不允许多个订单合并翻箱"); break; } } if (i < huStatusList.Count - 1) { total += huStatusList[i].Qty; planBill.PlanQty -= huStatusList[i].Qty; } else { mergedPlanBill = planBill.Id; planBill.PlanQty += total; } planBill.HuId = null; this.genericMgr.Update(planBill); } if (businessException.HasMessage) { throw businessException; } foreach (var huStatus in huStatusList) { huStatus.PlanBill = mergedPlanBill.Value; } }
public string New(string checkedIds, string Region) { IList<LocationLotDetail> viewLocationList = new List<LocationLotDetail>(); string[] checkedIdArray = checkedIds.Split(','); string selectStatement = string.Empty; IList<object> selectPartyPara = new List<object>(); foreach (var para in checkedIdArray) { if (selectStatement == string.Empty) { selectStatement = "from LocationLotDetail where Id in (?"; } else { selectStatement += ",?"; } selectPartyPara.Add(para); } selectStatement += ")"; viewLocationList = genericMgr.FindAll<LocationLotDetail>(selectStatement, selectPartyPara.ToArray()); BusinessException businessException = new BusinessException(); try { #region orderDetailList IList<InspectDetail> inspectDetailList = new List<InspectDetail>(); if (viewLocationList != null && viewLocationList.Count() > 0) { foreach (LocationLotDetail locationlotdetail in viewLocationList) { InspectDetail inspectDetail = new InspectDetail(); Item item = this.genericMgr.FindById<Item>(locationlotdetail.Item); inspectDetail.Item = locationlotdetail.Item; inspectDetail.HuId = locationlotdetail.HuId; inspectDetail.LotNo = locationlotdetail.LotNo; inspectDetail.ItemDescription = item.Description; inspectDetail.UnitCount = locationlotdetail.UnitCount; inspectDetail.ReferenceItemCode = item.ReferenceCode; inspectDetail.Uom = item.Uom; inspectDetail.LocationFrom =locationlotdetail.Location; inspectDetail.CurrentLocation = locationlotdetail.Location; inspectDetail.BaseUom = item.Uom; inspectDetail.UnitQty = 1; inspectDetailList.Add(inspectDetail); } } #endregion if (businessException.HasMessage) { throw businessException; } if (inspectDetailList != null && inspectDetailList.Count == 0) { throw new BusinessException(Resources.INP.InspectDetail.Errors_InspectDetail_Required); } InspectMaster inspectMaster = new InspectMaster(); inspectMaster.Region = Region; inspectMaster.InspectDetails = inspectDetailList; inspectMaster.Type = com.Sconit.CodeMaster.InspectType.Barcode; inspectMaster.IsATP = false; inspectMgr.CreateInspectMaster(inspectMaster); SaveSuccessMessage(Resources.INP.InspectMaster.InspectMaster_Added); return inspectMaster.InspectNo; } catch (BusinessException ex) { Response.TrySkipIisCustomErrors = true; Response.StatusCode = 500; string messagesStr = ""; IList<Message> messageList = ex.GetMessages(); foreach (Message message in messageList) { messagesStr += message.GetMessageString() ; } Response.Write(messagesStr); return string.Empty; } }
public void ReadDailyMrpPlanFromXls(Stream inputStream, DateTime? startDate, DateTime? endDate, string flowCode, bool isItemRef) { #region 判断 if (startDate.HasValue) { if (startDate.Value.Date < DateTime.Now.Date) { throw new BusinessException("开始日期必须大于当期日期"); } } else { startDate = DateTime.Now.Date; } if (endDate.HasValue) { if (endDate.Value.Date <= DateTime.Now.Date) { throw new BusinessException("结束日期必须大于当期日期"); } } else { endDate = DateTime.MaxValue.Date; } if (startDate.Value > endDate.Value) { throw new BusinessException("开始日期必须小于结束日期"); } if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } #endregion 判断 HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); IRow dateRow = sheet.GetRow(5); ImportHelper.JumpRows(rows, 6); #region 列定义 int colFlow = 0; //int colLocation = 0;//库位 int colItemCode = 1;//物料代码或参考物料号 //int colItemDescription = 2;//物料描述 int colUom = 3;//单位 #endregion List<FlowDetail> flowDetailList = new List<FlowDetail>(); var uomDic = this.genericMgr.FindAll<Uom>().ToDictionary(d => d.Code, d => d); if (string.IsNullOrWhiteSpace(flowCode)) { var flowMasters = this.genericMgr.FindAll<FlowMaster>(" from FlowMaster where Type=?", CodeMaster.OrderType.Distribution).ToList(); foreach (var flowMaster in flowMasters) { flowDetailList.AddRange(GetFlowDetails(flowMaster)); } } else { flowDetailList = GetFlowDetails(flowCode).ToList(); } var flowDetailDic = flowDetailList.GroupBy(p => p.Flow, (k, g) => new { k, g }).ToDictionary(d => d.k, d => d.g); List<MrpPlanLog> mrpPlanLogList = new List<MrpPlanLog>(); BusinessException businessException = new BusinessException(); while (rows.MoveNext()) { Item item = null; string uomCode = null; string itemReference = null; string flow = null; HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 0, 3)) { break;//边界 } string rowIndex = (row.RowNum + 1).ToString(); #region 读取路线 try { string flowCell = ImportHelper.GetCellStringValue(row.GetCell(colFlow)); if (flowCell != null && flowDetailDic.ContainsKey(flowCell)) { flow = flowCell; } else { businessException.AddMessage(string.Format("读取路线出错,第{0}行.", rowIndex)); continue; } } catch (Exception ex) { businessException.AddMessage(string.Format("读取路线出错,第{0}行." + ex.Message, rowIndex)); continue; } var flowDetails = flowDetailDic.ValueOrDefault(flow); #endregion #region 读取物料代码 try { string itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItemCode)); if (itemCode == null) { businessException.AddMessage(string.Format("物料号不能为空,第{0}行", rowIndex)); continue; } if (isItemRef) { item = this.genericMgr.FindAll<Item>("from Item as i where i.ReferenceCode = ? ", new object[] { itemCode }, 0, 1).First(); itemReference = itemCode; } else { item = this.itemMgr.GetCacheItem(itemCode); itemReference = item.ReferenceCode; } if (item == null) { businessException.AddMessage(string.Format("物料号{0}不存在,第{1}行.", itemCode, rowIndex)); continue; } } catch (Exception ex) { businessException.AddMessage(ex.Message + ". 第" + rowIndex + "行."); continue; } #endregion #region 读取单位 try { string uomCell = ImportHelper.GetCellStringValue(row.GetCell(colUom)); uomCode = uomDic.ValueOrDefault(uomCell).Code; } catch (Exception ex) { businessException.AddMessage(ex.Message + ". 第" + rowIndex + "行."); continue; } #endregion #region 使用flowDetails过滤 var q = flowDetails.Where(f => f.Item == item.Code && f.Uom == uomCode); string locationCode = string.Empty; if (q.Count() > 0) { locationCode = !string.IsNullOrWhiteSpace(q.FirstOrDefault().LocationFrom) ? q.FirstOrDefault().LocationFrom : q.FirstOrDefault().CurrentFlowMaster.LocationFrom; } else { if (flowDetails.First().CurrentFlowMaster.IsManualCreateDetail) { uomCode = uomCode == null ? item.Uom : uomCode; locationCode = flowDetails.First().CurrentFlowMaster.LocationFrom; } else { businessException.AddMessage(string.Format("没有找到匹配的路线明细,第{0}行.物料{1},单位{2}", rowIndex, item.Code, uomCode)); continue; } } #endregion #region 读取数量 try { for (int i = 4; ; i++) { ICell dateCell = dateRow.GetCell(i); #region 读取计划日期 DateTime currentDate = DateTime.Now; string weekOfYear = string.Empty; if (dateCell != null) { if (dateCell.CellType == CellType.NUMERIC) { currentDate = dateCell.DateCellValue; } else if (dateCell.CellType == CellType.STRING) { currentDate = DateTime.Parse(dateCell.StringCellValue); } } else { break; } if (startDate.HasValue && currentDate.Date < startDate.Value.Date) { continue; } if (endDate.HasValue && currentDate.Date > endDate.Value.Date) { break; } #endregion double qty = 0; if (row.GetCell(i) != null) { if (row.GetCell(i).CellType == CellType.NUMERIC) { qty = row.GetCell(i).NumericCellValue; } else { string qtyValue = ImportHelper.GetCellStringValue(row.GetCell(i)); if (qtyValue != null) { qty = Convert.ToDouble(qtyValue); } } } else { continue; } if (qty < 0) { businessException.AddMessage(string.Format("数量必须大于0,第{0}行", rowIndex)); continue; } else { MrpPlanLog mrpPlanLog = new MrpPlanLog(); decimal unitQty = itemMgr.ConvertItemUomQty(item.Code, uomCode, 1, item.Uom); mrpPlanLog.PlanDate = currentDate; mrpPlanLog.Item = item.Code; //dailyPlanLog.PlanVersion = dailyPlan.PlanVersion; mrpPlanLog.Flow = flowDetails.First().CurrentFlowMaster.Code; mrpPlanLog.Location = locationCode; mrpPlanLog.Party = flowDetails.First().CurrentFlowMaster.PartyTo; mrpPlanLog.OrderType = flowDetails.First().CurrentFlowMaster.Type; mrpPlanLog.Uom = uomCode; mrpPlanLog.Qty = qty; mrpPlanLog.UnitQty = unitQty; mrpPlanLog.ItemDescription = item.CodeDescription; mrpPlanLog.ItemReference = item.ReferenceCode; //dailyPlanLog.CreateDate = System.DateTime.Now; //dailyPlanLog.CreateUserId = user.Id; //dailyPlanLog.CreateUserName = user.FullName; mrpPlanLogList.Add(mrpPlanLog); } } } catch (Exception ex) { businessException.AddMessage(string.Format("读取数量出错,第{0}行." + ex.Message, rowIndex)); } #endregion } var mrpPlanLogGroups = mrpPlanLogList.GroupBy(p => p.Flow, (k, g) => new { k, g }); foreach (var mrpPlanLogGroup in mrpPlanLogGroups) { CreateMrpPlan(mrpPlanLogGroup.k, mrpPlanLogGroup.g.ToList()); } if (businessException.HasMessage) { throw businessException; } }
public List<MrpShiftPlan> ReadShiftPlanFromXls(Stream inputStream, DateTime startDate, DateTime endDate, string flow) { if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); IRow dateRow = sheet.GetRow(2); ImportHelper.JumpRows(rows, 3); #region 列定义 int colFlow = 0;// 路线 int colItemCode = 1;//物料代码或参考物料号 //int colItemDescription = 2;//物料描述 int colUom = 3;//单位 #endregion var shiftPlanList = new List<MrpShiftPlan>(); #region 读取数据 while (rows.MoveNext()) { string itemCode = null; string uomCode = null; string flowCode = null; HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 0, 4)) { break;//边界 } string rowIndex = (row.RowNum + 1).ToString(); #region 读取路线 try { flowCode = ImportHelper.GetCellStringValue(row.GetCell(colFlow)); if (flowCode == null) { throw new BusinessException("生产线不能为空", rowIndex); } else { if (!string.IsNullOrWhiteSpace(flow) && flow != flowCode) { continue; } } } catch (Exception ex) { throw new BusinessException(ex.Message); } #endregion #region 读取物料代码 try { itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItemCode)); if (itemCode == null) { throw new BusinessException("Import.ShipPlan.ItemCode.Empty", rowIndex); } } catch { throw new BusinessException("Import.ShipPlan.ItemCode.Error", rowIndex); } #endregion #region 读取单位 try { uomCode = ImportHelper.GetCellStringValue(row.GetCell(colUom)); } catch (Exception ex) { throw new BusinessException(ex.Message); } #endregion #region 读取数量 try { for (int i = 5; ; i++) { ICell dateCell = dateRow.GetCell(i - ((i - 5) % 3)); #region 读取计划日期 DateTime planDate = DateTime.Now; string weekOfYear = string.Empty; if (dateCell != null && dateCell.CellType == CellType.NUMERIC) { planDate = dateCell.DateCellValue; } else { break; } if (planDate.Date <= DateTime.Now) { continue; } if (planDate.Date < startDate.Date) { continue; } if (planDate.Date > endDate.Date) { break; } #endregion double qty = 0; if (row.GetCell(i) != null) { if (row.GetCell(i).CellType == CellType.NUMERIC) { qty = row.GetCell(i).NumericCellValue; } else { string qtyValue = ImportHelper.GetCellStringValue(row.GetCell(i)); if (qtyValue != null) { qty = Convert.ToDouble(qtyValue); } } } else { continue; } if (qty < 0) { throw new BusinessException("Import.ShipPlan.Qty.MustGreatThan0", rowIndex); } else if (qty == 0) { continue; } else { var shiftPlan = new MrpShiftPlan(); shiftPlan.PlanDate = planDate; shiftPlan.Item = itemCode; shiftPlan.Flow = flowCode; shiftPlan.Uom = uomCode; shiftPlan.Qty = qty; shiftPlanList.Add(shiftPlan); } } } catch (Exception ex) { throw new BusinessException("Import.ShipPlan.Qty.Error" + ex.Message, rowIndex); } #endregion } #endregion var flowCodes = shiftPlanList.Select(s => s.Flow).Distinct(); #region 读取路线 var flowDetailList = new List<FlowDetail>(); foreach (var flowCode in flowCodes) { var flowDetails = this.flowMgr.GetFlowDetailList(flowCode, false, true); if (flowDetails == null || flowDetails.Count() == 0) { FlowMaster flowMaster = this.genericMgr.FindById<FlowMaster>(flowCode); if (flowMaster.IsManualCreateDetail) { flowDetails = new List<FlowDetail>(); var flowDetail = new FlowDetail(); flowDetail.CurrentFlowMaster = flowMaster; flowDetails.Add(flowDetail); } } flowDetailList.AddRange(flowDetails); } #endregion BusinessException bex = new BusinessException(); #region 校验数据的有效性 foreach (var shiftPlan in shiftPlanList) { var flowDetails = flowDetailList.Where(f => f.CurrentFlowMaster.Code == shiftPlan.Flow); if (!flowDetails.First().CurrentFlowMaster.IsManualCreateDetail) { if (string.IsNullOrWhiteSpace(shiftPlan.Uom)) { flowDetails = flowDetails.Where(f => f.Item == shiftPlan.Item); if (flowDetails == null || flowDetails.Count() == 0) { bex.AddMessage("此物料在路线中不存在"); } else { shiftPlan.Uom = flowDetails.First().Uom; } } else { flowDetails = flowDetails.Where(f => f.Item == shiftPlan.Item && f.Uom == shiftPlan.Uom); if (flowDetails == null || flowDetails.Count() == 0) { bex.AddMessage("此物料在路线中不存在"); } } //shiftPlan.Machine = flowDetails.First().Machine; //Machine machine = this.genericMgr.FindById<Machine>(shiftPlan.Machine); //shiftPlan.ShiftQuota = machine.ShiftQuota; } else { if (string.IsNullOrWhiteSpace(shiftPlan.Uom)) { flowDetails = flowDetails.Where(f => f.Item == shiftPlan.Item); } else { flowDetails = flowDetails.Where(f => f.Item == shiftPlan.Item && f.Uom == shiftPlan.Uom); } if (flowDetails != null && flowDetails.Count() > 0) { //shiftPlan.Machine = flowDetails.First().Machine; //shiftPlan.Uom = flowDetails.First().Uom; //Machine machine = this.genericMgr.FindById<Machine>(shiftPlan.Machine); //shiftPlan.ShiftQuota = machine.ShiftQuota; } else { Item item = this.genericMgr.FindById<Item>(shiftPlan.Item); if (!string.IsNullOrWhiteSpace(shiftPlan.Uom)) { Uom uom = this.genericMgr.FindById<Uom>(shiftPlan.Uom); } else { shiftPlan.Uom = item.Uom; } } } } #endregion if (!bex.HasMessage) { int planVersion = int.Parse(numberControlMgr.GetNextSequence(com.Sconit.Entity.MRP.BusinessConstants.NUMBERCONTROL_SHIFTPLAN)); foreach (var shiftPlan in shiftPlanList) { var oldShiftPlans = this.genericMgr.FindAll<MrpShiftPlan> ("select d from ShiftPlan as d where d.PlanDate=? and d.Item=? and d.Flow=? and d.Shift=? ", new object[] { shiftPlan.PlanDate, shiftPlan.Item, shiftPlan.Flow, shiftPlan.Shift }); if (oldShiftPlans != null && oldShiftPlans.Count() > 0) { //var oldShiftPlan = oldShiftPlans.First(); //if (shiftPlan.Machine != oldShiftPlan.Machine // || shiftPlan.Qty != oldShiftPlan.Qty // || shiftPlan.ShiftQuota != oldShiftPlan.ShiftQuota // || shiftPlan.Uom != oldShiftPlan.Uom) //{ // if (oldShiftPlan.OrderQty > 0) // { // bex.AddMessage("已转生产单的班产计划不能再进行更改"); // } // else // { // oldShiftPlan.PlanVersion = planVersion; // oldShiftPlan.Machine = shiftPlan.Machine; // oldShiftPlan.Qty = shiftPlan.Qty; // oldShiftPlan.ShiftQuota = shiftPlan.ShiftQuota; // oldShiftPlan.Uom = shiftPlan.Uom; // //this.genericMgr.Update(oldShiftPlan); // //createlog // var shiftPlanLog = new MrpShiftPlanLog(); // shiftPlanLog.PlanVersion = planVersion; // shiftPlanLog.PlanId = oldShiftPlan.Id; // shiftPlanLog.Machine = oldShiftPlan.Machine; // shiftPlanLog.Qty = oldShiftPlan.Qty; // shiftPlanLog.ShiftQuota = oldShiftPlan.ShiftQuota; // shiftPlanLog.Uom = oldShiftPlan.Uom; // this.genericMgr.Create(shiftPlanLog); // } //} } else { //shiftPlan.PlanVersion = planVersion; //this.genericMgr.Create(shiftPlan); //var shiftPlanLog = new MrpShiftPlanLog(); //shiftPlanLog.PlanVersion = planVersion; //shiftPlanLog.PlanId = shiftPlan.Id; //shiftPlanLog.Machine = shiftPlan.Machine; //shiftPlanLog.Qty = shiftPlan.Qty; //shiftPlanLog.ShiftQuota = shiftPlan.ShiftQuota; //shiftPlanLog.Uom = shiftPlan.Uom; //this.genericMgr.Create(shiftPlanLog); } } } else { throw bex; } return shiftPlanList; }
public void ReadRccpPlanFromXls(Stream inputStream, DateTime startDate, DateTime endDate, bool isItemRef, com.Sconit.CodeMaster.TimeUnit dateType) { #region 判断 if (startDate > endDate) { throw new BusinessException("开始日期必须小于结束日期"); } #endregion 判断 #region Import if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); IRow dateRow = sheet.GetRow(5); ImportHelper.JumpRows(rows, 6); var rccpPlanLogList = new List<RccpPlanLog>(); #region 列定义 int colFlow = 0;//路线 int colItemCode = 1;//物料代码或参考物料号 int colUom = 3;//单位 #endregion BusinessException businessException = new BusinessException(); while (rows.MoveNext()) { Item item = null; string uomCode = null; string itemReference = null; string flowCode = null; HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 0, 3)) { break;//边界 } string rowIndex = (row.RowNum + 1).ToString(); #region 读取路线代码 flowCode = ImportHelper.GetCellStringValue(row.GetCell(colFlow)); #endregion #region 读取物料代码 try { string itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItemCode)); if (itemCode == null) { businessException.AddMessage(string.Format("物料不能为空,第{0}行", rowIndex)); continue; } if (isItemRef) { item = this.genericMgr.FindAll<Item>("from Item as i where i.ReferenceCode = ? ", new object[] { itemCode }, 0, 1).First(); itemReference = itemCode; } else { item = this.itemMgr.GetCacheItem(itemCode); itemReference = item.ReferenceCode; } if (item == null) { businessException.AddMessage(string.Format("物料号{0}不存在,第{1}行.", itemCode, rowIndex)); continue; } if (item.ItemCategory != "MODEL") { businessException.AddMessage(string.Format("物料号{0}不是车型,第{1}行.", itemCode, rowIndex)); continue; } } catch { businessException.AddMessage(string.Format("读取物料时出错,第{0}行.", rowIndex)); continue; } #endregion #region 读取单位 try { string uomCell = ImportHelper.GetCellStringValue(row.GetCell(colUom)); uomCode = this.genericMgr.FindById<Uom>(uomCell).Code; } catch (Exception ex) { businessException.AddMessage(string.Format("读取单位出错,第{0}行." + ex.Message, rowIndex)); continue; } #endregion #region 读取数量 try { for (int i = 4; ; i++) { ICell dateCell = dateRow.GetCell(i); string dateIndex = null; #region 读取计划日期 if (dateCell != null) { if (dateCell.CellType == CellType.STRING) { dateIndex = dateCell.StringCellValue; } else { if (dateType == CodeMaster.TimeUnit.Month) { if (dateCell.CellType == CellType.NUMERIC) { dateIndex = dateCell.DateCellValue.ToString("yyyy-MM"); } else { throw new BusinessException("月的时间索引必须为文本或日期格式"); } } else if (dateType == CodeMaster.TimeUnit.Day) { if (dateCell.CellType == CellType.NUMERIC) { dateIndex = dateCell.DateCellValue.ToString("yyyy-MM-dd"); } else { throw new BusinessException("天的时间索引必须为文本或日期格式"); } } else { throw new BusinessException("周的时间索引必须为文本格式"); } } if (string.IsNullOrWhiteSpace(dateIndex)) { break; } DateTime currentDateTime = DateTime.Now; if (dateType == CodeMaster.TimeUnit.Week) { currentDateTime = DateTimeHelper.GetWeekIndexDateFrom(dateIndex); } else if (dateType == CodeMaster.TimeUnit.Month) { if (!DateTime.TryParse(dateIndex + "-01", out currentDateTime)) { businessException.AddMessage("日期{0}格式无效", dateIndex); continue; } } else if (dateType == CodeMaster.TimeUnit.Day) { if (!DateTime.TryParse(dateIndex, out currentDateTime)) { businessException.AddMessage("日期{0}格式无效", dateIndex); continue; } } if (currentDateTime.CompareTo(startDate) < 0) { continue; } if (currentDateTime.CompareTo(endDate) > 0) { break; } } else { break; } #endregion double qty = 0; if (row.GetCell(i) != null) { if (row.GetCell(i).CellType == CellType.NUMERIC) { qty = row.GetCell(i).NumericCellValue; } else { string qtyValue = ImportHelper.GetCellStringValue(row.GetCell(i)); if (qtyValue != null) { qty = Convert.ToDouble(qtyValue); } } } else { continue; } if (qty < 0) { businessException.AddMessage(string.Format("数量需大于0,第{0}行", rowIndex)); continue; } else { decimal unitQty = itemMgr.ConvertItemUomQty(item.Code, uomCode, 1, item.Uom); RccpPlanLog rccpPlanLog = new RccpPlanLog(); rccpPlanLog.Flow = flowCode; rccpPlanLog.DateIndexTo = dateIndex; rccpPlanLog.DateIndex = dateIndex; rccpPlanLog.Item = item.Code; rccpPlanLog.Uom = uomCode; rccpPlanLog.DateType = dateType; rccpPlanLog.Qty = qty; rccpPlanLog.UnitQty = unitQty; rccpPlanLog.ItemDescription = item.CodeDescription; rccpPlanLog.ItemReference = item.ReferenceCode; rccpPlanLogList.Add(rccpPlanLog); } } } catch (Exception ex) { businessException.AddMessage(ex.Message); } #endregion } if (businessException.HasMessage) { throw businessException; } #endregion var flowMasters = this.genericMgr.FindAll<FlowMaster> (@"from FlowMaster as m where m.IsActive = ? and Type=? ", new object[] { true, CodeMaster.OrderType.Distribution }); #region Day if (dateType == CodeMaster.TimeUnit.Day) { var flowDetails = new List<FlowDetail>(); foreach (var flow in flowMasters) { foreach (var flowDetail in flowMgr.GetFlowDetailList(flow, false, true)) { if (flowDetail.MrpWeight > 0) { //flowDetail.DefaultLocationFrom = string.IsNullOrWhiteSpace(flowDetail.LocationFrom) ? flowDetail.CurrentFlowMaster.LocationFrom : flowDetail.LocationFrom; //flowDetail.DefaultLocationTo = string.IsNullOrWhiteSpace(flowDetail.LocationTo) ? flowDetail.CurrentFlowMaster.LocationTo : flowDetail.LocationTo; flowDetails.Add(flowDetail); } } } var flowDetailDic = flowDetails.GroupBy(p => new { Flow = p.Flow, Item = p.Item }).ToDictionary(d => d.Key, d => d.First()); var mrpPlanLogs = new List<MrpPlanLog>(); foreach (var rccpPlanLog in rccpPlanLogList) { try { var bomDetails = bomMgr.GetFlatBomDetail(rccpPlanLog.Item, DateTime.Parse(rccpPlanLog.DateIndex), true); var bomMaster = this.bomMgr.GetCacheBomMaster(rccpPlanLog.Item); var qty = itemMgr.ConvertItemUomQty(rccpPlanLog.Item, rccpPlanLog.Uom, (decimal)rccpPlanLog.Qty, bomMaster.Uom); foreach (var bomDetail in bomDetails) { var flowDetail = flowDetailDic.ValueOrDefault(new { Flow = rccpPlanLog.Flow, Item = bomDetail.Item }); if (flowDetail == null) { businessException.AddMessage("销售路线{0}中不存在此物料{1}", rccpPlanLog.Flow, bomDetail.Item); } else { var mrpPlanLog = new MrpPlanLog(); mrpPlanLog.Flow = rccpPlanLog.Flow; mrpPlanLog.Item = bomDetail.Item; Item bomItem = this.itemMgr.GetCacheItem(bomDetail.Item); mrpPlanLog.ItemDescription = bomItem.Description; mrpPlanLog.ItemReference = bomItem.ReferenceCode; mrpPlanLog.Location = flowDetail.DefaultLocationFrom; mrpPlanLog.OrderType = flowDetail.CurrentFlowMaster.Type; mrpPlanLog.Party = flowDetail.CurrentFlowMaster.PartyTo; mrpPlanLog.PlanDate = DateTime.Parse(rccpPlanLog.DateIndex); var item = this.itemMgr.GetCacheItem(mrpPlanLog.Item); mrpPlanLog.Qty = (double)itemMgr.ConvertItemUomQty(rccpPlanLog.Item, bomDetail.Uom, qty * bomDetail.CalculatedQty, item.Uom); decimal unitQty = itemMgr.ConvertItemUomQty(rccpPlanLog.Item, flowDetail.Uom, 1, item.Uom); mrpPlanLog.UnitQty = unitQty; mrpPlanLog.Uom = flowDetail.Uom; mrpPlanLogs.Add(mrpPlanLog); } } } catch (Exception) { businessException.AddMessage(string.Format("分解bom{0}出错", rccpPlanLog.Item)); } } if (businessException.HasMessage) { throw businessException; } var groupMrpPlanLogs = mrpPlanLogs.GroupBy(p => p.Flow, (k, g) => new { k, List = from q in g group q by new { q.PlanDate, q.Item, q.PlanVersion, q.Flow, q.Location } into result select new MrpPlanLog { PlanDate = result.Key.PlanDate, Item = result.Key.Item, PlanVersion = result.Key.PlanVersion, Flow = result.Key.Flow, Location = result.Key.Location, Qty = result.Sum(r => r.Qty), Uom = result.First().Uom, UnitQty = result.First().UnitQty, ItemDescription = result.First().ItemDescription, ItemReference = result.First().ItemReference, Party = result.First().Party, OrderType = result.First().OrderType } }); foreach (var groupMrpPlanLog in groupMrpPlanLogs) { this.CreateMrpPlan(groupMrpPlanLog.k, groupMrpPlanLog.List.ToList()); } } #endregion CreateRccpPlan(dateType, rccpPlanLogList); }
public void Import201202MiscOrder(Stream inputStream, string wMSNo, string moveTypeSet, string cancelMoveTypeSet,string miscType) { #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, 10); #region 列定义 int colMoveType = 1;//移动类型 //int colEffectiveDate = 2;//生效日期 //int colRegion = 3;//区域 int colLocation = 2;//库位 //int colReferenceNo = 5;//Sap订单号 int colItem = 3;//物料编号 int colQty = 4;//数量 int colCostCenter = 5;//成本中心 DateTime? prevEffeDate = null; string prevRegion = string.Empty; #endregion BusinessException businessException = new BusinessException(); int rowCount = 10; IList<MiscOrderDetail> activeDetailList = new List<MiscOrderDetail>(); IList<MiscOrderMaster> activeMasterList = new List<MiscOrderMaster>(); IList<Region> regionList = this.genericMgr.FindAll<Region>(); IList<Item> itemList = this.genericMgr.FindAll<Item>(); IList<Location> locationList = this.genericMgr.FindAll<Location>(); IList<Location> adjustocationList = this.genericMgr.FindAll<Location>(); IList<CostCenter> costCenterList = this.genericMgr.FindAll<CostCenter>(); //调整单Check库位权限 User user = SecurityContextHolder.Get(); string sql = @"select * from MD_Location as l where Code in(select distinct(LocFrom) from SCM_FlowMstr where type=4) and l.IsActive = ?"; IList<object> paramList = new List<object>(); paramList.Add(true); sql += " order by LEN(Code),Code "; adjustocationList = genericMgr.FindEntityWithNativeSql<Location>(sql, paramList.ToArray()) .Where(p => user.RegionPermissions.Contains(p.Region)).ToList(); // while (rows.MoveNext()) { rowCount++; HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 9)) { break;//边界 } string moveType = string.Empty; DateTime effectiveDate = System.DateTime.Now; string regionCode = string.Empty; string locationCode = string.Empty; string costCenterCode = string.Empty; string referenceNo = string.Empty; string itemCode = string.Empty; decimal qty = 0; Item item = new Item(); #region 读取数据 #region 移动类型 moveType = ImportHelper.GetCellStringValue(row.GetCell(colMoveType)); if (string.IsNullOrWhiteSpace(moveType)) { businessException.AddMessage(string.Format("第{0}行:移动类型不能为空。", rowCount)); } else { if (moveType != moveTypeSet && moveType != cancelMoveTypeSet) { businessException.AddMessage(string.Format("第{0}行:移动类型{1}填写有误,只能填{2}、{3}。", rowCount, moveType, moveTypeSet, cancelMoveTypeSet)); } } #endregion //#region 生效日期 //string readEffectiveDate = ImportHelper.GetCellStringValue(row.GetCell(colEffectiveDate)); //if (string.IsNullOrWhiteSpace(readEffectiveDate)) //{ // businessException.AddMessage(string.Format("第{0}行:生效日期不能为空。", rowCount)); //} //else //{ // if (!DateTime.TryParse(readEffectiveDate, out effectiveDate)) // { // businessException.AddMessage(string.Format("第{0}行:生效日期{1}填写有误.", rowCount, moveType)); // continue; // } // if (prevEffeDate != null) // { // if (prevEffeDate.Value != effectiveDate) // { // businessException.AddMessage(string.Format("第{0}行:生效日期{1}与前一行生效日期{2}不同。", rowCount, effectiveDate, prevEffeDate.Value)); // continue; // } // } // prevEffeDate = effectiveDate; //} //#endregion //#region 区域 //regionCode = ImportHelper.GetCellStringValue(row.GetCell(colRegion)); //if (string.IsNullOrWhiteSpace(regionCode)) //{ // businessException.AddMessage(string.Format("第{0}行:区域不能为空。", rowCount)); //} //else //{ // if (string.IsNullOrWhiteSpace(prevRegion)) // { // var regions = regionList.Where(l => l.Code == regionCode).ToList(); // if (regions == null || regions.Count == 0) // { // businessException.AddMessage(string.Format("第{0}行:区域{1}填写有误.", rowCount, regionCode)); // } // } // else // { // if (regionCode != prevRegion) // { // businessException.AddMessage(string.Format("第{0}行:区域{1}与前一行区域{2}不同。", rowCount, regionCode, prevRegion)); // continue; // } // } // prevRegion = regionCode; //} //#endregion #region 读取库位 locationCode = ImportHelper.GetCellStringValue(row.GetCell(colLocation)); if (!string.IsNullOrEmpty(locationCode)) { var locations = locationList.Where(l => l.Code == locationCode).ToList(); if (locations == null || locations.Count == 0) { businessException.AddMessage(string.Format("第{0}行:库位{1}不存在。", rowCount, locationCode)); } //else if (locations.First().Region != regionCode) //{ // businessException.AddMessage(string.Format("第{0}行:区域{1}不存在库位{2}。", rowCount, regionCode, locationCode)); //} else { regionCode = locations[0].Region; } if (miscType == "AdjustOrder") { var adjustlocations = adjustocationList.Where(l => l.Code == locationCode).ToList(); if (adjustlocations == null || adjustlocations.Count == 0) { businessException.AddMessage(string.Format("第{0}行:用户没有调整库位{1}的权限。", rowCount, locationCode)); } } } else { //businessException.AddMessage(string.Format("第{0}行:区域不能为空。", rowCount)); } #endregion #region 成本中心 costCenterCode = ImportHelper.GetCellStringValue(row.GetCell(colCostCenter)); if (!string.IsNullOrEmpty(costCenterCode)) { var costCenters = costCenterList.Where(l => l.Code == costCenterCode).ToList(); if (costCenters == null || costCenters.Count == 0) { businessException.AddMessage(string.Format("第{0}行:成本中心{1}不存在。", rowCount, costCenterCode)); } else { costCenterCode = costCenters.ToList().FirstOrDefault().Code; } //else if (locations.First().Region != regionCode) //{ // businessException.AddMessage(string.Format("第{0}行:区域{1}不存在库位{2}。", rowCount, regionCode, locationCode)); //} } else if (moveTypeSet=="201") { businessException.AddMessage(string.Format("第{0}行:成本中心不能为空。", rowCount)); } #endregion //#region Sap订单号 //referenceNo = ImportHelper.GetCellStringValue(row.GetCell(colReferenceNo)); //if (string.IsNullOrEmpty(referenceNo)) //{ // businessException.AddMessage(string.Format("第{0}行:Sap订单号不能为空。", rowCount)); //} //else //{ // //if (this.genericMgr.FindAllWithNativeSql<int>("select count(*) from SAP_ProdBomDet where AUFNR=? ", referenceNo.PadLeft(12, '0'))[0] == 0) // //{ // // businessException.AddMessage(string.Format("第{0}行:Sap订单号不存在ORD_OrderMstr_4表中。", rowCount)); // //} //} //#endregion #region 物料编号 itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItem)); if (string.IsNullOrWhiteSpace(itemCode)) { businessException.AddMessage(string.Format("第{0}行:物料编号不能为空。", rowCount)); } else { var items = itemList.Where(l => l.Code == itemCode).ToList(); if (items == null || items.Count == 0) { businessException.AddMessage(string.Format("第{0}行:物料编号{1}不存在.", rowCount, itemCode)); } else { item = items.First(); } } #endregion #region 数量 string readQty = ImportHelper.GetCellStringValue(row.GetCell(colQty)); if (string.IsNullOrEmpty(readQty)) { businessException.AddMessage(string.Format("第{0}行:数量不能为空。", rowCount)); } else { decimal.TryParse(readQty, out qty); if (qty <= 0) { businessException.AddMessage(string.Format("第{0}行:数量{1}只能为大于等于0的数字。", rowCount, readQty)); } } #endregion #endregion #region 填充数据 if (!businessException.HasMessage) { MiscOrderDetail miscOrderDetail = new MiscOrderDetail(); miscOrderDetail.MoveType = moveType; miscOrderDetail.EffectiveDate = effectiveDate; miscOrderDetail.Location = locationCode; miscOrderDetail.Region= regionCode; miscOrderDetail.Item = item.Code; miscOrderDetail.ItemDescription = item.Description; miscOrderDetail.ReferenceItemCode = item.ReferenceCode; miscOrderDetail.Uom = item.Uom; miscOrderDetail.BaseUom = item.Uom; miscOrderDetail.UnitCount = item.UnitCount; miscOrderDetail.Qty = qty; miscOrderDetail.CostCenter = costCenterCode; activeDetailList.Add(miscOrderDetail); } #endregion } if (businessException.HasMessage) { throw businessException; } if (activeDetailList.Count == 0) { throw new BusinessException("导入的有效数据为0,请确实。"); } //Merge details //201一张单 var allLocation = activeDetailList.Select(p => p.Location).Distinct(); foreach (var location in allLocation) { var outDetail = activeDetailList.Where(a => a.MoveType == moveTypeSet && a.Location==(string)location).ToList(); if (outDetail != null && outDetail.Count > 0) { MiscOrderDetail fisrDet = outDetail.First(); MiscOrderMoveType miscOrderMoveType = genericMgr.FindAll<MiscOrderMoveType>("from MiscOrderMoveType as m where m.MoveType =? ", moveTypeSet)[0]; MiscOrderMaster miscMaster = new MiscOrderMaster(); miscMaster.Type = miscOrderMoveType.IOType; miscMaster.MoveType = miscOrderMoveType.MoveType; miscMaster.CancelMoveType = miscOrderMoveType.CancelMoveType; miscMaster.Location = fisrDet.Location; miscMaster.Region = fisrDet.Region; miscMaster.EffectiveDate = fisrDet.EffectiveDate; miscMaster.IsScanHu = false; miscMaster.ReferenceNo = null; miscMaster.MiscOrderDetails = outDetail; miscMaster.WMSNo = wMSNo; //备注 miscMaster.CostCenter = fisrDet.CostCenter; miscMaster.SubType = miscType == "AdjustOrder" ? CodeMaster.MiscOrderSubType.SY05 : CodeMaster.MiscOrderSubType.COST; activeMasterList.Add(miscMaster); } //202 一张单 var inDetail = activeDetailList.Where(a => a.MoveType == cancelMoveTypeSet && a.Location == (string)location).ToList(); if (inDetail != null && inDetail.Count > 0) { MiscOrderDetail fisrInDet = inDetail.First(); MiscOrderMoveType miscOrderInMoveType = genericMgr.FindAll<MiscOrderMoveType>("from MiscOrderMoveType as m where m.MoveType =? ", cancelMoveTypeSet)[0]; var inMiscOrder = new MiscOrderMaster(); inMiscOrder.Type = miscOrderInMoveType.IOType; inMiscOrder.MoveType = miscOrderInMoveType.MoveType; inMiscOrder.CancelMoveType = miscOrderInMoveType.CancelMoveType; inMiscOrder.Location = fisrInDet.Location; inMiscOrder.Region = fisrInDet.Region; inMiscOrder.EffectiveDate = fisrInDet.EffectiveDate; inMiscOrder.IsScanHu = false; inMiscOrder.ReferenceNo = null; inMiscOrder.MiscOrderDetails = inDetail; inMiscOrder.WMSNo = wMSNo; //备注 inMiscOrder.CostCenter = fisrInDet.CostCenter; inMiscOrder.SubType = miscType == "AdjustOrder" ? CodeMaster.MiscOrderSubType.SY05 : CodeMaster.MiscOrderSubType.COST; activeMasterList.Add(inMiscOrder); } } if (businessException.HasMessage) { throw businessException; } string message = "生成单号"; foreach (var master in activeMasterList) { master.QualityType = com.Sconit.CodeMaster.QualityType.Qualified; activeDetailList = (from p in master.MiscOrderDetails group p by new { p.Item, p.ItemDescription, p.ReferenceItemCode, p.Uom, p.BaseUom, p.UnitCount, p.Location } into g select new MiscOrderDetail { Sequence = g.Max(p => p.Sequence), Item = g.Key.Item, ItemDescription = g.Key.ItemDescription, ReferenceItemCode = g.Key.ReferenceItemCode, Uom = g.Key.Uom, BaseUom = g.Key.BaseUom, UnitCount = g.Key.UnitCount, UnitQty = 1, Location = g.Key.Location, Qty = g.Sum(p => p.Qty), }).ToList(); master.MiscOrderDetails = new List<MiscOrderDetail>(); this.CreateMiscOrder(master); BatchUpdateMiscOrderDetails(master, activeDetailList, null, null); this.genericMgr.FlushSession(); master.MiscOrderDetails = null; //CloseMiscOrder(master, master.EffectiveDate); message += " " + master.MiscOrderNo + ";"; } MessageHolder.AddMessage(new Message(CodeMaster.MessageType.Info, message)); #endregion }
public void JudgeInspectDetail(IList<InspectDetail> inspectDetailList, DateTime effectiveDate) { #region 检查 if (inspectDetailList == null) { throw new BusinessException("判定结果不能为空。"); } IList<InspectDetail> noneZeroInspectDetailList = inspectDetailList.Where(i => i.CurrentQualifyQty > 0 || i.CurrentRejectQty > 0 || i.CurrentReturnQty > 0 || i.CurrentConcessionQty > 0).ToList(); if (noneZeroInspectDetailList == null || noneZeroInspectDetailList.Count == 0) { throw new BusinessException("判定结果不能为空。"); } BusinessException businessException = new BusinessException(); foreach (InspectDetail inspectDetail in noneZeroInspectDetailList) { if (inspectDetail.InspectQty < (inspectDetail.QualifyQty + inspectDetail.RejectQty + inspectDetail.CurrentQualifyQty + inspectDetail.CurrentRejectQty + inspectDetail.CurrentReturnQty + inspectDetail.CurrentConcessionQty)) { businessException.AddMessage("检验单{0}行号{1}的判定数超过了报验数。", inspectDetail.InspectNo, inspectDetail.Sequence.ToString()); } } if (businessException.HasMessage) { throw businessException; } #endregion #region 查找报验单头 string hql = string.Empty; IList<object> paras = new List<object>(); foreach (string inspectNo in noneZeroInspectDetailList.Select(i => i.InspectNo).Distinct()) { if (hql == string.Empty) { hql = "from InspectMaster where InspectNo in (?"; } else { hql += ", ?"; } paras.Add(inspectNo); } hql += ")"; IList<InspectMaster> inspectMasterList = this.genericMgr.FindAll<InspectMaster>(hql, paras.ToArray()); #endregion #region 生成报验结果 IList<InspectResult> inspectResultList = new List<InspectResult>(); #region 合格 ((List<InspectResult>)inspectResultList).AddRange(from det in noneZeroInspectDetailList where det.CurrentQualifyQty > 0 select new InspectResult { InspectNo = det.InspectNo, InspectDetailId = det.Id, InspectDetailSequence = det.Sequence, Item = det.Item, ItemDescription = det.ItemDescription, ReferenceItemCode = det.ReferenceItemCode, UnitCount = det.UnitCount, Uom = det.Uom, BaseUom = det.BaseUom, UnitQty = det.UnitQty, HuId = det.HuId, LotNo = det.LotNo, LocationFrom = det.LocationFrom, CurrentLocation = det.CurrentLocation, JudgeResult = CodeMaster.JudgeResult.Qualified, JudgeQty = det.CurrentQualifyQty, HandleQty = 0, IsHandle = false, ManufactureParty = det.ManufactureParty, IpNo = inspectMasterList.Where(mstr => mstr.InspectNo == det.InspectNo).Single().IpNo, IpDetailSequence = det.IpDetailSequence, WMSNo = det.WMSResNo, WMSSeq = det.WMSResSeq, ReceiptNo = inspectMasterList.Where(mstr => mstr.InspectNo == det.InspectNo).Single().ReceiptNo, ReceiptDetailSequence = det.ReceiptDetailSequence, }); #endregion #region 不合格 ((List<InspectResult>)inspectResultList).AddRange(from det in noneZeroInspectDetailList where det.CurrentRejectQty > 0 select new InspectResult { InspectNo = det.InspectNo, InspectDetailId = det.Id, InspectDetailSequence = det.Sequence, Item = det.Item, ItemDescription = det.ItemDescription, ReferenceItemCode = det.ReferenceItemCode, UnitCount = det.UnitCount, Uom = det.Uom, BaseUom = det.BaseUom, UnitQty = det.UnitQty, HuId = det.HuId, LotNo = det.LotNo, LocationFrom = det.LocationFrom, CurrentLocation = det.CurrentLocation, JudgeResult = CodeMaster.JudgeResult.Rejected, JudgeQty = det.CurrentRejectQty, HandleQty = 0, IsHandle = false, ManufactureParty = det.ManufactureParty, //CurrentHandleQty = det.CurrentIsRejectHandle ? det.CurrentRejectQty : 0, //CurrentRejectHandleResult = det.CurrentRejectHandleResult, IpNo = inspectMasterList.Where(mstr => mstr.InspectNo == det.InspectNo).Single().IpNo, IpDetailSequence = det.IpDetailSequence, FailCode = det.FailCode, Defect = det.Defect, WMSNo = det.WMSResNo, WMSSeq = det.WMSResSeq, Note = det.CurrentInspectResultNote, ReceiptNo = inspectMasterList.Where(mstr => mstr.InspectNo == det.InspectNo).Single().ReceiptNo, ReceiptDetailSequence = det.ReceiptDetailSequence, }); #endregion #region 退货 ((List<InspectResult>)inspectResultList).AddRange(from det in noneZeroInspectDetailList where det.CurrentReturnQty > 0 select new InspectResult { InspectNo = det.InspectNo, InspectDetailId = det.Id, InspectDetailSequence = det.Sequence, Item = det.Item, ItemDescription = det.ItemDescription, ReferenceItemCode = det.ReferenceItemCode, UnitCount = det.UnitCount, Uom = det.Uom, BaseUom = det.BaseUom, UnitQty = det.UnitQty, HuId = det.HuId, LotNo = det.LotNo, LocationFrom = det.LocationFrom, CurrentLocation = det.CurrentLocation, JudgeResult = CodeMaster.JudgeResult.Rejected, JudgeQty = det.CurrentReturnQty, HandleQty = 0, IsHandle = false, ManufactureParty = det.ManufactureParty, CurrentHandleQty = det.CurrentReturnQty, RejectHandleResult = CodeMaster.HandleResult.Return, IpNo = inspectMasterList.Where(mstr => mstr.InspectNo == det.InspectNo).Single().IpNo, IpDetailSequence = det.IpDetailSequence, FailCode = det.FailCode, Defect = det.Defect, WMSNo = det.WMSResNo, WMSSeq = det.WMSResSeq, Note = det.CurrentInspectResultNote, ReceiptNo = inspectMasterList.Where(mstr => mstr.InspectNo == det.InspectNo).Single().ReceiptNo, ReceiptDetailSequence = det.ReceiptDetailSequence, }); #endregion #region 让步使用 ((List<InspectResult>)inspectResultList).AddRange(from det in noneZeroInspectDetailList where det.CurrentConcessionQty > 0 select new InspectResult { InspectNo = det.InspectNo, InspectDetailId = det.Id, InspectDetailSequence = det.Sequence, Item = det.Item, ItemDescription = det.ItemDescription, ReferenceItemCode = det.ReferenceItemCode, UnitCount = det.UnitCount, Uom = det.Uom, BaseUom = det.BaseUom, UnitQty = det.UnitQty, HuId = det.HuId, LotNo = det.LotNo, LocationFrom = det.LocationFrom, CurrentLocation = det.CurrentLocation, JudgeResult = CodeMaster.JudgeResult.Rejected, JudgeQty = det.CurrentConcessionQty, HandleQty = 0, IsHandle = false, ManufactureParty = det.ManufactureParty, CurrentHandleQty = det.CurrentConcessionQty, RejectHandleResult = CodeMaster.HandleResult.Concession, IpNo = inspectMasterList.Where(mstr => mstr.InspectNo == det.InspectNo).Single().IpNo, IpDetailSequence = det.IpDetailSequence, FailCode = det.FailCode, Defect = det.Defect, WMSNo = det.WMSResNo, WMSSeq = det.WMSResSeq, Note = det.CurrentInspectResultNote, ReceiptNo = inspectMasterList.Where(mstr => mstr.InspectNo == det.InspectNo).Single().ReceiptNo, ReceiptDetailSequence = det.ReceiptDetailSequence, }); #endregion #endregion #region 保存报验头 foreach (InspectMaster inspectMaster in inspectMasterList) { if (inspectMaster.Status == CodeMaster.InspectStatus.Submit) { inspectMaster.Status = CodeMaster.InspectStatus.InProcess; this.genericMgr.Update(inspectMaster); } } #endregion #region 保存报验明细 foreach (InspectDetail inspectDetail in noneZeroInspectDetailList) { inspectDetail.QualifyQty += inspectDetail.CurrentQualifyQty; inspectDetail.RejectQty += inspectDetail.CurrentRejectQty; inspectDetail.RejectQty += inspectDetail.CurrentReturnQty; inspectDetail.RejectQty += inspectDetail.CurrentConcessionQty; if (inspectDetail.InspectQty == inspectDetail.QualifyQty + inspectDetail.RejectQty) { inspectDetail.IsJudge = true; } this.genericMgr.Update(inspectDetail); } #endregion #region 保存报验结果 foreach (InspectResult inspectResult in inspectResultList) { this.genericMgr.Create(inspectResult); } #endregion #region 关闭报验单 foreach (InspectMaster inspectMaster in inspectMasterList) { this.genericMgr.FlushSession(); TryCloseInspectMaster(inspectMaster); } #endregion #region 库存操作 foreach (InspectMaster inspectMaster in inspectMasterList) { this.locationDetailMgr.InspectJudge(inspectMaster, inspectResultList.Where(i => i.InspectNo == inspectMaster.InspectNo).ToList(), effectiveDate); } #endregion #region 不合格品自动处理 var autoCreateRejectList = from rst in inspectResultList where rst.CurrentHandleQty > 0 group rst by rst.RejectHandleResult into g select new { HandleResult = g.Key, InspectResultList = g.ToList() }; if (autoCreateRejectList != null && autoCreateRejectList.Count() > 0) { foreach (var autoCreateReject in autoCreateRejectList) { RejectMaster rejectMaster = CreateRejectMaster(autoCreateReject.HandleResult, autoCreateReject.InspectResultList, effectiveDate); ReleaseRejectMaster(rejectMaster); } } #endregion }
private void GenFiRccp(DateTime planVersion, CodeMaster.TimeUnit dateType, IList<MrpFlowDetail> mrpFlowDetailList, IList<RccpTrans> rccpTransList, BusinessException businessException) { var fiFlowDetailDic = mrpFlowDetailList.Where(p => p.ResourceGroup == CodeMaster.ResourceGroup.FI) .GroupBy(p => p.Item, (k, g) => new { k, g }).ToDictionary(d => d.k, d => d.g); var fiPlanList = new List<RccpFiPlan>(); var rccpTransGroups = rccpTransList.GroupBy(p => new { p.DateIndex, p.DateType, p.Item, p.PlanVersion, p.Model }, (k, g) => new { k, g }); foreach(var rccpTransGroup in rccpTransGroups) { DateTime dateFrom = DateTime.Now; if(dateType == CodeMaster.TimeUnit.Week) { dateFrom = Utility.DateTimeHelper.GetWeekIndexDateFrom(rccpTransGroup.k.DateIndex); } else { dateFrom = DateTime.Parse(rccpTransGroup.k.DateIndex + "-01"); } var mrpFlowDetail = (fiFlowDetailDic.ValueOrDefault(rccpTransGroup.k.Item) ?? new List<MrpFlowDetail>()) .FirstOrDefault(p => p.StartDate <= dateFrom && p.EndDate > dateFrom); if(mrpFlowDetail != null) { var fiPlan = new RccpFiPlan(); fiPlan.ProductLine = mrpFlowDetail.Flow; fiPlan.Machine = mrpFlowDetail.Machine == null ? string.Empty : mrpFlowDetail.Machine; fiPlan.Item = rccpTransGroup.k.Item; fiPlan.DateIndex = rccpTransGroup.k.DateIndex; fiPlan.DateType = dateType; fiPlan.PlanVersion = planVersion; fiPlan.Model = rccpTransGroup.k.Model ?? string.Empty; fiPlan.ModelRate = rccpTransGroup.g.First().ModelRate; fiPlan.Qty = rccpTransGroup.g.Sum(p => p.Qty); fiPlanList.Add(fiPlan); } } this.genericMgr.BulkInsert<RccpFiPlan>(fiPlanList); }
public void ImportFlow(Stream inputStream, CodeMaster.OrderType flowType) { 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, 10); #region 列定义 // FlowMaster int colType = 1;//路线类型 int colCode = 2; // 路线代码 int colDesc = 3; // 路线描述 // FlowDet int colItem = 4; // 物料 int colUom = 5; // 单位 int colUnitCount = 6; // 单包装 int colUcDesc = 7; // 单包装 int colMinStock = 8;// int colMaxStock = 9;// // FlowStrategy int colLeadTime = 10; // 提前期 #endregion var errorMessage = new BusinessException(); int colCount = 10; List<List<string>> rowDataList = new List<List<string>>(); var items = this.genericMgr.FindAll<Item>().ToDictionary(d => d.Code, d => d); #region 读取数据 while (rows.MoveNext()) { HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 8)) { break;//边界 } colCount++; var rowData = new List<string>(); #region FlowMaster rowData.Add("0"); rowData.Add(((int)flowType).ToString()); rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colCode))); if (string.IsNullOrWhiteSpace(rowData[2])) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.FlowCodeShouldNotEmpty, colCount.ToString())); } rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colDesc))); if (string.IsNullOrWhiteSpace(rowData[3])) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.FlowDescShouldNotEmpty, colCount.ToString())); } #endregion #region FlowDetail Item item = null; rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colItem))); if (!string.IsNullOrWhiteSpace(rowData[4])) { item = items.ValueOrDefault(rowData[4]); } if (item == null) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineItemNotFound, colCount.ToString(), rowData[4])); continue; } rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUom))); if (string.IsNullOrWhiteSpace(rowData[5])) { rowData[5] = item.Uom; } else { try { Uom uom = this.genericMgr.FindById<Uom>(rowData[5].ToUpper()); rowData[5] = uom.Code; } catch (Exception) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineUomNotFound, colCount.ToString(), rowData[5])); } } rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUnitCount))); if (string.IsNullOrWhiteSpace(rowData[6])) { rowData[6] = item.UnitCount.ToString(); } else { decimal unitCount = item.UnitCount; if (!decimal.TryParse(rowData[6], out unitCount)) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineUCIsNotNum, colCount.ToString())); } rowData[6] = unitCount == 0 ? item.UnitCount.ToString() : unitCount.ToString(); } //7 rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUcDesc))); rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colMinStock))); if (string.IsNullOrWhiteSpace(rowData[8])) { rowData[8] = "0"; } else { decimal decVal = 0m; if (!decimal.TryParse(rowData[8], out decVal)) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineSafeInvIsNotNum, colCount.ToString())); } rowData[8] = decVal.ToString(); } rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colMaxStock))); if (string.IsNullOrWhiteSpace(rowData[9])) { rowData[9] = "0"; } else { decimal decVal = 0m; if (!decimal.TryParse(rowData[9], out decVal)) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineMaxInvIsNotNum, colCount.ToString())); } rowData[9] = decVal.ToString(); } #endregion #region FlowStrategy rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colLeadTime))); if (string.IsNullOrWhiteSpace(rowData[10])) { rowData[10] = "0"; } else { decimal leadTimeVal = 0m; if (!decimal.TryParse(rowData[10], out leadTimeVal)) { rowData[0] = "1"; errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineLeantimeIsNotNum, colCount.ToString())); } rowData[10] = leadTimeVal.ToString(); } #endregion rowData.Add(item.Description);//11 rowData.Add(item.Uom);//12 rowData.Add(item.ReferenceCode);//13 rowDataList.Add(rowData); } #endregion #region 验证 //Excle中重复性验证 var flowItems = rowDataList.Where(p => p[0] == "0") .Select(p => new { Type = (CodeMaster.OrderType)(int.Parse(p[1])), Flow = p[2], FlowDescription = p[3], Item = p[4], Uom = p[5], UnitCount = decimal.Parse(p[6]), UcDesc = p[7], MinStock = decimal.Parse(p[8]), MaxStock = decimal.Parse(p[9]), LeadTime = decimal.Parse(p[10]), ItemDescription = p[11], BaseUom = p[12], ReferenceCode = p[13] }); if (flowItems == null || flowItems.Count() == 0) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheImportIsNotEffect); throw errorMessage; } var flowItemGroup = flowItems.GroupBy(p => new { p.Flow, p.Item, p.Uom, p.UnitCount }, (k, g) => new { k, Count = g.Count() }) .Where(p => p.Count > 1).Select(p => new { p.k.Flow, p.k.Item }); foreach (var flowItem in flowItemGroup) { errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.DuplicateFlowDetail, flowItem.Flow, flowItem.Item)); } var distinctFlowItems = flowItems.GroupBy(p => new { p.Flow, p.Item }, (k, g) => new { k, j = g.First() }) .Select(p => p.j); var excelFlowMasterList = distinctFlowItems.GroupBy(p => p.Flow, (k, g) => new { Code = k, List = g }); var flowMasterDic = this.genericMgr.FindAllIn<FlowMaster>("from FlowMaster where Code in(?", excelFlowMasterList.Select(p => p.Code)).ToDictionary(d => d.Code, d => d); var flowStrategyDic = this.genericMgr.FindAllIn<FlowStrategy>("from FlowStrategy where Flow in(?", excelFlowMasterList.Select(p => p.Code)).ToDictionary(d => d.Flow, d => d); var allParty = this.genericMgr.FindAll<Party>().ToDictionary(d => d.Code, d => d.Code); var allPriceList = this.genericMgr.FindAll<PriceListMaster>().ToDictionary(d => d.Code, d => d.Code); var allAddress = this.genericMgr.FindAll<Address>().ToDictionary(d => d.Code, d => d.Code); var allLocation = this.genericMgr.FindAll<Location>().ToDictionary(d => d.Code, d => d.Code); foreach (var excelFlowMaster in excelFlowMasterList) { var firstFlowItem = excelFlowMaster.List.First(); var flowMaster = flowMasterDic.ValueOrDefault(excelFlowMaster.Code); var flowStrategy = flowStrategyDic.ValueOrDefault(excelFlowMaster.Code); if (flowType != firstFlowItem.Type) { errorMessage.AddMessage(Resources.EXT.ServiceLan.FlowTypeIsNotCorrect, firstFlowItem.Type.ToString()); continue; } #region flowMaster if (flowMaster == null) { #region FlowMaster赋值 var flowCodeSplits = excelFlowMaster.Code.Split('-'); var flowDescriptionSplits = firstFlowItem.FlowDescription.Split('-'); var newFlowMaster = new FlowMaster(); newFlowMaster.Code = excelFlowMaster.Code; newFlowMaster.Type = firstFlowItem.Type; newFlowMaster.Description = firstFlowItem.FlowDescription; newFlowMaster.IsListDet = true; newFlowMaster.IsPrintOrder = true; newFlowMaster.IsPrintAsn = true; newFlowMaster.IsPrintRceipt = true; newFlowMaster.IsShipExceed = true; newFlowMaster.IsShipFifo = true; newFlowMaster.IsAllowProvEstRec = true; newFlowMaster.ReceiveGapTo = CodeMaster.ReceiveGapTo.AdjectLocFromInv; //Code Desc1 IsActive Type RefFlow PartyFrom PartyTo ShipFrom ShipTo LocFrom LocTo BillAddr //PriceList Routing ReturnRouting Dock IsAutoCreate IsAutoRelease IsAutoStart IsAutoShip IsAutoReceive //IsAutoBill IsListDet IsManualCreateDet IsListPrice IsPrintOrder IsPrintAsn IsPrintRcpt IsShipExceed //IsRecExceed IsOrderFulfillUC IsShipFulfillUC IsRecFulfillUC IsShipScanHu IsRecScanHu IsCreatePL //IsInspect IsShipFifo IsRejInspect IsRecFifo IsShipByOrder IsAsnUniqueRec IsMRP IsCheckPartyFromAuth //IsCheckPartyToAuth RecGapTo RecTemplate OrderTemplate AsnTemplate HuTemplate BillTerm CreateHuOpt //MaxOrderCount MRPOpt IsPause PauseTime FlowStrategy ExtraDmdSource PickStrategy CreateUser CreateUserNm //CreateDate LastModifyUser LastModifyUserNm LastModifyDate DAUAT LastRefreshDate ResourceGroup //IsAllowProvEstRec UcDeviation OrderDeviation if (firstFlowItem.Type == CodeMaster.OrderType.Procurement || firstFlowItem.Type == CodeMaster.OrderType.CustomerGoods || firstFlowItem.Type == CodeMaster.OrderType.SubContract) { newFlowMaster.PartyFrom = flowCodeSplits[0]; var location = this.genericMgr.FindById<Location>(flowCodeSplits[1]); newFlowMaster.PartyTo = location.Region; if (firstFlowItem.Type == CodeMaster.OrderType.SubContract) { newFlowMaster.LocationFrom = newFlowMaster.PartyFrom; } newFlowMaster.LocationTo = location.Code; newFlowMaster.BillAddress = newFlowMaster.PartyFrom; newFlowMaster.PriceList = newFlowMaster.PartyFrom; newFlowMaster.IsReceiveScanHu = true; newFlowMaster.OrderTemplate = "ORD_Purchase.xls"; newFlowMaster.AsnTemplate = "ASN_Purchase.xls"; newFlowMaster.ReceiptTemplate = "REC_Receipt.xls"; newFlowMaster.HuTemplate = "BarCodePurchase2D.xls"; newFlowMaster.BillTerm = CodeMaster.OrderBillTerm.ReceivingSettlement; newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None; newFlowMaster.IsListPrice = true; newFlowMaster.IsAsnUniqueReceive = true; newFlowMaster.IsAllowProvEstRec = true; } else if (firstFlowItem.Type == CodeMaster.OrderType.Distribution || firstFlowItem.Type == CodeMaster.OrderType.SubContractTransfer) { var location = this.genericMgr.FindById<Location>(flowCodeSplits[0]); newFlowMaster.LocationFrom = location.Code; newFlowMaster.PartyFrom = location.Region; newFlowMaster.PartyTo = flowCodeSplits[1]; if (firstFlowItem.Type == CodeMaster.OrderType.SubContractTransfer) { newFlowMaster.LocationTo = newFlowMaster.PartyTo; newFlowMaster.OrderTemplate = "ASN_Transfer.xls"; newFlowMaster.AsnTemplate = "ASN_Transfer.xls"; newFlowMaster.ReceiptTemplate = "REC_InvOut.xls"; newFlowMaster.HuTemplate = "BarCodeMI2D.xls"; } else { newFlowMaster.BillAddress = newFlowMaster.PartyTo; newFlowMaster.PriceList = newFlowMaster.PartyTo; newFlowMaster.OrderTemplate = "ORD_Sale.xls"; newFlowMaster.AsnTemplate = "ASN_Sale.xls"; newFlowMaster.ReceiptTemplate = "REC_Sale.xls"; newFlowMaster.HuTemplate = "BarCodeFI2D.xls"; newFlowMaster.BillTerm = CodeMaster.OrderBillTerm.ReceivingSettlement; newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None; } newFlowMaster.IsRejectInspect = true; newFlowMaster.IsShipScanHu = true; newFlowMaster.IsCreatePickList = false; } else if (firstFlowItem.Type == CodeMaster.OrderType.Production) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheProdLineNotFound, excelFlowMaster.Code); } else if (firstFlowItem.Type == CodeMaster.OrderType.Transfer) { var locationFrom = this.genericMgr.FindById<Location>(flowCodeSplits[0]); var locationTo = this.genericMgr.FindById<Location>(flowCodeSplits[1]); newFlowMaster.PartyFrom = locationFrom.Region; newFlowMaster.PartyTo = locationTo.Region; newFlowMaster.LocationFrom = locationFrom.Code; newFlowMaster.LocationTo = locationTo.Code; newFlowMaster.IsShipScanHu = true; newFlowMaster.IsReceiveScanHu = true; newFlowMaster.IsCreatePickList = false; newFlowMaster.OrderTemplate = "ASN_Transfer.xls"; newFlowMaster.AsnTemplate = "ASN_Transfer.xls"; newFlowMaster.ReceiptTemplate = "REC_InvOut.xls"; newFlowMaster.HuTemplate = "BarCodeEX2D.xls"; newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None; } newFlowMaster.ShipFrom = newFlowMaster.PartyFrom; newFlowMaster.ShipTo = newFlowMaster.PartyTo; #endregion #region 校验 bool isMark = false; if (!allParty.ContainsKey(newFlowMaster.PartyFrom)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePartyFromNotFound, newFlowMaster.PartyFrom); isMark = true; } if (!allParty.ContainsKey(newFlowMaster.PartyTo)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePartyToNotFound, newFlowMaster.PartyTo); isMark = true; } if (!string.IsNullOrWhiteSpace(newFlowMaster.LocationFrom) && !allLocation.ContainsKey(newFlowMaster.LocationFrom)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheLocFromNotFound, newFlowMaster.LocationFrom); isMark = true; } if (!string.IsNullOrWhiteSpace(newFlowMaster.LocationTo) && !allLocation.ContainsKey(newFlowMaster.LocationTo)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheLocToNotFound, newFlowMaster.LocationTo); isMark = true; } if (!string.IsNullOrWhiteSpace(newFlowMaster.PriceList) && !allPriceList.ContainsKey(newFlowMaster.PriceList)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePriceListNotFound, newFlowMaster.PriceList); isMark = true; } if (!string.IsNullOrWhiteSpace(newFlowMaster.BillAddress) && !allAddress.ContainsKey(newFlowMaster.BillAddress)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheBillAddrNotFound, newFlowMaster.BillAddress); isMark = true; } if (!allAddress.ContainsKey(newFlowMaster.ShipFrom)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheShipAddrNotFound, newFlowMaster.ShipFrom); isMark = true; } if (!allAddress.ContainsKey(newFlowMaster.ShipTo)) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheShipToNotFound, newFlowMaster.ShipTo); isMark = true; } #endregion if (!isMark && !errorMessage.HasMessage) { try { this.genericMgr.Create(newFlowMaster); } catch (Exception ex) { errorMessage.AddMessage(ex.Message); } } } else { if (flowMaster.Description != firstFlowItem.FlowDescription && !errorMessage.HasMessage) { flowMaster.Description = firstFlowItem.FlowDescription; this.genericMgr.Update(flowMaster); } } #endregion #region FlowStrategy if (!errorMessage.HasMessage) { if (flowStrategy == null) { //Flow Strategy Desc1 LeadTime EmLeadTime TimeUnit var newFlowStrategy = new FlowStrategy(); newFlowStrategy.Flow = excelFlowMaster.Code; newFlowStrategy.Description = firstFlowItem.FlowDescription; newFlowStrategy.LeadTime = firstFlowItem.LeadTime; newFlowStrategy.TimeUnit = CodeMaster.TimeUnit.Hour; this.genericMgr.Create(newFlowStrategy); } else { flowStrategy.LeadTime = firstFlowItem.LeadTime; this.genericMgr.Update(flowStrategy); } } #endregion #region FlowDetail if (!errorMessage.HasMessage) { var flowDetailDic = this.genericMgr.FindAllIn<FlowDetail> ("from FlowDetail where Flow = ? and Item in(? ", excelFlowMaster.List.Select(p => p.Item), new object[] { excelFlowMaster.Code }) .GroupBy(p => p.Item, (k, g) => new { Item = k, FlowDetails = g }) .ToDictionary(d => d.Item, d => d.FlowDetails); var maxSeq = 10; var maxItemSeq = this.genericMgr.FindAllIn<FlowDetail> ("from FlowDetail where Flow = ? ", new object[] { excelFlowMaster.Code }).Select(p => p.Sequence).Max(); if (flowDetailDic.Values != null && flowDetailDic.Values.Count > 0) { maxSeq = flowDetailDic.Values.Max(p => p.Max(q => q.Sequence)); } foreach (var flowItem in excelFlowMaster.List) { //Id Flow Seq Item RefItemCode Uom BaseUom UC UCDesc MinUC StartDate EndDate Bom LocFrom LocTo //BillAddr PriceList Routing ReturnRouting Strategy ProdScan Container ContainerDesc IsAutoCreate //IsInspect IsRejInspect SafeStock MaxStock MinLotSize OrderLotSize RecLotSize BatchSize RoundUpOpt //BillTerm MrpWeight MrpTotal MrpTotalAdj ExtraDmdSource PickStrategy EBELN EBELP CreateUser //CreateUserNm CreateDate LastModifyUser LastModifyUserNm LastModifyDate BinTo IsChangeUC Machine Uom1 //var item = this.genericMgr.FindById<Item>(flowItem.Item); try { //todo check Details var flowDetail = (flowDetailDic.ValueOrDefault(flowItem.Item) ?? new List<FlowDetail>()) .FirstOrDefault(p => p.UnitCount == flowItem.UnitCount); if (flowDetail == null) { var newFlowDetail = new FlowDetail(); newFlowDetail.Flow = flowItem.Flow; newFlowDetail.Item = flowItem.Item; newFlowDetail.BaseUom = flowItem.BaseUom; newFlowDetail.Uom = flowItem.Uom; //newFlowDetail.ReferenceItemCode = flowItem.ReferenceCode; newFlowDetail.UnitCount = flowItem.UnitCount; newFlowDetail.MinUnitCount = flowItem.UnitCount; newFlowDetail.UnitCountDescription = flowItem.UcDesc; newFlowDetail.Sequence = maxSeq+maxItemSeq; newFlowDetail.SafeStock = flowItem.MinStock; newFlowDetail.MaxStock = flowItem.MaxStock; newFlowDetail.MrpWeight = 1; newFlowDetail.RoundUpOption = Sconit.CodeMaster.RoundUpOption.ToUp; maxSeq += 10; this.genericMgr.Create(newFlowDetail); } else { flowDetail.BaseUom = flowItem.BaseUom; flowDetail.Uom = flowItem.Uom; flowDetail.UnitCount = flowItem.UnitCount; flowDetail.MinUnitCount = flowItem.UnitCount; flowDetail.UnitCountDescription = flowItem.UcDesc; flowDetail.SafeStock = flowItem.MinStock; flowDetail.MaxStock = flowItem.MaxStock; this.genericMgr.Update(flowDetail); } } catch (Exception ex) { errorMessage.AddMessage(ex.Message); } } } #endregion } #endregion if (errorMessage.HasMessage) { throw errorMessage; } }
public void RunRccp(DateTime planVersion, DateTime snapTime, CodeMaster.TimeUnit dateType, string dateIndex, User user) { lock(RunRccpLock) { planVersion = DateTime.Parse(planVersion.ToString("yyyy-MM-dd HH:mm:ss")); SecurityContextHolder.Set(user); log.Info(string.Format("---**------ SnapTime:{0} PlanVersion:{1} - 开始执行预测计划 ---", snapTime, planVersion)); BusinessException businessException = new BusinessException(); int rccpPlanVersion = 0; try { #region 获取RccpPlan log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始获取RccpPlan ---", snapTime, planVersion)); var rccpPlans = this.genericMgr.FindAll<RccpPlan> (@"from RccpPlan as m where m.DateIndex >= ? and DateType=? ", new object[] { dateIndex, dateType }); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束获取RccpPlan ---", snapTime, planVersion)); rccpPlanVersion = rccpPlans.Max(p => p.PlanVersion); #endregion #region 获取路线 log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始获取路线 ---", snapTime, planVersion)); var mrpFlowDetailList = this.genericMgr.FindAll<MrpFlowDetail> (@"from MrpFlowDetail as m where m.SnapTime = ?", new object[] { snapTime }); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束获取路线 ---", snapTime, planVersion)); #endregion #region 分解BOM log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始分解Bom ---", snapTime, planVersion)); var rccpTransList = GetRccpTrans(planVersion, rccpPlans, businessException); var rccpTransGroupList = (from r in rccpTransList group r by new { Item = r.Item, DateIndex = r.DateIndex, IsLastLevel = r.IsLastLevel, DateType = r.DateType } into g select new RccpTransGroup { PlanVersion = planVersion, DateType = g.Key.DateType, Item = g.Key.Item, DateIndex = g.Key.DateIndex, IsLastLevel = g.Key.IsLastLevel, Qty = g.Sum(r => r.Qty), ScrapPercentage = g.Sum(s => s.Qty) > 0 ? g.Sum(r => r.ScrapPercentage * (r.Qty / g.Sum(s => s.Qty))) : 0 }).ToList(); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束分解Bom ---", snapTime, planVersion)); #endregion #region 后加工 log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始执行后加工计划 ---", snapTime, planVersion)); GenFiRccp(planVersion, dateType, mrpFlowDetailList, rccpTransList, businessException); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束执行后加工计划 ---", snapTime, planVersion)); #endregion 后加工 #region 炼胶 委外 log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始执行炼胶计划 ---", snapTime, planVersion)); GenMiRccp(planVersion, dateType, dateIndex, mrpFlowDetailList, rccpTransGroupList, businessException); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束执行炼胶计划 ---", snapTime, planVersion)); #endregion 炼胶 #region 采购/委外等 log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始执行采购/委外计划 ---", snapTime, planVersion)); GenPurchaseRccp(planVersion, dateType, businessException, mrpFlowDetailList, rccpTransGroupList, snapTime, user); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束执行采购/委外计划 ---", snapTime, planVersion)); #endregion 采购/委外等 #region Create RccpTransGroup log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始记录RccpTrans/Group ---", snapTime, planVersion)); this.genericMgr.BulkInsert<RccpTransGroup>(rccpTransGroupList); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束记录RccpTrans/Group ---", snapTime, planVersion)); #endregion } catch(Exception ex) { businessException.AddMessage(new Message(CodeMaster.MessageType.Error, ex.StackTrace)); log.Error(ex); } List<RccpLog> rccpLogs = new List<RccpLog>(); CodeMaster.MessageType status = CodeMaster.MessageType.Info; if(businessException.HasMessage) { var messages = businessException.GetMessages().GroupBy(p => new { Message = p.GetMessageString(), MessageType = p.MessageType }, (k, g) => new { k.Message, k.MessageType }); foreach(var message in messages) { RccpLog rccpLog = new RccpLog(); rccpLog.ErrorLevel = message.MessageType.ToString(); rccpLog.Message = message.Message; rccpLog.Logger = "RunRccp"; rccpLog.PlanVersion = planVersion; rccpLogs.Add(rccpLog); //this.genericMgr.Create(rccpLog); if(message.MessageType == CodeMaster.MessageType.Warning) { log.Warn(rccpLog.Message); } else if(message.MessageType == CodeMaster.MessageType.Error) { log.Error(rccpLog.Message); } else { log.Info(rccpLog.Message); } } if(messages.Count(f => f.MessageType == CodeMaster.MessageType.Error) > 0) { status = CodeMaster.MessageType.Error; } else if(messages.Count(f => f.MessageType == CodeMaster.MessageType.Warning) > 0) { status = CodeMaster.MessageType.Warning; } } #region 记录RccpPlanMaster RccpPlanMaster rccpPlanMaster = new RccpPlanMaster(); rccpPlanMaster.DateType = dateType; rccpPlanMaster.SnapTime = snapTime; rccpPlanMaster.PlanVersion = planVersion; rccpPlanMaster.Status = status; rccpPlanMaster.RccpPlanVersion = rccpPlanVersion; rccpPlanMaster.CreateUserId = user.Id; rccpPlanMaster.CreateUserName = user.FullName; rccpPlanMaster.CreateDate = DateTime.Now; rccpPlanMaster.LastModifyUserId = user.Id; rccpPlanMaster.LastModifyUserName = user.FullName; rccpPlanMaster.LastModifyDate = DateTime.Now; this.genericMgr.Create(rccpPlanMaster); #endregion double timetick = 1001 - (rccpPlanMaster.CreateDate - planVersion).TotalMilliseconds; timetick = timetick > 0 ? timetick : 0; Thread.Sleep((int)timetick); string infoMessage = string.Format("完成预测计划时间:{0},时间总计:{1}秒", DateTime.Now.ToLocalTime(), (DateTime.Now - planVersion).TotalSeconds); log.Info(infoMessage); RccpLog infoLog = new RccpLog(); infoLog.ErrorLevel = CodeMaster.MessageType.Info.ToString(); infoLog.Message = infoMessage; infoLog.Logger = "RunRccp"; infoLog.PlanVersion = planVersion; rccpLogs.Add(infoLog); this.genericMgr.BulkInsert<RccpLog>(rccpLogs); } }
private void CheckKitOrderDetail(OrderMaster orderMaster, bool isCheckKitTraceItem, bool isShip) { BusinessException businessException = new BusinessException(); #region 明细行是否收/发货判断 IList<OrderDetail> unReceivedOrderDetailList = LoadExceptOrderDetail(orderMaster); if (unReceivedOrderDetailList != null && unReceivedOrderDetailList.Count > 0) { foreach (OrderDetail unReceivedOrderDetail in unReceivedOrderDetailList) { if (isShip) { businessException.AddMessage("KIT单{0}行号{1}零件号{2}没有发货。", orderMaster.OrderNo, unReceivedOrderDetail.Sequence.ToString(), unReceivedOrderDetail.Item); } else { businessException.AddMessage("KIT单{0}行号{1}零件号{2}没有收货。", orderMaster.OrderNo, unReceivedOrderDetail.Sequence.ToString(), unReceivedOrderDetail.Item); } } } #endregion #region 收/发货数是否等于订单数判断 foreach (OrderDetail orderDetail in orderMaster.OrderDetails) { if (isShip) { if (orderDetail.OrderedQty != orderDetail.ShipQtyInput) { businessException.AddMessage("KIT单{0}行号{1}零件号{2}的发货数和订单数不一致。", orderMaster.OrderNo, orderDetail.Sequence.ToString(), orderDetail.Item); } } else { if (orderDetail.OrderedQty != orderDetail.ReceiveQtyInput) { businessException.AddMessage("KIT单{0}行号{1}零件号{2}的收货数和订单数不一致。", orderMaster.OrderNo, orderDetail.Sequence.ToString(), orderDetail.Item); } } } #endregion #region KIT中的关键件是否扫描 if (isCheckKitTraceItem) { foreach (OrderDetail orderDetail in orderMaster.OrderDetails.Where(o => o.IsScanHu)) { if (orderDetail.OrderedQty != orderDetail.OrderDetailInputs.Where(o => !string.IsNullOrWhiteSpace(o.HuId)).Count()) { businessException.AddMessage("KIT单{0}行号{1}的关键零件{1}没有扫描。", orderMaster.OrderNo, orderDetail.Sequence.ToString(), orderDetail.Item); } } } #endregion if (businessException.HasMessage) { throw businessException; } }
private List<RccpTrans> GetRccpTrans(DateTime planVersion, IList<RccpPlan> rccpPlans, BusinessException businessException) { var groupRccpPlans = from p in rccpPlans //where p.Qty > 0 group p by new { p.DateIndex, p.DateType } into g select new { DateIndex = g.Key.DateIndex, DateType = g.Key.DateType, List = g.ToList() }; var rccpTransBag = new ConcurrentBag<RccpTrans>(); DateTime effdate = DateTime.Now; var errorItems = new List<string>(); var itemDic = this.itemMgr.GetCacheAllItem(); var bomDetDic = bomMgr.GetCacheAllBomDetail(); foreach(var bomDet in bomDetDic) { if(!itemDic.ContainsKey(bomDet.Key)) { errorItems.Add(bomDet.Key); } } if(errorItems.Count > 0) { string errorMessage = string.Format("{0}", string.Join(",", errorItems)); businessException.AddMessage(new Message(CodeMaster.MessageType.Warning, "没有发现bom{0}的物料基础数据", errorMessage)); } foreach(var groupRccpPlan in groupRccpPlans) { log.Info(string.Format("正在分解{0}的计划", groupRccpPlan.DateIndex)); if(groupRccpPlan.DateType == CodeMaster.TimeUnit.Month) { effdate = DateTime.Parse(string.Format("{0}-01", groupRccpPlan.DateIndex)); } else { effdate = Utility.DateTimeHelper.GetWeekIndexDateFrom(groupRccpPlan.DateIndex); } Parallel.ForEach(groupRccpPlan.List, rccpPlan => //foreach (var rccpPlan in rccpPlans) { RccpTrans topRccpTrans = new RccpTrans(); topRccpTrans.PlanVersion = planVersion; topRccpTrans.Item = rccpPlan.Item; topRccpTrans.Qty = rccpPlan.Qty; topRccpTrans.ScrapPercentage = 0; topRccpTrans.SourcePlanVersion = rccpPlan.PlanVersion; topRccpTrans.DateIndex = rccpPlan.DateIndex; topRccpTrans.DateType = rccpPlan.DateType; rccpTransBag.Add(topRccpTrans); var item = this.itemMgr.GetCacheItem(rccpPlan.Item); BomDetail modelBomDetail = null; if(item.ItemCategory == "FERT") { modelBomDetail = bomDetDic .Where(p => (this.itemMgr.GetCacheItem(p.Key) ?? new Item()).ItemCategory == "MODEL") .SelectMany(p => p.Value) .Where(p => p.Item == item.Code) .FirstOrDefault(); } var mrpBoms = GetMrpBomList(rccpPlan.Item, rccpPlan.Item, effdate, businessException, true); if(mrpBoms.Count() > 0) { foreach(var mrpBom in mrpBoms) { RccpTrans rccpTrans = new RccpTrans(); rccpTrans.Bom = mrpBom.Bom; rccpTrans.PlanVersion = planVersion; rccpTrans.Item = mrpBom.Item; rccpTrans.Qty = mrpBom.RateQty * rccpPlan.Qty; rccpTrans.ScrapPercentage = mrpBom.ScrapPercentage; rccpTrans.SourcePlanVersion = rccpPlan.PlanVersion; rccpTrans.DateIndex = rccpPlan.DateIndex; rccpTrans.DateType = rccpPlan.DateType; if(item.ItemCategory == "MODEL") { rccpTrans.Model = item.Code; rccpTrans.ModelRate = mrpBom.RateQty; } else if(item.ItemCategory == "FERT") { if(modelBomDetail != null) { rccpTrans.Model = modelBomDetail.Bom; rccpTrans.ModelRate = (double)modelBomDetail.UnitBomQty; } } rccpTransBag.Add(rccpTrans); this.GetNextRccpTrans(effdate, rccpTrans, rccpTransBag, businessException); } } else { topRccpTrans.IsLastLevel = true; } } ); } return rccpTransBag.ToList(); }
public ReceiptMaster AdjustIpGap(IList<IpDetail> ipDetailList, CodeMaster.IpGapAdjustOption ipGapAdjustOption, DateTime effectiveDate) { #region 判断送货单明细是否差异类型是否合并收货 if (ipDetailList.Where(det => det.Type == CodeMaster.IpDetailType.Normal).Count() > 0) { throw new TechnicalException("送货单差异明细类型不正确。"); } #endregion #region 判断送货单是否合并调整 if ((from det in ipDetailList select det.IpNo).Distinct().Count() > 1) { throw new TechnicalException("送货单不能合并调整差异。"); } #endregion #region 判断是否全0发货 if (ipDetailList == null || ipDetailList.Count == 0) { throw new BusinessException("收货差异调整明细不能为空。"); } IList<IpDetail> nonZeroIpDetailList = ipDetailList.Where(o => o.ReceiveQtyInput != 0).ToList(); if (nonZeroIpDetailList.Count == 0) { throw new BusinessException("收货差异调整明细不能为空。"); } #endregion #region 查询送货单头对象 string ipNo = (from det in ipDetailList select det.IpNo).Distinct().Single(); IpMaster ipMaster = this.genericMgr.FindById<IpMaster>(ipNo); ipMaster.IpDetails = nonZeroIpDetailList; #endregion #region 查询订单头对象 IList<OrderMaster> orderMasterList = LoadOrderMasters((from det in nonZeroIpDetailList select det.OrderNo).Distinct().ToArray()); #endregion #region 获取收货订单类型 IList<com.Sconit.CodeMaster.OrderType> orderTypeList = (from orderMaster in orderMasterList group orderMaster by orderMaster.Type into result select result.Key).ToList(); if (orderTypeList.Count > 1) { throw new BusinessException(Resources.ORD.OrderMaster.Errors_CannotMixOrderTypeReceive); } com.Sconit.CodeMaster.OrderType orderType = orderTypeList.First(); #endregion #region 查询送货单库存对象 IList<IpLocationDetail> ipLocationDetailList = LoadIpLocationDetails((from det in nonZeroIpDetailList select det.Id).ToArray()); #endregion #region 循环检查发货明细 foreach (IpDetail ipDetail in nonZeroIpDetailList) { #region 是否过量收货判断 if (Math.Abs(ipDetail.ReceivedQty) >= Math.Abs(ipDetail.Qty)) { //送货单的收货数已经大于等于发货数 throw new BusinessException("送货单{0}行号{1}零件{2}的收货数量超出了差异数量。", ipMaster.IpNo, ipDetail.Sequence.ToString(), ipDetail.Item); } else if (!ipMaster.IsReceiveExceed && Math.Abs(ipDetail.ReceivedQty + ipDetail.ReceiveQtyInput) > Math.Abs(ipDetail.Qty)) { //送货单的收货数 + 本次收货数大于发货数 throw new BusinessException("送货单{0}行号{1}零件{2}的收货数量超出了差异数量。", ipMaster.IpNo, ipDetail.Sequence.ToString(), ipDetail.Item); } #endregion #region 差异明细是否已经关闭 if (ipDetail.IsClose) { throw new BusinessException("送货单{0}行号{1}零件{2}已经关闭,不能进行差异调整。", ipMaster.IpNo, ipDetail.Sequence.ToString(), ipDetail.Item); } #endregion } #endregion #region 循环更新订单明细 BusinessException businessException = new BusinessException(); if (orderType != CodeMaster.OrderType.ScheduleLine) { #region 非计划协议 #region 查询订单明细对象 IList<OrderDetail> orderDetailList = LoadOrderDetails((from det in nonZeroIpDetailList where det.OrderDetailId.HasValue select det.OrderDetailId.Value).Distinct().ToArray()); #endregion foreach (OrderDetail orderDetail in orderDetailList) { IList<IpDetail> targetIpDetailList = (from det in nonZeroIpDetailList where det.OrderDetailId == orderDetail.Id select det).ToList(); #region 调整发货方库存 if (ipGapAdjustOption == CodeMaster.IpGapAdjustOption.GI) { //更新订单的发货数 orderDetail.ShippedQty -= targetIpDetailList.Sum(det => det.ReceiveQtyInput); genericMgr.Update(orderDetail); } #endregion #region 调整收货方库存 else { //更新订单的收货数 orderDetail.ReceivedQty += targetIpDetailList.Sum(det => det.ReceiveQtyInput); genericMgr.Update(orderDetail); } #endregion } #endregion } else { #region 计划协议 foreach (IpDetail ipDetail in nonZeroIpDetailList) { decimal remainReceiveQty = ipDetail.ReceiveQtyInput; if (ipGapAdjustOption == CodeMaster.IpGapAdjustOption.GI) { #region 调整发货方库存 //更新订单的发货数 IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and ShipQty > RecQty order by EndDate desc", new object[] { ipDetail.ExternalOrderNo, ipDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm }); if (scheduleOrderDetailList != null && scheduleOrderDetailList.Count > 0) { foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (remainReceiveQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { remainReceiveQty -= (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty); scheduleOrderDetail.ShippedQty = scheduleOrderDetail.ReceivedQty; } else { scheduleOrderDetail.ShippedQty -= remainReceiveQty; remainReceiveQty = 0; break; } this.genericMgr.Update(scheduleOrderDetail); } } #endregion } else { #region 调整收货方库存 //更新订单的收货数 IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and ShipQty > RecQty order by EndDate", new object[] { ipDetail.ExternalOrderNo, ipDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm }); if (scheduleOrderDetailList != null && scheduleOrderDetailList.Count > 0) { foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (remainReceiveQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { remainReceiveQty -= (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty); scheduleOrderDetail.ReceivedQty = scheduleOrderDetail.ShippedQty; } else { scheduleOrderDetail.ReceivedQty += remainReceiveQty; remainReceiveQty = 0; break; } this.genericMgr.Update(scheduleOrderDetail); } } #endregion } if (remainReceiveQty > 0) { businessException.AddMessage(Resources.ORD.IpMaster.Errors_ReceiveQtyExcceedOrderQty, ipMaster.IpNo, ipDetail.Item); } } #endregion } #region 循环IpDetail,更新收货数 foreach (IpDetail targetIpDetail in nonZeroIpDetailList) { #region 收货输入和送货单库存明细匹配 IList<IpLocationDetail> targetIpLocationDetailList = (from ipLocDet in ipLocationDetailList where ipLocDet.IpDetailId == targetIpDetail.Id select ipLocDet).OrderByDescending(d => d.IsConsignment).ToList(); //排序为了先匹配寄售的 bool isContainHu = targetIpLocationDetailList.Where(ipLocDet => !string.IsNullOrWhiteSpace(ipLocDet.HuId)).Count() > 0; if (ipMaster.IsReceiveScanHu) { #region 收货扫描条码 if (isContainHu) { #region 条码匹配条码 foreach (IpDetailInput targetIpDetailInput in targetIpDetail.IpDetailInputs) { IpLocationDetail matchedIpLocationDetail = targetIpLocationDetailList.Where(ipLocDet => ipLocDet.HuId == targetIpDetailInput.HuId).SingleOrDefault(); if (matchedIpLocationDetail != null) { #region 更新库存状态 matchedIpLocationDetail.ReceivedQty = matchedIpLocationDetail.Qty; matchedIpLocationDetail.IsClose = true; targetIpDetailInput.AddReceivedIpLocationDetail(matchedIpLocationDetail); genericMgr.Update(matchedIpLocationDetail); #endregion } else { #region 未匹配到的条码,报错 businessException.AddMessage("条码{0}不在送货单差异调整明细中。", targetIpDetailInput.HuId); #endregion } } #endregion } else { #region 数量匹配条码 IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList); if (gapIpDetail != null) { businessException.AddMessage("送货单{0}行号{1}零件{2}差异调整不正确。", ipMaster.IpNo, targetIpDetail.Sequence.ToString(), targetIpDetail.Item); } #endregion } #endregion } else { #region 收货不扫描条码 if (isContainHu) { #region 条码匹配数量 IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList); if (gapIpDetail != null) { businessException.AddMessage("送货单{0}行号{1}零件{2}差异调整不正确。", ipMaster.IpNo, targetIpDetail.Sequence.ToString(), targetIpDetail.Item); } #endregion } else { #region 数量匹配数量 IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList); if (gapIpDetail != null) { businessException.AddMessage("送货单{0}行号{1}零件{2}差异调整不正确。", ipMaster.IpNo, targetIpDetail.Sequence.ToString(), targetIpDetail.Item); } #endregion } #endregion } #endregion #region 更新IpDetail上的收货数 targetIpDetail.ReceivedQty += targetIpDetail.ReceiveQtyInput; if (targetIpLocationDetailList.Where(i => !i.IsClose).Count() == 0) { //只有所有的IpLocationDetail关闭才能关闭 targetIpDetail.IsClose = true; } genericMgr.Update(targetIpDetail); #endregion } #endregion if (businessException.HasMessage) { throw businessException; } #endregion #region 差异调整 ReceiptMaster receiptMaster = null; receiptMaster = this.receiptMgr.TransferIpGap2Receipt(ipMaster, ipGapAdjustOption); this.receiptMgr.CreateReceipt(receiptMaster, effectiveDate); #endregion #region 尝试关闭送货单 this.ipMgr.TryCloseIp(ipMaster); #endregion #region 尝试关闭订单 //处理超收的不能关闭订单 //foreach (OrderMaster orderMaster in orderMasterList) //{ // TryCloseOrder(orderMaster); //} #endregion return receiptMaster; }
private void GetNextRccpTrans(DateTime effdate, RccpTrans parentRccpPlan, ConcurrentBag<RccpTrans> rccpTransQueue, BusinessException businessException) { var pboms = GetMrpBomList(parentRccpPlan.Item, parentRccpPlan.Item, effdate, businessException, true); if(pboms.Count > 0) { foreach(var pbom in pboms) { RccpTrans rccpTrans = new RccpTrans(); rccpTrans.Bom = pbom.Bom; rccpTrans.PlanVersion = parentRccpPlan.PlanVersion; rccpTrans.Item = pbom.Item; rccpTrans.Qty = pbom.RateQty * parentRccpPlan.Qty; rccpTrans.ScrapPercentage = pbom.ScrapPercentage; rccpTrans.SourcePlanVersion = parentRccpPlan.SourcePlanVersion; rccpTrans.DateIndex = parentRccpPlan.DateIndex; rccpTrans.DateType = parentRccpPlan.DateType; rccpTrans.Model = parentRccpPlan.Model; rccpTrans.ModelRate = parentRccpPlan.ModelRate; rccpTransQueue.Add(rccpTrans); this.GetNextRccpTrans(effdate, rccpTrans, rccpTransQueue, businessException); } } else { parentRccpPlan.IsLastLevel = true; } }
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; }
public IList<Hu> MatchNewHuForRepack(IList<OrderDetail> orderDetailList, Boolean isJIT, BusinessException businessException) { #region 变量 // BusinessException businessException = new BusinessException(); List<Hu> huList = new List<Hu>(); List<InventoryOccupy> inventoryOccupyList = new List<InventoryOccupy>(); decimal totalQty = 0m; string oldHus = string.Empty; #endregion #region 检查发货单是否有占用的条码,有的话需要用当前数量减去已匹配数量 string hql = string.Empty; List<object> paras = new List<object>(); foreach (OrderDetail orderDetail in orderDetailList) { if (string.IsNullOrEmpty(hql)) { hql = "from HuMapping where IsEffective = 0 and OrderDetId in(?"; } else { hql += ", ?"; } paras.Add(orderDetail.Id); } hql += ")"; IList<HuMapping> huMappingList = this.genericMgr.FindAll<HuMapping>(hql, paras.ToArray()); if (huMappingList.Count > 0) { foreach (OrderDetail orderDetail in orderDetailList) { orderDetail.OrderedQty = orderDetail.OrderedQty - huMappingList.Where(o => o.OrderDetId == orderDetail.Id).Sum(o => o.Qty); } } #endregion #region 翻箱 orderDetailList = orderDetailList.Where(o => o.RemainShippedQty > 0).ToList(); if (orderDetailList.Count == 0) { businessException.AddMessage("没有需要打印翻箱标签得要货明细。"); return huList; } IList<string> itemList = orderDetailList.Select(o => o.Item).Distinct().ToList(); foreach (var item in itemList) { #region 查看库存是否满足要货需求 totalQty = 0m; oldHus = string.Empty; var groupOrderDetailList = orderDetailList.Where(o => o.Item == item).ToList(); var locationLotDetailList = genericMgr.FindAllWithNamedQuery<LocationLotDetail>("USP_Busi_GetAotuPickInventory", new Object[] { groupOrderDetailList[0].LocationFrom, groupOrderDetailList[0].Item, groupOrderDetailList[0].QualityType, 0, false, true }).OrderBy(l => l.Qty).ThenBy(l => l.LotNo).ToList(); var matchLocationLotDetailList = new List<LocationLotDetail>(); if (locationLotDetailList.Count == 0) { businessException.AddMessage("零件{0}在库位{1}中没有库存。", groupOrderDetailList[0].Item, groupOrderDetailList[0].LocationFrom); continue; } if (locationLotDetailList.Where(l => l.OccupyType == CodeMaster.OccupyType.None).Sum(l => l.Qty) < groupOrderDetailList.Sum(g => g.RemainShippedQty)) { businessException.AddMessage("物料{0}的库存数量{1}不满足本次要货数{2}。", item, locationLotDetailList.Where(l => l.OccupyType == CodeMaster.OccupyType.None).Sum(l => l.Qty).ToString("0.######"), groupOrderDetailList.Sum(g => g.RemainShippedQty).ToString("0.######")); } #endregion #region JIT件每条明细一张条码 if (isJIT == true) { try { //如果有数量能直接匹配上零头箱的,那么就直接将这个匹配 var oddMatchedlocationLotDetailList = (from l in locationLotDetailList from g in groupOrderDetailList where g.Item == l.Item && g.RemainShippedQty == l.Qty select new LocationLotDetail { Area = l.Area, BaseUom = l.BaseUom, Bin = l.Bin, BinSequence = l.BinSequence, ConsignmentSupplier = l.ConsignmentSupplier, CreateDate = l.CreateDate, CreateUserId = l.CreateUserId, CreateUserName = l.CreateUserName, FirstInventoryDate = l.FirstInventoryDate, HuId = l.HuId, HuQty = l.HuQty, HuUom = l.HuUom, Id = l.Id, IsATP = l.IsATP, IsConsignment = l.IsConsignment, IsFreeze = l.IsFreeze, IsOdd = l.IsOdd, Item = l.Item, ItemDescription = l.ItemDescription, LastModifyDate = l.LastModifyDate, LastModifyUserId = l.LastModifyUserId, LastModifyUserName = l.LastModifyUserName, Location = l.Location, LotNo = l.LotNo, ManufactureDate = l.ManufactureDate, ManufactureParty = l.ManufactureParty, OccupyReferenceNo = l.OccupyReferenceNo, OccupyType = l.OccupyType, PlanBill = l.PlanBill, Qty = l.Qty, QualityType = l.QualityType, ReferenceItemCode = l.ReferenceItemCode, UnitCount = l.UnitCount, UnitQty = l.UnitQty, Version = l.Version }); if (oddMatchedlocationLotDetailList.Count() > 0) { var oddMatchedlocationLotDetail = oddMatchedlocationLotDetailList.FirstOrDefault(); var oddMatchedOrderDetail = groupOrderDetailList.FirstOrDefault(o => o.RemainShippedQty == oddMatchedlocationLotDetail.Qty && o.Item == oddMatchedlocationLotDetail.Item); huList.AddRange(this.huMgr.CreateHu(oddMatchedOrderDetail, false, oddMatchedlocationLotDetail.ManufactureParty, oddMatchedlocationLotDetail.LotNo, oddMatchedlocationLotDetail.Qty, oddMatchedlocationLotDetail.Qty, oddMatchedlocationLotDetail.Qty, oddMatchedlocationLotDetail.HuId, oddMatchedOrderDetail.BinTo, true)); this.genericMgr.Update(oddMatchedlocationLotDetail); locationLotDetailList.Remove(oddMatchedlocationLotDetail); groupOrderDetailList.Remove(oddMatchedOrderDetail); } //将剩下的全部翻箱 var groupItemQty = groupOrderDetailList.Sum(g => g.RemainShippedQty); foreach (var locationLotDetail in locationLotDetailList) { totalQty += locationLotDetail.Qty; oldHus += locationLotDetail.HuId + ";"; InventoryOccupy inventoryOccupy = new InventoryOccupy(); inventoryOccupy.HuId = locationLotDetail.HuId; inventoryOccupy.Location = locationLotDetail.Location; inventoryOccupy.QualityType = locationLotDetail.QualityType; inventoryOccupy.OccupyType = CodeMaster.OccupyType.Pick; inventoryOccupy.OccupyReferenceNo = string.Empty; inventoryOccupyList.Add(inventoryOccupy); //locationLotDetail.OccupyType = CodeMaster.OccupyType.AutoPick; //this.genericMgr.Update(locationLotDetail); matchLocationLotDetailList.Add(locationLotDetail); if (totalQty >= groupItemQty) { break; } } foreach (var orderDetail in groupOrderDetailList) { if (totalQty - orderDetail.RemainShippedQty >= 0) { totalQty = totalQty - orderDetail.RemainShippedQty; huList.AddRange(this.huMgr.CreateHu(orderDetail, true, matchLocationLotDetailList[0].ManufactureParty, LotNoHelper.GenerateLotNo(DateTime.Now), orderDetail.RemainShippedQty, orderDetail.RemainShippedQty, orderDetail.RemainShippedQty, oldHus, orderDetail.BinTo, true)); } else { if (totalQty == 0m) { break; } else { huList.AddRange(this.huMgr.CreateHu(orderDetail, true, matchLocationLotDetailList[0].ManufactureParty, LotNoHelper.GenerateLotNo(DateTime.Now), totalQty, totalQty, totalQty, oldHus, orderDetail.BinTo, true)); totalQty = 0m; } } } if (totalQty > 0m) { huList.AddRange(this.huMgr.CreateHu(groupOrderDetailList[0], true, matchLocationLotDetailList[0].ManufactureParty, LotNoHelper.GenerateLotNo(DateTime.Now), totalQty, totalQty, totalQty, oldHus, string.Empty, false)); } } catch (BusinessException be) { businessException.AddMessage(be.GetMessages()[0].GetMessageString()); } } #endregion #region 看板件需求必须是UC的整数倍,零头不管 else { foreach (var orderDetail in groupOrderDetailList) { if (locationLotDetailList.Where(l => l.IsOdd == false && l.Qty == orderDetail.UnitCount).Count() <= 0) { businessException.AddMessage("零件{0}的包装数不满足要货的包装数。", orderDetail.Item ); } if (orderDetail.RemainShippedQty % orderDetail.UnitCount != 0) { businessException.AddMessage("要货单{0}中的看板件{1}的要货需求有零头数{2},系统无法自动翻箱。", orderDetail.OrderNo, orderDetail.Item, (orderDetail.RemainShippedQty % orderDetail.UnitCount).ToString()); } totalQty = 0m; oldHus = string.Empty; for (int i = 0; i < orderDetail.RemainShippedQty / orderDetail.UnitCount; ++i) { if (locationLotDetailList.Where(l => l.IsOdd == false && l.Qty == orderDetail.UnitCount).Count() > 0) { var oneIntPack = locationLotDetailList.FirstOrDefault(l => l.IsOdd == false && l.Qty == orderDetail.UnitCount); huList.AddRange(this.huMgr.CreateHu(orderDetail, false, oneIntPack.ManufactureParty, oneIntPack.LotNo, orderDetail.UnitCount, orderDetail.UnitCount, orderDetail.UnitCount, oneIntPack.HuId, orderDetail.BinTo, true)); InventoryOccupy inventoryOccupy = new InventoryOccupy(); inventoryOccupy.HuId = oneIntPack.HuId; inventoryOccupy.Location = oneIntPack.Location; inventoryOccupy.QualityType = oneIntPack.QualityType; inventoryOccupy.OccupyType = CodeMaster.OccupyType.Pick; inventoryOccupy.OccupyReferenceNo = string.Empty; inventoryOccupyList.Add(inventoryOccupy); locationLotDetailList.Remove(oneIntPack); //oneIntPack.OccupyType = CodeMaster.OccupyType.AutoPick; //this.genericMgr.Update(oneIntPack); } } } } #endregion #region 库存占用 try { if (inventoryOccupyList.Count > 0) { this.locationDetailMgr.InventoryOccupy(inventoryOccupyList); } } catch (BusinessException be) { businessException.AddMessage(be.GetMessages()[0].GetMessageString()); } #endregion } return huList; #endregion }
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; } }
public void BatchUpdateMiscOrderDetails(MiscOrderMaster miscOrderMaster, IList<string> addHuIdList, IList<string> deleteHuIdList) { if (miscOrderMaster.Status != CodeMaster.MiscOrderStatus.Create) { if (miscOrderMaster.Type == CodeMaster.MiscOrderType.GI) { throw new BusinessException("计划外出库单{0}的状态为{1}不能修改明细。", miscOrderMaster.MiscOrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.MiscOrderStatus, ((int)miscOrderMaster.Status).ToString())); } else { throw new BusinessException("计划外入库单{0}的状态为{1}不能修改明细。", miscOrderMaster.MiscOrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.MiscOrderStatus, ((int)miscOrderMaster.Status).ToString())); } } TryLoadMiscOrderDetails(miscOrderMaster); IList<MiscOrderLocationDetail> miscOrderLocationDetailList = TryLoadMiscOrderLocationDetails(miscOrderMaster); #region 新增计划外出入库明细 if (addHuIdList != null && addHuIdList.Count > 0) { #region 获取最大订单明细序号 string hql = "select max(Sequence) as seq from MiscOrderDetail where MiscOrderNo = ?"; IList maxSeqList = genericMgr.FindAll(hql, miscOrderMaster.MiscOrderNo); int maxSeq = maxSeqList != null && maxSeqList.Count > 0 && maxSeqList[0] != null ? (int)maxSeqList[0] : 0; #endregion #region 条码处理 #region 明细重复输入校验 #region 合并新增的HuId和原有的HuId IList<string> huIdList = new List<string>(); ((List<string>)huIdList).AddRange(addHuIdList); if (miscOrderLocationDetailList != null && miscOrderLocationDetailList.Count > 0) { ((List<string>)huIdList).AddRange(miscOrderLocationDetailList.Select(det => det.HuId).ToList()); } #endregion #region 检查是否重复 BusinessException businessException = new BusinessException(); var groupedHuIds = from huId in huIdList group huId by huId into result select new { HuId = result.Key, Count = result.Count() }; foreach (var groupedHuId in groupedHuIds.Where(g => g.Count > 1)) { businessException = new BusinessException(string.Format("重复扫描条码{0}。", groupedHuId.HuId)); } if (businessException.HasMessage) { throw businessException; } #endregion #endregion if (miscOrderMaster.Type == CodeMaster.MiscOrderType.GI) { #region 计划外出库 #region 库存占用 IList<InventoryOccupy> inventoryOccupyList = (from huId in addHuIdList select new InventoryOccupy { HuId = huId, //Location = miscOrderMaster.Location, 不指定库位 QualityType = miscOrderMaster.QualityType, OccupyType = CodeMaster.OccupyType.MiscOrder, OccupyReferenceNo = miscOrderMaster.MiscOrderNo }).ToList(); IList<LocationLotDetail> locationLotDetailList = this.locationDetailMgr.InventoryOccupy(inventoryOccupyList); #endregion #region 新增明细 foreach (LocationLotDetail locationLotDetail in locationLotDetailList) { MiscOrderDetail matchedMiscOrderDetail = null; #region 明细处理 if (miscOrderMaster.MiscOrderDetails != null && miscOrderMaster.MiscOrderDetails.Count > 0) { //查找匹配的明细行 matchedMiscOrderDetail = miscOrderMaster.MiscOrderDetails.Where(det => det.Item == locationLotDetail.Item && det.Uom == locationLotDetail.HuUom && det.UnitCount == locationLotDetail.UnitCount && det.Location == locationLotDetail.Location).SingleOrDefault(); } if (matchedMiscOrderDetail == null) { //没有找到明细行,新增明细 Item item = this.genericMgr.FindById<Item>(locationLotDetail.Item); //没有找到匹配的明细行,新增一行 matchedMiscOrderDetail = new MiscOrderDetail(); matchedMiscOrderDetail.MiscOrderNo = miscOrderMaster.MiscOrderNo; matchedMiscOrderDetail.Sequence = ++maxSeq; matchedMiscOrderDetail.Item = locationLotDetail.Item; matchedMiscOrderDetail.ItemDescription = item.Description; matchedMiscOrderDetail.ReferenceItemCode = item.ReferenceCode; matchedMiscOrderDetail.Uom = locationLotDetail.HuUom; matchedMiscOrderDetail.BaseUom = locationLotDetail.BaseUom; matchedMiscOrderDetail.UnitCount = locationLotDetail.UnitCount; matchedMiscOrderDetail.UnitQty = locationLotDetail.UnitQty; matchedMiscOrderDetail.Location = locationLotDetail.Location; //matchedMiscOrderDetail.ReserveNo = addMiscOrderDetail.ReserveNo; //matchedMiscOrderDetail.ReserveLine = addMiscOrderDetail.ReserveLine; matchedMiscOrderDetail.Qty = locationLotDetail.Qty; this.genericMgr.Create(matchedMiscOrderDetail); miscOrderMaster.MiscOrderDetails.Add(matchedMiscOrderDetail); } else { //找到明细行,更新数量 matchedMiscOrderDetail.Qty += locationLotDetail.Qty; this.genericMgr.Update(matchedMiscOrderDetail); } #endregion #region 库存明细新增 MiscOrderLocationDetail miscOrderLocationDetail = new MiscOrderLocationDetail(); miscOrderLocationDetail.MiscOrderNo = miscOrderMaster.MiscOrderNo; miscOrderLocationDetail.MiscOrderDetailId = matchedMiscOrderDetail.Id; miscOrderLocationDetail.MiscOrderDetailSequence = matchedMiscOrderDetail.Sequence; miscOrderLocationDetail.Item = locationLotDetail.Item; miscOrderLocationDetail.Uom = locationLotDetail.HuUom; miscOrderLocationDetail.HuId = locationLotDetail.HuId; miscOrderLocationDetail.LotNo = locationLotDetail.LotNo; miscOrderLocationDetail.IsCreatePlanBill = false; miscOrderLocationDetail.IsConsignment = locationLotDetail.IsConsignment; miscOrderLocationDetail.PlanBill = locationLotDetail.PlanBill; #region 查找寄售供应商 if (locationLotDetail.IsConsignment && locationLotDetail.PlanBill.HasValue) { miscOrderLocationDetail.ConsignmentSupplier = this.genericMgr.FindAll<string>("select Party from PlanBill where Id = ?", locationLotDetail.PlanBill.Value)[0]; } #endregion miscOrderLocationDetail.ActingBill = null; miscOrderLocationDetail.QualityType = locationLotDetail.QualityType; miscOrderLocationDetail.IsFreeze = locationLotDetail.IsFreeze; miscOrderLocationDetail.IsATP = locationLotDetail.IsATP; miscOrderLocationDetail.OccupyType = locationLotDetail.OccupyType; miscOrderLocationDetail.OccupyReferenceNo = locationLotDetail.OccupyReferenceNo; miscOrderLocationDetail.Qty = locationLotDetail.Qty; if (addHuIdList.Contains(miscOrderLocationDetail.HuId)) { this.genericMgr.Create(miscOrderLocationDetail); } #endregion } #endregion #endregion } else { #region 计划外入库 #region 检查条码状态 IList<HuStatus> huStatusList = this.huMgr.GetHuStatus(addHuIdList); foreach (string huId in addHuIdList) { HuStatus huStatus = huStatusList.Where(h => h.HuId == huId).SingleOrDefault(); if (huStatus == null) { businessException = new BusinessException(string.Format("条码{0}不存在。", huId)); } else if (huStatus.Status == CodeMaster.HuStatus.Location) { businessException = new BusinessException(string.Format("条码{0}在库位{1}中,不能计划外入库。", huStatus.HuId, huStatus.Location)); } else if (huStatus.Status == CodeMaster.HuStatus.Ip) { businessException = new BusinessException(string.Format("条码{0}为库位{1}至库位{2}的在途库存,不能计划外入库。", huStatus.HuId, huStatus.LocationFrom, huStatus.LocationTo)); } } if (businessException.HasMessage) { throw businessException; } #endregion #region 新增明细 foreach (HuStatus huStatus in huStatusList) { MiscOrderDetail matchedMiscOrderDetail = null; #region 明细处理 if (miscOrderMaster.MiscOrderDetails != null && miscOrderMaster.MiscOrderDetails.Count > 0) { //查找匹配的明细行 matchedMiscOrderDetail = miscOrderMaster.MiscOrderDetails .Where(det => det.Item == huStatus.Item && det.Uom == huStatus.Uom && det.UnitCount == huStatus.UnitCount) .SingleOrDefault(); } if (matchedMiscOrderDetail == null) { //没有找到明细行,新增明细//没有找到匹配的明细行,新增一行 Item item = this.genericMgr.FindById<Item>(huStatus.Item); matchedMiscOrderDetail = new MiscOrderDetail(); matchedMiscOrderDetail.MiscOrderNo = miscOrderMaster.MiscOrderNo; matchedMiscOrderDetail.Sequence = ++maxSeq; matchedMiscOrderDetail.Item = huStatus.Item; matchedMiscOrderDetail.ItemDescription = item.Description; matchedMiscOrderDetail.ReferenceItemCode = item.ReferenceCode; matchedMiscOrderDetail.Uom = huStatus.Uom; matchedMiscOrderDetail.BaseUom = huStatus.BaseUom; matchedMiscOrderDetail.UnitCount = huStatus.UnitCount; matchedMiscOrderDetail.UnitQty = huStatus.UnitQty; matchedMiscOrderDetail.ManufactureParty = huStatus.ManufactureParty; //matchedMiscOrderDetail.Location = //matchedMiscOrderDetail.ReserveNo = addMiscOrderDetail.ReserveNo; //matchedMiscOrderDetail.ReserveLine = addMiscOrderDetail.ReserveLine; matchedMiscOrderDetail.Qty = huStatus.Qty; this.genericMgr.Create(matchedMiscOrderDetail); miscOrderMaster.MiscOrderDetails.Add(matchedMiscOrderDetail); } else { //找到明细行,更新数量 matchedMiscOrderDetail.Qty += huStatus.Qty; this.genericMgr.Update(matchedMiscOrderDetail); } #endregion #region 库存明细新增 MiscOrderLocationDetail miscOrderLocationDetail = new MiscOrderLocationDetail(); miscOrderLocationDetail.MiscOrderNo = miscOrderMaster.MiscOrderNo; miscOrderLocationDetail.MiscOrderDetailId = matchedMiscOrderDetail.Id; miscOrderLocationDetail.MiscOrderDetailSequence = matchedMiscOrderDetail.Sequence; miscOrderLocationDetail.Item = huStatus.Item; miscOrderLocationDetail.Uom = huStatus.Uom; miscOrderLocationDetail.HuId = huStatus.HuId; miscOrderLocationDetail.LotNo = huStatus.LotNo; miscOrderLocationDetail.IsCreatePlanBill = false; miscOrderLocationDetail.IsConsignment = false; miscOrderLocationDetail.PlanBill = null; miscOrderLocationDetail.ConsignmentSupplier = null; miscOrderLocationDetail.ActingBill = null; miscOrderLocationDetail.QualityType = huStatus.QualityType; miscOrderLocationDetail.IsFreeze = false; miscOrderLocationDetail.IsATP = true; miscOrderLocationDetail.OccupyType = CodeMaster.OccupyType.None; miscOrderLocationDetail.OccupyReferenceNo = null; miscOrderLocationDetail.Qty = huStatus.Qty * huStatus.UnitQty; this.genericMgr.Create(miscOrderLocationDetail); #endregion } #endregion #endregion } #endregion } #endregion #region 删除计划外出入库明细 if (deleteHuIdList != null && deleteHuIdList.Count > 0) { #region 条码处理 #region 条码是否在计划外出入库单中存在检查 BusinessException businessException = new BusinessException(); foreach (string huId in deleteHuIdList) { if (miscOrderLocationDetailList == null || miscOrderLocationDetailList.Where(m => m.HuId == huId).Count() == 0) { if (miscOrderMaster.Type == CodeMaster.MiscOrderType.GI) { businessException.AddMessage("条码{0}在计划外出库单{1}中不存在。", huId, miscOrderMaster.MiscOrderNo); } else { businessException.AddMessage("条码{0}在计划外入库单{1}中不存在。", huId, miscOrderMaster.MiscOrderNo); } } } if (businessException.HasMessage) { throw businessException; } #endregion #region 循环删除 #region 取消占用 if (miscOrderMaster.Type == CodeMaster.MiscOrderType.GI) { this.locationDetailMgr.CancelInventoryOccupy(CodeMaster.OccupyType.MiscOrder, miscOrderMaster.MiscOrderNo, deleteHuIdList); } #endregion foreach (string huId in deleteHuIdList) { #region 扣减明细数量,删除库存明细 MiscOrderLocationDetail miscOrderLocationDetail = miscOrderLocationDetailList.Where(det => det.HuId == huId).Single(); MiscOrderDetail miscOrderDetail = miscOrderMaster.MiscOrderDetails.Where(det => det.Id == miscOrderLocationDetail.MiscOrderDetailId).Single(); miscOrderDetail.Qty -= miscOrderLocationDetail.Qty / miscOrderDetail.UnitQty; this.genericMgr.Update(miscOrderDetail); this.genericMgr.Delete(miscOrderLocationDetail); #endregion } #endregion #endregion } #endregion }
public ActionResult _ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { Regex r = new Regex("^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])|(?=.*[A-Z])(?=.*[a-z])(?=.*[^A-Za-z0-9])|(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9])|(?=.*[a-z])(?=.*[0-9])(?=.*[^A-Za-z0-9])).{6,}|(?:(?=.*[A-Z])(?=.*[a-z])|(?=.*[A-Z])(?=.*[0-9])|(?=.*[A-Z])(?=.*[^A-Za-z0-9])|(?=.*[a-z])(?=.*[0-9])|(?=.*[a-z])(?=.*[^A-Za-z0-9])|(?=.*[0-9])(?=.*[^A-Za-z0-9])|).{8,}"); if (!r.IsMatch(model.ConfirmPassword)) { BusinessException ex = new BusinessException(); ex.AddMessage(Resources.ACC.User.User_Regex); SaveBusinessExceptionMessage(ex); } else { User user = queryMgr.FindById<User>(model.Id); user.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(model.ConfirmPassword, "MD5"); user.LastPasswordModifyDate = DateTime.Now; this.genericMgr.UpdateWithTrim(user); SaveSuccessMessage(Resources.ACC.User.User_PasswordChanged); } } return PartialView(model); }
public void CloseMiscOrder(MiscOrderMaster miscOrderMaster, DateTime effectiveDate) { #region 检查 BusinessException businessException = new BusinessException(); if (miscOrderMaster.Status != CodeMaster.MiscOrderStatus.Create) { if (miscOrderMaster.Type == CodeMaster.MiscOrderType.GI) { businessException.AddMessage("计划外出库单{0}的状态为{1}不能确认。", miscOrderMaster.MiscOrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.MiscOrderStatus, ((int)miscOrderMaster.Status).ToString())); } else { businessException.AddMessage("计划外入库单{0}的状态为{1}不能确认。", miscOrderMaster.MiscOrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.MiscOrderStatus, ((int)miscOrderMaster.Status).ToString())); } } IList<MiscOrderDetail> miscOrderDetailList = TryLoadMiscOrderDetails(miscOrderMaster); if (miscOrderDetailList == null || miscOrderDetailList.Count() == 0) { if (miscOrderMaster.Type == CodeMaster.MiscOrderType.GI) { businessException.AddMessage("计划外出库单{0}明细为空。", miscOrderMaster.MiscOrderNo); } else { businessException.AddMessage("计划外入库单{0}明细为空。", miscOrderMaster.MiscOrderNo); } } else { foreach (MiscOrderDetail miscOrderDetail in miscOrderDetailList) { if (miscOrderDetail.Qty <= 0) { businessException.AddMessage("计划外入库单{0}明细行{1}的数量不能小于0。", miscOrderMaster.MiscOrderNo, miscOrderDetail.Sequence.ToString()); } } } if (businessException.HasMessage) { throw businessException; } #endregion User user = SecurityContextHolder.Get(); miscOrderMaster.CloseDate = DateTime.Now; miscOrderMaster.CloseUserId = user.Id; miscOrderMaster.CloseUserName = user.FullName; miscOrderMaster.Status = com.Sconit.CodeMaster.MiscOrderStatus.Close; this.genericMgr.Update(miscOrderMaster); //后加工废品报工不影响库存 if (miscOrderMaster.SubType == CodeMaster.MiscOrderSubType.MES27) { return; } // IList<MiscOrderLocationDetail> miscOrderLocationDetailList = TryLoadMiscOrderLocationDetails(miscOrderMaster); foreach (MiscOrderDetail miscOrderDetail in miscOrderDetailList.OrderByDescending(det => det.ManufactureParty)) { miscOrderDetail.ManufactureParty = miscOrderMaster.IsCs ? miscOrderDetail.ManufactureParty : null; IList<InventoryTransaction> inventoryTransactionList = this.locationDetailMgr.InventoryOtherInOut(miscOrderMaster, miscOrderDetail, effectiveDate); #region 新增、更新订单库存明细 foreach (InventoryTransaction inventoryTransaction in inventoryTransactionList) { if (miscOrderMaster.IsScanHu) { #region 条码 MiscOrderLocationDetail miscOrderLocationDetail = miscOrderLocationDetailList.Where(m => m.HuId == inventoryTransaction.HuId).Single(); if (inventoryTransaction.ActingBill.HasValue) { miscOrderLocationDetail.IsConsignment = false; miscOrderLocationDetail.PlanBill = null; miscOrderLocationDetail.ActingBill = inventoryTransaction.ActingBill; } this.genericMgr.Update(miscOrderLocationDetail); #endregion } else { #region 数量 MiscOrderLocationDetail miscOrderLocationDetail = new MiscOrderLocationDetail(); miscOrderLocationDetail.MiscOrderNo = miscOrderMaster.MiscOrderNo; miscOrderLocationDetail.MiscOrderDetailId = miscOrderDetail.Id; miscOrderLocationDetail.MiscOrderDetailSequence = miscOrderDetail.Sequence; miscOrderLocationDetail.Item = inventoryTransaction.Item; miscOrderLocationDetail.Uom = miscOrderDetail.Uom; //miscOrderLocationDetail.HuId = locationLotDetail.HuId; //miscOrderLocationDetail.LotNo = locationLotDetail.LotNo; miscOrderLocationDetail.IsCreatePlanBill = inventoryTransaction.IsCreatePlanBill; miscOrderLocationDetail.IsConsignment = inventoryTransaction.IsConsignment; miscOrderLocationDetail.PlanBill = inventoryTransaction.PlanBill; #region 查找寄售供应商 if (inventoryTransaction.IsConsignment && inventoryTransaction.PlanBill.HasValue) { miscOrderLocationDetail.ConsignmentSupplier = this.genericMgr.FindAll<string>("select Party from PlanBill where Id = ?", inventoryTransaction.PlanBill.Value).Single(); } #endregion miscOrderLocationDetail.ActingBill = null; miscOrderLocationDetail.QualityType = inventoryTransaction.QualityType; miscOrderLocationDetail.IsFreeze = inventoryTransaction.IsFreeze; miscOrderLocationDetail.IsATP = inventoryTransaction.IsATP; miscOrderLocationDetail.OccupyType = inventoryTransaction.OccupyType; miscOrderLocationDetail.OccupyReferenceNo = inventoryTransaction.OccupyReferenceNo; miscOrderLocationDetail.Qty = inventoryTransaction.Qty; this.genericMgr.Create(miscOrderLocationDetail); #endregion } } #endregion } }