//strSql.Append(",case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
//strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
//strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
//strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
//strSql.Append(",T.SETTLETIME STLDRDATE,CT.SETTLETIME STLCRDATE,CASE WHEN ISNULL(CT.SETTLETIME,'')='' OR ISNULL(T.SETTLETIME,GETDATE())<=ISNULL(CT.SETTLETIME,GETDATE()) THEN 0 ELSE (DATEDIFF([day],ISNULL(CT.SETTLETIME,GETDATE()),ISNULL(T.SETTLETIME,GETDATE()))) END ZYDAY");
//strSql.Append(" FROM V_OP_BILL B ");
//strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
//strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
//strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
//strSql.Append("LEFT JOIN V_MIN_SETTLEMENTTIME_CR CT ON (T.BSNO=B.BSNO) ");
//strSql.Append(" WHERE 1=1 ");
//if (!string.IsNullOrEmpty(condition))
//{
// strSql.Append(" and " + condition);
//}
//strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.RMBDR-G.STLRMBDR) AS RMBNODR,SUM(G.USDDR-G.STLUSDDR) AS USDNODR,SUM(G.OTDR-G.STLOTDR) AS OTNODR,SUM(G.TTLDR-G.STLTTLDR) AS TTLNODR");
strSql.Append(",SUM(G.RMBCR-G.STLRMBCR) AS RMBNOCR,SUM(G.USDCR-G.STLUSDCR) AS USDNOCR,SUM(G.OTCR-G.STLOTCR) AS OTNOCR,SUM(G.TTLCR-G.STLTTLCR) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
strSql.Append(" left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
strSql.Append(" FROM V_OP_BILL B left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.RMBDR-G.STLRMBDR) AS RMBNODR,SUM(G.USDDR-G.STLUSDDR) AS USDNODR,SUM(G.OTDR-G.STLOTDR) AS OTNODR,SUM(G.TTLDR-G.STLTTLDR) AS TTLNODR");
strSql.Append(",SUM(G.RMBCR-G.STLRMBCR) AS RMBNOCR,SUM(G.USDCR-G.STLUSDCR) AS USDNOCR,SUM(G.OTCR-G.STLOTCR) AS OTNOCR,SUM(G.TTLCR-G.STLTTLCR) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
if(PROFITBLCOUNTNOTFEN=="1")nofensql=" AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
varstrSql=newStringBuilder();
if(amendstr=="true")
{
strSql.Append("SELECT B.CUSTOMERNAME"+bstype);
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
strSql.Append(" Group by B.CUSTOMERNAME,C.[DESCRIPTION] "+bstype);
}
else
{
strSql.Append("SELECT B.CUSTOMERNAME"+bstype);
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",ISNULL(SUM(G.RMBDR),0) AS RMBDR,ISNULL(SUM(G.RMBCR),0) AS RMBCR,ISNULL(SUM(G.STLRMBDR),0) AS STLRMBDR,ISNULL(SUM(G.STLRMBCR),0) AS STLRMBCR,ISNULL(SUM(G.USDDR),0) AS USDDR,ISNULL(SUM(G.USDCR),0) AS USDCR,ISNULL(SUM(G.STLUSDDR),0) AS STLUSDDR,ISNULL(SUM(G.STLUSDCR),0) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
strSql.Append(" Group by B.CUSTOMERNAME,C.[DESCRIPTION] "+bstype);
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append("SELECT B.CARRIER"+bstype);
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
if(PROFITBLCOUNTNOTFEN=="1")nofensql=" AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
if(amendstr=="true")
{
strSql.Append(",B.SALE SALEGROUP,SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",B.SALE SALEGROUP,sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append("SELECT * FROM (SELECT U.DEPTNAME SALEDEPT ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(" LEFT JOIN VW_user U ON (U.SHOWNAME=B.SALE) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
strSql.Append(" Group by U.DEPTNAME ");
strSql.Append(") as t ");
}
else
{
strSql.Append("SELECT * FROM (SELECT U.DEPTNAME SALEDEPT ");
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append(" LEFT JOIN VW_user U ON (U.SHOWNAME=B.SALE) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
if(PROFITBLCOUNTNOTFEN=="1")nofensql=" AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
if(amendstr=="true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
if(PROFITBLCOUNTNOTFEN=="1")nofensql=" AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
varstrSql=newStringBuilder();
strSql.Append("SELECT * FROM (SELECT U.DEPTNAME OPDEPT");
if(amendstr=="true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append(" LEFT JOIN VW_user U ON (U.SHOWNAME=B.OP) ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
strSql.Append(" Group by U.DEPTNAME ");
strSql.Append(") as t ");
}
else
{
strSql.Append(",sum(case when B.OPTYPE='更改单' then 0 else 1 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append(" LEFT JOIN VW_user U ON (U.SHOWNAME=B.OP) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
strSql.Append(" Group by B.BSSOURCE,B.BSSOURCEDETAIL ");
strSql.Append("SELECT B.LANE,SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
strSql.Append(" Group by B.LANE ");
}
else
{
strSql.Append("SELECT B.LANE");
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append("SELECT isnull(cd.COUNTRY,'') COUNTRY ");
if(amendstr=="true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
strSql.Append(" Group by isnull(cd.COUNTRY,'') ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' "+nofensql+" then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
if(PROFITBLCOUNTNOTFEN=="1")nofensql=" AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
varstrSql=newStringBuilder();
//strSql.Append(" ");
//if (amendstr == "true")
//{
// strSql.Append("SELECT SUM(case WHEN A.OPTYPE='普通货' THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN A.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN A.CBM ELSE 0 END) CBM");
// strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
// if (PROFITRATEDR.PARAMVALUE != "1")
// {
// strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
// }
// else
// strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
// strSql.Append(",SUM(G.RMBDR-G.STLRMBDR) AS RMBNODR,SUM(G.USDDR-G.STLUSDDR) AS USDNODR,SUM(G.OTDR-G.STLOTDR) AS OTNODR,SUM(G.TTLDR-G.STLTTLDR) AS TTLNODR");
// strSql.Append(",SUM(G.RMBCR-G.STLRMBCR) AS RMBNOCR,SUM(G.USDCR-G.STLUSDCR) AS USDNOCR,SUM(G.OTCR-G.STLOTCR) AS OTNOCR,SUM(G.TTLCR-G.STLTTLCR) AS TTLNOCR");
// strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
// strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
// strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
// strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
// strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// // strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
// strSql.Append(" FROM V_OP_BS B ");
// strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
// strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
// strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// // strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
// strSql.Append(" FROM v_op_gain_sum_INV G");
// strSql.Append(" Where " + feecondition);
// strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
// strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
// }
// else
// {
// strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
// strSql.Append(" WHERE 1=1 ");
// }
// if (!string.IsNullOrEmpty(condition))
// {
// strSql.Append(" and " + condition);
// }
//}
//else
//{
if(amendstr=="true")
{
strSql.Append("SELECT SUM(case WHEN A.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND (A.BLTYPE='整箱' OR A.BLTYPE='拼箱主票') THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
}
else
{
strSql.Append("SELECT SUM(case WHEN B.OPTYPE='普通货' "+nofensql+" THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append("SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append("SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append("SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' AND (B.BLTYPE='整箱' OR B.BLTYPE='拼箱主票') THEN B.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where "+feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" and "+condition);
}
strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,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 = " (B.OP in (select showname from vw_user where deptgid='" + deptid + "') OR B.SALE in (select showname from vw_user where deptgid='" + deptid + "') OR B.CUSTSERVICE in (select showname from vw_user where deptgid='" + deptid + "') "
//+ " OR B.DOC in (select showname from vw_user where deptgid='" + deptid + "') OR B.FRCUSTSERVICE in (select showname from vw_user where deptgid='" + deptid + "') )";
str=" exists( select 1 from vw_user where deptgid='"+deptid+"' and(showname=B.OP OR showname=B.SALE OR showname=B.CUSTSERVICE OR showname=B.FRCUSTSERVICE OR showname=B.DOC )) ";
str=" (B.Corpid='"+Convert.ToString(reader["COMPANYID"])+"' or B.SALECORPID='"+Convert.ToString(reader["COMPANYID"])+"' ";
}
else
{
str=str+" or B.Corpid='"+Convert.ToString(reader["COMPANYID"])+"' or B.SALECORPID='"+Convert.ToString(reader["COMPANYID"])+"'";
};
}
str=str+")";
reader.Close();
}
}
elseif(visiblerange=="6")
{
str=" EXISTS (select 1 from user_authority_range_op P left join [user] u on (u.GID=P.OPID) where (B.OP=U.SHOWNAME OR B.SALE=U.SHOWNAME OR B.CUSTSERVICE=U.SHOWNAME) AND P.userid='"+userid+"' and P.AUTHORITYID='"+AUTHORITYID+"' and P.VISIBLERANGE=1) ";
}
elseif(visiblerange=="1")
{
str=" (UPPER(B.Corpid)='"+companyid+"' or B.SALECORPID='"+companyid+"') ";