380 lines
12 KiB
C#
380 lines
12 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using WalkingTec.Mvvm.Core;
|
|
using WalkingTec.Mvvm.Mvc;
|
|
using WalkingTec.Mvvm.Core.Extensions;
|
|
using HHWMS.Web.Models;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace HHWMS.Web.Controllers
|
|
{
|
|
[Area("receipt")]
|
|
[ActionDescription("入库单明细")]
|
|
public partial class ReceiptDetailController : BaseController
|
|
{
|
|
private readonly IUnitWork _unitwork;
|
|
public ReceiptDetailController(IUnitWork unitwork)
|
|
{
|
|
_unitwork = unitwork;
|
|
}
|
|
#region Search
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Index()
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetailListVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
[HttpPost]
|
|
public string Search(ReceiptDetailSearcher searcher)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetailListVM>(passInit: true);
|
|
if (ModelState.IsValid)
|
|
{
|
|
vm.Searcher = searcher;
|
|
return vm.GetJson(false);
|
|
}
|
|
else
|
|
{
|
|
return vm.GetError();
|
|
}
|
|
}
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
[HttpPost]
|
|
public string Search2(ReceiptDetailListVM2 vm)
|
|
{
|
|
vm.Searcher.Page = vm.FC.GetValue<int>("Page");
|
|
vm.Searcher.Limit = vm.FC.GetValue<int>("Limit");
|
|
return vm.GetJson(false);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Create
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult Create()
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetailVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult Create(ReceiptDetailVM vm)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
vm.DoAdd();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
vm.DoReInit();
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid();
|
|
}
|
|
}
|
|
}
|
|
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult Create2(int id)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetailVM>(passInit: true);
|
|
vm.Entity.ReceiptHeaderId = id;
|
|
vm.Entity.ReceiptHeader = new ReceiptHeader();
|
|
//vm.Entity.ReceiptHeader.Code = vm.DC.Set<ReceiptHeader>().Find(id).Code;
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult Create2(ReceiptDetailVM vm)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
vm.DoAdd();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
vm.DoReInit();
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid(index: 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult CreateDetails(int id)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetailVM>(passInit: true);
|
|
vm.Entity.ReceiptHeaderId = id;
|
|
vm.Entity.ReceiptHeader = new ReceiptHeader();
|
|
//vm.Entity.ReceiptHeader.Code = vm.DC.Set<ReceiptHeader>().Find(id).Code;
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult CreateDetails(ReceiptDetailVM vm)
|
|
{
|
|
var header = _unitwork.FindSingle<ReceiptHeader>(x => x.ID == vm.Entity.ReceiptHeaderId);
|
|
if(header.FirstStatus != ReceiptStatusEnum.新建)
|
|
{
|
|
return FFResult().Alert("主单据不是新建状态,不能新建明细!");
|
|
}
|
|
var plList = vm.Entity.MaterialCode.Split("\n");
|
|
var slList = vm.Entity.Lot.Split("\n");
|
|
var detailList = new List<ReceiptDetail>();
|
|
foreach(var item in plList)
|
|
{
|
|
if (!string.IsNullOrEmpty(item))
|
|
{
|
|
detailList.Add(new ReceiptDetail
|
|
{
|
|
UniqueCode = item,
|
|
Status = 0,
|
|
ZoneCode = ZoneCodeEnum.盘料库,
|
|
ReceiptHeaderId = vm.Entity.ReceiptHeaderId
|
|
});
|
|
}
|
|
}
|
|
|
|
foreach (var item in slList)
|
|
{
|
|
if (!string.IsNullOrEmpty(item))
|
|
{
|
|
detailList.Add(new ReceiptDetail
|
|
{
|
|
UniqueCode = item,
|
|
ZoneCode = ZoneCodeEnum.散料库,
|
|
Status = 0,
|
|
ReceiptHeaderId = vm.Entity.ReceiptHeaderId
|
|
});
|
|
}
|
|
}
|
|
var uniqueGroup = detailList.GroupBy(x => x.UniqueCode);
|
|
|
|
if (uniqueGroup.Any(x => x.Count() > 1))
|
|
{
|
|
var codeList = uniqueGroup.Where(x => x.Count() > 1)
|
|
.Select(x => x.Key)
|
|
.ToList();
|
|
return FFResult().Alert($"新增明细中,存在重复的唯一码!{String.Join(", ", codeList.ToArray())}");
|
|
}
|
|
|
|
// 判断唯一码是否已在库内
|
|
var reDetailList = _unitwork.Find<ReceiptDetail>(x => x.Status == ReceiptStatusEnum.新建)
|
|
.Select(x => new { x.UniqueCode, x.ReceiptHeader.Code })
|
|
.ToList();
|
|
var reDel = reDetailList.Select(x => x.UniqueCode)
|
|
.Intersect(detailList.Select(x => x.UniqueCode));
|
|
if (reDel.Count() > 0)
|
|
{
|
|
var tt= reDetailList.Where(x => reDel.Contains(x.UniqueCode))
|
|
.ToList();
|
|
var returnStr = "";
|
|
foreach (var item in tt)
|
|
{
|
|
returnStr += $"单号:{item.Code};唯一码:{item.UniqueCode};";
|
|
}
|
|
return FFResult().Alert($"新增明细中,存在已添加的唯一码!{returnStr}");
|
|
}
|
|
|
|
// 判断唯一码是否已在库内
|
|
var invList = _unitwork.Find<Inventory>(x => 1 == 1)
|
|
.Select(x => x.UniqueCode)
|
|
.ToList();
|
|
if(invList.Intersect(detailList.Select(x => x.UniqueCode)).Count() > 0)
|
|
{
|
|
return FFResult().Alert("新增明细中,存在已在库内的唯一码!");
|
|
}
|
|
// 补充物料明细
|
|
foreach (var item in detailList)
|
|
{
|
|
var materialqr = _unitwork.FindSingle<MaterialQr>(x => x.UniqueCode.Equals(item.UniqueCode));
|
|
if(materialqr == null)
|
|
{
|
|
return FFResult().Alert("新增明细中,存在不是WMS生成的唯一码!");
|
|
}
|
|
var material = _unitwork.FindSingle<Material>(x => x.QRCode.Equals(materialqr.QRCode));
|
|
item.MaterialCode = material.MaterialCode;
|
|
item.MaterialName = material.MaterialName;
|
|
item.MaterialSpec = material.MaterialSpec;
|
|
item.MaterialType = material.MaterialType;
|
|
item.MaterialUnit = material.MaterialUnit;
|
|
item.Batch = material.Batch;
|
|
item.Qty = material.Qty;
|
|
item.SupplierCode = material.SupplierCode;
|
|
item.CreateBy = Wtm.LoginUserInfo.ITCode;
|
|
item.CreateTime = DateTime.Now;
|
|
}
|
|
_unitwork.BatchAdd(detailList.ToArray());
|
|
return FFResult().CloseDialog().RefreshGrid(index: 1);
|
|
}
|
|
#endregion
|
|
|
|
#region Edit
|
|
[ActionDescription("Sys.Edit")]
|
|
public ActionResult Edit(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetailVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Edit")]
|
|
[HttpPost]
|
|
[ValidateFormItemOnly]
|
|
public ActionResult Edit(ReceiptDetailVM 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<ReceiptDetailVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Delete")]
|
|
[HttpPost]
|
|
public ActionResult Delete(string id, IFormCollection nouse)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetailVM>(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<ReceiptDetailVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
#endregion
|
|
|
|
#region BatchEdit
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult BatchEdit(string[] IDs)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetailBatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult DoBatchEdit(ReceiptDetailBatchVM 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<ReceiptDetailBatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchDelete")]
|
|
public ActionResult DoBatchDelete(ReceiptDetailBatchVM 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<ReceiptDetailImportVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Import")]
|
|
public ActionResult Import(ReceiptDetailImportVM 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(ReceiptDetailListVM vm)
|
|
{
|
|
return vm.GetExportData();
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|