Explorar o código

海盐订单统计出货核销sql更改2021年12月24日11:24:45

hu %!s(int64=4) %!d(string=hai) anos
pai
achega
741a1a5600

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

@@ -10,7 +10,7 @@ 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(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
+(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
 left 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
@@ -25,7 +25,7 @@ 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(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
+(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
 left 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
@@ -40,7 +40,7 @@ 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(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
+(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
 left 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
@@ -55,7 +55,7 @@ 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(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
+(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
 left 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
@@ -70,7 +70,7 @@ 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(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
+(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
 left 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
@@ -85,7 +85,7 @@ 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(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
+(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
 left 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

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

@@ -1,4 +1,4 @@
-select SUM(famount6) famount from (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount6 from (
+select isnull(SUM(famount6),0) famount6  from (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 
@@ -6,7 +6,7 @@ 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(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
+(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
 left 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

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

@@ -10,7 +10,7 @@ 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(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
+(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
 left 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
@@ -25,7 +25,7 @@ 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(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
+(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
 left 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
@@ -40,7 +40,7 @@ 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(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
+(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
 left 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
@@ -55,7 +55,7 @@ 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(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
+(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
 left 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
@@ -70,7 +70,7 @@ 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(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
+(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
 left 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
@@ -85,7 +85,7 @@ 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(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
+(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
 left 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

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

@@ -1,4 +1,4 @@
-select SUM(famount6) famount from (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount6 from (
+select isnull(SUM(famount6),0) famount6  from (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 
@@ -6,7 +6,7 @@ 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(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
+(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
 left 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