strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXRMBDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMBDR ");
if(Fieldset.RMBCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXRMBCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMBCR ");
if(Fieldset.USDDR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXUSDDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USDDR ");
if(Fieldset.USDCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXUSDCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USDCR ");
if(Fieldset.OTDR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15),B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXOTDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OTDR ");
if(Fieldset.OTCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXOTCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OTCR ");
if(Fieldset.TTLDR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXTTLDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTLDR ");
if(Fieldset.TTLCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXTTLCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTLCR ");
if(Fieldset.RMBPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXRMBDR-G.NOTAXRMBCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMBPROFIT ");
if(Fieldset.USDPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXUSDDR-G.NOTAXUSDCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USDPROFIT ");
if(Fieldset.OTPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXOTDR-G.NOTAXOTCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OTPROFIT ");
if(Fieldset.TTLPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXTTLDR-G.NOTAXTTLCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTLPROFIT ");
if(Fieldset.PROFITRATE)
{
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXTTLDR else 0 end)= 0) THEN 0 ELSE");
strSql.Append(" CONVERT(NUMERIC(18,2),ltrim(str((sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXTTLDR-G.NOTAXTTLCR else 0 end)) / (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXTTLDR else 0 end)) * 100, 10, 2))) END) AS ZL"+enumValue.MONTHNO.ToString()+"PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXTTLCR else 0 end)= 0) THEN 0 ELSE");
strSql.Append(" CONVERT(NUMERIC(18,2),ltrim(str((sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXTTLDR-G.NOTAXTTLCR else 0 end)) / (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOTAXTTLCR else 0 end)) * 100, 10, 2))) END) AS ZL"+enumValue.MONTHNO.ToString()+"PROFITRATE");
}
}
elseif(feetype=="2")
{
if(Fieldset.RMBDR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXRMBDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMBDR ");
if(Fieldset.RMBCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXRMBCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMBCR ");
if(Fieldset.USDDR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXUSDDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USDDR ");
if(Fieldset.USDCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXUSDCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USDCR ");
if(Fieldset.OTDR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15),B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXOTDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OTDR ");
if(Fieldset.OTCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXOTCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OTCR ");
if(Fieldset.TTLDR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXTTLDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTLDR ");
if(Fieldset.TTLCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXTTLCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTLCR ");
if(Fieldset.RMBPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXRMBDR-G.NOACCTAXRMBCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMBPROFIT ");
if(Fieldset.USDPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXUSDDR-G.NOACCTAXUSDCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USDPROFIT ");
if(Fieldset.OTPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXOTDR-G.NOACCTAXOTCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OTPROFIT ");
if(Fieldset.TTLPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXTTLDR-G.NOACCTAXTTLCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTLPROFIT ");
if(Fieldset.PROFITRATE)
{
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXTTLDR else 0 end)= 0) THEN 0 ELSE");
strSql.Append(" CONVERT(NUMERIC(18,2),ltrim(str((sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXTTLDR-G.NOACCTAXTTLCR else 0 end)) / (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXTTLDR else 0 end)) * 100, 10, 2))) END) AS ZL"+enumValue.MONTHNO.ToString()+"PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXTTLCR else 0 end)= 0) THEN 0 ELSE");
strSql.Append(" CONVERT(NUMERIC(18,2),ltrim(str((sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXTTLDR-G.NOACCTAXTTLCR else 0 end)) / (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.NOACCTAXTTLCR else 0 end)) * 100, 10, 2))) END) AS ZL"+enumValue.MONTHNO.ToString()+"PROFITRATE");
}
}
else
{
if(Fieldset.RMBDR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.RMBDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMBDR ");
if(Fieldset.RMBCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.RMBCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMBCR ");
if(Fieldset.USDDR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.USDDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USDDR ");
if(Fieldset.USDCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.USDCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USDCR ");
if(Fieldset.OTDR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.OTDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OTDR ");
if(Fieldset.OTCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.OTCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OTCR ");
if(Fieldset.TTLDR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.TTLDR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTLDR ");
if(Fieldset.TTLCR)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.TTLCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTLCR ");
if(Fieldset.RMBPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.RMBDR-G.RMBCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMBPROFIT ");
if(Fieldset.USDPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.USDDR-G.USDCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USDPROFIT ");
if(Fieldset.OTPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.OTDR-G.OTCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OTPROFIT ");
if(Fieldset.TTLPROFIT)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.TTLDR-G.TTLCR else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTLPROFIT ");
if(Fieldset.PROFITRATE)
{
if(PROFITRATEDR.PARAMVALUE!="1")
{
strSql.Append(", (CASE WHEN (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.TTLDR else 0 end)= 0) THEN 0 ELSE");
strSql.Append(" CONVERT(NUMERIC(18,2),ltrim(str((sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.TTLDR-G.TTLCR else 0 end)) / (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.TTLDR else 0 end)) * 100, 10, 2))) END) AS ZL"+enumValue.MONTHNO.ToString()+"PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.TTLCR else 0 end)= 0) THEN 0 ELSE");
strSql.Append(" CONVERT(NUMERIC(18,2),ltrim(str((sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.TTLDR-G.TTLCR else 0 end)) / (sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.TTLCR else 0 end)) * 100, 10, 2))) END) AS ZL"+enumValue.MONTHNO.ToString()+"PROFITRATE");
}
}
if(Fieldset.TEU)
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then B.TEU else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TEU ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' and B.BSNO=B.MASTERNO then 1 else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"BILLCOUNT ");
}
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append("LEFT JOIN v_op_gain_sum_tax G ON (G.BSNO=B.BSNO) ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" Group by B.SALE,B.CUSTOMERNAME ");
strSql.Append(" ,b.DOC,b.SALEDEPT,(select name from company where gid= b.SALECORPID)SALECORP ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" where F.AMOUNT<>F.SETTLEMENT and F.CUSTOMERNAME='"+CUSTOMERNAME+"' and EXISTS (select 1 from CH_FEE_AutoDuiDetail fd where (fd.MBLNO=B.MBLNO OR fd.MBLNO=B.HBLNO) and fd.BSNO='"+AutoDui_GID+"') ");
strSql.Append(" where F.AMOUNT<>F.SETTLEMENT and F.CUSTOMERNAME='"+CUSTOMERNAME+"' and EXISTS (select 1 from CH_FEE_AutoDuiDetail fd where (fd.MBLNO=B.MBLNO OR fd.MBLNO=B.HBLNO) and fd.BSNO='"+AutoDui_GID+"') and isnull(b.MBLNO,'')<>'' and isnull(b.iscancel,0)<>1 ");
//var blUpSQL = " update CH_FEE_AutoDuiDetail set B_BSNO=(select top 1 BSNO from v_op_bS where (MBLNO=D.b_mblno or HBLNO=D.MBLNO) and OPLBNAME in('海运进口','海运出口','空运进口','空运出口') ) FROM CH_FEE_AutoDuiDetail d where bsno='" + duihead.GID+"'";
varblUpSQL=" update CH_FEE_AutoDuiDetail set B_BSNO=(select top 1 BSNO from v_op_bS where (MBLNO=D.mblno or HBLNO=D.MBLNO) ) FROM CH_FEE_AutoDuiDetail d where bsno='" +duihead.GID+"'";
varblUpSQL=" update CH_FEE_AutoDuiDetail set B_BSNO=(select top 1 BSNO from v_op_bS where (MBLNO=D.mblno or HBLNO=D.MBLNO) and isnull(MBLNO,'')<>'' ) FROM CH_FEE_AutoDuiDetail d where bsno='" +duihead.GID+"'";