You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

141 lines
5.4 KiB

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;
namespace BWP.B3SheepButcherManage.BL
{
[BusinessInterface(typeof(WeightBillBL))]
[LogicName("羊过磅单")]
public interface IWeightBillBL : IDepartmentWorkFlowBillBL<WeightBill>
{ }
public class WeightBillBL : DepartmentWorkFlowBillBL<WeightBill>, IWeightBillBL
{
protected override void beforeSave(WeightBill dmo)
{
if (dmo.WeighRecords.Count > 0)
{
dmo.BuyWeigh1 = dmo.WeighRecords.Sum(x => (x.Weight ?? 0).Value);
dmo.BuyNum = dmo.WeighRecords.Sum(x => (x.Number));
}
//dmo.AlreadyButcherNum = dmo.WeighRecords.Count(x => x.IsButchered);
dmo.AbnormalMoney = dmo.WeighAbnormalRecording.Sum(x => (x.Abnormal_Money ?? 0).Value);
SetAbnormal_Money(dmo);
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)
{
//if (dmo.WeighShedWeight.Count <= 0)
//{
// var statPay = new StatPay();
// var bl = BIFactory.Create<IStatPayBL>(Session);
// bl.InitNewDmo(statPay);
// statPay.Supplier_ID = dmo.Supplier_ID;
// statPay.BillType = mDmoTypeID;
// statPay.Weigh_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.FarmingContract_ID = dmo.FarmingContract_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.ExceptDetails.Add(exception);
// }
// }
// bl.Insert(statPay);
// AppendMessage("生成结算单No." + statPay.ID);
//}
base.doCheck(dmo);
}
protected override void doUnCheck(WeightBill dmo)
{
//var stayPayBL = BIFactory.Create<IStatPayBL>(Session);
//var queryDom = new DmoQuery(typeof(StatPay));
//queryDom.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BillType", mDmoTypeID), DQCondition.EQ("Weigh_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);
}
}
}