using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; using DSWeb.MvcShipping.Helper; using DSWeb.MvcShipping.Comm.Cookie; using DSWeb.Areas.CommMng.DAL; using DSWeb.Areas.RptMng.Comm; using HcUtility.Comm; using HcUtility.Core; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using DSWeb.Areas.CommMng.Models; using DSWeb.MvcShipping.Models.MonthDataSet; using DSWeb.MvcShipping.Models.ProfitFieldSet; using DSWeb.MvcShipping.DAL.MsSysParamSet; namespace DSWeb.MvcShipping.Controllers { /// /// 月度利润报表查询 /// [JsonRequestBehavior] public class MsRptOpProfitMonthController : Controller { // // GET: /MvcShipping/MsRptOpProfit public ActionResult Index() { return View(); } public ActionResult ProfitFieldSet() { return View(); } // // GET:/RptMng/MsRptPcHeadQry/QryData public ContentResult BsListData(int start, int limit, string condition, string sort, string printstr, string sortstr) { if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "") { var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) }; } var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT 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,"); strSql.Append("B.ETD,B.PKGS,B.CBM"); strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID"); strSql.Append(",case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE"); strSql.Append(",case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF"); strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.CNTRTOTAL,B.CORPID"); 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(",B.TRADETYPE,B.GOODSNAME,B.FEESTATUS"); strSql.Append(",SUM(G.RMBDR) RMBDR,SUM(G.RMBCR) RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) USDDR,SUM(G.USDCR) USDCR,"); strSql.Append("SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) OTDR,SUM(G.OTCR) OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(ISNULL(G.TTLDR,0)) TTLDR,"); strSql.Append("SUM(ISNULL(G.TTLCR,0)) TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) 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 "); 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.NOTAXRMBDR) NOTAXRMBDR,SUM(G.NOTAXRMBCR) NOTAXRMBCR,SUM(G.NOTAXUSDDR) NOTAXUSDDR,SUM(G.NOTAXUSDCR) NOTAXUSDCR,SUM(G.NOTAXOTDR) NOTAXOTDR"); 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.TTLTAXDR) AS TTLTAXDR,SUM(G.TTLTAXCR) AS TTLTAXCR,SUM(G.TTLTAXDR-G.TTLTAXCR) AS TTLTAXPROFIT"); strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR"); 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_tax G ON (G.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,"); strSql.Append("B.ETD,B.PKGS,B.CBM,B.NETWEIGHT"); strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID"); strSql.Append(",B.CUSTOMDATE"); strSql.Append(",B.FEESTATUS"); strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID"); strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS"); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by " + sortstr); } else { strSql.Append(" order by ETD DESC,MBLNO"); } var jsonRespose = new JsonResponse { Success = true, Message = condition, Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.ETD DESC,B.MBLNO"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult CustListData(int start, int limit, string condition, string sort, string printstr, string sortstr,string datetype,string startmonth, string endmonth,string feetype) { if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "") { var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) }; } var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var monthlist = GetMonthList(datetype, startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var strSql = new StringBuilder(); strSql.Append("SELECT B.CUSTOMERNAME"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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 "); //20221121 增加 票数 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.CUSTOMERNAME "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by " + sortstr); } else { strSql.Append(" order by B.CUSTOMERNAME"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.CUSTOMERNAME"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult SaleListData(int start, int limit, string condition, string sort, string printstr, string sortstr,string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype,startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT B.SALE"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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 "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by B.SALE," + sortstr); } else { strSql.Append(" order by B.SALE"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.SALE"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult SaleDeptListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype, startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT B.SALEDEPT"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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.SALEDEPT "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by B.SALEDEPT," + sortstr); } else { strSql.Append(" order by B.SALEDEPT"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.SALEDEPT"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult SaleCustListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype, startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT B.SALE+'_'+B.CUSTOMERNAME SALE"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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 "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by B.SALE,B.CUSTOMERNAME ," + sortstr); } else { strSql.Append(" order by B.SALE,B.CUSTOMERNAME "); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.SALE,B.CUSTOMERNAME "); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult OpListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype, startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT B.OP"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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.OP "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by B.OP," + sortstr); } else { strSql.Append(" order by B.OP"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.OP"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult OpDeptListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype, startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT D.DEPTNAME OPDEPT"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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) "); strSql.Append("LEFT JOIN VW_user D ON (D.SHOWNAME=B.OP) "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" Where " + condition); } strSql.Append(" Group by D.DEPTNAME "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by D.DEPTNAME," + sortstr); } else { strSql.Append(" order by D.DEPTNAME"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by D.DEPTNAME"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult SaleCorpListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype, startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT C.NAME SALECORP"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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) "); strSql.Append("LEFT JOIN company C ON (C.GID=B.SALECORPID) "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" Where " + condition); } strSql.Append(" Group by C.NAME "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by " + sortstr); } else { strSql.Append(" order by C.NAME"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by C.NAME"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult BsSourceListData(int start, int limit, string condition, string sort, string printstr, string sortstr,string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype, startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT B.BSSOURCE"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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.BSSOURCE "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by " + sortstr); } else { strSql.Append(" order by B.BSSOURCE"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.BSSOURCE"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult BsSourceDetailListData(int start, int limit, string condition, string sort, string printstr, string sortstr,string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype, startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT B.BSSOURCE,B.BSSOURCEDETAIL"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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.BSSOURCE,B.BSSOURCEDETAIL "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by " + sortstr); } else { strSql.Append(" order by B.BSSOURCE,B.BSSOURCEDETAIL"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.BSSOURCE,B.BSSOURCEDETAIL"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult SumListData(int start, int limit, string condition, string sort, string printstr,string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype, startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT 1 as NO"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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); } if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult CarrierListData(int start, int limit, string condition, string sort, string printstr, string sortstr,string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype,startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT B.CARRIER"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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.CARRIER "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by " + sortstr); } else { strSql.Append(" order by B.CARRIER"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.CARRIER"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult YardListData(int start, int limit, string condition, string sort, string printstr, string sortstr,string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype, startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT B.YARD"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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.YARD "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by " + sortstr); } else { strSql.Append(" order by B.YARD"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.YARD"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public ContentResult LaneListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string datetype, string startmonth, string endmonth, string feetype) { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'"); // if (RPTPRNOCANCEL.PARAMVALUE == "1") // { // if (!string.IsNullOrEmpty(condition)) // { // condition = condition + " and isnull(B.ISCANCEL,0)<>1 "; // } // else // { // condition = " isnull(B.ISCANCEL,0)<>1 "; // } // } BasicDataRefDAL.SetISCANCELCondition(ref condition, "B.ISCANCEL"); var monthlist = GetMonthList(datetype, startmonth, endmonth); var Fieldset = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); var strSql = new StringBuilder(); strSql.Append("SELECT B.LANE"); foreach (var enumValue in monthlist) { if (feetype == "1") { if (Fieldset.RMBDR) 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"); } } else if (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.LANE "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by " + sortstr); } else { strSql.Append(" order by B.LANE"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.LANE"); } var dbparams = new List(); var paramps_sSQL = new CustomDbParamter(); paramps_sSQL.ParameterName = "@sSQL"; paramps_sSQL.DbType = DbType.String; paramps_sSQL.Direction = ParameterDirection.Input; paramps_sSQL.Value = strSql.ToString(); dbparams.Add(paramps_sSQL); var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set"); var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true); return new ContentResult() { Content = json }; } } public static string GetRangDAStr(string tb, string userid, string usercode, string companyid) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='modMonthProfitreportRange' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; string VSSQL = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { visiblerange = Convert.ToString(reader["VISIBLERANGE"]); operaterange = Convert.ToString(reader["OPERATERANGE"]); AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]); VSSQL = Convert.ToString(reader["VSSQL"]); break; } reader.Close(); } if (visiblerange == "4") { str = "1=2"; } else if (visiblerange == "3") { str = " (B.OP='" + usercode + "' OR B.SALE='" + usercode + "')"; } else if (visiblerange == "2") { if (tb == "index") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); var userstr = new StringBuilder(); 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 + "')"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'"; } else { str = str + " or B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'"; }; } str = str + ")"; reader.Close(); } } else { str = " (UPPER(B.Corpid)='" + companyid + "' or B.SALECORPID='" + companyid + "') "; } } else if (visiblerange == "5") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { 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(); } } else if (visiblerange == "6") { var userstr = new StringBuilder(); 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"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'"; } else { str = str + " or B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'"; }; } str = str + ")"; reader.Close(); } } else if (visiblerange == "1") { str = " (UPPER(B.Corpid)='" + companyid + "' or B.SALECORPID='" + companyid + "') "; } VSSQL = VSSQL.Trim(); if (!string.IsNullOrEmpty(VSSQL)) { if (!string.IsNullOrEmpty(str)) { str = str + " and (" + VSSQL + ") "; } else { str = " (" + VSSQL + ") "; } } return str; } #region 月度数 public ContentResult GetMonthsData(string datetype,string startmonth, string endmonth) { var dataList = GetMonthList(datetype,startmonth, endmonth, Convert.ToString(Session["COMPANYID"])); var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", data = dataList.ToList() }); return new ContentResult() { Content = json }; } static public List GetMonthList(string datetype, string startmonth, string endmonth,string companyid) { var startdate = startmonth.Split('-'); var enddate = endmonth.Split('-'); int monthstart = Convert.ToInt16(startdate[0]) * 12 + Convert.ToInt16(startdate[1]); int monthend = Convert.ToInt16(enddate[0]) * 12 + Convert.ToInt16(enddate[1]); var betweenmonth = monthend - monthstart + 1; if (datetype == "ACCDATE") startmonth = startmonth + "-01"; DateTime dt = DateTime.ParseExact(startmonth, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture); var evList = new List(); var month = ""; var profitfield=GetProfitFieldSet(companyid); for (int i = 0; i < betweenmonth; i++) { var evData = new ProfitMonthFieldSet(); evData.MONTHNAME = dt.ToString("yyyy年MM月"); evData.MONTHNO = i; month = dt.Month.ToString(); if (month.Length == 1) month = "0" + month; if (datetype == "ACCDATE") evData.MONTHFIELDNAME = dt.Year.ToString() + "-" + month; else evData.MONTHFIELDNAME = dt.Year.ToString() + "/" + month; evData.MONTHSORT = dt.ToString("MMyyyy"); evData.RMBDR = profitfield.RMBDR; evData.RMBCR = profitfield.RMBCR; evData.USDDR = profitfield.USDDR; evData.USDCR = profitfield.USDCR; evData.OTDR = profitfield.OTDR; evData.OTCR = profitfield.OTCR; evData.TTLDR = profitfield.TTLDR; evData.TTLCR = profitfield.TTLCR; evData.RMBPROFIT = profitfield.RMBPROFIT; evData.USDPROFIT = profitfield.USDPROFIT; evData.OTPROFIT = profitfield.OTPROFIT; evData.TTLPROFIT = profitfield.TTLPROFIT; evData.PROFITRATE = profitfield.PROFITRATE; evData.TEU = profitfield.TEU; evList.Add(evData); dt = dt.AddMonths(1); } var evList2 = new List(); if (betweenmonth > 12) { evList2 = evList.OrderBy(a => a.MONTHSORT).ToList(); return evList2; } return evList; } static public List GetMonthList(string datetype,string startmonth, string endmonth) { var startdate = startmonth.Split('-'); var enddate = endmonth.Split('-'); int monthstart = Convert.ToInt16(startdate[0]) * 12 + Convert.ToInt16(startdate[1]); int monthend = Convert.ToInt16(enddate[0]) * 12 + Convert.ToInt16(enddate[1]); var betweenmonth = monthend - monthstart + 1; if (datetype == "ACCDATE") startmonth = startmonth + "-01"; DateTime dt = DateTime.ParseExact(startmonth, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture); var evList = new List(); var month = ""; for (int i = 0; i < betweenmonth; i++) { var evData = new MonthDataSet(); evData.MONTHNAME = dt.ToString("yyyy年MM月"); evData.MONTHNO = i; month = dt.Month.ToString(); if (month.Length == 1) month = "0" + month; if (datetype == "ACCDATE") evData.MONTHFIELDNAME = dt.Year.ToString() + "-" + month; else evData.MONTHFIELDNAME = dt.Year.ToString() + "/" + month; evData.MONTHSORT = dt.ToString("MMyyyy"); evList.Add(evData); dt = dt.AddMonths(1); } var evList2 = new List(); if (betweenmonth > 12) { evList2 = evList.OrderBy(a => a.MONTHSORT).ToList(); return evList2; } return evList; } #endregion #region 利润字段设置 public ContentResult GetProfitFieldSet() { ProfitFieldSet head = null; head = GetProfitFieldSet(Convert.ToString(Session["COMPANYID"])); var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", data = head }); return new ContentResult() { Content = json }; } static public ProfitFieldSet GetProfitFieldSet(string companyid) { var strSql = new StringBuilder(); strSql.Append("SELECT GID,RMBDR,RMBCR,USDDR,USDCR,OTDR,OTCR,TTLDR,TTLCR,RMBPROFIT,USDPROFIT,OTPROFIT,TTLPROFIT,TEU,PROFITRATE from sys_profitfieldset"); strSql.Append(" Where COMPANYID='" + companyid + "'"); Database db = DatabaseFactory.CreateDatabase(); var evList = new List(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = new ProfitFieldSet(); evData.GID = Convert.ToString(reader["GID"]); if (reader["RMBDR"] != DBNull.Value) evData.RMBDR = Convert.ToBoolean(reader["RMBDR"]); if (reader["RMBCR"] != DBNull.Value) evData.RMBCR = Convert.ToBoolean(reader["RMBCR"]); if (reader["USDDR"] != DBNull.Value) evData.USDDR = Convert.ToBoolean(reader["USDDR"]); if (reader["USDCR"] != DBNull.Value) evData.USDCR = Convert.ToBoolean(reader["USDCR"]); if (reader["OTDR"] != DBNull.Value) evData.OTDR = Convert.ToBoolean(reader["OTDR"]); if (reader["OTCR"] != DBNull.Value) evData.OTCR = Convert.ToBoolean(reader["OTCR"]); if (reader["TTLDR"] != DBNull.Value) evData.TTLDR = Convert.ToBoolean(reader["TTLDR"]); if (reader["TTLCR"] != DBNull.Value) evData.TTLCR = Convert.ToBoolean(reader["TTLCR"]); if (reader["RMBPROFIT"] != DBNull.Value) evData.RMBPROFIT = Convert.ToBoolean(reader["RMBPROFIT"]); if (reader["USDPROFIT"] != DBNull.Value) evData.USDPROFIT = Convert.ToBoolean(reader["USDPROFIT"]); if (reader["OTPROFIT"] != DBNull.Value) evData.OTPROFIT = Convert.ToBoolean(reader["OTPROFIT"]); if (reader["TTLPROFIT"] != DBNull.Value) evData.TTLPROFIT = Convert.ToBoolean(reader["TTLPROFIT"]); if (reader["TEU"] != DBNull.Value) evData.TEU = Convert.ToBoolean(reader["TEU"]); if (reader["PROFITRATE"] != DBNull.Value) evData.PROFITRATE = Convert.ToBoolean(reader["PROFITRATE"]); evList.Add(evData); } reader.Close(); } if (evList.Count > 0) return evList[0]; return new ProfitFieldSet(); } public ContentResult SaveProfitFieldSet(string data) { var headData = JsonConvert.Deserialize(data); var isPost = true; var errorstr = ""; headData.COMPANYID = Convert.ToString(Session["COMPANYID"]); var result = new DBResult(); if (isPost) { Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdDelete = db.GetSqlStringCommand( @"delete from sys_profitfieldset where COMPANYID=@COMPANYID "); cmdDelete.Parameters.Clear(); db.AddInParameter(cmdDelete, "@COMPANYID", DbType.String, Convert.ToString(Session["COMPANYID"])); db.ExecuteNonQuery(cmdDelete, tran); var cmdInsert = db.GetSqlStringCommand( @"insert into sys_profitfieldset (GID,COMPANYID,RMBDR,RMBCR,USDDR,USDCR,OTDR,OTCR,TTLDR,TTLCR,RMBPROFIT,USDPROFIT,OTPROFIT,TTLPROFIT,TEU,PROFITRATE) values (@GID,@COMPANYID ,@RMBDR,@RMBCR,@USDDR,@USDCR,@OTDR,@OTCR,@TTLDR,@TTLCR,@RMBPROFIT,@USDPROFIT,@OTPROFIT,@TTLPROFIT,@TEU,@PROFITRATE) "); cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, headData.GID); db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, headData.COMPANYID); db.AddInParameter(cmdInsert, "@RMBDR", DbType.Boolean, headData.RMBDR); db.AddInParameter(cmdInsert, "@RMBCR", DbType.Boolean, headData.RMBCR); db.AddInParameter(cmdInsert, "@USDDR", DbType.Boolean, headData.USDDR); db.AddInParameter(cmdInsert, "@USDCR", DbType.Boolean, headData.USDCR); db.AddInParameter(cmdInsert, "@OTDR", DbType.Boolean, headData.OTDR); db.AddInParameter(cmdInsert, "@OTCR", DbType.Boolean, headData.OTCR); db.AddInParameter(cmdInsert, "@TTLDR", DbType.Boolean, headData.TTLDR); db.AddInParameter(cmdInsert, "@TTLCR", DbType.Boolean, headData.TTLCR); db.AddInParameter(cmdInsert, "@RMBPROFIT", DbType.Boolean, headData.RMBPROFIT); db.AddInParameter(cmdInsert, "@USDPROFIT", DbType.Boolean, headData.USDPROFIT); db.AddInParameter(cmdInsert, "@OTPROFIT", DbType.Boolean, headData.OTPROFIT); db.AddInParameter(cmdInsert, "@TTLPROFIT", DbType.Boolean, headData.TTLPROFIT); db.AddInParameter(cmdInsert, "@TEU", DbType.Boolean, headData.TEU); db.AddInParameter(cmdInsert, "@PROFITRATE", DbType.Boolean, headData.PROFITRATE); db.ExecuteNonQuery(cmdInsert, tran); tran.Commit(); result.Success = true; result.Message = "保存成功!"; } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; } } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var jsonRespose = new JsonResponse { Success = false, Message = errorstr + "重复,不允许保存!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } #endregion #region 参照部分 #endregion //private void SetField(ProfitFieldSet Fieldset,ref StringBuilder strSql) { // 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 "); //} } }