using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
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 TSingSoft.WebPluginFramework;
|
|
using TSingSoft.WebPluginFramework.BIPlugins.BLEvents;
|
|
using Forks.Utils;
|
|
|
|
namespace BWP.B3ButcherManageExport.BL
|
|
{
|
|
[BusinessInterface(typeof(PayToNcBL))]
|
|
public interface IPayToNcBL : INcBL<Pay>
|
|
{
|
|
void Export(List<long> idList, long p, DateTime? nullable);
|
|
}
|
|
|
|
[LogicName("付款单导NC凭证")]
|
|
[BindToFeature("B3ButcherManageExport.0004")]
|
|
[ExportID(B3FrameworksConsts.DmoTypeIDBases.B3ButcherManageExport, B3ButcherManageExportConsts.ExportIDOffsets.PayToNc)]
|
|
public class PayToNcBL : NcBL<Pay>, IPayToNcBL
|
|
{
|
|
public readonly List<string> MinPreDetailProperties = new List<string>();
|
|
protected override NcUfinterface CreateUfinterface(IList<Pay> dmos)
|
|
{
|
|
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.PayToNc;
|
|
}
|
|
|
|
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<Pay> dmos)
|
|
{
|
|
var groups = dmos.GroupBy(x => x.AccountingUnit_Name);
|
|
var count = groups.Count();
|
|
if (count > 1)
|
|
{
|
|
throw new ApplicationException("一次导出只能选择同一个会计单位下的单据");
|
|
}
|
|
}
|
|
|
|
public string GetStatPayDate(Pay dmo, string format)
|
|
{
|
|
if (dmo.Details.Count == 0)
|
|
return string.Empty;
|
|
return GetDateTime(dmo.Details[0].StatPay_Date, format);
|
|
}
|
|
|
|
public string GetSumMoney(IEnumerable<Pay_Detail> details)
|
|
{
|
|
return details.Sum(x => (x.Money ?? 0).Value).ToString();
|
|
}
|
|
|
|
public string GetSumServiceFee(IEnumerable<Pay_Detail> details)
|
|
{
|
|
return details.Sum(x => (x.ServiceFee ?? 0).Value).ToString();
|
|
}
|
|
|
|
public string GetSumAfterDiscont(IEnumerable<Pay_Detail> details)
|
|
{
|
|
return details.Sum(x => (x.AfterDiscont ?? 0).Value).ToString();
|
|
}
|
|
|
|
public string GetSumPreMoney(IEnumerable<Pay_AdvanceDetail> details)
|
|
{
|
|
return details.Sum(x => (x.AdvancePay_Money ?? 0).Value).ToString();
|
|
}
|
|
|
|
public string GetSumStatPay_Money1(IEnumerable<Pay_Detail> details)
|
|
{
|
|
return details.Sum(x => (x.StatPay_Money ?? 0).Value).ToString();
|
|
}
|
|
|
|
public string GetSumWeighBill_RealNumber(IEnumerable<Pay_Detail> details)
|
|
{
|
|
int? weighBillBuyNum = 0;
|
|
weighBillBuyNum = details.Sum(x => x.StatPay_RealNumber);
|
|
return (weighBillBuyNum ?? 0).ToString();
|
|
}
|
|
|
|
public string GetSumWeighBill_RealWeight(IEnumerable<Pay_Detail> details)
|
|
{
|
|
Money<decimal>? weighBillBuyWeigh1 = 0;
|
|
weighBillBuyWeigh1 = details.Sum(x => Convert.ToDecimal(x.StatPay_RealWeight));
|
|
return ((weighBillBuyWeigh1 ?? 0).Value).ToString("0.00");
|
|
}
|
|
|
|
public string GetSumWeighBill_BuyNum(IEnumerable<Pay_Detail> details)
|
|
{
|
|
int? weighBillBuyNum = 0;
|
|
foreach (var item in details.GroupBy(x => x.Weigh_ID))
|
|
{
|
|
var first = item.First();
|
|
weighBillBuyNum += first.WeighBill_BuyNum;
|
|
}
|
|
return (weighBillBuyNum ?? 0).ToString();
|
|
}
|
|
|
|
public string GetSumWeighBill_BuyWeigh1(IEnumerable<Pay_Detail> details)
|
|
{
|
|
Money<decimal>? weighBillBuyWeigh1 = 0;
|
|
foreach (var item in details.GroupBy(x => x.Weigh_ID))
|
|
{
|
|
var first = item.First();
|
|
weighBillBuyWeigh1 += first.WeighBill_BuyWeigh1;
|
|
}
|
|
return ((weighBillBuyWeigh1 ?? 0).Value).ToString("0.00");
|
|
}
|
|
|
|
protected override void BeforeExport(List<long> dmoIDs)
|
|
{
|
|
base.BeforeExport(dmoIDs);
|
|
var dmoType = typeof(Pay_AdvanceDetail);
|
|
var dom = new DQueryDom(new JoinAlias(dmoType));
|
|
dom.Columns.Add(DQSelectColumn.Field("ID"));
|
|
foreach (string property in MinPreDetailProperties)
|
|
{
|
|
dom.Columns.Add(DQSelectColumn.Field(property));
|
|
}
|
|
var expressionList = new List<IDQExpression>();
|
|
foreach (var dmo in Dmos)
|
|
expressionList.Add(DQExpression.Value(dmo.ID));
|
|
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("Pay_ID"), expressionList.ToArray()));
|
|
var details = new List<Pay_AdvanceDetail>();
|
|
using (IDQDataReader reader = Session.ExecuteReader(dom))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
var detail = new Pay_AdvanceDetail
|
|
{
|
|
ID = (long)reader[0]
|
|
};
|
|
int i = 1;
|
|
foreach (var property in MinPreDetailProperties)
|
|
{
|
|
var propertyInfo = dmoType.GetProperty(property);
|
|
if (propertyInfo != null)
|
|
propertyInfo.SetValue(detail, reader[i++], null);
|
|
}
|
|
details.Add(detail);
|
|
}
|
|
}
|
|
var groups = details.GroupBy(x => x.Pay_ID);
|
|
foreach (var gDetail in groups)
|
|
{
|
|
var firstDmo = Dmos.FirstOrDefault(x => x.ID == gDetail.Key);
|
|
if (firstDmo == null)
|
|
continue;
|
|
foreach (var billDetail in gDetail)
|
|
{
|
|
firstDmo.AdvanceDetails.Add(billDetail);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override Action<List<Pay>> FillDetail
|
|
{
|
|
get
|
|
{
|
|
return dmos =>
|
|
{
|
|
var dmoType = typeof(Pay_Detail);
|
|
var dom = new DQueryDom(new JoinAlias(dmoType));
|
|
dom.Columns.Add(DQSelectColumn.Field("ID"));
|
|
foreach (string property in MinDetailProperties)
|
|
{
|
|
dom.Columns.Add(DQSelectColumn.Field(property));
|
|
}
|
|
var expressionList = new List<IDQExpression>();
|
|
foreach (var dmo in dmos)
|
|
expressionList.Add(DQExpression.Value(dmo.ID));
|
|
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("Pay_ID"), expressionList.ToArray()));
|
|
var details = new List<Pay_Detail>();
|
|
using (IDQDataReader reader = Session.ExecuteReader(dom))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
var detail = new Pay_Detail
|
|
{
|
|
ID = (long)reader[0]
|
|
};
|
|
int i = 1;
|
|
foreach (var property in MinDetailProperties)
|
|
{
|
|
dmoType.GetProperty(property).SetValue(detail, reader[i++], null);
|
|
}
|
|
details.Add(detail);
|
|
}
|
|
}
|
|
var groups = details.GroupBy(x => x.Pay_ID);
|
|
foreach (var gDetail in groups)
|
|
{
|
|
var firstDmo = dmos.FirstOrDefault(x => x.ID == gDetail.Key);
|
|
if (firstDmo == null)
|
|
continue;
|
|
foreach (var billDetail in gDetail)
|
|
{
|
|
firstDmo.Details.Add(billDetail);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|