strSql.Append(" from ch_fee f left join v_op_bill b on (b.BSNO=f.BSNO) ");
strSql.Append(" where f.FEESTATUS=0 and f.SETTLEMENT=0 and f.ORDERAMOUNT=0 and f.ORDERINVOICE=0 AND ISNULL(F.INVOICE,0)=0 AND F.AMOUNT<>0) as v");
strSql.Append(" group by PARENTID,CUSTNAME,FEETYPE,CURRENCY,OPLB,OPLBNAME,BSTYPE,CUSTOMERNAME,MBLNO,HBLNO,VESSEL,VOYNO,BSSTATUS,SALE,OP,DOC,");
strSql.Append(" ETD,CUSTSERVICE,PORTLOAD,PORTDISCHARGE,CUSTOMNO,CARRIER,BSSOURCE,LANE,FORWARDER,NETWEIGHT,KGS,CNTRTOTAL,CORPID) as vs where AMOUNT=0 AND FEECOUNT>1 ");
//strSql.Append(" from ch_fee f left join v_op_bill b on (b.BSNO=f.BSNO) ");
//strSql.Append(" where f.FEESTATUS=0 and f.SETTLEMENT=0 and f.ORDERAMOUNT=0 and f.ORDERINVOICE=0 AND ISNULL(F.INVOICE,0)=0 AND F.AMOUNT<>0) as v");
//strSql.Append(" group by PARENTID,CUSTNAME,FEETYPE,CURRENCY,OPLB,OPLBNAME,BSTYPE,CUSTOMERNAME,MBLNO,HBLNO,VESSEL,VOYNO,BSSTATUS,SALE,OP,DOC,");
//strSql.Append(" ETD,CUSTSERVICE,PORTLOAD,PORTDISCHARGE,CUSTOMNO,CARRIER,BSSOURCE,LANE,FORWARDER,NETWEIGHT,KGS,CNTRTOTAL,CORPID) as vs where AMOUNT=0 AND FEECOUNT>1 ");
strSql.Append(",(select ShowName from [user] where GID=cm.OPERATOR) as OPERATORNAME");
strSql.Append(",(select ShowName from [user] where GID=cm.DELETEOPERATOR) as DELOPERATORNAME");
strSql.Append(",dbo.GetFeeNoStlByInvNo(cm.BILLNO) as NOSTL,FEEAMOUNT ");
strSql.Append(",VOUNO=(select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=cm.GID and BSTABLENAME='ch_fee_invoice' and STARTGID='"+strCwSTARTGID+"')");
// strSql.Append(",VOUNO=(select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=cm.GID and BSTABLENAME='ch_fee_invoice' and STARTGID='" + strCwSTARTGID + "')");
strSql.Append(",VOUNO=(select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=cm.GID and BSTABLENAME='ch_fee_invoice')");
strSql.Append(" FROM ch_fee_invoice cm where 1=1 ");
strSql.Append(",(select ShowName from [user] where GID=cm.OPERATOR) as OPERATORNAME");
strSql.Append(",(select ShowName from [user] where GID=cm.DELETEOPERATOR) as DELOPERATORNAME");
strSql.Append(",dbo.GetFeeNoStlByInvNo(cm.BILLNO) as NOSTL,FEEAMOUNT ");
strSql.Append(",VOUNO=(select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=cm.GID and BSTABLENAME='ch_fee_invoice' and STARTGID='"+strCwSTARTGID+"')");
// strSql.Append(",VOUNO=(select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=cm.GID and BSTABLENAME='ch_fee_invoice' and STARTGID='" + strCwSTARTGID + "')");
strSql.Append(",VOUNO=(select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=cm.GID and BSTABLENAME='ch_fee_invoice')");
strSql.Append(" FROM ch_fee_invoice cm where 1=1 ");
sql=sql+getAndConSql(sql,FeiYongZhuangTai," C.FEETYPE=2 AND ISNULL(C.SETTLEMENT,0)<>0 and ISNULL(C.ISINVOICE,0)=0 AND ((C.AMOUNT>0 and ISNULL(C.SETTLEMENT,0)>ISNULL(C.INVOICE,0)) or (C.AMOUNT<0 and ISNULL(C.SETTLEMENT,0)<ISNULL(C.INVOICE,0))) ");
}elseif(FeiYongZhuangTai=="19"){
sql=sql+getAndConSql(sql,FeiYongZhuangTai," C.FEETYPE=2 AND ISNULL(C.INVOICE,0)<>0 AND ((C.AMOUNT>0 and ISNULL(C.INVOICE,0)>ISNULL(C.SETTLEMENT,0)) or (C.AMOUNT<0 and ISNULL(C.INVOICE,0)<ISNULL(C.SETTLEMENT,0))) ");
}elseif(FeiYongZhuangTai=="20"){
sql=sql+getAndConSql(sql,FeiYongZhuangTai," ISNULL(C.SETTLEMENT,0)<>C.AMOUNT AND ISNULL(C.INVOICE,0)<>C.AMOUNT AND F.FEESTATUS IN (0,8) ");
sql=sql+getAndConSql(sql,FeiYongZhuangTai," C.FEETYPE=2 AND ISNULL(C.SETTLEMENT,0)<>0 and ISNULL(C.ISINVOICE,0)=0 AND ((C.AMOUNT>0 and ISNULL(C.SETTLEMENT,0)>ISNULL(C.INVOICE,0)) or (C.AMOUNT<0 and ISNULL(C.SETTLEMENT,0)<ISNULL(C.INVOICE,0))) ");
}elseif(FeiYongZhuangTai=="19"){
sql=sql+getAndConSql(sql,FeiYongZhuangTai," C.FEETYPE=2 AND ISNULL(C.INVOICE,0)<>0 AND ((C.AMOUNT>0 and ISNULL(C.INVOICE,0)>ISNULL(C.SETTLEMENT,0)) or (C.AMOUNT<0 and ISNULL(C.INVOICE,0)<ISNULL(C.SETTLEMENT,0))) ");
}elseif(FeiYongZhuangTai=="20"){
sql=sql+getAndConSql(sql,FeiYongZhuangTai," ISNULL(C.SETTLEMENT,0)<>C.AMOUNT AND ISNULL(C.INVOICE,0)<>C.AMOUNT AND F.FEESTATUS IN (0,8) ");
sql=sql+getAndConSql(sql,FeiYongZhuangTai," C.FEETYPE=2 AND ISNULL(C.SETTLEMENT,0)<>0 and ISNULL(C.ISINVOICE,0)=0 AND ((C.AMOUNT>0 and ISNULL(C.SETTLEMENT,0)>ISNULL(C.INVOICE,0)) or (C.AMOUNT<0 and ISNULL(C.SETTLEMENT,0)<ISNULL(C.INVOICE,0))) ");
}elseif(FeiYongZhuangTai=="19"){
sql=sql+getAndConSql(sql,FeiYongZhuangTai," C.FEETYPE=2 AND ISNULL(C.INVOICE,0)<>0 AND ((C.AMOUNT>0 and ISNULL(C.INVOICE,0)>ISNULL(C.SETTLEMENT,0)) or (C.AMOUNT<0 and ISNULL(C.INVOICE,0)<ISNULL(C.SETTLEMENT,0))) ");
}elseif(FeiYongZhuangTai=="20"){
sql=sql+getAndConSql(sql,FeiYongZhuangTai," ISNULL(C.SETTLEMENT,0)<>C.AMOUNT AND ISNULL(C.INVOICE,0)<>C.AMOUNT AND F.FEESTATUS IN (0,8) ");
//sql = sql + getAndConSql(sql, ISVOUNO, "(VOUNO='' or VOUNO is null)");
sql=sql+getAndConSql(sql,ISVOUNO,"gid not in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoice' and [STARTGID]='" +this.strCwSTARTGID+"')");
// sql = sql + getAndConSql(sql, ISVOUNO, "gid not in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoice' and [STARTGID]='" + this.strCwSTARTGID + "')");
sql=sql+getAndConSql(sql,ISVOUNO,"gid not in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoice')");
}
elseif(ISVOUNO=="已生成"){
//sql = sql + getAndConSql(sql, ISVOUNO, "(VOUNO<>'' and VOUNO is not null)");
sql=sql+getAndConSql(sql,ISVOUNO,"gid in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoice' and [STARTGID]='" +this.strCwSTARTGID+"')");
// sql = sql + getAndConSql(sql, ISVOUNO, "gid in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoice' and [STARTGID]='" + this.strCwSTARTGID + "')");
sql=sql+getAndConSql(sql,ISVOUNO,"gid in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoice')");
sql=sql+getAndConSql(sql,VOUNO,"gid in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoice' and [STARTGID]='" +this.strCwSTARTGID+"' and VOUALLNO like '%" +VOUNO+"%')");
// sql = sql + getAndConSql(sql, VOUNO, "gid in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoice' and [STARTGID]='" + this.strCwSTARTGID + "' and VOUALLNO like '%" + VOUNO + "%')");
sql=sql+getAndConSql(sql,VOUNO,"gid in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoice' and VOUALLNO like '%" +VOUNO+"%')");
//sql = sql + getAndConSql(sql, ISVOUNO, "(VOUNO='' or VOUNO is null)");
sql=sql+getAndConSql(sql,ISVOUNO,"BILLNO not in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoicehexiao' and [STARTGID]='" +this.strCwSTARTGID+"')");
// sql = sql + getAndConSql(sql, ISVOUNO, "BILLNO not in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoicehexiao' and [STARTGID]='" + this.strCwSTARTGID + "')");
sql=sql+getAndConSql(sql,ISVOUNO,"BILLNO not in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoicehexiao' )");
}
elseif(ISVOUNO=="已生成"){
//sql = sql + getAndConSql(sql, ISVOUNO, "(VOUNO<>'' and VOUNO is not null)");
sql=sql+getAndConSql(sql,ISVOUNO,"BILLNO in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoicehexiao' and [STARTGID]='" +this.strCwSTARTGID+"')");
// sql = sql + getAndConSql(sql, ISVOUNO, "BILLNO in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoicehexiao' and [STARTGID]='" + this.strCwSTARTGID + "')");
sql=sql+getAndConSql(sql,ISVOUNO,"BILLNO in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoicehexiao')");
sql=sql+getAndConSql(sql,VOUNO,"BILLNO in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoicehexiao' and [STARTGID]='" +this.strCwSTARTGID+"' and VOUALLNO like '%" +VOUNO+"%')");
// sql = sql + getAndConSql(sql, VOUNO, "BILLNO in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoicehexiao' and [STARTGID]='" + this.strCwSTARTGID + "' and VOUALLNO like '%" + VOUNO + "%')");
sql=sql+getAndConSql(sql,VOUNO,"BILLNO in (select BSGID from [cw_vouno_bs_gl] where [BSTABLENAME]='ch_fee_invoicehexiao' and VOUALLNO like '%" +VOUNO+"%')");
sql=sql+getAndConSql(sql,CUSTOMERNAME," ob.GID in(select LINKGID from op_blissuelist_Detail where BSNO in(select BSNO from v_op_blissue_bill where CUSTOMERNAME='"+CUSTOMERNAME+"')) ");
sql=sql+' and EXISTS (select 1 from v_op_gain_sum_ttl WHERE v_op_gain_sum_ttl.BSNO=B.PARENTID AND v_op_gain_sum_ttl.STLTTLCR=v_op_gain_sum_ttl.TTLCR) '
}elseif(FEERANGE=='未开票未作收费申请未结算'){
sql=sql+' and (isnull(f.INVOICE,0)=0 and isnull(f.SETTLEMENT,0)=0 and isnull(f.ORDERAMOUNT,0)=0) '
sql=sql+' and (isnull(f.INVOICE,0)=0 and isnull(f.SETTLEMENT,0)<>isnull(f.AMOUNT,0) and isnull(f.ORDERAMOUNT,0)=0) '
}elseif(FEERANGE=='已审核未结算'){
sql=sql+' and F.FEESTATUS IN (0,8,9) AND F.AMOUNT<>F.SETTLEMENT '