private SettleBillTransaction RecordSettleBillTransaction(PlanBill planBill, ActingBill actingBill, DateTime effectiveDate, bool isVoid) { #region 记BillTransaction SettleBillTransaction billTransaction = new SettleBillTransaction(); 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.HuId; //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); //采购付款为负数 if (planBill.Type == CodeMaster.BillType.Procurement) { if (isVoid) { //采购结算冲销负数 billTransaction.TransactionType = CodeMaster.BillTransactionType.POSettleVoid; billTransaction.BillQty = -qty; billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice; } else { //采购结算正数 billTransaction.TransactionType = CodeMaster.BillTransactionType.POSettle; billTransaction.BillQty = qty; billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice; } } else { if (isVoid) { //销售开票冲销负数 billTransaction.TransactionType = CodeMaster.BillTransactionType.SOSettleVoid; billTransaction.BillQty = -qty; billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice; } else { //销售开票正数 billTransaction.TransactionType = CodeMaster.BillTransactionType.SOSettle; billTransaction.BillQty = qty; billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice; } } #endregion billTransaction.UnitQty = planBill.UnitQty; // billTransaction.LocationFrom = planBill.LocationFrom; billTransaction.SettleLocation = planBill.CurrentLocation; billTransaction.EffectiveDate = effectiveDate; billTransaction.PlanBill = planBill.Id; billTransaction.ActingBill = actingBill.Id; billTransaction.BillTerm = actingBill.BillTerm; 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, SettleBillTransaction 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) //发生了结算,记录结算数量 { inventoryTransaction.BillTransactionId = billTransaction.Id; //inventoryTransaction.IsConsignment = false; inventoryTransaction.ActingBill = billTransaction.ActingBill; inventoryTransaction.ActingBillQty = qty; inventoryTransaction.PlanBillQty = 0; } 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, SettleBillTransaction 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; } 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 BackflushInventory(InventoryIO inventoryIO, IList<LocationLotDetail> backFlushLocLotDetList, IList<InventoryTransaction> inventoryTransactionList) { Boolean isVoidedActBill = false; SettleBillTransaction voidBillTransaction = new SettleBillTransaction(); if (backFlushLocLotDetList != null && backFlushLocLotDetList.Count > 0) { foreach (LocationLotDetail backFlushLocLotDet in backFlushLocLotDetList) { #region 只有发生在按条码发货,按数量收货的情况,因为有些待回冲的库存已经被上一个条码冲掉,这里就不继续回冲了。 if (backFlushLocLotDet.Qty == 0) { continue; } #endregion #region 判断是否满足回冲条件 if (inventoryIO.Qty == 0) { return; } PlanBill backFlushPlanBill = backFlushLocLotDet.IsConsignment && backFlushLocLotDet.PlanBill.HasValue ? this.genericMgr.FindById<PlanBill>(backFlushLocLotDet.PlanBill.Value) : null; PlanBill inputPlanBill = inventoryIO.IsConsignment ? TryLoadPlanBill(inventoryIO) : null; //如果被回冲和入库的都是寄售库存并且是同一个供应商,一定要回冲 if (backFlushLocLotDet.IsConsignment && inputPlanBill != null && backFlushPlanBill.BillAddress == inputPlanBill.BillAddress) { } else { //被回冲的寄售库存,和入库的寄售库存不是一个供应商,不能回冲 if (backFlushLocLotDet.IsConsignment && inputPlanBill != null && backFlushPlanBill.BillAddress != inputPlanBill.BillAddress) { return; } //被回冲的寄售库存的结算方式是上线结算,判断是否当前事务类型是否是ISS-*,不满足不能回冲 //if (backFlushLocLotDet.IsConsignment // && backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_ONLINE_BILLING) //{ // if (!transType.StartsWith("ISS-")) // { // return; // } //} //被回冲的寄售库存的结算方式是下线结算,判断是否当前事务类型是否是ISS-*并且不等于ISS-TR,不满足不能回冲 //if (backFlushLocLotDet.IsConsignment // && backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_LINEAR_CLEARING) //{ // if (!(transType.StartsWith("ISS-") && transType != BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR)) // { // return; // } //} } #endregion #region 回冲库存 decimal currentBFQty = 0; //本次回冲数 if (inventoryIO.Qty > 0) { if (backFlushLocLotDet.Qty + inventoryIO.Qty < 0) { //本次入库数 < 库存数量,全部回冲,回冲数量等于本次入库数 currentBFQty = inventoryIO.Qty; } else { //本次入库数 >= 库存数量,按负的库存数回冲 currentBFQty = 0 - backFlushLocLotDet.Qty; } } else { if (backFlushLocLotDet.Qty + inventoryIO.Qty > 0) { //本次出库数 < 库存数量,全部回冲,回冲数量等于本次出库数 currentBFQty = inventoryIO.Qty; } else { //本次出库数 >= 库存数量,按正的库存数回冲 currentBFQty = 0 - backFlushLocLotDet.Qty; } } //更新库存数量 backFlushLocLotDet.Qty += currentBFQty; this.genericMgr.Update(backFlushLocLotDet); #endregion #region 结算 SettleBillTransaction billTransaction = null; if (inventoryIO.Qty < 0 && inputPlanBill == null && backFlushLocLotDet.IsConsignment) { if (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SO //销售出库 || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_WO //生产出库 //|| inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_MIN //投料 李秋云 || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SWO //委外生产出库 || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_UNP //计划外出库 || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.CYC_CNT) //盘亏 //// (backFlushPlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_ONLINE_BILLING //上线结算条件,发生移库出库事务才结算,可以避免收货检验时入检验库位就结算 ////&& (transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_TR //// || transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_MATERIAL_IN)) ////|| //(backFlushPlanBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_LINEAR_CLEARING //下线结算条件 // && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO) ////|| (backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION //检验结算条件,从检验库位出库,并且发生ISS-INP事务 //// && backFlushLocLotDet.Location.Code == BusinessConstants.SYSTEM_LOCATION_INSPECT //// && transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_INP) ////|| (backFlushLocLotDet.PlannedBill.SettleTerm == BusinessConstants.CODE_MASTER_BILL_SETTLE_TERM_VALUE_INSPECTION //检验结算,从不合格品库位出库,立即结算 //// && backFlushLocLotDet.Location.Code == BusinessConstants.SYSTEM_LOCATION_REJECT) //|| transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_UNP //如果发生ISS_UNP或者CYC_CNT事务,强行结算 //|| transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_CYC_CNT //|| transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_SO //|| transType == BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO //|| transType.StartsWith(BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_RCT)) { //寄售库存需要进行结算,对被回冲的库存进行负数结算 backFlushPlanBill.CurrentActingQty = (0 - currentBFQty) / backFlushPlanBill.UnitQty; //按负数结算 backFlushPlanBill.CurrentLocation = backFlushLocLotDet.Location; billTransaction = this.billMgr.SettleBill(backFlushPlanBill, inventoryIO.EffectiveDate); } //else if (inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_PO //采购退货 // || inventoryIO.TransactionType == com.Sconit.CodeMaster.TransactionType.ISS_SL) //计划协议退货 //{ // //退货,寄售库存需要取消寄售数量 // backFlushPlanBill.CurrentVoidQty = (0 - currentBFQty) / backFlushPlanBill.UnitQty; //按负数结算 // this.billMgr.VoidPlanBill(backFlushPlanBill); //} } else { //如果出库PlanBill和被回冲PlanBill的Id相同,即指定PlanBill出库,不发生回冲 if (!(backFlushLocLotDet.IsConsignment && backFlushLocLotDet.PlanBill == inputPlanBill.Id)) { if (backFlushLocLotDet.IsConsignment) { //寄售库存需要进行结算,对被回冲的库存进行负数结算 backFlushPlanBill.CurrentActingQty = (0 - currentBFQty) / backFlushPlanBill.UnitQty; //按负数结算 backFlushPlanBill.CurrentLocation = backFlushLocLotDet.Location; billTransaction = this.billMgr.SettleBill(backFlushPlanBill, inventoryIO.EffectiveDate); } if (inputPlanBill != null) { 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); } //对入库的库存进行结算 inputPlanBill.CurrentActingQty = currentBFQty / inputPlanBill.UnitQty; //按正数结算 inputPlanBill.CurrentLocation = backFlushLocLotDet.Location; billTransaction = this.billMgr.SettleBill(inputPlanBill, inventoryIO.EffectiveDate); } } } #endregion #region 处理冲销寄售和结算信息 if (billTransaction == null) { if (isVoidedActBill == false) { billTransaction = VoidBill(inventoryIO); isVoidedActBill = true; voidBillTransaction = billTransaction; } else { billTransaction = voidBillTransaction; } } #endregion //记录被回冲的记录 if (inventoryIO.Qty > 0) { //回冲负数库存,按inventoryIO记录库存事务 inventoryTransactionList.Add(CreateInventoryTransaction(inventoryIO, currentBFQty, backFlushLocLotDet, billTransaction)); } else { //回冲正数库存,按backFlushLocLotDet记录库存事务 //因为是出库,不可能有创建Planbill的情况 inventoryTransactionList.Add(CreateInventoryTransaction(backFlushLocLotDet, currentBFQty, false, billTransaction)); } inventoryIO.Qty -= currentBFQty; } } }