|
@@ -1,6 +1,6 @@
|
|
|
declare @siteid varchar(20)
|
|
declare @siteid varchar(20)
|
|
|
set @siteid = $siteid$
|
|
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,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
|
|
|
|
|
|
|
+select t1.fsonum,t2.frownum,t5.fagentshortname fpayagentnum,t7.fagentshortname 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 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 pp_hr on pp_hr.hrid=t1.fsaler and pp_hr.siteid=@siteid
|
|
|
inner join tunit on tunit.FUNITID=t2.FUNITID
|
|
inner join tunit on tunit.FUNITID=t2.FUNITID
|
|
@@ -14,5 +14,7 @@ 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 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 (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
|
|
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
|
|
|
|
|
+left join tagents t5 on fpayagentnum=t5.fagentnum and t1.siteid=t5.siteid
|
|
|
|
|
+left join tagents t7 on t1.frecagentnum=t7.fagentnum and t1.siteid=t7.siteid
|
|
|
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
|
|
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
|
|
|
|
|
|