فهرست منبع

订单统计优化2021年12月10日 14:27:54

hu 4 سال پیش
والد
کامیت
fa9e32aaf5

+ 14 - 0
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/下级业务员查询.sql

@@ -0,0 +1,14 @@
+with cte(fdepno,issub) AS (
+	SELECT t1.fdepno,0 FROM tdepartment t1
+	inner join pp_hr t2 on t1.fdepno=t2.fdepno and t1.siteid=t2.siteid
+	WHERE t2.hrid=$hrid$ and t1.siteid=$siteid$
+	UNION ALL
+	SELECT t1.fdepno,1 FROM tdepartment t1
+	inner join cte t2 on t1.fleaddepno=t2.fdepno
+	where t1.siteid=$siteid$
+)
+select t2.hrid from cte t1
+inner join pp_hr t2 on t1.fdepno=t2.fdepno
+where t1.issub=1
+union
+select $hrid$

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

@@ -1,94 +1,95 @@
-declare @fsaler varchar(20),@siteid varchar(20)
-set @fsaler = $fsaler$
+declare @siteid varchar(20)
 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,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4,t6.famount5,t7.famount6 ftotalamount from tagents t1 
+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,-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 
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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,fsaler 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,-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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t7 on t1.fagentnum=t7.fagentnum
 left join
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount2 from (
+(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  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 
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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,fsaler 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,-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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t2 on t7.fagentnum=t2.fagentnum and t7.fsaler=t2.fsaler
 left join
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount3 from (
+(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  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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 fagentnum,sum(t.famount) famount,fsaler 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,-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
-left join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount4 from (
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t3 on t7.fagentnum=t3.fagentnum and t7.fsaler=t3.fsaler
+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  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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 fagentnum,sum(t.famount) famount,fsaler 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) 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t4 on t7.fagentnum=t4.fagentnum and t7.fsaler=t4.fsaler
 left join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount5 from (
+(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  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) group by t1.fagentnum,fsaler) t1
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  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 fagentnum,sum(t.famount) famount,fsaler 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 (
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t5 on t7.fagentnum=t5.fagentnum and t7.fsaler=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,0,getdate()),120) group by t1.fagentnum,fsaler) t1
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  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 fagentnum,sum(t.famount) famount,fsaler 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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t6 on t7.fagentnum=t6.fagentnum and t7.fsaler=t6.fsaler
+
 left join pp_hr on pp_hr.hrid=t7.fsaler where $where$

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

@@ -1,105 +1,95 @@
-declare @fsaler varchar(20),@siteid varchar(20)
-set @fsaler = $fsaler$
+declare @siteid varchar(20)
 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,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4,t6.famount5,t7.famount6 ftotalamount from tagents t1 
+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,-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 
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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,fsaler 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,-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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t7 on t1.fagentnum=t7.fagentnum
 left join
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount2 from (
+(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  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 
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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,fsaler 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,-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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t2 on t7.fagentnum=t2.fagentnum and t7.fsaler=t2.fsaler
 left join
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount3 from (
+(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  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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 fagentnum,sum(t.famount) famount,fsaler 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,-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
-
-left join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount4 from (
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t3 on t7.fagentnum=t3.fagentnum and t7.fsaler=t3.fsaler
+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  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
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 fagentnum,sum(t.famount) famount,fsaler 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) 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
-
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t4 on t7.fagentnum=t4.fagentnum and t7.fsaler=t4.fsaler
 left join 
-(select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount5 from (
+(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  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) group by t1.fagentnum,fsaler) t1
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  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 fagentnum,sum(t.famount) famount,fsaler 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 (
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t5 on t7.fagentnum=t5.fagentnum and t7.fsaler=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,0,getdate()),120) group by t1.fagentnum,fsaler) t1
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  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 fagentnum,sum(t.famount) famount,fsaler 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
-
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid 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 and t1.fsaler=t2.fsaler
+) t6 on t7.fagentnum=t6.fagentnum and t7.fsaler=t6.fsaler
 
 left join pp_hr on pp_hr.hrid=t7.fsaler where $where$

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

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

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

@@ -1,28 +1,28 @@
-declare @fsaler varchar(20),@siteid varchar(20)
-set @fsaler =$fsaler$
+declare @siteid varchar(20)
 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,fagentname,fagentshortname,pp_hr.displayname,t2.famount1,t3.famount2,t4.famount3,t5.famount4,t6.famount5,t7.famount6 ftotalamount from tagents t1 
+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  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
 (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  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
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid 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 and t7.fsaler=t2.fsaler
 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  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
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid 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 and t7.fsaler=t3.fsaler
 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  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
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid 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 and t7.fsaler=t4.fsaler
 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  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
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid 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 and t7.fsaler=t5.fsaler
 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
+where t1.fstatus in('审核','关闭') and isnull(t2.finvoiceamount,0)>=isnull(t2.fwriteoffamount,0) and t1.siteid=@siteid 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 and t7.fsaler=t6.fsaler
 left join pp_hr on pp_hr.hrid=t7.fsaler where $where$

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

@@ -133,10 +133,16 @@ public class orderform extends Controller {
 		 * 눼쉔鑒앴욋젯쌈
 		 */
 		DBConnect connect = new DBConnect();
+		SQLFactory a = new SQLFactory(this, "苟섬撚蛟逃꿴璂");
+		a.addParameter("hrid", content.getString("fsaler"));
+	    a.addParameter("siteid", content.getString("siteid"));
+	    Rows hridRows = connect.runSqlQuery(a.getSQL());
+	    String hridinwhere = hridRows.getInWhere("hrid");
 		   /**
          * 법쫀係숭�零
          */
-        String where = " 1=1 ";
+        String where = " 1=1 and  t7.fsaler in "+ hridinwhere +" ";
+        
         if (content.containsKey("where")) {
             JSONObject whereObject = content.getJSONObject("where");
             if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
@@ -159,7 +165,7 @@ public class orderform extends Controller {
 		String type = content.getString("type");
 		if (type.equals("땐데�뵙灌澗운")) {
 			SQLFactory factory = new SQLFactory(this, "땐데�뵙灌澗운瑯퍅固셕꿴璂");
-			factory.addParameter("fsaler", content.getString("fsaler"));
+			//factory.addParameter("fsaler", hridinwhere);
 			factory.addParameter("siteid", content.getString("siteid"));
 			 factory.addParameter_SQL("where", where);
 			// System.out.println(factory.getSQL());
@@ -167,21 +173,21 @@ public class orderform extends Controller {
 			 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("fsaler", hridinwhere);
 			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("fsaler", hridinwhere);
 			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("fsaler", hridinwhere);
 			factory.addParameter("siteid", content.getString("siteid"));
 			 factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());