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/ImportWMSRptController.cs

360 lines
19 KiB
C#

3 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.Areas.OA.Models.Wms_StockTake;
using DSWeb.Areas.CommMng.Models;
using DSWeb.TruckMng.Helper;
using Microsoft.Practices.EnterpriseLibrary.Data;
namespace DSWeb.Areas.Import.Controllers
{
/// <summary>
/// 应收应付明细
/// </summary>
public class ImportWMSRptController : Controller
{
//
// GET: /Import/RptImportFeedetail/
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = GetDataList(condition,sort);
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 };
}
public ContentResult GetGroupList(int start, int limit, string sort, string condition, string GROUPBY)
{
var dataList = GetGroupList(condition, sort, GROUPBY);
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 };
}
private static List<ImportWMSRptmb> GetDataList ( string strCondition, string sort )
{
var strSql = new StringBuilder();
strSql.Append(" select w.WMSNO,vws.*,(select name from company where gid=vws.corpid) COMPANYNAME ,vs.ETD ");
strSql.Append(" ,vs.mblno,vs.custno,(select substring(country,0,(charindex('(',country)) ) from code_country where countryid=m.countryid) country ");
strSql.Append(" ,c.FactoryNo,m.containerno,( select top 1 costprice_ex from ImportTrade_Cargo where GID=w.Cargo_gid ) costprice_ex ");
strSql.Append(" ,convert(numeric(20,6) , ( select top 1 costprice from ImportTrade_Cargo where GID=w.Cargo_gid ) )costprice ");
strSql.Append(" ,(select top 1 costCargo from ImportTrade_Cargo where gid=c.gid)*w.GOODSRKSL/(case (select sum(GOODSRKSL) from wms where cargo_gid=c.GID) when 0 then 1 else (select sum(GOODSRKSL) from wms where cargo_gid=c.GID) end) WmsInCost ");
strSql.Append(" ,(select top 1 costCargo from ImportTrade_Cargo where gid=c.gid)*w.GOODSRKSL/(case (select sum(GOODSRKSL) from wms where cargo_gid=c.GID) when 0 then 1 else (select sum(GOODSRKSL) from wms where cargo_gid=c.GID) end)*w.GOODSSTOCK/(case w.GOODSRKSL when 0 then 1 else w.GOODSRKSL end) stockCost ");
strSql.Append(" ,dbo.trimdate(c.productiondate_min) productiondate_min,dbo.trimdate(c.productiondate_max) productiondate_max,dbo.trimdate(c.ExpirationDate) ExpirationDate ");
strSql.Append(" ,( select top 1 StoreDays from ImportTrade_Cargo where GID=w.Cargo_gid ) StoreDays ");
strSql.Append(" ,( select top 1 cargoDays from ImportTrade_Cargo where GID=w.Cargo_gid ) cargoDays ,dbo.F_ImportTrade_sealinfo(c.GID) SALEINFO,C.CargoType ");
strSql.Append(" ,dbo.F_PAYCOMPANY(m.contractno) PAYCOMPANY,m.remark_6,m.Inspection_Storage,dbo.trimdate(m.Unsealdate) Unsealdate ");
strSql.Append(" ,isnull((select sum(sale_weight) from ImportTrade_Cargo where GID=c.gid),0) sale_weight ");
strSql.Append(" ,isnull((select sum(sale_boxcount) from ImportTrade_Cargo where GID=c.gid),0) sale_boxcount, ");
strSql.Append(" c.ExpirationDates,m.seller,c.Ename,c.KINDPKGS,m.Buy_OP,m.OP,m.Agent,c.price,c.currid,c.SPECIFICATIONS ");
strSql.Append(" from vw_wms_stocktake vws ");
strSql.Append(" left join v_op_bs vs on vs.BSNO=vws.ASSOCIATEDNO left join wms w on w.gid=vws.NID ");
strSql.Append(" left join import_cargo c on c.gid=w.Cargo_gid ");
strSql.Append(" left join import_main m on m.contractno=vs.BSNO ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
return SetData(strSql);
}
private static List<ImportWMSRptmb> GetGroupList ( string strCondition, string sort, string GROUPBY )
//CUSTOMERNAME,goodsname,chargeunit
//CUSTOMERNAME,goodsname,chargeunit
{
var strSql = new StringBuilder();
var searchField = "";
var GROUPField = "";
if (GROUPBY == "Customer") {
searchField = "CUSTOMERNAME,goodsname,chargeunit";
GROUPField = "CUSTOMERNAME,goodsname,chargeunit";
}
if (GROUPBY == "Company")
{
searchField = "(select name from company where gid=corpid) companyname,goodsname,chargeunit";
GROUPField = "corpid,goodsname,chargeunit";
}
strSql.Append(" select " + searchField);
strSql.Append(" ,sum(hj_GOODSRKSL) hj_GOODSRKSL,sum(hj_GOODSPFSL_OUT) hj_GOODSPFSL_OUT ");
strSql.Append(" ,sum(hj_GOODSstock) hj_GOODSstock,sum(hj_GOODSPACK) hj_GOODSPACK ");
strSql.Append(" ,sum(hj_GOODSPACKPFSL) hj_GOODSPACKPFSL,sum(hj_GOODSpackstock) hj_GOODSpackstock ");
strSql.Append(" ,sum(costprice*hj_goodsstock*1000) STOCKCOST,sum(costprice*hj_goodsstock)/(case sum(hj_goodsstock) when 0 then 1 else sum(hj_goodsstock) end) COSTPRICE ");
strSql.Append(" from ");
strSql.Append(" (select vws.* , vs.ETD ,tc.costprice ");
strSql.Append(" from vw_wms_stocktake vws ");
strSql.Append(" left join v_op_bs vs on vs.mblno=vws.blno ");
strSql.Append(" left join wms w on w.gid=vws.NID ");
strSql.Append(" left join ImportTrade_Cargo tc on tc.GID=w.Cargo_gid ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" )t1 ");
strSql.Append(" group by " + GROUPField);
strSql.Append(" ");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
if (GROUPBY == "Customer")
{
return SetCustomerData(strSql);
}else
//if (GROUPBY == "Company")
{
return SetCompanyData(strSql);
}
}
private static List<ImportWMSRptmb> SetData ( StringBuilder strSql )
{
var headList = new List<ImportWMSRptmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new ImportWMSRptmb();
#region Set DB data to Object
data.ExpirationDates = Convert.ToString(reader["ExpirationDates"]);
data.WMSDATE = Convert.ToString(reader["WMSDATE"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.STORAGENAME = Convert.ToString(reader["STORAGENAME"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.GOODSMODEL = Convert.ToString(reader["GOODSMODEL"]);
data.hj_GOODSRKSL = Convert.ToString(reader["hj_GOODSRKSL"]);
data.hj_GOODSPFSL_OUT = Convert.ToString(reader["hj_GOODSPFSL_OUT"]);
data.hj_GOODSSTOCK = Convert.ToString(reader["hj_GOODSSTOCK"]);
data.hj_GOODSPACK = Convert.ToString(reader["hj_GOODSPACK"]);
data.hj_GOODSPACKPFSL = Convert.ToString(reader["hj_GOODSPACKPFSL"]);
data.hj_GOODSPACKSTOCK = Convert.ToString(reader["hj_GOODSPACKSTOCK"]);
data.GID = Convert.ToString(reader["GID"]);
data.ASSOCIATEDNO = Convert.ToString(reader["ASSOCIATEDNO"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
data.CHARGEUNIT = Convert.ToString(reader["CHARGEUNIT"]);
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
data.GOODSGRADE = Convert.ToString(reader["GOODSGRADE"]);
data.GOODSSLICE = Convert.ToString(reader["GOODSSLICE"]);
data.GOODSSTANDARD = Convert.ToString(reader["SPECIFICATIONS"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.hj_GOODSPACKACTUAL = Convert.ToString(reader["hj_GOODSPACKACTUAL"]);
data.hj_GOODSRKSLACTUAL = Convert.ToString(reader["hj_GOODSRKSLACTUAL"]);
data.COMPANYNAME = Convert.ToString(reader["COMPANYNAME"]);
data.COUNTRY = Convert.ToString(reader["COUNTRY"]);
data.FACTORYNO = Convert.ToString(reader["FACTORYNO"]);
data.CONTAINERNO = Convert.ToString(reader["CONTAINERNO"]);
data.COSTPRICE = Convert.ToString(reader["COSTPRICE"]);
data.STOCKCOST = Convert.ToString(reader["STOCKCOST"]);
data.WMSINCOST = Convert.ToString(reader["WMSINCOST"]);
data.Productiondate_min = Convert.ToString(reader["Productiondate_min"]);
data.Productiondate_max = Convert.ToString(reader["Productiondate_max"]);
data.ExpirationDate = Convert.ToString(reader["ExpirationDate"]);
data.StoreDays = Convert.ToString(reader["StoreDays"]);
data.CargoDays = Convert.ToString(reader["CargoDays"]);
data.SALEINFO = Convert.ToString(reader["SALEINFO"]);
data.CargoType = Convert.ToString(reader["CargoType"]);
data.PAYCOMPANY = Convert.ToString(reader["PAYCOMPANY"]);
data.remark_6 = Convert.ToString(reader["remark_6"]);
data.Inspection_Storage = Convert.ToString(reader["Inspection_Storage"]);
data.Unsealdate = Convert.ToString(reader["Unsealdate"]);
data.sale_weight = Convert.ToString(reader["sale_weight"]);
data.sale_boxcount = Convert.ToString(reader["sale_boxcount"]);
data.PUTINTYPE = Convert.ToString(reader["PUTINTYPE"]);
data.WMSNO = Convert.ToString(reader["WMSNO"]);
data.seller = Convert.ToString(reader["seller"]);
data.Ename = Convert.ToString(reader["Ename"]);
data.KINDPKGS = Convert.ToString(reader["KINDPKGS"]);
data.Buy_OP = Convert.ToString(reader["Buy_OP"]);
data.OP = Convert.ToString(reader["OP"]);
data.Agent = Convert.ToString(reader["Agent"]);
data.price = Convert.ToString(reader["price"]);
data.currid = Convert.ToString(reader["currid"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
private static List<ImportWMSRptmb> SetCustomerData ( StringBuilder strSql )
{
var headList = new List<ImportWMSRptmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new ImportWMSRptmb();
#region Set DB data to Object
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.CHARGEUNIT = Convert.ToString(reader["CHARGEUNIT"]);
data.hj_GOODSRKSL = Convert.ToString(reader["hj_GOODSRKSL"]);
data.hj_GOODSPFSL_OUT = Convert.ToString(reader["hj_GOODSPFSL_OUT"]);
data.hj_GOODSSTOCK = Convert.ToString(reader["hj_GOODSSTOCK"]);
data.hj_GOODSPACK = Convert.ToString(reader["hj_GOODSPACK"]);
data.hj_GOODSPACKPFSL = Convert.ToString(reader["hj_GOODSPACKPFSL"]);
data.hj_GOODSPACKSTOCK = Convert.ToString(reader["hj_GOODSPACKSTOCK"]);
data.COSTPRICE = Convert.ToString(reader["COSTPRICE"]);
data.STOCKCOST = Convert.ToString(reader["STOCKCOST"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
private static List<ImportWMSRptmb> SetCompanyData ( StringBuilder strSql )
{
var headList = new List<ImportWMSRptmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new ImportWMSRptmb();
#region Set DB data to Object
data.COMPANYNAME = Convert.ToString(reader["COMPANYNAME"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.CHARGEUNIT = Convert.ToString(reader["CHARGEUNIT"]);
data.hj_GOODSRKSL = Convert.ToString(reader["hj_GOODSRKSL"]);
data.hj_GOODSPFSL_OUT = Convert.ToString(reader["hj_GOODSPFSL_OUT"]);
data.hj_GOODSSTOCK = Convert.ToString(reader["hj_GOODSSTOCK"]);
data.hj_GOODSPACK = Convert.ToString(reader["hj_GOODSPACK"]);
data.hj_GOODSPACKPFSL = Convert.ToString(reader["hj_GOODSPACKPFSL"]);
data.hj_GOODSPACKSTOCK = Convert.ToString(reader["hj_GOODSPACKSTOCK"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public ContentResult GetWMSDetailList(string condition,string sort)
{
var dataList = GetWMSDetailDataList(condition, sort);
var list = dataList.Skip(0).Take(500);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
private static List<WMSDetailmb> GetWMSDetailDataList(string strCondition, string sort)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT NID,BLNO,CUSTOMNO,CUSTOMERNAME,STORAGENAME,GOODSNAME,GOODSSTANDARD,GOODSMODEL,WMSNO,OUTBSNO_OUT,BSNO_OUT,WMSDATE,DODATE_OUT,GOODSRKSL,GOODSRKSLACTUAL,GOODSPFSL_OUT,GOODSSTOCK,CHARGEUNIT,GOODSOUTFEE_OUT, GOODSOUTFEEAP_OUT,ARFEE, APFEE,ARFEE_OUT,APFEE_OUT,FREESTORAGEPERIOD,CONTRACTNO,GOODSPACK,TRUCKNO_OUT,REMARK_OUT,MODIFIEDUSER,MODIFIEDTIME,CREATEUSER_OUT,CREATETIME_OUT FROM VW_WMS_DETAIL ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
return SetDetailData(strSql);
}
private static List<WMSDetailmb> SetDetailData(StringBuilder strSql)
{
var headList = new List<WMSDetailmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new WMSDetailmb();
#region Set DB data to Object
data.NID = Convert.ToString(reader["NID"]);
data.BLNO = Convert.ToString(reader["BLNO"]);
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.STORAGENAME = Convert.ToString(reader["STORAGENAME"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.GOODSSTANDARD = Convert.ToString(reader["GOODSSTANDARD"]);
data.GOODSMODEL = Convert.ToString(reader["GOODSMODEL"]);
data.WMSNO = Convert.ToString(reader["WMSNO"]);
data.OUTBSNO_OUT = Convert.ToString(reader["OUTBSNO_OUT"]);
data.BSNO_OUT = Convert.ToString(reader["BSNO_OUT"]);
data.WMSDATE = Convert.ToString(reader["WMSDATE"]);
data.DODATE_OUT = Convert.ToString(reader["DODATE_OUT"]);
data.GOODSRKSL = Convert.ToString(reader["GOODSRKSL"]);
data.GOODSRKSLACTUAL = Convert.ToString(reader["GOODSRKSLACTUAL"]);
data.GOODSPFSL_OUT = Convert.ToString(reader["GOODSPFSL_OUT"]);
data.GOODSSTOCK = Convert.ToString(reader["GOODSSTOCK"]);
data.CHARGEUNIT = Convert.ToString(reader["CHARGEUNIT"]);
data.GOODSOUTFEE_OUT = Convert.ToString(reader["GOODSOUTFEE_OUT"]);
data.GOODSOUTFEEAP_OUT = Convert.ToString(reader["GOODSOUTFEEAP_OUT"]);
data.ARFEE = Convert.ToString(reader["ARFEE"]);
data.APFEE = Convert.ToString(reader["APFEE"]);
data.ARFEE_OUT = Convert.ToString(reader["ARFEE_OUT"]);
data.APFEE_OUT = Convert.ToString(reader["APFEE_OUT"]);
data.FREESTORAGEPERIOD = Convert.ToString(reader["FREESTORAGEPERIOD"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
data.GOODSPACK = Convert.ToString(reader["GOODSPACK"]);
data.TRUCKNO_OUT = Convert.ToString(reader["TRUCKNO_OUT"]);
data.REMARK_OUT = Convert.ToString(reader["REMARK_OUT"]);
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]);
data.CREATEUSER_OUT = Convert.ToString(reader["CREATEUSER_OUT"]);
data.CREATETIME_OUT = Convert.ToString(reader["CREATETIME_OUT"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
}
}