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 System.IO;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
namespace DSWeb.MvcShipping.Controllers
{
///
/// 欠费月度分析查询
///
[JsonRequestBehavior]
public class MsRptNoTotalMonthController : Controller
{
//
// GET:
public ActionResult Index()
{
return View();
}
//
// GET:/RptMng/MsRptPcHeadQry/QryData
public ActionResult ZlSet()
{
return View();
}
public ContentResult SaleListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string datetype, string startmonth,string endmonth)
{
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 NORPTFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='NORPTFEESTATUS'");
if (NORPTFEESTATUS.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and F.FEESTATUS<>1 ";
}
else
{
condition = " F.FEESTATUS<>1 ";
}
}
var NORMONTHPTFEESTATUSISAUDIT = MsSysParamSetDAL.GetData("PARAMNAME='NORMONTHPTFEESTATUSISAUDIT'");
if (NORMONTHPTFEESTATUSISAUDIT.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
else
{
condition = " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
}
string LAN = Convert.ToString(Session["LANGUAGES"]);
var monthlist = GetMonthList(datetype,startmonth, endmonth,LAN);
var strSql = new StringBuilder();
strSql.Append("SELECT * from (");
strSql.Append("SELECT B.SALE");
foreach (var enumValue in monthlist)
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME+"' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL"+enumValue.MONTHNO.ToString()+"USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL" + enumValue.MONTHNO.ToString() + "TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
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 " + 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
{
strSql.Append(") as v");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by 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 CustListData(int start, int limit, string condition, string sort, string printstr,string sortstr, string datetype, string startmonth,string endmonth)
{
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 NORPTFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='NORPTFEESTATUS'");
if (NORPTFEESTATUS.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and F.FEESTATUS<>1 ";
}
else
{
condition = " F.FEESTATUS<>1 ";
}
}
var NORMONTHPTFEESTATUSISAUDIT = MsSysParamSetDAL.GetData("PARAMNAME='NORMONTHPTFEESTATUSISAUDIT'");
if (NORMONTHPTFEESTATUSISAUDIT.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
else
{
condition = " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
}
string LAN = Convert.ToString(Session["LANGUAGES"]);
var monthlist = GetMonthList(datetype,startmonth, endmonth,LAN);
var strSql = new StringBuilder();
strSql.Append("SELECT F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",isnull(dbo.GetCustZq(F.CUSTOMERNAME),'无账期') AS CUSTZQ ");
foreach (var enumValue in monthlist)
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL" + enumValue.MONTHNO.ToString() + "TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where " + condition);
}
strSql.Append(" Group by F.CUSTOMERNAME,C.[DESCRIPTION] ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by F.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 F.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 DeptListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string datetype, string startmonth, string endmonth)
{
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 NORPTFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='NORPTFEESTATUS'");
if (NORPTFEESTATUS.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and F.FEESTATUS<>1 ";
}
else
{
condition = " F.FEESTATUS<>1 ";
}
}
var NORMONTHPTFEESTATUSISAUDIT = MsSysParamSetDAL.GetData("PARAMNAME='NORMONTHPTFEESTATUSISAUDIT'");
if (NORMONTHPTFEESTATUSISAUDIT.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
else
{
condition = " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
}
string LAN = Convert.ToString(Session["LANGUAGES"]);
var monthlist = GetMonthList(datetype,startmonth, endmonth,LAN);
var strSql = new StringBuilder();
strSql.Append("SELECT B.SALEDEPT ");
foreach (var enumValue in monthlist)
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL" + enumValue.MONTHNO.ToString() + "TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where " + condition);
}
strSql.Append(" Group by B.SALEDEPT ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + 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)
{
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 NORPTFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='NORPTFEESTATUS'");
if (NORPTFEESTATUS.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and F.FEESTATUS<>1 ";
}
else
{
condition = " F.FEESTATUS<>1 ";
}
}
var NORMONTHPTFEESTATUSISAUDIT = MsSysParamSetDAL.GetData("PARAMNAME='NORMONTHPTFEESTATUSISAUDIT'");
if (NORMONTHPTFEESTATUSISAUDIT.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
else
{
condition = " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
}
string LAN = Convert.ToString(Session["LANGUAGES"]);
var monthlist = GetMonthList(datetype,startmonth, endmonth,LAN);
var strSql = new StringBuilder();
strSql.Append("SELECT B.SALE,F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",isnull(dbo.GetCustSaleZq(F.CUSTOMERNAME,B.SALE),'无账期') AS CUSTZQ ");
foreach (var enumValue in monthlist)
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL" + enumValue.MONTHNO.ToString() + "TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where " + condition);
}
strSql.Append(" Group by B.SALE,F.CUSTOMERNAME,C.[DESCRIPTION] ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.SALE,F.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,F.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 OpCustListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string datetype, string startmonth, string endmonth)
{
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 NORPTFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='NORPTFEESTATUS'");
if (NORPTFEESTATUS.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and F.FEESTATUS<>1 ";
}
else
{
condition = " F.FEESTATUS<>1 ";
}
}
var NORMONTHPTFEESTATUSISAUDIT = MsSysParamSetDAL.GetData("PARAMNAME='NORMONTHPTFEESTATUSISAUDIT'");
if (NORMONTHPTFEESTATUSISAUDIT.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
else
{
condition = " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
}
string LAN = Convert.ToString(Session["LANGUAGES"]);
var monthlist = GetMonthList(datetype, startmonth, endmonth,LAN);
var strSql = new StringBuilder();
strSql.Append("SELECT B.OP,F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",isnull(dbo.GetCustZq(F.CUSTOMERNAME),'无账期') AS CUSTZQ ");
foreach (var enumValue in monthlist)
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL" + enumValue.MONTHNO.ToString() + "TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where " + condition);
}
strSql.Append(" Group by B.OP,F.CUSTOMERNAME,C.[DESCRIPTION] ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.OP,F.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.OP,F.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 SumListData(int start, int limit, string condition, string sort, string datetype, string startmonth, string endmonth)
{
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 NORPTFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='NORPTFEESTATUS'");
if (NORPTFEESTATUS.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and F.FEESTATUS<>1 ";
}
else
{
condition = " F.FEESTATUS<>1 ";
}
}
var NORMONTHPTFEESTATUSISAUDIT = MsSysParamSetDAL.GetData("PARAMNAME='NORMONTHPTFEESTATUSISAUDIT'");
if (NORMONTHPTFEESTATUSISAUDIT.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
else
{
condition = " and (F.FEESTATUS=0 OR F.FEESTATUS=8 OR F.FEESTATUS=9) ";
}
}
string LAN = Convert.ToString(Session["LANGUAGES"]);
var monthlist = GetMonthList(datetype,startmonth, endmonth,LAN);
var strSql = new StringBuilder();
strSql.Append("SELECT 1 as NO ");
foreach (var enumValue in monthlist)
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "USD ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "RMB ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case when F.CURRENCY<>'RMB' and F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "OT ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B." + datetype + ", 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZL" + enumValue.MONTHNO.ToString() + "TTL ");
}
strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.Append(",sum(case when F.CURRENCY<>'RMB' AND F.CURRENCY<>'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLOT ");
strSql.Append(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where " + condition);
}
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]='modNoTotalMonthRange' 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)
{
string LAN = Convert.ToString(Session["LANGUAGES"]);
var dataList = GetMonthList(datetype,startmonth, endmonth,LAN);
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 LAN)
{
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();
if (LAN=="en-us")
evData.MONTHNAME = dt.ToString("yyyy_MM");
else
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;
evList.Add(evData);
dt=dt.AddMonths(1);
}
return evList;
}
#endregion
#region 参照部分
#endregion
}
}