You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/Controllers/MsRptZJTotalController.cs

568 lines
35 KiB
C#

2 years ago
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.MvcShipping.DAL.MsRptZjTotalDAL;
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 System.IO;
namespace DSWeb.MvcShipping.Controllers
{
/// <summary>
/// 资金综合分析查询
/// </summary>
[JsonRequestBehavior]
public class MsRptZjTotalController : Controller
{
//
// GET: /MvcShipping/MsRptOpProfit
public ActionResult Index()
{
return View();
}
//
// GET/RptMng/MsRptPcHeadQry/QryData
public ContentResult CustListData(int start, int limit, string condition, string sort, string printstr)
{
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;
}
}
if (string.IsNullOrEmpty(condition))
{
condition = " 1=1 ";
}
var strSql = new StringBuilder();
strSql.Append(" DECLARE @all_pay numeric select @all_pay=isnull((select sum(v_op_gain_sum.TTLCR) from v_op_gain_sum ");
strSql.Append(" where v_op_gain_sum.BSNO in (select B.BSNO from v_op_bill B where " + condition + " )),0) ");
strSql.Append("SELECT B.CUSTOMERNAME,sum(v_op_gain_sum.TTLDR-v_op_gain_sum.TTLCR) as TTLPROFIT,(case when isnull(sum(v_op_gain_sum.TTLCR),0)=0 then '无法计算' else");
strSql.Append(" ltrim(str(sum(v_op_gain_sum.TTLDR-v_op_gain_sum.TTLCR)/sum(v_op_gain_sum.TTLCR)*100,10,2))+'%' end) as TTLPROFITATS,");
strSql.Append(" sum(v_op_gain_sum.TTLCR) as TTLCR,(case when @all_pay=0 then '无法计算' else (ltrim(str(sum(v_op_gain_sum.TTLCR)/@all_pay*100,10,2))+'%') end) as TTLCRATS,");
strSql.Append(" isnull(sum(v_op_gain_sum.TTLDR),0) as TTLDR ");
strSql.Append(" INTO #bill ");
strSql.Append("FROM v_op_gain_sum inner join v_op_bill B on v_op_gain_sum.BSNO = B.BSNO where " + condition);
strSql.Append(" group by B.CUSTOMERNAME ");
strSql.Append("SELECT B.CUSTOMERNAME,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<= 30 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH1DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<= 30 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH1CR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 30 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=60 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH2DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 30 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=60 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH2CR, ");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE, ch_fee_settlement.SETTLETIME)> 60 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH3DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE, ch_fee_settlement.SETTLETIME)> 60 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH3CR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS OTMONTHDR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS OTMONTHCR ");
strSql.Append(" INTO #fee ");
strSql.Append("FROM ch_fee_do inner JOIN v_op_bill B on ch_fee_do.BSNO=B.BSNO inner JOIN ");
strSql.Append(" ch_fee_settlement ON ch_fee_do.BILLNO = ch_fee_settlement.BILLNO inner JOIN ch_fee ON ch_fee_do.FEEID = ch_fee.GID where ch_fee_do.CATEGORY in (1,2,3,8,9) and " + condition);
strSql.Append(" group by B.CUSTOMERNAME ");
strSql.Append("select #bill.CUSTOMERNAME,#bill.TTLPROFIT,#bill.TTLPROFITATS,#bill.TTLCR,#bill.TTLCRATS,");
strSql.Append("(case when #bill.TTLDR=0 then '' else ltrim(str((isnull(#fee.MONTH1DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH1ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH2DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH2ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH3DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH3ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHDR,0))/#bill.TTLDR*100,10,2))+'%' end) as OTMONTHATS , ");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHDR,0)+isnull(#fee.MONTH1DR,0)+isnull(#fee.MONTH2DR,0)+isnull(#fee.MONTH3DR,0))/#bill.TTLDR*100,10,2))+'%' end) as TTLDRATS, ");
strSql.Append("(case when #bill.TTLCR=0 then '' else ltrim(str((isnull(#fee.MONTH1CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH1CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH2CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH2CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH3CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH3CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHCR,0))/#bill.TTLCR*100,10,2))+'%' end) as OTMONTHCRATS , ");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHCR,0)+isnull(#fee.MONTH1CR,0)+isnull(#fee.MONTH2CR,0)+isnull(#fee.MONTH3CR,0))/#bill.TTLCR*100,10,2))+'%' end) as TTLMONTHCRATS, ");
strSql.Append(" #bill.TTLDR ");
strSql.Append("from #bill left join #fee on #bill.CUSTOMERNAME=#fee.CUSTOMERNAME ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
strSql.Append(" order by #bill.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 #bill.CUSTOMERNAME ");
}
var dbparams = new List<CustomDbParamter>();
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)
{
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;
}
}
if (string.IsNullOrEmpty(condition))
{
condition = " 1=1 ";
}
var strSql = new StringBuilder();
strSql.Append(" DECLARE @all_pay numeric select @all_pay=isnull((select sum(v_op_gain_sum.TTLCR) from v_op_gain_sum ");
strSql.Append(" where v_op_gain_sum.BSNO in (select B.BSNO from v_op_bill B where " + condition + " )),0) ");
strSql.Append("SELECT B.SALE,sum(v_op_gain_sum.TTLDR-v_op_gain_sum.TTLCR) as TTLPROFIT,(case when isnull(sum(v_op_gain_sum.TTLCR),0)=0 then '无法计算' else");
strSql.Append(" ltrim(str(sum(v_op_gain_sum.TTLDR-v_op_gain_sum.TTLCR)/sum(v_op_gain_sum.TTLCR)*100,10,2))+'%' end) as TTLPROFITATS,");
strSql.Append(" sum(v_op_gain_sum.TTLCR) as TTLCR,(case when @all_pay=0 then '无法计算' else (ltrim(str(sum(v_op_gain_sum.TTLCR)/@all_pay*100,10,2))+'%') end) as TTLCRATS,");
strSql.Append(" isnull(sum(v_op_gain_sum.TTLDR),0) as TTLDR ");
strSql.Append(" INTO #bill ");
strSql.Append("FROM v_op_gain_sum inner join v_op_bill B on v_op_gain_sum.BSNO = B.BSNO where " + condition);
strSql.Append(" group by B.SALE ");
strSql.Append("SELECT B.SALE,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<= 30 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH1DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<= 30 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH1CR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 30 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=60 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH2DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 30 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=60 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH2CR, ");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE, ch_fee_settlement.SETTLETIME)> 60 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH3DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE, ch_fee_settlement.SETTLETIME)> 60 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH3CR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS OTMONTHDR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS OTMONTHCR ");
strSql.Append(" INTO #fee ");
strSql.Append("FROM ch_fee_do inner JOIN v_op_bill B on ch_fee_do.BSNO=B.BSNO inner JOIN ");
strSql.Append(" ch_fee_settlement ON ch_fee_do.BILLNO = ch_fee_settlement.BILLNO inner JOIN ch_fee ON ch_fee_do.FEEID = ch_fee.GID where ch_fee_do.CATEGORY in (1,2,3,8,9) and " + condition);
strSql.Append(" group by B.SALE ");
strSql.Append("select #bill.SALE,#bill.TTLPROFIT,#bill.TTLPROFITATS,#bill.TTLCR,#bill.TTLCRATS,");
strSql.Append("(case when #bill.TTLDR=0 then '' else ltrim(str((isnull(#fee.MONTH1DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH1ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH2DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH2ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH3DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH3ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHDR,0))/#bill.TTLDR*100,10,2))+'%' end) as OTMONTHATS , ");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHDR,0)+isnull(#fee.MONTH1DR,0)+isnull(#fee.MONTH2DR,0)+isnull(#fee.MONTH3DR,0))/#bill.TTLDR*100,10,2))+'%' end) as TTLDRATS, ");
strSql.Append("(case when #bill.TTLCR=0 then '' else ltrim(str((isnull(#fee.MONTH1CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH1CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH2CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH2CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH3CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH3CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHCR,0))/#bill.TTLCR*100,10,2))+'%' end) as OTMONTHCRATS , ");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHCR,0)+isnull(#fee.MONTH1CR,0)+isnull(#fee.MONTH2CR,0)+isnull(#fee.MONTH3CR,0))/#bill.TTLCR*100,10,2))+'%' end) as TTLMONTHCRATS, ");
strSql.Append(" #bill.TTLDR ");
strSql.Append("from #bill left join #fee on #bill.SALE=#fee.SALE ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
strSql.Append(" order by #bill.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 #bill.SALE ");
}
var dbparams = new List<CustomDbParamter>();
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)
{
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;
}
}
if (string.IsNullOrEmpty(condition))
{
condition = " 1=1 ";
}
var strSql = new StringBuilder();
strSql.Append(" DECLARE @all_pay numeric select @all_pay=isnull((select sum(v_op_gain_sum.TTLCR) from v_op_gain_sum ");
strSql.Append(" where v_op_gain_sum.BSNO in (select B.BSNO from v_op_bill B where " + condition + " )),0) ");
strSql.Append("SELECT B.OP,sum(v_op_gain_sum.TTLDR-v_op_gain_sum.TTLCR) as TTLPROFIT,(case when isnull(sum(v_op_gain_sum.TTLCR),0)=0 then '无法计算' else");
strSql.Append(" ltrim(str(sum(v_op_gain_sum.TTLDR-v_op_gain_sum.TTLCR)/sum(v_op_gain_sum.TTLCR)*100,10,2))+'%' end) as TTLPROFITATS,");
strSql.Append("sum(v_op_gain_sum.TTLCR) as TTLCR,(case when @all_pay=0 then '无法计算' else (ltrim(str(sum(v_op_gain_sum.TTLCR)/@all_pay*100,10,2))+'%') end) as TTLCRATS,");
strSql.Append(" isnull(sum(v_op_gain_sum.TTLDR),0) as TTLDR ");
strSql.Append(" INTO #bill ");
strSql.Append("FROM v_op_gain_sum inner join v_op_bill B on v_op_gain_sum.BSNO = B.BSNO where " + condition);
strSql.Append(" group by B.OP ");
strSql.Append("SELECT B.OP,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<= 30 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH1DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<= 30 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH1CR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 30 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=60 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH2DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 30 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=60 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH2CR, ");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE, ch_fee_settlement.SETTLETIME)> 60 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH3DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE, ch_fee_settlement.SETTLETIME)> 60 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH3CR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS OTMONTHDR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS OTMONTHCR ");
strSql.Append(" INTO #fee ");
strSql.Append("FROM ch_fee_do inner JOIN v_op_bill B on ch_fee_do.BSNO=B.BSNO inner JOIN ");
strSql.Append(" ch_fee_settlement ON ch_fee_do.BILLNO = ch_fee_settlement.BILLNO inner JOIN ch_fee ON ch_fee_do.FEEID = ch_fee.GID where ch_fee_do.CATEGORY in (1,2,3,8,9) and " + condition);
strSql.Append(" group by B.OP ");
strSql.Append("select #bill.OP,#bill.TTLPROFIT,#bill.TTLPROFITATS,#bill.TTLCR,#bill.TTLCRATS,");
strSql.Append("(case when #bill.TTLDR=0 then '' else ltrim(str((isnull(#fee.MONTH1DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH1ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH2DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH2ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH3DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH3ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHDR,0))/#bill.TTLDR*100,10,2))+'%' end) as OTMONTHATS , ");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHDR,0)+isnull(#fee.MONTH1DR,0)+isnull(#fee.MONTH2DR,0)+isnull(#fee.MONTH3DR,0))/#bill.TTLDR*100,10,2))+'%' end) as TTLDRATS, ");
strSql.Append("(case when #bill.TTLCR=0 then '' else ltrim(str((isnull(#fee.MONTH1CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH1CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH2CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH2CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH3CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH3CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHCR,0))/#bill.TTLCR*100,10,2))+'%' end) as OTMONTHCRATS , ");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHCR,0)+isnull(#fee.MONTH1CR,0)+isnull(#fee.MONTH2CR,0)+isnull(#fee.MONTH3CR,0))/#bill.TTLCR*100,10,2))+'%' end) as TTLMONTHCRATS, ");
strSql.Append(" #bill.TTLDR ");
strSql.Append("from #bill left join #fee on #bill.OP=#fee.OP ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
strSql.Append(" order by #bill.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 #bill.OP ");
}
var dbparams = new List<CustomDbParamter>();
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)
{
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;
}
}
if (string.IsNullOrEmpty(condition))
{
condition = " 1=1 ";
}
var strSql = new StringBuilder();
strSql.Append(" DECLARE @all_pay numeric select @all_pay=isnull((select sum(v_op_gain_sum.TTLCR) from v_op_gain_sum ");
strSql.Append(" where v_op_gain_sum.BSNO in (select B.BSNO from v_op_bill B where " + condition + " )),0) ");
strSql.Append("SELECT sum(v_op_gain_sum.TTLDR-v_op_gain_sum.TTLCR) as TTLPROFIT,(case when isnull(sum(v_op_gain_sum.TTLCR),0)=0 then '无法计算' else");
strSql.Append(" ltrim(str(sum(v_op_gain_sum.TTLDR-v_op_gain_sum.TTLCR)/sum(v_op_gain_sum.TTLCR)*100,10,2))+'%' end) as TTLPROFITATS,");
strSql.Append(" sum(v_op_gain_sum.TTLCR) as TTLCR,(case when @all_pay=0 then '无法计算' else (ltrim(str(sum(v_op_gain_sum.TTLCR)/@all_pay*100,10,2))+'%') end) as TTLCRATS,");
strSql.Append(" isnull(sum(v_op_gain_sum.TTLDR),0) as TTLDR ");
strSql.Append(" INTO #bill ");
strSql.Append("FROM v_op_gain_sum inner join v_op_bill B on v_op_gain_sum.BSNO = B.BSNO where " + condition);
strSql.Append("SELECT ");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<= 30 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH1DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<= 30 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH1CR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 30 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=60 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH2DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 30 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=60 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH2CR, ");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE, ch_fee_settlement.SETTLETIME)> 60 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH3DR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE, ch_fee_settlement.SETTLETIME)> 60 and DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)<=90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS MONTH3CR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=1 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS OTMONTHDR,");
strSql.Append("SUM(CASE WHEN ch_fee_do.FEETYPE=2 then (CASE WHEN DATEDIFF([day], B.OPDATE,ch_fee_settlement.SETTLETIME)> 90 THEN ch_fee_do.ORIGAMOUNT * ch_fee.EXCHANGERATE ELSE 0 END) else 0 end) AS OTMONTHCR ");
strSql.Append(" INTO #fee ");
strSql.Append("FROM ch_fee_do inner JOIN v_op_bill B on ch_fee_do.BSNO=B.BSNO inner JOIN ");
strSql.Append(" ch_fee_settlement ON ch_fee_do.BILLNO = ch_fee_settlement.BILLNO inner JOIN ch_fee ON ch_fee_do.FEEID = ch_fee.GID where ch_fee_do.CATEGORY in (1,2,8,9) and " + condition);
strSql.Append("select #bill.TTLPROFIT,#bill.TTLPROFITATS,#bill.TTLCR,#bill.TTLCRATS,");
strSql.Append("(case when #bill.TTLDR=0 then '' else ltrim(str((isnull(#fee.MONTH1DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH1ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH2DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH2ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH3DR,0))/#bill.TTLDR*100,10,2))+'%' end) as MONTH3ATS,");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHDR,0))/#bill.TTLDR*100,10,2))+'%' end) as OTMONTHATS , ");
strSql.Append("(case when #bill.TTLDR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHDR,0)+isnull(#fee.MONTH1DR,0)+isnull(#fee.MONTH2DR,0)+isnull(#fee.MONTH3DR,0))/#bill.TTLDR*100,10,2))+'%' end) as TTLDRATS, ");
strSql.Append("(case when #bill.TTLCR=0 then '' else ltrim(str((isnull(#fee.MONTH1CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH1CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH2CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH2CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.MONTH3CR,0))/#bill.TTLCR*100,10,2))+'%' end) as MONTH3CRATS,");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHCR,0))/#bill.TTLCR*100,10,2))+'%' end) as OTMONTHCRATS , ");
strSql.Append("(case when #bill.TTLCR=0 then '无法计算' else ltrim(str((isnull(#fee.OTMONTHCR,0)+isnull(#fee.MONTH1CR,0)+isnull(#fee.MONTH2CR,0)+isnull(#fee.MONTH3CR,0))/#bill.TTLCR*100,10,2))+'%' end) as TTLMONTHCRATS, ");
strSql.Append(" #bill.TTLDR ");
strSql.Append("from #bill CROSS JOIN #fee ");
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<CustomDbParamter>();
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 ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modZjTotalreportRange' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
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"]);
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 + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(B.Corpid)='" + companyid + "'";
}
return str;
}
/// <summary>
/// 资金占用情况 泰邦
/// </summary>
/// <returns></returns>
public ActionResult ZJZY_TBIndex()
{
return View();
}
public ContentResult GetTBDataList(int start, int limit, string condition, string sort, string printstr, string sortstr)
{
var dataList = MsRptZjTotalDAL.GetTBDataList(condition, start, limit, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
//var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
#region 参照部分
#endregion
}
}