|
|
|
@ -7,6 +7,12 @@ using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using BWP.B3Frameworks; |
|
|
|
using BWP.B3Frameworks.BO.NamedValueTemplate; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery; |
|
|
|
using Forks.EnterpriseServices.SqlDoms; |
|
|
|
using Forks.Utils; |
|
|
|
using TSingSoft.WebPluginFramework; |
|
|
|
|
|
|
|
namespace BWP.B3SubstituteKill.BL |
|
|
|
@ -32,5 +38,127 @@ namespace BWP.B3SubstituteKill.BL |
|
|
|
dmo.Weight = dmo.Details.Sum(x => x.Weight.EToDecimal() ?? 0); |
|
|
|
base.beforeSave(dmo); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void doUnCheck(SubKillWeightBill dmo) |
|
|
|
{ |
|
|
|
DeleteNotCheckedStatPay(dmo); |
|
|
|
base.doUnCheck(dmo); |
|
|
|
} |
|
|
|
|
|
|
|
private void DeleteNotCheckedStatPay(SubKillWeightBill dmo) |
|
|
|
{ |
|
|
|
var queryDom = new DQueryDom(new JoinAlias(typeof(StatPay))); |
|
|
|
queryDom.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
|
queryDom.Where.Conditions.Add(DQCondition.EQ("Weigh_ID", dmo.ID)); |
|
|
|
var id = (long?)Session.ExecuteScalar(queryDom); |
|
|
|
if (id == null) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
var statPayBL = BIFactory.Create<IStatPayBL>(Session); |
|
|
|
var statPay = statPayBL.Load(id.Value); |
|
|
|
if (statPay != null) |
|
|
|
{ |
|
|
|
if (statPay.BillState != 单据状态.未审核) |
|
|
|
{ |
|
|
|
throw new ApplicationException("结算单 No." + statPay.ID + statPay.BillState + ",不能执行此操作。"); |
|
|
|
} |
|
|
|
statPayBL.Delete(statPay); |
|
|
|
AppendMessage("删除结算单No." + statPay.ID); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected override void doCheck(SubKillWeightBill dmo) |
|
|
|
{ |
|
|
|
CreateStatPay(dmo); |
|
|
|
base.doCheck(dmo); |
|
|
|
} |
|
|
|
|
|
|
|
private void CreateStatPay(SubKillWeightBill dmo) |
|
|
|
{ |
|
|
|
var statPay = new StatPay(); |
|
|
|
statPay.AccountingUnit_ID = dmo.AccountingUnit_ID; |
|
|
|
statPay.Domain_ID = dmo.Domain_ID; |
|
|
|
statPay.Department_ID = dmo.Department_ID; |
|
|
|
statPay.Employee_ID = dmo.Employee_ID; |
|
|
|
statPay.Date = dmo.Date; |
|
|
|
statPay.Weigh_ID = dmo.ID; |
|
|
|
statPay.Supplier_ID = dmo.Supplier_ID; |
|
|
|
statPay.Number = dmo.Number; |
|
|
|
statPay.Weight = dmo.Weight; |
|
|
|
statPay.PriceBill_ID = dmo.PriceBill_ID; |
|
|
|
|
|
|
|
var subKillPriceBill = GetSubKillPriceBill(dmo); |
|
|
|
if (subKillPriceBill != null) |
|
|
|
{ |
|
|
|
foreach (SubKillWeightBill_Detail wdetail in dmo.Details) |
|
|
|
{ |
|
|
|
foreach (SubKillPriceBill_CostItemDetail costItemDetail in subKillPriceBill.CostItemDetails) |
|
|
|
{ |
|
|
|
var detail = new StatPay_CostDetail(); |
|
|
|
detail.SubKillProductLine_ID = wdetail.SubKillProductLine_ID; |
|
|
|
detail.GenerationCostItem_ID = costItemDetail.GenerationCostItem_ID; |
|
|
|
detail.Price = costItemDetail.Price; |
|
|
|
detail.Number = wdetail.Number; |
|
|
|
detail.Money = detail.Price * detail.Number; |
|
|
|
statPay.CostDetails.Add(detail); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (SubKillPriceBill_CallBackDetail callBackDetail in subKillPriceBill.CallBackDetails) |
|
|
|
{ |
|
|
|
var detail = new StatPay_CallbackPayDetail(); |
|
|
|
detail.SubKillCallBack_ID = callBackDetail.SubKillCallBack_ID; |
|
|
|
detail.Price = callBackDetail.Price; |
|
|
|
detail.Money = callBackDetail.Price * wdetail.Number; |
|
|
|
statPay.CallbackPayDetails.Add(detail); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
foreach (SubKillWeightBill_Detail wdetail in dmo.Details) |
|
|
|
{ |
|
|
|
var detail = new StatPay_CostDetail(); |
|
|
|
detail.SubKillProductLine_ID = wdetail.SubKillProductLine_ID; |
|
|
|
detail.Number = wdetail.Number; |
|
|
|
detail.Money = detail.Price * detail.Number; |
|
|
|
statPay.CostDetails.Add(detail); |
|
|
|
} |
|
|
|
} |
|
|
|
BIFactory.Create<IStatPayBL>(Session).Insert(statPay); |
|
|
|
AppendMessage("生成代宰结算单:" + statPay.ID); |
|
|
|
} |
|
|
|
|
|
|
|
private SubKillPriceBill GetSubKillPriceBill(SubKillWeightBill dmo) |
|
|
|
{ |
|
|
|
var pricebillid = GetSubKillPriceBillID(dmo); |
|
|
|
if (pricebillid == null) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
var pricebill = BIFactory.Create<ISubKillPriceBillBL>(Session).Load(pricebillid.Value); |
|
|
|
return pricebill; |
|
|
|
} |
|
|
|
|
|
|
|
private long? GetSubKillPriceBillID(SubKillWeightBill dmo) |
|
|
|
{ |
|
|
|
var bill = new JoinAlias(typeof(SubKillPriceBill)); |
|
|
|
var detail = new JoinAlias(typeof(SubKillPriceBill_SupplierDetail)); |
|
|
|
var query = new DQueryDom(bill); |
|
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(bill, "ID", detail, "SubKillPriceBill_ID")); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ(bill, "Domain_ID", DomainContext.Current.ID)); |
|
|
|
query.Where.Conditions.Add(DQCondition.LessThanOrEqual("Date", dmo.Date)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ(bill, "AccountingUnit_ID", dmo.AccountingUnit_ID)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ(bill, "Department_ID", dmo.Department_ID)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("BillState", 单据状态.已审核)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ(detail, "Supplier_ID", dmo.Supplier_ID)); |
|
|
|
|
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true)); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID", bill)); |
|
|
|
|
|
|
|
return query.EExecuteScalar<long?>(Session); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |