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

1302 lines
52 KiB
C#

2 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using DSWeb.Areas.Import.Models.Comm;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.Import.DAL.ImportTrade;
using DSWeb.Areas.Import.DAL.ImportSales;
using DSWeb.Areas.Import.Models.ImportTrade;
using DSWeb.Areas.Import.DAL.XXH;
using DSWeb.Areas.Import.Models.XXH;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.TruckMng.Helper;
using DSWeb.TruckMng.Helper.Repository;
using DSWeb.Areas.Import.DAL.Comm;
using HcUtility.Comm;
using HcUtility.Core;
using DSWeb.Areas.CommMng.Models;
////应对新的单据管理模块
using DSWeb.MvcShipping.Controllers;
using DSWeb.MvcShipping.DAL.MsOpReceiptDAL;
using DSWeb.MvcShipping.Models.MsOpReceipt;
using DSWeb.MvcShipping.Models.MsOpAmend;
using System.Text;
using DSWeb.MvcShipping.DAL.MsOpSeaeDAL;
using DSWeb.MvcShipping.DAL.MsOpSeaeEdiPortDAL;
using DSWeb.MvcShipping.Models.MsOpSeae;
using DSWeb.MvcShipping.Models.MsOpSeaeBill;
using DSWeb.MvcShipping.DAL.MsCodeFtpSet;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.Areas.RptMng.Comm;
using Microsoft.Office.Interop.Excel;
using DSWeb.MvcShipping.Models.MsOpApply;
using DSWeb.MvcShipping.DAL.MsOpApplyDAL;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using DSWeb.MvcShipping.Models.MsSysBillNoSet;
using DSWeb.MvcShipping.Models.WMS;
using DSWeb.MvcShipping.Controllers;
using System.IO;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.MvcShipping.DAL.WMS;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
namespace DSWeb.Areas.Import.Controllers
{
[JsonRequestBehavior]
public class ImportTradeController : Controller
{
//
// GET: /Import/XXH
public ActionResult Index ( )
{
return View();
}
//
// GET: /Import/XXH/Edit
public ActionResult Edit ( )
{
return View();
}
public ActionResult FeeEdit ( )
{
return View();
}
public ActionResult WMSIN ( )
{
return View();
}
public ActionResult WMSINEdit ( )
{
return View();
}
public ActionResult WMSOUT ( )
{
return View();
}
public ActionResult WMSOUTEdit ( )
{
return View();
}
[ValidateInput(false)]
public ContentResult GetDataList_ALL ( int start, int limit, string sort, string condition )
{
var dataList = ImportTradeDAL.GetDataList_ALL(condition, CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_UserName(Request), CookieConfig.GetCookie_CompanyId(Request), 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 GetEditList_ALL ( int start, int limit, string sort, string condition )
{
var dataList = XXHDAL.GetEditList_ALL(condition, CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_UserName(Request), CookieConfig.GetCookie_CompanyId(Request), 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 GetDataList_ALL_single ( int start, int limit, string sort, string condition )
{
var dataList = XXHDAL.GetDataList_ALL_single(condition, CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_UserName(Request), CookieConfig.GetCookie_CompanyId(Request));
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 GetData_HT ( string handle, string condition )
{
HTmb head = null;
var list = XXHDAL.GetDataList_HT(condition);
if (list.Count > 0)
head = list[0];
if (head == null)
{ head = new HTmb(); }
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
//获取毛利(通过存储过程)
public ContentResult GetML ( string contractno )
{
MLmb head = null;
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 AR = null;
if (evList.Count > 0)
AR = evList[0];
if (AR == null)
{
AR = new AuthorityRangemb();
//OPERATERANGE = "3";
VISIBLERANGE = "3";
}
else
{
//OPERATERANGE = head.OPERATERANGE;
VISIBLERANGE = AR.VISIBLERANGE;
}
var condition = "BsNo='" + contractno + "' ";
if (VISIBLERANGE == "1")
{
condition = condition + " and enteroperator in(select userid from user_company where companyid='" + corpid + "')";
}
if (VISIBLERANGE == "2")
{
condition = condition + " and 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 enteroperator ='" + USERID + "'";
}
var list = XXHDAL.GetML(condition,contractno);
if (list.Count > 0)
head = list[0];
if (head == null)
{ head = new MLmb(); }
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
//
// GET/Import/XXH/GetData/
public ContentResult GetData(string handle, string condition)
{
ImportTrademb head = null;
if (handle == "edit")
{
var _t = "";
var list = ImportTradeDAL.GetDataList_ALL(condition, CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_UserName(Request), CookieConfig.GetCookie_CompanyId(Request), _t);
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new ImportTrademb();
}
if (handle == "add")
{
head.OP = CookieConfig.GetCookie_UserName(Request);
//head.OPRef = Convert.ToString(Session["SHOWNAME"]);
head.creator = CookieConfig.GetCookie_UserCode(Request);
head.EXCHANGERATE = "1";
head.CORPID = Convert.ToString(Session["COMPANYID"]);
}
if (head == null)
{
head = new ImportTrademb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
//
// GET/Import/ImportTrade/Save
public ContentResult Save ( string opstatus, string data, string CargoBody, string CargoDelBody )
{
//var headData = JsonConvert.Deserialize<MsOpSeae>(data.Replace("}", ",") + data2.Replace("{", "").Replace("}", ",") + data3.Replace("{", ""));
var head = JsonConvert.Deserialize<ImportTrademb>(data);
var CargobodyList = JsonConvert.Deserialize<List<Cargomb2>>(CargoBody);
var CargodelbodyList = JsonConvert.Deserialize<List<Cargomb2>>(CargoDelBody);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.CORPID=Convert.ToString(Session["COMPANYID"]);
head.ContractNo = PubSysDAL.GetBillNo("0201"); //获取合同号
//headData.LrDate = DateTime.Now;
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<Cargomb2>.ToModelObjectList(CargobodyList),
ModelObjectConvert<Cargomb2>.ToModelObjectList(CargodelbodyList)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = ImportTradeDAL.GetData_ALL("M.ContractNo='" + head.ContractNo + "'", CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_UserName(Request), CookieConfig.GetCookie_CompanyId(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Delete ( string data )
{
var head = JsonConvert.Deserialize<ImportTrademb>(data);
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head, Session["USERID"].ToString(), true);
var ContractNo = head.ContractNo;
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
var _count = XXHDAL.ClearHTH(ContractNo);
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
//return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
// Get:/Import/XXH/GetCargoList
public ContentResult GetCargoList ( string condition )
{
var _condition = " c.ContractNo = '" + condition + "' ";
List<Cargomb> list = XXHDAL.GetCargoList(_condition);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetCargoList2 ( string condition ) //增加三个字段
{
var _condition = " c.ContractNo = '" + condition + "' ";
List<Cargomb2> list = ImportTradeDAL.GetCargoList2(_condition);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetCargoList3 ( string condition ) //接受条件
{
var _condition = condition ;
List<Cargomb3> list = ImportTradeDAL.GetCargoList3(_condition);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
#region 获取指定合同号的费用数量,防止有费用的合同被删
public ContentResult GetChfee ( string handle, string condition )
{
HTmb head = null;
var list = XXHDAL.GetChfee(condition);
if (list.Count > 0)
head = list[0];
if (head == null)
{ head = new HTmb(); }
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
#endregion
#region 锁定商品信息,生成库存
//20160707 修改
//如无对应销售信息,货主为操作者的“本公司”
//如有对应销售信息,则首先判断销售重量是否大于等于实际入库重量。
//如剩余重量小于等于1kg则全部按销售重量和销售客户按比例生成。
//如剩余重量大于1kg则剩余部分按货主为操作者的“本公司”处理。
public ContentResult LockCargo ( string CUSTOMERNAME, string STORAGENAME, string WMSDATE, string CargoBody )
{
//首先通过商品信息生成和保存wms和wms_in
var CargobodyList = JsonConvert.Deserialize<List<Cargomb3>>(CargoBody);
var WMSNOList = MakeWMS(CUSTOMERNAME, STORAGENAME, WMSDATE, CargobodyList);
/*
var WMSC = new WMSController();
var USERID= CookieConfig.GetCookie_UserId(Request);
var _k = WMSC.LockWMS(WMSNOList, USERID, "1");
*/
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = WMSNOList });
return new ContentResult() { Content = JsonConvert.Serialize(json) };
}
public ContentResult LockCargo2 ( string STORAGENAME, string WMSDATE, string CargoBody )
{
//首先通过商品信息生成和保存wms和wms_in
var CargobodyList = JsonConvert.Deserialize<List<Cargomb3>>(CargoBody);
var WMSNOList = MakeWMS2( STORAGENAME, WMSDATE, CargobodyList);
/*
var WMSC = new WMSController();
var USERID= CookieConfig.GetCookie_UserId(Request);
var _k = WMSC.LockWMS(WMSNOList, USERID, "1");
*/
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = WMSNOList });
return new ContentResult() { Content = JsonConvert.Serialize(json) };
}
public string MakeWMS ( string CUSTOMERNAME, string STORAGENAME, string WMSDATE, List<Cargomb3> CargobodyList )
{
//首先通过商品信息生成和保存wms和wms_in
//返回值是所有生成的WMS信息的GID用于费用入账的参数
//
var WMSNOList = "";
foreach (var cargo in CargobodyList)
{
var SaleDetailList = ImportSalesDAL.GetDetailList(" s.CARGO_GID='" + cargo.GID + "'");
//如无对应销售信息,货主为操作者的“本公司”
//如有对应销售信息,则首先判断销售重量是否大于等于实际入库重量。
//如剩余重量小于等于3000kg则全部按销售重量和销售客户按比例生成。
//如剩余重量大于3000kg则剩余部分按货主为操作者的“本公司”处理。
/*
if (SaleDetailList.Count() == 0)
{*/ // 20160910 改为全部按照北京二商入库。
//CUSTOMERNAME = Session["COMPANYNAME"].ToString();
//如无对应销售信息,货主为操作者的“本公司”
var REMARK="";
if (SaleDetailList.Count() > 0) {
REMARK = "销售对象:";
foreach (var _SD in SaleDetailList)
{
if (REMARK == "销售对象:")
REMARK = REMARK + _SD.CUSTOMERNAME;
else
REMARK = REMARK + "," + _SD.CUSTOMERNAME;
}
}
var WMSGID = DoMakeWMS(Session["COMPANYNAME"].ToString(), STORAGENAME, WMSDATE, cargo, REMARK);
if (WMSNOList == "")
{
WMSNOList = "" + WMSGID + "";
}
else
WMSNOList = WMSNOList + "," + WMSGID + "";
/*
}
else
{
decimal salesweight = 0;
decimal cargoweight_ACT = decimal.Parse(cargo.WEIGHT_ACT);
decimal cargoweight = decimal.Parse(cargo.WEIGHT_ACT);
decimal cargoboxcount = decimal.Parse(cargo.BOXCOUNT_ACT);
foreach (var _sd in SaleDetailList)
{
salesweight = salesweight + decimal.Parse(_sd.WEIGHT);
}
//如有对应销售信息,则首先判断销售重量是否大于等于实际入库重量。
if (cargoweight_ACT - salesweight > 3000)
{
//如剩余重量大于3000kg则剩余部分按货主为操作者的“本公司”处理。
cargo.WEIGHT_ACT = (cargoweight_ACT - salesweight).ToString();
cargo.BOXCOUNT_ACT = (cargoboxcount * (cargoweight_ACT - salesweight) / cargoweight_ACT).ToString();
var WMSGID = DoMakeWMS(Session["COMPANYNAME"].ToString(), STORAGENAME, WMSDATE, cargo);
if (WMSNOList == "")
{
WMSNOList = "" + WMSGID + "";
}
else
WMSNOList = WMSNOList + "," + WMSGID + "";
cargoweight = salesweight;
foreach (var _sd in SaleDetailList)
{
cargo.WEIGHT_ACT = _sd.WEIGHT;
cargo.BOXCOUNT_ACT = (cargoboxcount * decimal.Parse(_sd.WEIGHT) / cargoweight_ACT).ToString();
WMSGID = DoMakeWMS(_sd.CUSTOMERNAME, STORAGENAME, WMSDATE, cargo);
if (WMSNOList == "")
{
WMSNOList = "" + WMSGID + "";
}
else
WMSNOList = WMSNOList + "," + WMSGID + "";
}
}
else
{
//如剩余重量小于等于1kg则全部按销售重量和销售客户按比例生成。
foreach (var _sd in SaleDetailList)
{
var wmsinweight = cargoweight_ACT * decimal.Parse(_sd.WEIGHT) / salesweight;
cargo.WEIGHT_ACT = wmsinweight.ToString();
cargo.BOXCOUNT_ACT = (cargoboxcount * decimal.Parse(_sd.WEIGHT) / salesweight).ToString();
var WMSGID = DoMakeWMS(_sd.CUSTOMERNAME, STORAGENAME, WMSDATE, cargo);
if (WMSNOList == "")
{
WMSNOList = "" + WMSGID + "";
}
else
WMSNOList = WMSNOList + "," + WMSGID + "";
}
}
}
*/
}
return WMSNOList;
}
public string MakeWMS2 ( string STORAGENAME, string WMSDATE, List<Cargomb3> CargobodyList )
{
//首先通过商品信息生成和保存wms和wms_in
//返回值是所有生成的WMS信息的GID用于费用入账的参数
//
var WMSNOList = "";
foreach (var cargo in CargobodyList)
{
var SaleDetailList = ImportSalesDAL.GetDetailList(" s.CARGO_GID='" + cargo.GID + "'");
//如无对应销售信息,货主为操作者的“本公司”
//如有对应销售信息,则首先判断销售重量是否大于等于实际入库重量。
//如剩余重量小于等于3000kg则全部按销售重量和销售客户按比例生成。
//如剩余重量大于3000kg则剩余部分按货主为操作者的“本公司”处理。
/*
if (SaleDetailList.Count() == 0)
{*/
// 20160910 改为全部按照北京二商入库。
//CUSTOMERNAME = Session["COMPANYNAME"].ToString();
//如无对应销售信息,货主为操作者的“本公司”
var REMARK = "";
/*
if (SaleDetailList.Count() > 0)
{
REMARK = "销售对象:";
foreach (var _SD in SaleDetailList)
{
if (REMARK == "销售对象:")
REMARK = REMARK + cargo.buyer;
else
REMARK = REMARK + "," + cargo.buyer;
}
}*/
var WMSGID = DoMakeWMS(cargo.buyer, STORAGENAME, WMSDATE, cargo, REMARK);
if (WMSNOList == "")
{
WMSNOList = "" + WMSGID + "";
}
else
WMSNOList = WMSNOList + "," + WMSGID + "";
/*
}
else
{
decimal salesweight = 0;
decimal cargoweight_ACT = decimal.Parse(cargo.WEIGHT_ACT);
decimal cargoweight = decimal.Parse(cargo.WEIGHT_ACT);
decimal cargoboxcount = decimal.Parse(cargo.BOXCOUNT_ACT);
foreach (var _sd in SaleDetailList)
{
salesweight = salesweight + decimal.Parse(_sd.WEIGHT);
}
//如有对应销售信息,则首先判断销售重量是否大于等于实际入库重量。
if (cargoweight_ACT - salesweight > 3000)
{
//如剩余重量大于3000kg则剩余部分按货主为操作者的“本公司”处理。
cargo.WEIGHT_ACT = (cargoweight_ACT - salesweight).ToString();
cargo.BOXCOUNT_ACT = (cargoboxcount * (cargoweight_ACT - salesweight) / cargoweight_ACT).ToString();
var WMSGID = DoMakeWMS(Session["COMPANYNAME"].ToString(), STORAGENAME, WMSDATE, cargo);
if (WMSNOList == "")
{
WMSNOList = "" + WMSGID + "";
}
else
WMSNOList = WMSNOList + "," + WMSGID + "";
cargoweight = salesweight;
foreach (var _sd in SaleDetailList)
{
cargo.WEIGHT_ACT = _sd.WEIGHT;
cargo.BOXCOUNT_ACT = (cargoboxcount * decimal.Parse(_sd.WEIGHT) / cargoweight_ACT).ToString();
WMSGID = DoMakeWMS(_sd.CUSTOMERNAME, STORAGENAME, WMSDATE, cargo);
if (WMSNOList == "")
{
WMSNOList = "" + WMSGID + "";
}
else
WMSNOList = WMSNOList + "," + WMSGID + "";
}
}
else
{
//如剩余重量小于等于1kg则全部按销售重量和销售客户按比例生成。
foreach (var _sd in SaleDetailList)
{
var wmsinweight = cargoweight_ACT * decimal.Parse(_sd.WEIGHT) / salesweight;
cargo.WEIGHT_ACT = wmsinweight.ToString();
cargo.BOXCOUNT_ACT = (cargoboxcount * decimal.Parse(_sd.WEIGHT) / salesweight).ToString();
var WMSGID = DoMakeWMS(_sd.CUSTOMERNAME, STORAGENAME, WMSDATE, cargo);
if (WMSNOList == "")
{
WMSNOList = "" + WMSGID + "";
}
else
WMSNOList = WMSNOList + "," + WMSGID + "";
}
}
}
*/
}
return WMSNOList;
}
private string DoMakeWMS ( string CUSTOMERNAME, string STORAGENAME, string WMSDATE, Cargomb3 cargo ,string REMARK)
{
var CargoInfo = ImportTradeDAL.GetData_ALL(" c.gid = '" + cargo.GID + "' ", CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_UserName(Request), CookieConfig.GetCookie_CompanyId(Request));
var head = new WMSmb_ImportTrade();
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.GID = "Wms" + Guid.NewGuid().ToString().Replace("-", ""); ;
head.WMSOP = CookieConfig.GetCookie_UserName(Request);
head.CUSTOMERNAME = CUSTOMERNAME;
head.STORAGENAME = STORAGENAME;
head.WMSDATE = WMSDATE;
var USERID = CookieConfig.GetCookie_UserId(Request);
var ORGCODE = CookieConfig.GetCookie_OrgCode(Request);
var WMSC = new WMSController();
head.WMSNO = WMSC.getCodeRule(USERID, ORGCODE, "入库单号", "WMSNO", "WMS", head.WMSDATE);//调用编码规则
head.WMSDATE = WMSDATE;
head.STARTBILLINGDATE = WMSDATE;
head.GOODSPACK = cargo.BOXCOUNT_ACT;
head.GOODSPACKACTUAL = cargo.BOXCOUNT_ACT;
head.GOODSPACKSTOCK = cargo.BOXCOUNT_ACT;
head.GOODSRKSL = (float.Parse(cargo.WEIGHT_ACT) / 1000).ToString();
head.GOODSRKSLACTUAL = (float.Parse(cargo.WEIGHT_ACT) / 1000).ToString();
head.GOODSSTOCK = (float.Parse(cargo.WEIGHT_ACT) / 1000).ToString();
head.ASSOCIATEDNO = cargo.ContractNo;
head.ARFEE = "0";
head.APFEE = "0";
head.ISCHANGE = "0";
head.BANKVALUE = "0";
head.MARKETVALUE = "0";
head.CARGO_GID = cargo.GID;
head.GOODSNAME = cargo.name;
head.CHARGEUNIT = "吨";
head.BLNO = CargoInfo.BillNo;
head.CONTRACTNO = CargoInfo.HTH;
head.GOODSMODEL = CargoInfo.factoryno;//牌号
head.CORPID = Session["COMPANYID"].ToString();
head.CREATEUSER = Session["USERID"].ToString();
head.MODIFIEDUSER = Session["USERID"].ToString();
head.MODIFIEDTIME = DateTime.Now.ToString();
head.CUSTOMNO = "";
head.ARCLIENT = CUSTOMERNAME;
head.REMARK = REMARK;
head.GOODSSTANDARD = cargo.SPECIFICATIONS;
var WMSIN = new WMSINmb();
WMSIN.GID = Guid.NewGuid().ToString();
WMSIN.BSNO = head.WMSNO;
WMSIN.GOODSPACK = cargo.BOXCOUNT_ACT;
WMSIN.GOODSPACKACTUAL = cargo.BOXCOUNT_ACT;
WMSIN.GOODSPACKSTOCK = cargo.BOXCOUNT_ACT;
WMSIN.GOODSRKSL = (float.Parse(cargo.WEIGHT_ACT) / 1000).ToString();
WMSIN.GOODSRKSLACTUAL = (float.Parse(cargo.WEIGHT_ACT) / 1000).ToString();
WMSIN.GOODSSTOCK = (float.Parse(cargo.WEIGHT_ACT) / 1000).ToString();
WMSIN.CNTRNO = CargoInfo.ContainerNo;
WMSIN.SEALNO = CargoInfo.SealNo;
WMSIN.GOODSKGS = "0";
WMSIN.ARFEE = "0";
WMSIN.APFEE = "0";
WMSIN.GOODSTHICKNESS = "0";
WMSIN.GOODSWIDTH = "0";
WMSIN.GOODSLENGTH = "0";
WMSIN.GOODSSLICE = cargo.BOXCOUNT_ACT;
WMSIN.MARKETVALUE = "0";
WMSIN.BANKVALUE = "0";
WMSIN.CHARGEUNIT = "吨";
WMSIN.GOODSCODE = CargoInfo.productiondate_min + "-" + CargoInfo.productiondate_max;
var wmsinlist = new List<WMSINmb>();
wmsinlist.Add(WMSIN);
var wmsinlistdel = new List<WMSINmb>();
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<WMSINmb>.ToModelObjectList(wmsinlist),
ModelObjectConvert<WMSINmb>.ToModelObjectList(wmsinlistdel)
);
if (result.Success)
{
//将cargo表的islocked设为1
var _i = ImportTradeDAL.SetCargoLock(cargo.GID, WMSDATE);
var _j = ImportTradeDAL.SetWMSRATE(STORAGENAME, USERID, head.GID, CUSTOMERNAME, WMSDATE);
return head.GID;
}
else
{
return "";
}
}
/*
private string DoChangeSales ( Cargomb2 cargo )
{
//根据实际入库件数 修改相应销售单的销售件数
}*/
#endregion
public ContentResult SaveWMSCargo ( string Cargobody )
{
var CargobodyList = JsonConvert.Deserialize<List<Cargomb3>>(Cargobody);
var WMSImportMain = JsonConvert.Deserialize<List<WMSmb_ImportTradeMain>>(Cargobody);
var modb = new ModelObjectRepository();
DBResult result = modb.Save(
ModelObjectConvert<Cargomb3>.ToModelObjectList(CargobodyList)
);
result = modb.Save(
ModelObjectConvert<WMSmb_ImportTradeMain>.ToModelObjectList(WMSImportMain)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#region 删除库存
public ContentResult DeleteWMS ( string CARGO_GID )
{
var _i = ImportTradeDAL.SetCargoUnLock(CARGO_GID);
var GIDList = WMSDAL.GetDataList(" CARGO_GID='" + CARGO_GID + "' ", "");
if (GIDList.Count > 0)
{
//var head = new WMSmb();
var USERID = CookieConfig.GetCookie_UserId(Request);
//var _GIDList = "";
var result = new DBResult();
foreach (var _w in GIDList)
{
var WMSC = new WMSController();
var _k = WMSC.LockWMS(_w.GID, USERID, "0");
var modb = new ModelObjectDB();
result = modb.Delete(_w, "delete from wms_in where ASSOCIATEDNO ='" + _w.GID + "' delete from WMS_RATE where BSNO ='" + _w.GID + "'");
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var jsonRespose = new JsonResponse { Success = true, Message = "无所属入库信息" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
#endregion
#region 查询库存,看是否有取用记录
public ContentResult GetCargoOut ( string CARGO_GID )
{
var _count = ImportTradeDAL.GetCargoOut(CARGO_GID);
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = _count });
return new ContentResult() { Content = json };
}
public ContentResult GetLocked ( string CARGO_GID )
{
var _count = ImportTradeDAL.GetLocked(CARGO_GID);
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = _count });
return new ContentResult() { Content = json };
}
#endregion
#region 参照部分
// Get:/Import/XXH/GetApp
public ContentResult GetApp ( string condition )
{
var _condition = " ap.cargoinfo_id in(select cargoinfo_id from import_cargo where contractno='" + condition + "') ";
_condition = _condition + " and ap.cargociq_id in(select cargociq_id from import_cargo where contractno='" + condition + "') ";
_condition = _condition + " and ap.countryid in(select countryid from import_main where contractno='" + condition + "')";
_condition = _condition + " and ap.sljg in(select port sljg from import_main where contractno='" + condition + "')";
// _condition = _condition + " and ap.company in(select company from import_main where contractno='" + condition + "')";
_condition = _condition + " and ap.isdeleted=0 and (validdate>(select creattime from import_main where contractno='" + condition + "') or validdate='')";
List<Appstatemb> list = XXHDAL.GetApp(_condition);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetCountry ( string condition )
{
var list = XXHDAL.GetCountry();
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public string KCEnterDate ( string contractno, string OutDate )
{
var KCEnterDate = "";
//KCEnterDate = XXHDAL.GetKCEnterDate(contractno);
return KCEnterDate;
}
#endregion
#region AMS
public ContentResult GetAmsData ( string condition )
{
MsOpSeaeAms head = null;
head = MsOpSeaeEdiPortDAL.GetAmsData(condition);
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult SaveAms ( string data, string bsno )
{
var headData = JsonConvert.Deserialize<MsOpSeaeAms>(data);
headData.BSNO = bsno;
if (headData.AMSNO == "*")
{
headData.DbOperationType = DbOperationType.DbotIns;
headData.AMSNO = Guid.NewGuid().ToString();
}
else
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
var BSNO = headData.AMSNO;
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsOpSeaeEdiPortDAL.GetAmsData("AMSNO='" + BSNO + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
[HttpPost]
public ContentResult UploadFile ( )
{
var jsonRespose = new JsonResponse { Success = false, Message = "" };
if (Request.Files.Count != 1)
{
jsonRespose.Success = false;
jsonRespose.Message = "请选择上传的文件";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var file = Request.Files["LoadImage"];
var fileGID = Request.Form["fileGid"];
var HTH = Request.Form["HTH"];
var RECEIPTTYPE = Request.Form["RECEIPTTYPE"];
var fileName_EX = Request.Form["fileName_EX"] + "_" + System.Guid.NewGuid().ToString();
if (file == null)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var path = "";
var FTPPATH = "";
var COMPANYID = Convert.ToString(Session["COMPANYID"]);
var _ftpurlList = BasicDataRefDAL.GeneralSelect("select ftpurl GVALUE,gid GID from company where GID='" + COMPANYID + "'");
var _ftpurl = _ftpurlList[0].GVALUE;
if (RECEIPTTYPE == "单据")
{
path = "D:/Doc/BJES/单据/" + HTH;
FTPPATH = "ftp://bjes:@" + _ftpurl + "/单据/" + HTH;//101.201.50.235//
}
else
{
path = "D:/Doc/BJES/" + RECEIPTTYPE;
FTPPATH = "ftp://bjes:@" + _ftpurl + "/" + RECEIPTTYPE;//120.27.53.37
}
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var size = file.ContentLength;
var name = HTH + fileName_EX;
var usercode = CookieConfig.GetCookie_UserCode(Request);
var realname = Path.GetFileName(file.FileName);
var _name = realname.Substring(realname.IndexOf("."), realname.Length - realname.IndexOf("."));
//string filename = path + "\\" + name + _name;
string filename = path + "/" + name + _name;
FTPPATH = FTPPATH + "/" + name + _name;
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
file.SaveAs(filename);
if (!System.IO.File.Exists(filename))
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
try
{
var message = string.Empty;
var isSucess = ImportTradeDAL.UpdateFileData(Request, filename, name, FTPPATH, fileGID, out message);
if (!isSucess)
{
jsonRespose.Success = false;
jsonRespose.Message = message;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var json = JsonConvert.Serialize(new { success = true, Message = "上传成功!", data = filename });
return new ContentResult() { Content = json };
}
catch (Exception e)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件出错 "+e.Message;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult DeleteUploadFile ( string data )
{
int iResult = 0;
var bodyList = data;
var result = new DBResult();
if (bodyList != "" || bodyList != null)
{
iResult = ImportTradeDAL.DeleteUploadFile(bodyList);
}
if (iResult == 1)
{
result.Success = true;
result.Message = "删除成功!";
}
else if (iResult == 0)
{
result.Success = false;
result.Message = "出现错误,未删除!";
}
else if (iResult == -1)
{
result.Success = false;
result.Message = "有异常,删除失败!";
}
else if (iResult == -2)
{
result.Success = false;
result.Message = "删除异常,事务已回滚成功!";
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
// Data = MsChFeeDAL.GetDataList(headData.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#region 生成补税/退税
public ContentResult MakeTax ( string ContractNo, string tax, string tax_zz )
{
var head = ImportTradeDAL.GetData_ALL("M.Contractno='" + ContractNo + "'", CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_UserName(Request), CookieConfig.GetCookie_CompanyId(Request));
Database db = DatabaseFactory.CreateDatabase();
var = 0M;
var = 0M;
var = 0M;
var = 0M;
var = "";
var = "";
var chfeelist = new List<MsChFee2>();
var _ = db.ExecuteScalar(CommandType.Text, "select sum(amount) from ch_fee where BSNO='" + ContractNo + "' and feetype=2 and (feename='关税' or (feename='补税' and remark like '%关税%') ) ");
if (string.IsNullOrEmpty(_.ToString())) {
_ = "0";
}
var = Convert.ToDecimal(_);
var 退 = db.ExecuteScalar(CommandType.Text, "select sum(amount) from ch_fee where BSNO='" + ContractNo + "' and feetype=1 and feename='退税' and remark like '%关税%'");
var = db.ExecuteScalar(CommandType.Text, "select sum(amount) from ch_fee where BSNO='" + ContractNo + "' and feetype=1 and feename='补税' and remark like '%关税%'");
if (string.IsNullOrEmpty(退.ToString()))
{
退 = "0";
}
= - Convert.ToDecimal(退);
if (string.IsNullOrEmpty(.ToString()))
{
= "0";
}
= + Convert.ToDecimal();
var _ = db.ExecuteScalar(CommandType.Text, "select sum(amount) from ch_fee where BSNO='" + ContractNo + "' and feetype=2 and (feename='增值税' or (feename='补税' and remark like '%增值税%') ) ");
if (string.IsNullOrEmpty(_.ToString()))
{
_ = "0";
}
var = Convert.ToDecimal(_);
var 退 = db.ExecuteScalar(CommandType.Text, "select sum(amount) from ch_fee where BSNO='" + ContractNo + "' and feetype=1 and feename='退税' and remark like '%增值税%'");
var = db.ExecuteScalar(CommandType.Text, "select sum(amount) from ch_fee where BSNO='" + ContractNo + "' and feetype=1 and feename='补税' and remark like '%增值税%'");
if (string.IsNullOrEmpty(退.ToString()))
{
退 = "0";
}
= - Convert.ToDecimal(退);
if (string.IsNullOrEmpty(.ToString()))
{
= "0";
}
= + Convert.ToDecimal();
if (Convert.ToDecimal(tax_zz) == )
{
//如果与当前应付税金相同,不做处理
} else
if (Convert.ToDecimal(tax_zz) > )
{
/*
*
<>
=
*/
/*
var _chfee = getChfee("关税", head.Agent, 2, );
chfeelist.Add(_chfee);
* */
var CargoList = ImportTradeDAL.GetCargoList2(" c.ContractNo='" + ContractNo + "' ");
foreach (var _C in CargoList) {
var _old_amount = 0M;
var old_tax = 0M;
var old_tax_zz = 0M;
if (Convert.ToDecimal(_C.price_limit) > Convert.ToDecimal(_C.price))
{
_old_amount = Convert.ToDecimal(_C.price_limit) * Convert.ToDecimal(_C.weight) * Convert.ToDecimal(_C.Exchangerate_Customs) * Convert.ToDecimal(_C.baolv);
old_tax = _old_amount * Convert.ToDecimal(_C.tax);
old_tax_zz = _old_amount * (1 + Convert.ToDecimal(_C.tax)) * Convert.ToDecimal(_C.tax_zz);
= + old_tax;
= + old_tax_zz;
}
else {
_old_amount = Convert.ToDecimal(_C.price) * Convert.ToDecimal(_C.weight) * Convert.ToDecimal(_C.Exchangerate_Customs) * Convert.ToDecimal(_C.baolv);
old_tax = _old_amount * Convert.ToDecimal(_C.tax);
old_tax_zz = _old_amount * (1 + Convert.ToDecimal(_C.tax)) * Convert.ToDecimal(_C.tax_zz);
= + old_tax;
= + old_tax_zz;
}
var = Convert.ToDecimal(db.ExecuteScalar(CommandType.Text, "select isnull((select sum(isnull(amount,0)) from ch_fee where BSNO='" + ContractNo + "' and feename='补税' and BXGID='"+_C.GID+"'),0)"));
if (Convert.ToDecimal(_C.price_limit) > Convert.ToDecimal(_C.price) && ==0) {
//而且该商品没有生成过补税
_old_amount = Convert.ToDecimal(_C.price) * Convert.ToDecimal(_C.weight) * Convert.ToDecimal(_C.Exchangerate_Customs) * Convert.ToDecimal(_C.baolv);
old_tax = _old_amount * Convert.ToDecimal(_C.tax);
old_tax_zz = _old_amount * (1 + Convert.ToDecimal(_C.tax)) * Convert.ToDecimal(_C.tax_zz);
var _new_amount = Convert.ToDecimal(_C.price_limit) * Convert.ToDecimal(_C.weight) * Convert.ToDecimal(_C.Exchangerate_Customs) * Convert.ToDecimal(_C.baolv);
var new_tax = _new_amount * Convert.ToDecimal(_C.tax) ;
var new_tax_zz = _new_amount * (1+Convert.ToDecimal(_C.tax))*Convert.ToDecimal(_C.tax_zz) ;
var _ = new_tax - old_tax;
var _ = new_tax_zz - old_tax_zz;
var _chfee = getChfee("补税", head.Agent, 2, _, _C, "关税补税");
var _chfee2 = getChfee("补税", head.Agent, 2, _, _C, "增值税补税");
chfeelist.Add(_chfee);
chfeelist.Add(_chfee2);
= +_;
= + _;
}
}
if ( + == )
{
//只有限价产生补税
}
else
{
var 退 = - ( + ) + - ( + );
if (退 > 0)
{
var _chfee = getChfee("补税", head.Agent, 2, 退,"汇率差补税");
chfeelist.Add(_chfee);
} else
{
var _chfee = getChfee("退税", head.Agent, 1, 0-退, "汇率差退税");
chfeelist.Add(_chfee);
}
}
} else
if (Convert.ToDecimal(tax) < )
{
var 退 = - Convert.ToDecimal(tax) ;
var _chfee = getChfee("退税", head.Agent, 1, 退,"");
chfeelist.Add(_chfee);
}
var modb = new ModelObjectRepository();
DBResult result = modb.SaveComm("BsNo", ContractNo,
ModelObjectConvert<MsChFee2>.ToModelObjectList(chfeelist),
null
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
private MsChFee2 getChfee ( string FeeName, string CustomerName, decimal FeeType, decimal Amount,string remark )
{
var _chfee = new MsChFee2();
_chfee.GId = System.Guid.NewGuid().ToString();
_chfee.BsNo = "";
_chfee.FeeStatus = 1;
_chfee.FeeType = FeeType;
if (FeeType == 2)
{
_chfee.FeeName = "补税";
}
else {
_chfee.FeeName = "退税";
}
_chfee.CustomerName = CustomerName;
_chfee.UnitPrice = Amount;
//_chfee.Tax=关税补税;
_chfee.Quantity = 1;
_chfee.Amount = Amount;
//_chfee.NoTaxAmount
_chfee.Currency = "RMB";
_chfee.ExChangerate = 1;
_chfee.Remark = FeeName;
_chfee.Commissionrate = 0;
_chfee.Settlement = 0;
_chfee.Invoice = 0;
_chfee.OrderAmount = 0;
_chfee.OrderInvoice = 0;
_chfee.EnteroPerator = Session["USERID"].ToString();
_chfee.EnterDate = DateTime.Now;
_chfee.IsDebit = "0";
_chfee.IsOpen = "0";
_chfee.IsAdvancedpay = "0";
_chfee.IsInvoice = "0";
_chfee.FeeFrt = "PP";
_chfee.IsCrmOrderFee = "0";
_chfee.AuditStatus = 0;
_chfee.MODIFIEDTIME = DateTime.Now.ToString();
_chfee.MODIFIEDUSER = Session["USERID"].ToString();
return _chfee;
}
private MsChFee2 getChfee ( string FeeName, string CustomerName, decimal FeeType, decimal Amount ,Cargomb2 _C,string remark)
{
var _chfee = new MsChFee2();
_chfee.GId = System.Guid.NewGuid().ToString();
_chfee.BsNo = "";
_chfee.FeeStatus = 1;
_chfee.FeeType = FeeType;
if (FeeType == 2)
{
_chfee.FeeName = "补税";
}
else
{
_chfee.FeeName = "退税";
}
_chfee.CustomerName = CustomerName;
_chfee.UnitPrice = Amount;
//_chfee.Tax=关税补税;
_chfee.Quantity = 1;
_chfee.Amount = Amount;
//_chfee.NoTaxAmount
_chfee.Currency = "RMB";
_chfee.ExChangerate = 1;
_chfee.Remark = _C.name + ' ' + FeeName + ' ' + remark;
_chfee.Commissionrate = 0;
_chfee.Settlement = 0;
_chfee.Invoice = 0;
_chfee.OrderAmount = 0;
_chfee.OrderInvoice = 0;
_chfee.EnteroPerator = Session["USERID"].ToString();
_chfee.EnterDate = DateTime.Now;
_chfee.IsDebit = "0";
_chfee.IsOpen = "0";
_chfee.IsAdvancedpay = "0";
_chfee.IsInvoice = "0";
_chfee.FeeFrt = "PP";
_chfee.IsCrmOrderFee = "0";
_chfee.AuditStatus = 0;
_chfee.MODIFIEDTIME = DateTime.Now.ToString();
_chfee.MODIFIEDUSER = Session["USERID"].ToString();
_chfee.BXGID = _C.GID;
return _chfee;
}
#endregion
}
}