public IList<Hu> CreateHu(ReceiptMaster receiptMaster, ReceiptDetail receiptDetail, DateTime effectiveDate) { IList<Hu> huList = new List<Hu>(); decimal remainReceivedQty = receiptDetail.ReceivedQty; receiptDetail.LotNo = LotNoHelper.GenerateLotNo(effectiveDate); //取生效日期为批号生成日期 IDictionary<string, decimal> huIdDic = numberControlMgr.GetHuId(receiptDetail); if (huIdDic != null && huIdDic.Count > 0) { foreach (string huId in huIdDic.Keys) { Hu hu = new Hu(); hu.HuId = huId; hu.LotNo = receiptDetail.LotNo; hu.Item = receiptDetail.Item; hu.ItemDescription = receiptDetail.ItemDescription; hu.BaseUom = receiptDetail.BaseUom; hu.Qty = huIdDic[huId]; hu.ManufactureParty = receiptMaster.PartyFrom; //取区域代码为制造商代码 hu.ManufactureDate = LotNoHelper.ResolveLotNo(receiptDetail.LotNo); hu.PrintCount = 0; hu.ConcessionCount = 0; hu.ReferenceItemCode = receiptDetail.ReferenceItemCode; hu.UnitCount = receiptDetail.UnitCount; hu.UnitQty = itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, 1, receiptDetail.BaseUom); hu.Uom = receiptDetail.Uom; hu.IsOdd = hu.Qty < receiptDetail.MinUc; hu.OrderNo = receiptDetail.OrderNo; hu.ReceiptNo = receiptMaster.ReceiptNo; hu.Flow = receiptMaster.Flow; hu.IpNo = receiptMaster.IpNo; hu.IsChangeUnitCount = false; hu.Remark = receiptDetail.Remark; hu.Direction = receiptDetail.Direction; hu.Flow = receiptDetail.Flow; hu.Shift = receiptMaster.Shift; //hu.UnitCountDescription = receiptDetail.UnitCountDescription; var item = this.itemMgr.GetCacheItem(receiptDetail.Item); hu.MaterialsGroup = this.GetMaterialsGroupDescrption(item.MaterialsGroup); hu.HuTemplate = receiptMaster.HuTemplate; hu.HuOption = GetHuOption(item); if (item.Warranty > 0) { hu.ExpireDate = hu.ManufactureDate.AddDays(item.Warranty); } if (item.WarnLeadTime > 0) { hu.RemindExpireDate = hu.ManufactureDate.AddDays(item.WarnLeadTime); } this.genericMgr.Create(hu); //this.AsyncSendPrintData(hu); huList.Add(hu); } } return huList; }
public IList<Hu> CreateHu(ReceiptMaster receiptMaster, ReceiptDetail receiptDetail, DateTime effectiveDate) { IList<Hu> huList = new List<Hu>(); decimal remainReceivedQty = receiptDetail.ReceivedQty; receiptDetail.LotNo = LotNoHelper.GenerateLotNo(effectiveDate); //取生效日期为批号生成日期 IDictionary<string, decimal> huIdDic = numberControlMgr.GetHuId(receiptDetail); if (huIdDic != null && huIdDic.Count > 0) { foreach (string huId in huIdDic.Keys) { Hu hu = new Hu(); hu.HuId = huId; hu.LotNo = receiptDetail.LotNo; hu.Item = receiptDetail.Item; hu.ItemDescription = receiptDetail.ItemDescription; hu.BaseUom = receiptDetail.BaseUom; hu.Qty = huIdDic[huId]; hu.ManufactureParty = receiptMaster.PartyFrom; //取区域代码为制造商代码 hu.ManufactureDate = LotNoHelper.ResolveLotNo(receiptDetail.LotNo); hu.PrintCount = 0; hu.ConcessionCount = 0; hu.ReferenceItemCode = receiptDetail.ReferenceItemCode; hu.UnitCount = receiptDetail.UnitCount; hu.UnitQty = itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, 1, receiptDetail.BaseUom); hu.Uom = receiptDetail.Uom; hu.IsOdd = hu.Qty < hu.UnitCount; hu.OrderNo = receiptDetail.OrderNo; hu.ReceiptNo = receiptMaster.ReceiptNo; hu.IsChangeUnitCount = false; //hu.UnitCountDescription = receiptDetail.UnitCountDescription; genericMgr.Create(hu); //创建条码中间表 this.CreateBarCode(hu,string.Empty); //this.AsyncSendPrintData(hu); huList.Add(hu); } } return huList; }
public IpMaster TransferReceipt2Ip(ReceiptMaster receiptMaster) { IpMaster ipMaster = Mapper.Map<ReceiptMaster, IpMaster>(receiptMaster); foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { IpDetail ipDetail = Mapper.Map<ReceiptDetail, IpDetail>(receiptDetail); foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.ShipQty = receiptLocationDetail.Qty / receiptDetail.UnitQty; ipDetailInput.HuId = receiptLocationDetail.HuId; ipDetailInput.LotNo = receiptLocationDetail.LotNo; ipDetail.AddIpDetailInput(ipDetailInput); } ipMaster.AddIpDetail(ipDetail); } return ipMaster; }
public void AsyncSendPrintData(ReceiptMaster receiptMaster) { if (receiptMaster.Type == CodeMaster.IpDetailType.Gap) { return; } //AsyncSend asyncSend = new AsyncSend(this.SendPrintData); //asyncSend.BeginInvoke(receiptMaster, null, null); if (receiptMaster.IsPrintReceipt) { try { var subPrintOrderList = this.genericMgr.FindAll<SubPrintOrder>(); string location = (receiptMaster.ReceiptDetails != null && receiptMaster.ReceiptDetails.Count > 0) ? receiptMaster.ReceiptDetails[0].LocationTo : null; var pubPrintOrders = subPrintOrderList.Where(p => (p.Flow == receiptMaster.Flow || string.IsNullOrWhiteSpace(p.Flow)) && (p.UserId == receiptMaster.CreateUserId || p.UserId == 0) && (p.Region == receiptMaster.PartyTo || string.IsNullOrWhiteSpace(p.Region)) && (location == null || p.Location == location || string.IsNullOrWhiteSpace(p.Location)) && p.ExcelTemplate == receiptMaster.ReceiptTemplate) .Select(p => new PubPrintOrder { Client = p.Client, ExcelTemplate = p.ExcelTemplate, Code = receiptMaster.ReceiptNo, Printer = p.Printer }); foreach (var pubPrintOrder in pubPrintOrders) { this.genericMgr.Create(pubPrintOrder); } } catch (Exception ex) { pubSubLog.Error("Send data to print sevrer error:", ex); } } }
private IList<ReceiptLocationDetail> TryLoadReceiptLocationDetails(ReceiptMaster receiptMaster) { if (receiptMaster.ReceiptDetails == null) { if (receiptMaster.ReceiptDetails == null) { TryLoadReceiptDetails(receiptMaster); } string hql = "from ReceiptLocationDetail where ReceiptNo = ?"; IList<ReceiptLocationDetail> receiptLocationDetailList = this.genericMgr.FindAll<ReceiptLocationDetail>(hql, receiptMaster.ReceiptNo); foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { receiptDetail.ReceiptLocationDetails = receiptLocationDetailList.Where(r => r.ReceiptDetailId == receiptDetail.Id).ToList(); } return receiptLocationDetailList; } else { IList<ReceiptLocationDetail> receiptLocationDetailList = new List<ReceiptLocationDetail>(); foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { ((List<ReceiptLocationDetail>)receiptLocationDetailList).AddRange(receiptDetail.ReceiptLocationDetails); } return receiptLocationDetailList; } }
public static bool HasPermission(ReceiptMaster receiptMaster, bool isSupplier = false) { return HasPermission(receiptMaster.OrderType, receiptMaster.IsCheckPartyFromAuthority, receiptMaster.IsCheckPartyToAuthority, receiptMaster.PartyFrom, receiptMaster.PartyTo, isSupplier, false); }
public void CancelReceipt(ReceiptMaster receiptMaster, DateTime effectiveDate) { if (!Utility.SecurityHelper.HasPermission(receiptMaster)) { //throw new BusinessException("没有此收货单{0}的操作权限。", receiptMaster.ReceiptNo); } #region 判断收货单状态,只有Close才能冲销 if (receiptMaster.Status == CodeMaster.ReceiptStatus.Cancel) { throw new BusinessException("收货单{0}已经冲销。", receiptMaster.ReceiptNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.ReceiptStatus, ((int)receiptMaster.Status).ToString())); } #endregion #region 加载收货单明细及收货单库存明细 // TryLoadReceiptDetails(receiptMaster); IList<ReceiptLocationDetail> receiptLocationDetailList = TryLoadReceiptLocationDetails(receiptMaster); #endregion #region 加载订单头和明细 //GAP收货取消不用调整订单数据 IList<OrderMaster> orderMasterList = null; IList<OrderDetail> orderDetialList = null; //if (receiptMaster.Type == CodeMaster.IpDetailType.Normal) //{ #region 获取订单头 orderMasterList = LoadOrderMasters(receiptMaster.ReceiptDetails.Select(det => det.OrderNo).Distinct().ToArray()); #endregion #region 获取订单明细 orderDetialList = LoadOrderDetails(receiptMaster.ReceiptDetails.Where(det => det.OrderDetailId.HasValue).Select(det => det.OrderDetailId.Value).Distinct().ToArray()); #endregion //} #endregion //小数保留位数 int decimalLength = int.Parse(systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.DecimalLength)); #region 回滚送货单 if (!string.IsNullOrWhiteSpace(receiptMaster.IpNo)) { IpMaster ipMaster = this.genericMgr.FindById<IpMaster>(receiptMaster.IpNo); #region 查找送货单明细 string selectIpDetailStatement = string.Empty; IList<object> selectIpDetailPram = new List<object>(); foreach (int ipDetailId in receiptMaster.ReceiptDetails.Select(recDet => recDet.IpDetailId).Distinct()) { if (selectIpDetailStatement == string.Empty) { selectIpDetailStatement = "from IpDetail where Id in (?"; } else { selectIpDetailStatement += ",?"; } selectIpDetailPram.Add(ipDetailId); } selectIpDetailStatement += ")"; IList<IpDetail> ipDetailList = this.genericMgr.FindAll<IpDetail>(selectIpDetailStatement, selectIpDetailPram.ToArray()); #endregion #region 查找送货单库存明细 IList<IpLocationDetail> ipLocationDetailList = LoadIpLocationDetails(ipDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion #region 查找差异送货单明细 IList<IpDetail> gapIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where GapReceiptNo = ?", receiptMaster.ReceiptNo); #endregion #region 差异全部关闭 if (gapIpDetailList != null && gapIpDetailList.Count > 0) { #region 查找差异送货单库存明细 IList<IpLocationDetail> gapIpLocationDetailList = LoadIpLocationDetails(gapIpDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion foreach (IpDetail gapIpDetail in gapIpDetailList) { if (gapIpDetail.ReceivedQty != 0) { throw new BusinessException("收货单{0}的收货差异已经调整,不能冲销。", receiptMaster.ReceiptNo); } gapIpDetail.IsClose = true; this.genericMgr.Update(gapIpDetail); } foreach (IpLocationDetail gapIpLocationDetail in gapIpLocationDetailList) { gapIpLocationDetail.IsClose = true; this.genericMgr.Update(gapIpLocationDetail); } } #endregion #region 打开未收货的发货明细 //只有正常收货才能打开未收货的发货明细。 int isGapRec = receiptMaster.ReceiptDetails.Where(recDet => recDet.IpDetailType == CodeMaster.IpDetailType.Gap).Count(); if (isGapRec == 0) { IList<IpDetail> unReceivedIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where IpNo = ? and Type = ?", new object[] { ipMaster.IpNo, CodeMaster.IpDetailType.Normal }); if (unReceivedIpDetailList != null && unReceivedIpDetailList.Count > 0) { #region 查找差异送货单库存明细 IList<IpLocationDetail> unReceivedIpLocationDetailList = LoadIpLocationDetails(unReceivedIpDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion foreach (IpDetail unReceivedIpDetail in unReceivedIpDetailList) { if (unReceivedIpDetail.IsClose && receiptMaster.ReceiptDetails.Select(p => p.IpDetailId).Contains(unReceivedIpDetail.Id)) { unReceivedIpDetail.IsClose = false; this.genericMgr.Update(unReceivedIpDetail); } } //foreach (IpLocationDetail unReceivedIpLocationDetail in unReceivedIpLocationDetailList) //{ // if (unReceivedIpLocationDetail.IsClose && receiptMaster.ReceiptDetails.Select(p => p.IpDetailId).Contains(unReceivedIpLocationDetail.IpDetailId)) // { // unReceivedIpLocationDetail.IsClose = false; // this.genericMgr.Update(unReceivedIpLocationDetail); // } //} } } #endregion #region 收货库存明细和送货库存明细匹配 foreach (ReceiptLocationDetail receiptLocationDetail in receiptLocationDetailList) { ReceiptDetail receiptDetail = receiptMaster.ReceiptDetails.Where(recDet => recDet.Id == receiptLocationDetail.ReceiptDetailId).Single(); decimal remainBaseQty = receiptLocationDetail.Qty; //基本单位 decimal remainQty = receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位 if (!string.IsNullOrWhiteSpace(receiptLocationDetail.HuId) && ipLocationDetailList.Where(ipLocDet => !string.IsNullOrWhiteSpace(ipLocDet.HuId)).Count() > 0) { #region 条码和条码匹配 IpLocationDetail ipLocationDetail = ipLocationDetailList.Where(ipLocDet => ipLocDet.HuId == receiptLocationDetail.HuId).SingleOrDefault(); IpDetail ipDetail = ipDetailList.Where(ipDet => ipDet.Id == receiptDetail.IpDetailId).Single(); if (ipDetail.Id != receiptDetail.IpDetailId) { throw new TechnicalException("收货单明细和发货单明细ID不匹配。"); } if (ipDetail.Type != receiptDetail.IpDetailType) { throw new TechnicalException("收货单明细和发货单明细类型不匹配。"); } #region 扣减发货单的收货数 if (ipLocationDetail != null) { ipLocationDetail.ReceivedQty -= remainBaseQty; ipLocationDetail.IsClose = false; } ipDetail.ReceivedQty -= remainQty; //转为订单单位 ipDetail.IsClose = false; remainBaseQty = 0; remainQty = 0; #endregion if (ipLocationDetail != null) { this.genericMgr.Update(ipLocationDetail); } this.genericMgr.Update(ipDetail); #endregion } else { #region 按数量匹配 IList<IpDetail> thisIpDetailList = ipDetailList.Where(ipDet => ipDet.ReceivedQty != 0 //过滤掉已经扣完的明细 && ipDet.Id == receiptDetail.IpDetailId).ToList(); if (thisIpDetailList != null && thisIpDetailList.Count > 0) { IList<IpLocationDetail> thisIpLocationDetailList = null; foreach (IpDetail thisIpDetail in thisIpDetailList) { if (thisIpDetail.ReceivedQty > 0) { thisIpLocationDetailList = ipLocationDetailList.Where( ipLocDet => ipLocDet.ReceivedQty > 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList(); } else if (thisIpDetail.ReceivedQty < 0) { thisIpLocationDetailList = ipLocationDetailList.Where( ipLocDet => ipLocDet.ReceivedQty < 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList(); } if (thisIpLocationDetailList != null && thisIpLocationDetailList.Count > 0) { foreach (IpLocationDetail thisIpLocationDetail in thisIpLocationDetailList) { if (thisIpLocationDetail.ReceivedQty > remainBaseQty) { //如果剩余冲销数量为0则不打开送货单 if (remainBaseQty != 0) { thisIpDetail.IsClose = false; thisIpLocationDetail.IsClose = false; } thisIpDetail.ReceivedQty -= remainQty; remainQty = 0; thisIpLocationDetail.ReceivedQty -= remainBaseQty; remainBaseQty = 0; } else { decimal thisBackflushQty = thisIpLocationDetail.ReceivedQty / thisIpDetail.UnitQty; //转为订单单位 remainQty -= thisBackflushQty; thisIpDetail.ReceivedQty -= thisBackflushQty; remainBaseQty -= thisIpLocationDetail.ReceivedQty; thisIpLocationDetail.ReceivedQty = 0; thisIpDetail.IsClose = false; thisIpLocationDetail.IsClose = false; } this.genericMgr.Update(thisIpLocationDetail); this.genericMgr.Update(thisIpDetail); } } else { //throw new TechnicalException("差异送货单明细和送货单库存明细不匹配。"); } } } #endregion } if (remainBaseQty != 0) { throw new TechnicalException("收货单的收货数没有回冲完。"); } } #endregion #region 更新订单明细 if (receiptMaster.OrderType != CodeMaster.OrderType.ScheduleLine) { #region 非计划协议 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single(); if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal) { matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; if (matchedOrderDetial.ReceivedQty < 0) { throw new TechnicalException("订单收货数小于0。"); } } else { //差异收货冲销 #region 调整发货方库存 if (receiptMaster.PartyFrom == ipMaster.PartyTo) //发货方等于收货方 { //更新订单的发货数 matchedOrderDetial.ShippedQty += receiptDetail.ReceivedQty; } #endregion #region 调整收货方库存 else { //更新订单的收货数 matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; } #endregion } genericMgr.Update(matchedOrderDetial); } #endregion } else { foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { decimal receivedQty = receiptDetail.ReceivedQty; if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal) { #region 调整收货方库存 IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and RecQty > 0 order by EndDate desc", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty; scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty; } else { scheduleOrderDetail.ReceivedQty -= receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } #endregion } else { //差异收货冲销 #region 调整发货方库存 if (receiptMaster.PartyFrom == ipMaster.PartyTo) //发货方等于收货方 { IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and OrderQty > ShipQty order by EndDate", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty)) { receivedQty -= scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty; scheduleOrderDetail.ShippedQty = scheduleOrderDetail.OrderedQty; } else { scheduleOrderDetail.ShippedQty += receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } } #endregion #region 调整收货方库存 else { IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and RecQty > 0 order by EndDate desc", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty; scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty; } else { scheduleOrderDetail.ReceivedQty -= receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } } #endregion } } } #endregion #region 回滚送货单状态 //1. 普通状态的送货明细没有收过货 //2. 差异状态的送货明细全部关闭 if (ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Normal && ipDet.ReceivedQty != 0).Count() == 0 && ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Gap && !ipDet.IsClose).Count() == 0) { ipMaster.Status = CodeMaster.IpStatus.Submit; this.genericMgr.Update(ipMaster); #region 回滚排序单状态 if (!string.IsNullOrWhiteSpace(ipMaster.SequenceNo)) { SequenceMaster sequenceMaster = this.genericMgr.FindById<SequenceMaster>(ipMaster.SequenceNo); sequenceMaster.Status = CodeMaster.SequenceStatus.Ship; this.genericMgr.Update(sequenceMaster); } #endregion } else if (ipMaster.Status != CodeMaster.IpStatus.InProcess) { ipMaster.Status = CodeMaster.IpStatus.InProcess; this.genericMgr.Update(ipMaster); } #endregion #region 退回排序单状态 if (!string.IsNullOrEmpty(ipMaster.SequenceNo)) { #region 更新排序单头 SequenceMaster sequenceMaster = this.genericMgr.FindById<SequenceMaster>(ipMaster.SequenceNo); sequenceMaster.Status = CodeMaster.SequenceStatus.Ship; sequenceMaster.CloseDate = null; sequenceMaster.CloseUserId = 0; sequenceMaster.CloseUserName = null; this.genericMgr.Update(sequenceMaster); #endregion foreach (SequenceDetail sequenceDetail in TryLoadSequenceDetails(sequenceMaster)) { //对于调整计划关闭的排序明细也有可能打开了,会有Bug if (orderDetialList.Select(i => i.Id).Contains(sequenceDetail.OrderDetailId)) { sequenceDetail.IsClose = false; this.genericMgr.Update(sequenceDetail); } } } #endregion } else { #region 更新订单明细 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail != null) { OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single(); matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; matchedOrderDetial.ScrapQty -= receiptDetail.ScrapQty; if (matchedOrderDetial.OrderType != CodeMaster.OrderType.Production && matchedOrderDetial.OrderType != CodeMaster.OrderType.SubContract) { matchedOrderDetial.ShippedQty -= receiptDetail.ReceivedQty; if (matchedOrderDetial.ShippedQty < 0) { throw new TechnicalException("订单发货数小于0。"); } } if (matchedOrderDetial.ReceivedQty < 0) { throw new TechnicalException("订单收货数小于0。"); } this.genericMgr.Update(matchedOrderDetial); } } #endregion } #endregion #region 更新订单 foreach (OrderMaster orderMaster in orderMasterList) { if (orderMaster.Status != CodeMaster.OrderStatus.InProcess) { orderMaster.Status = CodeMaster.OrderStatus.InProcess; orderMaster.CloseDate = null; orderMaster.CloseUserId = null; orderMaster.CloseUserName = null; this.genericMgr.Update(orderMaster); } } #endregion #region 更新收货单 receiptMaster.Status = CodeMaster.ReceiptStatus.Cancel; this.genericMgr.Update(receiptMaster); #endregion #region 冲销收货记录 List<IpDetail> cancelIpDetailList = new List<IpDetail>(); foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail.ReceivedQty != 0) { receiptDetail.CurrentPartyFrom = receiptMaster.PartyFrom; //为了记录库存事务 receiptDetail.CurrentPartyFromName = receiptMaster.PartyFromName; receiptDetail.CurrentPartyTo = receiptMaster.PartyTo; receiptDetail.CurrentPartyToName = receiptMaster.PartyToName; receiptDetail.CurrentExternalReceiptNo = receiptMaster.ExternalReceiptNo; receiptDetail.CurrentIsReceiveScanHu = receiptMaster.IsReceiveScanHu || orderMasterList.Where(o => o.OrderStrategy == CodeMaster.FlowStrategy.KIT).Count() > 0; receiptDetail.IsVoid = true; foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails) { ReceiptDetailInput receiptDetailInput = new ReceiptDetailInput(); receiptDetailInput.HuId = receiptLocationDetail.HuId; receiptDetailInput.ReceiveQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位 receiptDetailInput.LotNo = receiptLocationDetail.LotNo; receiptDetailInput.IsCreatePlanBill = receiptLocationDetail.IsCreatePlanBill; receiptDetailInput.IsConsignment = receiptLocationDetail.IsConsignment; receiptDetailInput.PlanBill = receiptLocationDetail.PlanBill; receiptDetailInput.ActingBill = receiptLocationDetail.ActingBill; receiptDetailInput.IsATP = receiptLocationDetail.IsATP; receiptDetailInput.IsFreeze = receiptLocationDetail.IsFreeze; receiptDetailInput.OccupyType = receiptLocationDetail.OccupyType; receiptDetailInput.OccupyReferenceNo = receiptLocationDetail.OccupyReferenceNo; receiptDetailInput.QualityType = receiptLocationDetail.QualityType; receiptDetail.AddReceiptDetailInput(receiptDetailInput); } #region 更新库存、记库存事务 IList<InventoryTransaction> rctInventoryTransactionList = this.locationDetailMgr.InventoryIn(receiptDetail, effectiveDate); #endregion #region 订单直接收货创建发货明细对象 if (!string.IsNullOrWhiteSpace(receiptMaster.IpNo)) { //nothing todo } else if (receiptMaster.Type == CodeMaster.IpDetailType.Gap) { //nothing todo } else if (receiptMaster.OrderType == CodeMaster.OrderType.Production) { //nothing todo } else if (receiptMaster.OrderType == CodeMaster.OrderType.SubContract && receiptMaster.OrderSubType == CodeMaster.OrderSubType.Normal) { //nothing todo } else //if (string.IsNullOrWhiteSpace(receiptMaster.IpNo) // && receiptMaster.Type != CodeMaster.IpDetailType.Gap // && receiptMaster.OrderType != CodeMaster.OrderType.Production // && (receiptMaster.OrderType != CodeMaster.OrderType.SubContract)) { IpDetail ipdetail = new IpDetail(); ipdetail.OrderNo = receiptDetail.OrderNo; ipdetail.OrderType = receiptDetail.OrderType; ipdetail.OrderSubType = receiptDetail.OrderSubType; ipdetail.OrderDetailId = receiptDetail.OrderDetailId; ipdetail.OrderDetailSequence = receiptDetail.OrderDetailSequence; ipdetail.Item = receiptDetail.Item; ipdetail.ItemDescription = receiptDetail.ItemDescription; ipdetail.ReferenceItemCode = receiptDetail.ReferenceItemCode; ipdetail.BaseUom = receiptDetail.BaseUom; ipdetail.Uom = receiptDetail.Uom; ipdetail.UnitCount = receiptDetail.UnitCount; //ipdetail.UnitCountDescription = receiptDetail.UnitCountDescription; //ipdetail.Container = receiptDetail.Container; //ipdetail.ContainerDescription = receiptDetail.ContainerDescription; ipdetail.QualityType = receiptDetail.QualityType; //ipdetail.ManufactureParty = receiptDetail.ManufactureParty; if ((ipdetail.OrderType == CodeMaster.OrderType.Procurement || ipdetail.OrderType == CodeMaster.OrderType.SubContract) && ipdetail.OrderSubType == CodeMaster.OrderSubType.Return) { //退货的订单需要入库y ipdetail.Qty = receiptDetail.ReceivedQty; } else { ipdetail.Qty = -receiptDetail.ReceivedQty; } //ipdetail.ReceivedQty = ipdetail.UnitQty = receiptDetail.UnitQty; ipdetail.LocationFrom = receiptDetail.LocationFrom; ipdetail.LocationFromName = receiptDetail.LocationFromName; ipdetail.LocationTo = receiptDetail.LocationTo; ipdetail.LocationToName = receiptDetail.LocationToName; ipdetail.IsInspect = false; //ipdetail.BillTerm = receiptDetail.BillTerm; ipdetail.IsVoid = true; cancelIpDetailList.Add(ipdetail); foreach (InventoryTransaction inventoryTransaction in rctInventoryTransactionList) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.HuId = inventoryTransaction.HuId; if ((ipdetail.OrderType == CodeMaster.OrderType.Procurement || ipdetail.OrderType == CodeMaster.OrderType.SubContract) && ipdetail.OrderSubType == CodeMaster.OrderSubType.Return) { ipDetailInput.ShipQty = -inventoryTransaction.Qty / ipdetail.UnitQty; } else { ipDetailInput.ShipQty = inventoryTransaction.Qty / ipdetail.UnitQty; } ipDetailInput.LotNo = inventoryTransaction.LotNo; ipDetailInput.IsCreatePlanBill = inventoryTransaction.IsCreatePlanBill; if (inventoryTransaction.ActingBill.HasValue) { int planBill = this.genericMgr.FindAllWithNativeSql<Int32>("select PlanBill from BIL_ActBill where Id = ?", inventoryTransaction.ActingBill.Value).Single(); ipDetailInput.IsConsignment = true; ipDetailInput.PlanBill = planBill; ipDetailInput.ActingBill = null; } else { ipDetailInput.IsConsignment = inventoryTransaction.IsConsignment; ipDetailInput.PlanBill = inventoryTransaction.PlanBill; ipDetailInput.ActingBill = inventoryTransaction.ActingBill; } ipDetailInput.OccupyType = inventoryTransaction.OccupyType; ipDetailInput.OccupyReferenceNo = inventoryTransaction.OccupyReferenceNo; ipdetail.AddIpDetailInput(ipDetailInput); } } #endregion } } #endregion #region 订单直接收货,冲销发货记录 if (cancelIpDetailList != null && cancelIpDetailList.Count > 0) { foreach (IpDetail cancelIpDetail in cancelIpDetailList) { cancelIpDetail.CurrentPartyFrom = receiptMaster.PartyFrom; //为了记录库存事务 cancelIpDetail.CurrentPartyFromName = receiptMaster.PartyFromName; //为了记录库存事务 cancelIpDetail.CurrentPartyTo = receiptMaster.PartyTo; //为了记录库存事务 cancelIpDetail.CurrentPartyToName = receiptMaster.PartyToName; //为了记录库存事务 this.locationDetailMgr.InventoryOut(cancelIpDetail); } } #endregion #region 生产单,委外冲销退回原材料 if (receiptMaster.OrderType == CodeMaster.OrderType.Production || receiptMaster.OrderType == CodeMaster.OrderType.SubContract) { var backflushInputList = ReceiptMaster2BackflushInputList(receiptMaster); locationDetailMgr.CancelBackflushProductMaterial(backflushInputList, effectiveDate); var orderBackflushDetailList = BackflushInputList2OrderBackflushDetailList(backflushInputList); DateTime dateTimeNow = DateTime.Now; User currentUser = SecurityContextHolder.Get(); foreach (OrderBackflushDetail orderBackflushDetail in orderBackflushDetailList) { orderBackflushDetail.EffectiveDate = effectiveDate; orderBackflushDetail.CreateUserId = currentUser.Id; orderBackflushDetail.CreateUserName = currentUser.FullName; orderBackflushDetail.CreateDate = dateTimeNow; orderBackflushDetail.IsVoid = true; this.genericMgr.Create(orderBackflushDetail); } } #endregion }
public void CreateReceipt(ReceiptMaster receiptMaster, bool isKit, DateTime effectiveDate) { if (!Utility.SecurityHelper.HasPermission(receiptMaster)) { //throw new BusinessException("没有此收货单{0}的操作权限。", receiptMaster.ReceiptNo); } #region 收货明细不能为空 if (receiptMaster.ReceiptDetails == null || receiptMaster.ReceiptDetails.Count == 0) { throw new BusinessException(Resources.ORD.ReceiptMaster.Errors_ReceiptDetailIsEmpty); } #endregion #region 保存收货单头 receiptMaster.ReceiptNo = numberControlMgr.GetReceiptNo(receiptMaster); receiptMaster.EffectiveDate = effectiveDate; receiptMaster.Status = CodeMaster.ReceiptStatus.Close; this.genericMgr.Create(receiptMaster); #endregion #region 保存收货单明细 int seqCount = 1; foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails.OrderBy(i => i.IpDetailSequence).ThenBy(i => i.OrderNo).ThenBy(i => i.OrderDetailSequence)) { if (receiptDetail.ReceiveQtyInput < 0) { //throw new BusinessException(Resources.SYS.ErrorMessage.Errors_NegativeExceptiond); } receiptDetail.ReceivedQty = receiptDetail.ReceiveQtyInput; receiptDetail.ScrapQty = receiptDetail.ScrapQtyInput; //receiptDetail.RejectedQty = receiptDetail.RejectQtyInput; receiptDetail.Sequence = seqCount++; receiptDetail.ReceiptNo = receiptMaster.ReceiptNo; this.genericMgr.Create(receiptDetail); } #endregion #region 收货创建条码 //只有生产才支持收货创建条码,因为物流收货IpLocaitonLotDetail上会有寄售信息,也有可能一条收货记录对应多条IpLocaitonLotDetail,没有办法赋值HuId if ((receiptMaster.OrderType == CodeMaster.OrderType.Production) && receiptMaster.CreateHuOption == CodeMaster.CreateHuOption.Receive && receiptMaster.OrderSubType == CodeMaster.OrderSubType.Normal) { var flowMaster = receiptMaster.CurrentFlowMaster; if (flowMaster == null && !string.IsNullOrWhiteSpace(receiptMaster.Flow)) { flowMaster = this.genericMgr.FindById<FlowMaster>(receiptMaster.Flow); receiptMaster.CurrentFlowMaster = flowMaster; } foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail.ReceivedQty > 0) { if (flowMaster != null) { if (flowMaster.UcDeviation >= 0) { receiptDetail.MaxUc = receiptDetail.UnitCount * Convert.ToDecimal(((flowMaster.UcDeviation / 100) + 1)); receiptDetail.MinUc = receiptDetail.UnitCount * Convert.ToDecimal((1 - (flowMaster.UcDeviation / 100))); } else { receiptDetail.MaxUc = receiptDetail.ReceivedQty; receiptDetail.MinUc = receiptDetail.ReceivedQty; } } else { receiptDetail.MaxUc = receiptDetail.UnitCount; receiptDetail.MinUc = receiptDetail.UnitCount; } IList<Hu> huList = huMgr.CreateHu(receiptMaster, receiptDetail, receiptMaster.StartTime); receiptDetail.ReceiptDetailInputs = (from hu in huList select new ReceiptDetailInput { ReceiveQty = hu.Qty, //转为订单单位 QualityType = receiptDetail.QualityType, HuId = hu.HuId, LotNo = hu.LotNo, IsCreatePlanBill = false, IsConsignment = false, PlanBill = null, ActingBill = null, IsFreeze = false, IsATP = true, OccupyType = com.Sconit.CodeMaster.OccupyType.None, OccupyReferenceNo = null }).ToList(); } } } #endregion #region 循环收货 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail.ReceivedQty != 0) { receiptDetail.CurrentPartyFrom = receiptMaster.PartyFrom; //为了记录库存事务 receiptDetail.CurrentPartyFromName = receiptMaster.PartyFromName; receiptDetail.CurrentPartyTo = receiptMaster.PartyTo; receiptDetail.CurrentPartyToName = receiptMaster.PartyToName; receiptDetail.CurrentExternalReceiptNo = receiptMaster.ExternalReceiptNo; receiptDetail.CurrentIsReceiveScanHu = receiptMaster.IsReceiveScanHu || isKit; //inputIpDetail.CurrentIsATP = inputIpDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified; //inputIpDetail.CurrentIsFreeze = false; //默认只出库未冻结库存 IList<InventoryTransaction> inventoryTransactionList = this.locationDetailMgr.InventoryIn(receiptDetail, effectiveDate); if (inventoryTransactionList != null && inventoryTransactionList.Count > 0) { IList<ReceiptLocationDetail> receiptLocationDetailList = (from trans in inventoryTransactionList group trans by new { HuId = trans.HuId, LotNo = trans.LotNo, IsCreatePlanBill = trans.IsCreatePlanBill, IsConsignment = trans.IsConsignment, PlanBill = trans.PlanBill, ActingBill = trans.ActingBill, IsFreeze = trans.IsFreeze, IsATP = trans.IsATP, WMSSeq = trans.WMSRecSeq, } into g select new ReceiptLocationDetail { Item = receiptDetail.Item, HuId = g.Key.HuId, LotNo = g.Key.LotNo, IsCreatePlanBill = g.Key.IsCreatePlanBill, IsConsignment = g.Key.IsConsignment, PlanBill = g.Key.PlanBill, ActingBill = g.Key.ActingBill, QualityType = receiptDetail.QualityType, IsFreeze = g.Key.IsFreeze, IsATP = g.Key.IsATP, OccupyType = receiptDetail.CurrentOccupyType, OccupyReferenceNo = receiptDetail.CurrentOccupyReferenceNo, Qty = g.Sum(t => t.Qty), WMSSeq = g.Key.WMSSeq }).ToList(); receiptDetail.AddReceiptLocationDetail(receiptLocationDetailList); } } } #endregion #region 保存发货单库存明细 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail.ReceiptLocationDetails != null && receiptDetail.ReceiptLocationDetails.Count > 0) { foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails) { receiptLocationDetail.ReceiptNo = receiptMaster.ReceiptNo; receiptLocationDetail.ReceiptDetailId = receiptDetail.Id; receiptLocationDetail.OrderType = receiptDetail.OrderType; receiptLocationDetail.OrderDetailId = receiptDetail.OrderDetailId; genericMgr.Create(receiptLocationDetail); } } } #endregion #region 检验 InspectMaster inspectMaster = inspectMgr.TransferReceipt2Inspect(receiptMaster); if (inspectMaster != null && inspectMaster.InspectDetails != null && inspectMaster.InspectDetails.Count > 0) { inspectMgr.CreateInspectMaster(inspectMaster, effectiveDate); } #endregion #region 生产原材料回用,委外退货 增加原材料库存 if ((receiptMaster.OrderType == CodeMaster.OrderType.Production || receiptMaster.OrderType == CodeMaster.OrderType.SubContract) && receiptMaster.OrderSubType == CodeMaster.OrderSubType.Return) { var backflushInputList = ReceiptMaster2BackflushInputList(receiptMaster); locationDetailMgr.BackflushProductMaterial(backflushInputList, effectiveDate); var orderBackflushDetailList = BackflushInputList2OrderBackflushDetailList(backflushInputList); DateTime dateTimeNow = DateTime.Now; User currentUser = SecurityContextHolder.Get(); foreach (OrderBackflushDetail orderBackflushDetail in orderBackflushDetailList) { orderBackflushDetail.EffectiveDate = effectiveDate; orderBackflushDetail.CreateUserId = currentUser.Id; orderBackflushDetail.CreateUserName = currentUser.FullName; orderBackflushDetail.CreateDate = dateTimeNow; orderBackflushDetail.IsVoid = true; this.genericMgr.Create(orderBackflushDetail); } } #endregion this.AsyncSendPrintData(receiptMaster); }
public void CancelReceipt(ReceiptMaster receiptMaster, DateTime effectiveDate) { #region 判断收货单状态,只有Close才能冲销 if (receiptMaster.Status == CodeMaster.ReceiptStatus.Cancel) { throw new BusinessException("收货单{0}已经冲销。", receiptMaster.ReceiptNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.ReceiptStatus, ((int)receiptMaster.Status).ToString())); } #endregion #region 加载收货单明细及收货单库存明细 // TryLoadReceiptDetails(receiptMaster); IList<ReceiptLocationDetail> receiptLocationDetailList = TryLoadReceiptLocationDetails(receiptMaster); #endregion #region 加载订单头和明细 //GAP收货取消不用调整订单数据 IList<OrderMaster> orderMasterList = null; IList<OrderDetail> orderDetialList = null; //if (receiptMaster.Type == CodeMaster.IpDetailType.Normal) //{ #region 获取订单头 orderMasterList = LoadOrderMasters(receiptMaster.ReceiptDetails.Select(det => det.OrderNo).Distinct().ToArray()); #endregion #region 获取订单明细 orderDetialList = LoadOrderDetails(receiptMaster.ReceiptDetails.Where(det => det.OrderDetailId.HasValue).Select(det => det.OrderDetailId.Value).Distinct().ToArray()); #endregion //} #endregion //小数保留位数 int decimalLength = int.Parse(systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.DecimalLength)); #region 回滚送货单 if (!string.IsNullOrWhiteSpace(receiptMaster.IpNo)) { IpMaster ipMaster = this.genericMgr.FindById<IpMaster>(receiptMaster.IpNo); #region 查找送货单明细 string selectIpDetailStatement = string.Empty; IList<object> selectIpDetailPram = new List<object>(); foreach (int ipDetailId in receiptMaster.ReceiptDetails.Select(recDet => recDet.IpDetailId).Distinct()) { if (selectIpDetailStatement == string.Empty) { selectIpDetailStatement = "from IpDetail where Id in (?"; } else { selectIpDetailStatement += ",?"; } selectIpDetailPram.Add(ipDetailId); } selectIpDetailStatement += ")"; IList<IpDetail> ipDetailList = this.genericMgr.FindAll<IpDetail>(selectIpDetailStatement, selectIpDetailPram.ToArray()); #endregion #region 查找送货单库存明细 IList<IpLocationDetail> ipLocationDetailList = LoadIpLocationDetails(ipDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion #region 查找差异送货单明细 IList<IpDetail> gapIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where GapReceiptNo = ?", receiptMaster.ReceiptNo); #endregion #region 差异全部关闭 if (gapIpDetailList != null && gapIpDetailList.Count > 0) { #region 查找差异送货单库存明细 IList<IpLocationDetail> gapIpLocationDetailList = LoadIpLocationDetails(gapIpDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion foreach (IpDetail gapIpDetail in gapIpDetailList) { if (gapIpDetail.ReceivedQty != 0) { throw new BusinessException("收货单{0}的收货差异已经调整,不能冲销。", receiptMaster.ReceiptNo); } gapIpDetail.IsClose = true; this.genericMgr.Update(gapIpDetail); } foreach (IpLocationDetail gapIpLocationDetail in gapIpLocationDetailList) { gapIpLocationDetail.IsClose = true; this.genericMgr.Update(gapIpLocationDetail); } } #endregion #region 打开未收货的发货明细 //只有ASN一次性收货才打开未收货的发货明细 if (ipMaster.IsAsnUniqueReceive) { //只有正常收货才能打开未收货的发货明细。 int isGapRec = receiptMaster.ReceiptDetails.Where(recDet => recDet.IpDetailType == CodeMaster.IpDetailType.Gap).Count(); if (isGapRec == 0) { IList<IpDetail> unReceivedIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where IpNo = ? and Type = ?", new object[] { ipMaster.IpNo, CodeMaster.IpDetailType.Normal }); if (unReceivedIpDetailList != null && unReceivedIpDetailList.Count > 0) { #region 查找差异送货单库存明细 IList<IpLocationDetail> unReceivedIpLocationDetailList = LoadIpLocationDetails(unReceivedIpDetailList.Select(ipDet => ipDet.Id).ToArray()); #endregion foreach (IpDetail unReceivedIpDetail in unReceivedIpDetailList) { if (unReceivedIpDetail.IsClose) { unReceivedIpDetail.IsClose = false; this.genericMgr.Update(unReceivedIpDetail); } } foreach (IpLocationDetail unReceivedIpLocationDetail in unReceivedIpLocationDetailList) { if (unReceivedIpLocationDetail.IsClose) { unReceivedIpLocationDetail.IsClose = false; this.genericMgr.Update(unReceivedIpLocationDetail); } } } } } #endregion #region 收货库存明细和送货库存明细匹配 foreach (ReceiptLocationDetail receiptLocationDetail in receiptLocationDetailList) { ReceiptDetail receiptDetail = receiptMaster.ReceiptDetails.Where(recDet => recDet.Id == receiptLocationDetail.ReceiptDetailId).Single(); decimal remainBaseQty = receiptLocationDetail.Qty; //基本单位 decimal remainQty = receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位 if (!string.IsNullOrWhiteSpace(receiptLocationDetail.HuId) && ipLocationDetailList.Where(ipLocDet => !string.IsNullOrWhiteSpace(ipLocDet.HuId)).Count() > 0) { #region 条码和条码匹配 IpLocationDetail ipLocationDetail = ipLocationDetailList.Where(ipLocDet => ipLocDet.HuId == receiptLocationDetail.HuId).SingleOrDefault(); IpDetail ipDetail = ipDetailList.Where(ipDet => ipDet.Id == receiptDetail.IpDetailId).Single(); if (ipDetail.Id != receiptDetail.IpDetailId) { throw new TechnicalException("收货单明细和发货单明细ID不匹配。"); } if (ipDetail.Type != receiptDetail.IpDetailType) { throw new TechnicalException("收货单明细和发货单明细类型不匹配。"); } #region 扣减发货单的收货数 if (ipLocationDetail != null) { ipLocationDetail.ReceivedQty -= remainBaseQty; ipLocationDetail.IsClose = false; } ipDetail.ReceivedQty -= remainQty; //转为订单单位 ipDetail.IsClose = false; remainBaseQty = 0; remainQty = 0; #endregion if (ipLocationDetail != null) { this.genericMgr.Update(ipLocationDetail); } this.genericMgr.Update(ipDetail); #endregion } else { #region 按数量匹配 IList<IpDetail> thisIpDetailList = ipDetailList.Where(ipDet => ipDet.ReceivedQty != 0 //过滤掉已经扣完的明细 && ipDet.Id == receiptDetail.IpDetailId).ToList(); if (thisIpDetailList != null && thisIpDetailList.Count > 0) { IList<IpLocationDetail> thisIpLocationDetailList = null; foreach (IpDetail thisIpDetail in thisIpDetailList) { if (thisIpDetail.ReceivedQty > 0) { thisIpLocationDetailList = ipLocationDetailList.Where( ipLocDet => ipLocDet.ReceivedQty > 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList(); } else if (thisIpDetail.ReceivedQty < 0) { thisIpLocationDetailList = ipLocationDetailList.Where( ipLocDet => ipLocDet.ReceivedQty < 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList(); } if (thisIpLocationDetailList != null && thisIpLocationDetailList.Count > 0) { foreach (IpLocationDetail thisIpLocationDetail in thisIpLocationDetailList) { if (thisIpLocationDetail.ReceivedQty > remainBaseQty) { thisIpDetail.ReceivedQty -= remainQty; remainQty = 0; thisIpLocationDetail.ReceivedQty -= remainBaseQty; remainBaseQty = 0; thisIpDetail.IsClose = false; thisIpLocationDetail.IsClose = false; } else { decimal thisBackflushQty = thisIpLocationDetail.ReceivedQty / thisIpDetail.UnitQty; //转为订单单位 remainQty -= thisBackflushQty; thisIpDetail.ReceivedQty -= thisBackflushQty; remainBaseQty -= thisIpLocationDetail.ReceivedQty; thisIpLocationDetail.ReceivedQty = 0; thisIpDetail.IsClose = false; thisIpLocationDetail.IsClose = false; } this.genericMgr.Update(thisIpLocationDetail); this.genericMgr.Update(thisIpDetail); } } else { //throw new TechnicalException("差异送货单明细和送货单库存明细不匹配。"); } } } #endregion } if (remainBaseQty != 0) { throw new TechnicalException("收货单的收货数没有回冲完。"); } } #endregion #region 更新订单明细 if (receiptMaster.OrderType != CodeMaster.OrderType.ScheduleLine) { #region 非计划协议 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single(); if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal) { matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; if (matchedOrderDetial.ReceivedQty < 0) { throw new TechnicalException("订单收货数小于0。"); } } else { //差异收货冲销 #region 调整发货方库存 if (receiptMaster.PartyFrom == ipMaster.PartyTo) //发货方等于收货方 { //更新订单的发货数 matchedOrderDetial.ShippedQty += receiptDetail.ReceivedQty; } #endregion #region 调整收货方库存 else { //更新订单的收货数 matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; } #endregion } genericMgr.Update(matchedOrderDetial); } #endregion } else { foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { decimal receivedQty = receiptDetail.ReceivedQty; if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal) { #region 调整收货方库存 IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq = ? and ScheduleType = ? and RecQty > 0 order by EndDate desc", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence, CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty; scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty; } else { scheduleOrderDetail.ReceivedQty -= receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } #endregion } else { //差异收货冲销 #region 调整发货方库存 if (receiptMaster.PartyFrom == ipMaster.PartyTo) //发货方等于收货方 { IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq = ? and ScheduleType = ? and OrderQty > ShipQty order by EndDate", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence, CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty)) { receivedQty -= scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty; scheduleOrderDetail.ShippedQty = scheduleOrderDetail.OrderedQty; } else { scheduleOrderDetail.ShippedQty += receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } } #endregion #region 调整收货方库存 else { IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq = ? and ScheduleType = ? and RecQty > 0 order by EndDate desc", new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence, CodeMaster.ScheduleType.Firm }); foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList) { if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty)) { receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty; scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty; } else { scheduleOrderDetail.ReceivedQty -= receivedQty; receivedQty = 0; } genericMgr.Update(scheduleOrderDetail); } } #endregion } } } #endregion #region 回滚送货单状态 //1. 普通状态的送货明细没有收过货 //2. 差异状态的送货明细全部关闭 if (ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Normal && ipDet.ReceivedQty != 0).Count() == 0 && ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Gap && !ipDet.IsClose).Count() == 0) { ipMaster.Status = CodeMaster.IpStatus.Submit; this.genericMgr.Update(ipMaster); } else if (ipMaster.Status != CodeMaster.IpStatus.InProcess) { ipMaster.Status = CodeMaster.IpStatus.InProcess; this.genericMgr.Update(ipMaster); } #endregion } else { #region 更新订单明细 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail != null) { OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single(); matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty; matchedOrderDetial.ScrapQty -= receiptDetail.ScrapQty; if (matchedOrderDetial.OrderType != CodeMaster.OrderType.Production && matchedOrderDetial.OrderType != CodeMaster.OrderType.SubContract) { matchedOrderDetial.ShippedQty -= receiptDetail.ReceivedQty; if (matchedOrderDetial.ShippedQty < 0) { throw new TechnicalException("订单发货数小于0。"); } } if (matchedOrderDetial.ReceivedQty < 0) { throw new TechnicalException("订单收货数小于0。"); } this.genericMgr.Update(matchedOrderDetial); } } #endregion } #endregion #region 更新订单 foreach (OrderMaster orderMaster in orderMasterList) { if (orderMaster.Status != CodeMaster.OrderStatus.InProcess) { orderMaster.Status = CodeMaster.OrderStatus.InProcess; orderMaster.CloseDate = null; orderMaster.CloseUserId = null; orderMaster.CompleteUserName = null; this.genericMgr.Update(orderMaster); } } #endregion #region 更新收货单 receiptMaster.Status = CodeMaster.ReceiptStatus.Cancel; this.genericMgr.Update(receiptMaster); #endregion #region 冲销收货记录 List<IpDetail> cancelIpDetailList = new List<IpDetail>(); foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail.ReceivedQty != 0) { receiptDetail.CurrentPartyFrom = receiptMaster.PartyFrom; //为了记录库存事务 receiptDetail.CurrentPartyFromName = receiptMaster.PartyFromName; receiptDetail.CurrentPartyTo = receiptMaster.PartyTo; receiptDetail.CurrentPartyToName = receiptMaster.PartyToName; receiptDetail.CurrentExternalReceiptNo = receiptMaster.ExternalReceiptNo; receiptDetail.CurrentIsReceiveScanHu = receiptMaster.IsReceiveScanHu; receiptDetail.IsVoid = true; foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails) { ReceiptDetailInput receiptDetailInput = new ReceiptDetailInput(); receiptDetailInput.HuId = receiptLocationDetail.HuId; receiptDetailInput.ReceiveQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位 receiptDetailInput.LotNo = receiptLocationDetail.LotNo; receiptDetailInput.IsCreatePlanBill = receiptLocationDetail.IsCreatePlanBill; receiptDetailInput.IsConsignment = receiptLocationDetail.IsConsignment; receiptDetailInput.PlanBill = receiptLocationDetail.PlanBill; receiptDetailInput.ActingBill = receiptLocationDetail.ActingBill; receiptDetailInput.IsATP = receiptLocationDetail.IsATP; receiptDetailInput.IsFreeze = receiptLocationDetail.IsFreeze; receiptDetailInput.OccupyType = receiptLocationDetail.OccupyType; receiptDetailInput.OccupyReferenceNo = receiptLocationDetail.OccupyReferenceNo; receiptDetailInput.QualityType = receiptLocationDetail.QualityType; receiptDetail.AddReceiptDetailInput(receiptDetailInput); } #region 更新库存、记库存事务 IList<InventoryTransaction> rctInventoryTransactionList = this.locationDetailMgr.InventoryIn(receiptDetail, effectiveDate); #endregion #region 订单直接收货创建发货明细对象 if (string.IsNullOrWhiteSpace(receiptMaster.IpNo) && receiptMaster.Type != CodeMaster.IpDetailType.Gap && receiptMaster.OrderType != CodeMaster.OrderType.Production && receiptMaster.OrderType != CodeMaster.OrderType.SubContract) { IpDetail ipdetail = new IpDetail(); ipdetail.OrderNo = receiptDetail.OrderNo; ipdetail.OrderType = receiptDetail.OrderType; ipdetail.OrderSubType = receiptDetail.OrderSubType; ipdetail.OrderDetailId = receiptDetail.OrderDetailId; ipdetail.OrderDetailSequence = receiptDetail.OrderDetailSequence; ipdetail.Item = receiptDetail.Item; ipdetail.ItemDescription = receiptDetail.ItemDescription; ipdetail.ReferenceItemCode = receiptDetail.ReferenceItemCode; ipdetail.BaseUom = receiptDetail.BaseUom; ipdetail.Uom = receiptDetail.Uom; ipdetail.UnitCount = receiptDetail.UnitCount; //ipdetail.UnitCountDescription = receiptDetail.UnitCountDescription; //ipdetail.Container = receiptDetail.Container; //ipdetail.ContainerDescription = receiptDetail.ContainerDescription; ipdetail.QualityType = receiptDetail.QualityType; //ipdetail.ManufactureParty = receiptDetail.ManufactureParty; ipdetail.Qty = receiptDetail.ReceivedQty; //ipdetail.ReceivedQty = ipdetail.UnitQty = receiptDetail.UnitQty; ipdetail.LocationFrom = receiptDetail.LocationFrom; ipdetail.LocationFromName = receiptDetail.LocationFromName; ipdetail.LocationTo = receiptDetail.LocationTo; ipdetail.LocationToName = receiptDetail.LocationToName; ipdetail.IsInspect = false; //ipdetail.BillTerm = receiptDetail.BillTerm; ipdetail.IsVoid = true; cancelIpDetailList.Add(ipdetail); foreach (InventoryTransaction inventoryTransaction in rctInventoryTransactionList) { IpDetailInput ipDetailInput = new IpDetailInput(); ipDetailInput.HuId = inventoryTransaction.HuId; ipDetailInput.ShipQty = inventoryTransaction.Qty / ipdetail.UnitQty; ipDetailInput.LotNo = inventoryTransaction.LotNo; ipDetailInput.IsCreatePlanBill = inventoryTransaction.IsCreatePlanBill; if (inventoryTransaction.ActingBill.HasValue) { int planBill = this.genericMgr.FindAllWithNativeSql<Int32>("select PlanBill from BIL_ActBill where Id = ?", inventoryTransaction.ActingBill.Value).Single(); ipDetailInput.IsConsignment = true; ipDetailInput.PlanBill = planBill; ipDetailInput.ActingBill = null; } else { ipDetailInput.IsConsignment = inventoryTransaction.IsConsignment; ipDetailInput.PlanBill = inventoryTransaction.PlanBill; ipDetailInput.ActingBill = inventoryTransaction.ActingBill; } ipDetailInput.OccupyType = inventoryTransaction.OccupyType; ipDetailInput.OccupyReferenceNo = inventoryTransaction.OccupyReferenceNo; ipdetail.AddIpDetailInput(ipDetailInput); } } #endregion } #region 来源区域是LOC、SQC 的冲销后更新 读取安吉文件中间表的冲销数 if ((receiptMaster.PartyFrom == systemMgr.GetEntityPreferenceValue(Entity.SYS.EntityPreference.CodeEnum.WMSAnjiRegion) || receiptMaster.PartyFrom == "SQC") && receiptMaster.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal && !string.IsNullOrWhiteSpace(receiptDetail.ExternalOrderNo)) { var wmsDatfileById = this.genericMgr.FindAll<WMSDatFile>(" select w from WMSDatFile as w where w.WMSId=? ", receiptDetail.ExternalOrderNo, NHibernate.NHibernateUtil.String); if (wmsDatfileById != null && wmsDatfileById.Count > 0) { wmsDatfileById.First().CancelQty += receiptDetail.ReceivedQty; this.genericMgr.Update(wmsDatfileById.First()); } //this.genericMgr.UpdateWithNativeQuery(" update FIS_WMSDatFile set CancelQty=CancelQty+? where WMSId=? ",new object[]{ receiptDetail.ReceivedQty, receiptDetail.ExternalOrderNo},new IType[]{NHibernate.NHibernateUtil.Decimal,NHibernate.NHibernateUtil.String}); #region 冲销的写入中间表传给安吉 this.genericMgr.Create(new CancelReceiptMasterDAT { WMSNo = receiptDetail.ExternalOrderNo, WMSSeq = receiptDetail.OrderDetailId, ReceivedQty = receiptDetail.ReceivedQty, CreateDate = System.DateTime.Now }); #endregion } #endregion } #endregion #region 订单直接收货,冲销发货记录 if (cancelIpDetailList != null && cancelIpDetailList.Count > 0) { foreach (IpDetail cancelIpDetail in cancelIpDetailList) { cancelIpDetail.CurrentPartyFrom = receiptMaster.PartyFrom; //为了记录库存事务 cancelIpDetail.CurrentPartyFromName = receiptMaster.PartyFromName; //为了记录库存事务 cancelIpDetail.CurrentPartyTo = receiptMaster.PartyTo; //为了记录库存事务 cancelIpDetail.CurrentPartyToName = receiptMaster.PartyToName; //为了记录库存事务 this.locationDetailMgr.InventoryOut(cancelIpDetail); } } #endregion #region 生产单冲销退回原材料 //if (receiptMaster.OrderType == CodeMaster.OrderType.Production // || receiptMaster.OrderType == CodeMaster.OrderType.SubContract) //{ // DateTime dateTimeNow = DateTime.Now; // User currentUser = SecurityContextHolder.Get(); // IList<OrderBackflushDetail> orderBackflushDetailList = new List<OrderBackflushDetail>(); // FlowMaster productLine = this.genericMgr.FindById<FlowMaster>(receiptMaster.Flow); // foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) // { // OrderMaster orderMaster = orderMasterList.Where(mstr => mstr.OrderNo == receiptDetail.OrderNo).Single(); // OrderDetail orderDetail = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId).Single(); // IList<OrderBomDetail> orderBomDetailList = this.genericMgr.FindAll<OrderBomDetail>("from OrderBomDetail where OrderDetailId = ?", receiptDetail.OrderDetailId); // IList<BackflushInput> backflushInputList = (from bom in orderBomDetailList // where bom.OrderedQty != 0 // select new BackflushInput // { // OrderNo = orderMaster.OrderNo, // OrderType = orderMaster.Type, // OrderSubType = orderMaster.SubType, // OrderDetailSequence = orderDetail.Sequence, // OrderDetailId = orderDetail.Id, // OrderBomDetail = bom, // ReceiptNo = receiptMaster.ReceiptNo, // ReceiptDetailId = receiptDetail.Id, // ReceiptDetailSequence = receiptDetail.Sequence, // TraceCode = orderMaster.TraceCode, // Item = bom.Item, // ItemDescription = bom.ItemDescription, // ReferenceItemCode = bom.ReferenceItemCode, // Uom = bom.Uom, // BaseUom = bom.BaseUom, // Qty = bom.BomUnitQty * (receiptDetail.ReceivedQty + receiptDetail.ScrapQty), // UnitQty = bom.UnitQty, // Location = string.IsNullOrWhiteSpace(bom.Location) ? (string.IsNullOrWhiteSpace(orderDetail.LocationFrom) ? orderMaster.LocationFrom : orderDetail.LocationFrom) : bom.Location, // CurrentProductLine = productLine, // ProductLine = productLine.Code, // FGItem = orderDetail.Item, // FGQualityType = CodeMaster.QualityType.Qualified, // Operation = bom.Operation, // OpReference = bom.OpReference, // }).ToList(); // IList<InventoryTransaction> inventoryTransactionList = this.locationDetailMgr.CancelBackflushProductMaterial(backflushInputList, effectiveDate); // foreach (BackflushInput backflushInput in backflushInputList) // { // ((List<OrderBackflushDetail>)orderBackflushDetailList).AddRange(from trans in backflushInput.InventoryTransactionList // group trans by trans.PlanBill into g // select new OrderBackflushDetail // { // OrderNo = backflushInput.OrderNo, // OrderDetailId = backflushInput.OrderDetailId, // OrderDetailSequence = backflushInput.OrderDetailSequence, // OrderBomDetailId = backflushInput.OrderBomDetail.Id, // OrderBomDetailSequence = backflushInput.OrderBomDetail.Sequence, // ReceiptNo = backflushInput.ReceiptNo, // ReceiptDetailId = backflushInput.ReceiptDetailId, // ReceiptDetailSequence = backflushInput.ReceiptDetailSequence, // Bom = backflushInput.OrderBomDetail.Bom, // FGItem = backflushInput.FGItem, // Item = backflushInput.Item, // ItemDescription = backflushInput.ItemDescription, // ReferenceItemCode = backflushInput.ReferenceItemCode, // Uom = backflushInput.Uom, // BaseUom = backflushInput.BaseUom, // UnitQty = backflushInput.UnitQty, // ManufactureParty = backflushInput.OrderBomDetail.ManufactureParty, // TraceCode = backflushInput.TraceCode, // //HuId = result.Key.HuId, // //LotNo = result.Key.LotNo, // Operation = backflushInput.Operation, // OpReference = backflushInput.OpReference, // BackflushedQty = backflushInput.FGQualityType == CodeMaster.QualityType.Qualified ? g.Sum(trans => trans.Qty) / backflushInput.UnitQty : 0, //根据收货成品的质量状态记录至不同的回冲数量中 // BackflushedRejectQty = backflushInput.FGQualityType == CodeMaster.QualityType.Reject ? g.Sum(trans => trans.Qty) / backflushInput.UnitQty : 0, // //BackflushedScrapQty = input.BackflushedQty, // LocationFrom = backflushInput.OrderBomDetail.Location, // ProductLine = backflushInput.ProductLine, // ProductLineFacility = backflushInput.ProductLineFacility, // PlanBill = g.Key, // EffectiveDate = effectiveDate, // CreateUserId = currentUser.Id, // CreateUserName = currentUser.FullName, // CreateDate = dateTimeNow, // IsVoid = true, // ReserveNo = backflushInput.OrderBomDetail.ReserveNo, // ReserveLine = backflushInput.OrderBomDetail.ReserveLine, // AUFNR = backflushInput.OrderBomDetail.AUFNR, // ICHARG = backflushInput.OrderBomDetail.ICHARG, // BWART = (int.Parse(backflushInput.OrderBomDetail.BWART) + 1).ToString(), // }); // } // } // foreach (OrderBackflushDetail orderBackflushDetail in orderBackflushDetailList) // { // this.genericMgr.Create(orderBackflushDetail); // } //} #endregion }
public void CreateReceipt(ReceiptMaster receiptMaster, bool isKit, DateTime effectiveDate) { #region 收货明细不能为空 if (receiptMaster.ReceiptDetails == null || receiptMaster.ReceiptDetails.Count == 0) { throw new BusinessException(Resources.ORD.ReceiptMaster.Errors_ReceiptDetailIsEmpty); } #endregion #region 保存收货单头 receiptMaster.ReceiptNo = numberControlMgr.GetReceiptNo(receiptMaster); receiptMaster.EffectiveDate = effectiveDate; receiptMaster.Status = CodeMaster.ReceiptStatus.Close; this.genericMgr.Create(receiptMaster); #endregion #region 保存收货单明细 int seqCount = 1; foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails.OrderBy(i => i.IpDetailSequence).ThenBy(i => i.OrderNo).ThenBy(i => i.OrderDetailSequence)) { receiptDetail.ReceivedQty = receiptDetail.ReceiveQtyInput; receiptDetail.ScrapQty = receiptDetail.ScrapQtyInput; //receiptDetail.RejectedQty = receiptDetail.RejectQtyInput; receiptDetail.Sequence = seqCount++; receiptDetail.ReceiptNo = receiptMaster.ReceiptNo; this.genericMgr.Create(receiptDetail); } #endregion #region 收货创建条码 //只有生产和委外才支持收货创建条码,因为物流收货IpLocaitonLotDetail上会有寄售信息,也有可能一条收货记录对应多条IpLocaitonLotDetail,没有办法赋值HuId if ((receiptMaster.OrderType == CodeMaster.OrderType.Production || receiptMaster.OrderType == CodeMaster.OrderType.SubContract) && receiptMaster.CreateHuOption == CodeMaster.CreateHuOption.Receive) { foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { IList<Hu> huList = huMgr.CreateHu(receiptMaster, receiptDetail, effectiveDate); if (receiptMaster.IsReceiveScanHu) //按条码收货 { receiptDetail.ReceiptDetailInputs = (from hu in huList select new ReceiptDetailInput { ReceiveQty = hu.Qty, //转为订单单位 QualityType = receiptDetail.QualityType, HuId = hu.HuId, LotNo = hu.LotNo, IsCreatePlanBill = false, IsConsignment = false, PlanBill = null, ActingBill = null, IsFreeze = false, IsATP = true, OccupyType = com.Sconit.CodeMaster.OccupyType.None, OccupyReferenceNo = null }).ToList(); } } } #endregion #region 循环收货 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { receiptDetail.CurrentPartyFrom = receiptMaster.PartyFrom; //为了记录库存事务 receiptDetail.CurrentPartyFromName = receiptMaster.PartyFromName; receiptDetail.CurrentPartyTo = receiptMaster.PartyTo; receiptDetail.CurrentPartyToName = receiptMaster.PartyToName; receiptDetail.CurrentExternalReceiptNo = receiptMaster.ExternalReceiptNo; receiptDetail.CurrentIsReceiveScanHu = receiptMaster.IsReceiveScanHu || isKit; if (receiptDetail.ReceivedQty != 0) { //inputIpDetail.CurrentIsATP = inputIpDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified; //inputIpDetail.CurrentIsFreeze = false; //默认只出库未冻结库存 IList<InventoryTransaction> inventoryTransactionList = this.locationDetailMgr.InventoryIn(receiptDetail, effectiveDate); if (inventoryTransactionList != null && inventoryTransactionList.Count > 0) { IList<ReceiptLocationDetail> receiptLocationDetailList = (from trans in inventoryTransactionList group trans by new { HuId = trans.HuId, LotNo = trans.LotNo, IsCreatePlanBill = trans.IsCreatePlanBill, IsConsignment = trans.IsConsignment, PlanBill = trans.PlanBill, ActingBill = trans.ActingBill, IsFreeze = trans.IsFreeze, IsATP = trans.IsATP, WMSSeq = trans.WMSRecSeq, } into g select new ReceiptLocationDetail { Item = receiptDetail.Item, HuId = g.Key.HuId, LotNo = g.Key.LotNo, IsCreatePlanBill = g.Key.IsCreatePlanBill, IsConsignment = g.Key.IsConsignment, PlanBill = g.Key.PlanBill, ActingBill = g.Key.ActingBill, QualityType = receiptDetail.QualityType, IsFreeze = g.Key.IsFreeze, IsATP = g.Key.IsATP, OccupyType = receiptDetail.CurrentOccupyType, OccupyReferenceNo = receiptDetail.CurrentOccupyReferenceNo, Qty = g.Sum(t => t.Qty), WMSSeq = g.Key.WMSSeq }).ToList(); receiptDetail.AddReceiptLocationDetail(receiptLocationDetailList); } } } #endregion #region 保存发货单库存明细 foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { //if (receiptDetail.ReceiptLocationDetails == null || receiptDetail.ReceiptLocationDetails.Count == 0) //{ // throw new TechnicalException("ReceiptLocationDetails is empty."); //} if (receiptDetail.ReceiptLocationDetails != null && receiptDetail.ReceiptLocationDetails.Count > 0) { foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails) { receiptLocationDetail.ReceiptNo = receiptMaster.ReceiptNo; receiptLocationDetail.ReceiptDetailId = receiptDetail.Id; receiptLocationDetail.OrderType = receiptDetail.OrderType; receiptLocationDetail.OrderDetailId = receiptDetail.OrderDetailId; genericMgr.Create(receiptLocationDetail); } } } #endregion #region 检验 InspectMaster inspectMaster = inspectMgr.TransferReceipt2Inspect(receiptMaster); if (inspectMaster != null && inspectMaster.InspectDetails != null && inspectMaster.InspectDetails.Count > 0) { inspectMgr.CreateInspectMaster(inspectMaster, effectiveDate); } #endregion this.AsyncSendPrintData(receiptMaster); }
public void AsyncSendPrintData(ReceiptMaster receiptMaster) { AsyncSend asyncSend = new AsyncSend(this.SendPrintData); asyncSend.BeginInvoke(receiptMaster, null, null); }
public void SendPrintData(ReceiptMaster receiptMaster) { try { PrintReceiptMaster printReceiptMaster = Mapper.Map<ReceiptMaster, PrintReceiptMaster>(receiptMaster); proxy = pubSubMgr.CreateProxy(); proxy.Publish(printReceiptMaster); } catch (Exception ex) { pubSubLog.Error("Send data to print sevrer error:", ex); } }
public void CancelVarietyOfReceipt(ReceiptMaster receiptMaster) { this.CancelReceipt(receiptMaster); genericMgr.FlushSession(); if (receiptMaster.OrderType == Sconit.CodeMaster.OrderType.Distribution) { ipMgr.CancelIp(receiptMaster.IpNo); } else if (receiptMaster.PartyFrom.ToUpper() == "LOC" || receiptMaster.PartyFrom.ToUpper() == "SQC") { IList<ReceiptDetail> recList = this.genericMgr.FindAll<ReceiptDetail>(" select r from ReceiptDetail as r where r.ReceiptNo=? ", receiptMaster.ReceiptNo); if (recList != null && recList.Count > 0 && !string.IsNullOrWhiteSpace(recList.First().IpNo)) { ipMgr.CancelIp(receiptMaster.IpNo); } } }
public ReceiptMaster ReceiveUrgentExOrder(FlowDetail flowDetail) { var flowMaster = flowDetail.CurrentFlowMaster; if(flowMaster == null) { flowMaster = genericMgr.FindById<FlowMaster>(flowDetail.Flow); } var orderMaster = orderMgr.TransferFlow2Order(flowMaster, false); OrderDetail orderDetail = new OrderDetail(); var item = this.itemMgr.GetCacheItem(flowDetail.Item); orderDetail.Item = item.Code; orderDetail.UnitCount = flowDetail.UnitCount; orderDetail.Uom = flowDetail.Uom; orderDetail.ItemDescription = item.Description; orderDetail.BaseUom = item.Uom; orderDetail.Sequence = 10; orderDetail.MinUnitCount = item.UnitCount; orderDetail.OrderedQty = (decimal)flowDetail.CurrentQty; orderDetail.IsInspect = flowDetail.IsFreeze; orderDetail.ReferenceItemCode = item.ReferenceCode; orderDetail.UnitCountDescription = flowDetail.UnitCountDescription; orderDetail.ContainerDescription = flowDetail.ContainerDescription; orderDetail.Remark = flowDetail.Remark; if(item.ItemOption == com.Sconit.CodeMaster.ItemOption.NeedAging) { orderDetail.OldOption = Sconit.CodeMaster.HuOption.UnAging; } else { orderDetail.OldOption = Sconit.CodeMaster.HuOption.NoNeed; } var productType = this.genericMgr.FindById<ProductType>(flowDetail.ProductType); orderDetail.ScheduleType = productType.SubType; orderMaster.AddOrderDetail(orderDetail); if(flowMaster.Code == "EXV") { orderMaster.ProductLineFacility = "EXV"; } orderMaster.IsAutoRelease = true; orderMaster.IsAutoStart = true; orderMaster.IsAutoReceive = false; orderMaster.IsOpenOrder = false; orderMaster.Shift = flowDetail.Shift; DateTime startTime = DateTime.Now; DateTime windowTime = DateTime.Now; workingCalendarMgr.GetStartTimeAndWindowTime(orderMaster.Shift, DateTime.Now.AddHours(-7.75).Date, out startTime, out windowTime); orderMaster.StartTime = startTime; orderMaster.WindowTime = windowTime; orderMaster.Priority = CodeMaster.OrderPriority.Urgent; orderMaster.CreateHuOption = Sconit.CodeMaster.CreateHuOption.Receive; orderMaster.EffectiveDate = startTime.Date; var bomDetail = this.bomMgr.GetOnlyNextLevelBomDetail(flowDetail.Item, orderMaster.StartTime) .Where(p => p.Item.StartsWith("29")).FirstOrDefault(); if(bomDetail != null) { item = itemMgr.GetCacheItem(bomDetail.Item); orderMaster.ReferenceOrderNo = bomDetail.Item; } orderMaster.SubType = CodeMaster.OrderSubType.Normal; orderMgr.CreateOrder(orderMaster); var receiptMaster = new ReceiptMaster(); if(flowDetail.CurrentQty <= 0) { Hu hu = new Hu(); hu.Qty = 0; hu.Item = item.Code; hu.ItemDescription = item.Description; hu.BaseUom = item.Uom; hu.Uom = item.Uom; hu.UnitCount = item.UnitCount; hu.UnitQty = 1; hu.Qty = 0; hu.HuTemplate = "BarCodeEXScrap.xls"; hu.ManufactureDate = DateTime.Now.AddHours(-7.75).Date; hu.LotNo = Utility.LotNoHelper.GenerateLotNo(hu.ManufactureDate); hu.PrintCount = 0; hu.ConcessionCount = 0; hu.ReferenceItemCode = item.ReferenceCode; hu.LocationTo = flowDetail.LocationTo; if(string.IsNullOrWhiteSpace(hu.LocationTo)) { hu.LocationTo = flowMaster.LocationTo; } hu.Shift = flowDetail.Shift; hu.Flow = flowDetail.Flow; hu.OrderNo = orderMaster.OrderNo; receiptMaster.HuList = new List<Hu>(); receiptMaster.HuList.Add(hu); receiptMaster.CreateHuOption = orderMaster.CreateHuOption; receiptMaster.HuTemplate = orderMaster.HuTemplate; orderMgr.ManualCloseOrder(orderMaster); } else { OrderDetailInput orderDetailInput = new OrderDetailInput(); orderDetailInput.ReceiveQty = (decimal)flowDetail.CurrentQty; orderMaster.OrderDetails[0].AddOrderDetailInput(orderDetailInput); receiptMaster = orderMgr.ReceiveOrder(orderMaster.OrderDetails); receiptMaster.HuList = receiptMaster.ReceiptDetails.SelectMany(p => p.ReceiptLocationDetails.Select(q => q.HuId)) .Select(p => { return this.genericMgr.FindById<Hu>(p); }).ToList(); foreach(var hu in receiptMaster.HuList) { hu.ItemVersion = flowDetail.ProductType; this.genericMgr.Update(hu); } } return receiptMaster; }
public ReceiptMaster ReceiveExOrder(MrpExShiftPlan mrpExShiftPlan) { OrderMaster orderMaster = new OrderMaster(); if(!string.IsNullOrWhiteSpace(mrpExShiftPlan.OrderNo)) { try { orderMaster = orderMgr.LoadOrderMaster(mrpExShiftPlan.OrderNo, true, false, true); if(orderMaster.Status != CodeMaster.OrderStatus.InProcess) { orderMaster = CreateExOrder(mrpExShiftPlan); } } catch(Exception) { orderMaster = CreateExOrder(mrpExShiftPlan); } } else { orderMaster = CreateExOrder(mrpExShiftPlan); } var receiptMaster = new ReceiptMaster(); if(mrpExShiftPlan.CurrentQty <= 0)//只是打印废品条码 { //打印废品条码 var item = new Item(); if(!string.IsNullOrWhiteSpace(mrpExShiftPlan.Section) && mrpExShiftPlan.Section != "299999") { item = itemMgr.GetCacheItem(mrpExShiftPlan.Section); } else { this.itemMgr.GetCacheItem(mrpExShiftPlan.Item); } Hu hu = new Hu(); hu.Qty = 0; hu.Item = item.Code; hu.ItemDescription = item.Description; hu.BaseUom = item.Uom; hu.Uom = item.Uom; hu.UnitCount = item.UnitCount; hu.UnitQty = 1; hu.Qty = 0; hu.HuTemplate = "BarCodeEXScrap.xls"; hu.ManufactureDate = mrpExShiftPlan.PlanDate; hu.LotNo = Utility.LotNoHelper.GenerateLotNo(hu.ManufactureDate); hu.PrintCount = 0; hu.ConcessionCount = 0; hu.ReferenceItemCode = item.ReferenceCode; hu.LocationTo = mrpExShiftPlan.LocationTo; hu.OrderNo = orderMaster.OrderNo; hu.Shift = mrpExShiftPlan.Shift; hu.Flow = mrpExShiftPlan.ProductLine; hu.ManufactureParty = orderMaster.PartyFrom; //hu.HuId = Guid.NewGuid().ToString(); //hu.IsOdd = hu.Qty < hu.UnitCount; //hu.IsChangeUnitCount = false; //hu.UnitCountDescription = null; //hu.SupplierLotNo = null; //hu.ContainerDesc = null; receiptMaster.HuList = new List<Hu>(); receiptMaster.HuList.Add(hu); receiptMaster.CreateHuOption = orderMaster.CreateHuOption; receiptMaster.HuTemplate = orderMaster.HuTemplate; } else { OrderDetailInput orderDetailInput = new OrderDetailInput(); orderDetailInput.ReceiveQty = (decimal)mrpExShiftPlan.CurrentQty; orderMaster.OrderDetails[0].AddOrderDetailInput(orderDetailInput); orderMaster.OrderDetails[0].IsInspect = mrpExShiftPlan.IsFreeze; orderMaster.IsInspect = true; receiptMaster = orderMgr.ReceiveOrder(orderMaster.OrderDetails); mrpExShiftPlan.ReceivedQty += mrpExShiftPlan.CurrentQty; this.genericMgr.Update(mrpExShiftPlan); receiptMaster.HuList = receiptMaster.ReceiptDetails.SelectMany(p => p.ReceiptLocationDetails.Select(q => q.HuId)) .Select(p => { return this.genericMgr.FindById<Hu>(p); }).ToList(); foreach(var hu in receiptMaster.HuList) { hu.ItemVersion = mrpExShiftPlan.ProductType; this.genericMgr.Update(hu); } } return receiptMaster; }
public void CreateReceipt(ReceiptMaster receiptMaster) { CreateReceipt(receiptMaster, DateTime.Now); }
public void CreateReceipt(ReceiptMaster receiptMaster, DateTime effectiveDate) { CreateReceipt(receiptMaster, false, effectiveDate); }
public static bool HasPermission(ReceiptMaster receiptMaster, bool isSupplier = false) { return HasPermission(receiptMaster.OrderType, receiptMaster.IsCheckPartyFromAuthority, receiptMaster.IsCheckPartyToAuthority, receiptMaster.PartyFrom, receiptMaster.PartyTo, isSupplier, receiptMaster.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return ? true : false, false); }
public void CancelReceipt(ReceiptMaster receiptMaster) { CancelReceipt(receiptMaster, DateTime.Now); }
private List<BackflushInput> ReceiptMaster2BackflushInputList(ReceiptMaster receiptMaster) { List<BackflushInput> backflushInputList = new List<BackflushInput>(); if (receiptMaster.CurrentFlowMaster == null && !string.IsNullOrWhiteSpace(receiptMaster.Flow)) { receiptMaster.CurrentFlowMaster = this.genericMgr.FindById<FlowMaster>(receiptMaster.Flow); } IList<ReceiptDetail> receiptDetailList = receiptMaster.ReceiptDetails; var allOrderBackFlushDetail = this.genericMgr.FindAllIn<OrderBackflushDetail>( "from OrderBackflushDetail where ReceiptDetailId in(?", receiptDetailList.Select(p => (object)p.Id)); var allOrderBackFlushDetailDic = allOrderBackFlushDetail.GroupBy(p => p.ReceiptDetailId, (k, g) => new { k, g }) .ToDictionary(d => d.k, d => d.g.ToList()); var allOrderBomDetailDic = this.genericMgr.FindAllIn<OrderBomDetail> (" from OrderBomDetail where OrderDetailId in(? ", receiptDetailList.Select(p => (object)p.OrderDetailId)) .GroupBy(p => p.OrderDetailId, (k, g) => new { k, g }).ToDictionary(d => d.k, d => d.g.ToList()); //委外退货要根据Bom来计算消耗用量 if (!(receiptMaster.OrderType == Sconit.CodeMaster.OrderType.SubContract && receiptMaster.OrderSubType == Sconit.CodeMaster.OrderSubType.Return)) { foreach (ReceiptDetail receiptDetail in receiptDetailList) { var orderBackFlushDetailList = allOrderBackFlushDetailDic.ValueOrDefault(receiptDetail.Id); if (orderBackFlushDetailList != null) { var backflushInputs = from bfd in orderBackFlushDetailList where bfd.BackflushedQty != 0 select new BackflushInput { OrderNo = receiptDetail.OrderNo, OrderType = receiptDetail.OrderType, OrderSubType = receiptDetail.OrderSubType, OrderDetailSequence = bfd.OrderDetailSequence, OrderDetailId = bfd.OrderDetailId, OrderBomDetail = new OrderBomDetail() { Id = bfd.OrderBomDetailId.Value, Sequence = bfd.OrderBomDetailSequence.Value, ManufactureParty = bfd.ManufactureParty, Location = bfd.LocationFrom, Bom = bfd.Bom, Item = bfd.Item, ReferenceItemCode = bfd.ReferenceItemCode, ItemDescription = bfd.ItemDescription, Uom = bfd.Uom, BaseUom = bfd.BaseUom, Operation = bfd.Operation.HasValue ? bfd.Operation.Value : 0, OpReference = bfd.OpReference, //OrderedQty = bfd.OrderedQty, UnitQty = bfd.UnitQty, //BomUnitQty = bfd.BomUnitQty, IsPrint = false, BackFlushMethod = CodeMaster.BackFlushMethod.GoodsReceive, FeedMethod = CodeMaster.FeedMethod.None, //IsScanHu = bfd.IsScanHu, IsAutoFeed = false, //EstimateConsumeTime = bfd.EstimateConsumeTime, ReserveNo = bfd.ReserveNo, ReserveLine = bfd.ReserveLine, //ZOPWZ = bfd.ZOPWZ, //ZOPID = bfd.ZOPID, //ZOPDS = bfd.ZOPDS, ICHARG = bfd.ICHARG, BWART = bfd.BWART, }, ReceiptNo = receiptDetail.ReceiptNo, ReceiptDetailId = receiptDetail.Id, ReceiptDetailSequence = receiptDetail.Sequence, //TraceCode = receiptDetail.TraceCode, Item = bfd.Item, ItemDescription = bfd.ItemDescription, ReferenceItemCode = bfd.ReferenceItemCode, Uom = bfd.Uom, BaseUom = bfd.BaseUom, Qty = -(bfd.BackflushedQty + bfd.BackflushedRejectQty), UnitQty = bfd.UnitQty, Location = string.IsNullOrWhiteSpace(bfd.LocationFrom) ? receiptDetail.LocationFrom : bfd.LocationFrom, CurrentProductLine = receiptMaster.CurrentFlowMaster, ProductLine = receiptMaster.CurrentFlowMaster.Code, FGItem = receiptDetail.Item, FGQualityType = receiptDetail.QualityType, Operation = bfd.Operation, OpReference = bfd.OpReference, //HuId = receiptDetail.ReceiptDetailInputs.First().HuId }; backflushInputList.AddRange(backflushInputs); } } } else { foreach (ReceiptDetail receiptDetail in receiptDetailList) { var orderBomDetailList = allOrderBomDetailDic.ValueOrDefault(receiptDetail.OrderDetailId.Value); if (orderBomDetailList != null) { var backflushInputs = from bom in orderBomDetailList where bom.OrderedQty != 0 select new BackflushInput { OrderNo = receiptDetail.OrderNo, OrderType = receiptDetail.OrderType, OrderSubType = receiptDetail.OrderSubType, OrderDetailSequence = bom.OrderDetailSequence, OrderDetailId = bom.OrderDetailId, OrderBomDetail = bom, ReceiptNo = receiptDetail.ReceiptNo, ReceiptDetailId = receiptDetail.Id, ReceiptDetailSequence = receiptDetail.Sequence, //TraceCode = receiptDetail.TraceCode, Item = bom.Item, ItemDescription = bom.ItemDescription, ReferenceItemCode = bom.ReferenceItemCode, Uom = bom.Uom, BaseUom = bom.BaseUom, Qty = bom.BomUnitQty * (receiptDetail.ReceivedQty + receiptDetail.ScrapQty), UnitQty = bom.UnitQty, Location = string.IsNullOrWhiteSpace(bom.Location) ? receiptDetail.LocationFrom : bom.Location, CurrentProductLine = receiptMaster.CurrentFlowMaster, ProductLine = receiptMaster.CurrentFlowMaster.Code, FGItem = receiptDetail.Item, FGQualityType = receiptDetail.QualityType, Operation = bom.Operation, OpReference = bom.OpReference, //HuId = receiptDetail.ReceiptDetailInputs.First().HuId }; backflushInputList.AddRange(backflushInputs); } } } //var allOrderBomDetailDic = this.genericMgr.FindAllIn<OrderBomDetail> // (" from OrderBomDetail where OrderDetailId in(? ", receiptDetailList.Select(p => (object)p.OrderDetailId)) // .GroupBy(p => p.OrderDetailId, (k, g) => new { k, g }).ToDictionary(d => d.k, d => d.g.ToList()); //foreach (ReceiptDetail receiptDetail in receiptDetailList) //{ // var orderBomDetailList = allOrderBomDetailDic.ValueOrDefault(receiptDetail.OrderDetailId.Value); // if (orderBomDetailList != null) // { // var backflushInputs = from bom in orderBomDetailList // where bom.OrderedQty != 0 // select new BackflushInput // { // OrderNo = receiptDetail.OrderNo, // OrderType = receiptDetail.OrderType, // OrderSubType = receiptDetail.OrderSubType, // OrderDetailSequence = bom.OrderDetailSequence, // OrderDetailId = bom.OrderDetailId, // OrderBomDetail = bom, // ReceiptNo = receiptDetail.ReceiptNo, // ReceiptDetailId = receiptDetail.Id, // ReceiptDetailSequence = receiptDetail.Sequence, // //TraceCode = receiptDetail.TraceCode, // Item = bom.Item, // ItemDescription = bom.ItemDescription, // ReferenceItemCode = bom.ReferenceItemCode, // Uom = bom.Uom, // BaseUom = bom.BaseUom, // Qty = bom.BomUnitQty * (receiptDetail.ReceivedQty + receiptDetail.ScrapQty), // UnitQty = bom.UnitQty, // Location = string.IsNullOrWhiteSpace(bom.Location) ? receiptDetail.LocationFrom : bom.Location, // CurrentProductLine = receiptMaster.CurrentFlowMaster, // ProductLine = receiptMaster.CurrentFlowMaster.Code, // FGItem = receiptDetail.Item, // FGQualityType = receiptDetail.QualityType, // Operation = bom.Operation, // OpReference = bom.OpReference, // //HuId = receiptDetail.ReceiptDetailInputs.First().HuId // }; // backflushInputList.AddRange(backflushInputs); // } //} return backflushInputList; }
public InspectMaster TransferReceipt2Inspect(ReceiptMaster receiptMaster) { List<ReceiptLocationDetail> inspectReceiptLocationDetailList = new List<ReceiptLocationDetail>(); IList<Region> createInspectRegonList = this.genericMgr.FindAll<Region>("from Region r where r.IsCreateInspect=?",true); if (createInspectRegonList != null && createInspectRegonList.Count > 0) { foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { int count = (from r in createInspectRegonList where r.Code == receiptDetail.CurrentPartyTo select r).Count(); if (receiptDetail.IsInspect && count > 0) { inspectReceiptLocationDetailList.AddRange(receiptDetail.ReceiptLocationDetails); } } //1月1日上线除冲焊和涂装外,其他区域收货全都不需要报验 //foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) //{ // string[] regionArray = new string[] { "CB1", "CP1", "HB1", "HP1", "TB1", "TP1", "TB2", "TP2" }; // int count = (from r in regionArray // where r.ToUpper() == receiptDetail.CurrentPartyTo.ToUpper() // select r).Count(); // if (receiptDetail.IsInspect && count > 0) // { // inspectReceiptLocationDetailList.AddRange(receiptDetail.ReceiptLocationDetails); // } //} //根据region表中的IsCreateInspect来确定是否创建报验单 if (inspectReceiptLocationDetailList != null && inspectReceiptLocationDetailList.Count > 0) { #region 报验单头 InspectMaster inspectMaster = new InspectMaster(); inspectMaster.IpNo = receiptMaster.IpNo; inspectMaster.ReceiptNo = receiptMaster.ReceiptNo; inspectMaster.Region = receiptMaster.PartyTo; inspectMaster.Status = com.Sconit.CodeMaster.InspectStatus.Submit; //inspectMaster.Type = receiptMaster.CreateHuOption == CodeMaster.CreateHuOption.Receive || receiptMaster.IsReceiveScanHu ? com.Sconit.CodeMaster.InspectType.Barcode : com.Sconit.CodeMaster.InspectType.Quantity; inspectMaster.Type = inspectReceiptLocationDetailList.Where(locDet => !string.IsNullOrWhiteSpace(locDet.HuId)).Count() > 0 ? com.Sconit.CodeMaster.InspectType.Barcode : com.Sconit.CodeMaster.InspectType.Quantity; inspectMaster.IsATP = true; inspectMaster.WMSNo = receiptMaster.WMSNo; #endregion #region 根据收货明细+条码+WMS行号汇总 var groupedInspectReceiptLocationDetailList = from locDet in inspectReceiptLocationDetailList group locDet by new { ReceiptDetailId = locDet.ReceiptDetailId, HuId = locDet.HuId, LotNo = locDet.LotNo, WMSSeq = locDet.WMSSeq, IsConsignment = locDet.IsConsignment, PlanBill = locDet.PlanBill, } into gj select new { ReceiptDetailId = gj.Key.ReceiptDetailId, HuId = gj.Key.HuId, LotNo = gj.Key.LotNo, WMSSeq = gj.Key.WMSSeq, IsConsignment = gj.Key.IsConsignment, PlanBill = gj.Key.PlanBill, ReceiveQty = gj.Sum(locDet => locDet.Qty), //基本单位 }; #endregion #region 报验单明细 foreach (var groupedInspectReceiptLocationDetail in groupedInspectReceiptLocationDetailList) { ReceiptDetail receiptDetail = receiptMaster.ReceiptDetails.Where(det => det.Id == groupedInspectReceiptLocationDetail.ReceiptDetailId).Single(); InspectDetail inspectDetail = new InspectDetail(); inspectDetail.Item = receiptDetail.Item; inspectDetail.ItemDescription = receiptDetail.ItemDescription; inspectDetail.ReferenceItemCode = receiptDetail.ReferenceItemCode; inspectDetail.BaseUom = receiptDetail.BaseUom; inspectDetail.HuId = groupedInspectReceiptLocationDetail.HuId; inspectDetail.LotNo = groupedInspectReceiptLocationDetail.LotNo; inspectDetail.Uom = receiptDetail.Uom; inspectDetail.UnitCount = receiptDetail.UnitCount; inspectDetail.UnitQty = receiptDetail.UnitQty; inspectDetail.LocationFrom = receiptDetail.LocationTo; inspectDetail.CurrentLocation = receiptDetail.LocationTo; inspectDetail.InspectQty = groupedInspectReceiptLocationDetail.ReceiveQty / inspectDetail.UnitQty; inspectDetail.IsJudge = false; inspectDetail.IpDetailSequence = receiptDetail.IpDetailSequence; inspectDetail.ReceiptDetailSequence = receiptDetail.Sequence; inspectDetail.WMSSeq = groupedInspectReceiptLocationDetail.WMSSeq; inspectDetail.IsConsignment = groupedInspectReceiptLocationDetail.IsConsignment; inspectDetail.PlanBill = groupedInspectReceiptLocationDetail.PlanBill; inspectMaster.AddInspectDetail(inspectDetail); } #endregion return inspectMaster; } else { return null; } } else { return null; } }
private IList<ReceiptDetail> TryLoadReceiptDetails(ReceiptMaster receiptMaster) { if (receiptMaster.ReceiptDetails == null) { string hql = "from ReceiptDetail where ReceiptNo = ?"; receiptMaster.ReceiptDetails = this.genericMgr.FindAll<ReceiptDetail>(hql, receiptMaster.ReceiptNo); } return receiptMaster.ReceiptDetails; }
private void BackflushVan(ProductLineMap productLineMap, IList<OrderDetail> nonZeroOrderDetailList, ReceiptMaster receiptMaster, OrderMaster orderMaster) { if (productLineMap.ProductLine == orderMaster.Flow) { #region 总装,回冲总装、驾驶室、底盘的物料 #region 回冲驾驶室和底盘 IList<string> subOrderMasterList = this.genericMgr.FindAll<string>("select OrderNo from OrderMaster where Type = ? and Flow in (?,?)", new object[] { CodeMaster.OrderType.Production, productLineMap.CabFlow, productLineMap.ChassisFlow, CodeMaster.OrderStatus.Close }); if (subOrderMasterList != null && subOrderMasterList.Count > 0) { string selectOrderDetHql = string.Empty; string selectReceiptDetHql = string.Empty; IList<object> parms = new List<object>(); foreach (string subOrderNo in subOrderMasterList) { if (selectOrderDetHql == string.Empty) { selectOrderDetHql = "from OrderDetail where OrderNo in (?"; selectReceiptDetHql = "from ReceiptDetail where OrderNo in (?"; } else { selectOrderDetHql += ",?"; selectReceiptDetHql += ",?"; } parms.Add(subOrderNo); } selectOrderDetHql += ")"; selectReceiptDetHql += ")"; IList<OrderDetail> subOrderDetailList = this.genericMgr.FindAll<OrderDetail>(selectOrderDetHql, parms.ToArray()); IList<ReceiptDetail> subReceiptDetailList = this.genericMgr.FindAll<ReceiptDetail>(selectReceiptDetHql, parms.ToArray()); foreach (OrderDetail subOrderDetail in subOrderDetailList) { OrderDetailInput subOrderDetailInput = new OrderDetailInput(); subOrderDetailInput.ReceiveQty = subOrderDetail.OrderedQty; subOrderDetail.AddOrderDetailInput(subOrderDetailInput); subOrderDetailInput.ReceiptDetails = subReceiptDetailList.Where(r => r.OrderDetailId == subOrderDetail.Id).ToList(); IList<OrderDetail> backFlushOrderDetailList = new List<OrderDetail>(); backFlushOrderDetailList.Add(subOrderDetail); this.productionLineMgr.BackflushProductOrder(backFlushOrderDetailList, orderMaster, DateTime.Now); } } #endregion #region 回冲总装 foreach (OrderDetail orderDetail in nonZeroOrderDetailList) { OrderDetailInput orderDetailInput = orderDetail.OrderDetailInputs[0]; orderDetailInput.ReceiptDetails = receiptMaster.ReceiptDetails.Where(r => r.OrderDetailId == orderDetail.Id).ToList(); } this.productionLineMgr.BackflushProductOrder(nonZeroOrderDetailList, orderMaster, DateTime.Now); #endregion #endregion } else { #region 驾驶室、底盘,不回冲物料 #endregion } }
public InspectMaster TransferReceipt2Inspect(ReceiptMaster receiptMaster) { List<ReceiptLocationDetail> inspectReceiptLocationDetailList = new List<ReceiptLocationDetail>(); foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails) { if (receiptDetail.IsInspect) { inspectReceiptLocationDetailList.AddRange(receiptDetail.ReceiptLocationDetails); } } if (inspectReceiptLocationDetailList != null && inspectReceiptLocationDetailList.Count > 0) { #region 报验单头 InspectMaster inspectMaster = new InspectMaster(); inspectMaster.IpNo = receiptMaster.IpNo; inspectMaster.ReceiptNo = receiptMaster.ReceiptNo; inspectMaster.Region = receiptMaster.PartyTo; inspectMaster.Status = com.Sconit.CodeMaster.InspectStatus.Submit; //inspectMaster.Type = receiptMaster.CreateHuOption == CodeMaster.CreateHuOption.Receive || receiptMaster.IsReceiveScanHu ? com.Sconit.CodeMaster.InspectType.Barcode : com.Sconit.CodeMaster.InspectType.Quantity; inspectMaster.Type = inspectReceiptLocationDetailList.Where(locDet => !string.IsNullOrWhiteSpace(locDet.HuId)).Count() > 0 ? com.Sconit.CodeMaster.InspectType.Barcode : com.Sconit.CodeMaster.InspectType.Quantity; inspectMaster.IsATP = true; inspectMaster.WMSNo = receiptMaster.WMSNo; inspectMaster.PartyFrom = receiptMaster.PartyFrom; inspectMaster.PartyFromName = receiptMaster.PartyFromName; #endregion #region 根据收货明细+条码+WMS行号汇总 var groupedInspectReceiptLocationDetailList = from locDet in inspectReceiptLocationDetailList group locDet by new { ReceiptDetailId = locDet.ReceiptDetailId, HuId = locDet.HuId, LotNo = locDet.LotNo, WMSSeq = locDet.WMSSeq, IsConsignment = locDet.IsConsignment, PlanBill = locDet.PlanBill, } into gj select new { ReceiptDetailId = gj.Key.ReceiptDetailId, HuId = gj.Key.HuId, LotNo = gj.Key.LotNo, WMSSeq = gj.Key.WMSSeq, IsConsignment = gj.Key.IsConsignment, PlanBill = gj.Key.PlanBill, ReceiveQty = gj.Sum(locDet => locDet.Qty), //基本单位 }; #endregion #region 报验单明细 foreach (var groupedInspectReceiptLocationDetail in groupedInspectReceiptLocationDetailList) { ReceiptDetail receiptDetail = receiptMaster.ReceiptDetails.Where(det => det.Id == groupedInspectReceiptLocationDetail.ReceiptDetailId).Single(); InspectDetail inspectDetail = new InspectDetail(); inspectDetail.Item = receiptDetail.Item; inspectDetail.ItemDescription = receiptDetail.ItemDescription; inspectDetail.ReferenceItemCode = receiptDetail.ReferenceItemCode; inspectDetail.BaseUom = receiptDetail.BaseUom; inspectDetail.HuId = groupedInspectReceiptLocationDetail.HuId; inspectDetail.LotNo = groupedInspectReceiptLocationDetail.LotNo; inspectDetail.Uom = receiptDetail.Uom; inspectDetail.UnitCount = receiptDetail.UnitCount; inspectDetail.UnitQty = receiptDetail.UnitQty; inspectDetail.LocationFrom = receiptDetail.LocationTo; inspectDetail.CurrentLocation = receiptDetail.LocationTo; inspectDetail.InspectQty = groupedInspectReceiptLocationDetail.ReceiveQty / inspectDetail.UnitQty; inspectDetail.IsJudge = false; inspectDetail.IpDetailSequence = receiptDetail.IpDetailSequence; inspectDetail.ReceiptDetailSequence = receiptDetail.Sequence; inspectDetail.WMSSeq = groupedInspectReceiptLocationDetail.WMSSeq; inspectDetail.IsConsignment = groupedInspectReceiptLocationDetail.IsConsignment; inspectDetail.PlanBill = groupedInspectReceiptLocationDetail.PlanBill; inspectMaster.AddInspectDetail(inspectDetail); } #endregion return inspectMaster; } else { return null; } }