Procházet zdrojové kódy

# WARNING: head commit changed in the meantime

业务员订单账期统计sql更改
hu před 4 roky
rodič
revize
d702017a45

+ 68 - 68
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单出货未付款账期统计查询.sql

@@ -1,68 +1,68 @@
-declare @fsaler varchar(20),@siteid varchar(20)
-set @fsaler = $fsaler$
-set @siteid = $siteid$
-select t1.fagentnum,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount1 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=30 group by t1.fagentnum,fsaler) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=30) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
-
-) t2 on t1.fagentnum=t2.fagentnum
-inner join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount2 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=90 group by t1.fagentnum,fsaler) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=90) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
-
-) t3 on t1.fagentnum=t3.fagentnum
-inner join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount3 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=180 group by t1.fagentnum,fsaler) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=180) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
-
-) t4 on t1.fagentnum=t4.fagentnum
-inner join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount4 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=365 group by t1.fagentnum,fsaler) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=365) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
-
-) t5 on t1.fagentnum=t5.fagentnum
-inner join pp_hr on pp_hr.hrid=t2.fsaler
+declare @fsaler varchar(20),@siteid varchar(20)
+set @fsaler = $fsaler$
+set @siteid = $siteid$
+select t1.fagentnum,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 left join
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount1 from (
+select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=30 group by t1.fagentnum,fsaler) t1
+left join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=30) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+
+) t2 on t1.fagentnum=t2.fagentnum
+left join
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount2 from (
+select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=90 group by t1.fagentnum,fsaler) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=90) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+
+) t3 on t1.fagentnum=t3.fagentnum
+left join
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount3 from (
+select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=180 group by t1.fagentnum,fsaler) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=180) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+
+) t4 on t1.fagentnum=t4.fagentnum
+inner join 
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount4 from (
+select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=365 group by t1.fagentnum,fsaler) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=365) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+
+) t5 on t1.fagentnum=t5.fagentnum
+left join pp_hr on pp_hr.hrid=t5.fsaler

+ 68 - 68
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单出货未开票账期统计查询.sql

@@ -1,68 +1,68 @@
-declare @fsaler varchar(20),@siteid varchar(20)
-set @fsaler = $fsaler$
-set @siteid =  $siteid$
-select t1.fagentnum,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount1 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=30 group by t1.fagentnum,fsaler) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=30) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
-
-) t2 on t1.fagentnum=t2.fagentnum
-inner join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount2 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=90 group by t1.fagentnum,fsaler) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=90) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
-
-) t3 on t1.fagentnum=t3.fagentnum
-inner join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount3 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=180 group by t1.fagentnum,fsaler) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=180) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
-
-) t4 on t1.fagentnum=t4.fagentnum
-inner join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount4 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=365 group by t1.fagentnum,fsaler) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=365) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
-
-) t5 on t1.fagentnum=t5.fagentnum
-inner join pp_hr on pp_hr.hrid=t2.fsaler
+declare @fsaler varchar(20),@siteid varchar(20)
+set @fsaler = $fsaler$
+set @siteid =  $siteid$
+select t1.fagentnum,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 left join
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount1 from (
+select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=30 group by t1.fagentnum,fsaler) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=30) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+
+) t2 on t1.fagentnum=t2.fagentnum
+left join
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount2 from (
+select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=90 group by t1.fagentnum,fsaler) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=90) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+
+) t3 on t1.fagentnum=t3.fagentnum
+left join
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount3 from (
+select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=180 group by t1.fagentnum,fsaler) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=180) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+
+) t4 on t1.fagentnum=t4.fagentnum
+inner join 
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount4 from (
+select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=365 group by t1.fagentnum,fsaler) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,t1.checkdate,getdate())<=365) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+
+) t5 on t1.fagentnum=t5.fagentnum
+left join pp_hr on pp_hr.hrid=t5.fsaler

+ 20 - 20
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单审核未收款账期统计查询.sql

@@ -1,20 +1,20 @@
-declare @fsaler varchar(20),@siteid varchar(20)
-set @fsaler =$fsaler$
-set @siteid = $siteid$
-select t1.fagentnum,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
-(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount1 from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=30 group by t1.fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
-inner join 
-(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount2 from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=90 group by t1.fagentnum,FSALER) t3 on t1.fagentnum=t3.fagentnum
-inner join 
-(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount3 from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=180 group by t1.fagentnum,FSALER) t4 on t1.fagentnum=t4.fagentnum
-inner join 
-(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount4 from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=365 group by t1.fagentnum,FSALER) t5 on t1.fagentnum=t5.fagentnum
-inner join pp_hr on pp_hr.hrid=t2.fsaler
+declare @fsaler varchar(20),@siteid varchar(20)
+set @fsaler =$fsaler$
+set @siteid = $siteid$
+select t1.fagentnum,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 left join
+(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount1 from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=30 group by t1.fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+left join
+(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount2 from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=90 group by t1.fagentnum,FSALER) t3 on t1.fagentnum=t3.fagentnum
+left join
+(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount3 from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=180 group by t1.fagentnum,FSALER) t4 on t1.fagentnum=t4.fagentnum
+inner join
+(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount4 from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=365 group by t1.fagentnum,FSALER) t5 on t1.fagentnum=t5.fagentnum
+left join pp_hr on pp_hr.hrid=t5.fsaler

+ 20 - 20
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单开票未收款账期统计查询.sql

@@ -1,20 +1,20 @@
-declare @fsaler varchar(20),@siteid varchar(20)
-set @fsaler =$fsaler$
-set @siteid =$siteid$
-select t1.fagentnum,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
-(select fsaler,t1.fagentnum,sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount1 from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=30  group by t1.fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
-inner join 
-(select fsaler,t1.fagentnum,sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount2 from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=90  group by t1.fagentnum,FSALER) t3 on t1.fagentnum=t3.fagentnum
-inner join 
-(select fsaler,t1.fagentnum,sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount3 from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=180  group by t1.fagentnum,FSALER) t4 on t1.fagentnum=t4.fagentnum
-inner join 
-(select fsaler,t1.fagentnum,sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount4 from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=365  group by t1.fagentnum,FSALER) t5 on t1.fagentnum=t5.fagentnum
-inner join pp_hr on pp_hr.hrid=t2.fsaler
+declare @fsaler varchar(20),@siteid varchar(20)
+set @fsaler =$fsaler$
+set @siteid =$siteid$
+select t1.fagentnum,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 left join
+(select fsaler,t1.fagentnum,sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount1 from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=30  group by t1.fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+left join
+(select fsaler,t1.fagentnum,sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount2 from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=90  group by t1.fagentnum,FSALER) t3 on t1.fagentnum=t3.fagentnum
+left join
+(select fsaler,t1.fagentnum,sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount3 from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=180  group by t1.fagentnum,FSALER) t4 on t1.fagentnum=t4.fagentnum
+inner join 
+(select fsaler,t1.fagentnum,sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount4 from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  DateDiff(dd,checkdate,getdate())<=365  group by t1.fagentnum,FSALER) t5 on t1.fagentnum=t5.fagentnum
+left join pp_hr on pp_hr.hrid=t5.fsaler