|
|
|
@ -0,0 +1,238 @@ |
|
|
|
using BWP.B3Frameworks; |
|
|
|
using BWP.B3Frameworks.BO.NamedValueTemplate; |
|
|
|
using BWP.Web.Layout; |
|
|
|
using BWP.Web.Utils; |
|
|
|
using BWP.Web.WebControls; |
|
|
|
using Forks.EnterpriseServices.DataForm; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery; |
|
|
|
using Forks.EnterpriseServices.SqlDoms; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using TSingSoft.WebControls2; |
|
|
|
using BWP.B3Butchery.BO; |
|
|
|
using BWP.B3ProduceUnitedInfos; |
|
|
|
using BWP.B3UnitedInfos; |
|
|
|
using BWP.B3UnitedInfos.BO; |
|
|
|
using BWP.B3Sale.Utils; |
|
|
|
using BWP.B3Sale.BO; |
|
|
|
using BWP.B3Frameworks.BO; |
|
|
|
using Forks.Utils; |
|
|
|
using BWP.B3Frameworks.BO.MoneyTemplate; |
|
|
|
|
|
|
|
namespace BWP.Web.Pages.B3YunKen.Reports |
|
|
|
{ |
|
|
|
class EmployeeExamineReport : DFBrowseGridReportPage<CustomerAccept> |
|
|
|
{ |
|
|
|
protected override string Caption |
|
|
|
{ |
|
|
|
get { return "业务员考核表"; } |
|
|
|
} |
|
|
|
|
|
|
|
protected override string QueryOptionsTabName |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return "显示字段"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected override string AccessRoleName |
|
|
|
{ |
|
|
|
get { return "B3_YunKen.报表分析.业务员考核表"; } |
|
|
|
} |
|
|
|
|
|
|
|
readonly Dictionary<string, DFInfo> _fileInfo = new Dictionary<string, DFInfo>(); |
|
|
|
readonly List<string> _sumCol = new List<string>(); |
|
|
|
|
|
|
|
protected override void AddQueryControls(VLayoutPanel vPanel) |
|
|
|
{ |
|
|
|
var layout = new LayoutManager("Main", mDFInfo, mQueryContainer); |
|
|
|
layout.Add("LoadTime", new SimpleLabel("到货时间"), QueryCreator.DateRange(mDFInfo.Fields["ID"], mQueryContainer, "MinLoadTime", "MaxLoadTime")); |
|
|
|
layout["LoadTime"].NotAutoAddToContainer = true; |
|
|
|
layout.Add("AccountingUnit_ID", new SimpleLabel("会计单位"), QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["AccountingUnit_ID"], mQueryContainer, "AccountingUnit_ID", B3FrameworksConsts.DataSources.授权会计单位全部)); |
|
|
|
layout["AccountingUnit_ID"].NotAutoAddToContainer = true; |
|
|
|
layout.Add("Employee_ID", new SimpleLabel("业务员"), QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["Employee_ID"], mQueryContainer, "Employee_ID", B3FrameworksConsts.DataSources.授权员工全部)); |
|
|
|
layout["Employee_ID"].NotAutoAddToContainer = true; |
|
|
|
var config = new AutoLayoutConfig { Cols = 2 }; |
|
|
|
config.Add("LoadTime"); |
|
|
|
config.Add("AccountingUnit_ID"); |
|
|
|
config.Add("Employee_ID"); |
|
|
|
layout.Config = config; |
|
|
|
vPanel.Add(layout.CreateLayout()); |
|
|
|
} |
|
|
|
|
|
|
|
ReportDisplayOptionHelper mDisplayHelper = new ReportDisplayOptionHelper(); |
|
|
|
protected override void AddQueryOptions(VLayoutPanel vPanel) |
|
|
|
{ |
|
|
|
mDisplayHelper.AddOptionItem("单号", "main", "ID", false); |
|
|
|
mDisplayHelper.AddOptionItem("业务员", "main", "Employee_Name", false); |
|
|
|
mDisplayHelper.AddOptionItem("购货客户", "main", "Customer_Name", false); |
|
|
|
mDisplayHelper.AddOptionItem("会计单位", "main", "AccountingUnit_Name", false); |
|
|
|
mDisplayHelper.AddOptionItem("验收金额", "main", "Money", false, false); |
|
|
|
mDisplayHelper.AddOptionItem("发货时间", "main", "LoadTime", false); |
|
|
|
mDisplayHelper.AddOptionItem("最近一次核销时间", "gatheringTimeData", "GatheringTime", false); |
|
|
|
mDisplayHelper.AddOptionItem("账期天数", "cus", "CreditDays", false); |
|
|
|
mDisplayHelper.AddOptionItem("账期阶段", () => { |
|
|
|
return DQExpression.Snippet<int>("ceiling(cast((datediff(dd,main.LoadTime,getdate())-isNull(cus.CreditDays,0)) as decimal(18,2))/5)"); |
|
|
|
}, false); |
|
|
|
mDisplayHelper.AddOptionItem("超期天数", () => { |
|
|
|
return DQExpression.Snippet<int>("datediff(dd,main.LoadTime,getdate())"); |
|
|
|
}, false); |
|
|
|
mDisplayHelper.AddOptionItem("已扣罚金额", () => { return DQExpression.Value(0); }, false,true,false); |
|
|
|
mDisplayHelper.AddOptionItem("本次扣罚金额", () => { return DQExpression.Value(0); }, false, true, false); |
|
|
|
mDisplayHelper.AddOptionItem("总扣罚金额", () => { return DQExpression.Value(0); }, false, true, false); |
|
|
|
mDisplayHelper.AddOptionItem("时间段扣罚金额", () => { return DQExpression.Value(0); }, false, true, false); |
|
|
|
AddQueryOption("选项", mDisplayHelper.GetAllDisplayNames(), mDisplayHelper.GetDefaultSelelectedDisplayNames()); |
|
|
|
base.AddQueryOptions(vPanel); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void CreateDFBrowseGridColumns(DFBrowseGrid grid) |
|
|
|
{ |
|
|
|
grid.Columns.Add(new DFBrowseGridAutoColumn()); |
|
|
|
grid.DataFilter = delegate(DFDataTable tbl) { |
|
|
|
using (IDmoSession session = Dmo.NewSession()) { |
|
|
|
var minDate = mQueryContainer.GetControl<DFDateInput>("MinLoadTime"); |
|
|
|
var maxDate = mQueryContainer.GetControl<DFDateInput>("MaxLoadTime"); |
|
|
|
for (int i = 0; i < tbl.Rows.Count; i++) { |
|
|
|
DFDataRow row = tbl.Rows[i]; |
|
|
|
var id = (long?)row["单号"]; |
|
|
|
var money = (Money<金额>?)row["验收金额"]; |
|
|
|
int num = Convert.ToInt32(Math.Truncate(Convert.ToDouble(row["账期阶段"] ?? 0))); |
|
|
|
long? days = (long?)row["账期天数"]; |
|
|
|
DateTime? loadTime = (DateTime?)row["发货时间"]; |
|
|
|
if (loadTime == null) |
|
|
|
continue; |
|
|
|
row["已扣罚金额"] = GetSumMoney((num - 1), money, session,id,days,loadTime, false); |
|
|
|
row["本次扣罚金额"] = GetSumMoney(num, money, session,id,days,loadTime, true); |
|
|
|
row["总扣罚金额"] = GetSumMoney(num, money, session,id,days,loadTime, false); |
|
|
|
//时间段 初末 值分别是哪个账期
|
|
|
|
|
|
|
|
if(!minDate.IsEmpty){ |
|
|
|
TimeSpan ts = minDate.Value.Value - loadTime.Value; |
|
|
|
int result = Convert.ToInt32(Math.Truncate(Convert.ToDouble((ts.Days - (days??0))/5))); |
|
|
|
var min = GetSumMoney(result, money, session, id, days, loadTime, false); |
|
|
|
|
|
|
|
TimeSpan ts2 = maxDate.Value.Value - loadTime.Value; |
|
|
|
int result2 = Convert.ToInt32(Math.Truncate(Convert.ToDouble((ts2.Days - (days ?? 0)) / 5))); |
|
|
|
var max = GetSumMoney(result2, money, session, id, days, loadTime, false); |
|
|
|
row["时间段扣罚金额"] = (max??0) - (min??0); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
GetSumValue(tbl, "已扣罚金额"); |
|
|
|
GetSumValue(tbl, "本次扣罚金额"); |
|
|
|
GetSumValue(tbl, "总扣罚金额"); |
|
|
|
GetSumValue(tbl, "时间段扣罚金额"); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
public void GetSumValue(DFDataTable tbl, string cName) |
|
|
|
{ |
|
|
|
var sum1 = tbl.Rows.Sum(row => { |
|
|
|
if (row[cName] == null) return 0; |
|
|
|
return Convert.ToDecimal(row[cName]); |
|
|
|
}); |
|
|
|
tbl.SumRow[cName] = sum1; |
|
|
|
} |
|
|
|
|
|
|
|
private int GetRange(long? AccountBill_ID, string date, IDmoSession session) |
|
|
|
{ |
|
|
|
var dom = new DQueryDom(new JoinAlias(typeof(CustomerAccept))); |
|
|
|
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Snippet<int>("ceiling(cast((datediff(dd,LoadTime,'" + date + "')-isNull(Days,0)) as decimal(18,2))/5)"), "RangeNumber")); |
|
|
|
dom.GroupBy.Expressions.Add(DQExpression.Field("LoadTime")); |
|
|
|
dom.GroupBy.Expressions.Add(DQExpression.Field("Days")); |
|
|
|
dom.Where.Conditions.Add(DQCondition.EQ("AccountBill_ID", AccountBill_ID)); |
|
|
|
using (var reader = session.ExecuteReader(dom)) { |
|
|
|
if (reader.Read()) { |
|
|
|
return Convert.ToInt32(reader[0]); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 传入参数第几个账期
|
|
|
|
/// </summary>
|
|
|
|
private Money<金额>? GetSumMoney(int? count, Money<金额>? money, IDmoSession session, long? id, long? days, DateTime? loadTime, bool isLast) |
|
|
|
{ |
|
|
|
Money<金额>? sumMoney = 0; |
|
|
|
for (int i = 0; i < (count ?? 0); i++) { |
|
|
|
if (isLast) { |
|
|
|
i = (count ?? 0) - 1; |
|
|
|
} |
|
|
|
var result = (days??0) + (i*5); |
|
|
|
loadTime.Value.AddDays(result); |
|
|
|
var invoiceInfo = new JoinAlias(typeof(InvoiceInfo)); |
|
|
|
var gathering = new JoinAlias(typeof(Gathering)); |
|
|
|
var dom = new DQueryDom(invoiceInfo); |
|
|
|
dom.From.AddJoin(JoinType.Left, new DQDmoSource(gathering), DQCondition.EQ(invoiceInfo, "Gathering_ID",gathering,"ID")); |
|
|
|
dom.Columns.Add(DQSelectColumn.Sum(invoiceInfo,"Money")); |
|
|
|
dom.Where.Conditions.Add(DQExpression.LessThanOrEqual(DQExpression.Field(gathering,"GatheringTime"),DQExpression.Value(loadTime))); |
|
|
|
dom.Where.Conditions.Add(DQCondition.EQ(invoiceInfo,"BillID", id)); |
|
|
|
dom.Where.Conditions.Add(DQCondition.EQ(invoiceInfo, "DmoTypeID", DmoTypeIDAttribute.GetID(typeof(CustomerAccept)))); |
|
|
|
dom.Where.Conditions.Add(DQCondition.EQ(gathering,"BillState", 单据状态.已审核)); |
|
|
|
using (var reader = session.ExecuteReader(dom)) { |
|
|
|
decimal sum = 0; |
|
|
|
while (reader.Read()) { |
|
|
|
if (reader[0] != null) { |
|
|
|
sum = Convert.ToDecimal(reader[0]);//已收款金额累计
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Money<金额>? noCancelMoney = money - sum; |
|
|
|
if (i == 0) { |
|
|
|
sumMoney = sumMoney + noCancelMoney * 4 / 10000; |
|
|
|
} else { |
|
|
|
sumMoney = sumMoney + noCancelMoney * 1 / 10000; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return sumMoney; |
|
|
|
} |
|
|
|
|
|
|
|
private DQueryDom GetGatheringTime() |
|
|
|
{ |
|
|
|
var bill = new JoinAlias(typeof(Gathering)); |
|
|
|
var detail = new JoinAlias(typeof(InvoiceInfo)); |
|
|
|
var query = new DQueryDom(bill); |
|
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(bill, "ID", detail, "Gathering_ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Max("GatheringTime")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("BillID",detail)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ(detail, "DmoTypeID",DmoTypeIDAttribute.GetID(typeof(CustomerAccept)))); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("BillState", 单据状态.已审核)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("Domain_ID", DomainContext.Current.ID)); |
|
|
|
query.GroupBy.Expressions.Add(DQExpression.Field(detail,"BillID")); |
|
|
|
return query; |
|
|
|
} |
|
|
|
|
|
|
|
class GatheringTimeData |
|
|
|
{ |
|
|
|
public DateTime? GatheringTime { get; set; } |
|
|
|
public long? BillID { get; set; } |
|
|
|
} |
|
|
|
|
|
|
|
protected override DQueryDom GetQueryDom() |
|
|
|
{ |
|
|
|
var query = base.GetQueryDom(); |
|
|
|
var main = query.From.RootSource.Alias; |
|
|
|
mDisplayHelper.AddAlias("main", main); |
|
|
|
var gatheringTimeData = new JoinAlias("gatheringTimeData", typeof(GatheringTimeData)); |
|
|
|
mDisplayHelper.AddAlias("gatheringTimeData", gatheringTimeData); |
|
|
|
var cus = new JoinAlias("cus", typeof(Customer)); |
|
|
|
mDisplayHelper.AddAlias("cus", cus); |
|
|
|
query.RegisterQueryTable(typeof(GatheringTimeData), new string[] { "GatheringTime", "BillID" }, GetGatheringTime()); |
|
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(gatheringTimeData), DQCondition.EQ(main, "ID", gatheringTimeData, "BillID")); |
|
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(cus), DQCondition.EQ(main, "Customer_ID", cus, "ID")); |
|
|
|
//query.Columns.Add(DQSelectColumn.Field("Money",main));
|
|
|
|
//query.Columns.Add(DQSelectColumn.Field("LoadTime", main));
|
|
|
|
//query.GroupBy.Expressions.Add(DQExpression.Field(main,"LoadTime"));
|
|
|
|
//query.GroupBy.Expressions.Add(DQExpression.Field(main, "Money"));
|
|
|
|
mDisplayHelper.AddSelectColumns(query, (name) => OptionIsSelected("选项", name), SumColumnIndexs); |
|
|
|
return query; |
|
|
|
} |
|
|
|
} |
|
|
|
} |