460 lines
15 KiB
C#
460 lines
15 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.xwms.ViewModels.ReceiptHeader2VMs;
|
|
using HHWMS.Web.Models;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using NPOI.SS.Formula;
|
|
|
|
namespace HHWMS.Web.Controllers
|
|
{
|
|
[Area("xwms")]
|
|
[ActionDescription("入库单")]
|
|
public partial class ReceiptHeader2Controller : BaseController
|
|
{
|
|
private readonly IUnitWork _unitwork;
|
|
|
|
public ReceiptHeader2Controller(IUnitWork unitwork)
|
|
{
|
|
_unitwork = unitwork;
|
|
}
|
|
|
|
#region Search
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Index()
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptHeader2ListVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
[HttpPost]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public string Search(ReceiptHeader2Searcher searcher)
|
|
{
|
|
var dc = Wtm.CreateDC(cskey:"hangyong");
|
|
Wtm.DC = dc;
|
|
var vm = Wtm.CreateVM<ReceiptHeader2ListVM>(passInit: true);
|
|
if (ModelState.IsValid)
|
|
{
|
|
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
|
searcher.WarehouseId = int.Parse(warehouseId);
|
|
vm.Searcher = searcher;
|
|
return vm.GetJson(false);
|
|
}
|
|
else
|
|
{
|
|
return vm.GetError();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Create
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult Create()
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptHeader2VM>();
|
|
vm.Entity.Type = "QTR";
|
|
vm.Entity.UserDef2 = "HYB";
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Create")]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public ActionResult Create(ReceiptHeader2VM vm)
|
|
{
|
|
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
|
vm.Entity.WarehouseId = int.Parse(warehouseId);
|
|
vm.Entity.Code = _unitwork.GetSerialNumber("QTR");
|
|
vm.Entity.FirstStatus = 0;
|
|
vm.Entity.LastStatus = 0;
|
|
vm.Entity.TotalLines = 0;
|
|
vm.Entity.TotalQty = 0;
|
|
var dc = Wtm.CreateDC(cskey: "hangyong");
|
|
Wtm.DC = dc;
|
|
vm.Entity.SupplierName = dc.Set<Supplier>()
|
|
.FirstOrDefault(x => x.Code == vm.Entity.SupplierCode)
|
|
?.Name;
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
vm.DoAdd();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
vm.DoReInit();
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshPage();
|
|
}
|
|
}
|
|
}
|
|
|
|
[ActionDescription("Sys.Create2")]
|
|
public ActionResult Create2()
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetail2VM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Create2")]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public ActionResult Create2(ReceiptDetail2VM vm)
|
|
{
|
|
if (string.IsNullOrEmpty(vm.Entity.MaterialCode))
|
|
{
|
|
return FFResult().Alert("物料必选!");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(vm.Entity.Batch))
|
|
{
|
|
return FFResult().Alert("批次信息不能为空!");
|
|
}
|
|
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
|
var dc = Wtm.CreateDC(cskey: "hangyong");
|
|
Wtm.DC = dc;
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
var _unit = new UnitWork(Wtm);
|
|
var header = new ReceiptHeader2
|
|
{
|
|
WarehouseId = int.Parse(warehouseId),
|
|
Code = _unitwork.GetSerialNumber("SDR"),
|
|
Type = "SDR",
|
|
FirstStatus = 0,
|
|
LastStatus = 0,
|
|
TotalLines = 1,
|
|
TotalQty = 0,
|
|
};
|
|
_unit.Add(header);
|
|
|
|
vm.Entity.WarehouseId = header.WarehouseId;
|
|
vm.Entity.ReceiptId = header.ID;
|
|
vm.Entity.ReceiptCode = header?.Code;
|
|
vm.Entity.Status = 0;
|
|
var mater = dc.Set<Material2>()
|
|
.FirstOrDefault(x => x.ID == int.Parse(vm.Entity.MaterialCode));
|
|
vm.Entity.MaterialCode = mater?.Code;
|
|
vm.Entity.Lot = mater?.Specification;
|
|
vm.Entity.Unit = mater?.MasterUnit;
|
|
vm.DoAdd();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
vm.DoReInit();
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshPage();
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Edit
|
|
[ActionDescription("Sys.Edit")]
|
|
public ActionResult Edit(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptHeader2VM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Edit")]
|
|
[HttpPost]
|
|
[ValidateFormItemOnly]
|
|
public ActionResult Edit(ReceiptHeader2VM 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<ReceiptHeader2VM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Delete")]
|
|
[HttpPost]
|
|
public ActionResult Delete(string id, IFormCollection nouse)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptHeader2VM>(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<ReceiptHeader2VM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
#endregion
|
|
|
|
#region BatchEdit
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult BatchEdit(string[] IDs)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptHeader2BatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult DoBatchEdit(ReceiptHeader2BatchVM 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<ReceiptHeader2BatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchDelete")]
|
|
public ActionResult DoBatchDelete(ReceiptHeader2BatchVM 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<ReceiptHeader2ImportVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Import")]
|
|
public ActionResult Import(ReceiptHeader2ImportVM 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(ReceiptHeader2ListVM vm)
|
|
{
|
|
return vm.GetExportData();
|
|
}
|
|
#endregion
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Create3")]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public ActionResult CreateDetail3(string px,string pxName, string lot, int num)
|
|
{
|
|
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
|
var dc = Wtm.CreateDC(cskey: "hangyong");
|
|
Wtm.DC = dc;
|
|
var _unit = new UnitWork(Wtm);
|
|
using (var tran = dc.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
var receipt = new ReceiptHeader2();
|
|
receipt.WarehouseId = int.Parse(warehouseId);
|
|
receipt.Code = _unitwork.GetSerialNumber("10");
|
|
receipt.Type = "10";
|
|
receipt.FirstStatus = 0;
|
|
receipt.LastStatus = 0;
|
|
|
|
_unit.Add(receipt);
|
|
|
|
var detailList = new List<ReceiptDetail2>();
|
|
while(num > 0)
|
|
{
|
|
var detail = new ReceiptDetail2();
|
|
detail.WarehouseId = receipt.WarehouseId;
|
|
detail.ReceiptId = receipt.ID;
|
|
detail.ReceiptCode = receipt.Code;
|
|
detail.MaterialCode = lot;
|
|
detail.MaterialName = pxName;
|
|
detail.Lot = lot;
|
|
detail.Project = $"{lot}--{px}";
|
|
detail.Qty = 1;
|
|
detail.Status = 0;
|
|
detail.CreateTime = DateTime.Now;
|
|
detailList.Add(detail);
|
|
num--;
|
|
}
|
|
_unit.BatchAdd(detailList.ToArray());
|
|
|
|
receipt.TotalLines = detailList.Count();
|
|
receipt.TotalQty = detailList.Sum(x => x.Qty);
|
|
_unit.Update(receipt);
|
|
|
|
tran.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
tran.Rollback();
|
|
return JsonMore(null, 500, ex.Message);
|
|
}
|
|
}
|
|
return JsonMore(null);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Create4")]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public ActionResult CreateDetail4(List<receipt4> data)
|
|
{
|
|
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
|
var dc = Wtm.CreateDC(cskey: "hangyong");
|
|
Wtm.DC = dc;
|
|
var _unit = new UnitWork(Wtm);
|
|
using (var tran = dc.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
var receipt = new ReceiptHeader2();
|
|
receipt.WarehouseId = int.Parse(warehouseId);
|
|
receipt.Code = _unitwork.GetSerialNumber("410");
|
|
receipt.Type = "10";
|
|
receipt.FirstStatus = 0;
|
|
receipt.LastStatus = 0;
|
|
|
|
_unit.Add(receipt);
|
|
|
|
var detailList = new List<ReceiptDetail2>();
|
|
var matList = new List<Material>();
|
|
foreach(var item in data)
|
|
{
|
|
var detail = new ReceiptDetail2();
|
|
detail.WarehouseId = receipt.WarehouseId;
|
|
detail.ReceiptId = receipt.ID;
|
|
detail.ReceiptCode = receipt.Code;
|
|
detail.MaterialCode = item.JH;
|
|
detail.MaterialName = item.JH;
|
|
detail.Lot = item.Lot;
|
|
detail.Sn = item.Sn;
|
|
detail.Qty = item.Qty;
|
|
detail.Project = item.JH;
|
|
detail.InventoryStatus = "1";
|
|
detail.UserDef1 = item.Lot;
|
|
detail.UserDef2 = item.PH;
|
|
detail.Status = 0;
|
|
detail.CreateTime = DateTime.Now;
|
|
detailList.Add(detail);
|
|
|
|
matList.Add(new Material
|
|
{
|
|
UniqueCode = item.JH,
|
|
MaterialSpec = item.Lot,
|
|
MaterialType = item.Sn,
|
|
Qty = item.Qty,
|
|
Batch = item.PH,
|
|
CreateTime = DateTime.Now,
|
|
});
|
|
}
|
|
_unitwork.BatchAdd(matList.ToArray());
|
|
_unit.BatchAdd(detailList.ToArray());
|
|
|
|
receipt.TotalLines = detailList.Count();
|
|
receipt.TotalQty = detailList.Sum(x => x.Qty);
|
|
_unit.Update(receipt);
|
|
|
|
tran.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
tran.Rollback();
|
|
return JsonMore(null, 500, ex.Message);
|
|
}
|
|
}
|
|
return JsonMore(null);
|
|
}
|
|
}
|
|
|
|
public class receipt4
|
|
{
|
|
/// <summary>
|
|
/// 卷号
|
|
/// </summary>
|
|
public string JH { get; set; }
|
|
public decimal Qty { get; set; }
|
|
public decimal Len { get; set; }
|
|
public string Lot { get; set; }
|
|
public string Sn { get; set;}
|
|
/// <summary>
|
|
/// 片厚
|
|
/// </summary>
|
|
public string PH { get; set; }
|
|
}
|
|
}
|