using HslCommunication.Secs.Types;
|
using SqlSugar.Extensions;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Net.NetworkInformation;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Common;
|
using WIDESEA_Common.OrderEnum;
|
using WIDESEA_Common.StockEnum;
|
using WIDESEA_Common.TaskEnum;
|
using WIDESEA_Common.WareHouseEnum;
|
using WIDESEA_Core;
|
using WIDESEA_ISquareCabinServices;
|
using WIDESEA_Model.Models;
|
using static WIDESEA_DTO.SquareCabin.OrderDto;
|
|
namespace WIDESEA_SquareCabinServices
|
{
|
public partial class DeliveryOrderServices
|
{
|
#region 创建平库调拨出库单、立库调拨入库单 在立库出库完成后调用 在出库完成后将物料表中的业务数量(Business_qty)减去实际出库数量
|
/// <summary>
|
/// 创建调拨单
|
/// </summary>
|
/// <param name="materielInfo">物料信息</param>
|
/// <returns></returns>
|
public WebResponseContent CreateAllocatInOut(Dt_MaterielInfo materielInfo)
|
{
|
WebResponseContent response = new WebResponseContent();
|
try
|
{
|
string WareCode = WarehouseEnum.大件库.ObjToInt().ToString("000");
|
if (materielInfo.Business_qty >= materielInfo.MinQty) return response;
|
Dt_Tactics tactics = _tacticsService.Repository.QueryFirst(x => x.TacticeName == "出库策略");
|
List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>();
|
//// 查询大件库中可用的库存
|
List<Dt_InventoryInfo> dt_InventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.MaterielCode == materielInfo.MaterielCode && x.StockStatus == StockStatusEmun.入库完成.ObjToInt() && x.AvailableQuantity > 0 && x.WarehouseCode == WareCode);//这里如果有俩个不同批次的物料,补货不管批次
|
if (dt_InventoryInfos.Count < 1) throw new Exception($"物料编号【{materielInfo.MaterielCode}】大件库无库存!请及时补充库存!");
|
if (tactics.SelectTactice == TacticsEnum.ComeOutonFirstTime.ObjToInt())
|
dt_InventoryInfos = dt_InventoryInfos.OrderBy(x => x.ValidityPeriod).ToList();
|
else
|
dt_InventoryInfos = dt_InventoryInfos.OrderBy(x => x.InDate).ToList();
|
Dt_DeliveryOrder deliveryOrder = new Dt_DeliveryOrder()
|
{
|
Out_no = DateTime.Now.ToString("yyMMddHHmmss"),
|
Warehouse_no = WareCode,
|
Out_type = OutOrderTypeEnum.Allocate.ObjToInt().ToString(),
|
OutStatus = "新建",
|
Details = new List<Dt_DeliveryOrderDetail>()
|
};
|
|
#region 循环
|
foreach (var item in dt_InventoryInfos)
|
{
|
decimal Qty = 0;
|
if (materielInfo.Business_qty >= materielInfo.MinQty) break;
|
//item.StockStatus = StockStatusEmun.出库锁定.ObjToInt();
|
while (item.StockQuantity > item.OutboundQuantity && materielInfo.Business_qty < materielInfo.MinQty)
|
{
|
Qty += materielInfo.BoxQty;
|
materielInfo.Business_qty += materielInfo.BoxQty;
|
item.OutboundQuantity += materielInfo.BoxQty;
|
}
|
item.AvailableQuantity = item.StockQuantity - item.OutboundQuantity;
|
#region 添加调拨出库单
|
Dt_DeliveryOrderDetail? deliveryOrderDetail = deliveryOrder.Details.FirstOrDefault(x => x.Batch_num == item.BatchNo);
|
if (deliveryOrderDetail == null)
|
{
|
deliveryOrderDetail = new Dt_DeliveryOrderDetail()
|
{
|
Batch_num = item.BatchNo,
|
Order_Outqty = 0,
|
Order_qty = Qty,
|
CreateDate = DateTime.Now,
|
Creater = App.User.UserName ?? "System",
|
Goods_no = item.MaterielCode,
|
OotDetailStatus = "新建",
|
Status = 2,
|
Reservoirarea = WareCode
|
};
|
deliveryOrder.Details.Add(deliveryOrderDetail);
|
}
|
else
|
{
|
deliveryOrderDetail.Order_qty += Qty;
|
}
|
//deliveryOrder.Details.Add(deliveryOrderDetail);
|
#endregion
|
#region 添加调拨出库任务
|
Dt_SupplyTask supplyTask = new Dt_SupplyTask()
|
{
|
WarehouseCode = item.WarehouseCode,
|
BatchNo = item.BatchNo,
|
MaterielName = item.MaterielName,
|
MaterielCode = item.MaterielCode,
|
MaterielSpec = item.MaterielSpec,
|
TaskStatus = SupplyStatusEnum.NewOut.ObjToInt(),
|
TaskType = TaskTypeEnum.AllocatOut.ObjToInt(),
|
CreateDate = DateTime.Now,
|
Creater = App.User.UserName ?? "System",
|
LocationCode = item.LocationCode,
|
OrderNo = deliveryOrder.Out_no,
|
StockQuantity = Qty,
|
SupplyQuantity = 0,
|
Remark = "调拨出库"
|
};
|
supplyTasks.Add(supplyTask);
|
#endregion
|
}
|
#endregion
|
|
|
#region 大件库补立库后立库业务库存数还是小于立库最小库存数,添加提示信息
|
//添加报警信息
|
if (materielInfo.Business_qty < materielInfo.MinQty)
|
{
|
_messageInfoService.AddMessageInfo(MessageGroupByEnum.InventoryLowAlarm, $"物料名称:{materielInfo.MaterielName}", $"【物料编码{materielInfo.MaterielCode}已生成调拨出入库单,请进行出入库流程。大件库库存过低!请及时补充库存!】");
|
}
|
else
|
{
|
_messageInfoService.AddMessageInfo(MessageGroupByEnum.InventoryLowAlarm, $"物料名称:{materielInfo.MaterielName}", $"【物料编码{materielInfo.MaterielCode}已生成调拨出入库单,请进行出入库流程】");
|
}
|
#endregion
|
#region 添加调拨出库单
|
//dt_InventoryInfos = dt_InventoryInfos.Where(X => X.StockStatus == StockStatusEmun.出库锁定.ObjToInt()).ToList();
|
//foreach (var item in dt_InventoryInfos.GroupBy(x => x.BatchNo)) //这里按批次分组了
|
//{
|
// Dt_DeliveryOrderDetail deliveryOrderDetail = new Dt_DeliveryOrderDetail()
|
// {
|
// Batch_num = item.Key,
|
// Order_Outqty = 0,
|
// Order_qty = item.Select(x => x.OutboundQuantity).Sum(),
|
// CreateDate = DateTime.Now,
|
// Creater = App.User.UserName ?? "System",
|
// Goods_no = item.First().MaterielCode,
|
// OotDetailStatus = "新建",
|
// Status = 2,
|
// Reservoirarea = item.First().WarehouseCode
|
// };
|
// deliveryOrder.Warehouse_no = item.First().WarehouseCode;
|
// deliveryOrder.Details.Add(deliveryOrderDetail);
|
//}
|
#endregion
|
|
#region 添加调拨出库任务
|
//foreach (var item in dt_InventoryInfos)
|
//{
|
// Dt_SupplyTask supplyTask = new Dt_SupplyTask()
|
// {
|
// WarehouseCode = item.WarehouseCode,
|
// BatchNo = item.BatchNo,
|
// MaterielName = item.MaterielName,
|
// MaterielCode = item.MaterielCode,
|
// MaterielSpec = item.MaterielSpec,
|
// TaskStatus = SupplyStatusEnum.NewOut.ObjToInt(),
|
// TaskType = TaskTypeEnum.AllocatOut.ObjToInt(),
|
// CreateDate = DateTime.Now,
|
// Creater = App.User.UserName ?? "System",
|
// LocationCode = item.LocationCode,
|
// OrderNo = deliveryOrder.Out_no,
|
// StockQuantity = item.OutboundQuantity,
|
// SupplyQuantity = 0,
|
// Remark = "调拨出库"
|
// };
|
// supplyTasks.Add(supplyTask);
|
//}
|
#endregion
|
|
#region 添加调拨入库单
|
Dt_CabinOrder cabinOrder = new Dt_CabinOrder()
|
{
|
Order_no = deliveryOrder.Out_no,
|
Order_type = InOrderTypeEnum.Allocat.ObjToInt().ToString(),
|
Warehouse_no = "001",
|
OdrderStatus = "新建",
|
Details = new List<Dt_CabinOrderDetail>()
|
};
|
foreach (var item in deliveryOrder.Details)
|
{
|
Dt_CabinOrderDetail orderDetail = new Dt_CabinOrderDetail()
|
{
|
Reservoirarea = cabinOrder.Warehouse_no,
|
Goods_no = item.Goods_no,
|
Order_qty = item.Order_qty,
|
Batch_num = item.Batch_num,
|
OrderDetailStatus = "新建",
|
Status = 0
|
};
|
cabinOrder.Details.Add(orderDetail);
|
}
|
#endregion
|
|
//_unitOfWorkManage.BeginTran();
|
_materielInfoService.UpdateData(materielInfo);
|
_inventoryInfoService.Repository.UpdateData(dt_InventoryInfos);
|
_supplyTaskService.AddData(supplyTasks);
|
if (deliveryOrder.Details.Count > 0) BaseDal.Db.InsertNav(deliveryOrder).Include(x => x.Details).ExecuteCommand();
|
if (cabinOrder.Details.Count > 0) _cabinOrderServices.Repository.Db.InsertNav(cabinOrder).Include(x => x.Details).ExecuteCommand();
|
//_unitOfWorkManage.CommitTran();
|
}
|
catch (Exception ex)
|
{
|
//_unitOfWorkManage.RollbackTran();
|
_messageInfoService.AddMessageInfo(MessageGroupByEnum.InventoryLowAlarm, "大件库补货立库", ex.Message);
|
response.Error(ex.Message);
|
}
|
return response;
|
}
|
#endregion
|
}
|
}
|