//strSql.Append(" and (RANGETYPE='集团' or SHORTNAME in (SELECT SHORTNAME from info_client_range where USERID='" + userid + "' ) or SHORTNAME not in (SELECT SHORTNAME from info_client_range ) ) ");
strSql.Append(" and ((RANGETYPE='个人' and exists (select 1 from info_client_range where info_client_range.SHORTNAME=info_Client.SHORTNAME and USERID='"+userid+"')) or RANGETYPE='集团' ) ");
if(!string.IsNullOrWhiteSpace(modcondition))modcondition+=" and ";
//modcondition += " (SHORTNAME in (SELECT SHORTNAME from info_client_range where USERID='" + USERINFO.USERID + "' ) or SHORTNAME not in (SELECT SHORTNAME from info_client_range )) ";
strSql.Append("select dl.*,b.ETD,B.CUSTOMERNAME,B.OP,B.CARRIER,B.TEU,B.SALE,B.CUSTNO from ");
strSql.Append("select dl.*,b.ETD,B.CUSTOMERNAME,B.OP,B.CARRIER,B.TEU,B.SALE,B.CUSTNO,b.DOC,b.SALEDEPT,(select name from company where gid= b.SALECORPID)SALECORP from ");
// strSql.Append("(select GID,BSNO,(select top 1 BSNO from v_op_bill where (MBLNO=D.b_mblno or HBLNO=D.MBLNO) and OPLBNAME in('海运进口','海运出口','空运进口','空运出口')) B_BSNO,MBLNO,B_MBLNO,RMBAMOUNT,USDAMOUNT,L_RMBAMOUNT,L_USDAMOUNT,ISOK,REMARK,REMARK2 ");
// strSql.Append("(select GID,BSNO,(select top 1 BSNO from v_op_bill where (MBLNO=D.b_mblno or HBLNO=D.MBLNO) and OPLBNAME in('海运进口','海运出口','空运进口','空运出口')) B_BSNO,MBLNO,B_MBLNO,RMBAMOUNT,USDAMOUNT,L_RMBAMOUNT,L_USDAMOUNT,ISOK,REMARK,REMARK2 ");
strSql.Append(" isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0)- ");
strSql.Append(" isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS L_USDAMOUNT ");
}
strSql.Append(" ,b.DOC,b.SALEDEPT,(select name from company where gid= b.SALECORPID)SALECORP ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" where F.AMOUNT<>F.SETTLEMENT and F.CUSTOMERNAME='"+CUSTOMERNAME+"' and EXISTS (select 1 from CH_FEE_AutoDuiDetail fd where (fd.MBLNO=B.MBLNO OR fd.MBLNO=B.HBLNO) and fd.BSNO='"+AutoDui_GID+"') ");
strSql.Append(" isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0)- ");
strSql.Append(" isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS L_USDAMOUNT ");
}
strSql.Append(" ,b.DOC,b.SALEDEPT,(select name from company where gid= b.SALECORPID)SALECORP ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" where F.AMOUNT<>F.SETTLEMENT and F.CUSTOMERNAME='"+CUSTOMERNAME+"' and EXISTS (select 1 from CH_FEE_AutoDuiDetail fd where (fd.MBLNO=B.MBLNO OR fd.MBLNO=B.HBLNO) and fd.BSNO='"+AutoDui_GID+"') ");