Se integro la plantilla de aviso de consolidado
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
|
||||
const BASE_URL = import.meta.env.VITE_API_URL || '';
|
||||
|
||||
export const avisoConsolidadoReportsApi = {
|
||||
|
||||
triggerPdfGeneration: async (invoiceId: number, companyId: number) => {
|
||||
const params = new URLSearchParams({ company_id: companyId.toString() });
|
||||
const endpoint = `${BASE_URL}/v1/a76/reports/exportacion/aviso_consolidado/${invoiceId}/download-async?${params.toString()}`;
|
||||
|
||||
const token = localStorage.getItem('access_token');
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al iniciar la generación del Aviso Consolidado');
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
getTaskStatus: async (taskId: string) => {
|
||||
const endpoint = `${BASE_URL}/v1/a76/reports/exportacion/aviso_consolidado/tasks/${taskId}`;
|
||||
|
||||
const token = localStorage.getItem('access_token');
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'GET',
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al consultar estado del Aviso Consolidado');
|
||||
return await response.json();
|
||||
}
|
||||
};
|
||||
@@ -372,6 +372,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
import { avisoConsolidadoReportsApi } from '$lib/api/dashboard/a76/reports/reports-aviso-consolidado';
|
||||
|
||||
async function handleDownloadConsolidated(invoice: any) {
|
||||
if (!companyStore.activeCompany) {
|
||||
toast.error("No hay empresa seleccionada");
|
||||
@@ -379,7 +381,7 @@
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. Trigger: Iniciar la tarea en Celery (Consolidado)
|
||||
// 1. Trigger: Iniciar la tarea en Celery (Consolidado Importación)
|
||||
const { task_id } = await consolidatedReportsApi.triggerPdfGeneration(
|
||||
invoice.id,
|
||||
companyStore.activeCompany.id
|
||||
@@ -394,7 +396,30 @@
|
||||
console.error(error);
|
||||
toast.error("No se pudo iniciar la descarga del consolidado");
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDownloadAvisoConsolidado(invoice: any) {
|
||||
if (!companyStore.activeCompany) {
|
||||
toast.error("No hay empresa seleccionada");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. Trigger: Iniciar la tarea en Celery (Aviso Consolidado Exportación)
|
||||
const { task_id } = await avisoConsolidadoReportsApi.triggerPdfGeneration(
|
||||
invoice.id,
|
||||
companyStore.activeCompany.id
|
||||
);
|
||||
|
||||
// 2. Abrir diálogo de progreso
|
||||
currentTaskId = task_id;
|
||||
currentStatusFunction = avisoConsolidadoReportsApi.getTaskStatus;
|
||||
showProgressDialog = true;
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("No se pudo iniciar la descarga del Aviso Consolidado");
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDownloadPackingList(invoice: any) {
|
||||
@@ -655,10 +680,17 @@
|
||||
<FileText class="h-4 w-4 mr-2" />
|
||||
Factura
|
||||
</Button>
|
||||
|
||||
<Button variant="outline" size="sm" onclick={() => selectedInvoice && handleDownloadConsolidated(selectedInvoice)} disabled={!selectedInvoice}>
|
||||
<Boxes class="h-4 w-4 mr-2" />
|
||||
Consolidado
|
||||
</Button>
|
||||
|
||||
<Button variant="outline" size="sm" onclick={() => selectedInvoice && handleDownloadAvisoConsolidado(selectedInvoice)} disabled={!selectedInvoice}>
|
||||
<Boxes class="h-4 w-4 mr-2" />
|
||||
Aviso Consolidado
|
||||
</Button>
|
||||
|
||||
<Button variant="outline" size="sm" onclick={() => selectedInvoice && handleDownloadPackingList(selectedInvoice)} disabled={!selectedInvoice}>
|
||||
<Package class="h-4 w-4 mr-2" />
|
||||
Packing List
|
||||
|
||||
Reference in New Issue
Block a user