bak
This commit is contained in:
@@ -584,5 +584,12 @@ export const invoicesApi = {
|
||||
can_generate: boolean;
|
||||
reasons: Array<{ field: string; message: string }>;
|
||||
}>(`/v1/a76/factura-cove/invoices/${invoiceId}/cove/eligibility?${params.toString()}`);
|
||||
},
|
||||
|
||||
getCoveReceipt: (invoiceId: number, companyId: number): Promise<Blob> => {
|
||||
const params = new URLSearchParams({ company_id: companyId.toString() });
|
||||
return api.getBlob(
|
||||
`/v1/a76/factura-cove/invoices/${invoiceId}/cove/acuse?${params.toString()}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -883,6 +883,20 @@
|
||||
const taskInfo = result.external_task_id ? ` (task_id: ${result.external_task_id})` : '';
|
||||
toast.success(baseMsg + taskInfo);
|
||||
} else if (result.status === 'validation_error' || result.status === 'error') {
|
||||
// El diálogo de progreso ya muestra `result.errors` detallados; reforzamos con toast breve.
|
||||
const errs = Array.isArray(result.errors) ? result.errors : [];
|
||||
if (errs.length > 0) {
|
||||
const first = errs[0];
|
||||
const line =
|
||||
typeof first?.message === 'string'
|
||||
? first.message
|
||||
: String(first?.message ?? '');
|
||||
const more =
|
||||
errs.length > 1 ? ` (+${errs.length - 1} más — revisa el cuadro de diálogo)` : '';
|
||||
toast.error(`${line}${more}`);
|
||||
} else if (typeof result.message === 'string' && result.message.trim()) {
|
||||
toast.error(result.message.trim());
|
||||
}
|
||||
reloadData();
|
||||
return;
|
||||
} else if (
|
||||
@@ -1297,6 +1311,38 @@
|
||||
{ label: 'Finalizando validaciones de COVE', percent: 95 }
|
||||
];
|
||||
|
||||
let isDownloadingCoveReceipt = $state(false);
|
||||
|
||||
async function handleDownloadCoveReceipt() {
|
||||
if (!selectedInvoice || !companyStore.activeCompany) {
|
||||
toast.info(m.invoice_list_toasts_select_invoice_for_cove());
|
||||
return;
|
||||
}
|
||||
isDownloadingCoveReceipt = true;
|
||||
try {
|
||||
const blob = await invoicesApi.getCoveReceipt(
|
||||
selectedInvoice.id,
|
||||
companyStore.activeCompany.id
|
||||
);
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `acuse_cove_${selectedInvoice.invoice_number || selectedInvoice.id}.pdf`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
toast.success('Acuse de COVE descargado correctamente.');
|
||||
} catch (e: any) {
|
||||
const msg =
|
||||
e?.message ||
|
||||
'Error al obtener el Acuse de COVE. Verifica que la factura tenga COVE generado.';
|
||||
toast.error(msg);
|
||||
} finally {
|
||||
isDownloadingCoveReceipt = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Opciones de tipo de operación para el filtro
|
||||
const operationTypeOptions = $derived.by(() => [
|
||||
{ value: '', label: m.invoice_list_operation_types_all() },
|
||||
@@ -1715,17 +1761,24 @@
|
||||
<Files class="mr-2 h-4 w-4" />
|
||||
<span>{m.invoice_list_footer_vu_addenda()}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-left hover:bg-accent"
|
||||
onclick={() => {
|
||||
showVuSubmenu = false;
|
||||
openCoveDialog();
|
||||
}}
|
||||
>
|
||||
<Files class="mr-2 h-4 w-4" />
|
||||
<span>{m.invoice_list_footer_vu_cove_receipt()}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-left hover:bg-accent"
|
||||
disabled={isDownloadingCoveReceipt}
|
||||
onclick={() => {
|
||||
showVuSubmenu = false;
|
||||
handleDownloadCoveReceipt();
|
||||
}}
|
||||
>
|
||||
<Files class="mr-2 h-4 w-4" />
|
||||
<span>
|
||||
{#if isDownloadingCoveReceipt}
|
||||
Descargando...
|
||||
{:else}
|
||||
{m.invoice_list_footer_vu_cove_receipt()}
|
||||
{/if}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-left hover:bg-accent"
|
||||
@@ -1903,10 +1956,13 @@
|
||||
<Files class="mr-2 h-4 w-4" />
|
||||
{m.invoice_list_footer_vu_addenda()}
|
||||
</DropdownMenu.Item>
|
||||
<DropdownMenu.Item onclick={() => openCoveDialog()}>
|
||||
<Files class="mr-2 h-4 w-4" />
|
||||
{m.invoice_list_footer_vu_cove_receipt()}
|
||||
</DropdownMenu.Item>
|
||||
<DropdownMenu.Item
|
||||
disabled={isDownloadingCoveReceipt}
|
||||
onclick={() => handleDownloadCoveReceipt()}
|
||||
>
|
||||
<Files class="mr-2 h-4 w-4" />
|
||||
{isDownloadingCoveReceipt ? 'Descargando...' : m.invoice_list_footer_vu_cove_receipt()}
|
||||
</DropdownMenu.Item>
|
||||
<DropdownMenu.Item onclick={() => toast.info(m.invoice_list_submenu_massive_cove_soon())}>
|
||||
<Files class="mr-2 h-4 w-4" />
|
||||
{m.invoice_list_footer_vu_massive_cove()}
|
||||
|
||||
Reference in New Issue
Block a user