| | | 1 | | using FAU.API.Security; |
| | | 2 | | using FAU.Logica.DTOs; |
| | | 3 | | using FAU.Logica.Services; |
| | | 4 | | using Microsoft.AspNetCore.Authorization; |
| | | 5 | | using Microsoft.AspNetCore.Mvc; |
| | | 6 | | |
| | | 7 | | namespace FAU.API.Controllers; |
| | | 8 | | |
| | | 9 | | [ApiController] |
| | | 10 | | [Route("api/liquidacion/[controller]")] |
| | | 11 | | [Authorize(Roles = "Administrador")] |
| | | 12 | | public class LiquidacionesController : ControllerBase |
| | | 13 | | { |
| | | 14 | | private readonly ILiquidacionService _liquidacionService; |
| | | 15 | | private readonly ILogger<LiquidacionesController> _logger; |
| | | 16 | | |
| | 0 | 17 | | public LiquidacionesController(ILiquidacionService liquidacionService, ILogger<LiquidacionesController> logger) |
| | | 18 | | { |
| | 0 | 19 | | _liquidacionService = liquidacionService; |
| | 0 | 20 | | _logger = logger; |
| | 0 | 21 | | } |
| | | 22 | | |
| | | 23 | | [HttpPost("generar")] |
| | | 24 | | public async Task<IActionResult> GenerarLiquidacion([FromBody] GenerarLiquidacionRequest request) |
| | | 25 | | { |
| | | 26 | | try |
| | | 27 | | { |
| | 0 | 28 | | if (!ModelState.IsValid) |
| | | 29 | | { |
| | 0 | 30 | | return BadRequest(ApiResponse<string>.ErrorResult("Solicitud de generación inválida")); |
| | | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | var (success, error) = await _liquidacionService.GenerarLiquidacionAsync(request.PeriodoId, request.Version) |
| | 0 | 34 | | if (!success) |
| | | 35 | | { |
| | 0 | 36 | | return BadRequest(ApiResponse<string>.ErrorResult(error ?? "Error al generar la liquidación")); |
| | | 37 | | } |
| | | 38 | | |
| | 0 | 39 | | return Ok(ApiResponse<object>.SuccessResult(new { request.PeriodoId, request.Version }, "Liquidación generad |
| | | 40 | | } |
| | 0 | 41 | | catch (Exception ex) |
| | | 42 | | { |
| | 0 | 43 | | _logger.LogError(ex, "Error al generar liquidación para periodo {PeriodoId} version {Version}", request.Peri |
| | 0 | 44 | | return StatusCode(500, ApiResponse<string>.ErrorResult("Error interno del servidor")); |
| | | 45 | | } |
| | 0 | 46 | | } |
| | | 47 | | |
| | | 48 | | [HttpGet("estados")] |
| | | 49 | | public async Task<IActionResult> ObtenerEstados([FromQuery] long periodoId, [FromQuery] int version) |
| | | 50 | | { |
| | | 51 | | try |
| | | 52 | | { |
| | 0 | 53 | | var estados = await _liquidacionService.ObtenerEstadosAsync(periodoId, version); |
| | 0 | 54 | | return Ok(ApiResponse<IEnumerable<CalculoEstadoDto>>.SuccessResult(estados, "Estados de liquidación obtenido |
| | | 55 | | } |
| | 0 | 56 | | catch (Exception ex) |
| | | 57 | | { |
| | 0 | 58 | | _logger.LogError(ex, "Error al obtener estados de liquidación para periodo {PeriodoId} version {Version}", p |
| | 0 | 59 | | return StatusCode(500, ApiResponse<string>.ErrorResult("Error interno del servidor")); |
| | | 60 | | } |
| | 0 | 61 | | } |
| | | 62 | | |
| | | 63 | | [HttpGet("items")] |
| | | 64 | | public async Task<IActionResult> ObtenerItems([FromQuery] long periodoId, [FromQuery] int version) |
| | | 65 | | { |
| | | 66 | | try |
| | | 67 | | { |
| | 0 | 68 | | var items = await _liquidacionService.ObtenerItemsAsync(periodoId, version); |
| | 0 | 69 | | return Ok(ApiResponse<IEnumerable<CalculoItemDto>>.SuccessResult(items, "Items de liquidación obtenidos")); |
| | | 70 | | } |
| | 0 | 71 | | catch (Exception ex) |
| | | 72 | | { |
| | 0 | 73 | | _logger.LogError(ex, "Error al obtener items de liquidación para periodo {PeriodoId} version {Version}", per |
| | 0 | 74 | | return StatusCode(500, ApiResponse<string>.ErrorResult("Error interno del servidor")); |
| | | 75 | | } |
| | 0 | 76 | | } |
| | | 77 | | |
| | | 78 | | [HttpGet("resumenes")] |
| | | 79 | | public async Task<IActionResult> ObtenerResumenes([FromQuery] long periodoId, [FromQuery] int version) |
| | | 80 | | { |
| | | 81 | | try |
| | | 82 | | { |
| | 0 | 83 | | var resumenes = await _liquidacionService.ObtenerResumenAsync(periodoId, version); |
| | 0 | 84 | | return Ok(ApiResponse<IEnumerable<LiquidacionResumenDto>>.SuccessResult(resumenes, "Resumen de liquidación o |
| | | 85 | | } |
| | 0 | 86 | | catch (Exception ex) |
| | | 87 | | { |
| | 0 | 88 | | _logger.LogError(ex, "Error al obtener resumen de liquidación para periodo {PeriodoId} version {Version}", p |
| | 0 | 89 | | return StatusCode(500, ApiResponse<string>.ErrorResult("Error interno del servidor")); |
| | | 90 | | } |
| | 0 | 91 | | } |
| | | 92 | | |
| | | 93 | | public class GenerarLiquidacionRequest |
| | | 94 | | { |
| | 0 | 95 | | public long PeriodoId { get; set; } |
| | 0 | 96 | | public int Version { get; set; } |
| | | 97 | | } |
| | | 98 | | } |