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