using BWP.B3ButcherManage.BO;
|
|
using BWP.B3ExportBase;
|
|
using BWP.B3ExportBase.BL;
|
|
using BWP.B3ExportBase.BO;
|
|
using BWP.B3Frameworks;
|
|
using Forks.EnterpriseServices;
|
|
using Forks.EnterpriseServices.BusinessInterfaces;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TSingSoft.WebPluginFramework;
|
|
using TSingSoft.WebPluginFramework.BIPlugins.BLEvents;
|
|
|
|
namespace BWP.B3ButcherManageExport.BL
|
|
{
|
|
[BusinessInterface(typeof(StatPayToNcBL))]
|
|
public interface IStatPayToNcBL : INcBL<StatPay>
|
|
{
|
|
void Export(List<long> idList, long p, DateTime? nullable);
|
|
|
|
string UpdateExportState(List<long> idList);
|
|
}
|
|
|
|
[LogicName("结算单导NC凭证")]
|
|
[BindToFeature("B3ButcherManageExport.0008")]
|
|
[ExportID(B3FrameworksConsts.DmoTypeIDBases.B3ButcherManageExport, B3ButcherManageExportConsts.ExportIDOffsets.StatPayToNc)]
|
|
public class StatPayToNcBL : NcBL<StatPay>, IStatPayToNcBL
|
|
{
|
|
public readonly List<string> MinPreDetailProperties = new List<string>();
|
|
public long AbnormalItem_ID = 0;
|
|
protected override NcUfinterface CreateUfinterface(IList<StatPay> dmos)
|
|
{
|
|
if (AbnormalItem_ID != 0)
|
|
{
|
|
var details = FillExceptionDetail(dmos.Select(x => x.ID));
|
|
foreach (var dmo in dmos)
|
|
{
|
|
var first = details.FirstOrDefault(x => x.StatPay_ID == dmo.ID);
|
|
if (first != null)
|
|
{
|
|
dmo.Money = dmo.Money - first.Money;
|
|
dmo.ExceptionDetails.Add(first);
|
|
}
|
|
}
|
|
}
|
|
|
|
var scriptHelper = new PythonScriptHelper(string.Empty, Config.Script, this);
|
|
scriptHelper.AddLocalVar("dmos", dmos);
|
|
if (Version == "6.3")
|
|
{
|
|
{
|
|
var bills = BO.NcVouchers.New();
|
|
scriptHelper.AddLocalVar("vouchers", bills);
|
|
scriptHelper.Execute();
|
|
var i = 0;
|
|
foreach (var bill in bills.Bills)
|
|
{
|
|
BillIDs.Add(i, bill.B2BillIDs);
|
|
i++;
|
|
}
|
|
return bills;
|
|
}
|
|
}
|
|
throw new Exception("未实现导出方法");
|
|
}
|
|
|
|
public override short GetMethodID()
|
|
{
|
|
return B3FrameworksConsts.DmoTypeIDBases.B3ButcherManageExport + B3ButcherManageExportConsts.ExportIDOffsets.StatPayToNc;
|
|
}
|
|
|
|
public DateTime Date { get; set; }
|
|
public void Export(List<long> dmoIDs, long extSystemID, DateTime? date)
|
|
{
|
|
Date = date ?? BLContext.Today;
|
|
Export(dmoIDs, extSystemID);
|
|
}
|
|
|
|
public void CheckAccountingUnit(IEnumerable<StatPay> dmos)
|
|
{
|
|
var groups = dmos.GroupBy(x => x.AccountingUnit_Name);
|
|
var count = groups.Count();
|
|
if (count > 1)
|
|
{
|
|
throw new ApplicationException("一次导出只能选择同一个会计单位下的单据");
|
|
}
|
|
}
|
|
|
|
public string UpdateExportState(List<long> idList)
|
|
{
|
|
CheckExportLog(idList);
|
|
var returnMess = "";
|
|
foreach (var id in idList)
|
|
{
|
|
var log = new ExportLog
|
|
{
|
|
BackInfo = string.Empty,
|
|
BillTypeID = DmoTypeIDAttribute.GetID(typeof(StatPay)),
|
|
BillID = id,
|
|
WpfUser_ID = BLContext.User.ID,
|
|
Time = BLContext.Now,
|
|
MethodID = ExportIDAttribute.GetID(GetType()),
|
|
StatusInfo = string.Empty
|
|
};
|
|
Session.Insert(log);
|
|
returnMess += string.Format("No.{0} ", id);
|
|
}
|
|
return returnMess;
|
|
}
|
|
|
|
IEnumerable<StatPay_Exception> FillExceptionDetail(IEnumerable<long> ids)
|
|
{
|
|
var query = new DQueryDom(new JoinAlias(typeof(StatPay_Exception)));
|
|
query.Columns.Add(DQSelectColumn.Field("StatPay_ID"));
|
|
query.Columns.Add(DQSelectColumn.Sum("Money"));
|
|
query.GroupBy.Expressions.Add(DQExpression.Field("StatPay_ID"));
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("AbnormalItem_ID", AbnormalItem_ID), DQCondition.InList(DQExpression.Field("StatPay_ID"), ids.Select(x => DQExpression.Value(x)).ToArray())));
|
|
query.Where.Conditions.Add(DQCondition.InEQ(DQExpression.IfNull(DQExpression.Field("Money"), DQExpression.Value(0)), DQExpression.Value(0)));
|
|
var list = new List<StatPay_Exception>();
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
using (var reader = session.ExecuteReader(query))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
list.Add(new StatPay_Exception()
|
|
{
|
|
StatPay_ID = (long)reader[0],
|
|
Money = Convert.ToDecimal(reader[1] ?? 0)
|
|
});
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
}
|