فهرست منبع

订单账期统计出货未开票,出货未核销整体逻辑变更2022年3月18日14:59:22

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

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

@@ -1,14 +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
+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$

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

@@ -1,66 +1,66 @@
-declare @siteid varchar(20)
-set @siteid =$siteid$
-select t1.fagentnum,fagentname,fagentshortname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
-(select t1.fagentnum,(t1.famount-t2.famount) famount1 from (
-select  t1.fagentnum,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())<=30 group by t1.fagentnum) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,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())<=30) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
-
-) t2 on t1.fagentnum=t2.fagentnum
-inner join 
-(select t1.fagentnum,(t1.famount-t2.famount) famount2 from (
-select  t1.fagentnum,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())<=90 group by t1.fagentnum) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,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())<=90) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
-
-) t3 on t1.fagentnum=t3.fagentnum
-inner join 
-(select t1.fagentnum,(t1.famount-t2.famount) famount3 from (
-select  t1.fagentnum,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())<=180 group by t1.fagentnum) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,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())<=180) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
-
-) t4 on t1.fagentnum=t4.fagentnum
-inner join 
-(select t1.fagentnum,(t1.famount-t2.famount) famount4 from (
-select  t1.fagentnum,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())<=365 group by t1.fagentnum) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,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())<=365) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
-
+declare @siteid varchar(20)
+set @siteid =$siteid$
+select t1.fagentnum,fagentname,fagentshortname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
+(select t1.fagentnum,(t1.famount-t2.famount) famount1 from (
+select  t1.fagentnum,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())<=30 group by t1.fagentnum) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,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())<=30) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
+
+) t2 on t1.fagentnum=t2.fagentnum
+inner join 
+(select t1.fagentnum,(t1.famount-t2.famount) famount2 from (
+select  t1.fagentnum,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())<=90 group by t1.fagentnum) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,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())<=90) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
+
+) t3 on t1.fagentnum=t3.fagentnum
+inner join 
+(select t1.fagentnum,(t1.famount-t2.famount) famount3 from (
+select  t1.fagentnum,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())<=180 group by t1.fagentnum) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,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())<=180) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
+
+) t4 on t1.fagentnum=t4.fagentnum
+inner join 
+(select t1.fagentnum,(t1.famount-t2.famount) famount4 from (
+select  t1.fagentnum,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())<=365 group by t1.fagentnum) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,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())<=365) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
+
 ) t5 on t1.fagentnum=t5.fagentnum where t1.fagentnum=$fagentnum$

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

@@ -1,66 +1,66 @@
-declare @siteid varchar(20)
-set @siteid =$siteid$
-select t1.fagentnum,fagentname,fagentshortname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
-(select t1.fagentnum,(t1.famount-t2.famount) famount1 from (
-select  t1.fagentnum,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())<=30 group by t1.fagentnum) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,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())<=30) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
-
-) t2 on t1.fagentnum=t2.fagentnum
-inner join 
-(select t1.fagentnum,(t1.famount-t2.famount) famount2 from (
-select  t1.fagentnum,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())<=90 group by t1.fagentnum) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,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())<=90) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
-
-) t3 on t1.fagentnum=t3.fagentnum
-inner join 
-(select t1.fagentnum,(t1.famount-t2.famount) famount3 from (
-select  t1.fagentnum,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())<=180 group by t1.fagentnum) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,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())<=180) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
-
-) t4 on t1.fagentnum=t4.fagentnum
-inner join 
-(select t1.fagentnum,(t1.famount-t2.famount) famount4 from (
-select  t1.fagentnum,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())<=365 group by t1.fagentnum) t1
-inner join (
-select fagentnum,sum(t.famount) famount from 
-(select distinct t2.saorderdetailid,t1.fagentnum,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())<=365) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
-
+declare @siteid varchar(20)
+set @siteid =$siteid$
+select t1.fagentnum,fagentname,fagentshortname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
+(select t1.fagentnum,(t1.famount-t2.famount) famount1 from (
+select  t1.fagentnum,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())<=30 group by t1.fagentnum) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,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())<=30) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
+
+) t2 on t1.fagentnum=t2.fagentnum
+inner join 
+(select t1.fagentnum,(t1.famount-t2.famount) famount2 from (
+select  t1.fagentnum,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())<=90 group by t1.fagentnum) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,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())<=90) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
+
+) t3 on t1.fagentnum=t3.fagentnum
+inner join 
+(select t1.fagentnum,(t1.famount-t2.famount) famount3 from (
+select  t1.fagentnum,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())<=180 group by t1.fagentnum) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,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())<=180) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
+
+) t4 on t1.fagentnum=t4.fagentnum
+inner join 
+(select t1.fagentnum,(t1.famount-t2.famount) famount4 from (
+select  t1.fagentnum,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())<=365 group by t1.fagentnum) t1
+inner join (
+select fagentnum,sum(t.famount) famount from 
+(select distinct t2.saorderdetailid,t1.fagentnum,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())<=365) t group by fagentnum) t2 on t1.fagentnum=t2.fagentnum
+
 ) t5 on t1.fagentnum=t5.fagentnum where t1.fagentnum=$fagentnum$

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

@@ -1,19 +1,19 @@
-declare @siteid varchar(20)
-set @siteid = $siteid$
-select t1.fagentnum,fagentname,fagentshortname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
-(select 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='HY' and  DateDiff(dd,checkdate,getdate())<=30 group by t1.fagentnum) t2 on t1.fagentnum=t2.fagentnum
-inner join 
-(select 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   DateDiff(dd,checkdate,getdate())<=90 group by t1.fagentnum) t3 on t1.fagentnum=t3.fagentnum
-inner join 
-(select 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   DateDiff(dd,checkdate,getdate())<=180 group by t1.fagentnum) t4 on t1.fagentnum=t4.fagentnum
-inner join 
-(select 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   DateDiff(dd,checkdate,getdate())<=365 group by t1.fagentnum) t5 on t1.fagentnum=t5.fagentnum
+declare @siteid varchar(20)
+set @siteid = $siteid$
+select t1.fagentnum,fagentname,fagentshortname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
+(select 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='HY' and  DateDiff(dd,checkdate,getdate())<=30 group by t1.fagentnum) t2 on t1.fagentnum=t2.fagentnum
+inner join 
+(select 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   DateDiff(dd,checkdate,getdate())<=90 group by t1.fagentnum) t3 on t1.fagentnum=t3.fagentnum
+inner join 
+(select 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   DateDiff(dd,checkdate,getdate())<=180 group by t1.fagentnum) t4 on t1.fagentnum=t4.fagentnum
+inner join 
+(select 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   DateDiff(dd,checkdate,getdate())<=365 group by t1.fagentnum) t5 on t1.fagentnum=t5.fagentnum
 where t1.fagentnum=$fagentnum$

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

@@ -1,18 +1,18 @@
-declare @siteid varchar(20)
-set @siteid = $siteid$
-select t1.fagentnum,fagentname,fagentshortname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
-(select 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   DateDiff(dd,checkdate,getdate())<=30  group by t1.fagentnum) t2 on t1.fagentnum=t2.fagentnum
-inner join 
-(select 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  DateDiff(dd,checkdate,getdate())<=90  group by t1.fagentnum) t3 on t1.fagentnum=t3.fagentnum
-inner join 
-(select 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  DateDiff(dd,checkdate,getdate())<=180  group by t1.fagentnum) t4 on t1.fagentnum=t4.fagentnum
-inner join 
-(select 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
+declare @siteid varchar(20)
+set @siteid = $siteid$
+select t1.fagentnum,fagentname,fagentshortname,t2.famount1,t3.famount2,t4.famount3,t5.famount4 from tagents t1 inner join 
+(select 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   DateDiff(dd,checkdate,getdate())<=30  group by t1.fagentnum) t2 on t1.fagentnum=t2.fagentnum
+inner join 
+(select 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  DateDiff(dd,checkdate,getdate())<=90  group by t1.fagentnum) t3 on t1.fagentnum=t3.fagentnum
+inner join 
+(select 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  DateDiff(dd,checkdate,getdate())<=180  group by t1.fagentnum) t4 on t1.fagentnum=t4.fagentnum
+inner join 
+(select 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  DateDiff(dd,checkdate,getdate())<=365  group by t1.fagentnum) t5 on t1.fagentnum=t5.fagentnum where t1.fagentnum=$fagentnum$

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

@@ -1,26 +1,25 @@
 declare @siteid varchar(20)
 set @siteid =$siteid$
-select t1.fsonum,t2.frownum,fpayagentnum,t1.frecagentnum,pp_hr.displayname,t2.fitemname,t2.fspec,t2.fmodel,tunit.fname,t2.fqty,t2.fprice,t2.frateamount,(t2.frateamount-isnull(t7.fwriteoffamount,0)) fwriteoffamount,t1.checkdate,t6.fdate,t3.fmaterial,t3.fdevice,t3.fspecalnote,t3.fitemno,t3.fnotes,TPROJECT.fprojectname,t4.kaipiaodate,(t2.frateamount-isnull(t7.finvoiceamount,0)) finvoiceamount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid 
+select (sainvoicedetail.famount-isnull(sainvoicedetail.finvoiceamount,0)) finvoiceamount ,t1.fsonum,t2.frownum,fpayagentnum,t1.frecagentnum,pp_hr.displayname,t2.fitemname,t2.fspec,t2.fmodel,tunit.fname,t2.fqty,t2.fprice,t2.frateamount,(sainvoicedetail.famount-isnull(sainvoicedetail.FWRITEOFFAMOUNT1,0)) fwriteoffamount,t1.checkdate,SAINVOICE.fdate,t3.fmaterial,t3.fdevice,t3.fspecalnote,t3.fitemno,t3.fnotes,TPROJECT.fprojectname,t4.kaipiaodate from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
 left join pp_hr on pp_hr.hrid=t1.fsaler and pp_hr.siteid=t1.siteid
 inner join tunit on tunit.FUNITID=t2.FUNITID
 inner join titem t3 on  t2.fitemno=t3.fitemno and t2.siteid=t3.siteid
 left join TPROJECT on TPROJECT.fprojectnum=t1.fprojectnum and TPROJECT.siteid=t1.siteid
 inner join(select t2.siteid,t2.saorderdetailid,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 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 group by t2.saorderdetailid,t2.siteid) t5 on t5.saorderdetailid=t2.saorderdetailid and t5.siteid=t2.siteid
-inner join (select  t2.saorderdetailid,t1.siteid,max(SAINVOICE.fdate) fdate from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid 
 inner join SAINVOICEDETAIL  on SAINVOICEDETAIL.FSOURCEID=t2.SAORDERDETAILID and SAINVOICEDETAIL.siteid=t2.siteid
-inner join SAINVOICE on SAINVOICEDETAIL.fparentid=SAINVOICE.sainvoiceid and SAINVOICEDETAIL.siteid=SAINVOICE.siteid group by t2.saorderdetailid,t1.siteid) t6 on t6.saorderdetailid=t2.saorderdetailid and t6.siteid=t2.siteid
+inner join SAINVOICE on SAINVOICEDETAIL.fparentid=SAINVOICE.sainvoiceid and SAINVOICEDETAIL.siteid=SAINVOICE.siteid
 inner join (select distinct t2.siteid,t2.saorderdetailid,isnull(t2.finvoiceamount,0) finvoiceamount,isnull(t2.fwriteoffamount,0) fwriteoffamount 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 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) 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 (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$ and $where$ order by t1.fsonum desc,t2.frownum asc
+
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),SAINVOICE.fdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) and t1.fagentnum=$fagentnum$ and $where$ order by t1.fsonum desc,t2.frownum asc
 

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

@@ -1,26 +1,25 @@
 declare @siteid varchar(20)
 set @siteid =$siteid$
-select t1.fsonum,t2.frownum,fpayagentnum,t1.frecagentnum,pp_hr.displayname,t2.fitemname,t2.fspec,t2.fmodel,tunit.fname,t2.fqty,t2.fprice,t2.frateamount,(t2.frateamount-isnull(t7.fwriteoffamount,0)) fwriteoffamount,t1.checkdate,t6.fdate,t3.fmaterial,t3.fdevice,t3.fspecalnote,t3.fitemno,t3.fnotes,TPROJECT.fprojectname,t4.kaipiaodate,(t2.frateamount-isnull(t7.finvoiceamount,0)) finvoiceamount from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid 
+select (sainvoicedetail.famount-isnull(sainvoicedetail.finvoiceamount,0)) finvoiceamount ,t1.fsonum,t2.frownum,fpayagentnum,t1.frecagentnum,pp_hr.displayname,t2.fitemname,t2.fspec,t2.fmodel,tunit.fname,t2.fqty,t2.fprice,t2.frateamount,(sainvoicedetail.famount-isnull(sainvoicedetail.FWRITEOFFAMOUNT1,0)) fwriteoffamount,t1.checkdate,SAINVOICE.fdate,t3.fmaterial,t3.fdevice,t3.fspecalnote,t3.fitemno,t3.fnotes,TPROJECT.fprojectname,t4.kaipiaodate from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
 left join pp_hr on pp_hr.hrid=t1.fsaler and pp_hr.siteid=t1.siteid
 inner join tunit on tunit.FUNITID=t2.FUNITID
 inner join titem t3 on  t2.fitemno=t3.fitemno and t2.siteid=t3.siteid
 left join TPROJECT on TPROJECT.fprojectnum=t1.fprojectnum and TPROJECT.siteid=t1.siteid
 inner join(select t2.siteid,t2.saorderdetailid,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 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 group by t2.saorderdetailid,t2.siteid) t5 on t5.saorderdetailid=t2.saorderdetailid and t5.siteid=t2.siteid
-inner join (select  t2.saorderdetailid,t1.siteid,max(SAINVOICE.fdate) fdate from saorder t1
-inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid 
 inner join SAINVOICEDETAIL  on SAINVOICEDETAIL.FSOURCEID=t2.SAORDERDETAILID and SAINVOICEDETAIL.siteid=t2.siteid
-inner join SAINVOICE on SAINVOICEDETAIL.fparentid=SAINVOICE.sainvoiceid and SAINVOICEDETAIL.siteid=SAINVOICE.siteid group by t2.saorderdetailid,t1.siteid) t6 on t6.saorderdetailid=t2.saorderdetailid and t6.siteid=t2.siteid
+inner join SAINVOICE on SAINVOICEDETAIL.fparentid=SAINVOICE.sainvoiceid and SAINVOICEDETAIL.siteid=SAINVOICE.siteid
 inner join (select distinct t2.siteid,t2.saorderdetailid,isnull(t2.finvoiceamount,0) finvoiceamount,isnull(t2.fwriteoffamount,0) fwriteoffamount 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 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) 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 (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,t6.fdate,getdate())<=365 and t1.fagentnum=$fagentnum$ and $where$ order by t1.fsonum desc,t2.frownum asc
+
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),SAINVOICE.fdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) and t1.fagentnum=$fagentnum$ and $where$ order by t1.fsonum desc,t2.frownum asc
 

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

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

+ 4 - 12
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单出货未付款金额查询.sql

@@ -1,14 +1,6 @@
-select isnull(SUM(famount6),0) famount  from (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount6 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+select sum(isnull(t4.famount,0)-isnull(t4.FWRITEOFFAMOUNT1,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 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$ 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(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 
-left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t1.siteid=$siteid$ and $where$) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t7 where  isnull(t7.famount6,0)>=0
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=$siteid$ and  $where$
+ and isnull(t4.famount,0)-isnull(t4.FWRITEOFFAMOUNT1,0)>0

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

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

+ 4 - 12
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单出货未开票金额查询.sql

@@ -1,14 +1,6 @@
-select isnull(SUM(famount6),0) famount  from (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount6 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+select sum(isnull(t4.famount,0)-isnull(t4.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 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$ 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(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 
-left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t1.siteid=$siteid$ and $where$) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t7 where  isnull(t7.famount6,0)>=0
+where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=$siteid$ and  $where$
+ and isnull(t4.famount,0)-isnull(t4.finvoiceamount,0)>0

+ 8 - 4
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单审核明细.sql

@@ -1,14 +1,18 @@
 declare @siteid varchar(20)
 set @siteid = $siteid$
-select t1.fsonum,t2.frownum,fpayagentnum,t1.frecagentnum,pp_hr.displayname,t2.fitemname,t2.fspec,t2.fmodel,tunit.fname,t2.fqty,t2.fprice,t2.frateamount,(t2.frateamount-isnull(t2.fwriteoffamount,0)) fwriteoffamount,CONVERT(VARCHAR(10),t1.checkdate,120) checkdate,SAINVOICE.fdate,t3.fmaterial,t3.fdevice,t3.fspecalnote,t3.fitemno,t3.fnotes,TPROJECT.fprojectname,t4.kaipiaodate,(t2.frateamount-isnull(t2.finvoiceamount,0)) finvoiceamount from saorder t1
+select t1.fsonum,t2.frownum,fpayagentnum,t1.frecagentnum,pp_hr.displayname,t2.fitemname,t2.fspec,t2.fmodel,tunit.fname,t2.fqty,t2.fprice,t2.frateamount,(t2.frateamount-isnull(t2.fwriteoffamount,0)) fwriteoffamount,CONVERT(VARCHAR(10),t1.checkdate,120) checkdate,t6.fdate,t3.fmaterial,t3.fdevice,t3.fspecalnote,t3.fitemno,t3.fnotes,TPROJECT.fprojectname,t4.kaipiaodate,(t2.frateamount-isnull(t2.finvoiceamount,0)) finvoiceamount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid 
 inner join pp_hr on pp_hr.hrid=t1.fsaler and pp_hr.siteid=@siteid
 inner join tunit on tunit.FUNITID=t2.FUNITID
-left join SAINVOICEDETAIL  on SAINVOICEDETAIL.FSOURCEID=t2.SAORDERDETAILID and SAINVOICEDETAIL.siteid=t2.siteid
-left join SAINVOICE on SAINVOICEDETAIL.fparentid=SAINVOICE.sainvoiceid and SAINVOICEDETAIL.siteid=SAINVOICE.siteid
+left join
+(select  t2.saorderdetailid,t1.siteid,max(SAINVOICE.fdate) fdate from saorder t1
+inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
+inner join SAINVOICEDETAIL  on SAINVOICEDETAIL.FSOURCEID=t2.SAORDERDETAILID and SAINVOICEDETAIL.siteid=t2.siteid
+inner join SAINVOICE on SAINVOICEDETAIL.fparentid=SAINVOICE.sainvoiceid and SAINVOICEDETAIL.siteid=SAINVOICE.siteid group by t2.saorderdetailid,t1.siteid
+) t6 on t6.saorderdetailid=t2.saorderdetailid and t6.siteid=t2.siteid
 inner join titem t3 on  t2.fitemno=t3.fitemno and t2.siteid=t3.siteid
 left join TPROJECT on TPROJECT.fprojectnum=t1.fprojectnum and TPROJECT.siteid=t1.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$ and $where$ order by t1.fsonum desc,t2.frownum asc
+where t1.fstatus in('ÉóºË','¹Ø±Õ') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) and t1.fagentnum=$fagentnum$ and $where$ order by t1.fsonum desc,t2.frownum asc
 

+ 150 - 150
src/rest/openapi/restcontroller/wechatapp/orderform/orderform.java

@@ -10,12 +10,12 @@ import openapi.base.data.Rows;
 import openapi.base.data.db.DBConnect;
 
 public class orderform extends Controller {
-    /**
-     * @param content
-     */
-    public orderform(JSONObject content) {
-        super(content);
-    }
+	/**
+	 * @param content
+	 */
+	public orderform(JSONObject content) {
+		super(content);
+	}
 	public String query_payamount() {
 		/**
 		 * 创建数据库连接
@@ -23,23 +23,23 @@ public class orderform extends Controller {
 		//System.out.println(111);
 		String type = content.getString("type");
 		DBConnect connect = new DBConnect();
-		 String where = " 1=1 ";
-		 if (type.equals("订单审核未收款")||type.equals("订单开票未收款")||type.equals("订单审核未收款")) {
-			 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();
-				}
+		String where = " 1=1 ";
+		if (type.equals("订单审核未收款")||type.equals("订单开票未收款")||type.equals("订单审核未收款")) {
+			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();
+			}
 		}else if(type.equals("订单出货未开票")) {
 			if(content.getInt("daynum")==0) {
 				where=where +" and CONVERT(VARCHAR(10),t3.fdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) ";
@@ -57,8 +57,8 @@ public class orderform extends Controller {
 				return getReturnObject_err("daynum参数数值不正确").toString();
 			}
 		}
-		
-		 
+
+
 //	        /**
 //	         *排序条件设置
 //	         */
@@ -67,36 +67,36 @@ public class orderform extends Controller {
 //	        if (content.containsKey("sort") && Arrays.asList(sortmsg).contains(content.getString("sort"))) {
 //	            sort = content.getString("sort");
 //	        }
-		   /**
-         * 过滤条件设置
-         */
-       
-        if (content.containsKey("where")) {
-            JSONObject whereObject = content.getJSONObject("where");
-            if (whereObject.containsKey("fsaler") && !"".equals(whereObject.getString("fsaler"))) {
-            	SQLFactory a = new SQLFactory(this, "下级业务员查询");
-        		a.addParameter("hrid", whereObject.getString("fsaler"));
-        	    a.addParameter("siteid", content.getString("siteid"));
-        	    Rows hridRows = connect.runSqlQuery(a.getSQL());
-        	    String hridinwhere = hridRows.getInWhere("hrid");
-                where = where + " and t1.fsaler in " +hridinwhere + " ";
-            }
-            if (whereObject.containsKey("fagentnum") && !"".equals(whereObject.getString("fagentnum"))) {
-                where = where + " and t1.fagentnum ='" + whereObject.getString("fagentnum") + "'";
-            }
-        }
+		/**
+		 * 过滤条件设置
+		 */
+
+		if (content.containsKey("where")) {
+			JSONObject whereObject = content.getJSONObject("where");
+			if (whereObject.containsKey("fsaler") && !"".equals(whereObject.getString("fsaler"))) {
+				SQLFactory a = new SQLFactory(this, "下级业务员查询");
+				a.addParameter("hrid", whereObject.getString("fsaler"));
+				a.addParameter("siteid", content.getString("siteid"));
+				Rows hridRows = connect.runSqlQuery(a.getSQL());
+				String hridinwhere = hridRows.getInWhere("hrid");
+				where = where + " and t1.fsaler in " +hridinwhere + " ";
+			}
+			if (whereObject.containsKey("fagentnum") && !"".equals(whereObject.getString("fagentnum"))) {
+				where = where + " and t1.fagentnum ='" + whereObject.getString("fagentnum") + "'";
+			}
+		}
 		/**
 		 * SQL查询参数设置并查询
 		 */
-		
+
 		if (type.equals("订单审核未收款")) {
 			//System.out.println(55);
 			//System.out.println(siteid);
 			SQLFactory factory = new SQLFactory(this, "订单审核未收款金额查询");
 			//factory.addParameter("fsaler", content.getString("fsaler"));
 			factory.addParameter("siteid", content.getString("siteid"));
-	        factory.addParameter_SQL("where", where);
-	        //System.err.println(factory.getSQL());
+			factory.addParameter_SQL("where", where);
+			//System.err.println(factory.getSQL());
 			Rows rows = connect.runSqlQuery(factory.getSQL());
 			//System.err.println(rows.getRow(0).getString("famount"));
 			return getReturnObject_suc(rows, false).toString();
@@ -104,15 +104,15 @@ 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);
+			factory.addParameter_SQL("where", where);
 			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("siteid", content.getString("siteid"));
-	        factory.addParameter_SQL("where", where);
-	        //System.out.println(factory.getSQL());
+			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"));
@@ -132,7 +132,7 @@ 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);
+			factory.addParameter_SQL("where", where);
 			Rows rows1 = connect.runSqlQuery(factory.getSQL());
 //			SQLFactory factory1 = new SQLFactory(this, "订单开票金额查询");
 //			//factory1.addParameter("fsaler", content.getString("fsaler"));
@@ -153,7 +153,7 @@ public class orderform extends Controller {
 		}
 
 	}
-	
+
 	public String query_payamountstatistics() {
 		/**
 		 * 创建数据库连接
@@ -161,23 +161,23 @@ 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 and  t7.fsaler in "+ hridinwhere +" ";
-        
-        if (content.containsKey("where")) {
-            JSONObject whereObject = content.getJSONObject("where");
-            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
-                where = where + " and (t1.fagentnum like'%" + whereObject.getString("condition") + "%' "
-                		      +"or fagentname like'%" + whereObject.getString("condition") + "%' "
-                		      +"or fagentshortname like'%" + whereObject.getString("condition") + "%' "
-                		      +"or pp_hr.displayname like'%" + whereObject.getString("condition") + "%') ";
-            }
-        }
+		a.addParameter("siteid", content.getString("siteid"));
+		Rows hridRows = connect.runSqlQuery(a.getSQL());
+		String hridinwhere = hridRows.getInWhere("hrid");
+		/**
+		 * 过滤条件设置
+		 */
+		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"))) {
+				where = where + " and (t1.fagentnum like'%" + whereObject.getString("condition") + "%' "
+						+"or fagentname like'%" + whereObject.getString("condition") + "%' "
+						+"or fagentshortname like'%" + whereObject.getString("condition") + "%' "
+						+"or pp_hr.displayname like'%" + whereObject.getString("condition") + "%') ";
+			}
+		}
 //	        /**
 //	         *排序条件设置
 //	         */
@@ -193,31 +193,31 @@ public class orderform extends Controller {
 			SQLFactory factory = new SQLFactory(this, "订单审核未收款账期统计查询");
 			//factory.addParameter("fsaler", hridinwhere);
 			factory.addParameter("siteid", content.getString("siteid"));
-			 factory.addParameter_SQL("where", where);
+			factory.addParameter_SQL("where", where);
 			// System.out.println(factory.getSQL());
 			Rows rows = connect.runSqlQuery(factory.getSQL());
-			 return getReturnObject_suc_page(rows, true, 1).toString();
+			return getReturnObject_suc_page(rows, true, 1).toString();
 		} else if (type.equals("订单开票未收款")) {
 			SQLFactory factory = new SQLFactory(this, "订单开票未收款账期统计查询");
 			//factory.addParameter("fsaler", hridinwhere);
 			factory.addParameter("siteid", content.getString("siteid"));
-			 factory.addParameter_SQL("where", where);
+			factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
-			 return getReturnObject_suc_page(rows, true, 1).toString();
+			return getReturnObject_suc_page(rows, true, 1).toString();
 		} else if (type.equals("订单出货未付款")) {
 			SQLFactory factory = new SQLFactory(this, "订单出货未付款账期统计查询");
 			//factory.addParameter("fsaler", hridinwhere);
 			factory.addParameter("siteid", content.getString("siteid"));
-			 factory.addParameter_SQL("where", where);
+			factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
-			 return getReturnObject_suc_page(rows, true, 1).toString();
+			return getReturnObject_suc_page(rows, true, 1).toString();
 		} else if (type.equals("订单出货未开票")) {
 			SQLFactory factory = new SQLFactory(this, "订单出货未开票账期统计查询");
 			//factory.addParameter("fsaler", hridinwhere);
 			factory.addParameter("siteid", content.getString("siteid"));
-			 factory.addParameter_SQL("where", where);
+			factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
-			 return getReturnObject_suc_page(rows, true, 1).toString();
+			return getReturnObject_suc_page(rows, true, 1).toString();
 		} else {
 			return getReturnObject_err("查询类型不存在").toString();
 		}
@@ -229,19 +229,19 @@ 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("condition") && !"".equals(whereObject.getString("condition"))) {
-                where = where + " and (t1.fagentnum like'%" + whereObject.getString("condition") + "%' "
-                		      +"or fagentname like'%" + whereObject.getString("condition") + "%' "
-                		      +"or fagentshortname like'%" + whereObject.getString("condition") + "%' "
-                		      +"or pp_hr.displayname like'%" + whereObject.getString("condition") + "%') ";
-            }
-        }
+		/**
+		 * 过滤条件设置
+		 */
+		String where = " 1=1 ";
+		if (content.containsKey("where")) {
+			JSONObject whereObject = content.getJSONObject("where");
+			if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+				where = where + " and (t1.fagentnum like'%" + whereObject.getString("condition") + "%' "
+						+"or fagentname like'%" + whereObject.getString("condition") + "%' "
+						+"or fagentshortname like'%" + whereObject.getString("condition") + "%' "
+						+"or pp_hr.displayname like'%" + whereObject.getString("condition") + "%') ";
+			}
+		}
 //	        /**
 //	         *排序条件设置
 //	         */
@@ -257,88 +257,88 @@ 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);
-		    System.out.println(factory.getSQL());
+			factory.addParameter_SQL("where", where);
+			System.out.println(factory.getSQL());
 			Rows rows = connect.runSqlQuery(factory.getSQL());
-			 return getReturnObject_suc_page(rows, true, 1).toString();
+			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);
+			factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
-			 return getReturnObject_suc_page(rows, true, 1).toString();
+			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);
+			factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
-			 return getReturnObject_suc_page(rows, true, 1).toString();
+			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);
+			factory.addParameter_SQL("where", where);
 			Rows rows = connect.runSqlQuery(factory.getSQL());
-			 return getReturnObject_suc_page(rows, true, 1).toString();
+			return getReturnObject_suc_page(rows, true, 1).toString();
 		} else {
 			return getReturnObject_err("查询类型不存在").toString();
 		}
 
 	}
 	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") + "%' "
-	                                +"or pp_hr.displayname like'%" + whereObject.getString("fsonum") + "%') ";
-	            }
-		 }
-	        /**
-	         * SQL到货确认单表头查询参数设置并查询
-	         */
-		 String type = content.getString("type");
-			if (type.equals("订单审核未收款")) {
-				SQLFactory factory = new SQLFactory(this, "订单审核明细");
-				factory.addParameter("fagentnum", fagentnum);
-		        factory.addParameter("siteid", content.getString("siteid"));
-		        where = where + " and (t2.frateamount-isnull(t2.fwriteoffamount,0))>0";
-		        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("fagentnum", fagentnum);
-		        factory.addParameter("siteid", content.getString("siteid"));
-		        where = where + " and isnull(t2.finvoiceamount,0)>isnull(t2.fwriteoffamount,0)";
-		        factory.addParameter_SQL("where", where);
-				Rows rows = connect.runSqlQuery(factory.getSQL());
-				return getReturnObject_suc_page(rows, true, 1).toString();
-			} else if (type.equals("订单出货未付款")) {
-				//System.out.println(555);
-				SQLFactory factory = new SQLFactory(this, "订单出货明细");
-				//factory.addParameter("fsaler", content.getString("fsaler"));
-				factory.addParameter("fagentnum", fagentnum);
-		        factory.addParameter("siteid", content.getString("siteid"));
-		        where = where + " and (t2.frateamount-isnull(t7.fwriteoffamount,0))>0";
-		        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, "订单出货明细1");
-				factory.addParameter("fagentnum", fagentnum);
-		        factory.addParameter("siteid", content.getString("siteid"));
-		        where = where + " and (t2.frateamount-isnull(t7.finvoiceamount,0))>0";
-		        factory.addParameter_SQL("where", where);
-				Rows rows = connect.runSqlQuery(factory.getSQL());
-				return getReturnObject_suc_page(rows, true, 1).toString();
-			} else {
-				return getReturnObject_err("查询类型不存在").toString();
-			}   
+		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") + "%' "
+						+"or pp_hr.displayname like'%" + whereObject.getString("fsonum") + "%') ";
+			}
+		}
+		/**
+		 * SQL到货确认单表头查询参数设置并查询
+		 */
+		String type = content.getString("type");
+		if (type.equals("订单审核未收款")) {
+			SQLFactory factory = new SQLFactory(this, "订单审核明细");
+			factory.addParameter("fagentnum", fagentnum);
+			factory.addParameter("siteid", content.getString("siteid"));
+			where = where + " and (t2.frateamount-isnull(t2.fwriteoffamount,0))>0";
+			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("fagentnum", fagentnum);
+			factory.addParameter("siteid", content.getString("siteid"));
+			where = where + " and isnull(t2.finvoiceamount,0)>isnull(t2.fwriteoffamount,0)";
+			factory.addParameter_SQL("where", where);
+			Rows rows = connect.runSqlQuery(factory.getSQL());
+			return getReturnObject_suc_page(rows, true, 1).toString();
+		} else if (type.equals("订单出货未付款")) {
+			//System.out.println(555);
+			SQLFactory factory = new SQLFactory(this, "订单出货明细");
+			//factory.addParameter("fsaler", content.getString("fsaler"));
+			factory.addParameter("fagentnum", fagentnum);
+			factory.addParameter("siteid", content.getString("siteid"));
+			where = where + " and (t2.frateamount-isnull(t7.fwriteoffamount,0))>0";
+			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, "订单出货明细1");
+			factory.addParameter("fagentnum", fagentnum);
+			factory.addParameter("siteid", content.getString("siteid"));
+			where = where + " and (t2.frateamount-isnull(t7.finvoiceamount,0))>0";
+			factory.addParameter_SQL("where", where);
+			Rows rows = connect.runSqlQuery(factory.getSQL());
+			return getReturnObject_suc_page(rows, true, 1).toString();
+		} else {
+			return getReturnObject_err("查询类型不存在").toString();
+		}
 	}
-	
+
 }