strSql.Append(",case OPDATE when '' then 0 else case when BALTTLDR<>0 OR BALTTLCR<>0 then DATEDIFF([day],CASE WHEN STLDATE IS NULL THEN OPDATE ELSE STLDATE END,GETDATE()) ");
strSql.Append(" else (DATEDIFF([day],CASE WHEN STLDATE IS NULL THEN OPDATE ELSE STLDATE END,SETTLETIME)) end end AS NODAY");
strSql.Append("case A.ETD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), A.ETD,23) end as ETD");
strSql.Append(",case A.ETA when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), A.ETA,23) end as ETA,case A.ATD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), A.ATD,23) end as ATD");
if(NORPTSTLDATETYPE.PARAMVALUE=="1")
{
strSql.Append(",CASE WHEN A.CUSTOMERNAME=F.CUSTOMERNAME THEN A.STLNAME ELSE isnull((select top 1 ACCTYPE from Info_Client_ACCDATE where LINKGID = (select top 1 GID from info_client where shortname =F.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=A.SALE)) and BGNDATE<=A.OPDATE AND ENDDATE>=A.OPDATE),'现结买单') END STLNAME");
}
else{
strSql.Append(",A.STLNAME STLNAME");
}
strSql.Append(",case A.OPDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), A.OPDATE,23) end as OPDATE,A.ENTERP,A.DELIVERYDATE");
strSql.Append(",case A.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), A.CUSTOMDATE,23) end as CUSTOMDATE,A.SERVICECONTRACTNO");
strSql.Append(",A.CNTR1,A.CNTR2,A.CNTR3,A.CNTR4,A.CNTR5,A.CNTR6,A.CNTR7,A.CNTR8,A.CNTR9,A.CNTR10,A.OTCNTR,A.TRADETYPE,A.GOODSNAME,A.FEESTATUS,A.PKGS,A.CBM,A.ORDERNO,A.SALECORPID,(select [NAME] from [company] where GID=A.SALECORPID) as SALECORP");
strSql.Append(",(CASE A.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,A.AGENTID ");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTCR,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'RMB' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVRMB,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVUSD,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(ORDERAMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(ORDERAMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLCR");
strSql.Append(",case when isnull(SUM(F.AMOUNT),0)<>isnull(SUM(F.SETTLEMENT),0) then (case A.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],A.OPDATE, GETDATE()) end) ");
strSql.Append(" else (case A.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],A.OPDATE, S.SETTLETIME) end) end AS ACTUALDAY,S.SETTLETIME");
if(NORPTSTLDATETYPE.PARAMVALUE=="1")
{
strSql.Append(",[dbo].[GetCustStlDay](A.OPDATE,F.CUSTOMERNAME,A.SALE) AS STLDATE");
strSql.Append(",isnull((select top 1 case ACCTYPE WHEN '月结' then accmonth*30 + accdays WHEN '季结' then accmonth*90 + accdays WHEN '旬结' then 10 else accdays end from Info_Client_ACCDATE where LINKGID = (select top 1 GID from info_client where shortname =F.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=B.SALE)) and BGNDATE<=B.OPDATE AND ENDDATE>=B.OPDATE),0) CONTRACTDAY ");
}
else{
strSql.Append(",CASE WHEN A.STLDATE IS NULL THEN A.OPDATE ELSE A.STLDATE END STLDATE");
strSql.Append(",isnull((select top 1 case ACCTYPE WHEN '月结' then accmonth*30 + accdays WHEN '季结' then accmonth*90 + accdays WHEN '旬结' then 10 else accdays end from Info_Client_ACCDATE where LINKGID = (select top 1 GID from info_client where shortname =A.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=B.SALE)) and BGNDATE<=B.OPDATE AND ENDDATE>=B.OPDATE),0) CONTRACTDAY ");
}
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
//strSql.Append(",case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else case when isnull(SUM(F.AMOUNT),0)<>isnull(SUM(F.SETTLEMENT),0) then DATEDIFF([day],B.OPDATE,(CASE C.STLNAME WHEN '月结' THEN ");
//strSql.Append("DATEADD(month,1,DATEADD(day,ISNULL(CAST(C.STLDATE AS INT),1),DATEADD(day,-Day(B.OPDATE)+1,B.OPDATE)))");
//strSql.Append("WHEN '半月结' THEN (CASE WHEN DATEPART(DAY, GETDATE())<=15 THEN DATEADD(day,ISNULL(CAST(C.STLFIRSTHALFDATE AS INT),16),DATEADD(Day,-Day(B.OPDATE)+1,B.OPDATE))");
//strSql.Append("ELSE DATEADD(MONTH,1,DATEADD(day,ISNULL(CAST(C.STLMIDDLEDATE AS INT),1),DATEADD(Day,-Day(B.OPDATE)+1,B.OPDATE))) END)");
//strSql.Append("ELSE GETDATE() END)) else (DATEDIFF([day],B.OPDATE, S.SETTLETIME)) end end AS NODAY");
strSql.Append("case B.ETD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.ETD,23) end as ETD");
strSql.Append(",case B.ETA when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.ETA,23) end as ETA,case B.ATD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.ATD,23) end as ATD");
if(NORPTSTLDATETYPE.PARAMVALUE=="1")
{
strSql.Append(",CASE WHEN B.CUSTOMERNAME=F.CUSTOMERNAME THEN B.STLNAME ELSE isnull((select top 1 ACCTYPE from Info_Client_ACCDATE where LINKGID = (select top 1 GID from info_client where shortname =F.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=B.SALE)) and BGNDATE<=B.OPDATE AND ENDDATE>=B.OPDATE),'现结买单') END STLNAME");
}
else{
strSql.Append(",B.STLNAME STLNAME");
}
strSql.Append(",case B.OPDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.OPDATE,23) end as OPDATE,B.ENTERP,B.DELIVERYDATE");
strSql.Append(",case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE,B.SERVICECONTRACTNO");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS,B.PKGS,B.CBM,B.ORDERNO,B.SALECORPID,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
strSql.Append(",(CASE B.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,B.AGENTID ");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTCR,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'RMB' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVRMB,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVUSD,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(ORDERAMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(ORDERAMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLCR");
strSql.Append(",case when isnull(SUM(F.AMOUNT),0)<>isnull(SUM(F.SETTLEMENT),0) then (case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],B.OPDATE, GETDATE()) end) ");
strSql.Append(" else (case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],B.OPDATE, S.SETTLETIME) end) end AS ACTUALDAY,S.SETTLETIME");
if(NORPTSTLDATETYPE.PARAMVALUE=="1")
{
strSql.Append(",[dbo].[GetCustStlDay](B.OPDATE,F.CUSTOMERNAME,B.SALE) AS STLDATE");
strSql.Append(",isnull((select top 1 case ACCTYPE WHEN '月结' then accmonth*30 + accdays WHEN '季结' then accmonth*90 + accdays WHEN '旬结' then 10 else accdays end from Info_Client_ACCDATE where LINKGID = (select top 1 GID from info_client where shortname =F.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=B.SALE)) and BGNDATE<=B.OPDATE AND ENDDATE>=B.OPDATE),0) CONTRACTDAY ");
}
else
{
strSql.Append(",CASE WHEN B.STLDATE IS NULL THEN B.OPDATE ELSE B.STLDATE END STLDATE");
strSql.Append(",isnull((select top 1 case ACCTYPE WHEN '月结' then accmonth*30 + accdays WHEN '季结' then accmonth*90 + accdays WHEN '旬结' then 10 else accdays end from Info_Client_ACCDATE where LINKGID = (select top 1 GID from info_client where shortname =B.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=B.SALE)) and BGNDATE<=B.OPDATE AND ENDDATE>=B.OPDATE),0) CONTRACTDAY ");
}
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
//strSql.Append(",case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else case when isnull(SUM(F.AMOUNT),0)<>isnull(SUM(F.SETTLEMENT),0) then DATEDIFF([day],B.OPDATE,(CASE C.STLNAME WHEN '月结' THEN ");
//strSql.Append("DATEADD(month,1,DATEADD(day,ISNULL(CAST(C.STLDATE AS INT),1),DATEADD(day,-Day(B.OPDATE)+1,B.OPDATE)))");
//strSql.Append("WHEN '半月结' THEN (CASE WHEN DATEPART(DAY, GETDATE())<=15 THEN DATEADD(day,ISNULL(CAST(C.STLFIRSTHALFDATE AS INT),16),DATEADD(Day,-Day(B.OPDATE)+1,B.OPDATE))");
//strSql.Append("ELSE DATEADD(MONTH,1,DATEADD(day,ISNULL(CAST(C.STLMIDDLEDATE AS INT),1),DATEADD(Day,-Day(B.OPDATE)+1,B.OPDATE))) END)");
//strSql.Append("ELSE GETDATE() END)) else (DATEDIFF([day],B.OPDATE, S.SETTLETIME)) end end AS NODAY");
// strSql.Append(",INVOICENO = stuff ((SELECT distinct INVOICENUM+',' FROM CH_FEE AS t WHERE ISNULL(t.INVOICENUM,'')<>'' AND t .BSNO = B.BSNO and t.CUSTOMERNAME=f.CUSTOMERNAME FOR xml path('')), 1, 0, '') ");
strSql.Append(",INVOICENO = stuff ((SELECT distinct i.INVOICENO+',' FROM CH_FEE_DO AS t left join ch_fee_invoice i on (i.BILLNO=t.BILLNO) WHERE t.CATEGORY=7 and t .BSNO = B.BSNO and i.CUSTOMERNAME=f.CUSTOMERNAME FOR xml path('')), 1, 0, '') ");
}
else
{
strSql.Append(",INVOICENO = stuff ((SELECT distinct BILLNO+',' FROM CH_FEE_DO AS t WHERE t.CATEGORY=4 and t .BSNO = B.BSNO and t.CUSTOMERNAME=f.CUSTOMERNAME FOR xml path('')), 1, 0, '') ");
// strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS STLTTLDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLDR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS STLTTLCR,");
// strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLCR");
// strSql.Append(" FROM CH_FEE F ");
// strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
// if (!string.IsNullOrEmpty(condition))
// {
// strSql.Append(" Where " + condition);
// }
// strSql.Append("GROUP BY F.CUSTOMERNAME,B.OPLBNAME, B.BSTYPE");
strSql.Append(",F.GID,F.FEETYPE,F.FEENAME,F.FEEDESCRIPTION,F.CUSTOMERNAME AS CUSTNAME,F.UNIT,F.UNITPRICE,F.QUANTITY,F.AMOUNT,F.CURRENCY,F.EXCHANGERATE,F.DEBITNO");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=F.FeeStatus) as FeeStatus_Ref");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=F.FeeType) as FeeType_Ref");
strSql.Append(",(select ShowName from [user] where GID=F.EnteroPerator) as ENTEROPERATORREF");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME,(SELECT TOP 1 INVOICENO FROM ch_fee_invoice WHERE BILLNO IN (SELECT BILLNO FROM CH_FEE_DO WHERE FEEID=F.GID )) INVOICENUM ");
strSql.Append(",cast(round( CASE WHEN ISNULL(ACCTAXRATE,0)=0 THEN ISNULL(AMOUNT,0) ELSE ISNULL(AMOUNT,0)- cast(round((ISNULL(AMOUNT,0)/(1+ACCTAXRATE/100)*ACCTAXRATE/100),2) as numeric(20,2)) END ,2) as numeric(20,2)) AS NOACCTAXAMOUNT");
strSql.Append(",cast(round((ISNULL(AMOUNT,0)/(1+ACCTAXRATE/100)*ACCTAXRATE/100),2) as numeric(20,2)) ACCTAX");
//strSql.Append(",C.ACTUALDAY,C.NODAY");
//strSql.Append(",case when isnull(F.AMOUNT,0)<>isnull(F.SETTLEMENT,0) then (case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],B.OPDATE, GETDATE()) end) ");
//strSql.Append(" else (case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],B.OPDATE, (SELECT MAX(SETTLETIME) FROM v_fee_do_settlement S WHERE S.BSNO=B.BSNO AND S.CUSTOMERNAME=F.CUSTOMERNAME)) end) end AS ACTUALDAY");
//strSql.Append(",case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else case when isnull(F.AMOUNT,0)<>isnull(F.SETTLEMENT,0) then DATEDIFF([day],B.OPDATE,(CASE C.STLNAME WHEN '月结' THEN ");
//strSql.Append("DATEADD(month,1,DATEADD(day,ISNULL(CAST(C.STLDATE AS INT),1),DATEADD(day,-Day(B.OPDATE)+1,B.OPDATE)))");
//strSql.Append("WHEN '半月结' THEN (CASE WHEN DATEPART(DAY, GETDATE())<=15 THEN DATEADD(day,ISNULL(CAST(C.STLFIRSTHALFDATE AS INT),16),DATEADD(Day,-Day(B.OPDATE)+1,B.OPDATE))");
//strSql.Append("ELSE DATEADD(MONTH,1,DATEADD(day,ISNULL(CAST(C.STLMIDDLEDATE AS INT),1),DATEADD(Day,-Day(B.OPDATE)+1,B.OPDATE))) END)");
//strSql.Append("ELSE GETDATE() END)) else (DATEDIFF([day],B.OPDATE, (SELECT MAX(SETTLETIME) FROM v_fee_do_settlement S WHERE S.BSNO=B.BSNO AND S.CUSTOMERNAME=F.CUSTOMERNAME))) end end AS NODAY");
//strSql.Append(",case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],B.OPDATE, GETDATE()) end AS ACTUALDAY");
//strSql.Append(",case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],B.OPDATE,(CASE C.STLNAME WHEN '月结' THEN ");
//strSql.Append("DATEADD(month,1,DATEADD(day,ISNULL(CAST(C.STLDATE AS INT),1),DATEADD(day,-Day(B.OPDATE)+1,B.OPDATE)))");
//strSql.Append("WHEN '半月结' THEN (CASE WHEN DATEPART(DAY, GETDATE())<=15 THEN DATEADD(day,ISNULL(CAST(C.STLFIRSTHALFDATE AS INT),16),DATEADD(Day,-Day(B.OPDATE)+1,B.OPDATE))");
//strSql.Append("ELSE DATEADD(MONTH,1,DATEADD(day,ISNULL(CAST(C.STLMIDDLEDATE AS INT),1),DATEADD(Day,-Day(B.OPDATE)+1,B.OPDATE))) END)");
//strSql.Append("ELSE GETDATE() END)) end AS NODAY");
//strSql.Append(",(SELECT MAX(SETTLETIME) FROM v_fee_do_settlement S WHERE S.BSNO=B.BSNO AND S.CUSTOMERNAME=F.CUSTOMERNAME) AS SETTLEDATE");
strSql.Append(" FROM CH_FEE F WITH (NOLOCK) ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
//strSql.Append(" INNER JOIN V_CUSTSTLDATE C ON (C.BSNO=B.BSNO AND C.CUSTNAME=F.CUSTOMERNAME) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
strSql.Append(",0 AS RMBDR,0 AS STLRMBDR,0 AS BALRMBDR,0 AS ORDERRMBDR,");
else
{
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS RMBCR,0 AS STLRMBCR,0 AS BALRMBCR,0 AS ORDERRMBCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS USDDR,0 AS STLUSDDR,0 AS BALUSDDR,0 AS ORDERUSDDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS USDCR,0 AS STLUSDCR,0 AS BALUSDCR,0 AS ORDERUSDCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS OTDR,0 AS STLOTDR,0 AS BALOTDR,0 AS ORDEROTDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS OTCR,0 AS STLOTCR,0 AS BALOTCR,0 AS ORDEROTCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS TTLDR,0 AS STLTTLDR,0 AS BALTTLDR,0 AS ORDERTTLDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(ORDERAMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS TTLCR,0 AS STLTTLCR,0 AS BALTTLCR,0 AS ORDERTTLCR");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(ORDERAMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLCR");
}
strSql.Append(" FROM CH_FEE F WITH (NOLOCK) ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append("SELECT F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
if(noDrCr=="10"||noDrCr=="11")
strSql.Append(",0 AS RMBDR,0 AS STLRMBDR,0 AS BALRMBDR,0 AS ORDERRMBDR,");
else
{
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS RMBCR,0 AS STLRMBCR,0 AS BALRMBCR,0 AS ORDERRMBCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS USDDR,0 AS STLUSDDR,0 AS BALUSDDR,0 AS ORDERUSDDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS USDCR,0 AS STLUSDCR,0 AS BALUSDCR,0 AS ORDERUSDCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS OTDR,0 AS STLOTDR,0 AS BALOTDR,0 AS ORDEROTDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS OTCR,0 AS STLOTCR,0 AS BALOTCR,0 AS ORDEROTCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS TTLDR,0 AS STLTTLDR,0 AS BALTTLDR,0 AS ORDERTTLDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(ORDERAMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS TTLCR,0 AS STLTTLCR,0 AS BALTTLCR,0 AS ORDERTTLCR");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(ORDERAMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLCR");
strSql.Append(",0 AS RMBDR,0 AS STLRMBDR,0 AS BALRMBDR,0 AS ORDERRMBDR,");
else
{
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS RMBCR,0 AS STLRMBCR,0 AS BALRMBCR,0 AS ORDERRMBCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS USDDR,0 AS STLUSDDR,0 AS BALUSDDR,0 AS ORDERUSDDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS USDCR,0 AS STLUSDCR,0 AS BALUSDCR,0 AS ORDERUSDCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS OTDR,0 AS STLOTDR,0 AS BALOTDR,0 AS ORDEROTDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS OTCR,0 AS STLOTCR,0 AS BALOTCR,0 AS ORDEROTCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS TTLDR,0 AS STLTTLDR,0 AS BALTTLDR,0 AS ORDERTTLDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(ORDERAMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS TTLCR,0 AS STLTTLCR,0 AS BALTTLCR,0 AS ORDERTTLCR");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(ORDERAMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLCR");
}
strSql.Append(" FROM CH_FEE F WITH (NOLOCK) ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append("SELECT B.SALE,F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
if(noDrCr=="10"||noDrCr=="11")
strSql.Append(",0 AS RMBDR,0 AS STLRMBDR,0 AS BALRMBDR,0 AS ORDERRMBDR,");
else
{
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS RMBCR,0 AS STLRMBCR,0 AS BALRMBCR,0 AS ORDERRMBCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS USDDR,0 AS STLUSDDR,0 AS BALUSDDR,0 AS ORDERUSDDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS USDCR,0 AS STLUSDCR,0 AS BALUSDCR,0 AS ORDERUSDCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS OTDR,0 AS STLOTDR,0 AS BALOTDR,0 AS ORDEROTDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS OTCR,0 AS STLOTCR,0 AS BALOTCR,0 AS ORDEROTCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS TTLDR,0 AS STLTTLDR,0 AS BALTTLDR,0 AS ORDERTTLDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(ORDERAMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS TTLCR,0 AS STLTTLCR,0 AS BALTTLCR,0 AS ORDERTTLCR");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(ORDERAMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLCR");
}
strSql.Append(" FROM CH_FEE F WITH (NOLOCK) ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" Group by B.SALE,F.CUSTOMERNAME,C.[DESCRIPTION] ");
strSql.Append(",0 AS RMBDR,0 AS STLRMBDR,0 AS BALRMBDR,0 AS ORDERRMBDR,");
else
{
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS RMBCR,0 AS STLRMBCR,0 AS BALRMBCR,0 AS ORDERRMBCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS USDDR,0 AS STLUSDDR,0 AS BALUSDDR,0 AS ORDERUSDDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS USDCR,0 AS STLUSDCR,0 AS BALUSDCR,0 AS ORDERUSDCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS OTDR,0 AS STLOTDR,0 AS BALOTDR,0 AS ORDEROTDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS OTCR,0 AS STLOTCR,0 AS BALOTCR,0 AS ORDEROTCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS TTLDR,0 AS STLTTLDR,0 AS BALTTLDR,0 AS ORDERTTLDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(ORDERAMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS TTLCR,0 AS STLTTLCR,0 AS BALTTLCR,0 AS ORDERTTLCR");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(ORDERAMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLCR");
}
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(",0 AS RMBDR,0 AS STLRMBDR,0 AS BALRMBDR,0 AS ORDERRMBDR,");
else
{
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS RMBCR,0 AS STLRMBCR,0 AS BALRMBCR,0 AS ORDERRMBCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS ORDERRMBCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS USDDR,0 AS STLUSDDR,0 AS BALUSDDR,0 AS ORDERUSDDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS USDCR,0 AS STLUSDCR,0 AS BALUSDCR,0 AS ORDERUSDCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(ORDERAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS ORDERUSDCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS OTDR,0 AS STLOTDR,0 AS BALOTDR,0 AS ORDEROTDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS OTCR,0 AS STLOTCR,0 AS BALOTCR,0 AS ORDEROTCR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(ORDERAMOUNT,0) END) END)ELSE 0 END),0) AS ORDEROTCR,");
}
if(noDrCr=="10"||noDrCr=="11")
strSql.Append("0 AS TTLDR,0 AS STLTTLDR,0 AS BALTTLDR,0 AS ORDERTTLDR,");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(ORDERAMOUNT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLDR,");
}
if(noDrCr=="01"||noDrCr=="11")
strSql.Append("0 AS TTLCR,0 AS STLTTLCR,0 AS BALTTLCR,0 AS ORDERTTLCR");
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS TTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS STLTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN cast(round(ISNULL(ORDERAMOUNT,0) *ISNULL( EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS ORDERTTLCR");
}
strSql.Append(" FROM CH_FEE F WITH (NOLOCK) ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(",B.TRADETYPE,B.GOODSNAME,B.FEESTATUS,B.PKGS,B.CBM,B.ORDERNO,B.SALECORPID,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
strSql.Append(",(CASE B.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN CURRENCY='USD' AND FEENAME='海运费' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDHYFCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN CURRENCY='USD' AND FEENAME='海运费' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDHYFCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN CURRENCY='USD' AND FEENAME='海运费' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDHYFCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN cast(round(ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0),2) as numeric(20,2)) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("case when isnull(SUM(F.AMOUNT),0)<>isnull(SUM(F.SETTLEMENT),0) then (case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],B.OPDATE, GETDATE()) end) ");
strSql.Append(" else (case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],B.OPDATE, S.SETTLETIME) end) end AS ACTUALDAY,S.SETTLETIME");
strSql.Append(",CASE WHEN B.STLDATE IS NULL THEN B.OPDATE ELSE B.STLDATE END STLDATE");
strSql.Append(",isnull((select top 1 case ACCTYPE WHEN '月结' then accmonth*30 + accdays WHEN '季结' then accmonth*90 + accdays WHEN '旬结' then 10 else accdays end from Info_Client_ACCDATE where LINKGID = (select top 1 GID from info_client where shortname =B.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=B.SALE)) and BGNDATE<=B.OPDATE AND ENDDATE>=B.OPDATE),0) CONTRACTDAY ");
str=" (B.Corpid='"+Convert.ToString(reader["COMPANYID"])+"' or B.SALECORPID='"+Convert.ToString(reader["COMPANYID"])+"' ";
}
else
{
str=str+" or B.Corpid='"+Convert.ToString(reader["COMPANYID"])+"' or B.SALECORPID='"+Convert.ToString(reader["COMPANYID"])+"'";
};
}
str=str+")";
reader.Close();
}
}
elseif(visiblerange=="6")
{
varopstr="";
varuserstr=newStringBuilder();
userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='"+userid+"' and AUTHORITYID='"+AUTHORITYID+"' and VISIBLERANGE=1");
strSql.Append(" from ch_fee f left join v_op_bill b on (b.BSNO=f.BSNO) ");
strSql.Append(" where f.FEESTATUS=0 and f.SETTLEMENT=0 and f.ORDERAMOUNT=0 and f.ORDERINVOICE=0 AND ISNULL(F.INVOICE,0)=0 AND F.AMOUNT<>0) as v");
strSql.Append(" group by PARENTID,CUSTNAME,FEETYPE,CURRENCY,OPLB,OPLBNAME,BSTYPE,CUSTOMERNAME,MBLNO,HBLNO,VESSEL,VOYNO,BSSTATUS,SALE,OP,DOC,");
strSql.Append(" ETD,CUSTSERVICE,PORTLOAD,PORTDISCHARGE,CUSTOMNO,CARRIER,BSSOURCE,LANE,FORWARDER,NETWEIGHT,KGS,CNTRTOTAL,CORPID) as vs where AMOUNT=0 AND FEECOUNT>1 ");