浏览代码

海盐订单统计优化

hu 4 年之前
父节点
当前提交
949182203e

+ 1 - 1
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单出货明细.sql

@@ -22,5 +22,5 @@ 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) t7 on t7.saorderdetailid=t2.saorderdetailid and t7.siteid=t2.siteid
 left join (select saorderdetail.SAORDERDETAILID,max(TINVOICEAPPLY.checkdate) kaipiaodate from  saorderdetail left join TINVOICEAPPLYORDER  on saorderdetail.SAORDERDETAILID=TINVOICEAPPLYORDER.SAORDERDETAILID and saorderdetail.siteid=TINVOICEAPPLYORDER.siteid 
                              left join TINVOICEAPPLY on TINVOICEAPPLY.TINVOICEAPPLYID=TINVOICEAPPLYORDER.TINVOICEAPPLYID and TINVOICEAPPLY.siteid=TINVOICEAPPLYORDER.siteid where TINVOICEAPPLY.checkdate is not null  group by saorderdetail.SAORDERDETAILID ) t4 on t2.saorderdetailid=t4.saorderdetailid
-where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and  DateDiff(dd,t1.checkdate,getdate())<=365 and t1.fagentnum=$fagentnum$ order by t1.fsonum desc,t2.frownum asc
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and  DateDiff(dd,t1.checkdate,getdate())<=365 and t1.fagentnum=$fagentnum$ and $where$ order by t1.fsonum desc,t2.frownum asc
 

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

@@ -1,21 +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 left join
+select t1.fagentnum,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4,t6.famount5,t7.famount6 ftotalamount 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) 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
-
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) 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 (
@@ -23,15 +22,14 @@ 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) 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
-
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120)) 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 (
@@ -39,30 +37,58 @@ 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) 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
-
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
 ) t4 on t1.fagentnum=t4.fagentnum
-inner join 
+left 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) 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
-
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120)) 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
+left join 
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount5 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  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) 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  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+) t6 on t1.fagentnum=t6.fagentnum
+inner join 
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount6 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  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) 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  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+) t7 on t1.fagentnum=t7.fagentnum
+left join pp_hr on pp_hr.hrid=t7.fsaler where $where$

+ 50 - 13
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 left join
+set @siteid = $siteid$
+select t1.fagentnum,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4,t6.famount5,t7.famount6 ftotalamount 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 (
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) 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.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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
 
 ) t2 on t1.fagentnum=t2.fagentnum
 left join
@@ -23,14 +23,14 @@ 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
 
 ) t3 on t1.fagentnum=t3.fagentnum
 left join
@@ -39,30 +39,67 @@ 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
 
 ) t4 on t1.fagentnum=t4.fagentnum
-inner join 
+
+left 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120)) 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
+
+left join 
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount5 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  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) 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  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+
+) t6 on t1.fagentnum=t6.fagentnum
+
+inner join 
+(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount6 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  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) 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  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum
+
+) t7 on t1.fagentnum=t7.fagentnum
+
+
+left join pp_hr on pp_hr.hrid=t7.fsaler where $where$

+ 5 - 5
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单出货金额查询.sql

@@ -1,5 +1,5 @@
-select 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 DateDiff(dd,t1.checkdate,getdate())<=$daynum$ and $where$
+select 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 $where$

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

@@ -1,20 +1,28 @@
 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,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4,t6.famount5,t7.famount6 ftotalamount 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
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) 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
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) 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
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) group by t1.fagentnum,FSALER) t4 on t1.fagentnum=t4.fagentnum
+left 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
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) group by t1.fagentnum,FSALER) t5 on t1.fagentnum=t5.fagentnum
+left join
+(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount5 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 CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) group by t1.fagentnum,FSALER) t6 on t1.fagentnum=t6.fagentnum
+inner join
+(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount6 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 CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) group by t1.fagentnum,FSALER) t7 on t1.fagentnum=t7.fagentnum
+left join pp_hr on pp_hr.hrid=t7.fsaler where $where$

+ 3 - 3
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单审核未收款金额查询.sql

@@ -1,3 +1,3 @@
-select sum(t2.frateamount-isnull(t2.fwriteoffamount,0)) famount 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  DateDiff(dd,checkdate,getdate())<=$daynum$ and $where$
+select sum(t2.frateamount-isnull(t2.fwriteoffamount,0)) famount 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 $where$

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

@@ -1,20 +1,28 @@
 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,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4,t6.famount5,t7.famount6 ftotalamount 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
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) 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
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120)  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 
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120)  group by t1.fagentnum,FSALER) t4 on t1.fagentnum=t4.fagentnum
+left 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
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid and FSALER=@fsaler and  CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120)  group by t1.fagentnum,FSALER) t5 on t1.fagentnum=t5.fagentnum
+left join 
+(select fsaler,t1.fagentnum,sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount5 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 CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120)  group by t1.fagentnum,FSALER) t6 on t1.fagentnum=t6.fagentnum
+inner join 
+(select fsaler,t1.fagentnum,sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount6 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  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)  group by t1.fagentnum,FSALER) t7 on t1.fagentnum=t7.fagentnum
+left join pp_hr on pp_hr.hrid=t7.fsaler where $where$

+ 3 - 3
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单开票未收款金额查询.sql

@@ -1,3 +1,3 @@
-select sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount 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 DateDiff(dd,checkdate,getdate())<=$daynum$ and $where$ 
+select sum(isnull(t2.finvoiceamount,0)-isnull(t2.fwriteoffamount,0)) famount 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 $where$ 

+ 6 - 6
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单开票金额查询.sql

@@ -1,6 +1,6 @@
-select sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,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 DateDiff(dd,t1.checkdate,getdate())<=$daynum$ and $where$ ) t
+select sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,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 $where$ ) t

+ 6 - 6
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单收款金额查询.sql

@@ -1,6 +1,6 @@
-select sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,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 DateDiff(dd,t1.checkdate,getdate())<=$daynum$ and $where$) t
+select sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,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 $where$) t

+ 72 - 11
src/rest/openapi/restcontroller/wechatapp/orderform/orderform.java

@@ -21,8 +21,24 @@ public class orderform extends Controller {
 		 * 눼쉔鑒앴욋젯쌈
 		 */
 		//System.out.println(111);
+		
 		DBConnect connect = new DBConnect();
-
+		 String where = " 1=1 ";
+		if(content.getInt("daynum")==0) {
+			where=where +" and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) ";
+		}else if(content.getInt("daynum")==30) {
+			where=where +" and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) ";
+		}else if(content.getInt("daynum")==90) {
+			where=where +" and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) ";
+		}else if(content.getInt("daynum")==180) {
+			where=where +" and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) ";
+		}else if(content.getInt("daynum")==365) {
+			where=where +" and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) ";
+		}else if(content.getInt("daynum")==999) {
+			where=where +" and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) ";
+		}else {
+			return getReturnObject_err("daynum꽝鑒鑒令꼇攣횅").toString();
+		}
 //	        /**
 //	         *탤埼係숭�零
 //	         */
@@ -34,7 +50,7 @@ public class orderform extends Controller {
 		   /**
          * 법쫀係숭�零
          */
-        String where = " 1=1 ";
+       
         if (content.containsKey("where")) {
             JSONObject whereObject = content.getJSONObject("where");
             if (whereObject.containsKey("fsaler") && !"".equals(whereObject.getString("fsaler"))) {
@@ -53,16 +69,14 @@ public class orderform extends Controller {
 			//System.out.println(siteid);
 			SQLFactory factory = new SQLFactory(this, "땐데�뵙灌澗운쏜띨꿴璂");
 			//factory.addParameter("fsaler", content.getString("fsaler"));
-			factory.addParameter("daynum", content.getInt("daynum"));
 			factory.addParameter("siteid", content.getString("siteid"));
 	        factory.addParameter_SQL("where", where);
-	        //System.out.println(factory.getSQL());
+	        System.out.println(factory.getSQL());
 			Rows rows = connect.runSqlQuery(factory.getSQL());
 			return getReturnObject_suc(rows, true).toString();
 		} else if (type.equals("땐데역튿灌澗운")) {
 			SQLFactory factory = new SQLFactory(this, "땐데역튿灌澗운쏜띨꿴璂");
 			//factory.addParameter("fsaler", content.getString("fsaler"));
-			factory.addParameter("daynum", content.getInt("daynum"));
 			factory.addParameter("siteid", content.getString("siteid"));
 	        factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
@@ -70,14 +84,12 @@ public class orderform extends Controller {
 		} else if (type.equals("땐데놔새灌마운")) {
 			SQLFactory factory = new SQLFactory(this, "땐데놔새쏜띨꿴璂");
 			//factory.addParameter("fsaler", content.getString("fsaler"));
-			factory.addParameter("daynum", content.getInt("daynum"));
 			factory.addParameter("siteid", content.getString("siteid"));
 	        factory.addParameter_SQL("where", where);
 	        //System.out.println(factory.getSQL());
 			Rows rows1 = connect.runSqlQuery(factory.getSQL());
 			SQLFactory factory1 = new SQLFactory(this, "땐데澗운쏜띨꿴璂");
 			//factory1.addParameter("fsaler", content.getString("fsaler"));
-			factory1.addParameter("daynum", content.getInt("daynum"));
 			factory1.addParameter("siteid", content.getString("siteid"));
 	        factory1.addParameter_SQL("where", where);
 			Rows rows2 = connect.runSqlQuery(factory1.getSQL());
@@ -93,13 +105,11 @@ public class orderform extends Controller {
 		} else if (type.equals("땐데놔새灌역튿")) {
 			SQLFactory factory = new SQLFactory(this, "땐데놔새쏜띨꿴璂");
 			//factory.addParameter("fsaler", content.getString("fsaler"));
-			factory.addParameter("daynum", content.getInt("daynum"));
 			factory.addParameter("siteid", content.getString("siteid"));
 	        factory.addParameter_SQL("where", where);
 			Rows rows1 = connect.runSqlQuery(factory.getSQL());
 			SQLFactory factory1 = new SQLFactory(this, "땐데역튿쏜띨꿴璂");
 			//factory1.addParameter("fsaler", content.getString("fsaler"));
-			factory1.addParameter("daynum", content.getInt("daynum"));
 			factory1.addParameter("siteid", content.getString("siteid"));
 	        factory1.addParameter_SQL("where", where);
 			Rows rows2 = connect.runSqlQuery(factory1.getSQL());
@@ -123,7 +133,25 @@ public class orderform extends Controller {
 		 * 눼쉔鑒앴욋젯쌈
 		 */
 		DBConnect connect = new DBConnect();
-
+		   /**
+         * 법쫀係숭�零
+         */
+        String where = " 1=1 ";
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("fagentnum") && !"".equals(whereObject.getString("fagentnum"))) {
+                where = where + " and t1.fagentnum like'%" + whereObject.getString("fagentnum") + "%'";
+            }
+            if (whereObject.containsKey("fagentname") && !"".equals(whereObject.getString("fagentname"))) {
+            	where = where + " and fagentname like'%" + whereObject.getString("fagentname") + "%'";
+            }
+            if (whereObject.containsKey("fagentshortname") && !"".equals(whereObject.getString("fagentshortname"))) {
+            	where = where + " and fagentshortname like'%" + whereObject.getString("fagentshortname") + "%'";
+            }
+            if (whereObject.containsKey("displayname") && !"".equals(whereObject.getString("displayname"))) {
+            	where = where + " and pp_hr.displayname like'%" + whereObject.getString("displayname") + "%'";
+            }
+        }
 //	        /**
 //	         *탤埼係숭�零
 //	         */
@@ -139,24 +167,28 @@ public class orderform extends Controller {
 			SQLFactory factory = new SQLFactory(this, "땐데�뵙灌澗운瑯퍅固셕꿴璂");
 			factory.addParameter("fsaler", content.getString("fsaler"));
 			factory.addParameter("siteid", content.getString("siteid"));
+			 factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
 			 return getReturnObject_suc_page(rows, true, 1).toString();
 		} else if (type.equals("땐데역튿灌澗운")) {
 			SQLFactory factory = new SQLFactory(this, "땐데역튿灌澗운瑯퍅固셕꿴璂");
 			factory.addParameter("fsaler", content.getString("fsaler"));
 			factory.addParameter("siteid", content.getString("siteid"));
+			 factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
 			 return getReturnObject_suc_page(rows, true, 1).toString();
 		} else if (type.equals("땐데놔새灌마운")) {
 			SQLFactory factory = new SQLFactory(this, "땐데놔새灌마운瑯퍅固셕꿴璂");
 			factory.addParameter("fsaler", content.getString("fsaler"));
 			factory.addParameter("siteid", content.getString("siteid"));
+			 factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
 			 return getReturnObject_suc_page(rows, true, 1).toString();
 		} else if (type.equals("땐데놔새灌역튿")) {
 			SQLFactory factory = new SQLFactory(this, "땐데놔새灌역튿瑯퍅固셕꿴璂");
 			factory.addParameter("fsaler", content.getString("fsaler"));
 			factory.addParameter("siteid", content.getString("siteid"));
+			 factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
 			 return getReturnObject_suc_page(rows, true, 1).toString();
 		} else {
@@ -170,6 +202,25 @@ public class orderform extends Controller {
 		 */
 		DBConnect connect = new DBConnect();
 
+        /**
+         * 법쫀係숭�零
+         */
+        String where = " 1=1 ";
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("fagentnum") && !"".equals(whereObject.getString("fagentnum"))) {
+                where = where + " and t1.fagentnum like'%" + whereObject.getString("fagentnum") + "%'";
+            }
+            if (whereObject.containsKey("fagentname") && !"".equals(whereObject.getString("fagentname"))) {
+            	where = where + " and fagentname like'%" + whereObject.getString("fagentname") + "%'";
+            }
+            if (whereObject.containsKey("fagentshortname") && !"".equals(whereObject.getString("fagentshortname"))) {
+            	where = where + " and fagentshortname like'%" + whereObject.getString("fagentshortname") + "%'";
+            }
+            if (whereObject.containsKey("displayname") && !"".equals(whereObject.getString("displayname"))) {
+            	where = where + " and pp_hr.displayname like'%" + whereObject.getString("displayname") + "%'";
+            }
+        }
 //	        /**
 //	         *탤埼係숭�零
 //	         */
@@ -185,24 +236,28 @@ public class orderform extends Controller {
 			SQLFactory factory = new SQLFactory(this, "쒔饋�땐데�뵙灌澗운瑯퍅固셕꿴璂");
 			factory.addParameter("fagentnum",fagentnum);
 			factory.addParameter("siteid", content.getString("siteid"));
+		    factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
 			 return getReturnObject_suc_page(rows, true, 1).toString();
 		} else if (type.equals("땐데역튿灌澗운")) {
 			SQLFactory factory = new SQLFactory(this, "쒔饋�땐데역튿灌澗운瑯퍅固셕꿴璂");
 			factory.addParameter("fagentnum",fagentnum);
 			factory.addParameter("siteid", content.getString("siteid"));
+			 factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
 			 return getReturnObject_suc_page(rows, true, 1).toString();
 		} else if (type.equals("땐데놔새灌마운")) {
 			SQLFactory factory = new SQLFactory(this, "쒔饋�땐데놔새灌마운瑯퍅固셕꿴璂");
 			factory.addParameter("fagentnum",fagentnum);
 			factory.addParameter("siteid", content.getString("siteid"));
+			 factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
 			 return getReturnObject_suc_page(rows, true, 1).toString();
 		} else if (type.equals("땐데놔새灌역튿")) {
 			SQLFactory factory = new SQLFactory(this, "쒔饋�땐데놔새灌역튿瑯퍅固셕꿴璂");
 			factory.addParameter("fagentnum",fagentnum);
 			factory.addParameter("siteid", content.getString("siteid"));
+			 factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
 			 return getReturnObject_suc_page(rows, true, 1).toString();
 		} else {
@@ -213,6 +268,12 @@ public class orderform extends Controller {
 	public String query_tagentdetails() {
 		 DBConnect connect = new DBConnect();
 		 String where = " 1=1 ";
+		 if (content.containsKey("where")) {
+	            JSONObject whereObject = content.getJSONObject("where");
+	            if (whereObject.containsKey("fsonum") && !"".equals(whereObject.getString("fsonum"))) {
+	                where = where + " and t1.fsonum like'%" + whereObject.getString("fsonum") + "%'";
+	            }
+		 }
 	        /**
 	         * SQL돕새횅훰데깊庫꿴璂꽝鑒�零깻꿴璂
 	         */
@@ -235,7 +296,7 @@ public class orderform extends Controller {
 				Rows rows = connect.runSqlQuery(factory.getSQL());
 				return getReturnObject_suc_page(rows, true, 1).toString();
 			} else if (type.equals("땐데놔새灌마운")) {
-				System.out.println(555);
+				//System.out.println(555);
 				SQLFactory factory = new SQLFactory(this, "땐데놔새츠玖");
 				//factory.addParameter("fsaler", content.getString("fsaler"));
 				factory.addParameter("fagentnum", fagentnum);