For Each ndr As DataRow In dt_cwhz.Select("")
Dim i As Integer = ndr("年份")
Dim j As Integer = ndr("月份")
If i > 0 AndAlso j > 0 Then
Dim d As Date = new Date(i, j, 1)
Dim filter As String = "业务往来_订单日期>= #" & d & "# and 业务往来_订单日期< #" & d.AddMonths(1) & "#"
If e.DataRow("业务往来_订单性质") = "自营" Then
ndr("经营_增加销售") = val(dt_ddfb.compute("sum(订单核算_合计)", filter))
ndr("经营_增加利润") = val(dt_ddfb.compute("sum(订单核算_毛利)", filter))
ndr("经营_税费") = val(dt_ddfb.compute("sum(订单核算_增值税费)", filter))
ndr("经营_返点") = val(dt_ddfb.compute("sum(订单核算_合计返点)", filter))
ndr("经营_运费") = val(dt_ddfb.compute("sum(订单核算_运费)", filter))
ndr("负债_对公增加") = val(dt_ddfb.compute("sum(订单核算_采购合计)", filter))
filter = "回款日期 >= #" & d & "# and 回款日期 < #" & d.AddMonths(1) & "#"
ndr("经营_回收货款") = val(dt_hkjl.compute("sum(收款金额)", filter))
End If
'Dim afdr As DataRow = dt_tzjl.Find(filter, "记录参数_操作时间 desc,[_Identify] desc")
filter = "记录参数_操作时间 >= #" & d & "# and 记录参数_操作时间 < #" & d.AddMonths(1) & "#"
ndr("投资_增加金额") = val(dt_tzjl.compute("sum(购入_增投合计)", filter))
ndr("投资_减少金额") = val(dt_tzjl.compute("sum(售出_撤资合计)", filter))
Dim afdr As DataRow = dt_tzjl.Find(filter, "记录参数_操作时间 desc,[_Identify] desc")
filter = "收益日期 >= #" & d & "# and 收益日期 < #" & d.AddMonths(1) & "#"
ndr("投资_其它收益") = val(dt_tzsy.compute("sum(收益金额)", filter))
Dim afdra As DataRow = dt_tzsy.Find(filter, "收益日期 desc,[_Identify] desc")
filter = "项目信息_更新日期 >= #" & d & "# and 项目信息_更新日期 < #" & d.AddMonths(1) & "#"
'Dim afdrb As DataRow = dt_hqsj.Find(filter, "项目信息_更新日期 desc,[_Identify] desc")
Dim afdrb As DataRow = dt_hqsj.Find(filter, "项目信息_更新日期 desc,[_Identify] desc,项目信息_变动编号 desc")
If afdrb IsNot Nothing Then
ndr("投资_溢价收益") = afdrb("核算记录_溢价收益")
ndr("投资_在运资金") = afdrb("核算记录_在投资金")
Else
ndr("投资_溢价收益") = 0
ndr("投资_在运资金") = 0
End If