using HslCommunication;
|
using MailKit.Search;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.Data.SqlClient;
|
using Newtonsoft.Json;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Common;
|
using WIDESEA_Common.LocationEnum;
|
using WIDESEA_Common.OrderEnum;
|
using WIDESEA_Common.StockEnum;
|
using WIDESEA_Common.TaskEnum;
|
using WIDESEA_Common.WareHouseEnum;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Enums;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_DTO.SquareCabin;
|
using WIDESEA_IBasicService;
|
using WIDESEA_ISquareCabinServices;
|
using WIDESEA_IWMsInfoServices;
|
using WIDESEA_Model.Models;
|
|
using static System.Net.WebRequestMethods;
|
using static WIDESEA_DTO.SquareCabin.OrderDto;
|
using static WIDESEA_DTO.SquareCabin.TowcsDto;
|
|
|
namespace WIDESEA_SquareCabinServices
|
{
|
public class CabinOrderServices : ServiceBase<Dt_CabinOrder, IRepository<Dt_CabinOrder>>, ICabinOrderServices
|
{
|
private readonly IBasicService _basicService;
|
private readonly IMedicineGoodsServices _medicineGoodsServices;
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
private readonly IInventory_BatchServices _inventory_BatchServices;
|
private readonly IInventoryInfoService _inventoryInfoService;
|
private readonly ICabinOrderDetailServices _cabinOrderDetailServices;
|
private readonly ISupplyTaskService _supplyTaskService;
|
private readonly ISupplyTaskHtyService _supplyTaskHtyService;
|
private readonly IMessageInfoService _messageInfoService;
|
public IRepository<Dt_CabinOrder> Repository => BaseDal;
|
|
public CabinOrderServices(IRepository<Dt_CabinOrder> BaseDal, IBasicService basicService, IMedicineGoodsServices medicineGoodsServices, IUnitOfWorkManage unitOfWorkManage, IInventory_BatchServices inventory_BatchServices, IInventoryInfoService inventoryInfoService, ICabinOrderDetailServices cabinOrderDetailServices, ICabinOrderHtyServices cabinOrderHtyServices, ICabinOrderDetailHtyServices cabinOrderDetailHtyServices, ISupplyTaskService supplyTaskService, ISupplyTaskHtyService supplyTaskHtyService, IMessageInfoService messageInfoService) : base(BaseDal)
|
{
|
_basicService = basicService;
|
_medicineGoodsServices = medicineGoodsServices;
|
_unitOfWorkManage = unitOfWorkManage;
|
_inventory_BatchServices = inventory_BatchServices;
|
_inventoryInfoService = inventoryInfoService;
|
_cabinOrderDetailServices = cabinOrderDetailServices;
|
_supplyTaskService = supplyTaskService;
|
_supplyTaskHtyService = supplyTaskHtyService;
|
_messageInfoService = messageInfoService;
|
}
|
|
|
|
/// <summary>
|
/// pda查询出库单信息
|
/// </summary>
|
/// <param name="saveModel"></param>
|
/// <returns></returns>
|
public WebResponseContent GetCabinOrders(SaveModel saveModel)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
int pageNo = saveModel.MainData["pageNo"].ObjToInt();
|
string warehouseCode = saveModel.MainData["warehouseId"].ToString();
|
string orderNo = saveModel.MainData["orderNo"].ToString();
|
List<Dt_CabinOrder> dt_ReceiveOrders = new List<Dt_CabinOrder>();
|
if (string.IsNullOrEmpty(orderNo))
|
{
|
dt_ReceiveOrders = Db.Queryable<Dt_CabinOrder>().Where(x => (x.OdrderStatus == "新建" || x.OdrderStatus == "开始") && x.Warehouse_no == warehouseCode).Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5);
|
}
|
else
|
{
|
dt_ReceiveOrders = Db.Queryable<Dt_CabinOrder>().Where(x => (x.Order_no.Contains(orderNo) || x.Supplier_no.Contains(orderNo)) && (x.OdrderStatus == "新建" || x.OdrderStatus == "开始") && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5);
|
}
|
|
content.OK(data: dt_ReceiveOrders);
|
}
|
catch (Exception)
|
{
|
|
throw;
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// pda查看入库详情表
|
/// </summary>
|
/// <param name="pageNo"></param>
|
/// <param name="orderNo"></param>
|
/// <returns></returns>
|
public WebResponseContent GetCabinOrderDetail(int pageNo, string orderNo)
|
{
|
WebResponseContent content = new WebResponseContent();
|
Dt_CabinOrder cabinOrder = Db.Queryable<Dt_CabinOrder>().Includes(x => x.Details).First(x => x.Order_no == orderNo);
|
List<Dt_CabinOrderDetail> cabinOrderDetails = cabinOrder.Details.Where(x => x.Status == 2 && x.OrderDetailStatus != "已完成").ToList();
|
content.OK(data: cabinOrderDetails);
|
return content;
|
}
|
|
|
/// <summary>
|
/// Pad入库完成
|
/// </summary>
|
/// <param name="saveModel"></param>
|
/// <returns></returns>
|
public WebResponseContent FeedbackIn([FromBody] SaveModel saveModel)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
var LocationCode = saveModel.MainData["LocationCode"].ToString();
|
var orderNo = saveModel.MainData["orderNo"].ToString();
|
var batchNo = saveModel.MainData["batchNo"].ToString();
|
var materielCode = saveModel.MainData["materielCode"].ToString();
|
var Inqty = saveModel.MainData["Inqty"].ObjToInt();
|
var warehouseCode = saveModel.MainData["warehouseCode"].ToString();
|
Dt_CabinOrder cabinOrder = BaseDal.Db.Queryable<Dt_CabinOrder>().Where(x => x.Order_no == orderNo && x.Warehouse_no == warehouseCode).Includes(x => x.Details).First();
|
if (cabinOrder == null || cabinOrder.OdrderStatus == "已完成")
|
return WebResponseContent.Instance.Error($"入库单已完成");
|
Dt_CabinOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Goods_no == materielCode && x.Batch_num == batchNo && x.Status == 2).FirstOrDefault();
|
if (cabinOrderDetail == null || cabinOrderDetail.OrderDetailStatus == "已完成")
|
return WebResponseContent.Instance.Error($"入库单明细已完成");
|
Dt_MaterielInfo materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == cabinOrderDetail.Goods_no);
|
if (materielInfo == null) return WebResponseContent.Instance.Error($"请维护物料编号【{cabinOrderDetail.Goods_no}】的物料信息");
|
cabinOrderDetail.Order_Inqty += Inqty;
|
if (cabinOrderDetail.Order_Inqty > cabinOrderDetail.Order_qty)
|
return WebResponseContent.Instance.Error($"入库数量不可超出单据数量");
|
|
#region 处理入库单,货位,库存,库存批次信息
|
_unitOfWorkManage.BeginTran();
|
|
#region 入库单
|
cabinOrder.OdrderStatus = "开始";
|
cabinOrderDetail.OrderDetailStatus = "开始";
|
if (cabinOrderDetail.Order_Inqty == cabinOrderDetail.Order_qty)
|
{
|
cabinOrderDetail.OrderDetailStatus = "已完成";
|
}
|
_cabinOrderDetailServices.Repository.UpdateData(cabinOrderDetail);
|
var cabinOrder1 = BaseDal.Db.Queryable<Dt_CabinOrder>().Where(x => x.Order_no == cabinOrder.Order_no && x.Warehouse_no == warehouseCode).Includes(x => x.Details).First();
|
if (!cabinOrder1.Details.Where(x => x.OrderDetailStatus != "已完成").Any()) cabinOrder.OdrderStatus = "已完成";
|
Repository.UpdateData(cabinOrder);
|
#endregion
|
|
#region 货位
|
var location = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode);
|
if (location == null) return WebResponseContent.Instance.Error($"请维护货位编号【{LocationCode}】的货位信息");
|
if (location.EnableStatus == EnableStatusEnum.Disable.ObjToInt())
|
return WebResponseContent.Instance.Error($"货位编号【{LocationCode}】已禁用,请恢复正常再使用");
|
if (location.WarehouseCode != cabinOrderDetail.Reservoirarea)
|
return WebResponseContent.Instance.Error($"货位编号【{LocationCode}】所属库房与当前入库单所属库房不匹配");
|
if (location.LocationStatus == LocationStatusEnum.Free.ObjToInt())
|
{
|
location.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
|
_basicService.LocationInfoService.UpdateData(location);
|
}
|
#endregion
|
|
#region 库存
|
Dt_InventoryInfo inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.LocationCode == LocationCode);
|
if (inventoryInfo != null)
|
{
|
inventoryInfo.StockQuantity += Inqty;
|
inventoryInfo.AvailableQuantity += Inqty;
|
inventoryInfo.InDate = DateTime.Now;
|
_inventoryInfoService.UpdateData(inventoryInfo);
|
}
|
else
|
{
|
inventoryInfo = new Dt_InventoryInfo()
|
{
|
LocationCode = LocationCode,
|
MaterielCode = materielInfo.MaterielCode,
|
MaterielName = materielInfo.MaterielName,
|
MaterielSpec = materielInfo.MaterielSpec,
|
OutboundQuantity = 0,
|
StockQuantity = Inqty,
|
AvailableQuantity = Inqty,
|
StockStatus = StockStatusEmun.入库完成.ObjToInt(),
|
ValidityPeriod = cabinOrderDetail.Exp_date,
|
WarehouseCode = cabinOrderDetail.Reservoirarea,
|
SupplyQuantity = 0,
|
InDate = DateTime.Now,
|
BatchNo = cabinOrderDetail.Batch_num,
|
Creater = App.User.UserName,
|
CreateDate = DateTime.Now,
|
};
|
_inventoryInfoService.AddData(inventoryInfo);
|
}
|
#endregion
|
|
#region 任务记录
|
#region MyRegion
|
//Dt_SupplyTask supplyTask = new Dt_SupplyTask()
|
//{
|
// WarehouseCode = cabinOrderDetail.Reservoirarea,
|
// TaskNum = cabinOrderDetail.Id,
|
// TaskStatus = SupplyStatusEnum.InFinish.ObjToInt(),
|
// BatchNo = inventoryInfo.BatchNo,
|
// MaterielName = inventoryInfo.MaterielName,
|
// MaterielCode = inventoryInfo.MaterielCode,
|
// MaterielSpec = inventoryInfo.MaterielSpec,
|
// TaskType = TaskTypeEnum.InPick.ObjToInt(),
|
// CreateDate = DateTime.Now,
|
// Creater = App.User.UserName,
|
// LocationCode = location.LocationCode,
|
// OrderNo = cabinOrder.Order_no,
|
// StockQuantity = Inqty,
|
// SupplyQuantity = 0,
|
// Remark = "入库"
|
//};
|
//_supplyTaskService.AddData(supplyTask);
|
#endregion
|
Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
|
{
|
WarehouseCode = cabinOrderDetail.Reservoirarea,
|
TaskNum = cabinOrderDetail.Id,
|
OperateType = OperateTypeEnum.人工完成.ToString(),
|
InsertTime = DateTime.Now,
|
TaskStatus = SupplyStatusEnum.InFinish.ObjToInt(),
|
BatchNo = inventoryInfo.BatchNo,
|
MaterielName = inventoryInfo.MaterielName,
|
MaterielCode = inventoryInfo.MaterielCode,
|
MaterielSpec = inventoryInfo.MaterielSpec,
|
TaskType = cabinOrder.Order_type == "1" ? TaskTypeEnum.In.ObjToInt() : TaskTypeEnum.OutReturn.ObjToInt(),
|
CreateDate = DateTime.Now,
|
Creater = App.User.UserName,
|
LocationCode = location.LocationCode,
|
OrderNo = cabinOrder.Order_no,
|
StockQuantity = Inqty,
|
SupplyQuantity = 0,
|
Remark = "入库"
|
};
|
_supplyTaskHtyService.AddData(supplyTask_Hty);
|
#endregion
|
|
#region 库存批次
|
Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode);
|
if (inventory_Batch != null)
|
{
|
inventory_Batch.StockQuantity += Inqty;
|
inventory_Batch.AvailableQuantity += Inqty;
|
_inventory_BatchServices.UpdateData(inventory_Batch);
|
}
|
else
|
{
|
inventory_Batch = new Dt_Inventory_Batch()
|
{
|
BatchNo = inventoryInfo.BatchNo,
|
CreateDate = inventoryInfo.CreateDate,
|
Creater = inventoryInfo.Creater,
|
MaterielCode = inventoryInfo.MaterielCode,
|
ERPStockQuantity = 0,
|
MaterielName = inventoryInfo.MaterielName,
|
MaterielSpec = inventoryInfo.MaterielSpec,
|
OutboundQuantity = inventoryInfo.OutboundQuantity,
|
ProductionDate = inventoryInfo.ProductionDate,
|
Status = false,
|
StockQuantity = inventoryInfo.StockQuantity,
|
AvailableQuantity = inventoryInfo.StockQuantity,
|
ValidityPeriod = inventoryInfo.ValidityPeriod,
|
SupplyQuantity = inventoryInfo.SupplyQuantity,
|
};
|
_inventory_BatchServices.AddData(inventory_Batch);
|
}
|
#endregion
|
|
_unitOfWorkManage.CommitTran();
|
#endregion
|
|
content.OK(cabinOrderDetail.Order_Inqty.ToString());
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
|
#region 创建入库单
|
/// <summary>
|
/// 创建入库单,返回一个入库单集合到data
|
/// </summary>
|
public WebResponseContent CreateInboundOrder(UpstreamOrderInfo order)
|
{
|
WebResponseContent webResponseContent = new WebResponseContent();
|
try
|
{
|
string WareCodeMJ = WarehouseEnum.麻精库.ObjToInt().ToString("000");
|
string WareCodeLD = WarehouseEnum.冷冻库.ObjToInt().ToString("000");
|
List<Dt_CabinOrder> dt_CabinOrders = new List<Dt_CabinOrder>();
|
#region 特殊药品入特殊库房
|
if (order.warehouse_no == WareCodeMJ || order.warehouse_no == WareCodeLD)
|
{
|
var entityOrder = new Dt_CabinOrder
|
{
|
Order_no = order.order_no,
|
Order_type = order.order_type,
|
Supplier_no = order.supplier_no,
|
Account_tiem = order.account_time,
|
OdrderStatus = "新建",
|
Supplier_name = order.supplier_name,
|
Warehouse_no = order.warehouse_no,
|
Details = order.details.Select(d => new Dt_CabinOrderDetail
|
{
|
Goods_no = d.goods_no,
|
Order_qty = Math.Abs(d.order_qty),
|
Batch_num = d.batch_num,
|
Exp_date = d.exp_date,
|
OrderDetailStatus = "新建",
|
Status = 2, //如果是001房那么就是未同步状态,如果不是001房那么就是无需同步状态
|
}).ToList()
|
};
|
dt_CabinOrders.Add(entityOrder);
|
webResponseContent.OK(data: dt_CabinOrders);
|
}
|
#endregion
|
else
|
{
|
var entityOrder = new Dt_CabinOrder//大件库订单
|
{
|
Order_no = order.order_no,
|
Order_type = order.order_type,
|
Supplier_no = order.supplier_no,
|
Account_tiem = order.account_time,
|
OdrderStatus = "新建",
|
Supplier_name = order.supplier_name,
|
Warehouse_no = WarehouseEnum.大件库.ObjToInt().ToString("000"),
|
Details = new List<Dt_CabinOrderDetail>()
|
};
|
var entityOrderLK = new Dt_CabinOrder//立库订单
|
{
|
Order_no = order.order_no,
|
Order_type = order.order_type,
|
Supplier_no = order.supplier_no,
|
Account_tiem = order.account_time,
|
OdrderStatus = "新建",
|
Supplier_name = order.supplier_name,
|
Warehouse_no = WarehouseEnum.立库.ObjToInt().ToString("000"),
|
Details = new List<Dt_CabinOrderDetail>()
|
};
|
foreach (var item in order.details)
|
{
|
// 将上游入库数量转为正数
|
item.order_qty = Math.Abs(item.order_qty);
|
#region 根据物料编码查询物料信息
|
Dt_MaterielInfo materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == item.goods_no);
|
if (materielInfo == null) throw new Exception($"未找到药品编码【{item.goods_no}】的信息");
|
if (!Enum.IsDefined(typeof(MaterielSourceTypeEnum), materielInfo.MaterielSourceType))
|
throw new Exception($"请设置药品编号【{item.goods_no}】的属性分类");
|
if (materielInfo.BoxQty < 1) throw new Exception($"请设置药品编号【{item.goods_no}】的箱规数量");
|
if (materielInfo.MinQty < 1) throw new Exception($"请设置药品编号【{item.goods_no}】的立库最低库存数");
|
#endregion
|
#region 大件
|
if (materielInfo.MaterielSourceType == MaterielSourceTypeEnum.PurchasePart)//如果物料是大件
|
{
|
Dt_CabinOrderDetail orderDetail = new Dt_CabinOrderDetail()
|
{
|
Reservoirarea = entityOrder.Warehouse_no,
|
Goods_no = item.goods_no,
|
Order_qty = item.order_qty,
|
Batch_num = item.batch_num,
|
Exp_date = item.exp_date,
|
OrderDetailStatus = "新建",
|
Status = 2
|
};
|
entityOrder.Details.Add(orderDetail);
|
}
|
#endregion
|
else
|
{
|
Dt_CabinOrderDetail orderDetail = null;
|
var ys = item.order_qty % materielInfo.BoxQty; //不能整除箱规的散件数
|
var xs = (int)(item.order_qty / materielInfo.BoxQty);//保留整数
|
#region 判断是否有散件
|
if (ys > 0)
|
{
|
orderDetail = new Dt_CabinOrderDetail()
|
{
|
Reservoirarea = entityOrderLK.Warehouse_no,
|
Goods_no = item.goods_no,
|
Order_qty = ys,
|
Batch_num = item.batch_num,
|
Exp_date = item.exp_date,
|
OrderDetailStatus = "新建",
|
Status = 0
|
};
|
materielInfo.Business_qty += ys;
|
}
|
#endregion
|
|
#region 判断立库库存是否大于立库最低库存数
|
while (materielInfo.Business_qty < materielInfo.MinQty && xs > 0) //当业务数量和整箱数都大于0的时候才会停止循环
|
{
|
xs--;
|
if (orderDetail == null)
|
{
|
orderDetail = new Dt_CabinOrderDetail()
|
{
|
Reservoirarea = entityOrderLK.Warehouse_no,
|
Goods_no = item.goods_no,
|
Order_qty = materielInfo.BoxQty,
|
Batch_num = item.batch_num,
|
Exp_date = item.exp_date,
|
OrderDetailStatus = "新建",
|
Status = 0
|
};
|
materielInfo.Business_qty += materielInfo.BoxQty;
|
}
|
else
|
{
|
orderDetail.Order_qty += materielInfo.BoxQty;
|
materielInfo.Business_qty += materielInfo.BoxQty;
|
}
|
}
|
|
if (orderDetail != null) entityOrderLK.Details.Add(orderDetail);
|
#endregion
|
|
#region 剩余整件入平库
|
if (xs > 0)
|
{
|
orderDetail = new Dt_CabinOrderDetail()
|
{
|
Reservoirarea = entityOrder.Warehouse_no,
|
Goods_no = item.goods_no,
|
Order_qty = materielInfo.BoxQty * xs,
|
Batch_num = item.batch_num,
|
Exp_date = item.exp_date,
|
OrderDetailStatus = "新建",
|
Status = 2
|
};
|
entityOrder.Details.Add(orderDetail);
|
}
|
#endregion
|
}
|
_basicService.MaterielInfoService.Repository.UpdateData(materielInfo);
|
}
|
if (entityOrder.Details.Count > 0) dt_CabinOrders.Add(entityOrder);
|
if (entityOrderLK.Details.Count > 0) dt_CabinOrders.Add(entityOrderLK);
|
webResponseContent.OK(data: dt_CabinOrders);
|
}
|
}
|
catch (Exception ex)
|
{
|
webResponseContent.Error(ex.Message);
|
}
|
return webResponseContent;
|
}
|
#endregion
|
|
#region 创建盘盈入库单
|
public WebResponseContent CreateCheckInOrder(UpstreamOrderInfo order)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
string WareCodeMJ = WarehouseEnum.麻精库.ObjToInt().ToString("000");
|
string WareCodeLD = WarehouseEnum.冷冻库.ObjToInt().ToString("000");
|
#region 特殊库房
|
if (order.warehouse_no == WareCodeMJ || order.warehouse_no == WareCodeLD)
|
{
|
#region 库存、库存批次平账
|
foreach (var item in order.details)
|
{
|
//找库存批次信息
|
Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num);
|
var Qty = Math.Abs(inventory_Batch.StockQuantity - inventory_Batch.SupplyQuantity);
|
if (Qty != item.order_qty) throw new Exception($"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
|
//找所有库存
|
List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo);
|
foreach (var inventoryInfo in inventoryInfos)
|
{
|
#region 添加盘盈入库任务
|
if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity)
|
{
|
Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
|
{
|
WarehouseCode = inventoryInfo.WarehouseCode,
|
OperateType = OperateTypeEnum.自动完成.ToString(),
|
InsertTime = DateTime.Now,
|
TaskStatus = SupplyStatusEnum.InFinish.ObjToInt(),
|
BatchNo = inventoryInfo.BatchNo,
|
MaterielName = inventoryInfo.MaterielName,
|
MaterielCode = inventoryInfo.MaterielCode,
|
MaterielSpec = inventoryInfo.MaterielSpec,
|
TaskType = TaskTypeEnum.ChenckIn.ObjToInt(),
|
CreateDate = DateTime.Now,
|
Creater = App.User.UserName,
|
LocationCode = inventoryInfo.LocationCode,
|
OrderNo = order.order_no,
|
StockQuantity = Math.Abs(inventoryInfo.StockQuantity - inventoryInfo.SupplyQuantity),
|
SupplyQuantity = 0,
|
Remark = "盘盈入库"
|
};
|
_supplyTaskHtyService.AddData(supplyTask_Hty);
|
}
|
#endregion
|
inventoryInfo.StockQuantity = inventoryInfo.SupplyQuantity;
|
inventoryInfo.SupplyQuantity = 0;
|
inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
|
}
|
inventory_Batch.StockQuantity = inventory_Batch.SupplyQuantity;
|
inventory_Batch.SupplyQuantity = 0;
|
_inventoryInfoService.UpdateData(inventoryInfos);
|
_inventory_BatchServices.UpdateData(inventory_Batch);
|
}
|
#endregion
|
|
#region 创建盘点单
|
var entityOrder = new Dt_CabinOrder
|
{
|
Order_no = order.order_no,
|
Order_type = order.order_type,
|
Supplier_no = order.supplier_no,
|
Account_tiem = order.account_time,
|
OdrderStatus = "已完成",
|
Supplier_name = order.supplier_name,
|
Warehouse_no = order.warehouse_no,
|
Details = order.details.Select(d => new Dt_CabinOrderDetail
|
{
|
Goods_no = d.goods_no,
|
Order_qty = Math.Abs(d.order_qty),
|
Order_Inqty = Math.Abs(d.order_qty),
|
Batch_num = d.batch_num,
|
Exp_date = d.exp_date,
|
Reservoirarea = order.warehouse_no,
|
OrderDetailStatus = "已完成",
|
Status = 2,
|
}).ToList()
|
};
|
Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
|
//Repository.AddData(entityOrder);
|
#endregion
|
}
|
#endregion
|
else
|
{
|
string WareCodeLK = WarehouseEnum.立库.ObjToInt().ToString("000");
|
string WareCodeDJ = WarehouseEnum.大件库.ObjToInt().ToString("000");
|
|
foreach (var item in order.details)
|
{
|
//找库存批次信息
|
Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num);
|
var Qty = Math.Abs(inventory_Batch.StockQuantity - inventory_Batch.SupplyQuantity);
|
if (Qty != item.order_qty) throw new Exception($"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
|
//找所有库存
|
List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo);
|
//获取立库盘点差异数
|
var inventoryLK = inventoryInfos.Where(x => x.WarehouseCode == WareCodeLK).First();
|
var LkQty = Math.Abs(inventoryLK.StockQuantity - inventoryLK.SupplyQuantity);
|
//获取大件库盘点差异数
|
var inventoryDJ = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
|
var DJQty = Math.Abs(inventoryDJ.Sum(x => x.StockQuantity) - inventoryDJ.Sum(x => x.SupplyQuantity));
|
if (LkQty + DJQty != Qty) throw new Exception($"【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的物料信息与物料批次信息盘盈数量不符");
|
if (LkQty == 0)//立库无差异
|
{
|
#region 库存、库存批次平账
|
foreach (var inventoryInfo in inventoryInfos)
|
{
|
#region 添加盘盈入库任务
|
if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity)
|
{
|
Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
|
{
|
WarehouseCode = inventoryInfo.WarehouseCode,
|
OperateType = OperateTypeEnum.自动完成.ToString(),
|
InsertTime = DateTime.Now,
|
TaskStatus = SupplyStatusEnum.InFinish.ObjToInt(),
|
BatchNo = inventoryInfo.BatchNo,
|
MaterielName = inventoryInfo.MaterielName,
|
MaterielCode = inventoryInfo.MaterielCode,
|
MaterielSpec = inventoryInfo.MaterielSpec,
|
TaskType = TaskTypeEnum.ChenckIn.ObjToInt(),
|
CreateDate = DateTime.Now,
|
Creater = App.User.UserName,
|
LocationCode = inventoryInfo.LocationCode,
|
OrderNo = order.order_no,
|
StockQuantity = Math.Abs(inventoryInfo.StockQuantity - inventoryInfo.SupplyQuantity),
|
SupplyQuantity = 0,
|
Remark = "盘盈入库"
|
};
|
_supplyTaskHtyService.AddData(supplyTask_Hty);
|
}
|
#endregion
|
inventoryInfo.StockQuantity = inventoryInfo.SupplyQuantity;
|
inventoryInfo.SupplyQuantity = 0;
|
inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
|
}
|
_inventoryInfoService.UpdateData(inventoryInfos);
|
inventory_Batch.StockQuantity = inventory_Batch.SupplyQuantity;
|
inventory_Batch.SupplyQuantity = 0;
|
_inventory_BatchServices.UpdateData(inventory_Batch);
|
#endregion
|
|
#region 创建大件库盘点单
|
var entityOrder = new Dt_CabinOrder
|
{
|
Order_no = order.order_no,
|
Order_type = order.order_type,
|
Supplier_no = order.supplier_no,
|
Account_tiem = order.account_time,
|
OdrderStatus = "已完成",
|
Supplier_name = order.supplier_name,
|
Warehouse_no = WareCodeDJ,
|
Details = order.details.Select(d => new Dt_CabinOrderDetail
|
{
|
Goods_no = d.goods_no,
|
Order_qty = Math.Abs(d.order_qty),
|
Order_Inqty = Math.Abs(d.order_qty),
|
Batch_num = d.batch_num,
|
Exp_date = d.exp_date,
|
Reservoirarea = WareCodeDJ,
|
OrderDetailStatus = "已完成",
|
Status = 2,
|
}).ToList()
|
};
|
//Repository.AddData(entityOrder);
|
Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
|
|
#endregion
|
}
|
else
|
{
|
#region 大件库库存平账
|
inventoryInfos = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
|
foreach (var inventoryInfo in inventoryInfos)
|
{
|
#region 添加盘盈入库任务
|
if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity)
|
{
|
Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
|
{
|
WarehouseCode = inventoryInfo.WarehouseCode,
|
OperateType = OperateTypeEnum.自动完成.ToString(),
|
InsertTime = DateTime.Now,
|
TaskStatus = SupplyStatusEnum.InFinish.ObjToInt(),
|
BatchNo = inventoryInfo.BatchNo,
|
MaterielName = inventoryInfo.MaterielName,
|
MaterielCode = inventoryInfo.MaterielCode,
|
MaterielSpec = inventoryInfo.MaterielSpec,
|
TaskType = TaskTypeEnum.ChenckIn.ObjToInt(),
|
CreateDate = DateTime.Now,
|
Creater = App.User.UserName,
|
LocationCode = inventoryInfo.LocationCode,
|
OrderNo = order.order_no,
|
StockQuantity = Math.Abs(inventoryInfo.StockQuantity - inventoryInfo.SupplyQuantity),
|
SupplyQuantity = 0,
|
Remark = "盘盈入库"
|
};
|
_supplyTaskHtyService.AddData(supplyTask_Hty);
|
}
|
#endregion
|
inventoryInfo.StockQuantity = inventoryInfo.SupplyQuantity;
|
inventoryInfo.SupplyQuantity = 0;
|
inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
|
}
|
_inventoryInfoService.UpdateData(inventoryInfos);
|
#endregion
|
|
#region 创建大件库盘点单
|
if (DJQty != 0)
|
{
|
var cabinOrder = new Dt_CabinOrder
|
{
|
Order_no = order.order_no,
|
Order_type = order.order_type,
|
Supplier_no = order.supplier_no,
|
Account_tiem = order.account_time,
|
OdrderStatus = "已完成",
|
Supplier_name = order.supplier_name,
|
Warehouse_no = WareCodeDJ,
|
Details = order.details.Select(d => new Dt_CabinOrderDetail
|
{
|
Goods_no = d.goods_no,
|
Order_qty = DJQty,
|
Order_Inqty = DJQty,
|
Batch_num = d.batch_num,
|
Exp_date = d.exp_date,
|
Reservoirarea = WareCodeDJ,
|
OrderDetailStatus = "已完成",
|
Status = 2,
|
}).ToList()
|
};
|
//Repository.AddData(cabinOrder);
|
Db.InsertNav(cabinOrder).Include(it => it.Details).ExecuteCommand();
|
|
}
|
#endregion
|
|
#region 创建立库盘点单
|
var entityOrder = new Dt_CabinOrder
|
{
|
Order_no = order.order_no,
|
Order_type = order.order_type,
|
Supplier_no = order.supplier_no,
|
Account_tiem = order.account_time,
|
OdrderStatus = "新建",
|
Supplier_name = order.supplier_name,
|
Warehouse_no = WareCodeLK,
|
Details = order.details.Select(d => new Dt_CabinOrderDetail
|
{
|
Goods_no = d.goods_no,
|
Order_qty = LkQty,
|
Batch_num = d.batch_num,
|
Exp_date = d.exp_date,
|
Reservoirarea = WareCodeLK,
|
OrderDetailStatus = "新建",
|
Status = 0,
|
}).ToList()
|
};
|
//Repository.AddData(entityOrder);
|
Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
|
#endregion
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
//_messageInfoService.AddMessageInfo(MessageGroupByEnum.InOrderAlarm, "创建盘盈入库单", ex.Message);
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
#endregion
|
}
|
}
|