varBLCOUNT=T_ALL_DA.GetStrSQL("BLCOUNT","select COUNT(*) BLCOUNT from ch_fee where FEETYPE=1 and (AMOUNT<>SETTLEMENT AND AMOUNT<>ORDERAMOUNT) and BSNO='"+bodyList[0].BSNO+"'");
varBLCOUNT2=T_ALL_DA.GetStrSQL("BLCOUNT","select COUNT(*) BLCOUNT from ch_fee where FEETYPE=1 and (AMOUNT<>SETTLEMENT and (AMOUNT<>ORDERINVOICE OR AMOUNT<>ORDERAMOUNT) ) and CUSTOMERNAME='" +bodyList[0].CustomerName+"'");
varBLCOUNT2=T_ALL_DA.GetStrSQL("BLCOUNT","select COUNT(*) BLCOUNT from ch_fee where FEETYPE=1 and (AMOUNT<>SETTLEMENT and (AMOUNT<>ORDERINVOICE AND AMOUNT<>ORDERAMOUNT) ) and CUSTOMERNAME='" +bodyList[0].CustomerName+"'");
varBLCOUNT2=T_ALL_DA.GetStrSQL("BLCOUNT","select COUNT(*) BLCOUNT from ch_fee where FEETYPE=1 and (AMOUNT<>SETTLEMENT and (AMOUNT<>ORDERINVOICE OR AMOUNT<>ORDERAMOUNT) ) and CUSTOMERNAME='" +billcust+"'");
varBLCOUNT2=T_ALL_DA.GetStrSQL("BLCOUNT","select COUNT(*) BLCOUNT from ch_fee where FEETYPE=1 and (AMOUNT<>SETTLEMENT and (AMOUNT<>ORDERINVOICE AND AMOUNT<>ORDERAMOUNT) ) and CUSTOMERNAME='" +billcust+"'");
varBLCOUNT2=T_ALL_DA.GetStrSQL("BLCOUNT","select COUNT(*) BLCOUNT from ch_fee where FEETYPE=1 and (AMOUNT<>SETTLEMENT and (AMOUNT<>ORDERINVOICE OR AMOUNT<>ORDERAMOUNT) ) and CUSTOMERNAME='" +billcust+"'");
varBLCOUNT2=T_ALL_DA.GetStrSQL("BLCOUNT","select COUNT(*) BLCOUNT from ch_fee where FEETYPE=1 and (AMOUNT<>SETTLEMENT and (AMOUNT<>ORDERINVOICE AND AMOUNT<>ORDERAMOUNT) ) and CUSTOMERNAME='" +billcust+"'");
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMNO,(CASE b.BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF");
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.ETA,b.PORTLOAD,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,CASE WHEN isnull(f.BSGOODSNAME,'')='' THEN b.GOODSNAME ELSE f.BSGOODSNAME END GOODSNAME");
strSql.Append(",b.DOC,b.SALE,(select top 1 INVNO from ch_fee_invoicehexiao where BILLNO IN (SELECT BILLNO FROM ch_fee_do_invoice WHERE FEEID=c.FEEID)) INVOICENO ");
strSql.Append(",(select TOP 1 BLSTATUS from op_blissuelist WHERE GID IN (SELECT LINKGID FROM op_blissuelist_Detail WHERE BSNO=B.PARENTID)) TFBLSTATUS");
strSql.Append(",(select TOP 1 SPREMARK from v_op_blissuelist_Detail WHERE BSNO=B.PARENTID) TFREMARK");
+" SELECT NEWID(),NEWID() as [任务编号],null as [上级任务号], '成本审批驳回' as [任务类型], '账单审核' as [任务来源], '未开始' as [任务状态], '驳回原因:"+headdata.COSTAUDITRESULT+"' as [任务说明],"
+"'"+username+"' as [发起人],GETDATE() as [录入日期],GETDATE() as[任务开始时间], '手动' as [完成方式],null as [完成时间] ,null as [KPI值] , '"+headdata.BSNO+"' as [提单号], "
+" null as [文件编号], '' as [邮件编号], '' as [电子档案路径], 0 as 是否公共,'"+ op.BSNO+"' as 客服员,'"+headdata.BSNO+"' as 编号,0");
+" null as [文件编号], '' as [邮件编号], '' as [电子档案路径], 0 as 是否公共,'"+GetUserNameWithUserId(op.BSNO)+"' as 客服员,'"+headdata.BSNO+"' as 编号,0");
varPREHEAD=MsOpCtnBsCardDAL.GetData(" BSNO IN (SELECT TOP 1 BSNO FROM op_ctnbscard WHERE CTNNO='"+headData.CTNNO+"' AND GID<>'"+headData.GID+"' AND (PORTLOAD_CNT_TIME<'"+headData.PORTLOAD_CNT_TIME+"' or ETD<'"+headData.ETD+"') ORDER BY ETD,PORTLOAD_CNT_TIME ) ",userid);
stringblUpSQL=" update ch_fee set WMSOUTBSNO='"+custno+"' where GID='"+bill.GId+"'";
boolbl=T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
stringblUpSQL2=" update ch_fee set BSGOODSNAME=ISNULL((SELECT TOP 1 GOODSNAME FROM op_ctnbscard WHERE GID=ch_fee.BSNO),'') from ch_fee where WMSOUTBSNO='"+bill.GId+"'";
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");
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 else accdays end from Info_Client_ACCDATE WITH (NOLOCK) where LINKGID = (select top 1 GID from info_client WITH (NOLOCK) where shortname =F.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=B.SALE)) and BGNDATE<=B.OPDATE AND ENDDATE>=B.OPDATE),0) CONTRACTDAY ");
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 else accdays end from Info_Client_ACCDATE WITH (NOLOCK) where LINKGID = (select top 1 GID from info_client WITH (NOLOCK) 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 else accdays end from Info_Client_ACCDATE WITH (NOLOCK) where LINKGID = (select top 1 GID from info_client WITH (NOLOCK) where shortname =A.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 else accdays end from Info_Client_ACCDATE WITH (NOLOCK) where LINKGID = (select top 1 GID from info_client WITH (NOLOCK) where shortname =A.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=B.SALE)) and BGNDATE<=B.OPDATE AND ENDDATE>=B.OPDATE),0) CONTRACTDAY ");
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");
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 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 ");
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 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 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 ");
}
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 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 ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append("INNER JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" INNER JOIN info_client C WITH (NOLOCK) ON (C.SHORTNAME=F.CUSTOMERNAME) ");
//strSql.Append(" LEFT JOIN V_MAX_SETTLEMENTTIME S ON (S.CUSTOMERNAME=F.CUSTOMERNAME AND S.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN V_MAX_SETTLEMENTTIME S ON (S.CUSTOMERNAME=F.CUSTOMERNAME AND S.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN ( select d.CUSTOMERNAME,d.BSNO,SUM(CASE WHEN d.CURRENCY='RMB' THEN d.AMOUNT ELSE 0 END) INVRMB , SUM(CASE WHEN d.CURRENCY = 'USD' THEN d.AMOUNT ELSE 0 END) INVUSD");
strSql.Append(",MAX(d.EXCHANGERATE) INVEXCHANGERATE FROM ch_fee_do d WHERE d.CATEGORY = 7 GROUP BY d.BSNO,d.CUSTOMERNAME) INV ON(INV.BSNO= B.BSNO and INV.CUSTOMERNAME=F.CUSTOMERNAME) ");
// 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");
// strSql.Append(",CASE WHEN A.CUSTOMERNAME=F.CUSTOMERNAME THEN A.STLNAME ELSE isnull((select top 1 ACCTYPE from Info_Client_ACCDATE WITH (NOLOCK) where LINKGID = (select top 1 GID from info_client WITH (NOLOCK) where shortname =F.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=A.SALE)) and BGNDATE<=A.OPDATE AND ENDDATE>=A.OPDATE),'现结买单') END 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");
// 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 ");
// strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
// strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME,C.CRMREMARK6 ");
// 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 WHEN CURRENCY<>'USD' AND CURRENCY<>'RMB' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVOT,");
// 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 else accdays end from Info_Client_ACCDATE WITH (NOLOCK) where LINKGID = (select top 1 GID from info_client WITH (NOLOCK) 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 else accdays end from Info_Client_ACCDATE WITH (NOLOCK) where LINKGID = (select top 1 GID from info_client WITH (NOLOCK) 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(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
// strSql.Append(" INNER JOIN V_OP_BS A ON (A.BSNO=B.PARENTID) ");
// strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
// strSql.Append(" INNER JOIN info_client C WITH (NOLOCK) ON (C.SHORTNAME=F.CUSTOMERNAME) ");
// strSql.Append(" LEFT JOIN V_MAX_SETTLEMENTTIME S ON (S.CUSTOMERNAME=F.CUSTOMERNAME AND S.BSNO=B.BSNO) ");
// strSql.Append(" LEFT JOIN ( select d.CUSTOMERNAME,d.BSNO,SUM(CASE WHEN d.CURRENCY='RMB' THEN d.AMOUNT ELSE 0 END) INVRMB , SUM(CASE WHEN d.CURRENCY = 'USD' THEN d.AMOUNT ELSE 0 END) INVUSD");
// strSql.Append(",MAX(d.EXCHANGERATE) INVEXCHANGERATE FROM ch_fee_do d WHERE d.CATEGORY = 7 GROUP BY d.BSNO,d.CUSTOMERNAME) INV ON(INV.BSNO= B.BSNO and INV.CUSTOMERNAME=F.CUSTOMERNAME) ");
// if (!string.IsNullOrEmpty(condition))
// {
// strSql.Append(" Where " + condition);
// }
// strSql.Append(" GROUP BY A.BSNO,A.OPLBNAME, A.BSTYPE,A.CUSTOMERNAME, A.CUSTNO, A.MBLNO,A.HBLNO,A.VESSEL, A.VOYNO, A.INPUTBY, A.CREATETIME, A.BSSTATUS, A.SALE, A.OP, A.DOC,A.YARD,A.BLISSUESTATUS,A.BLTYPE,");
// 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");
// 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");
// 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");
// 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 ");
// strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
// strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME,C.CRMREMARK6 ");
// 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 WHEN CURRENCY<>'USD' AND CURRENCY<>'RMB' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVOT,");
// 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 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 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(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
// strSql.Append("INNER JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
// strSql.Append(" INNER JOIN info_client C WITH (NOLOCK) ON (C.SHORTNAME=F.CUSTOMERNAME) ");
// strSql.Append(" LEFT JOIN V_MAX_SETTLEMENTTIME S ON (S.CUSTOMERNAME=F.CUSTOMERNAME AND S.BSNO=B.BSNO) ");
// strSql.Append(" LEFT JOIN ( select d.CUSTOMERNAME,d.BSNO,SUM(CASE WHEN d.CURRENCY='RMB' THEN d.AMOUNT ELSE 0 END) INVRMB , SUM(CASE WHEN d.CURRENCY = 'USD' THEN d.AMOUNT ELSE 0 END) INVUSD");
// strSql.Append(",MAX(d.EXCHANGERATE) INVEXCHANGERATE FROM ch_fee_do d WHERE d.CATEGORY = 7 GROUP BY d.BSNO,d.CUSTOMERNAME) INV ON(INV.BSNO= B.BSNO and INV.CUSTOMERNAME=F.CUSTOMERNAME) ");
// if (!string.IsNullOrEmpty(condition))
// {
// strSql.Append(" Where " + condition);
// }
// strSql.Append(" GROUP BY B.BSNO,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.BLISSUESTATUS,B.BLTYPE,");