private void RecordBillTransaction(BillDetail billDetail, DateTime effectiveDate, bool isCancel) { DateTime dateTimeNow = DateTime.Now; BillTransaction billTransaction = new BillTransaction(); billTransaction.ActingBill = billDetail.ActingBillId; billTransaction.BillDetail = billDetail.Id; billTransaction.Currency = billDetail.Currency; billTransaction.EffectiveDate = effectiveDate; billTransaction.ExternalIpNo = billDetail.ExternalIpNo; billTransaction.ExternalReceiptNo = billDetail.ExternalReceiptNo; billTransaction.IpNo = billDetail.IpNo; billTransaction.IsIncludeTax = billDetail.IsIncludeTax; billTransaction.IsProvisionalEstimate = billDetail.IsProvisionalEstimate; billTransaction.Item = billDetail.Item; billTransaction.ItemDescription = billDetail.ItemDescription; billTransaction.LocationFrom = billDetail.LocationFrom; billTransaction.OrderNo = billDetail.OrderNo; billTransaction.Party = billDetail.Party; billTransaction.PartyName = billDetail.PartyName; billTransaction.PriceList = billDetail.PriceList; billTransaction.ReceiptNo = billDetail.ReceiptNo; billTransaction.UnitCount = billDetail.UnitCount; billTransaction.UnitPrice = billDetail.UnitPrice; billTransaction.Uom = billDetail.Uom; billTransaction.UnitQty = billDetail.UnitQty; if (billDetail.Type == CodeMaster.BillType.Procurement) { if (isCancel) { //采购开票冲销负数 billTransaction.TransactionType = CodeMaster.BillTransactionType.POBilledVoid; billTransaction.BillQty = -billDetail.Qty; billTransaction.BillAmount = -billDetail.Amount; } else { //采购开票正数 billTransaction.TransactionType = CodeMaster.BillTransactionType.POBilled; billTransaction.BillQty = billDetail.Qty; billTransaction.BillAmount = billDetail.Amount; } } else { if (isCancel) { //销售开票冲销负数 billTransaction.TransactionType = CodeMaster.BillTransactionType.SOBilledVoid; billTransaction.BillQty = -billDetail.Qty; billTransaction.BillAmount = -billDetail.Amount; } else { //销售开票正数 billTransaction.TransactionType = CodeMaster.BillTransactionType.SOBilled; billTransaction.BillQty = billDetail.Qty; billTransaction.BillAmount = billDetail.Amount; } } User user = SecurityContextHolder.Get(); billTransaction.CreateUserId = user.Id; billTransaction.CreateUserName = user.FullName; billTransaction.CreateDate = DateTime.Now; this.genericMgr.Create(billTransaction); }
private BillTransaction RecordBillTransaction(PlanBill planBill, ActingBill actingBill, DateTime effectiveDate, bool isVoid) { #region 记BillTransaction BillTransaction billTransaction = new BillTransaction(); billTransaction.OrderNo = planBill.OrderNo; billTransaction.IpNo = planBill.IpNo; billTransaction.ExternalIpNo = planBill.ExternalIpNo; billTransaction.ReceiptNo = planBill.ReceiptNo; billTransaction.ExternalReceiptNo = planBill.ExternalReceiptNo; billTransaction.IsIncludeTax = planBill.IsIncludeTax; billTransaction.Item = planBill.Item; billTransaction.ItemDescription = planBill.ItemDescription; billTransaction.Uom = planBill.Uom; billTransaction.UnitCount = planBill.UnitCount; billTransaction.HuId = planBill.CurrentHuId; billTransaction.TransactionType = planBill.Type == com.Sconit.CodeMaster.BillType.Procurement ? (isVoid ? com.Sconit.CodeMaster.BillTransactionType.POSettleVoid : com.Sconit.CodeMaster.BillTransactionType.POSettle) : (isVoid ? com.Sconit.CodeMaster.BillTransactionType.SOSettleVoid : com.Sconit.CodeMaster.BillTransactionType.SOSettle); billTransaction.BillAddress = planBill.BillAddress; billTransaction.BillAddressDescription = planBill.BillAddressDescription; billTransaction.Party = planBill.Party; billTransaction.PartyName = planBill.PartyName; billTransaction.PriceList = planBill.PriceList; billTransaction.Currency = planBill.Currency; billTransaction.UnitPrice = planBill.UnitPrice; billTransaction.IsProvisionalEstimate = planBill.IsProvisionalEstimate; billTransaction.Tax = planBill.Tax; #region 记录数量 decimal qty = isVoid ? planBill.CurrentVoidQty : planBill.CurrentActingQty; billTransaction.BillQty = (isVoid ? -1 : 1) //冲销为负数 * (planBill.Type == com.Sconit.CodeMaster.BillType.Procurement ? -1 * qty : qty); //采购付款为负数 //billTransaction.BillAmount = 0; #endregion billTransaction.UnitQty = planBill.UnitQty; billTransaction.LocationFrom = planBill.LocationFrom; billTransaction.SettleLocation = planBill.CurrentLocation; billTransaction.EffectiveDate = effectiveDate; billTransaction.PlanBill = planBill.Id; billTransaction.ActingBill = actingBill.Id; User user = SecurityContextHolder.Get(); billTransaction.CreateUserId = user.Id; billTransaction.CreateUserName = user.FullName; billTransaction.CreateDate = DateTime.Now; this.genericMgr.Create(billTransaction); return billTransaction; #endregion }
private InventoryTransaction CreateInventoryTransaction(LocationLotDetail locationLotDetail, decimal qty, bool isCreatePlanBill, BillTransaction billTransaction) { InventoryTransaction inventoryTransaction = new InventoryTransaction(); inventoryTransaction.LocationLotDetailId = locationLotDetail.Id; inventoryTransaction.Location = locationLotDetail.Location; inventoryTransaction.Bin = locationLotDetail.Bin; inventoryTransaction.Item = locationLotDetail.Item; inventoryTransaction.HuId = locationLotDetail.HuId; inventoryTransaction.LotNo = locationLotDetail.LotNo; inventoryTransaction.IsConsignment = locationLotDetail.IsConsignment; inventoryTransaction.IsCreatePlanBill = isCreatePlanBill; inventoryTransaction.PlanBill = locationLotDetail.PlanBill; if (locationLotDetail.IsConsignment) { //寄售库存 inventoryTransaction.PlanBillQty = qty; } if (billTransaction != null) { //if (billTransaction.TransactionType == CodeMaster.BillTransactionType.POSettle) //{ //发生了结算,记录结算数量 inventoryTransaction.BillTransactionId = billTransaction.Id; inventoryTransaction.IsConsignment = false; inventoryTransaction.ActingBill = billTransaction.ActingBill; inventoryTransaction.ActingBillQty = qty; inventoryTransaction.PlanBillQty = 0; //} //else if(billTransaction.TransactionType == CodeMaster.BillTransactionType.POSettleVoid) //{ // //发生了反结算,记录反结算数量 // inventoryTransaction.BillTransactionId = billTransaction.Id; // inventoryTransaction.IsConsignment = true; // inventoryTransaction.ActingBill = 0; // inventoryTransaction.ActingBillQty = 0; //基本单位 // inventoryTransaction.PlanBill = billTransaction.PlanBill; // inventoryTransaction.PlanBillQty = qty; //} } inventoryTransaction.Qty = qty; inventoryTransaction.QualityType = locationLotDetail.QualityType; inventoryTransaction.IsATP = locationLotDetail.IsATP; inventoryTransaction.IsFreeze = locationLotDetail.IsFreeze; inventoryTransaction.OccupyType = locationLotDetail.OccupyType; inventoryTransaction.OccupyReferenceNo = locationLotDetail.OccupyReferenceNo; return inventoryTransaction; }
private InventoryTransaction CreateInventoryTransaction(InventoryIO inventoryIO, decimal qty, LocationLotDetail backFlushLocLotDet, BillTransaction billTransaction) { InventoryTransaction inventoryTransaction = new InventoryTransaction(); inventoryTransaction.LocationLotDetailId = backFlushLocLotDet.Id; inventoryTransaction.Location = inventoryIO.Location; inventoryTransaction.Bin = inventoryIO.Bin; inventoryTransaction.Item = inventoryIO.Item; inventoryTransaction.HuId = inventoryIO.HuId; inventoryTransaction.LotNo = inventoryIO.LotNo; inventoryTransaction.IsCreatePlanBill = inventoryIO.IsCreatePlanBill; inventoryTransaction.IsConsignment = inventoryIO.IsConsignment; inventoryTransaction.PlanBill = inventoryIO.PlanBill; if (inventoryIO.IsConsignment) { //寄售库存 inventoryTransaction.PlanBillQty = qty; } if (billTransaction != null) //发生了结算,记录结算数量 { inventoryTransaction.BillTransactionId = billTransaction.Id; inventoryTransaction.IsConsignment = false; inventoryTransaction.ActingBill = billTransaction.ActingBill; inventoryTransaction.ActingBillQty = qty; //基本单位 inventoryTransaction.PlanBillQty = inventoryIO.Qty - qty; } if (inventoryIO.CurrentBillTransaction != null) { inventoryTransaction.BillTransactionId = inventoryIO.CurrentBillTransaction.Id; //inventoryTransaction.IsConsignment = false; inventoryTransaction.ActingBill = inventoryIO.CurrentBillTransaction.ActingBill; inventoryTransaction.ActingBillQty = qty; //基本单位 //inventoryTransaction.PlanBillQty = inventoryIO.Qty - qty; } inventoryTransaction.Qty = qty; inventoryTransaction.QualityType = inventoryIO.QualityType; inventoryTransaction.IsATP = inventoryIO.IsATP; inventoryTransaction.IsFreeze = inventoryIO.IsFreeze; inventoryTransaction.OccupyType = inventoryIO.OccupyType; inventoryTransaction.OccupyReferenceNo = inventoryIO.OccupyReferenceNo; return inventoryTransaction; }
private void CreateNewLocationLotDetail(InventoryIO inventoryIO, IList<InventoryTransaction> inventoryTransactionList, BillTransaction billTransaction) { #region 是否允许负库存,占用不能出现负数库存,待验和不合格品不允许出现负库存 if (inventoryIO.Qty < 0) { //计划外出入库不允许负数库存 if (inventoryIO.TransactionType == CodeMaster.TransactionType.ISS_UNP || inventoryIO.TransactionType == CodeMaster.TransactionType.ISS_UNP_VOID || inventoryIO.TransactionType == CodeMaster.TransactionType.RCT_UNP || inventoryIO.TransactionType == CodeMaster.TransactionType.RCT_UNP_VOID) { throw new BusinessException(Resources.INV.LocationLotDetail.Errors_NotEnoughInventory, inventoryIO.Item, inventoryIO.Location); } else { if (inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue) { #region 寄售负库存 if (inventoryIO.QualityType != CodeMaster.QualityType.Qualified || !TryLoadLocation(inventoryIO).AllowNegativeConsignment) { PlanBill pb = TryLoadPlanBill(inventoryIO); throw new BusinessException("物料{0}在库位{1}中供应商{2}的寄售库存不足。", inventoryIO.Item, inventoryIO.Location, pb.Party); } #endregion } else { #region 非寄售负库存 if (//inventoryIO.OccupyType != com.Sconit.CodeMaster.OccupyType.None || inventoryIO.QualityType != CodeMaster.QualityType.Qualified || !TryLoadLocation(inventoryIO).AllowNegative) { throw new BusinessException(Resources.INV.LocationLotDetail.Errors_NotEnoughInventory, inventoryIO.Item, inventoryIO.Location); } #endregion } } } #endregion #region 冲销时按指定PlanBill出库数量不足 //只有冲销才会出现这种情况? //if (inventoryIO.Qty < 0 && inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue) //{ // throw new BusinessException(Resources.INV.LocationLotDetail.Errors_VoidFailNotEnoughSpecifyInventory, inventoryIO.Location, inventoryIO.Item); //} #endregion //todo disabled的零件能不能做库存事务 #region 虚零件和套件不能做库存事务不能做库存事务 //Item item = TryLoadItem(inventoryIO); //if (item.IsVirtual) //{ // throw new BusinessException(Resources.INV.LocationLotDetail.Errors_VirtualItemCannotProcessInventory, inventoryIO.Item); //} //if (item.IsKit) //{ // throw new BusinessException(Resources.INV.LocationLotDetail.Errors_KitItemCannotProcessInventory, inventoryIO.Item); //} #endregion #region 收货结算/入库结算/检验结算 //BillTransaction billTransaction = null; //if (inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue) //{ // PlanBill pb = TryLoadPlanBill(inventoryIO); // if (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.ReceivingSettlement //收货结算 // || (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.OnlineBilling && TryLoadLocation(inventoryIO).IsConsignment) //上线结算 // || (pb.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.AfterInspection //检验结算,检验合格收货事务或者让步使用收货事务 // //&& inventoryIO.QualityType == com.Sconit.CodeMaster.QualityType.Qualified // && (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_INP_QDII // || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_INP_CCS)) // || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.RCT_SO) //销售退货收货立即结算 // { // if (inventoryIO.QualityType == CodeMaster.QualityType.Inspect) // { // throw new BusinessException("待验物料{0}不能结算。", inventoryIO.Item); // } // else if (inventoryIO.QualityType == CodeMaster.QualityType.Reject) // { // throw new BusinessException("不合格物料{0}不能结算。", inventoryIO.Item); // } // pb.CurrentActingQty = inventoryIO.Qty / pb.UnitQty; // billTransaction = this.billMgr.SettleBill(pb, inventoryIO.EffectiveDate); // inventoryIO.IsConsignment = false; // //inventoryIO.PlanBill = null; // } //} #endregion #region 处理冲销寄售和结算信息 //if (billTransaction == null) //{ // //已经做了结算不可能发生冲销 // billTransaction = VoidBill(inventoryIO); //} #endregion #region 创建库存明细 LocationLotDetail newLocationLotDetail = Mapper.Map<InventoryIO, LocationLotDetail>(inventoryIO); #region 记录寄售供应商 if (inventoryIO.IsConsignment && inventoryIO.PlanBill.HasValue) { PlanBill pb = TryLoadPlanBill(inventoryIO); newLocationLotDetail.ConsignmentSupplier = pb.Party; } else { newLocationLotDetail.IsConsignment = false; newLocationLotDetail.PlanBill = null; newLocationLotDetail.ConsignmentSupplier = null; } #endregion #region 指定供应商负库存 if (string.IsNullOrWhiteSpace(inventoryIO.HuId) && inventoryIO.Qty < 0 && inventoryIO.OccupyType == com.Sconit.CodeMaster.OccupyType.None && !string.IsNullOrWhiteSpace(inventoryIO.ConsignmentSupplier)) { newLocationLotDetail.ConsignmentSupplier = inventoryIO.ConsignmentSupplier; PlanBill negPlanBill = this.billMgr.LoadPlanBill(inventoryIO.Item, inventoryIO.Location, inventoryIO.ConsignmentSupplier, inventoryIO.EffectiveDate, false); inventoryIO.IsConsignment = true; newLocationLotDetail.IsConsignment = true; inventoryIO.PlanBill = negPlanBill.Id; newLocationLotDetail.PlanBill = negPlanBill.Id; } #endregion #region 冲销反结算 if (billTransaction == null) { billTransaction = this.VoidBill(inventoryIO); if (billTransaction != null && inventoryIO.IsConsignment) //发生了反结算,记录寄售库存 { newLocationLotDetail.IsConsignment = true; newLocationLotDetail.PlanBill = billTransaction.PlanBill; newLocationLotDetail.ConsignmentSupplier = billTransaction.Party; #region 寄售负库存 if (inventoryIO.Qty < 0 && !TryLoadLocation(inventoryIO).AllowNegativeConsignment) { throw new BusinessException("物料{0}在库位{1}中供应商{2}的寄售库存不足。", inventoryIO.Item, inventoryIO.Location, billTransaction.Party); } #endregion } } #endregion if (!string.IsNullOrWhiteSpace(newLocationLotDetail.HuId)) { #region 更新条码首次入库日期 Hu hu = inventoryIO.CurrentHu; if (hu == null) { hu = this.genericMgr.FindById<Hu>(newLocationLotDetail.HuId); } if (!hu.FirstInventoryDate.HasValue) { hu.FirstInventoryDate = DateTime.Now; this.genericMgr.Update(hu); } #endregion // huId = huId.ToUpper(); //newLocationLotDetail.Hu = this.huMgrE.LoadHu(huId); ////库存数量和条码上的数量有差异,更新条码上的数量 //if (newLocationLotDetail.Hu.Qty * newLocationLotDetail.Hu.UnitQty != qty) //{ // newLocationLotDetail.Hu.Qty = qty / newLocationLotDetail.Hu.UnitQty; //} //newLocationLotDetail.Hu.Location = location.Code; //newLocationLotDetail.Hu.Status = BusinessConstants.CODE_MASTER_HU_STATUS_VALUE_INVENTORY; //this.huMgrE.UpdateHu(newLocationLotDetail.Hu); if (newLocationLotDetail.Qty < 0) { throw new TechnicalException("Barcode qty can't less than 0."); } } //入库 LocationLotDetail mergeLocationLotDetail = null; if (string.IsNullOrWhiteSpace(newLocationLotDetail.HuId) && TryLoadLocation(inventoryIO).MergeLocationLotDet) { //#region 查找库存明细是否可以合并,有条码的不能合并 //mergeLocationLotDetail = this.genericMgr.FindEntityWithNativeSql<LocationLotDetail>("exec USP_Busi_GetMergeInventory ?,?,?,?,?,?,?,?,?,?" // , new object[] { newLocationLotDetail.Location, newLocationLotDetail.Item, newLocationLotDetail.Qty, // newLocationLotDetail.PlanBill, newLocationLotDetail.QualityType, newLocationLotDetail.IsFreeze, // newLocationLotDetail.IsATP, newLocationLotDetail.OccupyType, newLocationLotDetail.OccupyReferenceNo, // newLocationLotDetail.ConsignmentSupplier} // , new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Decimal, // NHibernate.NHibernateUtil.Int32, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.Boolean, // NHibernate.NHibernateUtil.Boolean, NHibernate.NHibernateUtil.Int16, NHibernate.NHibernateUtil.String, // NHibernate.NHibernateUtil.String }).FirstOrDefault(); //#endregion } if (mergeLocationLotDetail != null) { mergeLocationLotDetail.Qty += newLocationLotDetail.Qty; this.genericMgr.Update(mergeLocationLotDetail); inventoryTransactionList.Add(CreateInventoryTransaction(inventoryIO, inventoryIO.Qty, mergeLocationLotDetail, billTransaction)); } else { if (!newLocationLotDetail.IsConsignment) { newLocationLotDetail.PlanBill = null; newLocationLotDetail.ConsignmentSupplier = null; } this.genericMgr.Create(newLocationLotDetail); inventoryTransactionList.Add(CreateInventoryTransaction(inventoryIO, inventoryIO.Qty, newLocationLotDetail, billTransaction)); } #endregion }