Backend API:
- Recargos por Zona (`dist_RecargoZona`):
  - CRUD completo (Modelos, DTOs, Repositorio, Servicio, Controlador).
  - Endpoints anidados bajo `/publicaciones/{idPublicacion}/recargos`.
  - Lógica de negocio para vigencias (cierre/reapertura de períodos).
  - Auditoría en `dist_RecargoZona_H`.
- Porcentajes de Pago Distribuidores (`dist_PorcPago`):
  - CRUD completo (Modelos, DTOs, Repositorio, Servicio, Controlador).
  - Endpoints anidados bajo `/publicaciones/{idPublicacion}/porcentajespago`.
  - Lógica de negocio para vigencias.
  - Auditoría en `dist_PorcPago_H`.
- Porcentajes/Montos Pago Canillitas (`dist_PorcMonPagoCanilla`):
  - CRUD completo (Modelos, DTOs, Repositorio, Servicio, Controlador).
  - Endpoints anidados bajo `/publicaciones/{idPublicacion}/porcentajesmoncanilla`.
  - Lógica de negocio para vigencias.
  - Auditoría en `dist_PorcMonPagoCanilla_H`.
- Secciones de Publicación (`dist_dtPubliSecciones`):
  - CRUD completo (Modelos, DTOs, Repositorio, Servicio, Controlador).
  - Endpoints anidados bajo `/publicaciones/{idPublicacion}/secciones`.
  - Auditoría en `dist_dtPubliSecciones_H`.
- Entradas/Salidas Distribuidores (`dist_EntradasSalidas`):
  - Implementado backend (Modelos, DTOs, Repositorio, Servicio, Controlador).
  - Lógica para determinar precios/recargos/porcentajes aplicables.
  - Cálculo de monto y afectación de saldos de distribuidores en `cue_Saldos`.
  - Auditoría en `dist_EntradasSalidas_H`.
- Correcciones de Mapeo Dapper:
  - Aplicados alias explícitos en repositorios de RecargoZona, PorcPago, PorcMonCanilla, PubliSeccion,
    Canilla, Distribuidor y Precio para asegurar mapeo correcto de IDs y columnas.
Frontend React:
- Recargos por Zona:
  - `recargoZonaService.ts`.
  - `RecargoZonaFormModal.tsx` para crear/editar períodos de recargos.
  - `GestionarRecargosPublicacionPage.tsx` para listar y gestionar recargos por publicación.
- Porcentajes de Pago Distribuidores:
  - `porcPagoService.ts`.
  - `PorcPagoFormModal.tsx`.
  - `GestionarPorcentajesPagoPage.tsx`.
- Porcentajes/Montos Pago Canillitas:
  - `porcMonCanillaService.ts`.
  - `PorcMonCanillaFormModal.tsx`.
  - `GestionarPorcMonCanillaPage.tsx`.
- Secciones de Publicación:
  - `publiSeccionService.ts`.
  - `PubliSeccionFormModal.tsx`.
  - `GestionarSeccionesPublicacionPage.tsx`.
- Navegación:
  - Actualizadas rutas y menús para acceder a la gestión de recargos, porcentajes (dist. y canillita) y secciones desde la vista de una publicación.
- Layout:
  - Uso consistente de `Box` con Flexbox en lugar de `Grid` en nuevos modales y páginas para evitar errores de tipo.
		
	
		
			
				
	
	
		
			118 lines
		
	
	
		
			6.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			118 lines
		
	
	
		
			6.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using GestionIntegral.Api.Dtos.Distribucion;
 | |
| using GestionIntegral.Api.Services.Distribucion;
 | |
| using Microsoft.AspNetCore.Authorization;
 | |
| using Microsoft.AspNetCore.Mvc;
 | |
| using Microsoft.Extensions.Logging;
 | |
| using System.Collections.Generic;
 | |
| using System.Security.Claims;
 | |
| using System.Threading.Tasks;
 | |
| 
 | |
| namespace GestionIntegral.Api.Controllers.Distribucion
 | |
| {
 | |
|     [Route("api/publicaciones/{idPublicacion}/porcentajespago")] // Anidado
 | |
|     [ApiController]
 | |
|     [Authorize]
 | |
|     public class PorcentajesPagoController : ControllerBase // Para Porcentajes de Pago Distribuidores
 | |
|     {
 | |
|         private readonly IPorcPagoService _porcPagoService;
 | |
|         private readonly ILogger<PorcentajesPagoController> _logger;
 | |
| 
 | |
|         // Permiso DG004 para gestionar porcentajes de pago de distribuidores
 | |
|         private const string PermisoGestionarPorcentajes = "DG004";
 | |
| 
 | |
|         public PorcentajesPagoController(IPorcPagoService porcPagoService, ILogger<PorcentajesPagoController> logger)
 | |
|         {
 | |
|             _porcPagoService = porcPagoService;
 | |
|             _logger = logger;
 | |
|         }
 | |
| 
 | |
|         private bool TienePermiso(string codAcc) => User.IsInRole("SuperAdmin") || User.HasClaim(c => c.Type == "permission" && c.Value == codAcc);
 | |
|         private int? GetCurrentUserId()
 | |
|         {
 | |
|             if (int.TryParse(User.FindFirstValue(ClaimTypes.NameIdentifier) ?? User.FindFirstValue("sub"), out int userId)) return userId;
 | |
|             return null;
 | |
|         }
 | |
| 
 | |
|         [HttpGet]
 | |
|         [ProducesResponseType(typeof(IEnumerable<PorcPagoDto>), StatusCodes.Status200OK)]
 | |
|         [ProducesResponseType(StatusCodes.Status403Forbidden)]
 | |
|         public async Task<IActionResult> GetPorcentajesPorPublicacion(int idPublicacion)
 | |
|         {
 | |
|             if (!TienePermiso("DP001") && !TienePermiso(PermisoGestionarPorcentajes)) return Forbid(); // DP001 para ver Publicación
 | |
|             var porcentajes = await _porcPagoService.ObtenerPorPublicacionIdAsync(idPublicacion);
 | |
|             return Ok(porcentajes);
 | |
|         }
 | |
| 
 | |
|         [HttpGet("{idPorcentaje:int}", Name = "GetPorcPagoById")]
 | |
|         [ProducesResponseType(typeof(PorcPagoDto), StatusCodes.Status200OK)]
 | |
|         [ProducesResponseType(StatusCodes.Status403Forbidden)]
 | |
|         [ProducesResponseType(StatusCodes.Status404NotFound)]
 | |
|         public async Task<IActionResult> GetPorcPagoById(int idPublicacion, int idPorcentaje)
 | |
|         {
 | |
|             if (!TienePermiso("DP001") && !TienePermiso(PermisoGestionarPorcentajes)) return Forbid();
 | |
|             var porcPago = await _porcPagoService.ObtenerPorIdAsync(idPorcentaje);
 | |
|             if (porcPago == null || porcPago.IdPublicacion != idPublicacion) return NotFound();
 | |
|             return Ok(porcPago);
 | |
|         }
 | |
| 
 | |
|         [HttpPost]
 | |
|         [ProducesResponseType(typeof(PorcPagoDto), StatusCodes.Status201Created)]
 | |
|         [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | |
|         [ProducesResponseType(StatusCodes.Status403Forbidden)]
 | |
|         public async Task<IActionResult> CreatePorcPago(int idPublicacion, [FromBody] CreatePorcPagoDto createDto)
 | |
|         {
 | |
|             if (!TienePermiso(PermisoGestionarPorcentajes)) return Forbid();
 | |
|             if (idPublicacion != createDto.IdPublicacion)
 | |
|                 return BadRequest(new { message = "ID de publicación en ruta no coincide con el del cuerpo." });
 | |
|             if (!ModelState.IsValid) return BadRequest(ModelState);
 | |
|             var userId = GetCurrentUserId();
 | |
|             if (userId == null) return Unauthorized();
 | |
| 
 | |
|             var (dto, error) = await _porcPagoService.CrearAsync(createDto, userId.Value);
 | |
|             if (error != null) return BadRequest(new { message = error });
 | |
|             if (dto == null) return StatusCode(StatusCodes.Status500InternalServerError, "Error al crear porcentaje.");
 | |
|             return CreatedAtRoute("GetPorcPagoById", new { idPublicacion = dto.IdPublicacion, idPorcentaje = dto.IdPorcentaje }, dto);
 | |
|         }
 | |
| 
 | |
|         [HttpPut("{idPorcentaje:int}")]
 | |
|         [ProducesResponseType(StatusCodes.Status204NoContent)]
 | |
|         [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | |
|         [ProducesResponseType(StatusCodes.Status403Forbidden)]
 | |
|         [ProducesResponseType(StatusCodes.Status404NotFound)]
 | |
|         public async Task<IActionResult> UpdatePorcPago(int idPublicacion, int idPorcentaje, [FromBody] UpdatePorcPagoDto updateDto)
 | |
|         {
 | |
|             if (!TienePermiso(PermisoGestionarPorcentajes)) return Forbid();
 | |
|             if (!ModelState.IsValid) return BadRequest(ModelState);
 | |
|             var userId = GetCurrentUserId();
 | |
|             if (userId == null) return Unauthorized();
 | |
| 
 | |
|             var existente = await _porcPagoService.ObtenerPorIdAsync(idPorcentaje);
 | |
|             if (existente == null || existente.IdPublicacion != idPublicacion)
 | |
|                 return NotFound(new { message = "Porcentaje no encontrado para esta publicación."});
 | |
| 
 | |
|             var (exito, error) = await _porcPagoService.ActualizarAsync(idPorcentaje, updateDto, userId.Value);
 | |
|             if (!exito) return BadRequest(new { message = error });
 | |
|             return NoContent();
 | |
|         }
 | |
| 
 | |
|         [HttpDelete("{idPorcentaje:int}")]
 | |
|         [ProducesResponseType(StatusCodes.Status204NoContent)]
 | |
|         [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | |
|         [ProducesResponseType(StatusCodes.Status403Forbidden)]
 | |
|         [ProducesResponseType(StatusCodes.Status404NotFound)]
 | |
|         public async Task<IActionResult> DeletePorcPago(int idPublicacion, int idPorcentaje)
 | |
|         {
 | |
|             if (!TienePermiso(PermisoGestionarPorcentajes)) return Forbid();
 | |
|             var userId = GetCurrentUserId();
 | |
|             if (userId == null) return Unauthorized();
 | |
| 
 | |
|             var existente = await _porcPagoService.ObtenerPorIdAsync(idPorcentaje);
 | |
|              if (existente == null || existente.IdPublicacion != idPublicacion)
 | |
|                 return NotFound(new { message = "Porcentaje no encontrado para esta publicación."});
 | |
| 
 | |
|             var (exito, error) = await _porcPagoService.EliminarAsync(idPorcentaje, userId.Value);
 | |
|             if (!exito) return BadRequest(new { message = error });
 | |
|             return NoContent();
 | |
|         }
 | |
|     }
 | |
| } |