|
|
@@ -0,0 +1,284 @@
|
|
|
+with
|
|
|
+ t2 as(-- -- -- -- -- 当年第一天到开始日期所有货款-- -- -- -- -- -- -- -- -- -
|
|
|
+ SELECT t3.agentnum fagentnum,
|
|
|
+ case when t1.rb='1'then t2.amount else -t2.amount end ftaxamount FROM st_stockbill T1
|
|
|
+ INNER JOIN st_stockbill_items T2 ON T1.st_stockbillid=t2.st_stockbillid
|
|
|
+ left JOIN sa_agents t3 ON t1.sys_enterpriseid=t3.sys_enterpriseid
|
|
|
+ where t1.status='审核' and t1.type='销售出库'
|
|
|
+ and t1.billdate>= DATE_FORMAT($begindate$, '%Y-01-01')
|
|
|
+ and t1.billdate<$enddate$
|
|
|
+ ),
|
|
|
+ c as(-- -- -- -- -- 当年第一天到开始日期所有档案费-- -- -- -- -- -- -- -- -- -
|
|
|
+ select t3.agentnum fagentnum,t1.amount from sa_cashbill t1
|
|
|
+ inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid=t3.sys_enterpriseid
|
|
|
+ where t1.status='审核' and t1.type=0 and t2.accountno='01' and t1.subclass='客户档案资料费'
|
|
|
+ and t1.checkdate>= DATE_FORMAT($begindate$, '%Y-01-01')
|
|
|
+ and t1.checkdate < $enddate$
|
|
|
+ ),
|
|
|
+ t5 as(-- -- -- -- -- 当年第一天到开始日期所有档案费-- -- -- -- -- -- -- -- -- -
|
|
|
+ select t3.agentnum fagentnum,t1.amount from sa_cashbill t1
|
|
|
+ inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid=t3.sys_enterpriseid
|
|
|
+
|
|
|
+ where t1.status='审核' and t1.type=1 and t2.accountno='01' and t1.subclass = '客户档案资料费'
|
|
|
+
|
|
|
+ and t1.checkdate>= DATE_FORMAT($begindate$, '%Y-01-01')
|
|
|
+ and t1.checkdate < $enddate$
|
|
|
+ ),
|
|
|
+ d as(-- -- -- -- -- 期间内返资料费-- -- -- -- -- -- -- -- -- -
|
|
|
+ select t3.agentnum fagentnum,t1.amount from sa_cashbill t1
|
|
|
+ inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid=t3.sys_enterpriseid
|
|
|
+ where t1.status='审核' and t1.type=1 and t2.accountno='01' and t1.subclass = '客户档案资料费' and
|
|
|
+
|
|
|
+ and t1.checkdate>= $begindate$
|
|
|
+ and t1.checkdate <= $enddate$
|
|
|
+
|
|
|
+ ),
|
|
|
+ h as (
|
|
|
+ select t3.agentnum fagentnum,t1.amount from sa_cashbill t1
|
|
|
+ inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid=t3.sys_enterpriseid
|
|
|
+ where t1.status='审核' and t2.accountno='01' and t1.subclass='客户档案资料费' and t1.ftype=0
|
|
|
+ and t1.checkdate>= $begindate$
|
|
|
+ and t1.checkdate <= $enddate$
|
|
|
+ ),
|
|
|
+ t3 as(-- -- -- -- -- -- -- -期间内回款-- -- -- -- -- -- -- -- -- -- -- -- -
|
|
|
+ select t3.agentnum fagentnum,t1.amount from sa_cashbill t1
|
|
|
+ inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid=t3.sys_enterpriseid
|
|
|
+ where t1.type =1 and t1.status ='审核' and t2.accountno='01' and ifnull(t1.subclass,'') != '客户档案资料费'
|
|
|
+ and t1.billdate>= $begindate$
|
|
|
+ and t1.billdate <= $enddate$
|
|
|
+ ),
|
|
|
+
|
|
|
+
|
|
|
+ t4 as(-- -- -- -- -- -- -- -当年第一天到开始日期回款(计算上期结余)-- -- -- -- -- -- -- -- -- -- -- -- -
|
|
|
+select t3.agentnum fagentnum,t1.amount from sa_cashbill t1
|
|
|
+ inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid=t3.sys_enterpriseid
|
|
|
+where t1.type =1 and t1.status ='审核' and t2.accountno='01' and ifnull(t1.subclass,0) != '客户档案资料费'
|
|
|
+ and t1.billdate>= DATE_FORMAT($begindate$, '%Y-01-01')
|
|
|
+ and t1.billdate < $enddate$
|
|
|
+ ),
|
|
|
+ t6 as(-- -- -- -- -- -- -- -- -- -- -本年第一天到开始日期退款-- 退货和报废退钱(计算上期结余)-- -- -- -- -- -- -- -- -- -
|
|
|
+select t4.agentnum fagentnum,ifnull(t2.amount,0) famount from st_stockbill t1
|
|
|
+ join st_stockbill_items t2 on t2.st_stockbillid=t1.st_stockbillid and t2.siteid=t1.siteid
|
|
|
+ join plm_item t3 on t3.itemid=t2.itemid and t3.siteid=t2.siteid and t3.topclassnum not in('其他费用','配件','0')
|
|
|
+ left join sa_agents t4 on t4.sys_enterpriseid=t1.sys_enterpriseid
|
|
|
+where t1.status='审核' and t1.type='其他入库' and t1.typemx in ('正品入库','报废入库')
|
|
|
+ and t1.billdate>= DATE_FORMAT($begindate$, '%Y-01-01')
|
|
|
+ and t1.billdate<$enddate$
|
|
|
+ ),
|
|
|
+ b as(
|
|
|
+-- -- -- -- -- -- -- -- -- -- -- -- -- -货款运费、货款其他、货款优惠、货款回收、上期结余、可用优惠-- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
+select t1.fagentnum,sum(hkyf) '货款运费',sum(hkqtfy) '货款其他',sum(hkyh) '货款优惠',sum(hkhs) '货款回收',
|
|
|
+ sum(sqjy) '上期结余',sum(kyyh) '可用优惠',sum(bftk) '退款',sum(hkpj) '货款配件',sum(cz) '充值',SUM(yfzlf) 已返资料费,SUM(zlf) 资料费
|
|
|
+from(
|
|
|
+ select -- 运费
|
|
|
+ t3.agentnum fagentnum,
|
|
|
+ case when t1.rb='1' then ifnull(t2.amount,0) else -ifnull(t2.amount,0) end hkyf,0 hkqtfy, 0 hkyh,0 hkhs,0 sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from st_stockbill t1
|
|
|
+ left join st_stockbill_items t2 on t1.st_stockbillid = t2.st_stockbillid and t1.siteid = t2.siteid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ left join plm_item t4 on t2.itemid = t4.itemid and t2.siteid = t4.siteid
|
|
|
+ where t1.status='审核' and t1.type ='销售出库' and t4.itemno='90001' -- 运费
|
|
|
+ and t1.billdate>=$begindate$ and t1.billdate<=$enddate$
|
|
|
+-- 货款其他 = 其他费用
|
|
|
+ union all-- 其他费用
|
|
|
+ select
|
|
|
+ t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,case when rb='1' then ifnull(t2.amount,0) else -ifnull(t2.amount,0) end hkqtfy, 0 hkyh,0 hkhs,0 sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from st_stockbill t1
|
|
|
+ left join st_stockbill_items t2 on t1.st_stockbillid = t2.st_stockbillid and t1.siteid = t2.siteid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ left join plm_item t4 on t2.itemid = t4.itemid and t2.siteid = t4.siteid
|
|
|
+ where t1.status='审核' and t1.type ='销售出库' and t4.itemno!='90001' and t4.topclassnum='其他费用' -- 其他费用
|
|
|
+ and t1.billdate>=$begindate$ and t1.billdate<=$enddate$
|
|
|
+ union all-- 货款优惠蓝字
|
|
|
+ select
|
|
|
+ t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy,t1.paydiscountamount hkyh,0 hkhs,0 sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from st_stockbill t1
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ where t1.status='审核' and t1.type ='销售出库' and t1.rb='1'
|
|
|
+ and t1.billdate>=$begindate$ and t1.billdate<=$enddate$
|
|
|
+ union all-- 货款优惠红字
|
|
|
+ select
|
|
|
+ t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy,-t1.paydiscountamount hkyh,0 hkhs,0 sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from st_stockbill t1
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ where t1.status='审核' and t1.type ='销售出库' and t1.rb='0'
|
|
|
+ and t1.billdate>=$begindate$ and t1.billdate<=$enddate$
|
|
|
+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 回收货款-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
+ union all-- 回收货款
|
|
|
+ select
|
|
|
+ t3.fagentnum,0 hkyf,0 hkqtfy,0 hkyh,t3.famount hkhs,0 sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from t3
|
|
|
+ union all-- 返资料费
|
|
|
+ select d.fagentnum,0 hkyf,0 hkqtfy,0 hkyh,0 hkhs,0 sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,d.famount yfzlf,0 zlf
|
|
|
+
|
|
|
+ from d
|
|
|
+ union all-- 资料费
|
|
|
+ select h.fagentnum,0 hkyf,0 hkqtfy,0 hkyh,0 hkhs,0 sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,h.famount zlf
|
|
|
+
|
|
|
+ from h
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+-- -- -- -- -- -- -- -计算上期结余-- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
+-- 上期结余=本年期初-所有货款+回款+退款+优惠(本年第一天到开始日期)-- -- -- -- -- -- -- -- -- -- -
|
|
|
+
|
|
|
+ union all-- 本年期初余额
|
|
|
+
|
|
|
+ select t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy,0 hkyh,0 hkhs,t1.balance sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from sa_cashbeginbal t1
|
|
|
+ inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ where t2.accountno='01' and t1.year=year($begindate$)
|
|
|
+ union all-- 货款(本年第一天到开始日期)
|
|
|
+ select t2.fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,-t2.ftaxamount sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from t2
|
|
|
+ union all-- 资料费(本年第一天到开始日期)
|
|
|
+ select c.fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,-c.famount sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from c
|
|
|
+ union all-- 返资料费(本年第一天到开始日期)
|
|
|
+ select t5.fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,t5.famount sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from t5
|
|
|
+ union all-- 回款(本年第一天到开始日期)
|
|
|
+ select t4.fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,t4.famount sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from t4
|
|
|
+ union all-- 退款(本年第一天到开始日期)
|
|
|
+ select t6.fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,t6.famount sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from t6
|
|
|
+ union all-- 货款优惠蓝字(本年第一天到开始日期所有优惠)
|
|
|
+ select
|
|
|
+ t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy,0 hkyh,0 hkhs,t1.paydiscountamount sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from st_stockbill t1
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ where t1.status='审核' and t1.type ='销售出库' and t1.rb='1'
|
|
|
+ and t1.billdate>=DATE_FORMAT($begindate$, '%Y-01-01')
|
|
|
+ and t1.billdate<$enddate$
|
|
|
+ union all-- 货款优惠红字(本你那第一天到开始日期所有优惠)
|
|
|
+ select
|
|
|
+ t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy,0 hkyh,0 hkhs,-t1.paydiscountamount sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from st_stockbill t1
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ where t1.status='审核' and t1.type ='销售出库' and t1.rb='0'
|
|
|
+ and t1.billdate>=DATE_FORMAT($begindate$, '%Y-01-01')
|
|
|
+ and t1.billdate<$begindate$
|
|
|
+ union all-- 维修配件(本年第一天到开始日期所有送修单中的维修配件)
|
|
|
+ select t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,-ifnull(t2.agentcost,0) sqjy,0 kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from sa_sendrepair t1
|
|
|
+ join sa_sendrepair_detail t2 on t2.sa_sendrepairid=t1.sa_sendrepairid and t2.siteid=t1.siteid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ where t1.status='审核'
|
|
|
+ and t1.checkdate>=DATE_FORMAT($begindate$, '%Y-01-01')
|
|
|
+ and t1.checkdate<$enddate$
|
|
|
+
|
|
|
+-- 可用优惠=本年期初+所有回收优惠-支出优惠
|
|
|
+ union all-- 本年期初优惠
|
|
|
+ select t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,0 sqjy,t1.DISCOUNTAMOUNT kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from sa_cashbeginbal t1
|
|
|
+ inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ where t2.accountno='01'
|
|
|
+ and t1.year=year($begindate$)
|
|
|
+ union ALL-- 收入优惠+
|
|
|
+ select
|
|
|
+ t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,0 sqjy,ifnull(t1.DISCOUNTAMOUNT,0) kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from sa_cashbill t1
|
|
|
+ inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ where t1.type =1 and t1.status ='审核' and t2.accountno='01'
|
|
|
+ and t1.billdate>=DATE_FORMAT($begindate$, '%Y-01-01')
|
|
|
+ and t1.billdate<$enddate$
|
|
|
+ union all-- 支出优惠-
|
|
|
+ select
|
|
|
+ t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,0 sqjy,-ifnull(t1.DISCOUNTAMOUNT,0) kyyh,0 bftk,0 hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from sa_cashbill t1
|
|
|
+ inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ where t1.type =0 and t1.status ='审核' and t2.accountno='01'
|
|
|
+ and t1.billdate>=DATE_FORMAT($begindate$, '%Y-01-01')
|
|
|
+ and t1.billdate<$enddate$
|
|
|
+ union all-- 报废退钱
|
|
|
+ select t4.agentnum fagentnum,0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,0 sqjy,0 kyyh,-ifnull(t2.amount,0) bftk,0 hkpj,0 cz,0 yfzlf,0 zlf from st_stockbill t1
|
|
|
+ join st_stockbill_items t2 on t2.st_stockbillid=t1.st_stockbillid and t2.siteid=t1.siteid
|
|
|
+ join plm_item t3 on t3.itemid=t2.itemid and t3.siteid=t2.siteid and t3.topclassnum not in('其他费用','配件','0')
|
|
|
+ left join sa_agents t4 on t1.sys_enterpriseid = t4.sys_enterpriseid and t1.siteid = t4.siteid
|
|
|
+ where t1.status='审核' and t1.type='其他入库' and t1.typemx ='报废入库' AND t2.amount!=0
|
|
|
+ and t1.billdate>=$begindate$ and t1.billdate<=$enddate$
|
|
|
+
|
|
|
+ union all -- 货款配件=销售配件费+维修配件费
|
|
|
+ select -- 销售配件费
|
|
|
+ t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,0 sqjy,0 kyyh,0 bftk,case when rb='1' then ifnull(t2.amount,0) else -ifnull(t2.amount,0) end hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from st_stockbill t1
|
|
|
+ join st_stockbill_items t2 on t2.st_stockbillid=t1.st_stockbillid and t2.siteid=t1.siteid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ join plm_item t4 on t2.itemid = t4.itemid and t2.siteid = t4.siteid and t4.topclassnum='配件'
|
|
|
+ where t1.status='审核' and t1.type ='销售出库'
|
|
|
+ and t1.billdate>=$begindate$ and t1.billdate<=$enddate$
|
|
|
+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 此处缺少维修配件费-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
+ union all-- 维修配件
|
|
|
+ select t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,0 sqjy,0 kyyh,0 bftk,ifnull(t2.agentcost,0) hkpj,0 cz,0 yfzlf,0 zlf
|
|
|
+ from sa_sendrepair t1
|
|
|
+ join sa_sendrepair_detail t2 on t2.sa_sendrepairid=t1.sa_sendrepairid and t2.siteid=t1.siteid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ where t1.status='审核'
|
|
|
+ and t1.checkdate>=$begindate$ and t1.checkdate<=$enddate$
|
|
|
+ union all -- 充值
|
|
|
+ select
|
|
|
+ t3.agentnum fagentnum,
|
|
|
+ 0 hkyf,0 hkqtfy, 0 hkyh,0 hkhs,0 sqjy,0 kyyh,0 bftk,0 hkpj,ifnull(t1.DISCOUNTAMOUNT,0) cz,0 yfzlf,0 zlf
|
|
|
+ from sa_cashbill t1
|
|
|
+ inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid
|
|
|
+ left join sa_agents t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ where t1.type ='收入' and t1.status ='审核' and t2.accountno='01'
|
|
|
+ and t1.billdate>=$begindate$ and t1.billdate<=$enddate$
|
|
|
+
|
|
|
+ ) t1 group by t1.fagentnum
|
|
|
+ ) ,
|
|
|
+ aaa as (
|
|
|
+select t.fagentnum,sum(t.ftaxamount) ftaxamount from(
|
|
|
+ SELECT t4.agentnum fagentnum,t3.topclassnum,
|
|
|
+ ifnull(case when t1.rb='1' then t2.amount else -t2.amount end,0) ftaxamount
|
|
|
+ FROM st_stockbill T1
|
|
|
+ INNER JOIN st_stockbill_items T2 ON T1.st_stockbillid=t2.st_stockbillid
|
|
|
+ inner join plm_item t3 on t2.itemid=t3.itemid and t3.topclassnum not in('其他费用','配件','0')
|
|
|
+ left join sa_agents t4 on t1.sys_enterpriseid = t4.sys_enterpriseid and t1.siteid = t4.siteid
|
|
|
+ where t1.status='审核' and t1.type='销售出库'
|
|
|
+ and t1.billdate>=$begindate$ and t1.billdate<=$enddate$
|
|
|
+ union all
|
|
|
+ select t4.agentnum fagentnum,t3.topclassnum,-ifnull(t2.amount,0) ftaxamount
|
|
|
+ FROM st_stockbill T1
|
|
|
+ INNER JOIN st_stockbill_items T2 ON T1.st_stockbillid=t2.st_stockbillid
|
|
|
+ inner join plm_item t3 on t2.itemid=t3.itemid and t3.topclassnum not in('其他费用','配件','0')
|
|
|
+ left join sa_agents t4 on t1.sys_enterpriseid = t4.sys_enterpriseid and t1.siteid = t4.siteid
|
|
|
+ where t1.status='审核' and t1.type='其他入库' and t1.typemx='正品入库' and t2.amount!=0
|
|
|
+ and t1.billdate>=$begindate$ and t1.billdate<=$enddate$
|
|
|
+ ) t group by t.fagentnum
|
|
|
+ )
|
|
|
+select
|
|
|
+ d.fagentnum '经销商代号',d.sys_enterpriseid,
|
|
|
+ b.kyyh,
|
|
|
+ isnull(b.上期结余,0)+isnull(b.货款回收,0)+ isnull(b.已返资料费,0)-( isnull(aaa.ftaxamount,0)+isnull(b.货款其他,0)+isnull(b.货款运费,0)+isnull(b.货款配件,0)+isnull(b.退款,0)- isnull(b.货款优惠,0))- isnull(b.资料费,0) bqjy
|
|
|
+from tagents d
|
|
|
+ left join b on b.fagentnum=d.fagentnum
|
|
|
+ left join aaa on aaa.fagentnum = d.fagentnum
|