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

276 lines
13 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.Models.WMSOUT_GuiGe;
using DSWeb.MvcShipping.Models.MsStevedores;
using DSWeb.MvcShipping.DAL.WMSStock;
using System.Collections.Generic;
using System.Data;
using System.IO;
using HcUtility.Comm;
using DSWeb.Areas.MvcShipping.DAL.Message;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using DSWeb.MvcShipping.DAL.MsCodeFtpSet;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.TruckMng.Helper;
using DSWeb.TruckMng.Helper.Repository;
using System.Web.Script.Serialization;
using System.Collections;
using System.Data.OleDb;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.MvcShipping.Models.WMSDeliver;
using JsonHelper;
using DSWeb.MvcShipping.DAL.WMSOUT_GuiGeDAL;
using DSWeb.EntityDA;
using DSWeb.MvcShipping.Models.CRM_QUOTATION;
using System.Data.SqlClient;
namespace DSWeb.MvcShipping.Controllers
{
public class WMSStockController : Controller
{
//
// GET:
public ActionResult Index ( )
{
return View();
}
//
// GET: /
public ContentResult GetDataList ( int start, int limit, string sort, string condition )
{
int count = 0;
var dataList = WMSEIPStockDAL.GetDataList(condition, start, limit, CookieConfig.GetCookie_UserId(Request), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), out count, sort);
var timeStamp = DateTime.Now.ToShortDateString();
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = count, data = dataList.ToList(), timeStamp = timeStamp });
return new ContentResult() { Content = json };
}
public ContentResult Receive(string data,string USERID)
{
var stockList = JsonConvert.Deserialize<List<EIP_Stock>>(data);
string msg = "";
bool flag = false;
foreach (var item in stockList)
{
bool flagWms = false;
bool flagWmsOut = false;
bool flagUpdate = false;
WMSOUT_GuiGe wmsout = new WMSOUT_GuiGe();
wmsout.GID = item.BSNO;
wmsout.BSNO = item.STOCKUPNO;
wmsout.CUSTOMERNAME = item.CUSTOMERNAME;
wmsout.SALECONTRACT = item.SALECONTRACT;
wmsout.GOODSNAME = item.GOODSNAMETT;
wmsout.DODATE = Convert.ToDateTime(item.STOCKUPDATE);
wmsout.ACCDATE = Convert.ToDateTime(item.STOCKUPDATE).ToString("yyyy-MM");
wmsout.OLDCUSTFEEDATE = Convert.ToDateTime(item.STOCKUPDATE);
wmsout.CREATEUSER = item.ENTEROPERATER;
wmsout.CREATETIME = Convert.ToDateTime(item.ENTERDATE);
wmsout.CORPID = item.CORPID;
wmsout.REMARK = item.REMARK;
wmsout.REMARK2 = item.EXPORTNO;
List<EIP_Tray> trayList = WMSEIPStockDAL.GetTrayList(item.BSNO);
int tmpPack = 0;
decimal tmpPfsl = 0;
WmsOutDetailModels detail = new WmsOutDetailModels();
foreach (var itemTray in trayList)
{
detail.GID = Guid.NewGuid().ToString();
detail.INBSNO = itemTray.GID;
detail.OUTBSNO = item.STOCKUPNO;
detail.GOODSNAME = itemTray.GOODSNAMETT;
//detail.GOODSNAMEID = itemTray.GOODSNAMETT;
detail.TRAYNO = itemTray.TRAYNO;
//detail.GOODSPFSL = Convert.ToDecimal(itemTray.TTWEIGHT);
detail.GOODSPFSL = 1;
tmpPfsl += 1;
detail.GOODSPACKPFSL = Convert.ToInt32(itemTray.TTPKGS);
tmpPack += Convert.ToInt32(itemTray.TTPKGS);
detail.STORAGENAME = itemTray.STORAGENAME;
detail.CORPID = itemTray.CORPID;
detail.DODATE = Convert.ToDateTime(item.STOCKUPDATE);
detail.STARTBILLINGDATE = DateTime.Now;//应收开始计费日期
detail.ENDBILLINGDATE = Convert.ToDateTime(item.STOCKUPDATE);//应收结束计费日期
flagWmsOut = WMSStockDAL.AddWMSOut(detail);
}
//Convert.ToString(Session["USERID"]);//创建人
//Convert.ToString(Session["COMPANYID"]).Trim();
wmsout.GOODSPFSL = tmpPfsl;
wmsout.GOODSPACKPFSL = tmpPack;
wmsout.GOODSOUTFEE = 0;
// wmsout.ARCLIENT = item.CUSTOMERNAME;
wmsout.ARCLIENTWMSOUT = item.CUSTOMERNAME;
wmsout.STORAGENAME = trayList[0].STORAGENAME;
wmsout.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//最后一次更新操作人
wmsout.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
flagWms = WMSStockDAL.Add(wmsout);
#region 更新入库信息
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
foreach (var enumValue in trayList)
{
//EIP是华腾项目参数
string sSQL = "update wms_in set GOODSPACKSTOCK=0,GOODSSTOCK=0 where GID='" + enumValue.GID.ToString().Trim() + "'";
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
sSQL = "update wms set GOODSPACKSTOCK=(select sum(GOODSPACKSTOCK) from wms_in where ASSOCIATEDNO='" + enumValue.BSNO.ToString().Trim() + "'),GOODSSTOCK=(select sum(GOODSSTOCK) from wms_in where ASSOCIATEDNO='" + enumValue.BSNO.ToString().Trim() + "') where gid='" + enumValue.BSNO.ToString().Trim() + "'";
bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
}
#endregion
#region 计算仓储费
Decimal totaloutfee = 0;//应收出库单的仓储费
Decimal totaloutfeeap = 0;//应付出库单的仓储费
var dataList = WMSOUT_GuiGeDAL.GetDetailList("edit", "outgid='" + wmsout.GID.ToString() + "'", "StockOutDetail", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
foreach (var enumValue in dataList)
{
// <param name="sqlTran">事务</param>
// <param name="strSTARTBILLINGDATE">开始计费日期</param>
// <param name="strOLDCUSTFEEDATE">上家承担仓储期限</param>
// <param name="strINBSNO">出库明细关联的入库单wms或wms_in的BSNO</param>
// <param name="strCUSTOMERNAME">出库主表的客户名称</param>
// <param name="outnums">出库量</param>
// <param name="strASSOCIATEDNO">关联wms_out_detail的GID</param>
// <param name="strFEETYPE">区别费用收、付类型</param>
int feedays = 0;//应收仓储天数
int feedaysap = 0;//应付仓储天数
Decimal sumfee = 0;//应收出库明细的仓储费
Decimal sumfeeap = 0;//应付出库明细的仓储费
#region 应收
if (enumValue.ARCLIENTWMSOUT.ToString().Trim() != "")
{
string getstr = WMSOUT_GuiGeDAL.getWmsRate(enumValue.STARTBILLINGDATE.ToString().Trim(), enumValue.DODATE_OUT.ToString().Trim(), enumValue.INBSNO_OUT.ToString().Trim(), enumValue.ARCLIENTWMSOUT.ToString().Trim(), Decimal.Parse(enumValue.GOODSPFSL_OUT.ToString().Trim()), enumValue.GID_OUT.ToString(), 1, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), enumValue.OUTBSNO_OUT.ToString().Trim(), wmsout.GID.ToString().Trim(), true, false);
string[] strls = getstr.Trim().Split(new string[] { "" }, StringSplitOptions.RemoveEmptyEntries);
sumfee = Decimal.Parse(strls[0].ToString());
totaloutfee += sumfee;//仓储费合计
if (strls.Length == 2)
feedays += int.Parse(strls[1].ToString());
#region 更新出库明细表的仓储费信息
string sSQL = "update wms_out_detail set GOODSOUTFEE=" + sumfee //应收仓储费
+ ",STARTBILLINGDATE='" + enumValue.STARTBILLINGDATE.ToString().Trim() + "'"//应收开始计费日期
+ ",ENDBILLINGDATE='" + enumValue.DODATE_OUT.ToString().Trim() + "'"//应收结束计费日期
+ ",FEEDAYS=" + feedays//应收计费天数
+ " where GID='" + enumValue.GID_OUT.ToString() + "'";
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
#endregion
}
#endregion
#region 应付
if (enumValue.TRUCKNAME.ToString().Trim() != "")
{
string getstr = WMSOUT_GuiGeDAL.getWmsRate(enumValue.STARTBILLINGDATEAP.ToString().Trim(), enumValue.DODATE_OUT.ToString().Trim(), enumValue.INBSNO_OUT.ToString().Trim(), enumValue.TRUCKNAME.ToString().Trim(), Decimal.Parse(enumValue.GOODSPFSL_OUT.ToString().Trim()), enumValue.GID_OUT.ToString(), 2, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), enumValue.OUTBSNO_OUT.ToString().Trim(), wmsout.GID.ToString().Trim(), true, false);
string[] strls = getstr.Trim().Split(new string[] { "" }, StringSplitOptions.RemoveEmptyEntries);
sumfeeap = Decimal.Parse(strls[0].ToString());
totaloutfeeap += sumfeeap;//仓储费合计
feedaysap += int.Parse(strls[1].ToString());
#region 更新出库明细表的仓储费信息
string sSQL = "update wms_out_detail set GOODSOUTFEEAP=" + sumfeeap //应付仓储费
+ ",STARTBILLINGDATEAP='" + enumValue.STARTBILLINGDATE.ToString().Trim() + "'"//应付开始计费日期
+ ",ENDBILLINGDATEAP='" + enumValue.DODATE_OUT.ToString().Trim() + "'"//应付结束计费日期
+ ",FEEDAYSAP=" + feedaysap//应付计费天数
+ " where GID='" + enumValue.GID_OUT.ToString() + "'";
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
#endregion
}
#endregion
}
#region 更新出库主表的仓储费信息
string sSQL2 = "update wms_out set GOODSOUTFEE=" + totaloutfee //应收仓储费
+ ",GOODSOUTFEEAP=" + totaloutfeeap//应付仓储费
+ " where GID='" + wmsout.GID.ToString().Trim() + "'";
bool bl2 = T_ALL_DA.GetExecuteSqlCommand(sSQL2);
#endregion
#endregion
//更新EIP中备货单状态
flagUpdate =WMSEIPStockDAL.UpdateRecvedByStockNo(item.BSNO);
if (flagWms && flagWmsOut && flagUpdate && bl2 )
{
flag = true;
msg = "接收数据成功!";
}
else
{
flag = false;
msg = "接收数据失败!";
}
}
var jsonRespose = new JsonResponse { Success = flag, Message = msg };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult setStock(string gid, string state)
{
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) };
}
bool flag = false;
string msg = "状态更新失败!";
if (WMSEIPStockDAL.UpdateByStockNo(gid, state))
{
flag = true;
msg = "状态更新成功!";
}
var jsonRespose = new JsonResponse { Success = flag, Message = msg };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
}