118 lines
4.0 KiB
C#
118 lines
4.0 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 Microsoft.EntityFrameworkCore;
|
|
using System.Linq;
|
|
using Newtonsoft.Json;
|
|
using System.Collections.Generic;
|
|
|
|
namespace HHWMS.Web.Controllers
|
|
{
|
|
[Area("receipt")]
|
|
[ActionDescription("盘料操作")]
|
|
public partial class ReceiptInController : BaseController
|
|
{
|
|
private readonly IUnitWork _unitWork;
|
|
public ReceiptInController(IUnitWork unitwork)
|
|
{
|
|
_unitWork = unitwork;
|
|
}
|
|
#region Search
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Index()
|
|
{
|
|
return PartialView("Index");
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult<dynamic> SelectReceiptCode()
|
|
{
|
|
var data = _unitWork.Find<ReceiptHeader>(x => x.FirstStatus <= ReceiptStatusEnum.收完)
|
|
.Select(x => new { label = x.Code, value = x.Code });
|
|
return JsonMore(data);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult<dynamic> SelectReceipt(string Code)
|
|
{
|
|
var data = _unitWork.Find<ReceiptHeader>(x => x.Code == Code)
|
|
.Include(x => x.ReceiptDetails.Where(a => a.Status < ReceiptStatusEnum.收完))
|
|
.FirstOrDefault();
|
|
if(data != null)
|
|
{
|
|
var result = data.ReceiptDetails.Select(x => new { name = x.UniqueCode });
|
|
return JsonMore(result);
|
|
}
|
|
else
|
|
{
|
|
return JsonMore(null);
|
|
}
|
|
}
|
|
/// <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.Code))
|
|
.Include(x => x.ReceiptDetails).ToList();
|
|
// 查找明细,修改对应状态,并且 绑定物料周转箱
|
|
foreach (Binding item in data)
|
|
{
|
|
// 更新入库单明细状态
|
|
var header = receiptHeaderList.First(x => x.Code.Equals(item.ReceiptCode));
|
|
var receipt = header.ReceiptDetails.First(x => x.UniqueCode.Equals(item.UniqueCode));
|
|
//var receipt = _unitWork.FindSingle<ReceiptDetail>(x => x.UniqueCode == item.UniqueCode);
|
|
if (receipt != null)
|
|
{
|
|
if (receipt.Status == ReceiptStatusEnum.收完) continue;
|
|
receipt.CompletedQty += item.BindQty;
|
|
}
|
|
if (receipt.CompletedQty == receipt.Qty)
|
|
{
|
|
receipt.Status = ReceiptStatusEnum.收完;
|
|
if (!header.ReceiptDetails.Any(x => x.Status < ReceiptStatusEnum.收完))
|
|
{
|
|
header.FirstStatus = ReceiptStatusEnum.收完;
|
|
_unitWork.Update(header);
|
|
}
|
|
}
|
|
// 新建库存
|
|
var inventory = new Inventory
|
|
{
|
|
ZoneCode = ZoneCodeEnum.盘料库,
|
|
UniqueCode = item.UniqueCode,
|
|
Flag = item.Index,
|
|
Qty = receipt.Qty,
|
|
Lot = item.Size.ToString(),
|
|
ContainerCode = item.BoxCode,
|
|
TaskStatus = InventoryTaskStatus.任务中
|
|
};
|
|
_unitWork.Add(inventory);
|
|
}
|
|
return JsonMore(null);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
public class Binding
|
|
{
|
|
public string ReceiptCode { get; set; }
|
|
public string UniqueCode { get; set; }
|
|
public string BoxCode { get; set; }
|
|
public int Index { get; set; }
|
|
public int Size { get; set; }
|
|
public int BindQty { get; set; }
|
|
}
|
|
}
|