strSql.Append(" and ISNULL(F.INVOICE,0)<>F.AMOUNT and ISNULL(F.ISINVOICE,0)=0 ");
}
elseif(feerang=="3")
elseif(feerang=="3"||feerang=="9")
{
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))) ");
}
elseif(feerang=="4")
elseif(feerang=="4"||feerang=="8")
{
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(" and ISNULL(F.INVOICE,0)<>F.AMOUNT and ISNULL(F.ISINVOICE,0)=0 ");
}
elseif(feerang=="3")
elseif(feerang=="3"||feerang=="9")
{
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))) ");
}
elseif(feerang=="4")
elseif(feerang=="4"||feerang=="8")
{
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(" and ISNULL(F.INVOICE,0)<>F.AMOUNT and ISNULL(F.ISINVOICE,0)=0 ");
}
elseif(feerang=="3")
elseif(feerang=="3"||feerang=="9")
{
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))) ");
}
elseif(feerang=="4")
elseif(feerang=="4"||feerang=="8")
{
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(" and ISNULL(F.INVOICE,0)<>F.AMOUNT and ISNULL(F.ISINVOICE,0)=0 ");
}
elseif(feerang=="3")
elseif(feerang=="3"||feerang=="9")
{
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))) ");
}
elseif(feerang=="4")
elseif(feerang=="4"||feerang=="8")
{
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(",DATEDIFF([day],ISNULL(T.SETTLETIME,GETDATE()),(select min(bgndate) from Info_Client_ACCDATE where LINKGID=(select gid from Info_Client where SHORTNAME=b.CUSTOMERNAME))) NODAY");
strSql.Append(",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,CASE WHEN (B.TTLDR-B.STLTTLDR)<0 THEN 0 ELSE (dbo.GetZHZYTTL(B.STLDATE,B.BSNO)+TTLNODR*ZYRATE*DATEDIFF([day],B.STLDATE,GETDATE())) END ZYTTL ");
strSql.Append(",ISNULL((SELECT SUM(RATEDIFF) FROM v_fee_rate WHERE BSNO=B.BSNO),0) RATEDIFF ");
strSql.Append(" FROM v_op_bill_gain_zh B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
strSql.Append(",DATEDIFF([day],ISNULL(T.SETTLETIME,GETDATE()),(select min(bgndate) from Info_Client_ACCDATE where LINKGID=(select gid from Info_Client where SHORTNAME=b.CUSTOMERNAME))) NODAY");
strSql.Append(",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,0 ZYTTL ");
strSql.Append(",ISNULL((SELECT SUM(RATEDIFF) FROM v_fee_rate WHERE BSNO=B.BSNO),0) RATEDIFF ");
strSql.Append(" FROM v_op_bill_gain_zh B ");
strSql.Append(" FROM v_op_bill_gain_zh B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_CR T ON (T.BSNO=B.BSNO) ");
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where B.TTLDR=0 ");