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.

742 lines
42 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Services;
using DSWeb.Areas.CommMng.Models;
using DSWeb.EntityDA;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Models.MonthDataSet;
using DSWebMobileService.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Newtonsoft.Json;
namespace DSWebMobileService
{
/// <summary>
/// MsRptNoTotalMonth 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class MsRptNoTotalMonth : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public static ContentResult SaleListData(string dType, int start, int limit, string condition, string sort, string printstr, string sortstr, string beginfrom, string beginto, string accfrom, string accto, string startmonth, string endmonth)
{
int iCount = 0;
var strDa = GetRangDAStr("index", Convert.ToString(SessionUtil.Session["USERID"]), Convert.ToString(SessionUtil.Session["SHOWNAME"]), Convert.ToString(SessionUtil.Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var monthlist = GetMonthList(startmonth, endmonth);
List<MonthDataSet> beginMonthList = new List<MonthDataSet>();
List<MonthDataSet> accMonthList = new List<MonthDataSet>(); //= GetMonthList(accfrom, accto);
string[] beginMonthArr = { };// new string[beginMonthList.Count];
string[] accMonthArr = { };
int monthNUM = 0;
if (beginfrom != "")
{
if (beginto == "") { beginto = DateTime.Today.Year.ToString() + "-" + DateTime.Today.Month.ToString() + "-" + DateTime.Today.Day.ToString(); }
beginMonthList = GetMonthList(beginfrom, beginto);
beginMonthArr = new string[beginMonthList.Count];
monthNUM = 0;
foreach (var beginMonth in beginMonthList)
{
beginMonthArr[monthNUM] = beginMonth.MONTHFIELDNAME;
monthNUM++;
}
}
if (accfrom != "")
{
if (accto == "") { accto = DateTime.Today.Year.ToString() + "-" + DateTime.Today.Month.ToString() + "-" + DateTime.Today.Day.ToString(); }
accMonthList = GetMonthList(accfrom, accto);
accMonthArr = new string[accMonthList.Count];
monthNUM = 0;
foreach (var accMonth in accMonthList)
{
accMonthArr[monthNUM] = accMonth.MONTHFIELDNAME;
monthNUM++;
}
}
var strSql = new StringBuilder();
foreach (var enumValue in monthlist)
{
if (iCount > 0)
{
strSql.AppendLine("union all");
}
strSql.AppendLine("SELECT B.SALE,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) as OPDATE");
strSql.AppendLine(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZLUSD ");
strSql.AppendLine(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZLRMB ");
strSql.AppendLine(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZLTTL ");
strSql.AppendLine(" FROM CH_FEE F ");
strSql.AppendLine("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
if (beginMonthArr.Length > 0)
{
if (iCount < beginMonthArr.Length)
{
if (beginMonthArr[iCount].Substring(5, 2) == "01" || beginMonthArr[iCount].Substring(5, 2) == "03" || beginMonthArr[iCount].Substring(5, 2) == "05" || beginMonthArr[iCount].Substring(5, 2) == "07" || beginMonthArr[iCount].Substring(5, 2) == "08" || beginMonthArr[iCount].Substring(5, 2) == "10" || beginMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[iCount] + "/01 00:00:00' and B.OPDATE<='" + beginMonthArr[iCount] + "/31 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "04" || beginMonthArr[iCount].Substring(5, 2) == "06" || beginMonthArr[iCount].Substring(5, 2) == "09" || beginMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[iCount] + "/01 00:00:00' and B.OPDATE<='" + beginMonthArr[iCount] + "/30 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[iCount] + "/01 00:00:00' and B.OPDATE<='" + beginMonthArr[iCount] + "/29 23:59:59' ");
}
}
else
{
if (beginMonthArr[iCount].Substring(5, 2) == "01" || beginMonthArr[iCount].Substring(5, 2) == "03" || beginMonthArr[iCount].Substring(5, 2) == "05" || beginMonthArr[iCount].Substring(5, 2) == "07" || beginMonthArr[iCount].Substring(5, 2) == "08" || beginMonthArr[iCount].Substring(5, 2) == "10" || beginMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "04" || beginMonthArr[iCount].Substring(5, 2) == "06" || beginMonthArr[iCount].Substring(5, 2) == "09" || beginMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
}
}
if (accMonthArr.Length > 0)
{
if (iCount < accMonthArr.Length)
{
if (accMonthArr[iCount].Substring(5, 2) == "01" || accMonthArr[iCount].Substring(5, 2) == "03" || accMonthArr[iCount].Substring(5, 2) == "05" || accMonthArr[iCount].Substring(5, 2) == "07" || accMonthArr[iCount].Substring(5, 2) == "08" || accMonthArr[iCount].Substring(5, 2) == "10" || accMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine(" and B.ACCDATE>='" + accMonthArr[iCount] + " 00:00:00' and B.ACCDATE<='" + accMonthArr[iCount] + " 23:59:59'");
}
else if (accMonthArr[iCount].Substring(5, 2) == "04" || accMonthArr[iCount].Substring(5, 2) == "06" || accMonthArr[iCount].Substring(5, 2) == "09" || accMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
}
else
{
if (accMonthArr[iCount].Substring(5, 2) == "01" || accMonthArr[iCount].Substring(5, 2) == "03" || accMonthArr[iCount].Substring(5, 2) == "05" || accMonthArr[iCount].Substring(5, 2) == "07" || accMonthArr[iCount].Substring(5, 2) == "08" || accMonthArr[iCount].Substring(5, 2) == "10" || accMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine(" and B.ACCDATE>='" + accMonthArr[accMonthArr.Length - 1] + " 00:00:00' and B.ACCDATE<='" + accMonthArr[accMonthArr.Length - 1] + " 23:59:59'");
}
else if (accMonthArr[iCount].Substring(5, 2) == "04" || accMonthArr[iCount].Substring(5, 2) == "06" || accMonthArr[iCount].Substring(5, 2) == "09" || accMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
}
}
// and F.FEETYPE=2 and F.AMOUNT<>F.SETTLEMENT and (F.FEESTATUS=0 or F.FEESTATUS=8 or F.FEESTATUS=9)应付
if (dType == "1")
{
strSql.AppendLine(" and F.FEETYPE=1 and F.AMOUNT<>F.SETTLEMENT and (F.FEESTATUS=0 or F.FEESTATUS=8 or F.FEESTATUS=9) ");//应收
}
else
{
strSql.AppendLine(" and F.FEETYPE=2 and F.AMOUNT<>F.SETTLEMENT and (F.FEESTATUS=0 or F.FEESTATUS=8 or F.FEESTATUS=9) ");//应付
}
if (!string.IsNullOrEmpty(condition))
{
strSql.AppendLine(" and " + condition);
}
strSql.AppendLine(" Group by B.SALE,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) ");
iCount++;
}
List<SaleModule> saleInquData = SetSaleData(strSql);
string jsonStr = "";
foreach (SaleModule data in saleInquData)
{
jsonStr += "{";
jsonStr += "\"SALE\":\"" + data.Sale + "\",\"OPDATE\":\"" + data.OPDate + "\",\"ZLRMB\":\"" + data.ZLRmb + "\",\"ZLUSD\":\"" + data.ZLUsd + "\",\"ZLTTL\":\"" + data.ZLTtl + "\"";
jsonStr += "},";
}
if (jsonStr.Length > 0)
{
jsonStr = jsonStr.Substring(0, jsonStr.Length - 1);
}
string result = "[" + jsonStr + "]";
return new ContentResult() { Content = result };
//}
}
private static List<SaleModule> SetSaleData(StringBuilder sql)
{
var bodyList = new List<SaleModule>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql.ToString()))
{
while (reader.Read())
{
SaleModule data = new SaleModule();
#region Set DB data to Object
data.Sale = Convert.ToString(reader["SALE"]);
data.OPDate = Convert.ToString(reader["OPDATE"]);
data.ZLUsd = Convert.ToString(reader["ZLUSD"]);
data.ZLRmb = Convert.ToString(reader["ZLRMB"]);
data.ZLTtl = Convert.ToString(reader["ZLTTL"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
[WebMethod]
public static ContentResult CustListData(string dType, int start, int limit, string condition, string sort, string printstr, string sortstr, string beginfrom, string beginto, string accfrom, string accto, string startmonth, string endmonth)
{
int iCount = 0;
var strDa = GetRangDAStr("index", Convert.ToString(SessionUtil.Session["USERID"]), Convert.ToString(SessionUtil.Session["SHOWNAME"]), Convert.ToString(SessionUtil.Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var monthlist = GetMonthList(startmonth, endmonth);
//var beginMonthList = GetMonthList(beginfrom, beginto);
List<MonthDataSet> beginMonthList = new List<MonthDataSet>();
List<MonthDataSet> accMonthList=new List<MonthDataSet>(); //= GetMonthList(accfrom, accto);
string[] beginMonthArr = { };// new string[beginMonthList.Count];
string[] accMonthArr = { };
int monthNUM = 0;
if (beginfrom != "")
{
if (beginto == "") { beginto = DateTime.Today.Year.ToString() + "-" + DateTime.Today.Month.ToString() + "-" + DateTime.Today.Day.ToString(); }
beginMonthList = GetMonthList(beginfrom, beginto);
beginMonthArr = new string[beginMonthList.Count];
monthNUM = 0;
foreach (var beginMonth in beginMonthList)
{
beginMonthArr[monthNUM] = beginMonth.MONTHFIELDNAME;
monthNUM++;
}
}
if (accfrom != "")
{
if (accto == "") { accto = DateTime.Today.Year.ToString() + "-" + DateTime.Today.Month.ToString() + "-" + DateTime.Today.Day.ToString(); }
accMonthList = GetMonthList(accfrom, accto);
accMonthArr = new string[accMonthList.Count];
monthNUM = 0;
foreach (var accMonth in accMonthList)
{
accMonthArr[monthNUM] = accMonth.MONTHFIELDNAME;
monthNUM++;
}
}
var strSql = new StringBuilder();
foreach (var enumValue in monthlist)
{
if (iCount > 0)
{
strSql.AppendLine("union all");
}
strSql.AppendLine("SELECT F.CUSTOMERNAME AS CUSTNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) as OPDATE ");
//strSql.AppendLine(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.AppendLine(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZLUSD ");
strSql.AppendLine(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZLRMB ");
strSql.AppendLine(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZLTTL ");
strSql.AppendLine(" FROM CH_FEE F ");
strSql.AppendLine("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
//strSql.AppendLine(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
if (beginMonthArr.Length > 0)
{
if (iCount < beginMonthArr.Length)
{
if (beginMonthArr[iCount].Substring(5, 2) == "01" || beginMonthArr[iCount].Substring(5, 2) == "03" || beginMonthArr[iCount].Substring(5, 2) == "05" || beginMonthArr[iCount].Substring(5, 2) == "07" || beginMonthArr[iCount].Substring(5, 2) == "08" || beginMonthArr[iCount].Substring(5, 2) == "10" || beginMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[iCount] + "/01 00:00:00' and B.OPDATE<='" + beginMonthArr[iCount] + "/31 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "04" || beginMonthArr[iCount].Substring(5, 2) == "06" || beginMonthArr[iCount].Substring(5, 2) == "09" || beginMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[iCount] + "/01 00:00:00' and B.OPDATE<='" + beginMonthArr[iCount] + "/30 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[iCount] + "/01 00:00:00' and B.OPDATE<='" + beginMonthArr[iCount] + "/29 23:59:59' ");
}
}
else {
if (beginMonthArr[iCount].Substring(5, 2) == "01" || beginMonthArr[iCount].Substring(5, 2) == "03" || beginMonthArr[iCount].Substring(5, 2) == "05" || beginMonthArr[iCount].Substring(5, 2) == "07" || beginMonthArr[iCount].Substring(5, 2) == "08" || beginMonthArr[iCount].Substring(5, 2) == "10" || beginMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "04" || beginMonthArr[iCount].Substring(5, 2) == "06" || beginMonthArr[iCount].Substring(5, 2) == "09" || beginMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
}
}
if (accMonthArr.Length > 0)
{
if (iCount < accMonthArr.Length)
{
if (accMonthArr[iCount].Substring(5, 2) == "01" || accMonthArr[iCount].Substring(5, 2) == "03" || accMonthArr[iCount].Substring(5, 2) == "05" || accMonthArr[iCount].Substring(5, 2) == "07" || accMonthArr[iCount].Substring(5, 2) == "08" || accMonthArr[iCount].Substring(5, 2) == "10" || accMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine(" and B.ACCDATE>='" + accMonthArr[iCount] + " 00:00:00' and B.ACCDATE<='" + accMonthArr[iCount] + " 23:59:59'");
}
else if (accMonthArr[iCount].Substring(5, 2) == "04" || accMonthArr[iCount].Substring(5, 2) == "06" || accMonthArr[iCount].Substring(5, 2) == "09" || accMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
}
else
{
if (accMonthArr[iCount].Substring(5, 2) == "01" || accMonthArr[iCount].Substring(5, 2) == "03" || accMonthArr[iCount].Substring(5, 2) == "05" || accMonthArr[iCount].Substring(5, 2) == "07" || accMonthArr[iCount].Substring(5, 2) == "08" || accMonthArr[iCount].Substring(5, 2) == "10" || accMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine(" and B.ACCDATE>='" + accMonthArr[accMonthArr.Length - 1] + " 00:00:00' and B.ACCDATE<='" + accMonthArr[accMonthArr.Length - 1] + " 23:59:59'");
}
else if (accMonthArr[iCount].Substring(5, 2) == "04" || accMonthArr[iCount].Substring(5, 2) == "06" || accMonthArr[iCount].Substring(5, 2) == "09" || accMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
}
}
// and F.FEETYPE=2 and F.AMOUNT<>F.SETTLEMENT and (F.FEESTATUS=0 or F.FEESTATUS=8 or F.FEESTATUS=9)应付
if (dType == "1")
{
strSql.AppendLine(" and F.FEETYPE=1 and F.AMOUNT<>F.SETTLEMENT and (F.FEESTATUS=0 or F.FEESTATUS=8 or F.FEESTATUS=9) ");//应收
}
else
{
strSql.AppendLine(" and F.FEETYPE=2 and F.AMOUNT<>F.SETTLEMENT and (F.FEESTATUS=0 or F.FEESTATUS=8 or F.FEESTATUS=9) ");//应付
}
if (!string.IsNullOrEmpty(condition))
{
strSql.AppendLine(" and " + condition);
}
strSql.AppendLine(" Group by F.CUSTOMERNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) ");
iCount++;
}
List<CustModulle> custInquData = SetCustData(strSql);
string jsonStr = "";
foreach (CustModulle data in custInquData)
{
jsonStr += "{";
jsonStr += "\"CUSTNAME\":\"" + data.CustName + "\",\"OPDATE\":\"" + data.OPDate + "\",\"ZLRMB\":\"" + data.ZLRmb + "\",\"ZLUSD\":\"" + data.ZLUsd + "\",\"ZLTTL\":\"" + data.ZLTtl + "\"";
jsonStr += "},";
}
if (jsonStr.Length > 0)
{
jsonStr = jsonStr.Substring(0, jsonStr.Length - 1);
}
string result = "[" + jsonStr + "]";
return new ContentResult() { Content = result };
}
private static List<CustModulle> SetCustData(StringBuilder sql)
{
var bodyList = new List<CustModulle>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql.ToString()))
{
while (reader.Read())
{
CustModulle data = new CustModulle();
#region Set DB data to Object
data.CustName = Convert.ToString(reader["CUSTNAME"]);
data.OPDate = Convert.ToString(reader["OPDATE"]);
data.ZLUsd = Convert.ToString(reader["ZLUSD"]);
data.ZLRmb = Convert.ToString(reader["ZLRMB"]);
data.ZLTtl = Convert.ToString(reader["ZLTTL"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
[WebMethod]
public static ContentResult SaleCustListData(string dType, int start, int limit, string condition, string sort, string printstr, string sortstr, string beginfrom, string beginto, string accfrom, string accto, string startmonth, string endmonth)
{
int iCount = 0;
var strDa = GetRangDAStr("index", Convert.ToString(SessionUtil.Session["USERID"]), Convert.ToString(SessionUtil.Session["SHOWNAME"]), Convert.ToString(SessionUtil.Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var monthlist = GetMonthList(startmonth, endmonth);
List<MonthDataSet> beginMonthList = new List<MonthDataSet>();
List<MonthDataSet> accMonthList = new List<MonthDataSet>(); //= GetMonthList(accfrom, accto);
string[] beginMonthArr = { };// new string[beginMonthList.Count];
string[] accMonthArr = { };
int monthNUM = 0;
if (beginfrom != "")
{
if (beginto == "") { beginto = DateTime.Today.Year.ToString() + "-" + DateTime.Today.Month.ToString() + "-" + DateTime.Today.Day.ToString(); }
beginMonthList = GetMonthList(beginfrom, beginto);
beginMonthArr = new string[beginMonthList.Count];
monthNUM = 0;
foreach (var beginMonth in beginMonthList)
{
beginMonthArr[monthNUM] = beginMonth.MONTHFIELDNAME;
monthNUM++;
}
}
if (accfrom != "")
{
if (accto == "") { accto = DateTime.Today.Year.ToString() + "-" + DateTime.Today.Month.ToString() + "-" + DateTime.Today.Day.ToString(); }
accMonthList = GetMonthList(accfrom, accto);
accMonthArr = new string[accMonthList.Count];
monthNUM = 0;
foreach (var accMonth in accMonthList)
{
accMonthArr[monthNUM] = accMonth.MONTHFIELDNAME;
monthNUM++;
}
}
var strSql = new StringBuilder();
foreach (var enumValue in monthlist)
{
if (iCount > 0)
{
strSql.AppendLine("union all");
}
strSql.AppendLine("SELECT B.SALE,F.CUSTOMERNAME AS CUSTNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) as OPDATE ");
//strSql.AppendLine(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.AppendLine(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZLUSD ");
strSql.AppendLine(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZLRMB ");
strSql.AppendLine(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then cast(round(ISNULL((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2)) end) as ZLTTL ");
/*strSql.AppendLine(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD ");
strSql.AppendLine(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB ");
strSql.AppendLine(",sum(cast(round(isnull((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE,0),2) as numeric(20,2))) as ZLTTLTTL ");*/
strSql.AppendLine(" FROM CH_FEE F ");
strSql.AppendLine("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
//strSql.AppendLine(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
if (beginMonthArr.Length > 0)
{
if (iCount < beginMonthArr.Length)
{
if (beginMonthArr[iCount].Substring(5, 2) == "01" || beginMonthArr[iCount].Substring(5, 2) == "03" || beginMonthArr[iCount].Substring(5, 2) == "05" || beginMonthArr[iCount].Substring(5, 2) == "07" || beginMonthArr[iCount].Substring(5, 2) == "08" || beginMonthArr[iCount].Substring(5, 2) == "10" || beginMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[iCount] + "/01 00:00:00' and B.OPDATE<='" + beginMonthArr[iCount] + "/31 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "04" || beginMonthArr[iCount].Substring(5, 2) == "06" || beginMonthArr[iCount].Substring(5, 2) == "09" || beginMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[iCount] + "/01 00:00:00' and B.OPDATE<='" + beginMonthArr[iCount] + "/30 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[iCount] + "/01 00:00:00' and B.OPDATE<='" + beginMonthArr[iCount] + "/29 23:59:59' ");
}
}
else
{
if (beginMonthArr[iCount].Substring(5, 2) == "01" || beginMonthArr[iCount].Substring(5, 2) == "03" || beginMonthArr[iCount].Substring(5, 2) == "05" || beginMonthArr[iCount].Substring(5, 2) == "07" || beginMonthArr[iCount].Substring(5, 2) == "08" || beginMonthArr[iCount].Substring(5, 2) == "10" || beginMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "04" || beginMonthArr[iCount].Substring(5, 2) == "06" || beginMonthArr[iCount].Substring(5, 2) == "09" || beginMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
}
}
if (accMonthArr.Length > 0)
{
if (iCount < accMonthArr.Length)
{
if (accMonthArr[iCount].Substring(5, 2) == "01" || accMonthArr[iCount].Substring(5, 2) == "03" || accMonthArr[iCount].Substring(5, 2) == "05" || accMonthArr[iCount].Substring(5, 2) == "07" || accMonthArr[iCount].Substring(5, 2) == "08" || accMonthArr[iCount].Substring(5, 2) == "10" || accMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine(" and B.ACCDATE>='" + accMonthArr[iCount] + " 00:00:00' and B.ACCDATE<='" + accMonthArr[iCount] + " 23:59:59'");
}
else if (accMonthArr[iCount].Substring(5, 2) == "04" || accMonthArr[iCount].Substring(5, 2) == "06" || accMonthArr[iCount].Substring(5, 2) == "09" || accMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
}
else
{
if (accMonthArr[iCount].Substring(5, 2) == "01" || accMonthArr[iCount].Substring(5, 2) == "03" || accMonthArr[iCount].Substring(5, 2) == "05" || accMonthArr[iCount].Substring(5, 2) == "07" || accMonthArr[iCount].Substring(5, 2) == "08" || accMonthArr[iCount].Substring(5, 2) == "10" || accMonthArr[iCount].Substring(5, 2) == "12")
{
strSql.AppendLine(" and B.ACCDATE>='" + accMonthArr[accMonthArr.Length - 1] + " 00:00:00' and B.ACCDATE<='" + accMonthArr[accMonthArr.Length - 1] + " 23:59:59'");
}
else if (accMonthArr[iCount].Substring(5, 2) == "04" || accMonthArr[iCount].Substring(5, 2) == "06" || accMonthArr[iCount].Substring(5, 2) == "09" || accMonthArr[iCount].Substring(5, 2) == "11")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
else if (beginMonthArr[iCount].Substring(5, 2) == "02")
{
strSql.AppendLine("where B.OPDATE>='" + beginMonthArr[beginMonthArr.Length - 1] + " 00:00:00' and B.OPDATE<='" + beginMonthArr[beginMonthArr.Length - 1] + " 23:59:59' ");
}
}
}
// and F.FEETYPE=2 and F.AMOUNT<>F.SETTLEMENT and (F.FEESTATUS=0 or F.FEESTATUS=8 or F.FEESTATUS=9)应付
if (dType == "1")
{
strSql.AppendLine(" and F.FEETYPE=1 and F.AMOUNT<>F.SETTLEMENT and (F.FEESTATUS=0 or F.FEESTATUS=8 or F.FEESTATUS=9) ");//应收
}
else
{
strSql.AppendLine(" and F.FEETYPE=2 and F.AMOUNT<>F.SETTLEMENT and (F.FEESTATUS=0 or F.FEESTATUS=8 or F.FEESTATUS=9) ");//应付
}
if (!string.IsNullOrEmpty(condition))
{
strSql.AppendLine(" and " + condition);
}
strSql.AppendLine(" Group by B.SALE,F.CUSTOMERNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) ");
iCount++;
}
List<SaleCustModule> saleCustInquData = SetSaleCustData(strSql);
string jsonStr = "";
foreach (SaleCustModule data in saleCustInquData)
{
jsonStr += "{";
jsonStr += "\"SALE\":\"" + data.Sale + "\",\"CUSTNAME\":\"" + data.CustName + "\",\"OPDATE\":\"" + data.OPDate + "\",\"ZLRMB\":\"" + data.ZLRmb + "\",\"ZLUSD\":\"" + data.ZLUsd + "\",\"ZLTTL\":\"" + data.ZLTtl + "\"";
jsonStr += "},";
}
if (jsonStr.Length > 0)
{
jsonStr = jsonStr.Substring(0, jsonStr.Length - 1);
}
string result = "[" + jsonStr + "]";
return new ContentResult() { Content = result };
}
private static List<SaleCustModule> SetSaleCustData(StringBuilder sql)
{
var bodyList = new List<SaleCustModule>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql.ToString()))
{
while (reader.Read())
{
SaleCustModule data = new SaleCustModule();
#region Set DB data to Object
data.Sale = Convert.ToString(reader["SALE"]);
data.CustName = Convert.ToString(reader["CUSTNAME"]);
data.OPDate = Convert.ToString(reader["OPDATE"]);
data.ZLUsd = Convert.ToString(reader["ZLUSD"]);
data.ZLRmb = Convert.ToString(reader["ZLRMB"]);
data.ZLTtl = Convert.ToString(reader["ZLTTL"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
private static List<MonthDataSet> GetMonthList(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;
DateTime dt = DateTime.ParseExact(startmonth, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture);
var evList = new List<MonthDataSet>();
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;
evData.MONTHFIELDNAME = dt.Year.ToString() + "/" + month;
evList.Add(evData);
dt = dt.AddMonths(1);
}
return evList;
}
private static string GetRangDAStr(string tb, string userid, string usercode, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.AppendLine("SELECT ");
strSql.AppendLine(" VISIBLERANGE,OPERATERANGE ");
strSql.AppendLine(" from VW_User_Authority ");
strSql.AppendLine(" where [NAME]='modNoTotalMonthRange' 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;
}
}
}