strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL"+enumValue.MONTHNO.ToString()+"TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append("SELECT F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",isnull(dbo.GetCustZq(F.CUSTOMERNAME),'无账期') AS CUSTZQ ");
foreach(varenumValueinmonthlist)
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL"+enumValue.MONTHNO.ToString()+"TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" Group by F.CUSTOMERNAME,C.[DESCRIPTION] ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL"+enumValue.MONTHNO.ToString()+"TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
strSql.Append("SELECT B.SALE,F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",isnull(dbo.GetCustSaleZq(F.CUSTOMERNAME,B.SALE),'无账期') AS CUSTZQ ");
foreach(varenumValueinmonthlist)
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL"+enumValue.MONTHNO.ToString()+"TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" Group by B.SALE,F.CUSTOMERNAME,C.[DESCRIPTION] ");
strSql.Append("SELECT B.OP,F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",isnull(dbo.GetCustZq(F.CUSTOMERNAME),'无账期') AS CUSTZQ ");
foreach(varenumValueinmonthlist)
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL"+enumValue.MONTHNO.ToString()+"TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" Group by B.OP,F.CUSTOMERNAME,C.[DESCRIPTION] ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B."+datetype+", 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL"+enumValue.MONTHNO.ToString()+"TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
str=" (B.OP='"+usercode+"' OR B.SALE='"+usercode+"')";
}
elseif(visiblerange=="2")
{
if(tb=="index")
{
varrangeDa=newRangeDA();
vardeptname=rangeDa.GetDEPTNAME(userid);
varuserstr=newStringBuilder();
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='"+companyid+"') and GID in (select userid from user_baseinfo where DEPTNAME='"+deptname+"')");
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")
{
varuserstr=newStringBuilder();
userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='"+userid+"' and AUTHORITYID='"+AUTHORITYID+"' and VISIBLERANGE=1");