|
|
@ -1,3 +1,4 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
|
using System.Linq; |
|
|
@ -7,6 +8,7 @@ using Irony; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Omu.ValueInjecter; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.ObjectMapping; |
|
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
@ -65,17 +67,47 @@ public class UnplannedIssueJobAppService |
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("create-by-recommend")] |
|
|
|
public async Task CreateByRecommendAsync(UnplannedReceiptRequestDTO requestDto) |
|
|
|
public async Task CreateByRecommendAsync(UnplannedIssueRequest requestDto) |
|
|
|
{ |
|
|
|
List<BalanceDTO> useBalancesOut = new EditableList<BalanceDTO>(); |
|
|
|
var jobs = await BuildUnplannedIssueJobAsync(requestDto, useBalancesOut).ConfigureAwait(false); |
|
|
|
await _repository.InsertManyAsync(jobs.ToList()).ConfigureAwait(false); |
|
|
|
await _unplannedIssueJobManager.AddManyAsync(jobs).ConfigureAwait(false); |
|
|
|
//await _repository.InsertManyAsync(jobs.ToList()).ConfigureAwait(false);
|
|
|
|
var first = jobs.FirstOrDefault(); |
|
|
|
var outEditInputs = await BuildExpectOutAsync(useBalancesOut).ConfigureAwait(false); |
|
|
|
foreach (var itm in outEditInputs) |
|
|
|
{ |
|
|
|
itm.JobNumber = first.Number; |
|
|
|
} |
|
|
|
await _expectOutAppService.AddManyAsync(outEditInputs).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<BalanceDTO> DeductInventory(List<BalanceDTO> inventory, decimal quantityToDeduct) |
|
|
|
{ |
|
|
|
List<BalanceDTO> balanceDTOs = new List<BalanceDTO>(); |
|
|
|
decimal totalDeducted = 0; |
|
|
|
foreach (var item in inventory) |
|
|
|
{ |
|
|
|
decimal availableToDeduct = Math.Min(item.Qty, quantityToDeduct - totalDeducted); |
|
|
|
item.Qty -= availableToDeduct; |
|
|
|
totalDeducted += availableToDeduct; |
|
|
|
BalanceDTO dto = new BalanceDTO(); |
|
|
|
dto.InjectFrom(item); |
|
|
|
dto.Qty = availableToDeduct; |
|
|
|
balanceDTOs.Add(dto); |
|
|
|
// 如果已经扣减达到所需数量,退出循环
|
|
|
|
if (totalDeducted >= quantityToDeduct) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
// 返回实际扣减的库存数量
|
|
|
|
return balanceDTOs; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -83,13 +115,16 @@ public class UnplannedIssueJobAppService |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<UnplannedIssueJob>> BuildUnplannedIssueJobAsync(UnplannedReceiptRequestDTO requestDto, List<BalanceDTO> useBalancesOut) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<UnplannedIssueJob>> BuildUnplannedIssueJobAsync(UnplannedIssueRequest requestDto, List<BalanceDTO> useBalancesOut) |
|
|
|
{ |
|
|
|
List<UnplannedIssueJob> jobs = new EditableList<UnplannedIssueJob>(); |
|
|
|
|
|
|
|
foreach (var requestDtoDetail in requestDto.Details)//非计划领料明细
|
|
|
|
{ |
|
|
|
var locationCodes = await _locationAppService.GetListByErpLocationCodes(new StringList(requestDtoDetail.ErpLocationCode)).ConfigureAwait(false);//获取存放库位
|
|
|
|
var locationCodes = await _locationAppService.GetListByErpLocationCodes(new StringList(requestDtoDetail.LocationErpCode)).ConfigureAwait(false);//获取存放库位
|
|
|
|
var input = new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = requestDtoDetail.ItemCode, |
|
|
@ -98,6 +133,8 @@ public class UnplannedIssueJobAppService |
|
|
|
Locations = locationCodes.Select(p => p.Code).ToList(), |
|
|
|
IsPackingCode = false |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var usableList = await _balanceAppService.GetUsableListAsync(input).ConfigureAwait(false);//获取推荐库存
|
|
|
|
usableList = usableList |
|
|
|
.OrderBy(p => p.Lot) |
|
|
@ -110,35 +147,60 @@ public class UnplannedIssueJobAppService |
|
|
|
decimal qty = 0; |
|
|
|
//实际要用库存
|
|
|
|
List<BalanceDTO> useBalances = new List<BalanceDTO>(); |
|
|
|
foreach (var balanceDto in usableList) |
|
|
|
{ |
|
|
|
if (qty >= requestDtoDetail.Qty) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
if (qty + balanceDto.Qty > requestDtoDetail.Qty) |
|
|
|
{ |
|
|
|
qty += requestDtoDetail.Qty - balanceDto.Qty; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
qty += balanceDto.Qty; |
|
|
|
} |
|
|
|
|
|
|
|
useBalances.Add(balanceDto); |
|
|
|
useBalancesOut.Add(balanceDto); |
|
|
|
|
|
|
|
var returnlist=DeductInventory(usableList, requestDtoDetail.Qty); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useBalances.AddRange(returnlist); |
|
|
|
useBalancesOut.AddRange(returnlist); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//foreach (var balanceDto in usableList)
|
|
|
|
//{
|
|
|
|
// decimal availableToDeduct = Math.Min(balanceDto.Qty, balanceDto.Qty - qty);
|
|
|
|
// balanceDto.Qty -= availableToDeduct;
|
|
|
|
// qty += availableToDeduct;
|
|
|
|
// if (qty >= balanceDto.Qty)
|
|
|
|
// break;
|
|
|
|
// if (qty >= requestDtoDetail.Qty)
|
|
|
|
// {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// if (qty + balanceDto.Qty > requestDtoDetail.Qty)
|
|
|
|
// {
|
|
|
|
// qty += requestDtoDetail.Qty - balanceDto.Qty;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// qty += balanceDto.Qty;
|
|
|
|
// }
|
|
|
|
// if (qty > 0)
|
|
|
|
// {
|
|
|
|
// useBalances.Add(balanceDto);
|
|
|
|
// useBalancesOut.Add(balanceDto);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
if (returnlist.Count == 0) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("库存余额不够!"); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var balanceDtoGroup in useBalances.GroupBy(p => p.LocationCode)) |
|
|
|
{ |
|
|
|
var locationDto = await _locationAppService.GetByCodeAsync(balanceDtoGroup.Key).ConfigureAwait(false); |
|
|
|
var job = new UnplannedIssueJob(); |
|
|
|
|
|
|
|
job.SetId(GuidGenerator.Create()); |
|
|
|
job.UnplannedIssueRequestNumber= requestDto.Number; |
|
|
|
job.JobType = EnumJobType.UnplannedIssueJob; |
|
|
|
job.JobStatus = EnumJobStatus.Open; |
|
|
|
job.IsAutoComplete = false; |
|
|
|
job.OANumber = requestDto.OANumber; |
|
|
|
job.Number =await _unplannedIssueJobManager.GetNumber().ConfigureAwait(true); |
|
|
|
|
|
|
|
job.Details = new List<UnplannedIssueJobDetail>(); |
|
|
|
job.FacDetails = new List<UnplannedIssueJobFacDetail>(); |
|
|
|
job.WarehouseCode = balanceDtoGroup.First().WarehouseCode; |
|
|
@ -146,11 +208,15 @@ public class UnplannedIssueJobAppService |
|
|
|
foreach (var balanceDto in balanceDtoGroup) |
|
|
|
{ |
|
|
|
var jobDetail = new UnplannedIssueJobDetail(); |
|
|
|
|
|
|
|
jobDetail.Number = job.Number; |
|
|
|
jobDetail.SetIdAndNumber(GuidGenerator,job.Id,job.Number); |
|
|
|
|
|
|
|
jobDetail.CaseCode = requestDtoDetail.CaseCode; |
|
|
|
jobDetail.Explain = requestDtoDetail.Explain; |
|
|
|
jobDetail.OnceBusiCode = requestDtoDetail.OnceBusiCode; |
|
|
|
jobDetail.ProjCapacityCode = requestDtoDetail.ProjCapacityCode; |
|
|
|
jobDetail.ReasonCode = requestDtoDetail.ReasonCode; |
|
|
|
//jobDetail.ReasonCode = requestDtoDetail.ReasonCode;
|
|
|
|
jobDetail.ItemCode = requestDtoDetail.ItemCode; |
|
|
|
jobDetail.ItemDesc1 = requestDtoDetail.ItemDesc1; |
|
|
|
jobDetail.ItemDesc2 = requestDtoDetail.ItemDesc2; |
|
|
@ -165,11 +231,14 @@ public class UnplannedIssueJobAppService |
|
|
|
jobDetail.RecommendSupplierBatch = balanceDto.SupplierBatch; |
|
|
|
|
|
|
|
var jobfacDetail = new UnplannedIssueJobFacDetail(); |
|
|
|
|
|
|
|
jobfacDetail.Number = job.Number; |
|
|
|
jobfacDetail.SetIdAndNumber(GuidGenerator, job.Id, job.Number); |
|
|
|
jobfacDetail.CaseCode = requestDtoDetail.CaseCode; |
|
|
|
jobfacDetail.Explain = requestDtoDetail.Explain; |
|
|
|
jobfacDetail.OnceBusiCode = requestDtoDetail.OnceBusiCode; |
|
|
|
jobfacDetail.ProjCapacityCode = requestDtoDetail.ProjCapacityCode; |
|
|
|
jobfacDetail.ReasonCode = requestDtoDetail.ReasonCode; |
|
|
|
//jobfacDetail.ReasonCode = requestDtoDetail.ReasonCode;
|
|
|
|
jobfacDetail.ItemCode = requestDtoDetail.ItemCode; |
|
|
|
jobfacDetail.ItemDesc1 = requestDtoDetail.ItemDesc1; |
|
|
|
jobfacDetail.ItemDesc2 = requestDtoDetail.ItemDesc2; |
|
|
@ -182,6 +251,8 @@ public class UnplannedIssueJobAppService |
|
|
|
jobfacDetail.RecommendProduceDate = balanceDto.ProduceDate; |
|
|
|
jobfacDetail.RecommendQty = balanceDto.Qty; |
|
|
|
jobfacDetail.RecommendSupplierBatch = balanceDto.SupplierBatch; |
|
|
|
|
|
|
|
|
|
|
|
//jobDetail.recommendRecommendToLocationArea = balanceDto.LocationArea;
|
|
|
|
//jobDetail.RecommendToLocationCode = balanceDto.LocationCode;
|
|
|
|
//jobDetail.RecommendToLocationErpCode = balanceDto.LocationErpCode;
|
|
|
@ -190,8 +261,11 @@ public class UnplannedIssueJobAppService |
|
|
|
|
|
|
|
job.Details.Add(jobDetail); |
|
|
|
job.FacDetails.Add(jobfacDetail); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//job.SetProperty("details", System.Text.Json.JsonSerializer.Serialize(job.Details));
|
|
|
|
|
|
|
|