|
|
@ -114,7 +114,7 @@ public class UnplannedIssueJobAppService |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<BalanceDTO>> DeductInventory(List<BalanceDTO> inventory, decimal quantityToDeduct) |
|
|
|
private async Task<List<BalanceDTO>> DeductInventory(List<BalanceDTO> inventory, decimal quantityToDeduct, EnumLocationType enumLocationType) |
|
|
|
{ |
|
|
|
List<BalanceDTO> balanceDTOs = new List<BalanceDTO>(); |
|
|
|
decimal totalDeducted = 0; |
|
|
@ -128,26 +128,18 @@ public class UnplannedIssueJobAppService |
|
|
|
{ |
|
|
|
var locationDto = await _locationAppService.GetByCodeAsync(item.LocationCode).ConfigureAwait(false); |
|
|
|
BalanceDTO dto = new BalanceDTO(); |
|
|
|
switch (locationDto.Type) |
|
|
|
if (enumLocationType == EnumLocationType.RAW) |
|
|
|
{ |
|
|
|
case EnumLocationType.RAW: |
|
|
|
dto.InjectFrom(item); |
|
|
|
dto.Qty = availableToDeduct; |
|
|
|
balanceDTOs.Add(dto); |
|
|
|
break; |
|
|
|
case EnumLocationType.FG: |
|
|
|
case EnumLocationType.DimensionalStorehouse: |
|
|
|
case EnumLocationType.CUST: |
|
|
|
case EnumLocationType.KittingWip: |
|
|
|
case EnumLocationType.OUTSIDE: |
|
|
|
case EnumLocationType.SEMI: |
|
|
|
case EnumLocationType.WIP: |
|
|
|
case EnumLocationType.THIRDPARTY: |
|
|
|
|
|
|
|
dto.InjectFrom(item); |
|
|
|
balanceDTOs.Add(dto); |
|
|
|
break; |
|
|
|
} |
|
|
|
dto.InjectFrom(item); |
|
|
|
dto.Qty = availableToDeduct; |
|
|
|
balanceDTOs.Add(dto); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
dto.InjectFrom(item); |
|
|
|
balanceDTOs.Add(dto); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// 如果已经扣减达到所需数量,退出循环
|
|
|
|
if (totalDeducted >= quantityToDeduct) |
|
|
@ -160,8 +152,7 @@ public class UnplannedIssueJobAppService |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<UnplannedIssueJob>> BuildUnplannedIssueJobAsync(UnplannedIssueRequest requestDto, List<BalanceDTO> useBalancesOut) |
|
|
|
{ |
|
|
|
List<UnplannedIssueJob> jobs = new EditableList<UnplannedIssueJob>(); |
|
|
@ -171,18 +162,109 @@ public class UnplannedIssueJobAppService |
|
|
|
{ |
|
|
|
var locationCodes = await _locationAppService.GetListByErpLocationCodes(new StringList(requestDtoDetail.LocationErpCode)).ConfigureAwait(false);//获取存放库位
|
|
|
|
|
|
|
|
var input = new RecommendBalanceRequestInput |
|
|
|
if (locationCodes.Count == 0) |
|
|
|
{ |
|
|
|
ItemCode = requestDtoDetail.ItemCode, |
|
|
|
Qty = requestDtoDetail.Qty, |
|
|
|
Statuses = new EditableList<EnumInventoryStatus> { EnumInventoryStatus.OK }, |
|
|
|
Locations = locationCodes.Select(p => p.Code).ToList(), |
|
|
|
IsPackingCode = false |
|
|
|
}; |
|
|
|
var usableList = await _balanceAppService.GetUsableListAsync(input).ConfigureAwait(false);//获取推荐库存
|
|
|
|
throw new UserFriendlyException("ERP库位没有对应WMS库位!"); |
|
|
|
} |
|
|
|
|
|
|
|
var first=locationCodes.FirstOrDefault(); |
|
|
|
var locationDto = await _locationAppService.GetByCodeAsync(first.Code).ConfigureAwait(false); |
|
|
|
var input = new RecommendBalanceRequestInput(); |
|
|
|
switch (locationDto.Type) |
|
|
|
{ |
|
|
|
case EnumLocationType.RAW: |
|
|
|
input = new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = requestDtoDetail.ItemCode, |
|
|
|
Qty = requestDtoDetail.Qty, |
|
|
|
Statuses = new EditableList<EnumInventoryStatus> { EnumInventoryStatus.OK }, |
|
|
|
Locations = locationCodes.Select(p => p.Code).ToList(), |
|
|
|
IsPackingCode = true |
|
|
|
}; |
|
|
|
break; |
|
|
|
case EnumLocationType.FG: |
|
|
|
input = new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = requestDtoDetail.ItemCode, |
|
|
|
Qty = requestDtoDetail.Qty, |
|
|
|
Statuses = new EditableList<EnumInventoryStatus> { EnumInventoryStatus.OK }, |
|
|
|
Locations = locationCodes.Select(p => p.Code).ToList(), |
|
|
|
IsPackingCode = false |
|
|
|
}; |
|
|
|
break; |
|
|
|
case EnumLocationType.DimensionalStorehouse: |
|
|
|
input = new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = requestDtoDetail.ItemCode, |
|
|
|
Qty = requestDtoDetail.Qty, |
|
|
|
Statuses = new EditableList<EnumInventoryStatus> { EnumInventoryStatus.OK }, |
|
|
|
Locations = locationCodes.Select(p => p.Code).ToList(), |
|
|
|
IsPackingCode = false |
|
|
|
}; |
|
|
|
break; |
|
|
|
case EnumLocationType.CUST: |
|
|
|
input = new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = requestDtoDetail.ItemCode, |
|
|
|
Qty = requestDtoDetail.Qty, |
|
|
|
Statuses = new EditableList<EnumInventoryStatus> { EnumInventoryStatus.OK }, |
|
|
|
Locations = locationCodes.Select(p => p.Code).ToList(), |
|
|
|
IsPackingCode = false |
|
|
|
}; |
|
|
|
break; |
|
|
|
case EnumLocationType.KittingWip: |
|
|
|
input = new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = requestDtoDetail.ItemCode, |
|
|
|
Qty = requestDtoDetail.Qty, |
|
|
|
Statuses = new EditableList<EnumInventoryStatus> { EnumInventoryStatus.OK }, |
|
|
|
Locations = locationCodes.Select(p => p.Code).ToList(), |
|
|
|
IsPackingCode = false |
|
|
|
}; |
|
|
|
break; |
|
|
|
case EnumLocationType.OUTSIDE: |
|
|
|
input = new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = requestDtoDetail.ItemCode, |
|
|
|
Qty = requestDtoDetail.Qty, |
|
|
|
Statuses = new EditableList<EnumInventoryStatus> { EnumInventoryStatus.OK }, |
|
|
|
Locations = locationCodes.Select(p => p.Code).ToList(), |
|
|
|
IsPackingCode = false |
|
|
|
}; |
|
|
|
break; |
|
|
|
case EnumLocationType.SEMI: |
|
|
|
input = new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = requestDtoDetail.ItemCode, |
|
|
|
Qty = requestDtoDetail.Qty, |
|
|
|
Statuses = new EditableList<EnumInventoryStatus> { EnumInventoryStatus.OK }, |
|
|
|
Locations = locationCodes.Select(p => p.Code).ToList(), |
|
|
|
IsPackingCode = false |
|
|
|
}; |
|
|
|
break; |
|
|
|
case EnumLocationType.WIP: |
|
|
|
input = new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = requestDtoDetail.ItemCode, |
|
|
|
Qty = requestDtoDetail.Qty, |
|
|
|
Statuses = new EditableList<EnumInventoryStatus> { EnumInventoryStatus.OK }, |
|
|
|
Locations = locationCodes.Select(p => p.Code).ToList(), |
|
|
|
IsPackingCode = false |
|
|
|
}; |
|
|
|
break; |
|
|
|
case EnumLocationType.THIRDPARTY: |
|
|
|
input = new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = requestDtoDetail.ItemCode, |
|
|
|
Qty = requestDtoDetail.Qty, |
|
|
|
Statuses = new EditableList<EnumInventoryStatus> { EnumInventoryStatus.OK }, |
|
|
|
Locations = locationCodes.Select(p => p.Code).ToList(), |
|
|
|
IsPackingCode = false |
|
|
|
}; |
|
|
|
break; |
|
|
|
} |
|
|
|
var usableList = await _balanceAppService.GetUsableListAsync(input).ConfigureAwait(false);//获取推荐库存
|
|
|
|
usableList = usableList.Where(p => p.Qty> 0).ToList(); |
|
|
|
|
|
|
|
usableList = usableList |
|
|
|
.OrderBy(p => p.Lot) |
|
|
|
.ThenBy(p => p.PutInTime) |
|
|
@ -194,7 +276,7 @@ public class UnplannedIssueJobAppService |
|
|
|
decimal qty = 0; |
|
|
|
//实际要用库存
|
|
|
|
List<BalanceDTO> useBalances = new List<BalanceDTO>(); |
|
|
|
var returnlist=await DeductInventory(usableList, requestDtoDetail.Qty).ConfigureAwait(false); |
|
|
|
var returnlist=await DeductInventory(usableList, requestDtoDetail.Qty, locationDto.Type).ConfigureAwait(false); |
|
|
|
useBalances.AddRange(returnlist); |
|
|
|
useBalancesOut.AddRange(returnlist); |
|
|
|
|
|
|
@ -227,29 +309,22 @@ public class UnplannedIssueJobAppService |
|
|
|
//}
|
|
|
|
if (returnlist.Count == 0) |
|
|
|
{ |
|
|
|
Errors.Add($"{"非生产领料"+requestDto.Number+"零件号:"+requestDtoDetail.ItemCode + "库存不够" + requestDtoDetail.Qty.ToString()}"); |
|
|
|
|
|
|
|
Errors.Add($"{"非生产领料"+requestDto.Number+"零件号:"+requestDtoDetail.ItemCode + "库存不够" + requestDtoDetail.Qty.ToString()}"); |
|
|
|
} |
|
|
|
foreach (var balanceDtoGroup in useBalances.GroupBy(p => p.LocationCode)) |
|
|
|
{ |
|
|
|
var locationDto = await _locationAppService.GetByCodeAsync(balanceDtoGroup.Key).ConfigureAwait(false); |
|
|
|
//var locationDto = await _locationAppService.GetByCodeAsync(balanceDtoGroup.Key).ConfigureAwait(false);
|
|
|
|
var job = new UnplannedIssueJob(); |
|
|
|
switch (locationDto.Type) |
|
|
|
if (locationDto.Type==EnumLocationType.RAW) |
|
|
|
{ |
|
|
|
case EnumLocationType.RAW: |
|
|
|
job.UnplannedIssueType = EnumUnplannedIssueType.Raw; |
|
|
|
break; |
|
|
|
case EnumLocationType.FG: |
|
|
|
case EnumLocationType.DimensionalStorehouse: |
|
|
|
case EnumLocationType.CUST: |
|
|
|
case EnumLocationType.KittingWip: |
|
|
|
case EnumLocationType.OUTSIDE: |
|
|
|
case EnumLocationType.SEMI: |
|
|
|
case EnumLocationType.WIP: |
|
|
|
case EnumLocationType.THIRDPARTY: |
|
|
|
job.UnplannedIssueType = EnumUnplannedIssueType.Wip; |
|
|
|
break; |
|
|
|
job.UnplannedIssueType = EnumUnplannedIssueType.Raw; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
job.UnplannedIssueType = EnumUnplannedIssueType.Wip; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
job.SetId(GuidGenerator.Create()); |
|
|
|
job.UnplannedIssueRequestNumber= requestDto.Number; |
|
|
|
job.JobType = EnumJobType.UnplannedIssueJob; |
|
|
|