|
|
@@ -2,27 +2,27 @@ 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(t7.famount6,0) ftotalamount from tagents t1
|
|
|
inner join
|
|
|
-(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount6 from saorder t1
|
|
|
+(select fsaler,t1.fagentnum,sum(t2.frateamount-t2.frateprice*isnull(t2.freturnqty,0)-isnull(t2.fwriteoffamount,0))famount6 from saorder t1
|
|
|
inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
|
|
|
where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) group by t1.fagentnum,fsaler) t7 on t1.fagentnum=t7.fagentnum
|
|
|
left join
|
|
|
-(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount1 from saorder t1
|
|
|
+(select fsaler,t1.fagentnum,sum(t2.frateamount-t2.frateprice*isnull(t2.freturnqty,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 t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) group by t1.fagentnum,fsaler) t2 on t7.fagentnum=t2.fagentnum and t7.fsaler=t2.fsaler
|
|
|
left join
|
|
|
-(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount2 from saorder t1
|
|
|
+(select fsaler,t1.fagentnum,sum(t2.frateamount-t2.frateprice*isnull(t2.freturnqty,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 t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) group by t1.fagentnum,fsaler) t3 on t7.fagentnum=t3.fagentnum and t7.fsaler=t3.fsaler
|
|
|
left join
|
|
|
-(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount3 from saorder t1
|
|
|
+(select fsaler,t1.fagentnum,sum(t2.frateamount-t2.frateprice*isnull(t2.freturnqty,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 t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) group by t1.fagentnum,fsaler) t4 on t7.fagentnum=t4.fagentnum and t7.fsaler=t4.fsaler
|
|
|
left join
|
|
|
-(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount4 from saorder t1
|
|
|
+(select fsaler,t1.fagentnum,sum(t2.frateamount-t2.frateprice*isnull(t2.freturnqty,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 t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) group by t1.fagentnum,fsaler) t5 on t7.fagentnum=t5.fagentnum and t7.fsaler=t5.fsaler
|
|
|
left join
|
|
|
-(select fsaler,t1.fagentnum,sum(t2.frateamount-isnull(t2.fwriteoffamount,0))famount5 from saorder t1
|
|
|
+(select fsaler,t1.fagentnum,sum(t2.frateamount-t2.frateprice*isnull(t2.freturnqty,0)-isnull(t2.fwriteoffamount,0))famount5 from saorder t1
|
|
|
inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
|
|
|
where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) group by t1.fagentnum,fsaler) t6 on t7.fagentnum=t6.fagentnum and t7.fsaler=t6.fsaler
|
|
|
inner join pp_hr on pp_hr.hrid=t7.fsaler where $where$ order by ftotalamount desc
|