528 lines
18 KiB
C#
528 lines
18 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.Linq;
|
||
using System.Data;
|
||
using HHWMS.Web.Models;
|
||
using System.Collections.Generic;
|
||
using System.Web;
|
||
using NPOI.SS.Formula.Functions;
|
||
|
||
namespace HHWMS.Web.Controllers
|
||
{
|
||
[Area("xwms")]
|
||
[ActionDescription("出库单")]
|
||
public partial class ShipmentHeader2Controller : BaseController
|
||
{
|
||
|
||
public ShipmentHeader2Controller()
|
||
{
|
||
}
|
||
|
||
#region Search
|
||
[ActionDescription("Sys.Search")]
|
||
public ActionResult Index()
|
||
{
|
||
var vm = Wtm.CreateVM<ShipmentHeader2ListVM>();
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[ActionDescription("Sys.Search")]
|
||
[HttpPost]
|
||
[FixConnection(CsName = "hangyong")]
|
||
public string Search(ShipmentHeader2Searcher searcher)
|
||
{
|
||
var dc = Wtm.CreateDC(cskey: "hangyong");
|
||
Wtm.DC = dc;
|
||
var vm = Wtm.CreateVM<ShipmentHeader2ListVM>(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<ShipmentHeader2VM>();
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[HttpPost]
|
||
[ActionDescription("Sys.Create")]
|
||
[FixConnection(CsName = "hangyong")]
|
||
public ActionResult Create(ShipmentHeader2VM vm)
|
||
{
|
||
var dc = Wtm.CreateDC(cskey: "hangyong");
|
||
Wtm.DC = dc;
|
||
if (!ModelState.IsValid)
|
||
{
|
||
return PartialView(vm);
|
||
}
|
||
else
|
||
{
|
||
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<ShipmentHeader2VM>(id);
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[ActionDescription("Sys.Edit")]
|
||
[HttpPost]
|
||
[ValidateFormItemOnly]
|
||
public ActionResult Edit(ShipmentHeader2VM 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<ShipmentHeader2VM>(id);
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[ActionDescription("Sys.Delete")]
|
||
[HttpPost]
|
||
public ActionResult Delete(string id, IFormCollection nouse)
|
||
{
|
||
var vm = Wtm.CreateVM<ShipmentHeader2VM>(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<ShipmentHeader2VM>(id);
|
||
return PartialView(vm);
|
||
}
|
||
#endregion
|
||
|
||
#region BatchEdit
|
||
[HttpPost]
|
||
[ActionDescription("Sys.BatchEdit")]
|
||
public ActionResult BatchEdit(string[] IDs)
|
||
{
|
||
var vm = Wtm.CreateVM<ShipmentHeader2BatchVM>(Ids: IDs);
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[HttpPost]
|
||
[ActionDescription("Sys.BatchEdit")]
|
||
public ActionResult DoBatchEdit(ShipmentHeader2BatchVM 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<ShipmentHeader2BatchVM>(Ids: IDs);
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[HttpPost]
|
||
[ActionDescription("Sys.BatchDelete")]
|
||
public ActionResult DoBatchDelete(ShipmentHeader2BatchVM 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<ShipmentHeader2ImportVM>();
|
||
return PartialView(vm);
|
||
}
|
||
|
||
[HttpPost]
|
||
[ActionDescription("Sys.Import")]
|
||
public ActionResult Import(ShipmentHeader2ImportVM 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(ShipmentHeader2ListVM vm)
|
||
{
|
||
return vm.GetExportData();
|
||
}
|
||
#endregion
|
||
|
||
[ActionDescription("Sys.CreateOut")]
|
||
public ActionResult CreateOut()
|
||
{
|
||
return PartialView("CreateOut");
|
||
}
|
||
[ActionDescription("Sys.CreateOut")]
|
||
[FixConnection(CsName = "hangyong")]
|
||
public ActionResult CreateOutBill(string tran, List<Inventory2> data)
|
||
{
|
||
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
||
var _unitwork = new UnitWork(Wtm);
|
||
var dc = Wtm.CreateDC(cskey: "hangyong");
|
||
|
||
using (var trans = dc.BeginTransaction())
|
||
{
|
||
try
|
||
{
|
||
var shipment = new ShipmentHeader2();
|
||
shipment.WarehouseId = int.Parse(warehouseId);
|
||
shipment.Code = _unitwork.GetSerialNumber("QTC");
|
||
shipment.UserDef1 = "HYB";
|
||
shipment.UserDef4 = tran;
|
||
shipment.Type = "QTC";
|
||
shipment.FirstStatus = 0;
|
||
shipment.LastStatus = 0;
|
||
|
||
_unitwork.Add(shipment);
|
||
|
||
var detailList = new List<ShipmentDetail2>();
|
||
foreach (var item in data)
|
||
{
|
||
var detail = new ShipmentDetail2();
|
||
detail.WarehouseId = shipment.WarehouseId;
|
||
detail.ShipmentId = shipment.ID;
|
||
detail.ShipmentCode = shipment.Code;
|
||
detail.MaterialCode = item.MaterialCode;
|
||
detail.MaterialName = item.MaterialName;
|
||
detail.Lot = item.Lot;
|
||
detail.Qty = item.ThisQty;
|
||
detail.Unit = item.Unit;
|
||
detail.InventoryStatus = item.Status;
|
||
detail.Batch = item.Batch;
|
||
detail.Status = 0;
|
||
detail.CreateTime = DateTime.Now;
|
||
detailList.Add(detail);
|
||
}
|
||
_unitwork.BatchAdd(detailList.ToArray());
|
||
|
||
shipment.TotalLines = detailList.Count;
|
||
shipment.TotalQty = detailList.Sum(x => x.Qty);
|
||
_unitwork.Update(shipment);
|
||
trans.Commit();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
trans.Rollback();
|
||
return JsonMore(null, 500, ex.Message);
|
||
}
|
||
return JsonMore(null);
|
||
}
|
||
}
|
||
|
||
[ActionDescription("Sys.SearchInv")]
|
||
[FixConnection(CsName = "hangyong")]
|
||
public ActionResult SearchInv(string materialCode, string materialName, string batch, string lot)
|
||
{
|
||
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
||
var _unitwork = new UnitWork(Wtm);
|
||
var list = _unitwork.Find<Inventory2>(x =>
|
||
x.WarehouseId == int.Parse(warehouseId)
|
||
&& x.MaterialCode.Contains(materialCode)
|
||
&& x.MaterialName.Contains(materialName)
|
||
&& x.Batch.Contains(batch)
|
||
&& x.Lot.Contains(lot)
|
||
).Select(x => new
|
||
{
|
||
x.LocationCode,
|
||
x.MaterialCode,
|
||
x.MaterialName,
|
||
x.Batch,
|
||
x.Lot,
|
||
x.ContainerCode,
|
||
x.SupplierName,
|
||
x.Qty,
|
||
UserDef2 = x.Status ?? "",
|
||
ThisQty = x.Qty,
|
||
UserDef3 = ""
|
||
}).ToList();
|
||
return JsonMore(list);
|
||
}
|
||
|
||
[ActionDescription("Sys.CreateMove")]
|
||
public ActionResult CreateMove()
|
||
{
|
||
return PartialView("CreateMove");
|
||
}
|
||
|
||
[ActionDescription("Sys.CreateMove")]
|
||
[FixConnection(CsName = "hangyong")]
|
||
public ActionResult CreateMoveBill(string address, List<Inventory2> data, string tran = "CHG")
|
||
{
|
||
var err = data.FirstOrDefault(x => x.UserDef3 == ""
|
||
|| x.UserDef2 == "");
|
||
if(err != null)
|
||
{
|
||
return JsonMore(null, 500, "状态和仓库是必选项!");
|
||
}
|
||
|
||
var err2 = data.FirstOrDefault(x => x.Qty <= 0);
|
||
if (err2 != null)
|
||
{
|
||
return JsonMore(null, 500, "数量不能小于0!");
|
||
}
|
||
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
||
var _unitwork = new UnitWork(Wtm);
|
||
var dc = Wtm.CreateDC(cskey: "hangyong");
|
||
using (var trans = dc.BeginTransaction())
|
||
{
|
||
try
|
||
{
|
||
var shipment = new ShipmentHeader2();
|
||
shipment.WarehouseId = int.Parse(warehouseId);
|
||
shipment.Code = _unitwork.GetSerialNumber("ZYC");
|
||
shipment.UserDef1 = "HYB";
|
||
shipment.UserDef4 = tran;
|
||
shipment.Type = "ZYC";
|
||
shipment.FirstStatus = 0;
|
||
shipment.LastStatus = 0;
|
||
|
||
_unitwork.Add(shipment);
|
||
|
||
var detailList = new List<ShipmentDetail2>();
|
||
foreach (var item in data)
|
||
{
|
||
var detail = new ShipmentDetail2();
|
||
detail.WarehouseId = shipment.WarehouseId;
|
||
detail.ShipmentId = shipment.ID;
|
||
detail.ShipmentCode = shipment.Code;
|
||
detail.MaterialCode = item.MaterialCode;
|
||
detail.MaterialName = item.MaterialName;
|
||
detail.Lot = item.Lot;
|
||
detail.Qty = item.ThisQty;
|
||
detail.Unit = item.Unit;
|
||
detail.UserDef3 = item.UserDef3;//地点
|
||
//detail.PurchasQty = item.THISQTYUOM;
|
||
//detail.PurchasUnits = item.UOM_0;
|
||
detail.InventoryStatus = item.Status;
|
||
detail.PurchasUnits = item.UserDef2;//状态
|
||
detail.Batch = item.Batch;
|
||
detail.Status = 0;
|
||
detail.CreateTime = DateTime.Now;
|
||
detailList.Add(detail);
|
||
}
|
||
_unitwork.BatchAdd(detailList.ToArray());
|
||
|
||
shipment.TotalLines = detailList.Count;
|
||
shipment.TotalQty = detailList.Sum(x => x.Qty);
|
||
_unitwork.Update(shipment);
|
||
trans.Commit();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
trans.Rollback();
|
||
return JsonMore(null, 500, ex.Message);
|
||
}
|
||
return JsonMore(null);
|
||
}
|
||
}
|
||
[ActionDescription("Sys.CheckInv")]
|
||
[FixConnection(CsName = "hangyong")]
|
||
public ActionResult CheckInv(string id)
|
||
{
|
||
var vm = Wtm.CreateVM<ShipmentDetail2VM>(id);
|
||
return PartialView(vm);
|
||
}
|
||
[ActionDescription("Sys.CheckInv")]
|
||
[FixConnection(CsName = "hangyong")]
|
||
public ActionResult CheckInvData(string str)
|
||
{
|
||
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
||
|
||
var dc = Wtm.CreateDC(cskey: "default");
|
||
var loc = dc.Set<SysDictData>().FirstOrDefault(x => x.DictType == "Loc"
|
||
&& x.DictValue == warehouseId.ToString())?.DictLabel;
|
||
|
||
var _unitwork = new UnitWork(Wtm);
|
||
|
||
var ship = _unitwork.FindSingle<ShipmentDetail2>(x => x.ID == int.Parse(str));
|
||
|
||
var WmsQty = _unitwork.Find<Inventory2>(x =>
|
||
x.MaterialCode == ship.MaterialCode
|
||
&& x.Batch == ship.Batch
|
||
&& x.WarehouseId == int.Parse(warehouseId)
|
||
).Sum(x => x.Qty);
|
||
|
||
var sql = @"select * from QREQ3.XWMSSTOHYB where 1=1";
|
||
sql += $" and LOC_0 = '{loc}' and ITMREF_0 = '{ship.MaterialCode}'";
|
||
// and LOT_0 = '{ship.Batch}'
|
||
var data = OracleHelper.GetDataSet(sql).Tables[0];
|
||
|
||
var list = data.AsEnumerable().Select
|
||
(x => new
|
||
{
|
||
STOFCY_0 = x.Field<string>("STOFCY_0"),
|
||
ITMREF_0 = x.Field<string>("ITMREF_0"),
|
||
LOT_0 = x.Field<string>("LOT_0"),
|
||
LOC_0 = x.Field<string>("LOC_0"),
|
||
QTYSTU_0 = x.Field<decimal>("QTYSTU_0"),
|
||
PCU_0 = x.Field<string>("PCU_0"),
|
||
STA_0 = x.Field<string>("STA_0"),
|
||
WmsQty = WmsQty
|
||
}
|
||
).ToList();
|
||
return JsonMore(list);
|
||
}
|
||
|
||
[ActionDescription("Sys.CheckInv")]
|
||
[FixConnection(CsName = "hangyong")]
|
||
public ActionResult Check(string str, List<XWMSSTOHYB> data)
|
||
{
|
||
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
||
|
||
//var dc = Wtm.CreateDC(cskey: "default");
|
||
var _unitwork = new UnitWork(Wtm);
|
||
|
||
var ship = _unitwork.FindSingle<ShipmentDetail2>(x =>
|
||
x.ID == int.Parse(str)
|
||
&& x.Status == 0);
|
||
if (ship == null)
|
||
{
|
||
return JsonMore(null, 500, "未找到新建状态的出库单明细!");
|
||
}
|
||
|
||
var item = data.FirstOrDefault();
|
||
if(item== null)
|
||
{
|
||
return JsonMore(null,500,"ERP无库存!");
|
||
}
|
||
if(ship.Qty > data.Sum(x => x.QTYSTU_0))
|
||
{
|
||
return JsonMore(null, 500, "ERP无足够库存!");
|
||
}
|
||
if(ship.Qty <= item.QTYSTU_0)
|
||
{
|
||
ship.Batch = item.LOT_0;
|
||
ship.InventoryStatus = item.STA_0;
|
||
_unitwork.Update(ship);
|
||
}
|
||
else if(ship.Qty > item.QTYSTU_0)
|
||
{
|
||
var newShip = ship;
|
||
newShip.ID = null;
|
||
newShip.Qty = ship.Qty - item.QTYSTU_0;
|
||
_unitwork.Add(newShip);
|
||
|
||
ship.Qty = item.QTYSTU_0;
|
||
ship.Batch = item.LOT_0;
|
||
ship.InventoryStatus = item.STA_0;
|
||
_unitwork.Update(ship);
|
||
|
||
data.Remove(item);
|
||
|
||
Check(newShip.ID.ToString(), data);
|
||
}
|
||
|
||
return JsonMore(null);
|
||
}
|
||
|
||
[ActionDescription("Sys.SearchWare")]
|
||
public ActionResult SearchWare()
|
||
{
|
||
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
||
|
||
//var dc = Wtm.CreateDC(cskey: "default");
|
||
var _unitwork = new UnitWork(Wtm);
|
||
|
||
var list = _unitwork.Find<SysDictData>(x =>
|
||
x.DictType == "Loc"
|
||
&& x.DictValue.Length > 1)
|
||
.Select(x => new
|
||
{
|
||
label = HttpUtility.HtmlDecode(x.DictLabel),
|
||
value = x.DictValue
|
||
}).ToList();
|
||
|
||
return JsonMore(list);
|
||
}
|
||
}
|
||
}
|