strSql.Append(" ,(CASE B.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=1 THEN (CASE D.ORIGCURRENCY WHEN 'RMB' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=2 THEN (CASE D.ORIGCURRENCY WHEN 'RMB' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=1 THEN (CASE D.ORIGCURRENCY WHEN 'USD' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=2 THEN (CASE D.ORIGCURRENCY WHEN 'USD' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=1 THEN (CASE WHEN D.ORIGCURRENCY not in('RMB','USD') THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS OTDR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=2 THEN (CASE WHEN D.ORIGCURRENCY not in('RMB','USD') THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS OTCR ");
strSql.Append(",(select BANKNAME from [sys_bank] where GID=s.ACCOUNTUSD) as ACCOUNTUSDREF,[dbo].[GetCustStlDay](B.OPDATE,s.CUSTOMERNAME,B.SALE) AS STLDATE ");
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");
strSql.Append(" ,isnull(CASE WHEN F.FEETYPE=1 THEN (CASE F.CURRENCY WHEN 'RMB' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END,0) AS STLRMBDR ");
strSql.Append(" ,isnull(CASE WHEN F.FEETYPE=2 THEN (CASE F.CURRENCY WHEN 'RMB' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END,0) AS STLRMBCR ");
strSql.Append(" ,isnull(CASE WHEN F.FEETYPE=1 THEN (CASE F.CURRENCY WHEN 'USD' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END,0) AS STLUSDDR ");
strSql.Append(" ,isnull(CASE WHEN F.FEETYPE=2 THEN (CASE F.CURRENCY WHEN 'USD' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END,0) AS STLUSDCR ");
strSql.Append(" ,isnull(CASE WHEN F.FEETYPE=1 THEN (CASE WHEN F.CURRENCY not in('RMB','USD') THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END,0) AS STLOTDR ");
strSql.Append(" ,isnull(CASE WHEN F.FEETYPE=2 THEN (CASE WHEN F.CURRENCY not in('RMB','USD') THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END,0) AS STLOTCR ");
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 F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=1 THEN (CASE D.ORIGCURRENCY WHEN 'RMB' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=2 THEN (CASE D.ORIGCURRENCY WHEN 'RMB' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBCR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=1 THEN (CASE D.ORIGCURRENCY WHEN 'USD' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLUSDDR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=2 THEN (CASE D.ORIGCURRENCY WHEN 'USD' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLUSDCR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=1 THEN (CASE WHEN D.ORIGCURRENCY not in('RMB','USD') THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLOTDR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=2 THEN (CASE WHEN D.ORIGCURRENCY not in('RMB','USD') THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLOTCR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=1 THEN ISNULL(D.ORIGAMOUNT,0)*F.EXCHANGERATE ELSE 0 END),0) AS STLTTLDR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=2 THEN ISNULL(D.ORIGAMOUNT,0)*F.EXCHANGERATE ELSE 0 END),0) AS STLTTLCR ");
strSql.Append(" FROM CH_FEE_DO D ");
strSql.Append(" left join CH_FEE F on F.GID=D.FEEID ");
strSql.Append("INNER JOIN V_OP_BILL B ON (B.BSNO=D.BSNO) ");
strSql.Append(" left JOIN ch_fee_settlement s ON (s.BILLNO=D.BILLNO) ");
strSql.Append(" Where D.CATEGORY in(1,2,3,8,9) ");
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");
strSql.Append(",ISNULL((SELECT SUM(ISNULL(AMOUNT,0)) FROM CH_FEE WHERE CURRENCY='USD' AND FEENAME='海运费' and FEETYPE=2 AND BSNO=B.BSNO),0) AS USDHYFCR,");
strSql.Append("ISNULL((SELECT SUM(ISNULL(SETTLEMENT,0)) FROM CH_FEE WHERE CURRENCY='USD' AND FEENAME='海运费' and FEETYPE=2 AND BSNO=B.BSNO),0) AS STLUSDHYFCR,");
strSql.Append("ISNULL((SELECT SUM(ISNULL(AMOUNT-SETTLEMENT,0)) FROM CH_FEE WHERE CURRENCY='USD' AND FEENAME='海运费' and FEETYPE=2 AND BSNO=B.BSNO),0) AS BALUSDHYFCR");
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(" isnull(SUM(CASE WHEN D.FEETYPE=1 THEN (CASE D.ORIGCURRENCY WHEN 'RMB' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=2 THEN (CASE D.ORIGCURRENCY WHEN 'RMB' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBCR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=1 THEN (CASE D.ORIGCURRENCY WHEN 'USD' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLUSDDR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=2 THEN (CASE D.ORIGCURRENCY WHEN 'USD' THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLUSDCR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=1 THEN (CASE WHEN D.ORIGCURRENCY not in('RMB','USD') THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLOTDR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=2 THEN (CASE WHEN D.ORIGCURRENCY not in('RMB','USD') THEN ISNULL(D.ORIGAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS STLOTCR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=1 THEN ISNULL(D.ORIGAMOUNT,0)*F.EXCHANGERATE ELSE 0 END),0) AS STLTTLDR ");
strSql.Append(" ,isnull(SUM(CASE WHEN D.FEETYPE=2 THEN ISNULL(D.ORIGAMOUNT,0)*F.EXCHANGERATE ELSE 0 END),0) AS STLTTLCR ");
strSql.Append(" FROM CH_FEE_DO D ");
strSql.Append(" left join CH_FEE F on F.GID=D.FEEID ");
strSql.Append("INNER JOIN V_OP_BILL B ON (B.BSNO=D.BSNO) ");
strSql.Append(" left JOIN ch_fee_settlement s ON (s.BILLNO=D.BILLNO) ");
strSql.Append(" Where D.CATEGORY in(1,2,3,8,9) ");
str=" (B.OP='"+usercode+"' OR B.SALE='"+usercode+"')";
}
elseif(visiblerange=="2")
{
if(tb=="index")
{
varrangeDa=newRangeDA();
vardeptname=rangeDa.GetDEPTNAME(userid);
varuserstr=newStringBuilder();
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='"+companyid+"') and GID in (select userid from user_baseinfo where DEPTNAME='"+deptname+"')");
str=str+" or b.Corpid='"+Convert.ToString(reader["COMPANYID"])+"'";
};
}
str=str+")";
reader.Close();
}
}
elseif(visiblerange=="6")
{
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");
str=" (b.OP='"+Convert.ToString(reader["SHOWNAME"])+"' OR b.SALE='"+Convert.ToString(reader["SHOWNAME"])+"' OR b.CUSTSERVICE='"+Convert.ToString(reader["SHOWNAME"])+"' OR b.INPUTBY='"+Convert.ToString(reader["SHOWNAME"])+"' ";
}
else
{
str=str+" or b.OP='"+Convert.ToString(reader["SHOWNAME"])+"' OR b.SALE='"+Convert.ToString(reader["SHOWNAME"])+"' OR b.CUSTSERVICE='"+Convert.ToString(reader["SHOWNAME"])+"' OR b.INPUTBY='"+Convert.ToString(reader["SHOWNAME"])+"' ";