strSql.Append(",isnull(SUM(CASE F.CURRENCY WHEN 'RMB' THEN CASE WHEN F.FEETYPE=1 THEN ISNULL(F.AMOUNT,0) ELSE -ISNULL(F.AMOUNT,0) END ELSE 0 END),0) AS TTLRMB");
strSql.Append(",isnull(SUM(CASE D.ORIGCURRENCY WHEN 'RMB' THEN CASE WHEN F.FEETYPE=1 THEN ISNULL(ORIGAMOUNT,0) ELSE -ISNULL(ORIGAMOUNT,0) END ELSE 0 END),0) AS INVRMB");
strSql.Append(",isnull(SUM(CASE F.CURRENCY WHEN 'USD' THEN CASE WHEN F.FEETYPE=1 THEN ISNULL(F.AMOUNT,0) ELSE -ISNULL(F.AMOUNT,0) END ELSE 0 END),0) AS TTLUSD");
strSql.Append(",isnull(SUM(CASE D.ORIGCURRENCY WHEN 'USD' THEN CASE WHEN F.FEETYPE=1 THEN ISNULL(ORIGAMOUNT,0) ELSE -ISNULL(ORIGAMOUNT,0) END ELSE 0 END),0) AS INVUSD");
strSql.Append(" FROM CH_FEE_DO D ");
strSql.Append(" LEFT JOIN ch_fee_invoice i ON (D.BILLNO=I.BILLNO) ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (D.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN ch_fee F ON (D.FEEID=F.GID) ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" GROUP BY B.BSNO,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,");
str=" F.ENTEROPERATOR in (select USERID from user_company where COMPANYID='"+companyid+"') and ENTEROPERATOR in (select userid from user_baseinfo where DEPTNAME='"+deptname+"')";
}
elseif(visiblerange=="1")
{
str=" F.ENTEROPERATOR in (select USERID from user_company where COMPANYID='"+companyid+"') ";
}
elseif(visiblerange=="5")
{
varuserstr=newStringBuilder();
userstr.Append(" select COMPANYID from user_authority_range_company where userid='"+userid+"' and AUTHORITYID='"+AUTHORITYID+"' and VISIBLERANGE=1");
str=" (F.ENTEROPERATOR in (select USERID from user_company where COMPANYID='"+companyid+"') ";
}
else
{
str=str+" or F.ENTEROPERATOR in (select USERID from user_company where COMPANYID='"+companyid+"')";
};
}
if(str!="")
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");
strSql.Append(",(CASE B.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",i.INVOICENO,i.INVOICEMAKETIME ");
strSql.Append(",isnull(SUM(CASE F.CURRENCY WHEN 'RMB' THEN CASE WHEN F.FEETYPE=1 THEN ISNULL(F.AMOUNT,0) ELSE -ISNULL(F.AMOUNT,0) END ELSE 0 END),0) AS TTLRMB");
strSql.Append(",isnull(SUM(CASE D.ORIGCURRENCY WHEN 'RMB' THEN CASE WHEN F.FEETYPE=1 THEN ISNULL(ORIGAMOUNT,0) ELSE -ISNULL(ORIGAMOUNT,0) END ELSE 0 END),0) AS INVRMB");
strSql.Append(",isnull(SUM(CASE F.CURRENCY WHEN 'USD' THEN CASE WHEN F.FEETYPE=1 THEN ISNULL(F.AMOUNT,0) ELSE -ISNULL(F.AMOUNT,0) END ELSE 0 END),0) AS TTLUSD");
strSql.Append(",isnull(SUM(CASE D.ORIGCURRENCY WHEN 'USD' THEN CASE WHEN F.FEETYPE=1 THEN ISNULL(ORIGAMOUNT,0) ELSE -ISNULL(ORIGAMOUNT,0) END ELSE 0 END),0) AS INVUSD");
strSql.Append(" FROM ch_fee F ");
strSql.Append(" LEFT JOIN ch_fee_do D ON (D.FEEID=F.GID AND D.CATEGORY=7) ");
strSql.Append(" LEFT JOIN ch_fee_invoice i ON (D.BILLNO=I.BILLNO) ");
strSql.Append(" left JOIN V_OP_BILL B ON (f.BSNO=B.BSNO) ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" GROUP BY B.BSNO,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,");
strSql.Append(",(CASE B.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",i.INVNO,i.INVDATE ");
strSql.Append(",isnull(SUM(CASE F.CURRENCY WHEN 'RMB' THEN CASE WHEN F.FEETYPE=2 THEN ISNULL(F.AMOUNT,0) ELSE -ISNULL(F.AMOUNT,0) END ELSE 0 END),0) AS TTLRMB");
strSql.Append(",isnull(SUM(CASE D.ORIGCURRENCY WHEN 'RMB' THEN CASE WHEN F.FEETYPE=2 THEN ISNULL(ORIGAMOUNT,0) ELSE -ISNULL(ORIGAMOUNT,0) END ELSE 0 END),0) AS INVRMB");
strSql.Append(",isnull(SUM(CASE F.CURRENCY WHEN 'USD' THEN CASE WHEN F.FEETYPE=2 THEN ISNULL(F.AMOUNT,0) ELSE -ISNULL(F.AMOUNT,0) END ELSE 0 END),0) AS TTLUSD");
strSql.Append(",isnull(SUM(CASE D.ORIGCURRENCY WHEN 'USD' THEN CASE WHEN F.FEETYPE=2 THEN ISNULL(ORIGAMOUNT,0) ELSE -ISNULL(ORIGAMOUNT,0) END ELSE 0 END),0) AS INVUSD");
strSql.Append(" FROM ch_fee F ");
strSql.Append(" LEFT JOIN ch_fee_do_invoice D ON (D.FEEID=F.GID) ");
strSql.Append(" LEFT JOIN ch_fee_invoicehexiao i ON (D.BILLNO=I.BILLNO) ");
strSql.Append(" left JOIN V_OP_BILL B ON (f.BSNO=B.BSNO) ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" GROUP BY B.BSNO,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,");
strSql.Append(" ,i.FEEITEM,i.AMOUNT,cast(i.INVAMOUNT as decimal(18,2))INVAMOUNT,i.AMOUNTCAPITAL,i.OTCURRAMOUNT,i.CURRENCY,i.REMARK,i.APPLICANT,i.APPLYTIME,i.OPERATOR,i.LICENSECODE,i.TAXCODE,i.INVOICETYPE,i.BILLSTATUS");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=i.INVOICECATEGORY) as INVOICECATEGORYREF");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97009 and EnumValueID=i.INVOICETYPE) as INVOICETYPEREF");
strSql.Append(",(case i.billstatus when 1 then '已锁定' else '未锁定' end) as BILLSTATUSREF");
strSql.Append(",(select ShowName from [user] where GID=i.OPERATOR) as OPERATORNAME");
strSql.Append(",(select ShowName from [user] where GID=i.DELETEOPERATOR) as DELOPERATORNAME");
strSql.Append(",isnull(SUM(CASE D.ORIGCURRENCY WHEN 'RMB' THEN CASE WHEN D.FEETYPE=1 THEN ISNULL(ORIGAMOUNT,0) ELSE -ISNULL(ORIGAMOUNT,0) END ELSE 0 END),0) AS INVRMB");
strSql.Append(",isnull(SUM(CASE D.ORIGCURRENCY WHEN 'USD' THEN CASE WHEN D.FEETYPE=1 THEN ISNULL(ORIGAMOUNT,0) ELSE -ISNULL(ORIGAMOUNT,0) END ELSE 0 END),0) AS INVUSD");
strSql.Append(" FROM ch_fee_invoice i ");
strSql.Append(" left join CH_FEE_DO D on (D.BILLNO=i.BILLNO)");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" GROUP BY i.GID,i.INVOICENO,i.BILLNO,i.CUSTOMERNAME,i.ACTUALCUSTOMERNAME,i.INVOICECUSTNAME,i.INVOICEMAKETIME,i.BANK,i.ACCOUNT,i.BSNO,i.VESSELVOYAGE,i.ETD,i.POL,i.POD");
strSql.Append("SELECT F.CUSTOMERNAME AS CUSTNAME ");
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 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 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 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) ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" Group by F.CUSTOMERNAME,F.FEETYPE ");
strSql.Append(",isnull(SUM(CASE F.CURRENCY WHEN 'RMB' THEN CASE WHEN D.FEETYPE=1 THEN ISNULL(F.AMOUNT,0) ELSE -ISNULL(F.AMOUNT,0) END ELSE 0 END),0) AS TTLRMB");
strSql.Append(",isnull(SUM(CASE D.ORIGCURRENCY WHEN 'RMB' THEN CASE WHEN D.FEETYPE=1 THEN ISNULL(ORIGAMOUNT,0) ELSE -ISNULL(ORIGAMOUNT,0) END ELSE 0 END),0) AS INVRMB");
strSql.Append(",isnull(SUM(CASE F.CURRENCY WHEN 'USD' THEN CASE WHEN D.FEETYPE=1 THEN ISNULL(F.AMOUNT,0) ELSE -ISNULL(F.AMOUNT,0) END ELSE 0 END),0) AS TTLUSD");
strSql.Append(",isnull(SUM(CASE D.ORIGCURRENCY WHEN 'USD' THEN CASE WHEN D.FEETYPE=1 THEN ISNULL(ORIGAMOUNT,0) ELSE -ISNULL(ORIGAMOUNT,0) END ELSE 0 END),0) AS INVUSD");
strSql.Append(",(select sum(cast(INVAMOUNT as decimal(18,2))) from ch_fee_invoice i ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(") AS TTLINV");
strSql.Append(" FROM CH_FEE_DO D ");
strSql.Append(" LEFT JOIN ch_fee_invoice i ON (D.BILLNO=I.BILLNO) ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (D.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN ch_fee F ON (D.FEEID=F.GID) ");
userstr.Append(" select GID 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"])+"' ";