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.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
|
{
|
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.StockQuantity > x.OutboundQuantity && x.WarehouseCode == WarehouseEnum.大件库.ObjToInt().ToString("000"));
|
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();
|
decimal Qty = 0;
|
foreach (var item in dt_InventoryInfos)
|
{
|
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 大件库补立库后立库业务库存数还是小于立库最小库存数,添加提示信息
|
|
#endregion
|
#region 添加调拨出库单
|
Dt_DeliveryOrder deliveryOrder = new Dt_DeliveryOrder()
|
{
|
Out_no = DateTime.Now.ToString("yyMMddHHmmss"),
|
Out_type = OutOrderTypeEnum.Allocate.ObjToInt().ToString(),
|
OutStatus = "新建",
|
Details = new List<Dt_DeliveryOrderDetail>()
|
};
|
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,
|
Order_Inqty = item.Order_qty,
|
Batch_num = item.Batch_num,
|
OrderDetailStatus = "新建",
|
Status = 0
|
};
|
cabinOrder.Details.Add(orderDetail);
|
}
|
#endregion
|
|
_unitOfWorkManage.BeginTran();
|
_inventoryInfoService.Repository.UpdateData(dt_InventoryInfos);
|
_supplyTaskService.AddData(supplyTasks);
|
BaseDal.Db.InsertNav(deliveryOrder).Include(x => x.Details).ExecuteCommand();
|
_cabinOrderServices.Repository.Db.InsertNav(cabinOrder).Include(x => x.Details).ExecuteCommand();
|
_unitOfWorkManage.CommitTran();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
response.Error(ex.Message);
|
}
|
return response;
|
}
|
#endregion
|
}
|
}
|