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/Import/Controllers/RptImportFeedetailControlle...

214 lines
12 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 DSWeb.Areas.Import.Models.RptImportFeedetail;
using DSWeb.TruckMng.Helper;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.CommMng.Models;
using System.Data.SqlClient;
namespace DSWeb.Areas.Import.Controllers
{
/// <summary>
/// 应收应付明细
/// </summary>
public class RptImportFeedetailController : Controller
{
//
// GET: /Import/RptImportFeedetail/
public ActionResult Index()
{
return View();
}
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
if (string.IsNullOrEmpty(condition))
{
condition += " 1=1 ";
}
var corpid = Convert.ToString(Session["COMPANYID"]);
var USERID = Convert.ToString(Session["USERID"]);
var DEPTGID = Convert.ToString(Session["DEPTGID"]);
//var OPERATERANGE="";
var VISIBLERANGE = "";
var modName = "modImport_Fee";
var evList = BasicDataRefDAL.GetAR(modName, USERID);
AuthorityRangemb head = null;
if (evList.Count > 0)
head = evList[0];
if (head == null)
{
head = new AuthorityRangemb();
//OPERATERANGE = "3";
VISIBLERANGE = "3";
}
else
{
//OPERATERANGE = head.OPERATERANGE;
VISIBLERANGE = head.VISIBLERANGE;
}
if (VISIBLERANGE == "1")
{
condition = condition + " and f.enteroperator in(select userid from user_company where companyid='" + corpid + "')";
}
if (VISIBLERANGE == "2")
{
condition = condition + " and f.enteroperator in(select userid from user_baseinfo where companyname=(select name from company where gid='" + corpid + "') ";
condition = condition + " and deptname=(select deptname from sys_dept where gid='" + DEPTGID + "')) ";
}
if (VISIBLERANGE == "3")
{
condition = condition + " and f.enteroperator ='" + USERID + "'";
}
var dataList = GetDataList(condition);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
/*create view v_chfee as
SELECT f.GId,f.BsNo,f.FeeStatus, (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=f.FeeStatus) as FeeStatus_Ref,
(select NAME from vMsTruckFeeType where NAME=f.FeeName) as FeeName_Ref,
(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref
,f.FeeDescription,f.enterdate,f.CustomerName as CustomerName_Ref,f.Unit,f.UnitPrice,f.Quantity,
case f.feetype when 1 then f.Amount else 0 end amount_ys, case f.feetype when 1 then 0 else f.Amount end amount_yf,
case f.feetype when 1 then f.Amount*f.exchangerate else 0 end amount_rmbys, case f.feetype when 1 then 0 else f.Amount*f.exchangerate end amount_rmbyf,
f.Currency,f.ExChangerate ,f.Remark,m.ContractNo,m.HTH,m.seller,m.buyer,m.Billno,m.Vessel,m.Voyage,dbo.trimdate(m.Sailingdate) Sailingdate
,dbo.trimdate(m.ArrivalDate) ArrivalDate,m.ContainerNo,m.SealNo,dbo.trimdate(m.creattime) creattime,m.Id
,(select showname from [user] where gid=f.enteroperator) createuser, f.SETTLEMENT,(f.Amount-f.SETTLEMENT) as remain,
--dbo.f_danhao(f.gid,4) [AC_AD],
--dbo.f_danhao(f.gid,1) CR1, --dbo.f_danhao(f.gid,2) CR2,dbo.f_danhao(f.gid,8) CR8,dbo.f_danhao(f.gid,9) CR9 ,
f.ACCDATE,f.ISVOU,f.VOUCHERNO,f.AUDITDATE,(select showname from [user] where gid=f.auditoperator) auditoperator
,dbo.f_VOUNO(f.gid) VOUNO
from ch_fee f left join Import_main m on (f.bsno=m.ContractNo)
where m.id is not null */
private static List<RptImportFeedetail> GetDataList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(" select * into #T1 from( SELECT f.GId,f.BsNo,f.FeeStatus, ");
strSql.Append(" (select top 1 EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=f.FeeStatus) as FeeStatus_Ref, ");
strSql.Append(" (select top 1 NAME from vMsTruckFeeType where NAME=f.FeeName) as FeeName_Ref, ");
strSql.Append(" (select top 1 EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref ");
strSql.Append(" ,f.FeeDescription,f.enterdate,f.CustomerName as CustomerName_Ref,f.Unit,f.UnitPrice,f.Quantity, case f.feetype when 1 then f.Amount else 0 end amount_ys, ");
strSql.Append(" case f.feetype when 1 then 0 else f.Amount end amount_yf, case f.feetype when 1 then f.Amount*f.exchangerate else 0 end amount_rmbys, ");
strSql.Append(" case f.feetype when 1 then 0 else f.Amount*f.exchangerate end amount_rmbyf, f.Currency,f.ExChangerate ");
strSql.Append(" ,f.Remark,m.ContractNo,m.CUSTNO HTH,(select top 1 seller from import_main where CONTRACTNO=m.BSNO) seller ");
strSql.Append(" ,m.CUSTOMERNAME buyer,m.MBLNO Billno,m.Vessel,m.VOYNO Voyage,(select top 1 dbo.trimdate(Sailingdate) from import_main where CONTRACTNO=m.BSNO) Sailingdate ");
strSql.Append(" ,dbo.trimdate(m.ETD) ArrivalDate,(select top 1 ContainerNo from import_main where CONTRACTNO=m.BSNO) ContainerNo ");
strSql.Append(" ,(select top 1 SealNo from import_main where CONTRACTNO=m.BSNO) SealNo,dbo.trimdate(m.CREATETIME) creattime ");
strSql.Append(" ,(select top 1 showname from [user] where gid=f.enteroperator) createuser, case f.feetype when 1 then f.SETTLEMENT else 0 end SETTLEMENT_ys, ");
strSql.Append(" case f.feetype when 1 then 0 else f.SETTLEMENT end SETTLEMENT_yf, case f.feetype when 1 then (f.Amount-f.SETTLEMENT)*f.exchangerate else 0-(f.Amount-f.SETTLEMENT)*f.exchangerate end remain, ");
strSql.Append(" case f.feetype when 1 then dbo.f_danhao(f.gid,5) else dbo.f_danhao(f.gid,4) end [AC_AD], dbo.f_danhao(f.gid,1) [CR_DR], debitno,dbo.f_danhao(f.gid,6) [Inv], ");
strSql.Append(" f.ACCDATE,f.ISVOU,f.VOUCHERNO,f.AUDITDATE,(select top 1 showname from [user] where gid=f.auditoperator) auditoperator ,dbo.f_VOUNO(f.gid) VOUNO,dbo.f_str(f.bsno) cargoname ");
strSql.Append(" ,(select top 1 name from company c where c.gid=m.CORPID) company ,m.op ");
strSql.Append(" from ch_fee f ");
strSql.Append(" left join v_op_bs m on (f.bsno=m.bsno) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" )tt ");
strSql.Append(" select * from #T1 ");
strSql.Append(" union all ");
strSql.Append(" select '','zzzzzzzz',0,'','','','','','','',0,0,sum(amount_ys),sum(amount_yf),sum(amount_rmbys),sum(amount_rmbyf), ");
strSql.Append(" '',0,'','','','','','','','','','','','','','',sum(SETTLEMENT_ys),sum(SETTLEMENT_yf),sum(remain),'','','','','','','','','','','','','' from #T1 order by bsno,FeeType_Ref,FeeName_Ref, ");
strSql.Append(" customername_Ref,enterdate "); //0
strSql.Append(" drop table #T1 ");
return SetData(strSql);
}
private static List<RptImportFeedetail> SetData(StringBuilder strSql)
{
var headList = new List<RptImportFeedetail>();
Database db = DatabaseFactory.CreateDatabase();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 120000; //要加这一句
using (IDataReader reader = db.ExecuteReader(cmd))
{
while (reader.Read())
{
var data = new RptImportFeedetail();
#region Set DB data to Object
data.GId = Convert.ToString(reader["GId"]);
data.Billno = Convert.ToString(reader["BillNo"]);
data.ContractNo = Convert.ToString(reader["ContractNo"]);
data.HTH = Convert.ToString(reader["HTH"]);
data.creattime = Convert.ToString(reader["creattime"]);
data.seller = Convert.ToString(reader["seller"]);
data.buyer = Convert.ToString(reader["buyer"]);
data.Vessel = Convert.ToString(reader["Vessel"]);
data.Voyage = Convert.ToString(reader["Voyage"]);
data.Sailingdate = Convert.ToString(reader["Sailingdate"]);
data.ArrivalDate = Convert.ToString(reader["ArrivalDate"]);
data.ContainerNo = Convert.ToString(reader["ContainerNo"]);
data.SealNo = Convert.ToString(reader["SealNo"]);
data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]);
data.FeeStatus = Convert.ToString(reader["FeeStatus"]);
data.FeeStatus_Ref = Convert.ToString(reader["FeeStatus_Ref"]);
data.FeeName_Ref = Convert.ToString(reader["FeeName_Ref"]);
data.FeeDescription = Convert.ToString(reader["FeeDescription"]);
data.CustomerName_Ref = Convert.ToString(reader["CustomerName_Ref"]);
data.Unit = Convert.ToString(reader["Unit"]);
data.Currency = Convert.ToString(reader["Currency"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.UnitPrice = Convert.ToDecimal(reader["UnitPrice"]);
data.Quantity = Convert.ToDecimal(reader["Quantity"]);
data.Amount_YS = Convert.ToString(reader["Amount_YS"]);
data.Amount_YF = Convert.ToString(reader["Amount_YF"]);
data.Amount_RMBYS = Convert.ToString(reader["Amount_RMBYS"]);
data.Amount_RMBYF = Convert.ToString(reader["Amount_RMBYF"]);
data.ExChangerate = Convert.ToString(reader["ExChangerate"]);
data.EnterDate = Convert.ToString(reader["EnterDate"]);
data.CreateUser = Convert.ToString(reader["CreateUser"]);
data.AC_AD = Convert.ToString(reader["AC_AD"]);
data.CR_DR = Convert.ToString(reader["CR_DR"]);
//data.DR = Convert.ToString(reader["DR"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.ISVOU = Convert.ToString(reader["ISVOU"]);
data.VOUCHERNO = Convert.ToString(reader["VOUCHERNO"]);
data.AUDITOPERATOR = Convert.ToString(reader["AUDITOPERATOR"]);
data.AUDITDATE = Convert.ToString(reader["AUDITDATE"]);
data.VOUNO = Convert.ToString(reader["VOUNO"]);
data.SETTLEMENT_ys = Convert.ToString(reader["SETTLEMENT_ys"]);
data.SETTLEMENT_yf = Convert.ToString(reader["SETTLEMENT_yf"]);
data.REMAIN = Convert.ToString(reader["REMAIN"]);
data.CARGONAME = Convert.ToString(reader["CARGONAME"]);
data.COMPANY = Convert.ToString(reader["COMPANY"]);
data.OP = Convert.ToString(reader["OP"]);
data.DEBITNO = Convert.ToString(reader["DEBITNO"]);
data.INV = Convert.ToString(reader["INV"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
}
}