private void RecordPlanBillTransaction(PlanBill planBill, DateTime effectiveDate, int refId, bool isVoid) { #region 记BillTransaction PlanBillTransaction billTransaction = new PlanBillTransaction(); 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.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.PlanQty; if (planBill.Type == CodeMaster.BillType.Procurement) { if (isVoid) { //采购结算冲销负数 billTransaction.TransactionType = CodeMaster.BillTransactionType.POPlanBillVoid; billTransaction.BillQty = -qty; billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice; } else { //采购结算正数 billTransaction.TransactionType = CodeMaster.BillTransactionType.POPlanBill; billTransaction.BillQty = qty; billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice; } } else { if (isVoid) { //销售开票冲销负数 billTransaction.TransactionType = CodeMaster.BillTransactionType.SOPlanBillVoid; billTransaction.BillQty = -qty; billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice; } else { //销售开票正数 billTransaction.TransactionType = CodeMaster.BillTransactionType.SOPlanBill; billTransaction.BillQty = qty; billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice; } } #endregion billTransaction.UnitQty = planBill.UnitQty; billTransaction.LocationFrom = planBill.LocationFrom; billTransaction.SettleLocation = planBill.LocationFrom; billTransaction.EffectiveDate = effectiveDate; billTransaction.PlanBill = planBill.Id; billTransaction.RefId = refId; billTransaction.BillTerm = planBill.BillTerm; User user = SecurityContextHolder.Get(); billTransaction.CreateUserId = user.Id; billTransaction.CreateUserName = user.FullName; billTransaction.CreateDate = DateTime.Now; this.genericMgr.Create(billTransaction); #endregion }
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 }
public PlanBill CreatePlanBill(ReceiptDetail receiptDetail, ReceiptDetailInput receiptDetailInput, DateTime effectiveDate) { PlanBill planBill = new PlanBill(); planBill.OrderNo = receiptDetail.OrderNo; planBill.IpNo = receiptDetail.IpNo; //planBill.ExternalIpNo = receiptDetail.ExternalIpNo; planBill.ReceiptNo = receiptDetail.ReceiptNo; planBill.ExternalReceiptNo = receiptDetail.CurrentExternalReceiptNo; if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.CustomerGoods || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine) { planBill.Type = com.Sconit.CodeMaster.BillType.Procurement; if (receiptDetail.OrderSubType == CodeMaster.OrderSubType.Normal) { planBill.LocationFrom = receiptDetail.LocationTo; planBill.Party = receiptDetail.CurrentPartyFrom; planBill.PartyName = receiptDetail.CurrentPartyFromName; } else { planBill.LocationFrom = receiptDetail.LocationFrom; planBill.Party = receiptDetail.CurrentPartyTo; planBill.PartyName = receiptDetail.CurrentPartyToName; } } else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution) { planBill.Type = com.Sconit.CodeMaster.BillType.Distribution; if (receiptDetail.OrderSubType == CodeMaster.OrderSubType.Normal) { planBill.LocationFrom = receiptDetail.LocationFrom; planBill.Party = receiptDetail.CurrentPartyTo; planBill.PartyName = receiptDetail.CurrentPartyToName; } else { planBill.LocationFrom = receiptDetail.LocationTo; planBill.Party = receiptDetail.CurrentPartyFrom; planBill.PartyName = receiptDetail.CurrentPartyFromName; } } planBill.Item = receiptDetail.Item; planBill.ItemDescription = receiptDetail.ItemDescription; planBill.Uom = receiptDetail.Uom; planBill.UnitCount = receiptDetail.UnitCount; planBill.BillTerm = receiptDetail.BillTerm; planBill.BillAddress = receiptDetail.BillAddress; //planBill.BillAddressDescription = receiptDetail.BillAddressDescription; planBill.PriceList = receiptDetail.PriceList; planBill.Currency = receiptDetail.Currency; planBill.UnitPrice = receiptDetail.UnitPrice.HasValue ? receiptDetail.UnitPrice.Value : 0; planBill.IsProvisionalEstimate = receiptDetail.UnitPrice.HasValue ? receiptDetail.IsProvisionalEstimate : false; planBill.Tax = receiptDetail.Tax; planBill.IsIncludeTax = receiptDetail.IsIncludeTax; if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal) { //planBill.PlanQty = receiptDetailInput.ReceiveQty / receiptDetail.UnitQty; planBill.PlanQty = receiptDetailInput.ReceiveQty; } else { //planBill.PlanQty = -receiptDetailInput.ReceiveQty / receiptDetail.UnitQty; planBill.PlanQty = -receiptDetailInput.ReceiveQty; } planBill.PlanAmount = planBill.UnitPrice * planBill.PlanQty; planBill.UnitQty = receiptDetail.UnitQty; planBill.HuId = receiptDetailInput.HuId; planBill.EffectiveDate = effectiveDate; planBill.Flow = receiptDetail.Flow; planBill.ReferenceItemCode = receiptDetail.ReferenceItemCode; this.genericMgr.Create(planBill); this.RecordPlanBillTransaction(planBill, effectiveDate, receiptDetail.Id, false); return planBill; }
public SettleBillTransaction VoidSettleBill(ActingBill actingBill, PlanBill planBill, bool voidPlanBill) { #region 更新ActingBill if (Math.Abs(actingBill.BillQty) < Math.Abs(actingBill.BillingQty + actingBill.VoidQty + actingBill.CurrentVoidQty)) { //待开票数量不足,不能冲销结算 throw new BusinessException(Resources.BIL.Bill.Errors_VoidActBillFailActQtyNotEnough, actingBill.Item); } actingBill.VoidQty += actingBill.CurrentVoidQty; actingBill.IsClose = (actingBill.BillQty == (actingBill.BillingQty + actingBill.VoidQty)); this.genericMgr.Update(actingBill); #endregion #region 反向更新PlanBill if (planBill == null) { planBill = this.genericMgr.FindById<PlanBill>(actingBill.PlanBill); } planBill.ActingQty -= actingBill.CurrentVoidQty; if (Math.Abs(planBill.ActingQty + planBill.VoidQty) > Math.Abs(planBill.PlanQty)) { //冲销的数量大于待开票数量 throw new BusinessException(Resources.BIL.Bill.Errors_VoidActingQtyExceedPlanQty, planBill.Item); } if (voidPlanBill) { if (Math.Abs(planBill.ActingQty + planBill.VoidQty + actingBill.CurrentVoidQty) > Math.Abs(planBill.PlanQty)) { //已经结算,不能冲销寄售信息 throw new BusinessException(Resources.BIL.Bill.Errors_VoidPlanBillFailPlanQtyNotEnough, planBill.Item); } planBill.VoidQty += actingBill.CurrentVoidQty; } if (planBill.PlanQty == (planBill.ActingQty + planBill.VoidQty)) { planBill.IsClose = true; } else { planBill.IsClose = false; } this.genericMgr.Update(planBill); #endregion #region 记录库存事务 planBill.CurrentVoidQty = actingBill.CurrentVoidQty; return this.RecordSettleBillTransaction(planBill, actingBill, actingBill.EffectiveDate, true); #endregion }
public void VoidPlanBill(PlanBill planBill) { if (Math.Abs(planBill.ActingQty + planBill.VoidQty + planBill.CurrentVoidQty) > Math.Abs(planBill.PlanQty)) { //已经结算,不能冲销寄售信息 throw new BusinessException(Resources.BIL.Bill.Errors_VoidPlanBillFailPlanQtyNotEnough, planBill.Item); } planBill.VoidQty += planBill.CurrentVoidQty; if (planBill.PlanQty == (planBill.ActingQty + planBill.VoidQty)) { planBill.IsClose = true; } else { planBill.IsClose = false; } this.genericMgr.Update(planBill); this.RecordPlanBillTransaction(planBill, DateTime.Now, planBill.Id, true); }
public SettleBillTransaction SettleBill(PlanBill planBill) { return SettleBill(planBill, DateTime.Now); }
public SettleBillTransaction SettleBill(PlanBill planBill, DateTime effectiveDate) { ////重新计价 //PriceListDetail priceListDetail = // this.itemMgr.GetItemPrice // (planBill.Item, planBill.Uom, planBill.PriceList, planBill.Currency, planBill.EffectiveDate); //if (priceListDetail != null &&//正式价不能更新成暂估价 // (!priceListDetail.IsProvisionalEstimate || (priceListDetail.IsProvisionalEstimate && planBill.IsProvisionalEstimate))) //{ // planBill.IsIncludeTax = priceListDetail.PriceList.IsIncludeTax; // planBill.Tax = priceListDetail.PriceList.Tax; // planBill.IsProvisionalEstimate = priceListDetail.IsProvisionalEstimate; // planBill.UnitPrice = priceListDetail.UnitPrice; //} //校验,已结算数+本次结算数不能大于总结算数量,可能有负数结算,所以要用绝对值比较 if (Math.Abs(planBill.ActingQty + planBill.CurrentActingQty) > Math.Abs(planBill.PlanQty)) { throw new BusinessException(Resources.BIL.Bill.Errors_ActingQtyExceedPlanQty, planBill.Item); } ActingBill actingBill = this.RetriveActingBill(planBill, effectiveDate.Date); if (actingBill.Id == 0) { this.genericMgr.Create(actingBill); } else { this.genericMgr.Update(actingBill); } //// #region 更新Planed Bill的已结算数量 planBill.ActingQty += planBill.CurrentActingQty; planBill.ActingAmount += planBill.UnitPrice * planBill.CurrentActingQty; planBill.IsClose = (planBill.ActingQty != planBill.PlanQty); this.genericMgr.Update(planBill); #endregion #region 记BillTransaction return RecordSettleBillTransaction(planBill, actingBill, effectiveDate, false); #endregion }
public PlanBill CreatePlanBill(MiscOrderMaster miscOrderMaster, MiscOrderDetail miscOrderDetail, MiscOrderLocationDetail miscOrderLocationDetail, DateTime effectiveDate) { PlanBill planBill = new PlanBill(); planBill.OrderNo = miscOrderMaster.MiscOrderNo; planBill.ReceiptNo = miscOrderMaster.MiscOrderNo; planBill.ExternalReceiptNo = miscOrderMaster.ReferenceNo; planBill.Type = com.Sconit.CodeMaster.BillType.Procurement; planBill.Party = miscOrderDetail.ManufactureParty; planBill.Item = miscOrderDetail.Item; planBill.ItemDescription = miscOrderDetail.ItemDescription; planBill.Uom = miscOrderDetail.Uom; planBill.UnitCount = miscOrderDetail.UnitCount; planBill.BillTerm = CodeMaster.OrderBillTerm.OnlineBilling; PartyAddress partyAddress = this.genericMgr.FindAll<PartyAddress>( "from PartyAddress as pa where pa.Party = ? and pa.Type = ? order by IsPrimary desc,Sequence asc ", new object[] { planBill.Party, CodeMaster.AddressType.BillAddress }, 0, 1).FirstOrDefault(); if (partyAddress == null) { throw new BusinessException(Resources.EXT.ServiceLan.TheBillAddressNotSpecialSupplier, planBill.Party); } planBill.BillAddress = partyAddress.Address.Code; planBill.PlanAmount = 0; int refId = 0; if (miscOrderMaster.IsScanHu) { planBill.PlanQty = miscOrderLocationDetail.Qty; planBill.UnitQty = miscOrderDetail.UnitQty; planBill.HuId = miscOrderLocationDetail.HuId; refId = miscOrderLocationDetail.Id; } else { planBill.PlanQty = miscOrderDetail.Qty; planBill.UnitQty = miscOrderDetail.UnitQty; refId = miscOrderDetail.Id; } planBill.LocationFrom = string.IsNullOrWhiteSpace(miscOrderDetail.Location) ? miscOrderMaster.Location : miscOrderDetail.Location; planBill.EffectiveDate = effectiveDate; this.genericMgr.Create(planBill); this.RecordPlanBillTransaction(planBill, effectiveDate, refId, false); return planBill; }
private ActingBill RetriveActingBill(PlanBill planBill, DateTime effectiveDate) { DetachedCriteria criteria = DetachedCriteria.For<ActingBill>(); criteria.Add(Expression.Eq("ReceiptNo", planBill.ReceiptNo)); IList<ActingBill> actingBillList = this.genericMgr.FindAll<ActingBill>(criteria); ActingBill actingBill = new ActingBill(); if (actingBillList == null || actingBillList.Count == 0) { actingBill = Mapper.Map<PlanBill, ActingBill>(planBill); } else { var actingBills = actingBillList.Where(p => p.OrderNo == planBill.OrderNo && p.ExternalReceiptNo == planBill.ExternalReceiptNo && p.Type == planBill.Type && p.Item == planBill.Item && p.BillAddress == planBill.BillAddress && p.Uom == planBill.Uom && p.UnitCount == planBill.UnitCount && p.PriceList == planBill.PriceList && p.RecPrice == planBill.UnitPrice && p.Currency == planBill.Currency && p.IsIncludeTax == planBill.IsIncludeTax && p.Tax == planBill.Tax && p.LocationFrom == planBill.LocationFrom && p.IsProvisionalEstimate == planBill.IsProvisionalEstimate && p.EffectiveDate == effectiveDate); if (actingBills == null || actingBills.Count() == 0) { actingBill = Mapper.Map<PlanBill, ActingBill>(planBill); } else if (actingBills.Count() == 1) { actingBill = actingBills.First(); } else { throw new TechnicalException("Acting bill record consolidate error, find target acting bill number great than 1."); } } actingBill.BillQty += planBill.CurrentActingQty; actingBill.EffectiveDate = effectiveDate; actingBill.IsClose = (actingBill.BillQty == (actingBill.BillingQty + actingBill.VoidQty)); actingBill.BillAmount += planBill.UnitPrice * planBill.CurrentActingQty; actingBill.RecPrice = planBill.UnitPrice; return actingBill; }
public void CancelVoidPlanBill(PlanBill planBill) { planBill.VoidQty -= planBill.CurrentCancelVoidQty; this.genericMgr.Update(planBill); }
private ActingBill CreateActingBill(PlanBill planBill, DateTime effectiveDate) { DateTime formatedEffDate = DateTime.Parse(effectiveDate.ToShortDateString()); //仅保留年月日 ActingBill actingBill = (this.genericMgr.FindEntityWithNativeSql<ActingBill>("select * from BIL_ActBill where PlanBill = ?", planBill.Id)).SingleOrDefault(); if (actingBill == null) { actingBill = Mapper.Map<PlanBill, ActingBill>(planBill); actingBill.EffectiveDate = formatedEffDate; //actingBill.IsClose = (actingBill.BillQty != (actingBill.BilledQty + actingBill.VoidQty)); } else { actingBill.CurrentVoidQty = 0; } actingBill.BillQty += planBill.CurrentActingQty; return actingBill; }
public void VoidPlanBill(PlanBill planBill) { //if (Math.Abs(planBill.ActingQty + planBill.VoidQty + planBill.CurrentVoidQty) > Math.Abs(planBill.PlanQty)) //{ // //已经结算,不能冲销寄售信息 // throw new BusinessException(Resources.BIL.Bill.Errors_VoidPlanBillFailPlanQtyNotEnough, planBill.Item); //} planBill.VoidQty += planBill.CurrentVoidQty; //if (planBill.PlanQty == (planBill.ActingQty + planBill.VoidQty)) //{ // planBill.IsClose = true; //} //else //{ // planBill.IsClose = false; //} this.genericMgr.Update(planBill); }
public BillTransaction VoidSettleBill(ActingBill actingBill, PlanBill planBill, bool voidPlanBill) { #region 更新ActingBill //if (Math.Abs(actingBill.BillQty) < Math.Abs(actingBill.BilledQty + actingBill.VoidQty + actingBill.CurrentVoidQty)) //{ // //待开票数量不足,不能冲销结算 // throw new BusinessException(Resources.BIL.Bill.Errors_VoidActBillFailActQtyNotEnough, actingBill.Item); //} actingBill.VoidQty += actingBill.CurrentVoidQty; //actingBill.IsClose = (actingBill.BillQty == (actingBill.BilledQty + actingBill.VoidQty)); this.genericMgr.Update(actingBill); #endregion #region 反向更新PlanBill if (planBill == null) { planBill = this.genericMgr.FindById<PlanBill>(actingBill.PlanBill); planBill.CurrentVoidQty = 0; planBill.CurrentCancelVoidQty = 0; planBill.CurrentActingQty = 0; planBill.CurrentLocation = null; planBill.CurrentHuId = null; planBill.CurrentActingBill = null; planBill.CurrentBillTransaction = null; } planBill.ActingQty -= actingBill.CurrentVoidQty; //if (Math.Abs(planBill.ActingQty + planBill.VoidQty) > Math.Abs(planBill.PlanQty)) //{ // //冲销的数量大于待开票数量 // throw new BusinessException(Resources.BIL.Bill.Errors_VoidActingQtyExceedPlanQty, planBill.Item); //} if (voidPlanBill) { //if (Math.Abs(planBill.ActingQty + planBill.VoidQty + actingBill.CurrentVoidQty) > Math.Abs(planBill.PlanQty)) //{ // //已经结算,不能冲销寄售信息 // throw new BusinessException(Resources.BIL.Bill.Errors_VoidPlanBillFailPlanQtyNotEnough, planBill.Item); //} planBill.VoidQty += actingBill.CurrentVoidQty; } //if (planBill.PlanQty == (planBill.ActingQty + planBill.VoidQty)) //{ // planBill.IsClose = true; //} //else //{ // planBill.IsClose = false; //} this.genericMgr.Update(planBill); #endregion #region 记录账单事务 planBill.CurrentVoidQty = actingBill.CurrentVoidQty; return this.RecordBillTransaction(planBill, actingBill, actingBill.EffectiveDate, true); #endregion }
public BillTransaction SettleBill(PlanBill planBill, DateTime effectiveDate) { //if (string.IsNullOrWhiteSpace(receiptNo)) //{ // throw new TechnicalException("receiptNo can't be null or white space"); //} //检验,已结算数+本次结算数不能大于总结算数量,可能有负数结算,所以要用绝对值比较 //if (Math.Abs(planBill.ActingQty + planBill.CurrentActingQty) > Math.Abs(planBill.PlanQty)) //{ // throw new BusinessException(Resources.BIL.Bill.Errors_ActingQtyExceedPlanQty, planBill.Item); //} ActingBill actingBill = this.CreateActingBill(planBill, effectiveDate); #region 计算结算金额,不在支持订单折扣,直接按照单价计算金额 //if (Math.Abs(oldPlannedBill.ActingQty.Value + oldPlannedBill.CurrentActingQty) < Math.Abs(oldPlannedBill.PlannedQty)) //{ // //总结算数小于计划数,用实际单价计算待开票金额 // planBill.CurrentBillAmount = oldPlannedBill.UnitPrice * oldPlannedBill.CurrentActingQty; //} //else //{ // planBill.CurrentBillAmount = oldPlannedBill.PlannedAmount - (oldPlannedBill.ActingAmount.HasValue ? oldPlannedBill.ActingAmount.Value : 0); //} //actingBill.BillAmount += planBill.CurrentBillAmount; #endregion #region 更新Planed Bill的已结算数量 planBill.ActingQty += planBill.CurrentActingQty; //PlanBill不在有关闭的情况 //planBill.IsClose = (planBill.ActingQty != planBill.PlanQty); this.genericMgr.Update(planBill); #endregion if (actingBill.Id == 0) { genericMgr.Create(actingBill); } else { genericMgr.Update(actingBill); } #region 记BillTransaction return RecordBillTransaction(planBill, actingBill, effectiveDate, false); #endregion //return actingBill; }
public PlanBill CreatePlanBill(ReceiptDetail receiptDetail, ReceiptDetailInput receiptDetailInput, DateTime effectiveDate) { PlanBill planBill = null; #region 寄售查找是否有PlanBill if (!(receiptDetail.BillTerm == CodeMaster.OrderBillTerm.ReceivingSettlement || receiptDetail.BillTerm == CodeMaster.OrderBillTerm.NA)) { planBill = this.genericMgr.FindEntityWithNativeSql<PlanBill>("select * from BIL_PlanBill where Item = ? and BillAddr = ? and BillTerm not in(?,?)", new object[] { receiptDetail.Item, receiptDetail.BillAddress, CodeMaster.OrderBillTerm.NA, CodeMaster.OrderBillTerm.ReceivingSettlement }).FirstOrDefault(); if (planBill != null) { planBill.CurrentVoidQty = 0; planBill.CurrentCancelVoidQty = 0; planBill.CurrentActingQty = 0; planBill.CurrentLocation = null; planBill.CurrentHuId = null; planBill.CurrentActingBill = null; planBill.CurrentBillTransaction = null; if (planBill.BillTerm != receiptDetail.BillTerm) { //throw new BusinessException("物料{0}的结算方式({1})和寄售结算方式({2})不一致。", receiptDetail.Item, // systemMgr.GetCodeDetailDescription(CodeMaster.CodeMaster.BillTerm, (int)receiptDetail.BillTerm), // systemMgr.GetCodeDetailDescription(CodeMaster.CodeMaster.BillTerm, (int)planBill.BillTerm)); throw new BusinessException("物料{0}的结算方式({1})和寄售结算方式({2})不一致。", receiptDetail.Item, systemMgr.GetCodeDetailDescription(CodeMaster.CodeMaster.OrderBillTerm, (int)receiptDetail.BillTerm), systemMgr.GetCodeDetailDescription(CodeMaster.CodeMaster.OrderBillTerm, (int)planBill.BillTerm)); } } //if (planBill.Uom != receiptDetail.Uom) //{ // throw new BusinessException("物料{0}的收货单位{1}和寄售结算的单位{2}不一致。", receiptDetail.Item, receiptDetail.Uom, planBill.Uom); //} } else { planBill = this.genericMgr.FindEntityWithNativeSql<PlanBill>("select * from BIL_PlanBill where Item = ? and BillAddr = ? and RecNo = ?", new object[] { receiptDetail.Item, receiptDetail.BillAddress, receiptDetail.ReceiptNo }).FirstOrDefault(); if (planBill != null) { planBill.CurrentVoidQty = 0; planBill.CurrentCancelVoidQty = 0; planBill.CurrentActingQty = 0; planBill.CurrentLocation = null; planBill.CurrentHuId = null; planBill.CurrentActingBill = null; planBill.CurrentBillTransaction = null; } } #endregion #region 没有PlanBill,创建PlanBill if (planBill == null) { planBill = new PlanBill(); if (receiptDetail.BillTerm == CodeMaster.OrderBillTerm.ReceivingSettlement || receiptDetail.BillTerm == CodeMaster.OrderBillTerm.NA) { planBill.OrderNo = receiptDetail.OrderNo; planBill.IpNo = receiptDetail.IpNo; //planBill.ExternalIpNo = receiptDetail.ExternalIpNo; planBill.ReceiptNo = receiptDetail.ReceiptNo; planBill.ExternalReceiptNo = receiptDetail.Id.ToString(); } if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine) { planBill.Type = com.Sconit.CodeMaster.BillType.Procurement; if (receiptDetailInput.ReceiveQty > 0) { planBill.Party = receiptDetail.CurrentPartyFrom; planBill.PartyName = receiptDetail.CurrentPartyFromName; } else { planBill.Party = receiptDetail.CurrentPartyTo; planBill.PartyName = receiptDetail.CurrentPartyToName; } } else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution) { planBill.Type = com.Sconit.CodeMaster.BillType.Distribution; if (receiptDetailInput.ReceiveQty > 0) { planBill.Party = receiptDetail.CurrentPartyTo; planBill.PartyName = receiptDetail.CurrentPartyToName; } else { planBill.Party = receiptDetail.CurrentPartyFrom; planBill.PartyName = receiptDetail.CurrentPartyFromName; } } planBill.Item = receiptDetail.Item; planBill.ItemDescription = receiptDetail.ItemDescription; planBill.Uom = receiptDetail.Uom; planBill.UnitCount = receiptDetail.UnitCount; planBill.BillTerm = receiptDetail.BillTerm == CodeMaster.OrderBillTerm.NA ? CodeMaster.OrderBillTerm.ReceivingSettlement : receiptDetail.BillTerm; planBill.BillAddress = receiptDetail.BillAddress; //planBill.BillAddressDescription = receiptDetail.BillAddressDescription; planBill.PriceList = receiptDetail.PriceList; planBill.Currency = receiptDetail.Currency; planBill.UnitPrice = receiptDetail.UnitPrice.HasValue ? receiptDetail.UnitPrice.Value : 0; planBill.IsProvisionalEstimate = receiptDetail.UnitPrice.HasValue ? receiptDetail.IsProvisionalEstimate : false; planBill.Tax = receiptDetail.Tax; planBill.IsIncludeTax = receiptDetail.IsIncludeTax; planBill.PlanAmount = 0; if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal) { //planBill.PlanQty = receiptDetailInput.ReceiveQty / receiptDetail.UnitQty; planBill.PlanQty = receiptDetailInput.ReceiveQty; } else { //planBill.PlanQty = -receiptDetailInput.ReceiveQty / receiptDetail.UnitQty; planBill.PlanQty = -receiptDetailInput.ReceiveQty; } planBill.UnitQty = receiptDetail.UnitQty; //planBill.HuId = receiptDetailInput.HuId; //planBill.LocationFrom = receiptDetail.LocationFrom; planBill.EffectiveDate = effectiveDate; this.genericMgr.Create(planBill); } #endregion #region 有PlanBill,增加待结算数量 else { if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal) { if (planBill.Uom != receiptDetail.Uom) { planBill.PlanQty += this.itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, receiptDetailInput.ReceiveQty, planBill.Uom); } else { planBill.PlanQty += receiptDetailInput.ReceiveQty; } } else { if (planBill.Uom != receiptDetail.Uom) { planBill.PlanQty -= this.itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, receiptDetailInput.ReceiveQty, planBill.Uom); } else { planBill.PlanQty -= receiptDetailInput.ReceiveQty; } } this.genericMgr.Update(planBill); } #endregion #region 收货结算 if (receiptDetail.BillTerm == CodeMaster.OrderBillTerm.NA || receiptDetail.BillTerm == CodeMaster.OrderBillTerm.ReceivingSettlement) { if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal) { if (planBill.Uom != receiptDetail.Uom) { planBill.CurrentActingQty = this.itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, receiptDetailInput.ReceiveQty, planBill.Uom); } else { planBill.CurrentActingQty = receiptDetailInput.ReceiveQty; } } else { if (planBill.Uom != receiptDetail.Uom) { planBill.CurrentActingQty = -this.itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, receiptDetailInput.ReceiveQty, planBill.Uom); } else { planBill.CurrentActingQty = -receiptDetailInput.ReceiveQty; } } BillTransaction billTransaction = this.SettleBill(planBill, effectiveDate); planBill.CurrentActingBill = billTransaction.ActingBill; planBill.CurrentBillTransaction = billTransaction.Id; } #endregion return planBill; }
public PlanBill LoadPlanBill(string item, string location, string consignmentSupplier, DateTime effectiveDate, bool isInitLoc) { string uom = null; string billAddr = null; CodeMaster.OrderBillTerm billTerm = CodeMaster.OrderBillTerm.OnlineBilling; decimal uc = 1; string baseUom = null; if (!isInitLoc) { IList<object[]> parms = this.genericMgr.FindAllWithNativeSql<object[]>(@"select det.Uom, ISNULL(det.BillAddr, mstr.BillAddr) as BillAddr, ISNULL(det.LocTo, mstr.LocTo) as LocTo, det.BillTerm as dBillTerm, mstr.BillTerm as mBillTerm, det.UC, i.Uom from SCM_FlowDet as det inner join SCM_FlowMstr as mstr on det.Flow = mstr.Code inner join MD_Item as i on det.Item = i.Code where det.Item = ? and mstr.PartyFrom = ? and mstr.Type = ? and det.IsActive = ? and mstr.IsActive = ?", new object[] { item, consignmentSupplier, CodeMaster.OrderType.Procurement, true, true }); if (parms == null || parms.Count == 0) { //没有采购路线一定不能进行收货结算,否则有可能因为没有合同导致sap无法结算 throw new BusinessException("没有找到供应商{0}物料{1}的采购路线,不能出现寄售负数库存。", consignmentSupplier, item); //Item item1 = this.genericMgr.FindById<Item>(item); //uom = item1.Uom; //uc = item1.UnitCount; //baseUom = item1.Uom; //PartyAddress partyAddress = this.genericMgr.FindAll<PartyAddress>("select pa from PartyAddress as pa inner join pa.Address as a where pa.Party = ? and a.Type = ?", new object[] { consignmentSupplier, CodeMaster.AddressType.BillAddress }).First(); //billAddr = partyAddress.Address.Code; //billTerm = CodeMaster.OrderBillTerm.NA; } else { object[] parm = parms.Where(p => (string)p[2] == location).FirstOrDefault(); if (parm == null) { parm = parms.First(); } uom = (string)parm[0]; billAddr = (string)parm[1]; CodeMaster.OrderBillTerm detBillTerm = (CodeMaster.OrderBillTerm)(int.Parse(parm[3].ToString())); CodeMaster.OrderBillTerm mstrBillTerm = (CodeMaster.OrderBillTerm)(int.Parse(parm[4].ToString())); //CodeMaster.OrderBillTerm billTerm = detBillTerm != CodeMaster.OrderBillTerm.NA ? detBillTerm : mstrBillTerm; //指定供应商的一定是寄售结算 billTerm = CodeMaster.OrderBillTerm.OnlineBilling; uc = (decimal)parm[5]; baseUom = (string)parm[6]; } } else { Item itemInstance = this.genericMgr.FindById<Item>(item); string ba = this.genericMgr.FindAllWithNativeSql<string>("select a.Code from MD_Address as a inner join MD_PartyAddr as pa on a.Code = pa.Address where pa.Party = ? and a.Type = ?", new object[] { consignmentSupplier, com.Sconit.CodeMaster.AddressType.BillAddress }).FirstOrDefault(); if (ba == null) { throw new BusinessException("没有找到供应商{0}开票地址,不能出现寄售负数库存。", consignmentSupplier); } uom = itemInstance.Uom; billAddr = ba; //指定供应商的一定是寄售结算 billTerm = CodeMaster.OrderBillTerm.OnlineBilling; uc = itemInstance.UnitCount; baseUom = itemInstance.Uom; } PlanBill planBill = this.genericMgr.FindEntityWithNativeSql<PlanBill>("select * from BIL_PlanBill where Item = ? and BillAddr = ? and BillTerm = ?", new object[] { item, billAddr, billTerm }).FirstOrDefault(); #region 没有PlanBill,创建PlanBill if (planBill == null) { planBill = new PlanBill(); planBill.Type = com.Sconit.CodeMaster.BillType.Procurement; planBill.Party = consignmentSupplier; planBill.Item = item; planBill.ItemDescription = this.genericMgr.FindById<Item>(item).Description; planBill.Uom = uom; planBill.UnitCount = uc; planBill.BillTerm = billTerm; planBill.BillAddress = billAddr; planBill.PlanAmount = 0; if (baseUom != uom) { planBill.UnitQty = itemMgr.ConvertItemUomQty(item, baseUom, 1, uom); } else { planBill.UnitQty = 1; } planBill.PlanQty = 0; planBill.EffectiveDate = effectiveDate; this.genericMgr.Create(planBill); } #endregion else { planBill.CurrentVoidQty = 0; planBill.CurrentCancelVoidQty = 0; planBill.CurrentActingQty = 0; planBill.CurrentLocation = null; planBill.CurrentHuId = null; planBill.CurrentActingBill = null; planBill.CurrentBillTransaction = null; } return planBill; }