394 lines
13 KiB
C#
394 lines
13 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using WalkingTec.Mvvm.Core;
|
|
using WalkingTec.Mvvm.Mvc;
|
|
using WalkingTec.Mvvm.Core.Extensions;
|
|
using HHWMS.Web;
|
|
using System.Reflection;
|
|
using HHWMS.Web.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Linq;
|
|
using NPOI.SS.Formula.Functions;
|
|
using System.Collections.Generic;
|
|
|
|
namespace HHWMS.Web.Controllers
|
|
{
|
|
[Area("shipment")]
|
|
[ActionDescription("出库单")]
|
|
public partial class ShipmentHeaderController : BaseController
|
|
{
|
|
private readonly IUnitWork _unitwork;
|
|
public ShipmentHeaderController(IUnitWork unitwork)
|
|
{
|
|
_unitwork = unitwork;
|
|
}
|
|
#region Search
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Index()
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderListVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
[HttpPost]
|
|
public string Search(ShipmentHeaderSearcher searcher)
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderListVM>(passInit: true);
|
|
if (ModelState.IsValid)
|
|
{
|
|
vm.Searcher = searcher;
|
|
return vm.GetJson(false);
|
|
}
|
|
else
|
|
{
|
|
return vm.GetError();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Create
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult Create()
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderVM>();
|
|
vm.Entity.Code = _unitwork.GetSerialNumber("SO");
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult Create(ShipmentHeaderVM vm)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
vm.Entity.FirstStatus = ShipStatusEnum.新建;
|
|
vm.Entity.BillType = "sout";
|
|
vm.DoAdd();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
vm.DoReInit();
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid();
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Edit
|
|
[ActionDescription("Sys.Edit")]
|
|
public ActionResult Edit(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Edit")]
|
|
[HttpPost]
|
|
[ValidateFormItemOnly]
|
|
public ActionResult Edit(ShipmentHeaderVM vm)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
vm.DoEdit();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
vm.DoReInit();
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Delete
|
|
[ActionDescription("Sys.Delete")]
|
|
public ActionResult Delete(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Delete")]
|
|
[HttpPost]
|
|
public ActionResult Delete(string id, IFormCollection nouse)
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderVM>(id);
|
|
vm.DoDelete();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Details
|
|
[ActionDescription("Sys.Details")]
|
|
public ActionResult Details(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderVM>(id);
|
|
vm.Details.SearcherMode = ListVMSearchModeEnum.MasterDetail;
|
|
return PartialView(vm);
|
|
}
|
|
#endregion
|
|
|
|
#region BatchEdit
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult BatchEdit(string[] IDs)
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderBatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult DoBatchEdit(ShipmentHeaderBatchVM vm, IFormCollection nouse)
|
|
{
|
|
if (!ModelState.IsValid || !vm.DoBatchEdit())
|
|
{
|
|
return PartialView("BatchEdit",vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchEditSuccess", vm.Ids.Length]);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region BatchDelete
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchDelete")]
|
|
public ActionResult BatchDelete(string[] IDs)
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderBatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchDelete")]
|
|
public ActionResult DoBatchDelete(ShipmentHeaderBatchVM vm, IFormCollection nouse)
|
|
{
|
|
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
|
{
|
|
return PartialView("BatchDelete",vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchDeleteSuccess", vm.Ids.Length]);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Import
|
|
[ActionDescription("Sys.Import")]
|
|
public ActionResult Import()
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderImportVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Import")]
|
|
public ActionResult Import(ShipmentHeaderImportVM vm, IFormCollection nouse)
|
|
{
|
|
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.ImportSuccess", vm.EntityList.Count.ToString()]);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Export
|
|
[ActionDescription("Sys.Export")]
|
|
[HttpPost]
|
|
public IActionResult ExportExcel(ShipmentHeaderListVM vm)
|
|
{
|
|
return vm.GetExportData();
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 库位分析
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[ActionDescription("ShipmentHeader.Analyse")]
|
|
public ActionResult Analyse(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回分析数据
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[ActionDescription("ShipmentHeader.Analyse")]
|
|
[HttpPost]
|
|
public ActionResult AnalyseData(int id)
|
|
{
|
|
var data = _unitwork.Find<ShipmentHeader>(x => x.ID == id)
|
|
.Include(x => x.ShipmentDetails).ToList();
|
|
var details = data.FirstOrDefault().ShipmentDetails.Where(x => x.Status < ShipStatusEnum.分配完成);
|
|
foreach (var item in details)
|
|
{
|
|
var invQty = _unitwork.FindSingle<Inventory>(x =>
|
|
x.UniqueCode.Equals(item.UniqueCode)
|
|
&& x.TaskStatus == InventoryTaskStatus.无任务);
|
|
item.InventoryStatus = invQty != null ? "满足" : "不足";
|
|
}
|
|
return JsonMore(details);
|
|
}
|
|
|
|
[ActionDescription("ShipmentHeader.ShelfInv")]
|
|
public ActionResult ShelfInv(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<ShipmentHeaderVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 货架库存
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[ActionDescription("ShipmentHeader.ShelfInv")]
|
|
public ActionResult ShelfInvData(int id)
|
|
{
|
|
var data = _unitwork.Find<ShipmentHeader>(x => x.ID == id)
|
|
.Include(x => x.ShipmentDetails)
|
|
.FirstOrDefault();
|
|
var details = data.ShipmentDetails.Where(x => x.Status < ShipStatusEnum.分配完成)
|
|
.Select(x => x.UniqueCode)
|
|
.ToList();
|
|
|
|
var invList = _unitwork.Find<Inventory>(x => x.ZoneCode.Equals(ZoneCodeEnum.货架库)
|
|
&& x.TaskStatus.Equals(InventoryTaskStatus.无任务)
|
|
&& details.Contains(x.UniqueCode))
|
|
.OrderBy(x => x.LocationCode)
|
|
.ToList();
|
|
//var details = data.ShipmentDetails.Where(x => invList.Contains(x.UniqueCode));
|
|
return JsonMore(invList);
|
|
}
|
|
|
|
[ActionDescription("ShipmentHeader.Pick")]
|
|
[HttpPost]
|
|
public ActionResult Pick(List<Binding> data, int shipId)
|
|
{
|
|
var shipment = _unitwork.Find<ShipmentHeader>(x => x.ID.Equals(shipId))
|
|
.Include(x => x.ShipmentDetails)
|
|
.FirstOrDefault();
|
|
if(shipment == null)
|
|
{
|
|
return JsonMore(null, 500, "未找到该出库单!");
|
|
}
|
|
foreach(var detail in shipment.ShipmentDetails
|
|
.Where(x => data.Select(x => x.UniqueCode).Contains(x.UniqueCode)))
|
|
{
|
|
detail.Status = ShipStatusEnum.拣货完成;
|
|
}
|
|
if (!shipment.ShipmentDetails.Any(x => x.Status < ShipStatusEnum.拣货完成))
|
|
{
|
|
shipment.FirstStatus = ShipStatusEnum.拣货完成;
|
|
}
|
|
else
|
|
{
|
|
shipment.FirstStatus = ShipStatusEnum.拣货中;
|
|
}
|
|
shipment.UpdateBy = Wtm.LoginUserInfo.ITCode;
|
|
shipment.UpdateTime = DateTime.Now;
|
|
_unitwork.Update(shipment);
|
|
|
|
var ids = data.Select(x => x.ID).ToList();
|
|
if(ids.Count > 0) {
|
|
var invList = _unitwork.Find<Inventory>(x => ids.Contains(x.ID))
|
|
.ToList();
|
|
|
|
// 加入交易表
|
|
var listInvtran = new List<InventoryTransaction>();
|
|
foreach (var inv in invList)
|
|
{
|
|
listInvtran.Add(new InventoryTransaction
|
|
{
|
|
BillType = "out",
|
|
ZoneCode = inv.ZoneCode,
|
|
BillCode = shipment.Code,
|
|
Type = inv.UniqueCode,
|
|
MaterialCode = inv.MaterialCode,
|
|
MaterialName = inv.MaterialName,
|
|
MaterialSpec = inv.MaterialSpec,
|
|
MaterialUnit = inv.MaterialUnit,
|
|
MaterialType = inv.MaterialType,
|
|
Batch = inv.Batch,
|
|
Lot = inv.Lot,
|
|
CompanyCode = inv.CompanyCode,
|
|
LocationCode = inv.LocationCode,
|
|
SupplierCode = inv.SupplierCode,
|
|
Qty = inv.Qty,
|
|
CreateTime = DateTime.Now
|
|
});
|
|
}
|
|
_unitwork.BatchAdd(listInvtran.ToArray());
|
|
|
|
// 删除库存
|
|
_unitwork.BatchDelete<Inventory>(x => data.Select(u => u.ID).Contains(x.ID));
|
|
}
|
|
return JsonMore(null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取库存数据
|
|
/// </summary>
|
|
/// <param name="uniqueCode"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public ActionResult GetInvData(string uniqueCode)
|
|
{
|
|
var data = _unitwork.Find<Inventory>(x => x.UniqueCode == uniqueCode).ToList();
|
|
return JsonMore(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启动出库
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public ActionResult StartOut(int id)
|
|
{
|
|
var data = _unitwork.FindById<ShipmentHeader>(id);
|
|
if (data != null)
|
|
{
|
|
data.FirstStatus = ShipStatusEnum.分配中;
|
|
_unitwork.Update(data);
|
|
}
|
|
return FFResult().RefreshGrid().Message("启动成功!");
|
|
}
|
|
}
|
|
}
|