--
原来的主要代码:
Dim fh As String
Dim tb As Table = Tables("应收账龄日报")
Dim dt As DataTable = tb.DataTable
Dim sjdt As DataTable = DataTables("月销售明细")
Dim cr As Row = Args(0)
Dim kh As String = Args(1)
Dim qrq As Date = cr("前统计日期")
Dim rq As Date = cr("统计日期")
Dim kdr As DataRow = DataTables("客户档案").Find("客户名称 = \'"& kh &"\'")
If kdr Is Nothing \'从大逻辑上说是不可能为空,因为在此之前有应收日报统计,有关于客户归属地的强制填报
fh = "未找到客户【" + kh + "】的归属省区!"
End If
If fh > "" \'就是直接退出
Else
dt.LoadFilter = "[客户名称] = \'"& kh &"\' And [报表类别] = \'客户日结\' " \'一定要忽略"客户账龄/省区账龄/分公司账龄"这些正式报告表
dt.Load
sjdt.LoadFilter = "客户网点名称 = \'"& kh &"\' And 销售日期 > #"& qrq &"# And 销售日期 <= #"& rq &"# " \'在数据源很大的时候,还是会提升效率的
sjdt.Load
For Each xsrq As Date In sjdt.GetValues("销售日期") \',"客户网点名称 = \'"& kh &"\'")
Dim zr As Row = tb.AddNew
zr("日期") = xsrq
zr("年") = xsrq.Year
zr("月") = xsrq.Month
zr("日") = xsrq.Day
zr("客户名称") = kh
zr("统计日期") = cr("统计日期")
zr("当前金价") = cr("当前金价")
zr("摘要") = "货款往来"
zr("报表类别") = "客户日结"
zr("分公司") = kdr("分公司")
zr("地理省区") = kdr("地理省区")
zr("绩效省区") = kdr("绩效省区")
Next
Dim hr As Row = tb.AddNew
hr("客户名称") = kh
hr("统计日期") = cr("统计日期")
hr("当前金价") = cr("当前金价")
hr("摘要") = Format(hr("统计日期"),"yyyyMMdd") +"统计"
hr("报表类别") = "客户账龄"
hr("分公司") = kdr("分公司")
hr("地理省区") = kdr("地理省区")
hr("绩效省区") = kdr("绩效省区")
Functions.Execute("BillCh1")
Functions.Execute("BillGd2")
Functions.Execute("BillGdNtPrc3")
Functions.Execute("BillAncFee4")
Functions.Execute("BillSalRtn5")
Functions.Execute("BillRtnFee6")
\'以下正序轮询,结算出每日的累计欠款与欠料
Dim qks() As String = {"应收款增加","应收款减少","应收款结余","应收料增加","应收料减少","应收料结余"}
Dim kzr As Row = tb.Rows(0)
For Each r As Row In tb.Rows
If r("统计日期") = cr("统计日期")
Dim brq As Date = r("日期")
Dim sr As DataRow
If brq = kzr("日期")
sr = kzr.DataRow
Else
sr = dt.Find("日期 < #"& brq &"#","日期 Desc")
End If
If sr IsNot Nothing
r("应收款结余") = sr("应收款结余") + r("应收款增加") - r("应收款减少")
r("应收料结余") = sr("应收料结余") + r("应收料增加") - r("应收料减少")
Else
r("应收款结余") = r("应收款增加") - r("应收款减少")
r("应收料结余") = r("应收料增加") - r("应收料减少")
End If
End If
Next
End If