Feat: Implementa Reporte de Distribución de Suscripciones y Refactoriza Gestión de Ajustes

Se introduce una nueva funcionalidad de reporte crucial para la logística y se realiza una refactorización mayor del sistema de ajustes para garantizar la correcta imputación contable.

###  Nuevas Características

- **Nuevo Reporte de Distribución de Suscripciones (RR011):**
    - Se añade un nuevo reporte en PDF que genera un listado de todas las suscripciones activas en un rango de fechas.
    - El reporte está diseñado para el equipo de reparto, incluyendo datos clave como nombre del suscriptor, dirección, teléfono, días de entrega y observaciones.
    - Se implementa el endpoint, la lógica de servicio, la consulta a la base de datos y el template de QuestPDF en el backend.
    - Se crea la página correspondiente en el frontend (React) con su selector de fechas y se añade la ruta y el enlace en el menú de reportes.

### 🔄 Refactorización Mayor

- **Asociación de Ajustes a Empresas:**
    - Se refactoriza por completo la entidad `Ajuste` para incluir una referencia obligatoria a una `IdEmpresa`.
    - **Motivo:** Corregir un error crítico en la lógica de negocio donde los ajustes de un suscriptor se aplicaban a la primera factura generada, sin importar a qué empresa correspondía el ajuste.
    - Se provee un script de migración SQL para actualizar el esquema de la base de datos (`susc_Ajustes`).
    - Se actualizan todos los DTOs, repositorios y servicios (backend) para manejar la nueva relación.
    - Se modifica el `FacturacionService` para que ahora aplique los ajustes pendientes correspondientes a cada empresa dentro de su bucle de facturación.
    - Se actualiza el formulario de creación/edición de ajustes en el frontend (React) para incluir un selector de empresa obligatorio.

### ️ Optimizaciones de Rendimiento

- **Solución de N+1 Queries:**
    - Se optimiza el método `ObtenerTodos` en `SuscriptorService` para obtener todas las formas de pago en una única consulta en lugar de una por cada suscriptor.
    - Se optimiza el método `ObtenerAjustesPorSuscriptor` en `AjusteService` para obtener todos los nombres de usuarios y empresas en dos consultas masivas, en lugar de N consultas individuales.
    - Se añade el método `GetByIdsAsync` al `IUsuarioRepository` y su implementación para soportar esta optimización.

### 🐛 Corrección de Errores

- Se corrigen múltiples errores en el script de migración de base de datos (uso de `GO` dentro de transacciones, error de "columna inválida").
- Se soluciona un error de SQL (`INSERT` statement) en `AjusteRepository` que impedía la creación de nuevos ajustes.
- Se corrige un bug en el `AjusteService` que causaba que el nombre de la empresa apareciera como "N/A" en la UI debido a un mapeo incompleto en el método optimizado.
- Se corrige la lógica de generación de emails en `FacturacionService` para mostrar correctamente el nombre de la empresa en cada sección del resumen de cuenta.
This commit is contained in:
2025-08-09 17:39:21 -03:00
parent 899e0a173f
commit 21c5c1d7d9
35 changed files with 856 additions and 158 deletions

View File

@@ -1,10 +1,9 @@
// Archivo: Frontend/src/components/Modals/Suscripciones/AjusteFormModal.tsx
import React, { useState, useEffect } from 'react';
import { Modal, Box, Typography, TextField, Button, CircularProgress, Alert, FormControl, InputLabel, Select, MenuItem, type SelectChangeEvent, InputAdornment } from '@mui/material';
import type { CreateAjusteDto } from '../../../models/dtos/Suscripciones/CreateAjusteDto';
import type { UpdateAjusteDto } from '../../../models/dtos/Suscripciones/UpdateAjusteDto';
import type { AjusteDto } from '../../../models/dtos/Suscripciones/AjusteDto';
import type { EmpresaDropdownDto } from '../../../models/dtos/Distribucion/EmpresaDropdownDto';
const modalStyle = {
position: 'absolute' as 'absolute',
@@ -27,9 +26,10 @@ interface AjusteFormModalProps {
idSuscriptor: number;
errorMessage?: string | null;
clearErrorMessage: () => void;
empresas: EmpresaDropdownDto[];
}
const AjusteFormModal: React.FC<AjusteFormModalProps> = ({ open, onClose, onSubmit, idSuscriptor, errorMessage, clearErrorMessage, initialData }) => {
const AjusteFormModal: React.FC<AjusteFormModalProps> = ({ open, onClose, onSubmit, idSuscriptor, errorMessage, clearErrorMessage, initialData, empresas }) => {
const [formData, setFormData] = useState<AjusteFormData>({});
const [loading, setLoading] = useState(false);
const [localErrors, setLocalErrors] = useState<{ [key: string]: string | null }>({});
@@ -38,16 +38,16 @@ const AjusteFormModal: React.FC<AjusteFormModalProps> = ({ open, onClose, onSubm
useEffect(() => {
if (open) {
// Formatear fecha correctamente: el DTO de Ajuste tiene FechaAlta con hora, pero el input necesita "yyyy-MM-dd"
const fechaParaFormulario = initialData?.fechaAjuste
? initialData.fechaAjuste.split(' ')[0] // Tomar solo la parte de la fecha
? initialData.fechaAjuste.split(' ')[0]
: new Date().toISOString().split('T')[0];
setFormData({
idSuscriptor: initialData?.idSuscriptor || idSuscriptor,
idEmpresa: initialData?.idEmpresa || undefined, // undefined para que el placeholder se muestre
fechaAjuste: fechaParaFormulario,
tipoAjuste: initialData?.tipoAjuste || 'Credito',
monto: initialData?.monto || undefined, // undefined para que el placeholder se muestre
monto: initialData?.monto || undefined,
motivo: initialData?.motivo || ''
});
setLocalErrors({});
@@ -56,6 +56,7 @@ const AjusteFormModal: React.FC<AjusteFormModalProps> = ({ open, onClose, onSubm
const validate = (): boolean => {
const errors: { [key: string]: string | null } = {};
if (!formData.idEmpresa) errors.idEmpresa = "Debe seleccionar una empresa.";
if (!formData.fechaAjuste) errors.fechaAjuste = "La fecha es obligatoria.";
if (!formData.tipoAjuste) errors.tipoAjuste = "Seleccione un tipo.";
if (!formData.monto || formData.monto <= 0) errors.monto = "El monto debe ser mayor a cero.";
@@ -64,7 +65,6 @@ const AjusteFormModal: React.FC<AjusteFormModalProps> = ({ open, onClose, onSubm
return Object.keys(errors).length === 0;
};
// --- HANDLERS CON TIPADO EXPLÍCITO ---
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
setFormData((prev: AjusteFormData) => ({
@@ -75,7 +75,7 @@ const AjusteFormModal: React.FC<AjusteFormModalProps> = ({ open, onClose, onSubm
if (errorMessage) clearErrorMessage();
};
const handleSelectChange = (e: SelectChangeEvent<string>) => { // Tipado como string
const handleSelectChange = (e: SelectChangeEvent<string | number>) => { // Acepta string o number
const { name, value } = e.target;
setFormData((prev: AjusteFormData) => ({ ...prev, [name]: value }));
if (localErrors[name]) setLocalErrors(prev => ({ ...prev, [name]: null }));
@@ -108,7 +108,25 @@ const AjusteFormModal: React.FC<AjusteFormModalProps> = ({ open, onClose, onSubm
<Box sx={modalStyle}>
<Typography variant="h6">{isEditing ? 'Editar Ajuste Manual' : 'Registrar Ajuste Manual'}</Typography>
<Box component="form" onSubmit={handleSubmit} sx={{ mt: 2 }}>
<TextField name="fechaAjuste" label="Fecha del Ajuste" type="date" value={formData.fechaAjuste || ''} onChange={handleInputChange} required fullWidth margin="dense" InputLabelProps={{ shrink: true }} error={!!localErrors.fechaAjuste} helperText={localErrors.fechaAjuste} />
<FormControl fullWidth margin="dense" required error={!!localErrors.idEmpresa}>
<InputLabel id="empresa-label">Empresa</InputLabel>
<Select
name="idEmpresa"
labelId="empresa-label"
value={formData.idEmpresa || ''}
onChange={handleSelectChange}
label="Empresa"
>
{empresas.map((empresa) => (
<MenuItem key={empresa.idEmpresa} value={empresa.idEmpresa}>
{empresa.nombre}
</MenuItem>
))}
</Select>
{localErrors.idEmpresa && <Typography color="error" variant="caption">{localErrors.idEmpresa}</Typography>}
</FormControl>
<FormControl fullWidth margin="dense" error={!!localErrors.tipoAjuste}>
<InputLabel id="tipo-ajuste-label" required>Tipo de Ajuste</InputLabel>
<Select name="tipoAjuste" labelId="tipo-ajuste-label" value={formData.tipoAjuste || ''} onChange={handleSelectChange} label="Tipo de Ajuste">
@@ -116,12 +134,16 @@ const AjusteFormModal: React.FC<AjusteFormModalProps> = ({ open, onClose, onSubm
<MenuItem value="Debito">Débito (Cargo extra al cliente)</MenuItem>
</Select>
</FormControl>
<TextField name="monto" label="Monto" type="number" value={formData.monto || ''} onChange={handleInputChange} required fullWidth margin="dense" error={!!localErrors.monto} helperText={localErrors.monto} InputProps={{ startAdornment: <InputAdornment position="start">$</InputAdornment> }} inputProps={{ step: "0.01" }} />
<TextField name="motivo" label="Motivo" value={formData.motivo || ''} onChange={handleInputChange} required fullWidth margin="dense" multiline rows={3} error={!!localErrors.motivo} helperText={localErrors.motivo} />
<Alert severity="info" sx={{ mt: 2 }}>
Nota: Este ajuste se aplicará en la facturación del período correspondiente a la "Fecha del Ajuste".
Nota: Este ajuste se aplicará a la factura de la <strong>empresa seleccionada</strong> en el período correspondiente a la "Fecha del Ajuste".
</Alert>
{errorMessage && <Alert severity="error" sx={{ mt: 2 }}>{errorMessage}</Alert>}
<Box sx={{ mt: 3, display: 'flex', justifyContent: 'flex-end', gap: 1 }}>
<Button onClick={onClose} color="secondary" disabled={loading}>Cancelar</Button>
<Button type="submit" variant="contained" disabled={loading}>

View File

@@ -79,24 +79,41 @@ const SuscriptorFormModal: React.FC<SuscriptorFormModalProps> = ({ open, onClose
if (!formData.nroDocumento?.trim()) errors.nroDocumento = 'El número de documento es obligatorio.';
if (!formData.idFormaPagoPreferida) errors.idFormaPagoPreferida = 'La forma de pago es obligatoria.';
if (CBURequerido) {
if (!formData.cbu || formData.cbu.trim().length !== 22) {
errors.cbu = 'El CBU es obligatorio y debe tener 22 dígitos.';
}
} else if (formData.cbu && formData.cbu.trim().length > 0 && formData.cbu.trim().length !== 22) {
errors.cbu = 'El CBU debe tener 22 dígitos o estar vacío.';
// Validar formato de Nro de Documento (solo números)
if (formData.nroDocumento && !/^[0-9]+$/.test(formData.nroDocumento)) {
errors.nroDocumento = 'El documento solo debe contener números.';
}
// Validar formato de Email
if (formData.email && !/^\S+@\S+\.\S+$/.test(formData.email)) {
errors.email = 'El formato del email no es válido.';
}
// Validar formato y longitud de CBU
if (CBURequerido) {
if (!formData.cbu || !/^[0-9]+$/.test(formData.cbu) || formData.cbu.length !== 22) {
errors.cbu = 'El CBU es obligatorio y debe tener 22 dígitos numéricos.';
}
} else if (formData.cbu && formData.cbu.trim().length > 0 && (!/^[0-9]+$/.test(formData.cbu) || formData.cbu.length !== 26)) {
errors.cbu = 'El CBU debe tener 22 dígitos numéricos o estar vacío.';
}
setLocalErrors(errors);
return Object.keys(errors).length === 0;
};
// --- HANDLER DE INPUT MEJORADO ---
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
setFormData(prev => ({ ...prev, [name]: value }));
// Prevenir entrada de caracteres no numéricos para CBU y NroDocumento
if (name === 'cbu' || name === 'nroDocumento') {
const numericValue = value.replace(/[^0-9]/g, '');
setFormData(prev => ({ ...prev, [name]: numericValue }));
} else {
setFormData(prev => ({ ...prev, [name]: value }));
}
if (localErrors[name]) setLocalErrors(prev => ({ ...prev, [name]: null }));
if (errorMessage) clearErrorMessage();
};
@@ -164,7 +181,7 @@ const SuscriptorFormModal: React.FC<SuscriptorFormModalProps> = ({ open, onClose
<MenuItem value="CUIL">CUIL</MenuItem>
</Select>
</FormControl>
<TextField name="nroDocumento" label="Nro Documento" value={formData.nroDocumento || ''} onChange={handleInputChange} required fullWidth margin="dense" sx={{ flex: 2 }} error={!!localErrors.nroDocumento} helperText={localErrors.nroDocumento} disabled={loading} />
<TextField name="nroDocumento" label="Nro Documento" value={formData.nroDocumento || ''} onChange={handleInputChange} required fullWidth margin="dense" sx={{ flex: 2 }} error={!!localErrors.nroDocumento} helperText={localErrors.nroDocumento} disabled={loading} inputProps={{ maxLength: 11 }} />
</Box>
<FormControl fullWidth margin="dense" error={!!localErrors.idFormaPagoPreferida}>
<InputLabel id="forma-pago-label" required>Forma de Pago</InputLabel>

View File

@@ -2,6 +2,8 @@ export interface AjusteDto {
idAjuste: number;
fechaAjuste: string;
idSuscriptor: number;
idEmpresa: number;
nombreEmpresa?: string;
tipoAjuste: 'Credito' | 'Debito';
monto: number;
motivo: string;

View File

@@ -1,4 +1,5 @@
export interface CreateAjusteDto {
idEmpresa: number;
fechaAjuste: string;
idSuscriptor: number;
tipoAjuste: 'Credito' | 'Debito';

View File

@@ -1,4 +1,5 @@
export interface UpdateAjusteDto {
idEmpresa: number;
fechaAjuste: string; // "yyyy-MM-dd"
tipoAjuste: 'Credito' | 'Debito';
monto: number;

View File

@@ -0,0 +1,68 @@
import React, { useState } from 'react';
import { Box, Alert, Paper } from '@mui/material';
import reporteService from '../../services/Reportes/reportesService';
import { usePermissions } from '../../hooks/usePermissions';
import axios from 'axios';
import SeleccionaReporteDistribucionSuscripciones from './SeleccionaReporteDistribucionSuscripciones';
const ReporteDistribucionSuscripcionesPage: React.FC = () => {
const [loading, setLoading] = useState(false);
const [apiError, setApiError] = useState<string | null>(null);
const { tienePermiso, isSuperAdmin } = usePermissions();
const puedeVerReporte = isSuperAdmin || tienePermiso("RR011");
const handleGenerateReport = async (params: { fechaDesde: string; fechaHasta: string; }) => {
setLoading(true);
setApiError(null);
try {
const { fileContent, fileName } = await reporteService.getReporteDistribucionSuscripcionesPdf(params.fechaDesde, params.fechaHasta);
const url = window.URL.createObjectURL(new Blob([fileContent], { type: 'application/pdf' }));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', fileName);
document.body.appendChild(link);
link.click();
link.parentNode?.removeChild(link);
window.URL.revokeObjectURL(url);
} catch (err: any) {
let message = 'Ocurrió un error al generar el reporte.';
if (axios.isAxiosError(err) && err.response) {
if (err.response.status === 404) {
message = "No se encontraron datos para los parámetros seleccionados.";
} else if (err.response.data instanceof Blob && err.response.data.type === "application/json") {
const errorText = await err.response.data.text();
try {
const errorJson = JSON.parse(errorText);
message = errorJson.message || message;
} catch {
message = errorText || message;
}
}
}
setApiError(message);
} finally {
setLoading(false);
}
};
if (!puedeVerReporte) {
return <Alert severity="error">No tiene permiso para ver este reporte.</Alert>;
}
return (
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'flex-start', pt: 4 }}>
<Paper elevation={3} sx={{ borderRadius: '8px' }}>
<SeleccionaReporteDistribucionSuscripciones
onGenerarReporte={handleGenerateReport}
isLoading={loading}
apiErrorMessage={apiError}
/>
</Paper>
</Box>
);
};
export default ReporteDistribucionSuscripcionesPage;

View File

@@ -24,6 +24,7 @@ const allReportModules: { category: string; label: string; path: string }[] = [
{ category: 'Novedades de Canillitas', label: 'Novedades de Canillitas', path: 'novedades-canillas' },
{ category: 'Listados Distribución', label: 'Dist. Mensual Can/Acc', path: 'listado-distribucion-mensual' },
{ category: 'Suscripciones', label: 'Facturas para Publicidad', path: 'suscripciones-facturas-publicidad' },
{ category: 'Suscripciones', label: 'Distribución de Suscripciones', path: 'suscripciones-distribucion' },
];
const predefinedCategoryOrder = [

View File

@@ -0,0 +1,63 @@
import React, { useState } from 'react';
import { Box, Typography, Button, CircularProgress, Alert, TextField } from '@mui/material';
interface SeleccionaReporteProps {
onGenerarReporte: (params: { fechaDesde: string, fechaHasta: string }) => Promise<void>;
isLoading?: boolean;
apiErrorMessage?: string | null;
}
const SeleccionaReporteDistribucionSuscripciones: React.FC<SeleccionaReporteProps> = ({
onGenerarReporte,
isLoading,
apiErrorMessage
}) => {
const [fechaDesde, setFechaDesde] = useState(new Date().toISOString().split('T')[0]);
const [fechaHasta, setFechaHasta] = useState(new Date().toISOString().split('T')[0]);
const handleGenerar = () => {
onGenerarReporte({ fechaDesde, fechaHasta });
};
return (
<Box sx={{ p: 2, border: '1px solid #ccc', borderRadius: '4px', minWidth: 400 }}>
<Typography variant="h6" gutterBottom>
Reporte de Distribución de Suscripciones
</Typography>
<Typography variant="body2" color="text.secondary" sx={{mb: 2}}>
Seleccione un rango de fechas para generar el listado de suscriptores activos y sus detalles de entrega.
</Typography>
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', mb: 2 }}>
<TextField
label="Fecha Desde"
type="date"
fullWidth
value={fechaDesde}
onChange={(e) => setFechaDesde(e.target.value)}
InputLabelProps={{ shrink: true }}
disabled={isLoading}
/>
<TextField
label="Fecha Hasta"
type="date"
fullWidth
value={fechaHasta}
onChange={(e) => setFechaHasta(e.target.value)}
InputLabelProps={{ shrink: true }}
disabled={isLoading}
/>
</Box>
{apiErrorMessage && <Alert severity="error" sx={{ mt: 2 }}>{apiErrorMessage}</Alert>}
<Box sx={{ mt: 3, display: 'flex', justifyContent: 'flex-end', gap: 1 }}>
<Button onClick={handleGenerar} variant="contained" disabled={isLoading}>
{isLoading ? <CircularProgress size={24} /> : 'Generar Reporte'}
</Button>
</Box>
</Box>
);
};
export default SeleccionaReporteDistribucionSuscripciones;

View File

@@ -7,6 +7,8 @@ import EditIcon from '@mui/icons-material/Edit';
import CancelIcon from '@mui/icons-material/Cancel';
import ajusteService from '../../services/Suscripciones/ajusteService';
import suscriptorService from '../../services/Suscripciones/suscriptorService';
import empresaService from '../../services/Distribucion/empresaService';
import type { EmpresaDropdownDto } from '../../models/dtos/Distribucion/EmpresaDropdownDto';
import { usePermissions } from '../../hooks/usePermissions';
import axios from 'axios';
import type { AjusteDto } from '../../models/dtos/Suscripciones/AjusteDto';
@@ -33,6 +35,7 @@ const CuentaCorrienteSuscriptorPage: React.FC = () => {
const [suscriptor, setSuscriptor] = useState<SuscriptorDto | null>(null);
const [ajustes, setAjustes] = useState<AjusteDto[]>([]);
const [empresas, setEmpresas] = useState<EmpresaDropdownDto[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [modalOpen, setModalOpen] = useState(false);
@@ -50,18 +53,23 @@ const CuentaCorrienteSuscriptorPage: React.FC = () => {
}
setLoading(true); setApiErrorMessage(null); setError(null);
try {
const suscriptorData = await suscriptorService.getSuscriptorById(idSuscriptor);
// Usamos Promise.all para cargar todo en paralelo y mejorar el rendimiento
const [suscriptorData, ajustesData, empresasData] = await Promise.all([
suscriptorService.getSuscriptorById(idSuscriptor),
ajusteService.getAjustesPorSuscriptor(idSuscriptor, filtroFechaDesde || undefined, filtroFechaHasta || undefined),
empresaService.getEmpresasDropdown()
]);
setSuscriptor(suscriptorData);
const ajustesData = await ajusteService.getAjustesPorSuscriptor(idSuscriptor, filtroFechaDesde || undefined, filtroFechaHasta || undefined);
setAjustes(ajustesData);
setEmpresas(empresasData);
} catch (err) {
setError("Error al cargar los datos.");
} finally {
setLoading(false);
}
}, [idSuscriptor, puedeGestionar, filtroFechaDesde, filtroFechaHasta]);
}, [idSuscriptor, filtroFechaDesde, filtroFechaHasta]);
useEffect(() => { cargarDatos(); }, [cargarDatos]);
@@ -151,7 +159,7 @@ const CuentaCorrienteSuscriptorPage: React.FC = () => {
type="date"
size="small"
value={filtroFechaDesde}
onChange={handleFechaDesdeChange} // <-- USAR NUEVO HANDLER
onChange={handleFechaDesdeChange}
InputLabelProps={{ shrink: true }}
/>
<TextField
@@ -159,7 +167,7 @@ const CuentaCorrienteSuscriptorPage: React.FC = () => {
type="date"
size="small"
value={filtroFechaHasta}
onChange={handleFechaHastaChange} // <-- USAR NUEVO HANDLER
onChange={handleFechaHastaChange}
InputLabelProps={{ shrink: true }}
/>
</Box>
@@ -178,6 +186,7 @@ const CuentaCorrienteSuscriptorPage: React.FC = () => {
<TableHead>
<TableRow>
<TableCell>Fecha Ajuste</TableCell>
<TableCell>Empresa</TableCell>
<TableCell>Tipo</TableCell>
<TableCell>Motivo</TableCell>
<TableCell align="right">Monto</TableCell>
@@ -188,13 +197,14 @@ const CuentaCorrienteSuscriptorPage: React.FC = () => {
</TableHead>
<TableBody>
{loading ? (
<TableRow><TableCell colSpan={7} align="center"><CircularProgress size={24} /></TableCell></TableRow>
<TableRow><TableCell colSpan={8} align="center"><CircularProgress size={24} /></TableCell></TableRow>
) : ajustes.length === 0 ? (
<TableRow><TableCell colSpan={7} align="center">No se encontraron ajustes para los filtros seleccionados.</TableCell></TableRow>
<TableRow><TableCell colSpan={8} align="center">No se encontraron ajustes para los filtros seleccionados.</TableCell></TableRow>
) : (
ajustes.map(a => (
<TableRow key={a.idAjuste} sx={{ '& .MuiTableCell-root': { color: a.estado === 'Anulado' ? 'text.disabled' : 'inherit' }, textDecoration: a.estado === 'Anulado' ? 'line-through' : 'none' }}>
<TableCell>{formatDisplayDate(a.fechaAjuste)}</TableCell>
<TableCell>{a.nombreEmpresa || 'N/A'}</TableCell>
<TableCell>
<Chip label={a.tipoAjuste} size="small" color={a.tipoAjuste === 'Credito' ? 'success' : 'error'} />
</TableCell>
@@ -233,6 +243,7 @@ const CuentaCorrienteSuscriptorPage: React.FC = () => {
initialData={editingAjuste}
errorMessage={apiErrorMessage}
clearErrorMessage={() => setApiErrorMessage(null)}
empresas={empresas}
/>
</Box>
);

View File

@@ -76,6 +76,7 @@ import GestionarNovedadesCanillaPage from '../pages/Distribucion/GestionarNoveda
import ReporteNovedadesCanillasPage from '../pages/Reportes/ReporteNovedadesCanillasPage';
import ReporteListadoDistMensualPage from '../pages/Reportes/ReporteListadoDistMensualPage';
import ReporteFacturasPublicidadPage from '../pages/Reportes/ReporteFacturasPublicidadPage';
import ReporteDistribucionSuscripcionesPage from '../pages/Reportes/ReporteDistribucionSuscripcionesPage';
// Suscripciones
import SuscripcionesIndexPage from '../pages/Suscripciones/SuscripcionesIndexPage';
@@ -289,6 +290,11 @@ const AppRoutes = () => {
<ReporteFacturasPublicidadPage />
</SectionProtectedRoute>
}/>
<Route path="suscripciones-distribucion" element={
<SectionProtectedRoute requiredPermission="RR011" sectionName="Reporte Distribución de Suscripciones">
<ReporteDistribucionSuscripcionesPage />
</SectionProtectedRoute>
}/>
</Route>
{/* Módulo de Radios (anidado) */}

View File

@@ -35,9 +35,9 @@ interface GetNovedadesCanillasParams {
}
interface GetListadoDistMensualParams {
fechaDesde: string; // yyyy-MM-dd
fechaHasta: string; // yyyy-MM-dd
esAccionista: boolean;
fechaDesde: string; // yyyy-MM-dd
fechaHasta: string; // yyyy-MM-dd
esAccionista: boolean;
}
const getExistenciaPapelPdf = async (params: GetExistenciaPapelParams): Promise<Blob> => {
@@ -420,40 +420,63 @@ const getCanillasGananciasReporte = async (params: GetNovedadesCanillasParams):
};
const getListadoDistMensualDiarios = async (params: GetListadoDistMensualParams): Promise<ListadoDistCanMensualDiariosDto[]> => {
const response = await apiClient.get<ListadoDistCanMensualDiariosDto[]>('/reportes/listado-distribucion-mensual/diarios', { params });
return response.data;
const response = await apiClient.get<ListadoDistCanMensualDiariosDto[]>('/reportes/listado-distribucion-mensual/diarios', { params });
return response.data;
};
const getListadoDistMensualDiariosPdf = async (params: GetListadoDistMensualParams): Promise<Blob> => {
const response = await apiClient.get('/reportes/listado-distribucion-mensual/diarios/pdf', {
params,
responseType: 'blob',
});
return response.data;
const response = await apiClient.get('/reportes/listado-distribucion-mensual/diarios/pdf', {
params,
responseType: 'blob',
});
return response.data;
};
const getListadoDistMensualPorPublicacion = async (params: GetListadoDistMensualParams): Promise<ListadoDistCanMensualPubDto[]> => {
const response = await apiClient.get<ListadoDistCanMensualPubDto[]>('/reportes/listado-distribucion-mensual/publicaciones', { params });
return response.data;
const response = await apiClient.get<ListadoDistCanMensualPubDto[]>('/reportes/listado-distribucion-mensual/publicaciones', { params });
return response.data;
};
const getListadoDistMensualPorPublicacionPdf = async (params: GetListadoDistMensualParams): Promise<Blob> => {
const response = await apiClient.get('/reportes/listado-distribucion-mensual/publicaciones/pdf', {
params,
responseType: 'blob',
});
return response.data;
const response = await apiClient.get('/reportes/listado-distribucion-mensual/publicaciones/pdf', {
params,
responseType: 'blob',
});
return response.data;
};
const getReporteFacturasPublicidadPdf = async (anio: number, mes: number): Promise<{ fileContent: Blob, fileName: string }> => {
const params = new URLSearchParams({ anio: String(anio), mes: String(mes) });
const url = `/reportes/suscripciones/facturas-para-publicidad/pdf?${params.toString()}`;
const params = new URLSearchParams({ anio: String(anio), mes: String(mes) });
const url = `/reportes/suscripciones/facturas-para-publicidad/pdf?${params.toString()}`;
const response = await apiClient.get(url, {
responseType: 'blob',
});
const contentDisposition = response.headers['content-disposition'];
let fileName = `ReportePublicidad_Suscripciones_${anio}-${String(mes).padStart(2, '0')}.pdf`; // Fallback
if (contentDisposition) {
const fileNameMatch = contentDisposition.match(/filename="(.+)"/);
if (fileNameMatch && fileNameMatch.length > 1) {
fileName = fileNameMatch[1];
}
}
return { fileContent: response.data, fileName: fileName };
};
const getReporteDistribucionSuscripcionesPdf = async (fechaDesde: string, fechaHasta: string): Promise<{ fileContent: Blob, fileName: string }> => {
const params = new URLSearchParams({
fechaDesde: fechaDesde,
fechaHasta: fechaHasta
});
const url = `/reportes/suscripciones/distribucion/pdf?${params.toString()}`;
const response = await apiClient.get(url, {
responseType: 'blob',
});
const contentDisposition = response.headers['content-disposition'];
let fileName = `ReportePublicidad_Suscripciones_${anio}-${String(mes).padStart(2, '0')}.pdf`; // Fallback
let fileName = `ReporteDistribucion_Suscripciones_${fechaDesde}_al_${fechaHasta}.pdf`; // Fallback
if (contentDisposition) {
const fileNameMatch = contentDisposition.match(/filename="(.+)"/);
if (fileNameMatch && fileNameMatch.length > 1) {
@@ -508,6 +531,7 @@ const reportesService = {
getListadoDistMensualPorPublicacion,
getListadoDistMensualPorPublicacionPdf,
getReporteFacturasPublicidadPdf,
getReporteDistribucionSuscripcionesPdf,
};
export default reportesService;