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(data.Replace("}", ",") + data2.Replace("{", "").Replace("}", ",") + data3.Replace("{", "")); var head = JsonConvert.Deserialize(data); var CargobodyList = JsonConvert.Deserialize>(CargoBody); var CargodelbodyList = JsonConvert.Deserialize>(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.ToModelObjectList(CargobodyList), ModelObjectConvert.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(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 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 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 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>(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>(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 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 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(); wmsinlist.Add(WMSIN); var wmsinlistdel = new List(); var modb = new ModelObjectRepository(); DBResult result = modb.Save(head, ModelObjectConvert.ToModelObjectList(wmsinlist), ModelObjectConvert.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>(Cargobody); var WMSImportMain = JsonConvert.Deserialize>(Cargobody); var modb = new ModelObjectRepository(); DBResult result = modb.Save( ModelObjectConvert.ToModelObjectList(CargobodyList) ); result = modb.Save( ModelObjectConvert.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 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(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 ( ) { 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) }; } 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(); 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.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 } }