diff --git a/DoliMiddlewareApi/Controllers/InvoicesController.cs b/DoliMiddlewareApi/Controllers/InvoicesController.cs index 6b00b40..0eefa3d 100644 --- a/DoliMiddlewareApi/Controllers/InvoicesController.cs +++ b/DoliMiddlewareApi/Controllers/InvoicesController.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; using DoliMiddlewareApi.Dtos; using DoliMiddlewareApi.Dtos.command; +using DoliMiddlewareApi.Dtos.query; using DoliMiddlewareApi.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -82,4 +83,11 @@ public class InvoicesController(InvoiceService invoiceService) : ControllerBase await invoiceService.DeleteInvoiceLineAsync(invoiceId, lineId); return NoContent(); } + + [HttpGet("{id:int}/payments")] + public async Task>> GetInvoicePayments([Range(1, int.MaxValue)] int id) + { + var payments = await invoiceService.GetInvoicePaymentsAsync(id); + return Ok(payments); + } } diff --git a/DoliMiddlewareApi/Dtos/Dolibarr/InvoicePaymentResponse.cs b/DoliMiddlewareApi/Dtos/Dolibarr/InvoicePaymentResponse.cs new file mode 100644 index 0000000..e9ac85e --- /dev/null +++ b/DoliMiddlewareApi/Dtos/Dolibarr/InvoicePaymentResponse.cs @@ -0,0 +1,10 @@ +namespace DoliMiddlewareApi.Dtos.Dolibarr; + +public class InvoicePaymentResponse +{ + public required string amount { get; set; } + public string type { get; set; } + public required string date { get; set; } + public string num { get; set; } + public string @ref { get; set; } +} \ No newline at end of file diff --git a/DoliMiddlewareApi/Dtos/query/InvoicePaymentDto.cs b/DoliMiddlewareApi/Dtos/query/InvoicePaymentDto.cs new file mode 100644 index 0000000..f751820 --- /dev/null +++ b/DoliMiddlewareApi/Dtos/query/InvoicePaymentDto.cs @@ -0,0 +1,10 @@ +namespace DoliMiddlewareApi.Dtos.query; + +public class InvoicePaymentDto +{ + public required string @Ref { get; set; } + public DateTime PaymentDate { get; set; } + public string? Type { get; set; } + public string? TransactionNum { get; set; } + public int Amount { get; set; } +} \ No newline at end of file diff --git a/DoliMiddlewareApi/Mappers/InvoiceMapper.cs b/DoliMiddlewareApi/Mappers/InvoiceMapper.cs index e951d26..fb2d612 100644 --- a/DoliMiddlewareApi/Mappers/InvoiceMapper.cs +++ b/DoliMiddlewareApi/Mappers/InvoiceMapper.cs @@ -1,6 +1,7 @@ using System.Globalization; using DoliMiddlewareApi.Dtos; using DoliMiddlewareApi.Dtos.Dolibarr; +using DoliMiddlewareApi.Dtos.query; using DoliMiddlewareApi.Exceptions; namespace DoliMiddlewareApi.Mappers; @@ -85,6 +86,8 @@ public static class InvoiceMapper : 0 }; } + + private static string ConvertStatusToWord(string? statusNumber) { @@ -107,4 +110,19 @@ public static class InvoiceMapper _ => throw new BadRequestException($"Estado inválido: {status}. Valores válidos: draft, unpaid, paid") }; } + + + public static InvoicePaymentDto MapToInvoicePaymentDto(InvoicePaymentResponse response) + { + return new InvoicePaymentDto + { + Ref = response.@ref ?? "", + PaymentDate = DateTime.TryParseExact(response.date, "yyyy-MM-dd HH:mm:ss", + CultureInfo.InvariantCulture, DateTimeStyles.None, out var date) ? date : DateTime.MinValue, + Type = response.type ?? "", + TransactionNum = response.num ?? "", + Amount = decimal.TryParse(response.amount, NumberStyles.Any, CultureInfo.InvariantCulture, + out decimal amount) ? (int)Math.Round(amount, 0) : 0 + }; + } } \ No newline at end of file diff --git a/DoliMiddlewareApi/Services/InvoiceService.cs b/DoliMiddlewareApi/Services/InvoiceService.cs index d0e18b0..f74b738 100644 --- a/DoliMiddlewareApi/Services/InvoiceService.cs +++ b/DoliMiddlewareApi/Services/InvoiceService.cs @@ -3,6 +3,7 @@ using System.Globalization; using DoliMiddlewareApi.Dtos; using DoliMiddlewareApi.Dtos.command; using DoliMiddlewareApi.Dtos.Dolibarr; +using DoliMiddlewareApi.Dtos.query; using DoliMiddlewareApi.Exceptions; using DoliMiddlewareApi.Mappers; using DoliMiddlewareApi.Services.Clients; @@ -162,4 +163,12 @@ public class InvoiceService(IDolibarrApiClient apiClient) return clients.Where(c => c is { id: not null }) .ToDictionary(c => int.Parse(c!.id!), c => c!.name ?? ""); } + + public async Task> GetInvoicePaymentsAsync(int invoiceId) + { + var dataList = await apiClient.GetCollectionAsync($"invoices/{invoiceId}/payments"); + var payments = dataList.Select(InvoiceMapper.MapToInvoicePaymentDto).ToList(); + + return payments; + } }