|
|
@@ -0,0 +1,581 @@
|
|
|
+with cashbill as (select sys_enterpriseid,
|
|
|
+ sa_accountclassid,
|
|
|
+ substring(t1.period, 6, 2) period,
|
|
|
+ sum(if(type = 0, 0 - amount, 0 + amount)) amount
|
|
|
+ from sa_cashbill t1
|
|
|
+ where ((t1.type = 1 and t1.class in ('货款', '物流赔偿')) or
|
|
|
+ (t1.type = 0 and t1.subclass = '拨款'))
|
|
|
+ and t1.status = '审核'
|
|
|
+ and t1.siteid = $siteid$
|
|
|
+ and substring(t1.period, 1, 4) =$year$
|
|
|
+ group by sys_enterpriseid, sa_accountclassid, substring(t1.period, 6, 2)),
|
|
|
+ cashbill1 as (select t1.sys_enterpriseid, sum(amount) amount, substring(t1.period, 6, 2) period
|
|
|
+ from sa_cashbill t1
|
|
|
+ left join sa_agents t2
|
|
|
+ on t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ where t1.type = 1
|
|
|
+ and t1.status = '审核'
|
|
|
+ and t1.siteid = $siteid$
|
|
|
+ and IF(t2.agentnum in ('D1001', 'DY01', '2314', '2315', '2316', '2701'), 1 = 1, t1.sa_accountclassid != 96)
|
|
|
+ and substring(t1.period, 1, 4) =$year$
|
|
|
+ and t1.subclass in ('广告费', '上样补贴', '装修补贴','内购返点', '年终返利')
|
|
|
+ group by sys_enterpriseid, substring(t1.period, 6, 2)),
|
|
|
+ orders as (select t.sys_enterpriseid, submitdate, sum(t.amount) amount
|
|
|
+ from (select t1.sys_enterpriseid, t2.amount, date_format(t1.checkdate, '%m') submitdate
|
|
|
+ from sa_order t1
|
|
|
+ inner join sa_orderitems t2
|
|
|
+ on t1.siteid = t2.siteid and t1.sa_orderid = t2.sa_orderid
|
|
|
+ inner join plm_item t3
|
|
|
+ on t2.siteid = t3.siteid and t2.itemid = t3.itemid
|
|
|
+ left join sa_agents t4
|
|
|
+ on t1.siteid = t4.siteid and t1.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ where t1.siteid = $siteid$
|
|
|
+ and t1.status in ('审核', '关闭','手工关闭') and t3.financeclasstype='木制品'
|
|
|
+ and year(t1.checkdate) =$year$
|
|
|
+
|
|
|
+union all
|
|
|
+select t1.sys_enterpriseid, 0 - (t2.undeliqty * t2.price) , date_format(t1.closedate, '%m')
|
|
|
+from sa_order t1
|
|
|
+ inner join sa_orderitems t2
|
|
|
+ on t1.siteid = t2.siteid and t1.sa_orderid = t2.sa_orderid
|
|
|
+ inner join plm_item t3
|
|
|
+ on t2.siteid = t3.siteid and t2.itemid = t3.itemid
|
|
|
+ left join sa_agents t4
|
|
|
+ on t1.siteid = t4.siteid and t1.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+where t1.siteid = $siteid$
|
|
|
+ and t1.status = '手工关闭' and t3.financeclasstype='木制品'
|
|
|
+ and year(t1.closedate) =$year$
|
|
|
+
|
|
|
+union all
|
|
|
+select t1.sys_enterpriseid, -t2.amount, date_format(t1.recheckdate, '%m')
|
|
|
+from sa_aftersalesmag t1
|
|
|
+ inner join sa_aftersalesmag_items t2
|
|
|
+ on t1.siteid = t2.siteid and t1.sa_aftersalesmagid = t2.sa_aftersalesmagid
|
|
|
+ left join sa_agents t4
|
|
|
+ on t1.siteid = t4.siteid and t1.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+where t1.siteid = $siteid$
|
|
|
+ and t1.status = '复核' and t2.reason='木制品退货'
|
|
|
+ and year(t1.recheckdate) =$year$) t
|
|
|
+group by sys_enterpriseid, submitdate)
|
|
|
+select distinct t1.enterprisename,
|
|
|
+ t1.siteid,
|
|
|
+ t1.province,
|
|
|
+ t2.agentnum,
|
|
|
+ t4.areaname2,
|
|
|
+ t4.areaname3,
|
|
|
+ cast(cast(t5.amount1 as float) as char) amount11,
|
|
|
+ cast(cast(t5.amount2 as float) as char) amount12,
|
|
|
+ cast(cast(t5.amount3 as float) as char) amount13,
|
|
|
+ cast(cast(t5.amount4 as float) as char) amount14,
|
|
|
+ cast(cast(t5.amount5 as float) as char) amount15,
|
|
|
+ cast(cast((t5.amount1 + t5.amount5 + t5.amount3) as float) as char) sum1,
|
|
|
+ cast(cast(t6.amount1 as float) as char) amount21,
|
|
|
+ cast(cast(t6.amount2 as float) as char) amount22,
|
|
|
+ cast(cast(t6.amount3 as float) as char) amount23,
|
|
|
+ cast(cast(t6.amount4 as float) as char) amount24,
|
|
|
+ cast(cast(t6.amount5 as float) as char) amount25,
|
|
|
+ cast(cast((t6.amount1 + t6.amount5 + t6.amount3) as float) as char) sum2,
|
|
|
+ cast(cast(t7.amount1 as float) as char) amount31,
|
|
|
+ cast(cast(t7.amount2 as float) as char) amount32,
|
|
|
+ cast(cast(t7.amount3 as float) as char) amount33,
|
|
|
+ cast(cast(t7.amount4 as float) as char) amount34,
|
|
|
+ cast(cast(t7.amount5 as float) as char) amount35,
|
|
|
+ cast(cast((t7.amount1 + t7.amount5 + t7.amount3) as float) as char) sum3,
|
|
|
+ cast(cast(t8.amount1 as float) as char) amount41,
|
|
|
+ cast(cast(t8.amount2 as float) as char) amount42,
|
|
|
+ cast(cast(t8.amount3 as float) as char) amount43,
|
|
|
+ cast(cast(t8.amount4 as float) as char) amount44,
|
|
|
+ cast(cast(t8.amount5 as float) as char) amount45,
|
|
|
+ cast(cast((t8.amount1 + t8.amount5 + t8.amount3) as float) as char) sum4,
|
|
|
+ cast(cast(t9.amount1 as float) as char) amount51,
|
|
|
+ cast(cast(t9.amount2 as float) as char) amount52,
|
|
|
+ cast(cast(t9.amount3 as float) as char) amount53,
|
|
|
+ cast(cast(t9.amount4 as float) as char) amount54,
|
|
|
+ cast(cast(t9.amount5 as float) as char) amount55,
|
|
|
+ cast(cast((t9.amount1 + t9.amount5 + t9.amount3) as float) as char) sum5,
|
|
|
+ cast(cast(t10.amount1 as float) as char) amount61,
|
|
|
+ cast(cast(t10.amount2 as float) as char) amount62,
|
|
|
+ cast(cast(t10.amount3 as float) as char) amount63,
|
|
|
+ cast(cast(t10.amount4 as float) as char) amount64,
|
|
|
+ cast(cast(t10.amount5 as float) as char) amount65,
|
|
|
+ cast(cast((t10.amount1 + t10.amount5 + t10.amount3) as float) as char) sum6,
|
|
|
+ cast(cast(t11.amount1 as float) as char) amount71,
|
|
|
+ cast(cast(t11.amount2 as float) as char) amount72,
|
|
|
+ cast(cast(t11.amount3 as float) as char) amount73,
|
|
|
+ cast(cast(t11.amount4 as float) as char) amount74,
|
|
|
+ cast(cast(t11.amount5 as float) as char) amount75,
|
|
|
+ cast(cast((t11.amount1 + t11.amount5 + t11.amount3) as float) as char) sum7,
|
|
|
+ cast(cast(t12.amount1 as float) as char) amount81,
|
|
|
+ cast(cast(t12.amount2 as float) as char) amount82,
|
|
|
+ cast(cast(t12.amount3 as float) as char) amount83,
|
|
|
+ cast(cast(t12.amount4 as float) as char) amount84,
|
|
|
+ cast(cast(t12.amount5 as float) as char) amount85,
|
|
|
+ cast(cast((t12.amount1 + t12.amount5 + t12.amount3) as float) as char) sum8,
|
|
|
+ cast(cast(t13.amount1 as float) as char) amount91,
|
|
|
+ cast(cast(t13.amount2 as float) as char) amount92,
|
|
|
+ cast(cast(t13.amount3 as float) as char) amount93,
|
|
|
+ cast(cast(t13.amount4 as float) as char) amount94,
|
|
|
+ cast(cast(t13.amount5 as float) as char) amount95,
|
|
|
+ cast(cast((t13.amount1 + t13.amount5 + t13.amount3) as float) as char) sum9,
|
|
|
+ cast(cast(t14.amount1 as float) as char) amount101,
|
|
|
+ cast(cast(t14.amount2 as float) as char) amount102,
|
|
|
+ cast(cast(t14.amount3 as float) as char) amount103,
|
|
|
+ cast(cast(t14.amount4 as float) as char) amount104,
|
|
|
+ cast(cast(t14.amount5 as float) as char) amount105,
|
|
|
+ cast(cast((t14.amount1 + t14.amount5 + t14.amount3) as float) as char) sum10,
|
|
|
+ cast(cast(t15.amount1 as float) as char) amount111,
|
|
|
+ cast(cast(t15.amount2 as float) as char) amount112,
|
|
|
+ cast(cast(t15.amount3 as float) as char) amount113,
|
|
|
+ cast(cast(t15.amount4 as float) as char) amount114,
|
|
|
+ cast(cast(t15.amount5 as float) as char) amount115,
|
|
|
+ cast(cast((t15.amount1 + t15.amount5 + t15.amount3) as float) as char) sum11,
|
|
|
+ cast(cast(t16.amount1 as float) as char) amount121,
|
|
|
+ cast(cast(t16.amount2 as float) as char) amount122,
|
|
|
+ cast(cast(t16.amount3 as float) as char) amount123,
|
|
|
+ cast(cast(t16.amount4 as float) as char) amount124,
|
|
|
+ cast(cast(t16.amount5 as float) as char) amount125,
|
|
|
+ cast(cast((t16.amount1 + t16.amount5 + t16.amount3) as float) as char) sum12,
|
|
|
+ cast(cast(t17.amount1 as float) as char) count1,
|
|
|
+ cast(cast(t17.amount2 as float) as char) count2,
|
|
|
+ cast(cast(t17.amount3 as float) as char) count3,
|
|
|
+ cast(cast(t17.amount4 as float) as char) count4,
|
|
|
+ cast(cast(t17.amount5 as float) as char) count5,
|
|
|
+ cast(cast((t17.amount1 + t17.amount5 + t17.amount3) as float) as char) count6
|
|
|
+from sys_enterprise t1
|
|
|
+ left join sa_agents t2 on t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join sys_enterprise_tradefield t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
|
|
|
+ left join (select t1.sa_saleareaid, t3.areaname areaname1, t2.areaname areaname2, t1.areaname areaname3
|
|
|
+ from sa_salearea t1
|
|
|
+ inner join sa_salearea t2
|
|
|
+ on t1.siteid = t2.siteid and t1.parentid = t2.sa_saleareaid and t2.level = 2
|
|
|
+ inner join sa_salearea t3
|
|
|
+ on t1.siteid = t2.siteid and t2.parentid = t3.sa_saleareaid and t3.level = 1
|
|
|
+ where t1.siteid = $siteid$
|
|
|
+ union all
|
|
|
+ select t1.sa_saleareaid, t2.areaname, t1.areaname, null
|
|
|
+ from sa_salearea t1
|
|
|
+ inner join sa_salearea t2
|
|
|
+ on t1.siteid = t2.siteid and t1.parentid = t2.sa_saleareaid and t2.level = 1
|
|
|
+ where t1.siteid = $siteid$
|
|
|
+ union all
|
|
|
+ select t1.sa_saleareaid, t1.areaname, null, null
|
|
|
+ from sa_salearea t1
|
|
|
+ where t1.level = 1
|
|
|
+ and t1.siteid = $siteid$) t4 on t3.sa_saleareaid = t4.sa_saleareaid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '01'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '01'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '01'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '01') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '01'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t5
|
|
|
+ on t1.sys_enterpriseid = t5.sys_enterpriseid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '02'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '02'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '02'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '02') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '02'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t6
|
|
|
+ on t1.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '03'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '03'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '03'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '03') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '03'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t7
|
|
|
+ on t1.sys_enterpriseid = t7.sys_enterpriseid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '04'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '04'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '04'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '04') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '04'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t8
|
|
|
+ on t1.sys_enterpriseid = t8.sys_enterpriseid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '05'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '05'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '05'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '05') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '05'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t9
|
|
|
+ on t1.sys_enterpriseid = t9.sys_enterpriseid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '06'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '06'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '06'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '06') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '06'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t10
|
|
|
+ on t1.sys_enterpriseid = t10.sys_enterpriseid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '07'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '07'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '07'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '07') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '07'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t11
|
|
|
+ on t1.sys_enterpriseid = t11.sys_enterpriseid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '08'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '08'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '08'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '08') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '08'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t12
|
|
|
+ on t1.sys_enterpriseid = t12.sys_enterpriseid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '09'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '09'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '09'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '09') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '09'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t13
|
|
|
+ on t1.sys_enterpriseid = t13.sys_enterpriseid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '10'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '10'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '10'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '10') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '10'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t14
|
|
|
+ on t1.sys_enterpriseid = t14.sys_enterpriseid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '11'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '11'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '11'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '11') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '11'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t15
|
|
|
+ on t1.sys_enterpriseid = t15.sys_enterpriseid
|
|
|
+ left join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ and t1.period = '12'
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ and t1.period = '12'
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ where t1.period = '12'
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, t.amount
|
|
|
+ from orders t
|
|
|
+ where t.submitdate = '12') t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ and t1.period = '12'
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$) t16
|
|
|
+ on t1.sys_enterpriseid = t16.sys_enterpriseid
|
|
|
+ inner join (select t5.sys_enterpriseid,
|
|
|
+ ifnull(t1.amount, 0) amount1,
|
|
|
+ ifnull(t2.amount, 0) amount2,
|
|
|
+ ifnull(t3.amount, 0) amount3,
|
|
|
+ ifnull(t4.amount, 0) amount4,
|
|
|
+ ifnull(t6.amount, 0) amount5
|
|
|
+ from sys_enterprise t5
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 67
|
|
|
+ group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 69
|
|
|
+ group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill1 t1
|
|
|
+ group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
|
|
|
+ left join (select t.sys_enterpriseid, sum(t.amount) amount
|
|
|
+ from orders t
|
|
|
+ group by t.sys_enterpriseid) t4
|
|
|
+ on t5.sys_enterpriseid = t4.sys_enterpriseid
|
|
|
+ left join (select sys_enterpriseid, sum(amount) amount
|
|
|
+ from cashbill t1
|
|
|
+ where t1.sa_accountclassid = 98
|
|
|
+ group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
|
|
|
+ where t5.siteid = $siteid$
|
|
|
+ and (t1.amount>=0 or t2.amount>= 0 or t3.amount>= 0 or
|
|
|
+ t4.amount>= 0) or t6.amount>= 0) t17 on t1.sys_enterpriseid = t17.sys_enterpriseid
|
|
|
+where t1.siteid = $siteid$
|
|
|
+ and t1.sys_enterpriseid not in (9116, 9117)
|
|
|
+ and $where$
|
|
|
+
|