|
|
@ -5,9 +5,12 @@ using System.Net.Http; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Castle.Components.DictionaryAdapter; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.EventBus; |
|
|
|
using Volo.Abp.ObjectMapping; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
|
using Win_in.Sfs.Basedata.Domain; |
|
|
|
using Win_in.Sfs.Label.Application.Contracts; |
|
|
|
using Win_in.Sfs.Label.Domain.Shared; |
|
|
|
using Win_in.Sfs.Shared.Domain; |
|
|
@ -32,10 +35,9 @@ public class PurchaseOrderEventHandler |
|
|
|
private readonly IItemPackAppService _itemPackAppService; |
|
|
|
private readonly ISupplierItemAppService _supplierItemAppService; |
|
|
|
private readonly IDockAppService _dockAppService; |
|
|
|
private readonly ISupplierTimeWindowAppService _supplierTimeWindowAppService; |
|
|
|
private readonly IInventoryLabelAppService _inventoryLabelAppService; |
|
|
|
private readonly ISupplierAppService _supplierAppService; |
|
|
|
private readonly ISupplierTimeWindowAppService _supplierTimeWindowAppService; |
|
|
|
|
|
|
|
|
|
|
|
public PurchaseOrderEventHandler(ISupplierAsnAppService supplierAsnAppService, |
|
|
|
ILabelDefinitionAppService labelDefinitionAppService, |
|
|
@ -94,10 +96,41 @@ public class PurchaseOrderEventHandler |
|
|
|
private async Task<SupplierAsnEditInput> BuildSupplierAsnAsync(PurchaseOrder purchaseOrder) |
|
|
|
{ |
|
|
|
var supplierAsnEditInput= ObjectMapper.Map<PurchaseOrder, SupplierAsnEditInput>(purchaseOrder); |
|
|
|
supplierAsnEditInput.Details = new EditableList<SupplierAsnDetailInput>();//导入的是采购订单 所以下面要根据标包计算 拆成多个发货单
|
|
|
|
|
|
|
|
//收货口 //todo 处理有问题是否要和供应商关联
|
|
|
|
//所有的物品Code
|
|
|
|
var itemCodes = purchaseOrder.Details.GroupBy(p =>new{ p.ItemCode,p.Lot}).Select(p => p.Key.ItemCode); |
|
|
|
|
|
|
|
//收货口
|
|
|
|
var dock = await _dockAppService.GetAllListByFilterAsync( |
|
|
|
new SfsBaseDataRequestInputBase() { Condition = new Condition(){Filters = new List<Filter>()}, MaxResultCount = 99, SkipCount = 0, Sorting = string.Empty }, true).ConfigureAwait(false); |
|
|
|
new SfsBaseDataRequestInputBase() { Condition = new Condition() { Filters = new List<Filter>() }, MaxResultCount = 99, SkipCount = 0, Sorting = string.Empty }, true).ConfigureAwait(false); |
|
|
|
|
|
|
|
//供应商窗口
|
|
|
|
var supplierTimeWindowDtos = await _supplierTimeWindowAppService.GetListBySupplierCodeAsync(purchaseOrder.SupplierCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
//一次性返回所有物品信息
|
|
|
|
var itemBasicDtos = await _itemBasicAppService.GetByCodesAsync(itemCodes).ConfigureAwait(false); |
|
|
|
var ItemPacks = new List<ItemPackDTO>();//一次性返回所有物品包装信息
|
|
|
|
var supplierItemDtos = new List<SupplierItemDTO>();//一次性返回所有供应商物品信息
|
|
|
|
|
|
|
|
//供应商信息
|
|
|
|
var supplierDto =await _supplierAppService.GetByCodeAsync(purchaseOrder.SupplierCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
//所有的标签
|
|
|
|
List<InventoryLabelEditInput> inventoryLabelEditInputs = new List<InventoryLabelEditInput>(); |
|
|
|
|
|
|
|
foreach (var itemCode in itemCodes)//查询
|
|
|
|
{ |
|
|
|
var itemPackDtos = await _itemPackAppService.GetListByItemCodeAsync(itemCode).ConfigureAwait(false); |
|
|
|
var itemPackDto = itemPackDtos.First(); |
|
|
|
var supplierItem = await _supplierItemAppService.GetBySupplierCodeAndItemCodeAsync(purchaseOrder.SupplierCode, itemCode).ConfigureAwait(false); |
|
|
|
ItemPacks.Add(itemPackDto); |
|
|
|
supplierItemDtos.Add(supplierItem); |
|
|
|
} |
|
|
|
|
|
|
|
#region 主表赋值
|
|
|
|
|
|
|
|
//收货口 //todo 处理有问题是否要和供应商关联
|
|
|
|
supplierAsnEditInput.DockCode = dock.First().Code; |
|
|
|
|
|
|
|
//赋值采购订单编号
|
|
|
@ -119,7 +152,6 @@ public class PurchaseOrderEventHandler |
|
|
|
supplierAsnEditInput.CreateType = EnumSupplierAsnCreateType.Import; |
|
|
|
|
|
|
|
//供应商时间窗口
|
|
|
|
var supplierTimeWindowDtos=await _supplierTimeWindowAppService.GetListBySupplierCodeAsync(purchaseOrder.SupplierCode).ConfigureAwait(false); |
|
|
|
var dayOfWeek = new List<string>() { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; |
|
|
|
var chineseWeek= dayOfWeek[Clock.Now.DayOfWeek.GetHashCode()]; //中文星期
|
|
|
|
var dateTimeWindowDto=supplierTimeWindowDtos.First(p => p.Week == chineseWeek); |
|
|
@ -131,67 +163,162 @@ public class PurchaseOrderEventHandler |
|
|
|
//发货单号
|
|
|
|
supplierAsnEditInput.Number = await _supplierAsnAppService.GenerateSupplierAsnNumberAsync(supplierAsnEditInput.ActiveDate).ConfigureAwait(false); |
|
|
|
|
|
|
|
//所有的物品Code
|
|
|
|
var itemCodes = purchaseOrder.Details.GroupBy(p => p.ItemCode).Select(p => p.Key); |
|
|
|
|
|
|
|
//一次性返回所有物品信息
|
|
|
|
var itemBasicDtos=await _itemBasicAppService.GetByCodesAsync(itemCodes).ConfigureAwait(false); |
|
|
|
var ItemPacks = new List<ItemPackDTO>();//一次性返回所有物品包装信息
|
|
|
|
var supplierItemDtos = new List<SupplierItemDTO>();//一次性返回所有供应商物品信息
|
|
|
|
|
|
|
|
//一次性返回所有箱码
|
|
|
|
var generateManyAsync = await _labelDefinitionAppService |
|
|
|
.GenerateManyAsync(EnumLabelType.PurchaseLabel.ToString(), Clock.Now.ToString(SharedConst.TimeFormat), |
|
|
|
supplierAsnEditInput.Details.Count).ConfigureAwait(false); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
foreach (var itemCode in itemCodes)//查询
|
|
|
|
//根据采购订单的数量拆分成多个 箱
|
|
|
|
foreach (var purchaseOrderDetaildetail in purchaseOrder.Details) |
|
|
|
{ |
|
|
|
var itemPackDtos = await _itemPackAppService.GetListByItemCodeAsync(itemCode).ConfigureAwait(false); |
|
|
|
var itemPackDto = itemPackDtos.First(); |
|
|
|
var supplierItem = await _supplierItemAppService.GetBySupplierCodeAndItemCodeAsync(purchaseOrder.SupplierCode, itemCode).ConfigureAwait(false); |
|
|
|
ItemPacks.Add(itemPackDto); |
|
|
|
supplierItemDtos.Add(supplierItem); |
|
|
|
} |
|
|
|
//当前物品的总数
|
|
|
|
var itemQty = purchaseOrderDetaildetail.Qty; |
|
|
|
|
|
|
|
//赋值 详情表
|
|
|
|
supplierAsnEditInput.Details.ForEach(detail => |
|
|
|
{ |
|
|
|
var purchaseOrderDetail= purchaseOrder.Details.First(p => p.ItemCode == detail.ItemCode); |
|
|
|
//todo 一个物品多个包装?怎么取值
|
|
|
|
//标包数
|
|
|
|
var itemPackDto=ItemPacks.First(p => p.ItemCode == purchaseOrderDetaildetail.ItemCode); |
|
|
|
|
|
|
|
//添加箱码
|
|
|
|
var pakcingCode = generateManyAsync.First(); |
|
|
|
detail.PackingCode = pakcingCode; |
|
|
|
generateManyAsync.Remove(pakcingCode); |
|
|
|
//总箱数
|
|
|
|
var itemPackQty = (int)(itemQty / itemPackDto.Qty); |
|
|
|
if (itemQty % itemPackQty!= 0) |
|
|
|
{ |
|
|
|
itemPackQty++; |
|
|
|
} |
|
|
|
|
|
|
|
//添加物品信息
|
|
|
|
var itemBasicDto= itemBasicDtos.First(p=>p.Code==detail.ItemCode); |
|
|
|
detail.ItemName= itemBasicDto.Name; |
|
|
|
detail.ItemDesc1 = itemBasicDto.Desc1; |
|
|
|
detail.ItemDesc2= itemBasicDto.Desc2; |
|
|
|
|
|
|
|
//标包
|
|
|
|
var itemPack = ItemPacks.First(p => p.ItemCode == detail.ItemCode); //todo 一个物品多个包装?怎么取值
|
|
|
|
detail.StdPackQty = itemPack.Qty; |
|
|
|
var itemBasicDto = itemBasicDtos.First(p => p.Code == purchaseOrderDetaildetail.ItemCode); |
|
|
|
|
|
|
|
//供应商物品
|
|
|
|
var supplierItemDto=supplierItemDtos.First(p => |
|
|
|
p.ItemCode == detail.ItemCode && p.SupplierCode == supplierAsnEditInput.SupplierCode); |
|
|
|
detail.SupplierPackQty = supplierItemDto.SupplierPackQty; |
|
|
|
detail.SupplierPackUom= supplierItemDto.SupplierPackUom; |
|
|
|
//todo 批次赋值有问题
|
|
|
|
detail.SupplierBatch = purchaseOrderDetail.Lot; |
|
|
|
var supplierItemDto = supplierItemDtos.First(p => |
|
|
|
p.ItemCode == purchaseOrderDetaildetail.ItemCode && p.SupplierCode == purchaseOrder.SupplierCode); |
|
|
|
|
|
|
|
//一次性返回所有箱码
|
|
|
|
var generateManyAsync = await _labelDefinitionAppService |
|
|
|
.GenerateManyAsync(EnumLabelType.PurchaseLabel.ToString(), Clock.Now.ToString(SharedConst.TimeFormat), |
|
|
|
itemPackQty).ConfigureAwait(false); |
|
|
|
|
|
|
|
for (var i = 0; i < itemPackQty; i++) |
|
|
|
{ |
|
|
|
var supplierAsnDetailInput = ObjectMapper.Map<PurchaseOrderDetail, SupplierAsnDetailInput>(purchaseOrderDetaildetail); |
|
|
|
//添加箱码
|
|
|
|
var pakcingCode = generateManyAsync.First(); |
|
|
|
supplierAsnDetailInput.PackingCode = pakcingCode; |
|
|
|
generateManyAsync.Remove(pakcingCode); |
|
|
|
|
|
|
|
supplierAsnDetailInput.ItemName = itemBasicDto.Name; |
|
|
|
supplierAsnDetailInput.ItemDesc1 = itemBasicDto.Desc1; |
|
|
|
supplierAsnDetailInput.ItemDesc2 = itemBasicDto.Desc2; |
|
|
|
|
|
|
|
//标包
|
|
|
|
supplierAsnDetailInput.StdPackQty = itemPackDto.Qty; |
|
|
|
|
|
|
|
supplierAsnDetailInput.SupplierPackQty = supplierItemDto.SupplierPackQty; |
|
|
|
supplierAsnDetailInput.SupplierPackUom = supplierItemDto.SupplierPackUom; |
|
|
|
//todo 批次赋值有问题
|
|
|
|
supplierAsnDetailInput.SupplierBatch = purchaseOrderDetaildetail.Lot; |
|
|
|
|
|
|
|
//订单行
|
|
|
|
supplierAsnDetailInput.PoLine = purchaseOrderDetaildetail.PoLine; |
|
|
|
|
|
|
|
//推荐ERP库位
|
|
|
|
supplierAsnDetailInput.RecommendErpCode = purchaseOrderDetaildetail.LocationErpCode; |
|
|
|
|
|
|
|
//订单行
|
|
|
|
detail.PoLine = purchaseOrderDetail.PoLine; |
|
|
|
supplierAsnDetailInput.PoNumber = purchaseOrder.Number; |
|
|
|
supplierAsnDetailInput.Qty = itemQty>itemPackDto.Qty ? itemPackDto.Qty : itemQty; |
|
|
|
|
|
|
|
//推荐ERP库位
|
|
|
|
detail.RecommendErpCode = purchaseOrderDetail.LocationErpCode; |
|
|
|
itemQty-=itemPackDto.Qty; |
|
|
|
|
|
|
|
detail.PoNumber = purchaseOrder.Number; |
|
|
|
}); |
|
|
|
var InventoryLabelEditInput = await BuildInventoryLabelEditInputAsync(supplierAsnEditInput, supplierAsnDetailInput, supplierDto, itemBasicDto, supplierItemDto, itemPackDto).ConfigureAwait(false); |
|
|
|
inventoryLabelEditInputs.Add(InventoryLabelEditInput); |
|
|
|
|
|
|
|
supplierAsnEditInput.Details.Add(supplierAsnDetailInput); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//插入所有的标签
|
|
|
|
await _inventoryLabelAppService.CreateManyByNoCodeAsync(inventoryLabelEditInputs).ConfigureAwait(false); |
|
|
|
|
|
|
|
//赋值 详情表
|
|
|
|
return supplierAsnEditInput; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 创建 构造标签
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="supplierAsn"></param>
|
|
|
|
/// <param name="supplierAsnDetail"></param>
|
|
|
|
/// <param name="supplierDto"></param>
|
|
|
|
/// <param name="itemBasicDto"></param>
|
|
|
|
/// <param name="supplierItemDto"></param>
|
|
|
|
/// <param name="itemPackDto"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private Task<InventoryLabelEditInput> BuildInventoryLabelEditInputAsync(SupplierAsnEditInput supplierAsn, |
|
|
|
SupplierAsnDetailInput supplierAsnDetail, |
|
|
|
SupplierDTO supplierDto, |
|
|
|
ItemBasicDTO itemBasicDto, |
|
|
|
SupplierItemDTO supplierItemDto, |
|
|
|
ItemPackDTO itemPackDto) |
|
|
|
{ |
|
|
|
if (itemBasicDto == null) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"{supplierAsnDetail.ItemCode}零件信息为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (supplierDto == null) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"{supplierAsn.SupplierCode}供应商为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (supplierItemDto == null) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"{supplierAsn.SupplierCode}供应商零件或{itemBasicDto.Code}零件信息为空"); |
|
|
|
} |
|
|
|
|
|
|
|
var inputLabel = new InventoryLabelEditInput(); |
|
|
|
inputLabel.LabelType = EnumLabelType.PurchaseLabel; |
|
|
|
|
|
|
|
inputLabel.SupplierCode = supplierAsn.SupplierCode; |
|
|
|
inputLabel.RpNumber = supplierAsn.RpNumber; |
|
|
|
inputLabel.AsnNumber = supplierAsn.Number; |
|
|
|
|
|
|
|
inputLabel.PoNumber = supplierAsnDetail.PoNumber; |
|
|
|
inputLabel.SupplierBatch = supplierAsnDetail.SupplierBatch; |
|
|
|
inputLabel.ProduceDate = supplierAsnDetail.ProduceDate; |
|
|
|
inputLabel.ArriveDate = supplierAsnDetail.ArriveDate; |
|
|
|
inputLabel.FullBarcodeString = supplierAsnDetail.PackingCode; |
|
|
|
inputLabel.LocationErpCode = supplierAsnDetail.RecommendErpCode; |
|
|
|
inputLabel.Lot = supplierAsnDetail.Lot; |
|
|
|
inputLabel.RecommendLocationCode = supplierAsnDetail.RecommendErpCode; |
|
|
|
inputLabel.Remark = supplierAsnDetail.Remark; |
|
|
|
inputLabel.Code = supplierAsnDetail.PackingCode; |
|
|
|
|
|
|
|
inputLabel.Qty = supplierAsnDetail.Qty; |
|
|
|
inputLabel.Uom = supplierAsnDetail.Uom; |
|
|
|
|
|
|
|
inputLabel.ItemCode = itemBasicDto.Code; |
|
|
|
inputLabel.ItemName = itemBasicDto.Name; |
|
|
|
inputLabel.ItemDesc1 = itemBasicDto.Desc1; |
|
|
|
inputLabel.ItemDesc2 = itemBasicDto.Desc2; |
|
|
|
|
|
|
|
inputLabel.ExpireDate = DateTime.Now.AddDays(itemBasicDto.GetValidateDays()); |
|
|
|
|
|
|
|
inputLabel.ExtraProperties = new ExtraPropertyDictionary(); |
|
|
|
inputLabel.LabelStatus = LabelStatus.Enable; |
|
|
|
|
|
|
|
inputLabel.Specifications = itemBasicDto.Color; |
|
|
|
inputLabel.StdPackQty = itemPackDto.Qty; |
|
|
|
|
|
|
|
inputLabel.SupplierItemCode = supplierItemDto.SupplierItemCode; |
|
|
|
inputLabel.SupplierItemName = supplierItemDto.ItemName; |
|
|
|
inputLabel.SupplierName = supplierDto.Name; |
|
|
|
inputLabel.SupplierSimpleName = supplierDto.ShortName; |
|
|
|
inputLabel.Team = string.Empty; |
|
|
|
inputLabel.ProdLine = string.Empty; |
|
|
|
inputLabel.QLevel = string.Empty; |
|
|
|
inputLabel.QualityFile = string.Empty; |
|
|
|
|
|
|
|
inputLabel.Shift = string.Empty; |
|
|
|
inputLabel.ContainerCode = string.Empty; |
|
|
|
|
|
|
|
return Task.FromResult(inputLabel); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|