Se integro el modulo de importacion definitiva

This commit is contained in:
2026-02-16 11:52:27 -06:00
parent 3d691d6881
commit 5d230fc4d7
11 changed files with 822 additions and 161 deletions

View File

@@ -61,5 +61,35 @@ export const reportsTransmissionApi = {
if (!response.ok) throw new Error('Error al consultar estado de la transmisión temporal');
return await response.json();
},
triggerDefinitiveGeneration: async (request: any) => {
const endpoint = `${BASE_URL}/v1/a76/reports/importacion/transmission/definitive/generate`;
const token = localStorage.getItem('access_token');
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(request)
});
if (!response.ok) throw new Error('Error al iniciar la generación definitiva');
return await response.json();
},
getDefinitiveTaskStatus: async (taskId: string) => {
const endpoint = `${BASE_URL}/v1/a76/reports/importacion/transmission/definitive/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 de la transmisión definitiva');
return await response.json();
}
};

View File

@@ -36,18 +36,14 @@
let regimen = $state('Temporal');
let activeTab = $state('movimiento');
// Manifests State (12 slots, organized in 4 tabs of 3 inputs)
// We'll store them in a single array for simplicity, mapped to tabs
let manifests = $state(Array(12).fill(''));
let activeManifestTab = $state('tab1');
let manifests = $state<string[]>([]);
// Selector Modal State
let isManifestSelectorOpen = $state(false);
let currentManifestIndex = $state(0);
// Invoice Manual State (12 slots)
let manualInvoices = $state(Array(12).fill(''));
let activeInvoiceTab = $state('tab1');
let manualInvoices = $state<string[]>([]);
let isInvoiceSelectorOpen = $state(false);
let currentInvoiceIndex = $state(0);
@@ -58,6 +54,7 @@
let fileName = $state<string | null>(null);
let progressTitle = $state('Generando Archivo de Transmisión');
let isTemporalTask = $state(false);
let isDefinitiveTask = $state(false);
// Ports State
let entryPort = $state('');
@@ -129,8 +126,16 @@
};
try {
const res = await reportsTransmissionApi.triggerTemporalGeneration(payload);
isTemporalTask = true;
let res;
if (regimen === 'Definitiva') {
res = await reportsTransmissionApi.triggerDefinitiveGeneration(payload);
isDefinitiveTask = true;
isTemporalTask = false;
} else {
res = await reportsTransmissionApi.triggerTemporalGeneration(payload);
isTemporalTask = true;
isDefinitiveTask = false;
}
if (res.task_id) {
taskId = res.task_id;
@@ -213,8 +218,8 @@
if (open && companyStore.activeCompany?.id) {
loadManifests();
// Pre-fill first slot if we have a specific invoice and it's empty
if (invoice?.invoice_number && manualInvoices[0] === '') {
manualInvoices[0] = invoice.invoice_number;
if (invoice?.invoice_number && !manualInvoices.includes(invoice.invoice_number)) {
manualInvoices.push(invoice.invoice_number);
}
}
});
@@ -239,7 +244,11 @@
}
function handleManifestSelect(manifest: any) {
manifests[currentManifestIndex] = manifest.manifest_number;
if (currentManifestIndex === -1) {
manifests.push(manifest.manifest_number);
} else {
manifests[currentManifestIndex] = manifest.manifest_number;
}
isManifestSelectorOpen = false;
}
@@ -249,12 +258,19 @@
}
function handleInvoiceSelect(invoice: any) {
manualInvoices[currentInvoiceIndex] = invoice.invoice_number;
if (currentInvoiceIndex === -1) {
manualInvoices.push(invoice.invoice_number);
} else {
manualInvoices[currentInvoiceIndex] = invoice.invoice_number;
}
isInvoiceSelectorOpen = false;
}
// This function is expected by PdfProgressDialog to check status
async function checkTaskStatus(id: string) {
if (isDefinitiveTask) {
return await reportsTransmissionApi.getDefinitiveTaskStatus(id);
}
if (isTemporalTask) {
return await reportsTransmissionApi.getTemporalTaskStatus(id);
}
@@ -358,149 +374,99 @@
<Label class="text-base font-medium">MANIFIESTOS (ENTRYS)</Label>
</div>
<div class="rounded-md border p-3">
<Tabs.Root bind:value={activeManifestTab}>
<Tabs.List class="mb-2 grid grid-cols-4">
<Tabs.Trigger value="tab1">1 - 3</Tabs.Trigger>
<Tabs.Trigger value="tab2">4 - 6</Tabs.Trigger>
<Tabs.Trigger value="tab3">7 - 9</Tabs.Trigger>
<Tabs.Trigger value="tab4">10 - 12</Tabs.Trigger>
</Tabs.List>
<div class="grid grid-cols-2 gap-3 md:grid-cols-3 lg:grid-cols-4">
{#each manifests as m, i}
<div
class="group relative flex flex-col items-center justify-center rounded-lg border-2 border-solid border-blue-500 bg-blue-50/30 p-4 transition-all"
role="button"
tabindex="0"
onclick={() => openManifestSelector(i)}
onkeydown={(e) =>
(e.key === 'Enter' || e.key === ' ') && openManifestSelector(i)}
>
<span class="absolute top-1 left-2 text-[10px] font-bold text-blue-400"
>{i + 1}</span
>
<div
class="w-full cursor-pointer truncate text-center text-sm font-semibold text-blue-700"
>
{m}
</div>
<button
class="absolute -top-2 -right-2 z-20 rounded-full bg-destructive p-1 text-white shadow-md hover:scale-110 active:scale-95"
onclick={(e) => {
e.preventDefault();
e.stopPropagation();
manifests.splice(i, 1);
}}
>
<X class="h-3 w-3" />
</button>
</div>
{/each}
<Tabs.Content value="tab1" class="space-y-2">
{#each [0, 1, 2] as i}
<div class="flex items-center gap-2">
<Label class="w-8 text-muted-foreground">{i + 1}.</Label>
<Input
bind:value={manifests[i]}
placeholder={`MANIFIESTO (ENTRY) ${i + 1}`}
readonly
onclick={() => openManifestSelector(i)}
class="cursor-pointer"
/>
</div>
{/each}
</Tabs.Content>
<Tabs.Content value="tab2" class="space-y-2">
{#each [3, 4, 5] as i}
<div class="flex items-center gap-2">
<Label class="w-8 text-muted-foreground">{i + 1}.</Label>
<Input
bind:value={manifests[i]}
placeholder={`MANIFIESTO (ENTRY) ${i + 1}`}
readonly
onclick={() => openManifestSelector(i)}
class="cursor-pointer"
/>
</div>
{/each}
</Tabs.Content>
<Tabs.Content value="tab3" class="space-y-2">
{#each [6, 7, 8] as i}
<div class="flex items-center gap-2">
<Label class="w-8 text-muted-foreground">{i + 1}.</Label>
<Input
bind:value={manifests[i]}
placeholder={`MANIFIESTO (ENTRY) ${i + 1}`}
readonly
onclick={() => openManifestSelector(i)}
class="cursor-pointer"
/>
</div>
{/each}
</Tabs.Content>
<Tabs.Content value="tab4" class="space-y-2">
{#each [9, 10, 11] as i}
<div class="flex items-center gap-2">
<Label class="w-8 text-muted-foreground">{i + 1}.</Label>
<Input
bind:value={manifests[i]}
placeholder={`MANIFIESTO (ENTRY) ${i + 1}`}
readonly
onclick={() => openManifestSelector(i)}
class="cursor-pointer"
/>
</div>
{/each}
</Tabs.Content>
</Tabs.Root>
<!-- Add Slot -->
<div
class="flex h-[72px] cursor-pointer flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted p-4 transition-all hover:border-blue-400 hover:bg-blue-50/50"
role="button"
tabindex="0"
onclick={() => openManifestSelector(-1)}
onkeydown={(e) =>
(e.key === 'Enter' || e.key === ' ') && openManifestSelector(-1)}
>
<Folder class="mb-1 h-4 w-4 text-muted-foreground" />
<span class="text-xs font-medium text-muted-foreground">Agregar...</span>
</div>
</div>
{/if}
<div class="rounded-md border p-3">
{#if movementType === 'Importacion'}
<div class="mb-2 text-base font-medium">FACTURAS ({regimen?.toUpperCase()})</div>
<Tabs.Root bind:value={activeInvoiceTab}>
<Tabs.List class="mb-2 grid grid-cols-4">
<Tabs.Trigger value="tab1">1 - 3</Tabs.Trigger>
<Tabs.Trigger value="tab2">4 - 6</Tabs.Trigger>
<Tabs.Trigger value="tab3">7 - 9</Tabs.Trigger>
<Tabs.Trigger value="tab4">10 - 12</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="tab1" class="space-y-2">
{#each [0, 1, 2] as i}
<div class="flex items-center gap-2">
<Label class="w-8 text-muted-foreground">{i + 1}.</Label>
<Input
bind:value={manualInvoices[i]}
placeholder={`FACTURA ${i + 1}`}
readonly
onclick={() => openInvoiceSelector(i)}
class="cursor-pointer"
/>
<div class="grid grid-cols-2 gap-3 md:grid-cols-3 lg:grid-cols-4">
{#each manualInvoices as m, i}
<div
class="group relative flex flex-col items-center justify-center rounded-lg border-2 border-solid border-emerald-500 bg-emerald-50/30 p-4 transition-all"
role="button"
tabindex="0"
onclick={() => openInvoiceSelector(i)}
onkeydown={(e) =>
(e.key === 'Enter' || e.key === ' ') && openInvoiceSelector(i)}
>
<span class="absolute top-1 left-2 text-[10px] font-bold text-emerald-400"
>{i + 1}</span
>
<div
class="w-full cursor-pointer truncate text-center text-sm font-semibold text-emerald-700"
>
{m}
</div>
{/each}
</Tabs.Content>
<button
class="absolute -top-2 -right-2 z-20 rounded-full bg-destructive p-1 text-white shadow-md hover:scale-110 active:scale-95"
onclick={(e) => {
e.preventDefault();
e.stopPropagation();
manualInvoices.splice(i, 1);
}}
>
<X class="h-3 w-3" />
</button>
</div>
{/each}
<Tabs.Content value="tab2" class="space-y-2">
{#each [3, 4, 5] as i}
<div class="flex items-center gap-2">
<Label class="w-8 text-muted-foreground">{i + 1}.</Label>
<Input
bind:value={manualInvoices[i]}
placeholder={`FACTURA ${i + 1}`}
readonly
onclick={() => openInvoiceSelector(i)}
class="cursor-pointer"
/>
</div>
{/each}
</Tabs.Content>
<Tabs.Content value="tab3" class="space-y-2">
{#each [6, 7, 8] as i}
<div class="flex items-center gap-2">
<Label class="w-8 text-muted-foreground">{i + 1}.</Label>
<Input
bind:value={manualInvoices[i]}
placeholder={`FACTURA ${i + 1}`}
readonly
onclick={() => openInvoiceSelector(i)}
class="cursor-pointer"
/>
</div>
{/each}
</Tabs.Content>
<Tabs.Content value="tab4" class="space-y-2">
{#each [9, 10, 11] as i}
<div class="flex items-center gap-2">
<Label class="w-8 text-muted-foreground">{i + 1}.</Label>
<Input
bind:value={manualInvoices[i]}
placeholder={`FACTURA ${i + 1}`}
readonly
onclick={() => openInvoiceSelector(i)}
class="cursor-pointer"
/>
</div>
{/each}
</Tabs.Content>
</Tabs.Root>
<!-- Add Slot -->
<div
class="flex h-[72px] cursor-pointer flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted p-4 transition-all hover:border-emerald-400 hover:bg-emerald-50/50"
role="button"
tabindex="0"
onclick={() => openInvoiceSelector(-1)}
onkeydown={(e) =>
(e.key === 'Enter' || e.key === ' ') && openInvoiceSelector(-1)}
>
<Folder class="mb-1 h-4 w-4 text-muted-foreground" />
<span class="text-xs font-medium text-muted-foreground">Agregar...</span>
</div>
</div>
{/if}
</div>
@@ -561,16 +527,6 @@
</div>
</div>
{/if}
<div class="flex justify-end">
<Button
size="lg"
onclick={handleAction}
class="bg-blue-600 text-white shadow-lg hover:bg-blue-700"
>
<Send class="mr-2 h-5 w-5" />
Generar Archivo
</Button>
</div>
</div>
</div>
@@ -683,6 +639,10 @@
<Dialog.Footer>
<Button variant="outline" onclick={handleClose}>Cerrar</Button>
<Button onclick={handleAction} class="bg-blue-600 text-white shadow hover:bg-blue-700">
<Send class="mr-2 h-4 w-4" />
Generar Archivo
</Button>
</Dialog.Footer>
</Dialog.Content>