fix: las facturas ahora devuelven tmb el nombre del cliente.
This commit is contained in:
parent
e729388981
commit
c674ac66d9
|
|
@ -10,7 +10,5 @@ public class InvoiceDto
|
||||||
public decimal? Total { get; set; }
|
public decimal? Total { get; set; }
|
||||||
public decimal? RemainToPay { get; set; }
|
public decimal? RemainToPay { get; set; }
|
||||||
public string Status { get; set; }
|
public string Status { get; set; }
|
||||||
|
public string? ClientName { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +38,20 @@ public class InvoiceService(IDolibarrApiClient apiClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
var dataList = await apiClient.GetCollectionAsync<InvoiceResponse>(endpoint);
|
var dataList = await apiClient.GetCollectionAsync<InvoiceResponse>(endpoint);
|
||||||
return dataList.Select(InvoiceMapper.MapToInvoiceDto).ToList();
|
var invoices = dataList.Select(InvoiceMapper.MapToInvoiceDto).ToList();
|
||||||
|
|
||||||
|
if (invoices.Count == 0)
|
||||||
|
return invoices;
|
||||||
|
|
||||||
|
var clientIds = invoices.Select(i => i.ClientId).Distinct().ToList();
|
||||||
|
var clientNames = await GetClientNamesAsync(clientIds);
|
||||||
|
|
||||||
|
foreach (var invoice in invoices)
|
||||||
|
{
|
||||||
|
invoice.ClientName = clientNames.GetValueOrDefault(invoice.ClientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return invoices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> CreateInvoiceAsync(CreateInvoiceDto dto)
|
public async Task<int> CreateInvoiceAsync(CreateInvoiceDto dto)
|
||||||
|
|
@ -102,4 +115,13 @@ public class InvoiceService(IDolibarrApiClient apiClient)
|
||||||
|
|
||||||
await apiClient.PutAsync($"invoices/{id}", current);
|
await apiClient.PutAsync($"invoices/{id}", current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<Dictionary<int, string>> GetClientNamesAsync(List<int> clientIds)
|
||||||
|
{
|
||||||
|
var uniqueIds = clientIds.Distinct().ToList();
|
||||||
|
var tasks = uniqueIds.Select(id => apiClient.GetResourceAsync<ClientResponse>($"thirdparties/{id}"));
|
||||||
|
var clients = await Task.WhenAll(tasks);
|
||||||
|
return clients.Where(c => c is { id: not null })
|
||||||
|
.ToDictionary(c => int.Parse(c!.id!), c => c!.name ?? "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue