using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNetCore.Mvc;using WMS.BZWeb; using WMS.Core; using WMS.Core._02Entity; using WMS.Core._02Entity.FeiXu; using WMS.Core.APPBLL; using WMS.Core.ServiceCore; using WMS.Info; using WMS.Info.Dto; using WMS.Util; namespace WMS.BZWeb { [Area("OrderManager")] public class StockOutOrderController : MvcControllerBase { private FxStockOutOrderCore bll = new FxStockOutOrderCore(); #region 视图功能 /// /// 订单管理页面 /// /// [HttpGet] public ActionResult Index() { return View(); } /// /// So单下载 /// /// [HttpGet] public ActionResult SoForm() { return View(); } /// /// 领料单下载 /// /// [HttpGet] public ActionResult MatForm() { return View(); } /// /// 指定出库 /// /// [HttpGet] public ActionResult AssignForm() { return View(); } /// /// 查看实际出库明细 /// /// [HttpGet] public ActionResult DetailIndex() { return View(); } #endregion #region 获取数据 /// /// 查询单据明细 /// /// 分页参数 /// 查询条件函数 /// [HttpGet] ////[AjaxOnly] public ActionResult GetStockOutOrderPageList(string pagination, string queryJson) { Pagination paginationobj = InitPagination(pagination); return ToPageDataResult(paginationobj, bll.GetStockOutOrderPageList(paginationobj, queryJson)); } /// /// 分页查询 /// /// 分页参数 /// 查询条件函数 /// [HttpGet] ////[AjaxOnly] public ActionResult GetStockOutOrdeItem(string OrderNo) { var data = bll.GeSockOutOrderItem(OrderNo); return Success("", data); } /// /// 分页查询 /// /// 分页参数 /// 查询条件函数 /// [HttpPost] ////[AjaxOnly] public ActionResult GetMatInventory(string pNo) { var data = bll.GetMatInventory(pNo); List invs = new List(); var orderLines = bll.GeSockOutOrderItem(pNo).Where(c => c.F_planQty != c.F_actualQty); foreach (var line in orderLines) { foreach (var item in data.OrderBy(c => c.F_editTime)) { int needQty = invs.Sum(s => s.F_AssignQty); int quantity = item.F_quantity; if (needQty < line.F_planQty) { if ((line.F_planQty - needQty) < quantity) quantity = line.F_planQty - needQty; invs.Add(new StockLineDetailRequest { F_matNo = item.F_matNo, F_matName = item.F_matName, F_matType = item.F_matType, F_trayNo = item.F_trayNo, F_quantity = item.F_quantity, F_AssignQty = quantity, F_boxNo = item.F_boxNo, F_projectNo = item.F_projectNo }); } } } if (!invs.Any()) return Fail("没有库存信息!"); return Success("", new { data = invs, sumQty = invs.Sum(s => s.F_AssignQty) }); } /// /// 获取拣选口 /// /// 分页参数 /// 查询条件函数 /// [HttpGet] ////[AjaxOnly] public ActionResult PointQuery(int type) { List lstPoint = new List(); if (type == 0) { lstPoint.AddRange(new PointBll().Query(new Info.Models.PointQueryRequest() { PointType = (int)EPointType.YLCKJXK })); lstPoint.AddRange(new PointBll().Query(new Info.Models.PointQueryRequest() { PointType = (int)EPointType.CPCKJXK })); } else { lstPoint = new PointBll().Query(new Info.Models.PointQueryRequest() { PointType = type }); } List treeList = new List(); foreach (var item in lstPoint) { TreeModel node = new TreeModel(); node.id = item.F_no; node.text = item.F_name; node.value = item.F_no; node.showcheck = true; node.checkstate = 0; node.isexpand = true; node.icon = ACLAuthorize.IcoAuthorize; node.parentId = ""; treeList.Add(node); } return Success("", treeList); } /// /// 查询单据明细 /// /// 分页参数 /// 查询条件函数 /// [HttpGet] ////[AjaxOnly] public ActionResult GetAssignFormData(string pno) { return Success("", bll.GetAssignFormData(pno)); } /// /// 获取实际出库明细 /// /// 主键值 /// [HttpGet] ////[AjaxOnly] public ActionResult GetStockOutDetail(string pno, string keyword) { var data = bll.GetStockOutDetail(pno, keyword); return Success("", data); } #endregion #region 提交数据 /// /// 删除订单明细数据 /// /// 主键值 /// [HttpPost] ////[AjaxOnly] public ActionResult DeleteForm(string keyValue) { LoginUserInfo LoginUser = LoginBLLCore.GetLoginUser(); bll.CanelEntity(LoginUser, keyValue); return Success("作废成功。"); } /// /// 下载销售单 /// /// 出库单据数据 /// public ActionResult DownSo(string soJson) { try { var sod = soJson.ToObject(); var orderLines = FxDbCore.GetData($"select sod_nbr,sod_line,sod_part,sod_um,sod_qty_ord,sod_qty_ship from pub.sod_det where sod_domain='AFCN' and sod_site='SUZ' and sod_nbr='{sod.sod_nbr}' and sod_line={sod.sod_line} "); if (!orderLines.Any()) return Fail($"找不到该销售单的出库明细!"); return Success("", orderLines); } catch (Exception e) { return Fail($"获取出库单单信息失败{e.Message}"); } } /// /// 下载领料单 /// /// 出库单据数据 /// public ActionResult DownMatSo(string IssNbr) { try { if (string.IsNullOrWhiteSpace(IssNbr)) return Fail("领料单号不能为空"); var orderLines = FxDbCore.GetData($"select \"Domain\",FromSite,FromWhse,FromLoc,FromPart,FromLot,FromRef,ToSite,ToWhse,ToLoc,ToPart,ToLot,ToRef,TrType,Task,WLocGp,IssNbr,QtyExp from pub.TranD where \"Domain\"='AFCN' and site = 'SUZ' and FromSite ='SUZ' and FromWhse='31' and ToWhse='31' and ToSite='SUZ' and Task='PICK' and IssNbr='{IssNbr}' "); if (!orderLines.Any()) return Fail($"找不到该领料单的出库明细!"); return Success("", orderLines); } catch (Exception e) { return Fail($"获取出库单单信息失败{e.Message}"); } } /// /// 保存领料任务 /// /// 实体集合Json /// [HttpPost] ////[AjaxOnly] public ActionResult SoMatSave(string soJson, string formJson) { if (string.IsNullOrEmpty(soJson)) throw SysExCore.ThrowFailException("未选择数据"); var sods = soJson.ToObject>(); var stockOut = formJson.ToObject(); LoginUserInfo LoginUser = LoginBLLCore.GetLoginUser(); bll.SoMatSave(stockOut, sods, LoginUser); return Success("保存成功。", ""); } /// /// 保存 /// /// 实体集合Json /// [HttpPost] ////[AjaxOnly] public ActionResult SoSave(string soJson) { if (string.IsNullOrEmpty(soJson)) throw SysExCore.ThrowFailException("未选择数据"); var sods = soJson.ToObject>(); if (sods == null) throw SysExCore.ThrowFailException("请求数据不能为空"); LoginUserInfo LoginUser = LoginBLLCore.GetLoginUser(); bll.SoSave(sods, LoginUser); return Success("保存成功。", ""); } /// /// 出库保存 /// /// 实体集合Json /// [HttpPost] ////[AjaxOnly] public ActionResult AssignSave(string soJson, string formJson) { if (string.IsNullOrEmpty(soJson)) throw SysExCore.ThrowFailException("未选择数据"); var stockOutDetail = soJson.ToObject>(); var stockOut = formJson.ToObject(); LoginUserInfo LoginUser = LoginBLLCore.GetLoginUser(); bll.AssignCreate(stockOut, stockOutDetail.FindAll(c => c.F_quantity > 0), LoginUser); return Success("保存成功。", ""); } /// /// 系统推荐出库保存 /// /// 实体集合Json /// [HttpPost] ////[AjaxOnly] public ActionResult SystemAssignSave(string no) { if (string.IsNullOrEmpty(no)) throw SysExCore.ThrowFailException("未选择数据"); LoginUserInfo LoginUser = LoginBLLCore.GetLoginUser(); bll.SystemAssignCreate(no, LoginUser); return Success("保存成功。", ""); } #endregion } }