feature/correccion-de-atajos-tranportes
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
import { driversApi, type Driver } from '$lib/api/dashboard/a76/drivers';
|
||||
import { transportersApi, type Transporter } from '$lib/api/dashboard/a76/transporters';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
@@ -85,6 +86,7 @@
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
if (loading) return;
|
||||
error = null;
|
||||
loading = true;
|
||||
|
||||
@@ -162,6 +164,17 @@
|
||||
open = false;
|
||||
error = null;
|
||||
}
|
||||
|
||||
function onSaveFormEvent() {
|
||||
void handleSubmit();
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
document.addEventListener('save-form', onSaveFormEvent);
|
||||
});
|
||||
onDestroy(() => {
|
||||
document.removeEventListener('save-form', onSaveFormEvent);
|
||||
});
|
||||
</script>
|
||||
|
||||
<Dialog.Root bind:open>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import { trailersApi, type Trailer } from '$lib/api/dashboard/a76/trailers';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
@@ -53,6 +54,7 @@
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
if (loading) return;
|
||||
error = null;
|
||||
loading = true;
|
||||
|
||||
@@ -92,6 +94,17 @@
|
||||
open = false;
|
||||
error = null;
|
||||
}
|
||||
|
||||
function onSaveFormEvent() {
|
||||
void handleSubmit();
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
document.addEventListener('save-form', onSaveFormEvent);
|
||||
});
|
||||
onDestroy(() => {
|
||||
document.removeEventListener('save-form', onSaveFormEvent);
|
||||
});
|
||||
</script>
|
||||
|
||||
<Dialog.Root bind:open>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import { transportersApi, type Transporter } from '$lib/api/dashboard/a76/transporters';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
@@ -76,6 +77,7 @@
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
if (loading) return;
|
||||
error = null;
|
||||
loading = true;
|
||||
|
||||
@@ -117,6 +119,17 @@
|
||||
open = false;
|
||||
error = null;
|
||||
}
|
||||
|
||||
function onSaveFormEvent() {
|
||||
void handleSubmit();
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
document.addEventListener('save-form', onSaveFormEvent);
|
||||
});
|
||||
onDestroy(() => {
|
||||
document.removeEventListener('save-form', onSaveFormEvent);
|
||||
});
|
||||
</script>
|
||||
|
||||
<Dialog.Root bind:open>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import { vehiclesApi, type Vehicle } from '$lib/api/dashboard/a76/vehicles';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
@@ -90,6 +91,7 @@
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
if (loading) return;
|
||||
error = null;
|
||||
loading = true;
|
||||
|
||||
@@ -131,6 +133,17 @@
|
||||
open = false;
|
||||
error = null;
|
||||
}
|
||||
|
||||
function onSaveFormEvent() {
|
||||
void handleSubmit();
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
document.addEventListener('save-form', onSaveFormEvent);
|
||||
});
|
||||
onDestroy(() => {
|
||||
document.removeEventListener('save-form', onSaveFormEvent);
|
||||
});
|
||||
</script>
|
||||
|
||||
<Dialog.Root bind:open>
|
||||
|
||||
@@ -19,7 +19,7 @@ export const obtenerAtajosPrincipalesEdicionPedimento = (acciones: {
|
||||
action: () => acciones.cambiarPestana('cuentas-compensacion')
|
||||
},
|
||||
{ key: 'Alt+X', description: 'Tab Otros', action: () => acciones.cambiarPestana('otros-datos') },
|
||||
{ key: 'Alt+J', description: 'Tab Digital', action: () => acciones.cambiarPestana('digitalizacion') },
|
||||
{ key: 'Alt+W', description: 'Tab Digital', action: () => acciones.cambiarPestana('digitalizacion') },
|
||||
{ key: 'Ctrl+S', description: 'Guardar cambios', action: acciones.manejarGuardar },
|
||||
{ key: 'Escape', description: 'Regresar / Cancelar', action: acciones.manejarRegresar }
|
||||
];
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
import { driversApi, type Driver } from '$lib/api/dashboard/a76/drivers';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { browser } from '$app/environment';
|
||||
import { useShortcuts } from '$lib/hooks/use-shortcuts';
|
||||
import { obtenerAtajosCatalogoSimple } from '$lib/config/shortcuts/dashboard/general_catalogs/common/factory';
|
||||
|
||||
let data = $state<Driver[]>([]);
|
||||
let totalItems = $state(0);
|
||||
@@ -91,6 +93,23 @@
|
||||
loadData();
|
||||
});
|
||||
|
||||
useShortcuts('Conductores', [
|
||||
...obtenerAtajosCatalogoSimple({
|
||||
manejarNuevo: () => {
|
||||
createDialogOpen = true;
|
||||
},
|
||||
manejarActualizar: loadData
|
||||
}),
|
||||
{
|
||||
key: 'Ctrl+S',
|
||||
description: 'Guardar',
|
||||
action: () => {
|
||||
if (!createDialogOpen) return;
|
||||
document.dispatchEvent(new CustomEvent('save-form'));
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
const columns = createColumns(loadData);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,188 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import * as Card from '$lib/components/ui/card';
|
||||
import * as Table from '$lib/components/ui/table';
|
||||
import { Search, Loader2, Download } from 'lucide-svelte';
|
||||
import {
|
||||
getTariffFractions,
|
||||
type TariffFraction
|
||||
} from '$lib/api/dashboard/a76/general_catalogs/tariff-fractions';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { useShortcuts } from '$lib/hooks/use-shortcuts';
|
||||
import { obtenerAtajosListaFracciones } from '$lib/config/shortcuts/dashboard/general_catalogs/tariff_fractions/list';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
// Estado
|
||||
let tariffFractions = $state<TariffFraction[]>([]);
|
||||
let searchQuery = $state('');
|
||||
let isLoading = $state(false);
|
||||
let currentPage = $state(1);
|
||||
let totalPages = $state(1);
|
||||
let totalRecords = $state(0);
|
||||
const pageSize = 50;
|
||||
let searchTimeout: NodeJS.Timeout;
|
||||
|
||||
// Atajos
|
||||
useShortcuts(
|
||||
'Lista Fracciones',
|
||||
obtenerAtajosListaFracciones({
|
||||
manejarNuevo: () => {}, // No hay botón de nuevo en esta vista
|
||||
manejarActualizar: () => loadTariffFractions(currentPage)
|
||||
})
|
||||
);
|
||||
|
||||
onMount(() => {
|
||||
loadTariffFractions();
|
||||
});
|
||||
|
||||
// Efecto para búsqueda con debounce
|
||||
$effect(() => {
|
||||
// Limpiar timeout anterior
|
||||
clearTimeout(searchTimeout);
|
||||
|
||||
// Setup nuevo timeout
|
||||
searchTimeout = setTimeout(() => {
|
||||
// Resetear a página 1 cuando cambia la búsqueda
|
||||
if (currentPage !== 1) {
|
||||
currentPage = 1;
|
||||
}
|
||||
loadTariffFractions(1, searchQuery);
|
||||
}, 500);
|
||||
|
||||
return () => clearTimeout(searchTimeout);
|
||||
});
|
||||
|
||||
async function loadTariffFractions(page: number = 1, search: string = '') {
|
||||
const companyId = companyStore.activeCompany?.id;
|
||||
if (!companyId) {
|
||||
console.error('No hay compañía activa');
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
try {
|
||||
// Preparar filtros
|
||||
const filters: Record<string, any> = {};
|
||||
if (search.trim()) {
|
||||
filters.search = search.trim();
|
||||
}
|
||||
|
||||
const response = await getTariffFractions(page, pageSize, companyId, filters);
|
||||
if (response.data) {
|
||||
tariffFractions = response.data.items;
|
||||
totalPages = response.data.pages;
|
||||
totalRecords = response.data.total;
|
||||
currentPage = response.data.page;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error cargando fracciones arancelarias:', error);
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function goToPage(page: number) {
|
||||
if (page >= 1 && page <= totalPages && page !== currentPage) {
|
||||
await loadTariffFractions(page, searchQuery);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-6 p-6 h-[calc(100svh-4rem)] group-has-data-[collapsible=icon]/sidebar-wrapper:h-[calc(100svh-3rem)] overflow-hidden">
|
||||
<div class="flex-none flex items-center justify-between">
|
||||
<div class="space-y-1">
|
||||
<h1 class="text-2xl font-bold tracking-tight">Catálogo de Fracciones SITAR - SCAII</h1>
|
||||
<p class="text-muted-foreground">Nomenclatura arancelaria mexicana completa</p>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" class="h-9" title="Exportar a CSV">
|
||||
<Download class="mr-2 h-4 w-4" />
|
||||
Exportar
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Card.Root class="flex min-h-0 flex-1 flex-col border bg-background">
|
||||
<Card.Header>
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<Card.Title>Listado de Fracciones</Card.Title>
|
||||
<div class="relative min-w-[320px] flex-1 xl:max-w-xl">
|
||||
<Search class="absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
bind:value={searchQuery}
|
||||
placeholder="Buscar por código, fracción, descripción, NICO o UMT..."
|
||||
class="h-9 bg-card pl-9"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Card.Header>
|
||||
<Card.Content class="min-h-0 p-0">
|
||||
<div class="catalog-table-shell bg-background">
|
||||
<Table.Root>
|
||||
<Table.Header class="catalog-table-header">
|
||||
<Table.Row>
|
||||
<Table.Head class="catalog-table-head-cell w-[100px]">Código</Table.Head>
|
||||
<Table.Head class="catalog-table-head-cell w-[120px]">Fracción</Table.Head>
|
||||
<Table.Head class="catalog-table-head-cell min-w-[350px]">Descripción</Table.Head>
|
||||
<Table.Head class="catalog-table-head-cell w-[80px]">NICO</Table.Head>
|
||||
<Table.Head class="catalog-table-head-cell w-[80px]">UMT</Table.Head>
|
||||
<Table.Head class="catalog-table-head-cell w-[100px]">Adv. Impo</Table.Head>
|
||||
<Table.Head class="catalog-table-head-cell w-[100px]">Adv. Expo</Table.Head>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{#if tariffFractions.length === 0}
|
||||
<Table.Row>
|
||||
<Table.Cell colspan={7} class="h-24 text-center text-sm text-muted-foreground">
|
||||
{#if isLoading}
|
||||
Cargando fracciones arancelarias...
|
||||
{:else if searchQuery}
|
||||
No se encontraron fracciones que coincidan con la búsqueda
|
||||
{:else}
|
||||
No hay fracciones arancelarias disponibles
|
||||
{/if}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
{:else}
|
||||
{#each tariffFractions as fraction (fraction.id)}
|
||||
<Table.Row class="catalog-table-row">
|
||||
<Table.Cell class="font-mono text-sm">{fraction.code}</Table.Cell>
|
||||
<Table.Cell class="font-mono text-sm font-medium">{fraction.fraction}</Table.Cell>
|
||||
<Table.Cell class="text-sm">{fraction.description || '-'}</Table.Cell>
|
||||
<Table.Cell class="text-sm">{fraction.nico || '-'}</Table.Cell>
|
||||
<Table.Cell class="text-sm">{fraction.umt || '-'}</Table.Cell>
|
||||
<Table.Cell class="text-sm">{fraction.adv_impo || '-'}</Table.Cell>
|
||||
<Table.Cell class="text-sm">{fraction.adv_expo || '-'}</Table.Cell>
|
||||
</Table.Row>
|
||||
{/each}
|
||||
{/if}
|
||||
</Table.Body>
|
||||
</Table.Root>
|
||||
</div>
|
||||
</Card.Content>
|
||||
</Card.Root>
|
||||
|
||||
<div class="flex-none text-sm text-muted-foreground">
|
||||
Mostrando {tariffFractions.length} de {totalRecords} fracciones arancelarias
|
||||
{#if searchQuery}
|
||||
<span class="ml-2">•</span>
|
||||
<span class="ml-2">Filtrado</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if totalPages > 1}
|
||||
<div class="flex-none flex items-center justify-center gap-2">
|
||||
<Button variant="outline" size="sm" class="h-9" disabled={currentPage === 1 || isLoading} onclick={() => goToPage(1)}>
|
||||
Primera
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" class="h-9" disabled={currentPage === 1 || isLoading} onclick={() => goToPage(currentPage - 1)}>
|
||||
Anterior
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" class="h-9" disabled={currentPage === totalPages || isLoading} onclick={() => goToPage(currentPage + 1)}>
|
||||
Siguiente
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" class="h-9" disabled={currentPage === totalPages || isLoading} onclick={() => goToPage(totalPages)}>
|
||||
Última
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
import { trailersApi, type Trailer } from '$lib/api/dashboard/a76/trailers';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { browser } from '$app/environment';
|
||||
import { useShortcuts } from '$lib/hooks/use-shortcuts';
|
||||
import { obtenerAtajosCatalogoSimple } from '$lib/config/shortcuts/dashboard/general_catalogs/common/factory';
|
||||
|
||||
// --- ESTADO ---
|
||||
let data = $state<Trailer[]>([]);
|
||||
@@ -98,6 +100,23 @@
|
||||
loadData();
|
||||
});
|
||||
|
||||
useShortcuts('Trailers', [
|
||||
...obtenerAtajosCatalogoSimple({
|
||||
manejarNuevo: () => {
|
||||
createDialogOpen = true;
|
||||
},
|
||||
manejarActualizar: loadData
|
||||
}),
|
||||
{
|
||||
key: 'Ctrl+S',
|
||||
description: 'Guardar',
|
||||
action: () => {
|
||||
if (!createDialogOpen) return;
|
||||
document.dispatchEvent(new CustomEvent('save-form'));
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
const columns = createColumns(loadData);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
import { transportersApi, type Transporter } from '$lib/api/dashboard/a76/transporters';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { browser } from '$app/environment';
|
||||
import { useShortcuts } from '$lib/hooks/use-shortcuts';
|
||||
import { obtenerAtajosCatalogoSimple } from '$lib/config/shortcuts/dashboard/general_catalogs/common/factory';
|
||||
|
||||
// --- ESTADO ---
|
||||
let data = $state<Transporter[]>([]);
|
||||
@@ -98,6 +100,23 @@
|
||||
loadData();
|
||||
});
|
||||
|
||||
useShortcuts('Transportistas', [
|
||||
...obtenerAtajosCatalogoSimple({
|
||||
manejarNuevo: () => {
|
||||
createDialogOpen = true;
|
||||
},
|
||||
manejarActualizar: loadData
|
||||
}),
|
||||
{
|
||||
key: 'Ctrl+S',
|
||||
description: 'Guardar',
|
||||
action: () => {
|
||||
if (!createDialogOpen) return;
|
||||
document.dispatchEvent(new CustomEvent('save-form'));
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
const columns = createColumns(loadData);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
import { vehiclesApi, type Vehicle } from '$lib/api/dashboard/a76/vehicles';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { browser } from '$app/environment';
|
||||
import { useShortcuts } from '$lib/hooks/use-shortcuts';
|
||||
import { obtenerAtajosCatalogoSimple } from '$lib/config/shortcuts/dashboard/general_catalogs/common/factory';
|
||||
|
||||
// --- ESTADO ---
|
||||
let data = $state<Vehicle[]>([]);
|
||||
@@ -98,6 +100,23 @@
|
||||
loadData();
|
||||
});
|
||||
|
||||
useShortcuts('Vehículos (transporte)', [
|
||||
...obtenerAtajosCatalogoSimple({
|
||||
manejarNuevo: () => {
|
||||
createDialogOpen = true;
|
||||
},
|
||||
manejarActualizar: loadData
|
||||
}),
|
||||
{
|
||||
key: 'Ctrl+S',
|
||||
description: 'Guardar',
|
||||
action: () => {
|
||||
if (!createDialogOpen) return;
|
||||
document.dispatchEvent(new CustomEvent('save-form'));
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
const columns = createColumns(loadData);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -229,6 +229,14 @@
|
||||
key: 'Alt+Shift+D',
|
||||
description: 'Delete',
|
||||
action: handleDelete
|
||||
},
|
||||
{
|
||||
key: 'Ctrl+S',
|
||||
description: 'Guardar clase',
|
||||
action: () => {
|
||||
if (!showInsertDialog || isSaving) return;
|
||||
document.dispatchEvent(new CustomEvent('save-form'));
|
||||
}
|
||||
}
|
||||
]);
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user