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 }
private void FeedRawMaterialFromXls(Stream inputStream, string productLine, string productLineFacility, string orderNo, bool isForceFeed, DateTime effectiveDate) { #region 导入数据 if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); ImportHelper.JumpRows(rows, 11); #region 列定义 int colItem = 1;//物料代码 int colUom = 3;//单位 int colLocFrom = 4;// 来源库位 int colQty = 5;//数量 #endregion IList<FeedInput> feedInputList = new List<FeedInput>(); while (rows.MoveNext()) { HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 9)) { break;//边界 } string itemCode = string.Empty; decimal qty = 0; string uomCode = string.Empty; string locationFromCode = string.Empty; string locationToCode = string.Empty; #region 读取数据 #region 读取物料代码 itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItem)); if (itemCode == null || itemCode.Trim() == string.Empty) { ImportHelper.ThrowCommonError(row.RowNum, colItem, row.GetCell(colItem)); } #endregion #region 读取单位 uomCode = row.GetCell(colUom) != null ? row.GetCell(colUom).StringCellValue : string.Empty; if (uomCode == null || uomCode.Trim() == string.Empty) { throw new BusinessException("Import.Read.Error.Empty", (row.RowNum + 1).ToString(), colUom.ToString()); } #endregion #region 读取来源库位 locationFromCode = row.GetCell(colLocFrom) != null ? row.GetCell(colLocFrom).StringCellValue : string.Empty; if (string.IsNullOrEmpty(locationFromCode)) { throw new BusinessException("Import.Read.Error.Empty", (row.RowNum + 1).ToString(), colLocFrom.ToString()); } Location locationFrom = genericMgr.FindById<Location>(locationFromCode); #endregion #region 读取数量 try { qty = Convert.ToDecimal(row.GetCell(colQty).NumericCellValue); } catch { ImportHelper.ThrowCommonError(row.RowNum, colQty, row.GetCell(colQty)); } #endregion #endregion #region 填充数据 FeedInput feedInput = new FeedInput(); feedInput.LocationFrom = locationFromCode; feedInput.Item = itemCode; feedInput.Uom = uomCode; feedInput.Qty = qty; feedInput.BaseUom = uomCode; feedInputList.Add(feedInput); #endregion } #endregion #region 投料 FeedRawMaterial(productLine, productLineFacility, orderNo, feedInputList, isForceFeed, effectiveDate); #endregion }
public IList<InventoryTransaction> FeedProductRawMaterial(FeedInput feedInput, DateTime effectiveDate) { #region 出库位 List<InventoryTransaction> issInventoryTransactionList = new List<InventoryTransaction>(); InventoryIO inventoryIO = new InventoryIO(); inventoryIO.Location = feedInput.LocationFrom; inventoryIO.Item = feedInput.Item; inventoryIO.HuId = feedInput.HuId; inventoryIO.Qty = -feedInput.Qty * feedInput.UnitQty; //出库为负数,库存单位 inventoryIO.LotNo = feedInput.LotNo; inventoryIO.QualityType = feedInput.QualityType; inventoryIO.IsATP = feedInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified; inventoryIO.IsFreeze = false; //可能指定移库冻结的零件? //inventoryIO.IsCreatePlanBill = ipDetailInput.IsCreatePlanBill; //inventoryIO.IsConsignment = ipDetailInput.IsConsignment; //inventoryIO.PlanBill = ipDetailInput.PlanBill; //inventoryIO.ActingBill = ipDetailInput.ActingBill; inventoryIO.TransactionType = com.Sconit.CodeMaster.TransactionType.ISS_MIN; //生产投料出库 inventoryIO.OccupyType = com.Sconit.CodeMaster.OccupyType.None; //应该是非占用的零件才能投料 //inventoryIO.OccupyReferenceNo = ipDetail.CurrentOccupyReferenceNo; inventoryIO.IsVoid = false; inventoryIO.EffectiveDate = effectiveDate; //inventoryIO.ManufactureParty = ; issInventoryTransactionList.AddRange(RecordInventory(inventoryIO)); //记录出库事务 RecordLocationTransaction(feedInput, effectiveDate, issInventoryTransactionList, true); #endregion #region 入生产线物料 by 李秋云 不记入库 //var groupedInventoryTransactionList = from trans in issInventoryTransactionList // group trans by new // { // IsConsignment = trans.IsConsignment, // PlanBill = trans.PlanBill // } into result // select new // { // IsConsignment = result.Key.IsConsignment, // PlanBill = result.Key.PlanBill, // Qty = result.Sum(trans => -trans.Qty) // }; //IList<ProductLineLocationDetail> productLineLocationDetailList = new List<ProductLineLocationDetail>(); //foreach (var trans in groupedInventoryTransactionList) //{ // ProductLineLocationDetail productLineLocationDetail = new ProductLineLocationDetail(); // productLineLocationDetail.ProductLine = feedInput.ProductLine; // productLineLocationDetail.ProductLineFacility = feedInput.ProductLineFacility; // productLineLocationDetail.OrderNo = feedInput.OrderNo; // productLineLocationDetail.OrderDetailId = feedInput.OrderDetailId; // productLineLocationDetail.TraceCode = feedInput.TraceCode; // productLineLocationDetail.Operation = feedInput.Operation; // productLineLocationDetail.OpReference = feedInput.OpReference; // productLineLocationDetail.Item = feedInput.Item; // productLineLocationDetail.ItemDescription = feedInput.CurrentItem.Description; // productLineLocationDetail.ReferenceItemCode = feedInput.CurrentItem.ReferenceCode; // productLineLocationDetail.HuId = feedInput.HuId; // productLineLocationDetail.LotNo = feedInput.LotNo; // productLineLocationDetail.IsConsignment = trans.IsConsignment; // productLineLocationDetail.PlanBill = trans.PlanBill; // productLineLocationDetail.Qty = trans.Qty; //库存单位 // productLineLocationDetail.BackFlushQty = 0; // productLineLocationDetail.VoidQty = 0; // productLineLocationDetail.LocationFrom = feedInput.LocationFrom; // productLineLocationDetail.ReserveNo = feedInput.ReserveNo; //预留号 // productLineLocationDetail.ReserveLine = feedInput.ReserveLine; //行号 // productLineLocationDetail.AUFNR = feedInput.AUFNR; //生产单号 // productLineLocationDetail.ICHARG = feedInput.ICHARG; //生产批次 // productLineLocationDetail.BWART = feedInput.BWART; //移动类型 // productLineLocationDetail.NotReport = feedInput.NotReport; //不导出给SAP // this.genericMgr.Create(productLineLocationDetail); // productLineLocationDetailList.Add(productLineLocationDetail); // //InventoryTransaction rctInventoryTransaction = Mapper.Map<InventoryTransaction, InventoryTransaction>(trans); // //rctInventoryTransaction.ActingBillQty *= -1; // //rctInventoryTransaction.Qty *= -1; // //rctInventoryTransactionList.Add(rctInventoryTransaction); //} //List<InventoryTransaction> rctInventoryTransactionList = (from det in productLineLocationDetailList // select new InventoryTransaction // { // LocationLotDetailId = det.Id, // Location = det.ProductLine, // Bin = det.ProductLineFacility, // Item = det.Item, // HuId = det.HuId, // LotNo = det.LotNo, // Qty = det.Qty, // IsConsignment = det.IsConsignment, // PlanBill = det.PlanBill, // PlanBillQty = det.IsConsignment ? det.Qty : 0, // QualityType = det.QualityType, // IsATP = det.QualityType == com.Sconit.CodeMaster.QualityType.Qualified // }).ToList(); ////记录入库事务 //RecordLocationTransaction(feedInput, effectiveDate, rctInventoryTransactionList, false); //issInventoryTransactionList.AddRange(rctInventoryTransactionList); #endregion return issInventoryTransactionList; }
private void RecordLocationTransaction(FeedInput feedInput, DateTime effectiveDate, IList<InventoryTransaction> inventoryTransactionList, bool isIssue) //isIssue区分是投料出库还是投料入生产线 { DateTime dateTimeNow = DateTime.Now; //根据PlanBill和ActingBill分组,为了不同供应商的库存事务分开 var groupedInventoryTransactionList = from trans in inventoryTransactionList group trans by new { IsConsignment = trans.IsConsignment, PlanBill = trans.PlanBill, ActingBill = trans.ActingBill } into result select new { IsConsignment = result.Key.IsConsignment, PlanBill = result.Key.PlanBill, ActingBill = result.Key.ActingBill, //Qty = result.Sum(trans => isIssue ? -trans.Qty : trans.Qty), Qty = result.Sum(trans => trans.Qty), //PlanBillQty = result.Sum(trans => isIssue ? -trans.PlanBillQty : trans.PlanBillQty), PlanBillQty = result.Sum(trans => trans.PlanBillQty), //ActingBillQty = result.Sum(trans => isIssue ? -trans.ActingBillQty : trans.ActingBillQty), ActingBillQty = result.Sum(trans => trans.ActingBillQty), InventoryTransactionList = result.ToList() }; foreach (var groupedInventoryTransaction in groupedInventoryTransactionList) { LocationTransaction locationTransaction = new LocationTransaction(); if (feedInput.OrderNo != null) { locationTransaction.OrderNo = feedInput.OrderNo; locationTransaction.OrderType = feedInput.OrderType; locationTransaction.OrderSubType = feedInput.OrderSubType; //locationTransaction.OrderDetailSequence = //locationTransaction.OrderDetailId = //locationTransaction.OrderBomDetId = } //locationTransaction.IpNo = //locationTransaction.IpDetailId = //locationTransaction.IpDetailSequence = //locationTransaction.ReceiptNo = //locationTransaction.ReceiptDetailId = //locationTransaction.ReceiptDetailSequence = //locationTransaction.SequenceNo = locationTransaction.TraceCode = feedInput.TraceCode; locationTransaction.Item = feedInput.Item; locationTransaction.Uom = feedInput.Uom; locationTransaction.BaseUom = feedInput.BaseUom; locationTransaction.Qty = groupedInventoryTransaction.Qty / feedInput.UnitQty;//isIssue ? -feedInput.Qty : feedInput.Qty; locationTransaction.UnitQty = feedInput.UnitQty; locationTransaction.IsConsignment = groupedInventoryTransaction.IsConsignment;//isIssue ? -feedInput.Qty : feedInput.Qty; if (groupedInventoryTransaction.IsConsignment && groupedInventoryTransaction.PlanBill.HasValue) { locationTransaction.PlanBill = groupedInventoryTransaction.PlanBill.Value;//inventoryTransactionList.Sum(i => (isIssue ? -i.PlanBillQty : i.PlanBillQty) / feedInput.UnitQty); } locationTransaction.PlanBillQty = groupedInventoryTransaction.PlanBillQty / feedInput.UnitQty;//inventoryTransactionList.Sum(i => (isIssue ? -i.PlanBillQty : i.PlanBillQty) / feedInput.UnitQty); if (groupedInventoryTransaction.ActingBill.HasValue) { locationTransaction.ActingBill = groupedInventoryTransaction.ActingBill.Value;//inventoryTransactionList.Sum(i => (isIssue ? -i.PlanBillQty : i.PlanBillQty) / feedInput.UnitQty); } locationTransaction.ActingBillQty = groupedInventoryTransaction.ActingBillQty / feedInput.UnitQty; //inventoryTransactionList.Sum(i => (isIssue ? -i.ActingBillQty : i.ActingBillQty) / feedInput.UnitQty); locationTransaction.QualityType = feedInput.QualityType; locationTransaction.HuId = feedInput.HuId; locationTransaction.LotNo = feedInput.LotNo; locationTransaction.TransactionType = isIssue ? com.Sconit.CodeMaster.TransactionType.ISS_WO : com.Sconit.CodeMaster.TransactionType.RCT_MIN; locationTransaction.IOType = isIssue ? CodeMaster.TransactionIOType.Out : CodeMaster.TransactionIOType.In; locationTransaction.PartyFrom = feedInput.CurrentLocationFrom.Region; locationTransaction.PartyTo = feedInput.CurrentProductLine.PartyFrom; locationTransaction.LocationFrom = feedInput.LocationFrom; //locationTransaction.LocationTo = feedInput.ProductLine; //记录投料入的生产线 locationTransaction.LocationIOReason = string.Empty; locationTransaction.EffectiveDate = effectiveDate; locationTransaction.CreateUserId = SecurityContextHolder.Get().Id; locationTransaction.CreateDate = dateTimeNow; this.genericMgr.Create(locationTransaction); RecordLocationTransactionDetail(locationTransaction, groupedInventoryTransaction.InventoryTransactionList); } }
public IList<InventoryTransaction> FeedProductRawMaterial(FeedInput feedInput) { return FeedProductRawMaterial(feedInput, DateTime.Now); }