325 lines
9.5 KiB
C#
325 lines
9.5 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Linq;
|
|
using WalkingTec.Mvvm.Core;
|
|
using WalkingTec.Mvvm.Core.Extensions;
|
|
using WalkingTec.Mvvm.Mvc;
|
|
using HHWMS.Web;
|
|
using HHWMS.Web.Models;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace HHWMS.Web.Controllers
|
|
{
|
|
[Area("inventory")]
|
|
[ActionDescription("库存交易")]
|
|
public partial class InventoryTransactionController : BaseController
|
|
{
|
|
private readonly IUnitWork _unitwork;
|
|
|
|
public InventoryTransactionController(IUnitWork unitwork)
|
|
{
|
|
_unitwork = unitwork;
|
|
}
|
|
|
|
#region Search
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Index()
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryTransactionListVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
[HttpPost]
|
|
public string Search(InventoryTransactionSearcher searcher)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryTransactionListVM>(passInit: true);
|
|
if (ModelState.IsValid)
|
|
{
|
|
vm.Searcher = searcher;
|
|
return vm.GetJson(false);
|
|
}
|
|
else
|
|
{
|
|
return vm.GetError();
|
|
}
|
|
}
|
|
|
|
#endregion Search
|
|
|
|
#region Create
|
|
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult Create()
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryTransactionVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult Create(InventoryTransactionVM vm)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
vm.DoAdd();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
vm.DoReInit();
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Create
|
|
|
|
#region Edit
|
|
|
|
[ActionDescription("Sys.Edit")]
|
|
public ActionResult Edit(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryTransactionVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Edit")]
|
|
[HttpPost]
|
|
[ValidateFormItemOnly]
|
|
public ActionResult Edit(InventoryTransactionVM 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 Edit
|
|
|
|
#region Delete
|
|
|
|
[ActionDescription("Sys.Delete")]
|
|
public ActionResult Delete(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryTransactionVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Delete")]
|
|
[HttpPost]
|
|
public ActionResult Delete(string id, IFormCollection nouse)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryTransactionVM>(id);
|
|
vm.DoDelete();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid();
|
|
}
|
|
}
|
|
|
|
#endregion Delete
|
|
|
|
#region Details
|
|
|
|
[ActionDescription("Sys.Details")]
|
|
public ActionResult Details(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryTransactionVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
#endregion Details
|
|
|
|
#region BatchEdit
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult BatchEdit(string[] IDs)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryTransactionBatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult DoBatchEdit(InventoryTransactionBatchVM 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 BatchEdit
|
|
|
|
#region BatchDelete
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchDelete")]
|
|
public ActionResult BatchDelete(string[] IDs)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryTransactionBatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchDelete")]
|
|
public ActionResult DoBatchDelete(InventoryTransactionBatchVM 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 BatchDelete
|
|
|
|
#region Import
|
|
|
|
[ActionDescription("Sys.Import")]
|
|
public ActionResult Import()
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryTransactionImportVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Import")]
|
|
public ActionResult Import(InventoryTransactionImportVM 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 Import
|
|
|
|
#region Export
|
|
|
|
[ActionDescription("Sys.Export")]
|
|
[HttpPost]
|
|
public IActionResult ExportExcel(InventoryTransactionListVM vm)
|
|
{
|
|
return vm.GetExportData();
|
|
}
|
|
|
|
#endregion Export
|
|
|
|
#region ERP领料出库补传
|
|
|
|
[AllRights]
|
|
[ActionDescription("补传ERP领料出库")]
|
|
public async Task<ActionResult> RetryAddOtherOut(string id)
|
|
{
|
|
if (!int.TryParse(id, out var transactionId))
|
|
{
|
|
return FFResult().Alert("库存交易记录参数错误").RefreshGrid();
|
|
}
|
|
|
|
var transaction = _unitwork.FindSingle<InventoryTransaction>(x => x.ID == transactionId);
|
|
if (transaction == null)
|
|
{
|
|
return FFResult().Alert("库存交易记录不存在").RefreshGrid();
|
|
}
|
|
|
|
if (transaction.Type != InventoryTranType.出库
|
|
|| transaction.BillType != InventoryTransaction.ErpOtherOutBillType)
|
|
{
|
|
return FFResult().Alert("只有线边库领料出库记录允许回传ERP").RefreshGrid();
|
|
}
|
|
|
|
if (transaction.UploadErpFlag == 1)
|
|
{
|
|
return FFResult().Alert("该出库记录已成功回传ERP,无需重复操作").RefreshGrid();
|
|
}
|
|
|
|
var vm = Wtm.CreateVM<InventoryVM>();
|
|
var success = await vm.ProcessErpOtherOut(transaction);
|
|
return success
|
|
? FFResult().Alert("回传ERP成功").RefreshGrid()
|
|
: FFResult().Alert("回传ERP失败").RefreshGrid();
|
|
}
|
|
|
|
#endregion ERP领料出库补传
|
|
|
|
#region ERP成品出库补传
|
|
|
|
[ActionDescription("补传ERP成品出库")]
|
|
public async Task<ActionResult> RetryAddSaleOut(string id)
|
|
{
|
|
if (!int.TryParse(id, out var transactionId))
|
|
{
|
|
return FFResult().Alert("库存交易记录参数错误").RefreshGrid();
|
|
}
|
|
|
|
var transaction = _unitwork.FindSingle<InventoryTransaction>(x => x.ID == transactionId);
|
|
if (transaction == null)
|
|
{
|
|
return FFResult().Alert("库存交易记录不存在").RefreshGrid();
|
|
}
|
|
|
|
if (transaction.Type != InventoryTranType.出库
|
|
|| transaction.BillType != InventoryTransaction.ErpSaleOutBillType)
|
|
{
|
|
return FFResult().Alert("只有成品发货出库记录允许执行此补传").RefreshGrid();
|
|
}
|
|
|
|
if (transaction.UploadErpFlag == 1)
|
|
{
|
|
return FFResult().Alert("该批次已成功回传ERP,无需重复操作").RefreshGrid();
|
|
}
|
|
|
|
var transactions = _unitwork.Find<InventoryTransaction>(x =>
|
|
x.BillType == InventoryTransaction.ErpSaleOutBillType
|
|
&& x.BillCode == transaction.BillCode
|
|
&& x.UploadErpFlag != 1)
|
|
.ToList();
|
|
var vm = Wtm.CreateVM<InventoryVM>();
|
|
var success = await vm.ProcessErpSaleOut(transactions, true);
|
|
return success
|
|
? FFResult().Alert("本批成品出库回传ERP成功").RefreshGrid()
|
|
: FFResult().Alert("本批成品出库回传ERP失败").RefreshGrid();
|
|
}
|
|
|
|
#endregion ERP成品出库补传
|
|
}
|
|
}
|