using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BWP.B3ButcherManage.BO;
|
|
using BWP.B3ExportBase;
|
|
using BWP.B3ExportBase.BL;
|
|
using BWP.B3Frameworks;
|
|
using Forks.EnterpriseServices;
|
|
using Forks.EnterpriseServices.BusinessInterfaces;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
using TSingSoft.WebPluginFramework;
|
|
|
|
namespace BWP.B3ButcherManageExport.BL {
|
|
[BusinessInterface(typeof(StatPayToEasVoucherBL))]
|
|
public interface IStatPayToEasVoucherBL : IEasVoucherBL<StatPay> {
|
|
void Export(List<long> dmoIDs, long extSystemID, DateTime? date);
|
|
}
|
|
|
|
[LogicName("屠宰结算单导EAS凭证")]
|
|
[BindToFeature("B3ButcherManageExport.0002")]
|
|
[ExportID(B3FrameworksConsts.DmoTypeIDBases.B3ButcherManageExport,
|
|
B3ButcherManageExportConsts.ExportIDOffsets.StatPayToEasVoucher)]
|
|
public class StatPayToEasVoucherBL : EasVoucherBL<StatPay>, IStatPayToEasVoucherBL {
|
|
private DateTime _date;
|
|
|
|
public DateTime Date {
|
|
get { return _date; }
|
|
set { _date = value; }
|
|
}
|
|
|
|
public List<string> MinOtherRewardDetailProperties { get; set; }
|
|
|
|
public void Export(List<long> dmoIDs, long extSystemID, DateTime? date) {
|
|
_date = date ?? BLContext.Today;
|
|
MinOtherRewardDetailProperties = new List<string>();
|
|
Export(dmoIDs, extSystemID);
|
|
}
|
|
|
|
public IEnumerable<StatPay_Butcher> GetDetails(IEnumerable<StatPay> dmos) {
|
|
var details = new List<StatPay_Butcher>();
|
|
foreach (var dmo in dmos) {
|
|
foreach (var detail in dmo.Details) {
|
|
details.Add(detail);
|
|
}
|
|
}
|
|
return details;
|
|
}
|
|
|
|
public IEnumerable GroupByDate(IEnumerable<StatPay> dmos) {
|
|
return dmos.GroupBy(x => (x.Date ?? BLContext.Today).Date);
|
|
}
|
|
|
|
public IEnumerable GroupByMonth(IEnumerable<StatPay> dmos) {
|
|
return dmos.GroupBy(x => (x.Date ?? BLContext.Today).Month);
|
|
}
|
|
|
|
public IEnumerable GroupBySupplier(IEnumerable<StatPay> dmos) {
|
|
return dmos.GroupBy(x => x.Supplier_ID);
|
|
}
|
|
|
|
public IEnumerable<StatPay_OtherReward> GetOtherRewardDetails(IEnumerable<StatPay> dmos) {
|
|
var details = new List<StatPay_OtherReward>();
|
|
foreach (var dmo in dmos) {
|
|
foreach (var detail in dmo.OtherRewardDetails) {
|
|
details.Add(detail);
|
|
}
|
|
}
|
|
return details;
|
|
}
|
|
|
|
public decimal ESumOtherRewardMoney(IEnumerable<StatPay> dmos) {
|
|
return ESumOtherRewardMoney(dmos, null);
|
|
}
|
|
|
|
public decimal ESumOtherRewardMoney(IEnumerable<StatPay> dmos, IList name) {
|
|
var details = GetOtherRewardDetails(dmos);
|
|
if (name == null || name.Count == 0)
|
|
return details.Sum(x => (x.Money ?? 0).Value);
|
|
var ds = details.Where(x => name.Contains(x.AbnormalItem_Name)).ToList();
|
|
return ds.Sum(x => (x.Money ?? 0).Value);
|
|
}
|
|
|
|
public decimal ESumDetailsMoney(IEnumerable<StatPay> dmos) {
|
|
var details = GetDetails(dmos);
|
|
return details.Sum(x => (x.Money ?? 0).Value);
|
|
}
|
|
|
|
public decimal SumDetailsMoney(IEnumerable<StatPay_Butcher> dmos) {
|
|
return dmos.Sum(x => (x.Money ?? 0).Value);
|
|
}
|
|
|
|
public decimal SumOtherRewardMoney(IEnumerable<StatPay_OtherReward> dmos) {
|
|
return dmos.Sum(x => (x.Money ?? 0).Value);
|
|
}
|
|
|
|
public decimal SumMoney(IEnumerable<StatPay> dmos) {
|
|
return dmos.Sum(x => (x.Money ?? 0).Value);
|
|
}
|
|
|
|
protected override Action<List<StatPay>> FillDetail {
|
|
get {
|
|
return dmos => {
|
|
AddDetails(dmos);
|
|
AddStatOtherRewardDetails(dmos);
|
|
};
|
|
}
|
|
}
|
|
|
|
private void AddDetails(List<StatPay> dmos) {
|
|
var dmoType = typeof(StatPay_Butcher);
|
|
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("StatPay_ID"), expressionList.ToArray()));
|
|
var details = new List<StatPay_Butcher>();
|
|
details.Clear();
|
|
using (IDQDataReader reader = Session.ExecuteReader(dom)) {
|
|
while (reader.Read()) {
|
|
var detail = new StatPay_Butcher {
|
|
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.StatPay_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);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void AddStatOtherRewardDetails(List<StatPay> dmos) {
|
|
var dmoType = typeof(StatPay_OtherReward);
|
|
var dom = new DQueryDom(new JoinAlias(dmoType));
|
|
dom.Columns.Add(DQSelectColumn.Field("ID"));
|
|
foreach (string property in MinOtherRewardDetailProperties) {
|
|
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("StatPay_ID"), expressionList.ToArray()));
|
|
var details = new List<StatPay_OtherReward>();
|
|
details.Clear();
|
|
using (IDQDataReader reader = Session.ExecuteReader(dom)) {
|
|
while (reader.Read()) {
|
|
var detail = new StatPay_OtherReward {
|
|
ID = (long)reader[0]
|
|
};
|
|
int i = 1;
|
|
foreach (var property in MinOtherRewardDetailProperties) {
|
|
dmoType.GetProperty(property).SetValue(detail, reader[i++], null);
|
|
}
|
|
details.Add(detail);
|
|
}
|
|
}
|
|
var groups = details.GroupBy(x => x.StatPay_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.OtherRewardDetails.Add(billDetail);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|