152 lines
5.5 KiB
C#
152 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection.Emit;
|
|
using HHWMS.Web.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using NPOI.SS.Formula.Functions;
|
|
using WalkingTec.Mvvm.Core;
|
|
using WalkingTec.Mvvm.Mvc;
|
|
|
|
namespace HHWMS.Web.Controllers;
|
|
|
|
[Area("receipt")]
|
|
[ActionDescription("货架入库")]
|
|
public class ReceiptShelfInController : BaseController
|
|
{
|
|
private readonly IUnitWork _unitWork;
|
|
|
|
public ReceiptShelfInController(IUnitWork unitWork)
|
|
{
|
|
_unitWork = unitWork;
|
|
}
|
|
|
|
#region Search
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Index()
|
|
{
|
|
return PartialView("Index");
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 扫描唯一码,并验证,返回入库单明细
|
|
/// </summary>
|
|
/// <param name="uniqueCode"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public ActionResult ScanUniqueCode(string uniqueCode)
|
|
{
|
|
var receiptDetail = _unitWork.FindSingle<ReceiptDetail>(x => x.UniqueCode.Equals(uniqueCode)
|
|
&& x.Status == ReceiptStatusEnum.新建);
|
|
if (receiptDetail != null)
|
|
{
|
|
if (receiptDetail.Status == ReceiptStatusEnum.收完)
|
|
{
|
|
return JsonMore(null, 500, $"{uniqueCode}已全部收完,无需重新绑定!");
|
|
}
|
|
return JsonMore(receiptDetail);
|
|
}
|
|
return JsonMore(null, 500, $"{uniqueCode}不存在!");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public ActionResult BindingData(List<Binding> data)
|
|
{
|
|
var receiptHeaderList = _unitWork.Find<ReceiptHeader>(x =>
|
|
data.Select(x => x.ReceiptCode).ToList().Contains(x.ID.ToString()))
|
|
.Include(x => x.ReceiptDetails).ToList();
|
|
|
|
var invList = new List<Inventory>();
|
|
var listInvtran = new List<InventoryTransaction>();
|
|
|
|
using (var tran = Wtm.DC.Database.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
// 查找明细,修改对应状态,并且 绑定物料周转箱
|
|
foreach (Binding item in data.OrderBy(x => x.ReceiptCode))
|
|
{
|
|
// 更新入库单明细状态
|
|
var header = receiptHeaderList.Find(x => x.ID.ToString().Equals(item.ReceiptCode));
|
|
var receipt = header.ReceiptDetails.FirstOrDefault(x => x.UniqueCode.Equals(item.UniqueCode));
|
|
if (receipt != null)
|
|
{
|
|
receipt.Status = ReceiptStatusEnum.收完;
|
|
if (!header.ReceiptDetails.Any(x => x.Status < ReceiptStatusEnum.收完))
|
|
{
|
|
header.FirstStatus = ReceiptStatusEnum.收完;
|
|
}
|
|
receipt.UpdateTime = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception($"入库单{item.ReceiptCode}不存在{item.UniqueCode}的明细!");
|
|
}
|
|
|
|
// 新建库存
|
|
invList.Add(new Inventory
|
|
{
|
|
ZoneCode = ZoneCodeEnum.货架库,
|
|
LocationCode = item.BoxCode,
|
|
UniqueCode = item.UniqueCode,
|
|
MaterialCode = receipt.MaterialCode,
|
|
MaterialType = receipt.MaterialType,
|
|
MaterialName = receipt.MaterialName,
|
|
MaterialSpec = receipt.MaterialSpec,
|
|
Batch = receipt.Batch,
|
|
MaterialUnit = receipt.MaterialUnit,
|
|
SupplierCode = receipt.SupplierCode,
|
|
Qty = receipt.Qty,
|
|
Status = "0",
|
|
TaskStatus = InventoryTaskStatus.无任务,
|
|
CreateBy = Wtm.LoginUserInfo.ITCode,
|
|
CreateTime = DateTime.Now
|
|
}); ;
|
|
|
|
foreach (var inv in invList)
|
|
{
|
|
listInvtran.Add(new InventoryTransaction
|
|
{
|
|
BillType = "in",
|
|
ZoneCode = inv.ZoneCode,
|
|
Type = inv.UniqueCode,
|
|
MaterialCode = inv.MaterialCode,
|
|
MaterialName = inv.MaterialName,
|
|
MaterialSpec = inv.MaterialSpec,
|
|
MaterialUnit = inv.MaterialUnit,
|
|
MaterialType = inv.MaterialType,
|
|
Batch = inv.Batch,
|
|
Lot = inv.Lot,
|
|
CompanyCode = inv.CompanyCode,
|
|
LocationCode = inv.LocationCode,
|
|
SupplierCode = inv.SupplierCode,
|
|
Qty = inv.Qty,
|
|
CreateTime = DateTime.Now
|
|
});
|
|
}
|
|
}
|
|
_unitWork.BatchAdd(invList.ToArray());
|
|
_unitWork.BatchAdd(listInvtran.ToArray());
|
|
_unitWork.BatchUpdate(receiptHeaderList.ToArray());
|
|
|
|
tran.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
tran.Rollback();
|
|
return JsonMore(null, 500, ex.Message);
|
|
}
|
|
}
|
|
return JsonMore(null);
|
|
}
|
|
|
|
}
|