347 lines
11 KiB
C#
347 lines
11 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 HHWMS.Web.Models;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using System.Web;
|
|
|
|
namespace HHWMS.Web.Controllers
|
|
{
|
|
[Area("xwms")]
|
|
[ActionDescription("入库明细")]
|
|
public partial class ReceiptDetail2Controller : BaseController
|
|
{
|
|
private readonly IUnitWork _unitwork;
|
|
|
|
public ReceiptDetail2Controller(IUnitWork unitwork)
|
|
{
|
|
_unitwork = unitwork;
|
|
}
|
|
|
|
#region Search
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Index()
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetail2ListVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
[HttpPost]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public string Search(ReceiptDetail2Searcher searcher)
|
|
{
|
|
var dc = Wtm.CreateDC(cskey: "hangyong");
|
|
Wtm.DC = dc;
|
|
var vm = Wtm.CreateVM<ReceiptDetail2ListVM>(passInit: true);
|
|
if (ModelState.IsValid)
|
|
{
|
|
vm.Searcher = searcher;
|
|
return vm.GetJson(false);
|
|
}
|
|
else
|
|
{
|
|
return vm.GetError();
|
|
}
|
|
}
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
[HttpPost]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public string Search2(ReceiptDetail2ListVM vm)
|
|
{
|
|
var dc = Wtm.CreateDC(cskey: "hangyong");
|
|
Wtm.DC = dc;
|
|
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(int id)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetail2VM>();
|
|
vm.Entity.ReceiptId = id;
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Create")]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public ActionResult Create(ReceiptDetail2VM vm)
|
|
{
|
|
var dc = Wtm.CreateDC(cskey: "hangyong");
|
|
Wtm.DC = dc;
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
var header = dc.Set<ReceiptHeader2>()
|
|
.FirstOrDefault(x => x.ID == vm.Entity.ReceiptId);
|
|
vm.Entity.WarehouseId = header.WarehouseId;
|
|
vm.Entity.ReceiptCode = header?.Code;
|
|
var detailList = dc.Set<ReceiptDetail2>()
|
|
.Where(x => x.ReceiptId == vm.Entity.ReceiptId).ToList();
|
|
vm.Entity.SourceLine = (detailList.Count() + 1).ToString();
|
|
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.Unit = mater?.MasterUnit;
|
|
vm.Entity.Batch = vm.Entity.Batch = _unitwork.GetSerialNumber("HYB", 5).Remove(3, 2);
|
|
vm.DoAdd();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
vm.DoReInit();
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid(index: 1);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Edit
|
|
[ActionDescription("Sys.Edit")]
|
|
public ActionResult Edit(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetail2VM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Edit")]
|
|
[HttpPost]
|
|
[ValidateFormItemOnly]
|
|
public ActionResult Edit(ReceiptDetail2VM vm)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
vm.DoEdit();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
vm.DoReInit();
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGridRow((long)vm.Entity.ID);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Delete
|
|
[ActionDescription("Sys.Delete")]
|
|
public ActionResult Delete(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetail2VM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Delete")]
|
|
[HttpPost]
|
|
public ActionResult Delete(string id, IFormCollection nouse)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetail2VM>(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<ReceiptDetail2VM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
#endregion
|
|
|
|
#region BatchEdit
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult BatchEdit(string[] IDs)
|
|
{
|
|
var vm = Wtm.CreateVM<ReceiptDetail2BatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult DoBatchEdit(ReceiptDetail2BatchVM 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<ReceiptDetail2BatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchDelete")]
|
|
public ActionResult DoBatchDelete(ReceiptDetail2BatchVM 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<ReceiptDetail2ImportVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Import")]
|
|
public ActionResult Import(ReceiptDetail2ImportVM 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(ReceiptDetail2ListVM vm)
|
|
{
|
|
return vm.GetExportData();
|
|
}
|
|
#endregion
|
|
|
|
[ActionDescription("Sys.Print")]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public ActionResult Print(string id)
|
|
{
|
|
var dc = Wtm.CreateDC(cskey: "hangyong");
|
|
Wtm.DC = dc;
|
|
var vm = Wtm.CreateVM<ReceiptDetail2VM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Prints")]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public ActionResult Prints(string ids)
|
|
{
|
|
return Ok();
|
|
}
|
|
|
|
[ActionDescription("Sys.SearchDetail")]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public ActionResult SearchDetail(int id)
|
|
{
|
|
var dc = Wtm.CreateDC(cskey: "hangyong");
|
|
Wtm.DC = dc;
|
|
var data = dc.Set<ReceiptDetail2>().Where(x => x.ID == id);
|
|
return JsonMore(data);
|
|
}
|
|
|
|
[ActionDescription("Sys.ChaiDetail")]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public ActionResult ChaiDetail(List<ReceiptDetail> data)
|
|
{
|
|
var dc = Wtm.CreateDC(cskey: "hangyong");
|
|
Wtm.DC = dc;
|
|
var _unit = new UnitWork(Wtm);
|
|
|
|
using (var tran = dc.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
var receipt = _unit.FindSingle<ReceiptDetail2>(x =>
|
|
x.MaterialCode == data.FirstOrDefault().MaterialCode
|
|
&& x.Batch == data.FirstOrDefault().Batch);
|
|
if (receipt != null)
|
|
{
|
|
receipt.Qty = data.FirstOrDefault().Qty;
|
|
_unit.Update(receipt);
|
|
|
|
var ll = new List<ReceiptDetail2>();
|
|
foreach (var item in data.Skip(1))
|
|
{
|
|
var detail = new ReceiptDetail2();
|
|
detail.WarehouseId = receipt.WarehouseId;
|
|
detail.ReceiptId = receipt.ReceiptId;
|
|
detail.ReceiptCode = receipt.ReceiptCode;
|
|
detail.SourceCode = receipt.SourceCode;
|
|
detail.SourceLine = receipt.SourceLine;
|
|
detail.MaterialCode = receipt.MaterialCode;
|
|
detail.MaterialName = receipt.MaterialName;
|
|
detail.Lot = receipt.Lot;
|
|
detail.SupplierCode = receipt.SupplierCode;
|
|
detail.SupplierName = receipt.SupplierName;
|
|
detail.Qty = item.Qty;
|
|
detail.Unit = receipt.Unit;
|
|
detail.PurchasQty = receipt.PurchasQty;
|
|
detail.PurchasUnits = receipt.PurchasUnits;
|
|
detail.InventoryStatus = receipt.InventoryStatus;
|
|
detail.Batch = receipt.Batch;
|
|
detail.Status = 0;
|
|
detail.CreateTime = DateTime.Now;
|
|
ll.Add(detail);
|
|
}
|
|
_unit.BatchAdd(ll.ToArray());
|
|
tran.Commit();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
tran.Rollback();
|
|
return JsonMore(null, 500, ex.Message);
|
|
}
|
|
}
|
|
return JsonMore(null);
|
|
}
|
|
}
|
|
}
|