feat : Endpoint Get para los pagos de factura
This commit is contained in:
parent
eef2c9954c
commit
26ad842256
|
|
@ -1,6 +1,7 @@
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using DoliMiddlewareApi.Dtos;
|
using DoliMiddlewareApi.Dtos;
|
||||||
using DoliMiddlewareApi.Dtos.command;
|
using DoliMiddlewareApi.Dtos.command;
|
||||||
|
using DoliMiddlewareApi.Dtos.query;
|
||||||
using DoliMiddlewareApi.Services;
|
using DoliMiddlewareApi.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
@ -82,4 +83,11 @@ public class InvoicesController(InvoiceService invoiceService) : ControllerBase
|
||||||
await invoiceService.DeleteInvoiceLineAsync(invoiceId, lineId);
|
await invoiceService.DeleteInvoiceLineAsync(invoiceId, lineId);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:int}/payments")]
|
||||||
|
public async Task<ActionResult<List<InvoicePaymentDto>>> GetInvoicePayments([Range(1, int.MaxValue)] int id)
|
||||||
|
{
|
||||||
|
var payments = await invoiceService.GetInvoicePaymentsAsync(id);
|
||||||
|
return Ok(payments);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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; }
|
||||||
|
}
|
||||||
|
|
@ -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; }
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using DoliMiddlewareApi.Dtos;
|
using DoliMiddlewareApi.Dtos;
|
||||||
using DoliMiddlewareApi.Dtos.Dolibarr;
|
using DoliMiddlewareApi.Dtos.Dolibarr;
|
||||||
|
using DoliMiddlewareApi.Dtos.query;
|
||||||
using DoliMiddlewareApi.Exceptions;
|
using DoliMiddlewareApi.Exceptions;
|
||||||
|
|
||||||
namespace DoliMiddlewareApi.Mappers;
|
namespace DoliMiddlewareApi.Mappers;
|
||||||
|
|
@ -85,6 +86,8 @@ public static class InvoiceMapper
|
||||||
: 0
|
: 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static string ConvertStatusToWord(string? statusNumber)
|
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")
|
_ => 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
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ using System.Globalization;
|
||||||
using DoliMiddlewareApi.Dtos;
|
using DoliMiddlewareApi.Dtos;
|
||||||
using DoliMiddlewareApi.Dtos.command;
|
using DoliMiddlewareApi.Dtos.command;
|
||||||
using DoliMiddlewareApi.Dtos.Dolibarr;
|
using DoliMiddlewareApi.Dtos.Dolibarr;
|
||||||
|
using DoliMiddlewareApi.Dtos.query;
|
||||||
using DoliMiddlewareApi.Exceptions;
|
using DoliMiddlewareApi.Exceptions;
|
||||||
using DoliMiddlewareApi.Mappers;
|
using DoliMiddlewareApi.Mappers;
|
||||||
using DoliMiddlewareApi.Services.Clients;
|
using DoliMiddlewareApi.Services.Clients;
|
||||||
|
|
@ -162,4 +163,12 @@ public class InvoiceService(IDolibarrApiClient apiClient)
|
||||||
return clients.Where(c => c is { id: not null })
|
return clients.Where(c => c is { id: not null })
|
||||||
.ToDictionary(c => int.Parse(c!.id!), c => c!.name ?? "");
|
.ToDictionary(c => int.Parse(c!.id!), c => c!.name ?? "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<InvoicePaymentDto>> GetInvoicePaymentsAsync(int invoiceId)
|
||||||
|
{
|
||||||
|
var dataList = await apiClient.GetCollectionAsync<InvoicePaymentResponse>($"invoices/{invoiceId}/payments");
|
||||||
|
var payments = dataList.Select(InvoiceMapper.MapToInvoicePaymentDto).ToList();
|
||||||
|
|
||||||
|
return payments;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue