|
|
using CB = BWP.B3CowButcherManage.BO;
|
|
|
using BWP.B3CowButcherManage.NamedValueTemplate;
|
|
|
using BWP.B3Frameworks;
|
|
|
using BWP.B3Frameworks.BL;
|
|
|
using BWP.B3Frameworks.BO.NamedValueTemplate;
|
|
|
using BWP.B3SheepButcherManage.BO;
|
|
|
using Forks.EnterpriseServices;
|
|
|
using Forks.EnterpriseServices.BusinessInterfaces;
|
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
|
using Forks.EnterpriseServices.SimpleScript;
|
|
|
using Forks.EnterpriseServices.SqlDoms;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using TSingSoft.WebPluginFramework;
|
|
|
using BWP.B3Frameworks.Utils;
|
|
|
|
|
|
namespace BWP.B3SheepButcherManage.BL
|
|
|
{
|
|
|
[BusinessInterface(typeof(WeightBillBL))]
|
|
|
[LogicName("羊过磅单")]
|
|
|
public interface IWeightBillBL : IDepartmentWorkFlowBillBL<WeightBill>
|
|
|
{
|
|
|
void UpdateDetailOtherNumber(long p);
|
|
|
}
|
|
|
|
|
|
public class WeightBillBL : DepartmentWorkFlowBillBL<WeightBill>, IWeightBillBL
|
|
|
{
|
|
|
protected override void beforeSave(WeightBill dmo)
|
|
|
{
|
|
|
foreach (var detail in dmo.WeighRecords)
|
|
|
detail.RemainNumber = detail.Number;
|
|
|
if (dmo.WeighRecords.Count > 0)
|
|
|
{
|
|
|
dmo.BuyWeigh1 = dmo.WeighRecords.Sum(x => (x.Weight ?? 0).Value);
|
|
|
dmo.BuyNum = dmo.WeighRecords.Sum(x => (x.Number));
|
|
|
}
|
|
|
SetAbnormal_Money(dmo);
|
|
|
dmo.AbnormalMoney = dmo.WeighAbnormalRecording.Sum(x => (x.Abnormal_Money ?? 0).Value);
|
|
|
base.beforeSave(dmo);
|
|
|
}
|
|
|
|
|
|
public void SetAbnormal_Money(WeightBill dmo)
|
|
|
{
|
|
|
if (dmo.WeighAbnormalRecording.Count <= 0)
|
|
|
return;
|
|
|
var sanction = new JoinAlias(typeof(CB.SanctionSetting));
|
|
|
var abnormalItem = new JoinAlias(typeof(CB.RewardItem));
|
|
|
var dom = new DQueryDom(sanction);
|
|
|
dom.From.AddJoin(JoinType.Inner, new DQDmoSource(abnormalItem),
|
|
|
DQCondition.EQ(sanction, "RewardItem_ID", abnormalItem, "ID"));
|
|
|
dom.Columns.Add(DQSelectColumn.Field("ID", abnormalItem));
|
|
|
dom.Columns.Add(DQSelectColumn.Field("ID", sanction));
|
|
|
dom.Columns.Add(DQSelectColumn.Field("Condition", sanction));
|
|
|
dom.Columns.Add(DQSelectColumn.Field("BeforeScript", sanction));
|
|
|
dom.Where.Conditions.Add(DQCondition.EQ(sanction, "FitBill", 奖罚设置适用单据类型.过磅单));
|
|
|
dom.Where.Conditions.Add(DQCondition.EQ("BillState", 单据状态.已审核));
|
|
|
dom.Where.Conditions.Add(DQCondition.EQ("Domain_ID", DomainContext.Current.ID));
|
|
|
dom.Where.Conditions.Add(DQCondition.EQ("AccountingUnit_ID", dmo.AccountingUnit_ID));
|
|
|
var sanctionList = dom.EExecuteList<long, long, string, string>(Session);
|
|
|
foreach (var detail in dmo.WeighAbnormalRecording)
|
|
|
{
|
|
|
var items = sanctionList.Where(x => x.Item1 == detail.RewardItem_ID);
|
|
|
if (items.Count() > 0)
|
|
|
{
|
|
|
var result = items.First();
|
|
|
var runner = new Runner();
|
|
|
runner.Global["奖罚依据"] = "";
|
|
|
runner.Execute(result.Item4);
|
|
|
var bType = TypeMarshal.AsString(runner.Global["奖罚依据"]);
|
|
|
if (bType == "过磅单")
|
|
|
{
|
|
|
runner.Global["单价"] = 0m;
|
|
|
runner.Execute(result.Item3);
|
|
|
detail.Abnormal_Money = TypeMarshal.AsNumber(runner.Global["单价"]);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
detail.Abnormal_Money = null;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
protected override void doCheck(WeightBill dmo)
|
|
|
{
|
|
|
var statPay = new StatPay();
|
|
|
|
|
|
var bl = BIFactory.Create<IStatPayBL>(Session);
|
|
|
bl.InitNewDmo(statPay);
|
|
|
statPay.Supplier_ID = dmo.Supplier_ID;
|
|
|
statPay.WeightBill_ID = dmo.ID;
|
|
|
statPay.WeighTime = dmo.WeighTime;
|
|
|
statPay.RealWeight = dmo.BuyWeigh1;
|
|
|
statPay.RealNumber = dmo.BuyNum;
|
|
|
statPay.Department_ID = dmo.Department_ID;
|
|
|
statPay.Employee_ID = dmo.Employee_ID;
|
|
|
statPay.AccountingUnit_ID = dmo.AccountingUnit_ID;
|
|
|
statPay.ValuationArea_ID = dmo.ValuationArea_ID;
|
|
|
if (dmo.MoneyCountMethod != null)
|
|
|
{
|
|
|
statPay.MoneyCountMethod = dmo.MoneyCountMethod.Value;
|
|
|
}
|
|
|
if (dmo.WeighAbnormalRecording.Count > 0)
|
|
|
{
|
|
|
foreach (var abnormal in dmo.WeighAbnormalRecording)
|
|
|
{
|
|
|
var exception = new StatPay_Exception();
|
|
|
exception.RewardItem_ID = abnormal.RewardItem_ID;
|
|
|
// exception.Price = abnormal;
|
|
|
exception.Money = (decimal?)abnormal.Abnormal_Money;
|
|
|
statPay.ExceptionDetails.Add(exception);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bl.Insert(statPay);
|
|
|
AppendMessage("生成结算单No." + statPay.ID);
|
|
|
base.doCheck(dmo);
|
|
|
}
|
|
|
|
|
|
protected override void doUnCheck(WeightBill dmo)
|
|
|
{
|
|
|
if (dmo.WeighRecords.Any(x => x.PlanNumber > 0 || x.ButcherNumber > 0))
|
|
|
throw new ApplicationException("过磅单已经排宰");
|
|
|
|
|
|
var stayPayBL = BIFactory.Create<IStatPayBL>(Session);
|
|
|
var queryDom = new DmoQuery(typeof(StatPay));
|
|
|
queryDom.Where.Conditions.Add(DQCondition.EQ("WeightBill_ID", dmo.ID));
|
|
|
foreach (StatPay pay in Session.ExecuteList(queryDom))
|
|
|
{
|
|
|
if (pay.BillState != 单据状态.未审核)
|
|
|
{
|
|
|
throw new Exception("结算单:" + pay.ID + " 单据状态不是未审核");
|
|
|
}
|
|
|
stayPayBL.Delete(pay);
|
|
|
AppendMessage("删除结算单No." + pay.ID);
|
|
|
}
|
|
|
base.doUnCheck(dmo);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新屠宰单明细的已计划数量,已屠宰数量,剩余数量
|
|
|
/// </summary>
|
|
|
public void UpdateDetailOtherNumber(long weighDetailID)
|
|
|
{
|
|
|
if (weighDetailID == 0)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
var butcher = new JoinAlias(typeof(Butcher));
|
|
|
var detail = new JoinAlias(typeof(Butcher_Detail));
|
|
|
var subQuery = new DQueryDom(detail);
|
|
|
subQuery.From.AddJoin(JoinType.Left, new DQDmoSource(butcher), DQCondition.EQ(detail, "Butcher_ID", butcher, "ID"));
|
|
|
subQuery.Where.Conditions.Add(DQCondition.EQ(detail, "Weigh_Detail_ID", weighDetailID));
|
|
|
subQuery.Where.Conditions.Add(DQCondition.InEQ(butcher, "BillState", 单据状态.已作废));
|
|
|
subQuery.Columns.Add(DQSelectColumn.Count());
|
|
|
subQuery.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(
|
|
|
DQExpression.LogicCase(DQCondition.IsNotNull(DQExpression.Field("Weight")), DQExpression.ConstValue(1), DQExpression.ConstValue(0))), "HasWeight"));
|
|
|
var tuple = subQuery.EExecuteScalar<long?, int?>(Session);
|
|
|
var planNumber = tuple.Item1 ?? 0;
|
|
|
var butcherNumber = tuple.Item2 ?? 0;
|
|
|
|
|
|
//var hurryDetail = new JoinAlias(typeof(HurryButcher_Detail));
|
|
|
//var hurry = new JoinAlias(typeof(HurryButcher));
|
|
|
//var hurryDom = new DQueryDom(hurryDetail);
|
|
|
//hurryDom.From.AddJoin(JoinType.Left, new DQDmoSource(hurry), DQCondition.EQ(hurryDetail, "HurryButcher_ID", hurry, "ID"));
|
|
|
//hurryDom.Where.Conditions.Add(DQCondition.EQ("Weigh_Detail_ID", weighDetailID));
|
|
|
//hurryDom.Where.Conditions.Add(DQCondition.Or(
|
|
|
// DQCondition.EQ(hurry, "BillState", 单据状态.已审核),
|
|
|
// DQCondition.EQ(hurry, "BillState", 单据状态.已完毕)));
|
|
|
//hurryDom.Columns.Add(DQSelectColumn.Sum("Number"));
|
|
|
//var hurryNumber = (int?)Session.ExecuteScalar(hurryDom);
|
|
|
|
|
|
//butcherNumber = (butcherNumber) + (hurryNumber ?? 0);
|
|
|
//planNumber = (planNumber) + (hurryNumber ?? 0);
|
|
|
|
|
|
var updatedom = new DQUpdateDom(typeof(WeightBill_Record));
|
|
|
updatedom.Where.Conditions.Add(DQCondition.EQ("ID", weighDetailID));
|
|
|
|
|
|
long weightid = InnerBLUtil.GetDmoPropertyByID<long>(Session, typeof(WeightBill_Record), "WeightBill_ID", weighDetailID);
|
|
|
|
|
|
updatedom.Columns.Add(new DQUpdateColumn("PlanNumber", planNumber));//已计划头数
|
|
|
updatedom.Columns.Add(new DQUpdateColumn("ButcherNumber", butcherNumber)); //已屠宰
|
|
|
updatedom.Columns.Add(new DQUpdateColumn("RemainNumber", DQExpression.Subtract(DQExpression.Field("Number"), DQExpression.Value(planNumber > butcherNumber ? planNumber : butcherNumber))));
|
|
|
//剩余头数
|
|
|
|
|
|
Session.ExecuteNonQuery(updatedom);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|