strSql.Append(",(CASE B.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",isnull(SUM(CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS TTLRMB,");
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 'RMB' THEN ISNULL(AMOUNT-ISNULL(INVOICE,0),0) ELSE 0 END),0) AS BALINVRMB,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS STLRMB,");
// strSql.Append("isnull(SUM(CASE WHEN CURRENCY='RMB' AND ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE 0 END,0) ELSE 0 END),0) AS INVNOSTLRMB,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='RMB' AND ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0) ELSE 0 END),0) AS INVNOSTLRMB,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='RMB' AND ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0) ELSE 0 END),0) AS STLNOINVRMB,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS TTLUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-ISNULL(INVOICE,0),0) ELSE 0 END),0) AS BALINVUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS STLUSD,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='USD' AND ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0) ELSE 0 END),0) AS INVNOSTLUSD,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='USD' AND ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0) ELSE 0 END),0) AS STLNOINVUSD,");
strSql.Append("isnull(SUM(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0)),0) AS TTL,");
strSql.Append("isnull(SUM(ISNULL(INVOICE,0) * ISNULL(EXCHANGERATE,0)),0) AS TTLINV,");
strSql.Append("isnull(SUM(ISNULL(AMOUNT-ISNULL(INVOICE,0),0) * ISNULL(EXCHANGERATE,0)),0) AS BALINVTTL,");
strSql.Append("isnull(SUM(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0)),0) AS STLTTL,");
strSql.Append("isnull(SUM(CASE WHEN ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0)* ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS INVNOSTL,");
strSql.Append("isnull(SUM(CASE WHEN ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0)* ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS STLNOINV");
strSql.Append(" FROM CH_FEE F ");
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) where 1=1 ");
strSql.Append(" and ISNULL(F.INVOICE,0)<>0 AND ((F.AMOUNT>0 and ISNULL(F.INVOICE,0)>ISNULL(F.SETTLEMENT,0)) or (F.AMOUNT<0 and ISNULL(F.INVOICE,0)<ISNULL(F.SETTLEMENT,0))) ");
strSql.Append(" and ISNULL(F.SETTLEMENT,0)<>0 and ISNULL(F.ISINVOICE,0)=0 AND ((F.AMOUNT>0 and ISNULL(F.SETTLEMENT,0)>ISNULL(F.INVOICE,0)) or (F.AMOUNT<0 and ISNULL(F.SETTLEMENT,0)<ISNULL(F.INVOICE,0))) ");
strSql.Append(",CASE F.FEETYPE WHEN 1 THEN '收' WHEN 2 THEN '付' ELSE '' END AS FEETYPEREF");
strSql.Append(",isnull(SUM(CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS TTLRMB,");
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 'RMB' THEN ISNULL(AMOUNT-ISNULL(INVOICE,0),0) ELSE 0 END),0) AS BALINVRMB,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS STLRMB,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='RMB' AND ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0) ELSE 0 END),0) AS INVNOSTLRMB,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='RMB' AND ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0) ELSE 0 END),0) AS STLNOINVRMB,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS TTLUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-ISNULL(INVOICE,0),0) ELSE 0 END),0) AS BALINVUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS STLUSD,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='USD' AND ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0) ELSE 0 END),0) AS INVNOSTLUSD,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='USD' AND ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0) ELSE 0 END),0) AS STLNOINVUSD,");
strSql.Append("isnull(SUM(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0)),0) AS TTL,");
strSql.Append("isnull(SUM(ISNULL(INVOICE,0) * ISNULL(EXCHANGERATE,0)),0) AS TTLINV,");
strSql.Append("isnull(SUM(ISNULL(AMOUNT-ISNULL(INVOICE,0),0) * ISNULL(EXCHANGERATE,0)),0) AS BALINVTTL,");
strSql.Append("isnull(SUM(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0)),0) AS STLTTL,");
strSql.Append("isnull(SUM(CASE WHEN ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0)* ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS INVNOSTL,");
strSql.Append("isnull(SUM(CASE WHEN ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0)* ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS STLNOINV");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) where 1=1 ");
strSql.Append(" and ISNULL(F.INVOICE,0)<>0 AND ((F.AMOUNT>0 and ISNULL(F.INVOICE,0)>ISNULL(F.SETTLEMENT,0)) or (F.AMOUNT<0 and ISNULL(F.INVOICE,0)<ISNULL(F.SETTLEMENT,0))) ");
strSql.Append(" and ISNULL(F.SETTLEMENT,0)<>0 and ISNULL(F.ISINVOICE,0)=0 AND ((F.AMOUNT>0 and ISNULL(F.SETTLEMENT,0)>ISNULL(F.INVOICE,0)) or (F.AMOUNT<0 and ISNULL(F.SETTLEMENT,0)<ISNULL(F.INVOICE,0))) ");
strSql.Append(",CASE F.FEETYPE WHEN 1 THEN '收' WHEN 2 THEN '付' ELSE '' END AS FEETYPEREF");
strSql.Append(",isnull(SUM(CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS TTLRMB,");
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 'RMB' THEN ISNULL(AMOUNT-ISNULL(INVOICE,0),0) ELSE 0 END),0) AS BALINVRMB,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS STLRMB,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='RMB' AND ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0) ELSE 0 END),0) AS INVNOSTLRMB,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='RMB' AND ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0) ELSE 0 END),0) AS STLNOINVRMB,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS TTLUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-ISNULL(INVOICE,0),0) ELSE 0 END),0) AS BALINVUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS STLUSD,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='USD' AND ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0) ELSE 0 END),0) AS INVNOSTLUSD,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='USD' AND ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0) ELSE 0 END),0) AS STLNOINVUSD,");
strSql.Append("isnull(SUM(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0)),0) AS TTL,");
strSql.Append("isnull(SUM(ISNULL(INVOICE,0) * ISNULL(EXCHANGERATE,0)),0) AS TTLINV,");
strSql.Append("isnull(SUM(ISNULL(AMOUNT-ISNULL(INVOICE,0),0) * ISNULL(EXCHANGERATE,0)),0) AS BALINVTTL,");
strSql.Append("isnull(SUM(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0)),0) AS STLTTL,");
strSql.Append("isnull(SUM(CASE WHEN ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0)* ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS INVNOSTL,");
strSql.Append("isnull(SUM(CASE WHEN ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0)* ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS STLNOINV");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) where 1=1 ");
strSql.Append(" and ISNULL(F.INVOICE,0)<>0 AND ((F.AMOUNT>0 and ISNULL(F.INVOICE,0)>ISNULL(F.SETTLEMENT,0)) or (F.AMOUNT<0 and ISNULL(F.INVOICE,0)<ISNULL(F.SETTLEMENT,0))) ");
strSql.Append(" and ISNULL(F.SETTLEMENT,0)<>0 and ISNULL(F.ISINVOICE,0)=0 AND ((F.AMOUNT>0 and ISNULL(F.SETTLEMENT,0)>ISNULL(F.INVOICE,0)) or (F.AMOUNT<0 and ISNULL(F.SETTLEMENT,0)<ISNULL(F.INVOICE,0))) ");
strSql.Append(",CASE F.FEETYPE WHEN 1 THEN '收' WHEN 2 THEN '付' ELSE '' END AS FEETYPEREF");
strSql.Append(",isnull(SUM(CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS TTLRMB,");
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 'RMB' THEN ISNULL(AMOUNT-ISNULL(INVOICE,0),0) ELSE 0 END),0) AS BALINVRMB,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS STLRMB,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='RMB' AND ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0) ELSE 0 END),0) AS INVNOSTLRMB,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='RMB' AND ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0) ELSE 0 END),0) AS STLNOINVRMB,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS TTLUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-ISNULL(INVOICE,0),0) ELSE 0 END),0) AS BALINVUSD,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS STLUSD,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='USD' AND ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0) ELSE 0 END),0) AS INVNOSTLUSD,");
strSql.Append("isnull(SUM(CASE WHEN CURRENCY='USD' AND ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0) ELSE 0 END),0) AS STLNOINVUSD,");
strSql.Append("isnull(SUM(ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0)),0) AS TTL,");
strSql.Append("isnull(SUM(ISNULL(INVOICE,0) * ISNULL(EXCHANGERATE,0)),0) AS TTLINV,");
strSql.Append("isnull(SUM(ISNULL(AMOUNT-ISNULL(INVOICE,0),0) * ISNULL(EXCHANGERATE,0)),0) AS BALINVTTL,");
strSql.Append("isnull(SUM(ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0)),0) AS STLTTL,");
strSql.Append("isnull(SUM(CASE WHEN ISNULL(INVOICE,0)<>0 THEN ISNULL(CASE WHEN INVOICE>ISNULL(SETTLEMENT,0) THEN INVOICE-ISNULL(SETTLEMENT,0) ELSE INVOICE-ISNULL(SETTLEMENT,0) END,0)* ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS INVNOSTL,");
strSql.Append("isnull(SUM(CASE WHEN ISNULL(SETTLEMENT,0)<>0 THEN ISNULL(CASE WHEN SETTLEMENT>ISNULL(INVOICE,0) THEN SETTLEMENT-ISNULL(INVOICE,0) ELSE 0 END,0)* ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS STLNOINV");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) where 1=1 ");
strSql.Append(" and ISNULL(F.INVOICE,0)<>0 AND ((F.AMOUNT>0 and ISNULL(F.INVOICE,0)>ISNULL(F.SETTLEMENT,0)) or (F.AMOUNT<0 and ISNULL(F.INVOICE,0)<ISNULL(F.SETTLEMENT,0))) ");
strSql.Append(" and ISNULL(F.SETTLEMENT,0)<>0 and ISNULL(F.ISINVOICE,0)=0 AND ((F.AMOUNT>0 and ISNULL(F.SETTLEMENT,0)>ISNULL(F.INVOICE,0)) or (F.AMOUNT<0 and ISNULL(F.SETTLEMENT,0)<ISNULL(F.INVOICE,0))) ");
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"])+"' ";