Se corrigio y expandio los datos de clientes y proveedores
This commit is contained in:
@@ -116,9 +116,7 @@ class ClientProviderCreateDTO(BaseModel):
|
||||
)
|
||||
position: Optional[str] = Field(None, max_length=30, description="Position")
|
||||
incoterm: Optional[str] = Field(None, max_length=19, description="Incoterm")
|
||||
is_national_provider: Optional[str] = Field(
|
||||
None, max_length=2, description="Is national provider"
|
||||
)
|
||||
is_national_provider: Optional[bool] = None
|
||||
is_active: Optional[bool] = Field(None, description="Enabled/Disabled status")
|
||||
|
||||
# Nested DTOs
|
||||
@@ -159,9 +157,7 @@ class ClientProviderUpdateDTO(BaseModel):
|
||||
)
|
||||
position: Optional[str] = Field(None, max_length=30, description="Position")
|
||||
incoterm: Optional[str] = Field(None, max_length=19, description="Incoterm")
|
||||
is_national_provider: Optional[str] = Field(
|
||||
None, max_length=2, description="Is national provider"
|
||||
)
|
||||
is_national_provider: Optional[bool] = None
|
||||
is_active: Optional[bool] = Field(None, description="Enabled/Disabled status")
|
||||
|
||||
# Nested DTOs
|
||||
@@ -193,7 +189,7 @@ class ClientProviderResponseDTO(BaseModel):
|
||||
responsible: Optional[str] = None
|
||||
position: Optional[str] = None
|
||||
incoterm: Optional[str] = None
|
||||
is_national_provider: Optional[str] = None
|
||||
is_national_provider: Optional[bool] = None
|
||||
is_active: Optional[bool] = None
|
||||
tenant_id: int
|
||||
company_id: int
|
||||
|
||||
@@ -1,173 +1,97 @@
|
||||
/**
|
||||
* API Client para Clientes y Proveedores
|
||||
* Gestiona las operaciones CRUD para clientes y proveedores
|
||||
*/
|
||||
import { api } from '$lib/api';
|
||||
|
||||
// --- Interfaces para Tablas Hijas ---
|
||||
|
||||
export interface ClientProviderAddress {
|
||||
id?: number;
|
||||
streets?: string | null;
|
||||
streets?: string | null;
|
||||
exterior_number?: string | null;
|
||||
interior_number?: string | null;
|
||||
neighborhood?: string | null;
|
||||
municipality?: string | null;
|
||||
city?: string | null;
|
||||
state?: string | null;
|
||||
country?: string | null;
|
||||
zip_code?: string | null;
|
||||
client_id?: number;
|
||||
interior_number?: string | null;
|
||||
exterior_number?: string | null;
|
||||
municipality?: string | null;
|
||||
postal_code?: string | null;
|
||||
email?: string | null;
|
||||
phone?: string | null;
|
||||
contact?: string | null;
|
||||
}
|
||||
|
||||
export interface ClientProviderPrograms {
|
||||
id?: number;
|
||||
program_code?: string | null;
|
||||
authorization_date?: string | null;
|
||||
client_id?: number;
|
||||
id?: number;
|
||||
program?: string | null;
|
||||
program_number?: string | null;
|
||||
secon_auth_date?: number | null; // YYYYMMDD
|
||||
prosec?: number | null;
|
||||
manufacturer_id?: string | null;
|
||||
tax_id?: string | null;
|
||||
ctpat_svi?: string | null;
|
||||
is_certified_company?: string | null;
|
||||
}
|
||||
|
||||
// --- Interfaz Principal ---
|
||||
|
||||
export interface ClientProvider {
|
||||
id: number;
|
||||
rfc: string;
|
||||
name: string;
|
||||
curp?: string | null;
|
||||
residence_country?: string | null;
|
||||
domicile_fiscal?: string | null;
|
||||
foreign_tax_id?: string | null;
|
||||
client_or_provider?: string | null;
|
||||
is_active?: boolean;
|
||||
tenant_id: number;
|
||||
address?: ClientProviderAddress | null;
|
||||
programs?: ClientProviderPrograms | null;
|
||||
}
|
||||
|
||||
export interface ClientProviderBasic {
|
||||
id: number;
|
||||
rfc: string;
|
||||
name: string;
|
||||
curp?: string | null;
|
||||
residence_country?: string | null;
|
||||
domicile_fiscal?: string | null;
|
||||
foreign_tax_id?: string | null;
|
||||
client_or_provider?: string | null;
|
||||
is_active?: boolean;
|
||||
tenant_id: number;
|
||||
id: number;
|
||||
rfc: string;
|
||||
name: string;
|
||||
short_name?: string | null;
|
||||
curp?: string | null;
|
||||
client_or_provider: 'client' | 'provider' | 'both';
|
||||
|
||||
// Campos planos de la tabla principal
|
||||
type_nat_foreign?: string | null;
|
||||
responsible?: string | null;
|
||||
position?: string | null;
|
||||
|
||||
// Booleanos (Coincidiendo con la BD)
|
||||
is_national_provider?: boolean | null;
|
||||
is_active?: boolean;
|
||||
|
||||
// Relaciones Anidadas
|
||||
address?: ClientProviderAddress | null;
|
||||
programs?: ClientProviderPrograms | null;
|
||||
}
|
||||
|
||||
export interface ClientProviderListResponse {
|
||||
items: ClientProvider[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
items: ClientProvider[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
}
|
||||
|
||||
export interface CreateClientProviderData {
|
||||
rfc: string;
|
||||
name: string;
|
||||
curp?: string | null;
|
||||
residence_country?: string | null;
|
||||
domicile_fiscal?: string | null;
|
||||
foreign_tax_id?: string | null;
|
||||
client_or_provider?: string | null;
|
||||
is_active?: boolean;
|
||||
address?: Omit<ClientProviderAddress, 'id' | 'client_id'> | null;
|
||||
programs?: Omit<ClientProviderPrograms, 'id' | 'client_id'> | null;
|
||||
// DTOs de Envío (excluyendo IDs automáticos)
|
||||
export interface CreateClientProviderData extends Omit<ClientProvider, 'id' | 'address' | 'programs'> {
|
||||
address?: ClientProviderAddress | null;
|
||||
programs?: ClientProviderPrograms | null;
|
||||
}
|
||||
|
||||
export interface UpdateClientProviderData {
|
||||
rfc?: string;
|
||||
name?: string;
|
||||
curp?: string | null;
|
||||
residence_country?: string | null;
|
||||
domicile_fiscal?: string | null;
|
||||
foreign_tax_id?: string | null;
|
||||
client_or_provider?: string | null;
|
||||
is_active?: boolean;
|
||||
address?: Partial<ClientProviderAddress> | null;
|
||||
programs?: Partial<ClientProviderPrograms> | null;
|
||||
}
|
||||
export interface UpdateClientProviderData extends Partial<CreateClientProviderData> {}
|
||||
|
||||
/**
|
||||
* API para Clientes y Proveedores
|
||||
*/
|
||||
export const clientsProvidersApi = {
|
||||
/**
|
||||
* Lista todos los clientes y proveedores con paginación
|
||||
* @param companyId - ID de la compañía
|
||||
* @param page - Número de página (por defecto 1)
|
||||
* @param pageSize - Tamaño de página (por defecto 50)
|
||||
* @param filters - Filtros opcionales
|
||||
*/
|
||||
list: (companyId: number, page = 1, pageSize = 50, filters?: Record<string, any>) => {
|
||||
const params = new URLSearchParams({
|
||||
company_id: companyId.toString(),
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString()
|
||||
});
|
||||
list: (companyId: number, page = 1, pageSize = 50, filters?: Record<string, any>) => {
|
||||
const params = new URLSearchParams({
|
||||
company_id: companyId.toString(),
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString()
|
||||
});
|
||||
if (filters) {
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value) params.append(key, value.toString());
|
||||
});
|
||||
}
|
||||
return api.get<ClientProviderListResponse>(`/v1/a76/clients-providers?${params.toString()}`);
|
||||
},
|
||||
get: (id: number, companyId: number) =>
|
||||
api.get<ClientProvider>(`/v1/a76/clients-providers/${id}?company_id=${companyId}`),
|
||||
|
||||
create: (companyId: number, data: any) =>
|
||||
api.post<ClientProvider>(`/v1/a76/clients-providers?company_id=${companyId}`, data),
|
||||
|
||||
if (filters) {
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
params.append(key, value.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
update: (id: number, companyId: number, data: any) =>
|
||||
api.patch<ClientProvider>(`/v1/a76/clients-providers/${id}?company_id=${companyId}`, data),
|
||||
|
||||
return api.get<ClientProviderListResponse>(
|
||||
`/v1/a76/clients-providers?${params.toString()}`
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Obtiene un cliente/proveedor por ID
|
||||
* @param id - ID del cliente/proveedor
|
||||
* @param companyId - ID de la compañía
|
||||
*/
|
||||
get: (id: number, companyId: number) =>
|
||||
api.get<ClientProvider>(`/v1/a76/clients-providers/${id}?company_id=${companyId}`),
|
||||
|
||||
/**
|
||||
* Obtiene información básica de un cliente/proveedor
|
||||
* @param id - ID del cliente/proveedor
|
||||
* @param companyId - ID de la compañía
|
||||
*/
|
||||
getBasic: (id: number, companyId: number) =>
|
||||
api.get<ClientProviderBasic>(
|
||||
`/v1/a76/clients-providers/${id}/basic?company_id=${companyId}`
|
||||
),
|
||||
|
||||
/**
|
||||
* Crea un nuevo cliente/proveedor
|
||||
* @param companyId - ID de la compañía
|
||||
* @param data - Datos del cliente/proveedor a crear
|
||||
*/
|
||||
create: (companyId: number, data: CreateClientProviderData) =>
|
||||
api.post<ClientProvider>(`/v1/a76/clients-providers?company_id=${companyId}`, data),
|
||||
|
||||
/**
|
||||
* Actualiza un cliente/proveedor existente
|
||||
* @param id - ID del cliente/proveedor a actualizar
|
||||
* @param companyId - ID de la compañía
|
||||
* @param data - Datos a actualizar
|
||||
*/
|
||||
update: (id: number, companyId: number, data: UpdateClientProviderData) =>
|
||||
api.patch<ClientProvider>(`/v1/a76/clients-providers/${id}?company_id=${companyId}`, data),
|
||||
|
||||
/**
|
||||
* Alterna el estado activo/inactivo de un cliente/proveedor
|
||||
* @param id - ID del cliente/proveedor
|
||||
* @param companyId - ID de la compañía
|
||||
*/
|
||||
toggleStatus: (id: number, companyId: number) =>
|
||||
api.put<ClientProvider>(
|
||||
`/v1/a76/clients-providers/${id}/toggle-status?company_id=${companyId}`,
|
||||
{}
|
||||
),
|
||||
|
||||
/**
|
||||
* Elimina un cliente/proveedor
|
||||
* @param id - ID del cliente/proveedor a eliminar
|
||||
* @param companyId - ID de la compañía
|
||||
*/
|
||||
delete: (id: number, companyId: number) =>
|
||||
api.delete(`/v1/a76/clients-providers/${id}?company_id=${companyId}`)
|
||||
};
|
||||
delete: (id: number, companyId: number) =>
|
||||
api.delete(`/v1/a76/clients-providers/${id}?company_id=${companyId}`)
|
||||
};
|
||||
@@ -1,111 +1,101 @@
|
||||
import type { ColumnDef } from "@tanstack/table-core";
|
||||
import { renderComponent, renderSnippet } from "$lib/components/ui/data-table/index.js";
|
||||
import { createRawSnippet } from "svelte";
|
||||
import DataTableActions from "./data-table-actions.svelte";
|
||||
import type { ClientProvider } from "$lib/api/dashboard/a76/clients-providers";
|
||||
|
||||
export type { ClientProvider };
|
||||
export function createColumns(onSuccess) {
|
||||
return [
|
||||
{
|
||||
accessorKey: "id",
|
||||
header: "ID",
|
||||
cell: ({ row }) => {
|
||||
const snippet = createRawSnippet((getData) => {
|
||||
const { val } = getData();
|
||||
return { render: () => `<span class="font-medium">${val}</span>` };
|
||||
});
|
||||
return renderSnippet(snippet, { val: row.original.id });
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "rfc",
|
||||
header: "RFC",
|
||||
cell: ({ row }) => {
|
||||
const snippet = createRawSnippet((getData) => {
|
||||
const { val } = getData();
|
||||
return { render: () => `<code class="bg-muted px-1 py-0.5 rounded font-mono text-sm">${val}</code>` };
|
||||
});
|
||||
return renderSnippet(snippet, { val: row.original.rfc });
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "name",
|
||||
header: "Nombre",
|
||||
cell: ({ row }) => {
|
||||
const snippet = createRawSnippet((getData) => {
|
||||
const { val } = getData();
|
||||
return { render: () => `<div class="max-w-[250px] truncate font-medium" title="${val}">${val}</div>` };
|
||||
});
|
||||
return renderSnippet(snippet, { val: row.original.name });
|
||||
}
|
||||
},
|
||||
{
|
||||
id: "country",
|
||||
header: "País",
|
||||
cell: ({ row }) => {
|
||||
const snippet = createRawSnippet((getData) => {
|
||||
const { val } = getData();
|
||||
return { render: () => `<div>${val || '-'}</div>` };
|
||||
});
|
||||
// Busca en address.country, si no existe pone null
|
||||
const country = row.original.address?.country;
|
||||
return renderSnippet(snippet, { val: country });
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "client_or_provider",
|
||||
header: "Tipo",
|
||||
cell: ({ row }) => {
|
||||
const snippet = createRawSnippet((getData) => {
|
||||
const { val } = getData();
|
||||
const map = { client: 'Cliente', provider: 'Proveedor', both: 'Ambos' };
|
||||
const colors = {
|
||||
client: 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300',
|
||||
provider: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300',
|
||||
both: 'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-300'
|
||||
};
|
||||
return {
|
||||
render: () => `<span class="px-2 py-0.5 rounded-full text-xs font-medium ${colors[val] || 'bg-gray-100'}">${map[val] || val}</span>`
|
||||
};
|
||||
});
|
||||
return renderSnippet(snippet, { val: row.original.client_or_provider });
|
||||
}
|
||||
},
|
||||
// --- CORRECCIÓN AQUÍ ---
|
||||
{
|
||||
accessorKey: "is_active",
|
||||
header: "Estado",
|
||||
cell: ({ row }) => {
|
||||
const snippet = createRawSnippet((getData) => {
|
||||
const { val } = getData();
|
||||
|
||||
// CORRECCIÓN: Usamos !!val para convertir cualquier valor positivo (true, 1) a true.
|
||||
// Si val es null, undefined, false o 0, será false.
|
||||
const isActive = !!val;
|
||||
|
||||
export function createColumns(onSuccess?: () => void): ColumnDef<ClientProvider>[] {
|
||||
return [
|
||||
{
|
||||
accessorKey: "id",
|
||||
header: "ID",
|
||||
cell: ({ row }) => {
|
||||
const idSnippet = createRawSnippet<[{ id: number }]>((getId) => {
|
||||
const { id } = getId();
|
||||
return {
|
||||
render: () =>
|
||||
`<span class="font-medium">${id}</span>`
|
||||
};
|
||||
});
|
||||
return renderSnippet(idSnippet, { id: row.original.id });
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "rfc",
|
||||
header: "RFC",
|
||||
cell: ({ row }) => {
|
||||
const rfcSnippet = createRawSnippet<[{ rfc: string }]>((getRfc) => {
|
||||
const { rfc } = getRfc();
|
||||
return {
|
||||
render: () =>
|
||||
`<code class="relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold">${rfc}</code>`
|
||||
};
|
||||
});
|
||||
return renderSnippet(rfcSnippet, { rfc: row.original.rfc });
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "name",
|
||||
header: "Nombre",
|
||||
cell: ({ row }) => {
|
||||
const nameSnippet = createRawSnippet<[{ name: string }]>((getName) => {
|
||||
const { name } = getName();
|
||||
return {
|
||||
render: () => `<div class="max-w-[300px] truncate font-medium">${name}</div>`
|
||||
};
|
||||
});
|
||||
return renderSnippet(nameSnippet, { name: row.original.name });
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "client_or_provider",
|
||||
header: "Tipo",
|
||||
cell: ({ row }) => {
|
||||
const typeSnippet = createRawSnippet<[{ type: string | null | undefined }]>((getType) => {
|
||||
const { type } = getType();
|
||||
const displayType = type === 'client' ? 'Cliente' : type === 'provider' ? 'Proveedor' : type === 'both' ? 'Ambos' : 'N/A';
|
||||
const colorClass = type === 'client' ? 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300'
|
||||
: type === 'provider' ? 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300'
|
||||
: type === 'both' ? 'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-300'
|
||||
: 'bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-300';
|
||||
return {
|
||||
render: () => `<span class="inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${colorClass}">${displayType}</span>`
|
||||
};
|
||||
});
|
||||
return renderSnippet(typeSnippet, { type: row.original.client_or_provider });
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "residence_country",
|
||||
header: "País",
|
||||
cell: ({ row }) => {
|
||||
const countrySnippet = createRawSnippet<[{ country: string | null | undefined }]>((getCountry) => {
|
||||
const { country } = getCountry();
|
||||
return {
|
||||
render: () => `<div class="max-w-[120px] truncate">${country || '-'}</div>`
|
||||
};
|
||||
});
|
||||
return renderSnippet(countrySnippet, { country: row.original.residence_country });
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "is_active",
|
||||
header: "Estado",
|
||||
cell: ({ row }) => {
|
||||
const statusSnippet = createRawSnippet<[{ status: number | undefined }]>((getStatus) => {
|
||||
const { status } = getStatus();
|
||||
const isEnabled = status === 1;
|
||||
const statusText = isEnabled ? 'Activo' : 'Inactivo';
|
||||
const colorClass = isEnabled
|
||||
? 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300'
|
||||
: 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300';
|
||||
return {
|
||||
render: () => `<span class="inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${colorClass}">${statusText}</span>`
|
||||
};
|
||||
});
|
||||
return renderSnippet(statusSnippet, { status: row.original.is_active });
|
||||
}
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
cell: ({ row }) => {
|
||||
return renderComponent(DataTableActions, { item: row.original, onSuccess });
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
// Mantener compatibilidad hacia atrás
|
||||
export const columns = createColumns();
|
||||
const text = isActive ? 'Activo' : 'Inactivo';
|
||||
const color = isActive
|
||||
? 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300'
|
||||
: 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300';
|
||||
|
||||
return {
|
||||
render: () => `<span class="px-2 py-0.5 rounded-full text-xs font-medium ${color}">${text}</span>`
|
||||
};
|
||||
});
|
||||
return renderSnippet(snippet, { val: row.original.is_active });
|
||||
}
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
cell: ({ row }) => renderComponent(DataTableActions, { item: row.original, onSuccess })
|
||||
}
|
||||
];
|
||||
}
|
||||
@@ -1,363 +1,453 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { browser } from '$app/environment';
|
||||
import { page } from '$app/stores';
|
||||
import { goto } from "$app/navigation";
|
||||
|
||||
// UI Components
|
||||
// Componentes UI
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import * as Card from "$lib/components/ui/card";
|
||||
import * as Select from "$lib/components/ui/select";
|
||||
import { LoaderCircle, ArrowLeft, Save } from 'lucide-svelte';
|
||||
import * as Tabs from "$lib/components/ui/tabs";
|
||||
import { Switch } from "$lib/components/ui/switch";
|
||||
import { LoaderCircle, ArrowLeft, Save, Building2, MapPin, FileText, Settings } from 'lucide-svelte';
|
||||
|
||||
// API & Stores
|
||||
import { clientsProvidersApi } from "$lib/api/dashboard/a76/clients-providers";
|
||||
import { companyStore } from "$lib/stores/company.svelte";
|
||||
|
||||
// 1. DETECCIÓN DE MODO (CREAR vs EDITAR)
|
||||
// --- CONFIGURACIÓN ---
|
||||
let id = $derived($page.params.id);
|
||||
let isEditing = $derived(!!id);
|
||||
let title = $derived(isEditing ? "Editar Cliente/Proveedor" : "Nuevo Cliente/Proveedor");
|
||||
let title = $derived(isEditing ? "Editar Socio Comercial" : "Nuevo Socio Comercial");
|
||||
|
||||
// Mapa para corregir la visualización del Select
|
||||
const typeLabels: Record<string, string> = {
|
||||
client: "Cliente",
|
||||
provider: "Proveedor",
|
||||
both: "Ambos"
|
||||
};
|
||||
|
||||
// Sincronización de Cookies (Token)
|
||||
onMount(() => {
|
||||
if (browser) {
|
||||
const getCookie = (name: string) => document.cookie.split(`; ${name}=`).pop()?.split(';').shift() || null;
|
||||
const cT = getCookie('access_token');
|
||||
const lT = localStorage.getItem('access_token');
|
||||
if (cT && cT !== lT) localStorage.setItem('access_token', cT);
|
||||
}
|
||||
});
|
||||
// --- ESTADO INICIAL (PLANO) ---
|
||||
const getEmptyForm = () => ({
|
||||
rfc: "",
|
||||
name: "",
|
||||
short_name: "",
|
||||
curp: "",
|
||||
client_or_provider: "client",
|
||||
type_nat_foreign: "N",
|
||||
responsible: "",
|
||||
position: "",
|
||||
is_active: true,
|
||||
is_national_provider: false,
|
||||
|
||||
// Estado inicial del formulario
|
||||
function getEmptyForm() {
|
||||
return {
|
||||
rfc: "", name: "", curp: "", residence_country: "",
|
||||
domicile_fiscal: "", foreign_tax_id: "",
|
||||
client_or_provider: "client", is_active: true,
|
||||
// Dirección
|
||||
street: "", neighborhood: "", city: "", state: "",
|
||||
country: "", zip_code: "",
|
||||
// Programas
|
||||
program_code: "", authorization_date: ""
|
||||
};
|
||||
}
|
||||
|
||||
streets: "",
|
||||
exterior_number: "",
|
||||
interior_number: "",
|
||||
neighborhood: "",
|
||||
municipality: "",
|
||||
city: "",
|
||||
state: "",
|
||||
country: "",
|
||||
postal_code: "",
|
||||
email: "",
|
||||
phone: "",
|
||||
contact: "",
|
||||
|
||||
// Tabla Programas (Programs)
|
||||
program: "",
|
||||
program_number: "",
|
||||
authorization_date_str: "", // String para input date
|
||||
prosec: 0,
|
||||
manufacturer_id: "",
|
||||
tax_id: "",
|
||||
ctpat_svi: "",
|
||||
is_certified_company: "0"
|
||||
});
|
||||
|
||||
let formData = $state(getEmptyForm());
|
||||
let loading = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
|
||||
// --- UTILIDADES DE FECHA ---
|
||||
const intDateToString = (dateInt?: number | null) => {
|
||||
if (!dateInt) return "";
|
||||
const s = dateInt.toString();
|
||||
if (s.length !== 8) return "";
|
||||
return `${s.substring(0, 4)}-${s.substring(4, 6)}-${s.substring(6, 8)}`;
|
||||
};
|
||||
// --- UTILIDADES ---
|
||||
const intDateToString = (d?: number | null) => d ? `${d.toString().substring(0, 4)}-${d.toString().substring(4, 6)}-${d.toString().substring(6, 8)}` : "";
|
||||
const stringDateToInt = (d?: string) => d ? parseInt(d.replace(/-/g, '')) : null;
|
||||
const clean = (v: any) => (typeof v === 'string' && !v.trim() ? null : v);
|
||||
|
||||
const stringDateToInt = (dateStr?: string) => {
|
||||
if (!dateStr) return null;
|
||||
return parseInt(dateStr.replace(/-/g, '')) || null;
|
||||
};
|
||||
|
||||
// Efecto de carga automática
|
||||
// --- CARGA DE DATOS ---
|
||||
$effect(() => {
|
||||
if (id && companyStore.activeCompany?.id) {
|
||||
loadClientById(Number(id));
|
||||
} else {
|
||||
// Si salimos de editar a crear, limpiamos
|
||||
if (!id) {
|
||||
formData = getEmptyForm();
|
||||
error = null;
|
||||
}
|
||||
}
|
||||
if (id && companyStore.activeCompany?.id) loadData(Number(id));
|
||||
else if (!id) formData = getEmptyForm();
|
||||
});
|
||||
|
||||
async function loadClientById(clientId: number) {
|
||||
async function loadData(clientId: number) {
|
||||
if (!companyStore.activeCompany?.id) return;
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
|
||||
try {
|
||||
// Usamos el nuevo endpoint GET /{id} que agregaste al backend
|
||||
const response = await clientsProvidersApi.get(clientId, companyStore.activeCompany.id);
|
||||
const item = (response as any).data || response;
|
||||
const res = await clientsProvidersApi.get(clientId, companyStore.activeCompany.id);
|
||||
const item = (res as any).data || res;
|
||||
|
||||
if (item) {
|
||||
const addr = item.address || {};
|
||||
const prog = item.programs || {};
|
||||
|
||||
// Mapear respuesta anidada -> formulario plano
|
||||
formData = {
|
||||
rfc: item.rfc || "",
|
||||
name: item.name || "",
|
||||
short_name: item.short_name || "",
|
||||
curp: item.curp || "",
|
||||
residence_country: item.residence_country || "",
|
||||
domicile_fiscal: item.domicile_fiscal || "",
|
||||
foreign_tax_id: item.foreign_tax_id || "",
|
||||
client_or_provider: item.client_or_provider || "client",
|
||||
is_active: item.is_active ?? true,
|
||||
|
||||
// Mapeo de dirección
|
||||
street: addr.streets || addr.street || "",
|
||||
type_nat_foreign: item.type_nat_foreign || "N",
|
||||
responsible: item.responsible || "",
|
||||
position: item.position || "",
|
||||
is_active: !!item.is_active,
|
||||
is_national_provider: !!item.is_national_provider,
|
||||
|
||||
streets: addr.streets || "",
|
||||
exterior_number: addr.exterior_number || "",
|
||||
interior_number: addr.interior_number || "",
|
||||
neighborhood: addr.neighborhood || "",
|
||||
municipality: addr.municipality || "",
|
||||
city: addr.city || "",
|
||||
state: addr.state || "",
|
||||
country: addr.country || "",
|
||||
zip_code: addr.postal_code || addr.zip_code || "",
|
||||
|
||||
// Mapeo de programas
|
||||
program_code: prog.program_number || prog.program_code || "",
|
||||
authorization_date: intDateToString(prog.secon_auth_date)
|
||||
postal_code: addr.postal_code || "",
|
||||
email: addr.email || "",
|
||||
phone: addr.phone || "",
|
||||
contact: addr.contact || "",
|
||||
|
||||
program: prog.program || "",
|
||||
program_number: prog.program_number || "",
|
||||
authorization_date_str: intDateToString(prog.secon_auth_date),
|
||||
prosec: prog.prosec || 0,
|
||||
manufacturer_id: prog.manufacturer_id || "",
|
||||
tax_id: prog.tax_id || "",
|
||||
ctpat_svi: prog.ctpat_svi || "",
|
||||
is_certified_company: prog.is_certified_company || "0"
|
||||
};
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error("Error al cargar:", e);
|
||||
error = "No se pudieron cargar los detalles del cliente. Error: " + (e.message || "Desconocido");
|
||||
error = "Error al cargar: " + e.message;
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!companyStore.activeCompany) { error = "No hay compañía seleccionada"; return; }
|
||||
if (!formData.rfc.trim()) { error = "El RFC es obligatorio"; return; }
|
||||
if (!formData.name.trim()) { error = "El nombre es obligatorio"; return; }
|
||||
// --- ENVÍO DE DATOS ---
|
||||
async function handleSubmit() {
|
||||
if (!companyStore.activeCompany) { error = "Selecciona una compañía"; return; }
|
||||
if (!formData.rfc.trim() || !formData.name.trim()) { error = "RFC y Nombre obligatorios"; return; }
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
|
||||
try {
|
||||
// Payloads para backend
|
||||
const addressPayload: any = {
|
||||
street: formData.street || null,
|
||||
streets: formData.street || null,
|
||||
postal_code: formData.zip_code || null,
|
||||
zip_code: formData.zip_code || null,
|
||||
neighborhood: formData.neighborhood || null,
|
||||
city: formData.city || null,
|
||||
state: formData.state || null,
|
||||
country: formData.country || formData.residence_country || null,
|
||||
};
|
||||
|
||||
const programsPayload: any = {
|
||||
program_code: formData.program_code || null,
|
||||
program_number: formData.program_code || null,
|
||||
secon_auth_date: stringDateToInt(formData.authorization_date),
|
||||
};
|
||||
|
||||
const basePayload = {
|
||||
rfc: formData.rfc,
|
||||
name: formData.name,
|
||||
curp: formData.curp || null,
|
||||
residence_country: formData.residence_country || null,
|
||||
domicile_fiscal: formData.domicile_fiscal || null,
|
||||
foreign_tax_id: formData.foreign_tax_id || null,
|
||||
// Reconstruir objeto anidado para el backend
|
||||
const payload = {
|
||||
rfc: clean(formData.rfc),
|
||||
name: clean(formData.name),
|
||||
short_name: clean(formData.short_name),
|
||||
curp: clean(formData.curp),
|
||||
client_or_provider: formData.client_or_provider,
|
||||
type_nat_foreign: clean(formData.type_nat_foreign),
|
||||
responsible: clean(formData.responsible),
|
||||
position: clean(formData.position),
|
||||
is_active: formData.is_active,
|
||||
address: addressPayload,
|
||||
programs: programsPayload
|
||||
is_national_provider: formData.is_national_provider,
|
||||
|
||||
address: {
|
||||
streets: clean(formData.streets),
|
||||
exterior_number: clean(formData.exterior_number),
|
||||
interior_number: clean(formData.interior_number),
|
||||
neighborhood: clean(formData.neighborhood),
|
||||
municipality: clean(formData.municipality),
|
||||
city: clean(formData.city),
|
||||
state: clean(formData.state),
|
||||
country: clean(formData.country),
|
||||
postal_code: clean(formData.postal_code),
|
||||
email: clean(formData.email),
|
||||
phone: clean(formData.phone),
|
||||
contact: clean(formData.contact)
|
||||
},
|
||||
|
||||
programs: {
|
||||
program: clean(formData.program),
|
||||
program_number: clean(formData.program_number),
|
||||
secon_auth_date: stringDateToInt(formData.authorization_date_str),
|
||||
prosec: Number(formData.prosec) || null,
|
||||
manufacturer_id: clean(formData.manufacturer_id),
|
||||
tax_id: clean(formData.tax_id),
|
||||
ctpat_svi: clean(formData.ctpat_svi),
|
||||
is_certified_company: clean(formData.is_certified_company)
|
||||
}
|
||||
};
|
||||
|
||||
const companyId = companyStore.activeCompany.id;
|
||||
let response;
|
||||
const response = isEditing
|
||||
? await clientsProvidersApi.update(Number(id), companyId, payload as any)
|
||||
: await clientsProvidersApi.create(companyId, payload as any);
|
||||
|
||||
if (isEditing) {
|
||||
response = await clientsProvidersApi.update(Number(id), companyId, basePayload as any);
|
||||
} else {
|
||||
response = await clientsProvidersApi.create(companyId, basePayload as any);
|
||||
}
|
||||
|
||||
if (response.error) {
|
||||
if (response.status === 401) {
|
||||
error = 'Sesión expirada.';
|
||||
window.location.reload();
|
||||
} else {
|
||||
error = response.error || "Error al procesar la solicitud";
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (response.error) throw new Error(response.error);
|
||||
|
||||
goto('/dashboard/clients_and_providers');
|
||||
|
||||
} catch (e: any) {
|
||||
console.error("Error:", e);
|
||||
error = e.message || "Error desconocido";
|
||||
console.error(e);
|
||||
error = e.message || "Error al guardar";
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="space-y-6 pb-24">
|
||||
<div class="w-full mx-auto max-w-6xl py-6 px-4 space-y-6 pb-48">
|
||||
<div class="flex items-center gap-4">
|
||||
<Button variant="ghost" size="icon" onclick={() => goto('/dashboard/clients_and_providers')}>
|
||||
<Button variant="outline" size="icon" href="/dashboard/clients_and_providers">
|
||||
<ArrowLeft class="h-4 w-4" />
|
||||
</Button>
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold tracking-tight">{title}</h1>
|
||||
<p class="text-muted-foreground">
|
||||
{isEditing ? "Modifica los datos del registro existente." : "Completa los datos para el nuevo registro."}
|
||||
</p>
|
||||
<h1 class="text-2xl font-bold tracking-tight">{title}</h1>
|
||||
<p class="text-muted-foreground">Gestión integral del catálogo de socios comerciales.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Card.Root>
|
||||
<Card.Header>
|
||||
<Card.Title>Información General</Card.Title>
|
||||
<Card.Description>Los campos marcados con * son obligatorios</Card.Description>
|
||||
</Card.Header>
|
||||
<Card.Content>
|
||||
{#if loading && isEditing && !formData.name}
|
||||
<div class="flex justify-center py-10">
|
||||
<LoaderCircle class="h-8 w-8 animate-spin text-primary" />
|
||||
</div>
|
||||
{:else}
|
||||
<form id="cp-form" onsubmit={handleSubmit} class="space-y-6">
|
||||
{#if error}
|
||||
<div class="rounded-lg border border-destructive bg-destructive/10 p-3 text-sm text-destructive font-medium flex items-center gap-2">
|
||||
<span>🚨</span> {error}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="space-y-4">
|
||||
<h3 class="text-sm font-semibold border-b pb-2">Información Básica</h3>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="space-y-2">
|
||||
<Label for="rfc">RFC *</Label>
|
||||
<Input id="rfc" bind:value={formData.rfc} placeholder="Ej: XAXX010101000" maxlength={13} required disabled={loading} />
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<Label for="client_or_provider">Tipo *</Label>
|
||||
<Select.Root type="single" bind:value={formData.client_or_provider}>
|
||||
<Select.Trigger id="client_or_provider">
|
||||
{typeLabels[formData.client_or_provider] || "Selecciona un tipo"}
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
<Select.Item value="client" label="Cliente">Cliente</Select.Item>
|
||||
<Select.Item value="provider" label="Proveedor">Proveedor</Select.Item>
|
||||
<Select.Item value="both" label="Ambos">Ambos</Select.Item>
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<Label for="name">Nombre / Razón Social *</Label>
|
||||
<Input id="name" bind:value={formData.name} placeholder="Nombre completo" maxlength={256} required disabled={loading} />
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="space-y-2">
|
||||
<Label for="curp">CURP</Label>
|
||||
<Input id="curp" bind:value={formData.curp} placeholder="Opcional" maxlength={18} disabled={loading} />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="residence_country">País de Residencia</Label>
|
||||
<Input id="residence_country" bind:value={formData.residence_country} placeholder="Ej: MEX" maxlength={64} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4">
|
||||
<h3 class="text-sm font-semibold border-b pb-2">Datos Fiscales</h3>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="space-y-2">
|
||||
<Label for="domicile_fiscal">Domicilio Fiscal</Label>
|
||||
<Input id="domicile_fiscal" bind:value={formData.domicile_fiscal} placeholder="Domicilio completo" maxlength={256} disabled={loading} />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="foreign_tax_id">ID Fiscal Extranjero</Label>
|
||||
<Input id="foreign_tax_id" bind:value={formData.foreign_tax_id} placeholder="Tax ID" maxlength={64} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4">
|
||||
<h3 class="text-sm font-semibold border-b pb-2">Dirección Física</h3>
|
||||
|
||||
<div class="space-y-2">
|
||||
<Label for="street">Calle y Número</Label>
|
||||
<Input id="street" bind:value={formData.street} placeholder="Calle..." maxlength={256} disabled={loading} />
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="space-y-2">
|
||||
<Label for="neighborhood">Colonia</Label>
|
||||
<Input id="neighborhood" bind:value={formData.neighborhood} placeholder="Colonia..." maxlength={128} disabled={loading} />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="zip_code">Código Postal</Label>
|
||||
<Input id="zip_code" bind:value={formData.zip_code} placeholder="CP" maxlength={10} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div class="space-y-2">
|
||||
<Label for="city">Ciudad</Label>
|
||||
<Input id="city" bind:value={formData.city} placeholder="Ciudad" maxlength={128} disabled={loading} />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="state">Estado</Label>
|
||||
<Input id="state" bind:value={formData.state} placeholder="Estado" maxlength={128} disabled={loading} />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="country">País</Label>
|
||||
<Input id="country" bind:value={formData.country} placeholder="MEX" maxlength={64} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4">
|
||||
<h3 class="text-sm font-semibold border-b pb-2">Programas de Fomento</h3>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="space-y-2">
|
||||
<Label for="program_code">Nº Programa (IMMEX)</Label>
|
||||
<Input id="program_code" bind:value={formData.program_code} placeholder="Ej: 1234-56" maxlength={32} disabled={loading} />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="authorization_date">Fecha Autorización</Label>
|
||||
<Input id="authorization_date" type="date" bind:value={formData.authorization_date} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{/if}
|
||||
</Card.Content>
|
||||
</Card.Root>
|
||||
</div>
|
||||
|
||||
<div class="fixed bottom-0 right-0 left-0 md:left-64 p-4 border-t bg-background/95 backdrop-blur z-50 flex justify-end gap-4 shadow-lg">
|
||||
<Button type="button" variant="outline" onclick={() => goto('/dashboard/clients_and_providers')} disabled={loading}>
|
||||
Cancelar
|
||||
</Button>
|
||||
|
||||
{#if !isEditing}
|
||||
<Button type="button" variant="ghost" onclick={() => formData = getEmptyForm()} disabled={loading}>
|
||||
Limpiar
|
||||
</Button>
|
||||
{#if error}
|
||||
<div class="p-4 rounded-md bg-destructive/10 text-destructive border border-destructive/20 text-sm font-medium">
|
||||
⚠️ {error}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<Button type="submit" form="cp-form" disabled={loading}>
|
||||
{#if loading}
|
||||
<LoaderCircle class="mr-2 h-4 w-4 animate-spin" />
|
||||
Guardando...
|
||||
{:else}
|
||||
<Save class="mr-2 h-4 w-4" />
|
||||
{isEditing ? "Guardar Cambios" : "Crear Registro"}
|
||||
{/if}
|
||||
</Button>
|
||||
<form onsubmit={(e) => { e.preventDefault(); handleSubmit(); }} class="space-y-6">
|
||||
<Card.Root>
|
||||
<Card.Content class="p-6">
|
||||
<Tabs.Root value="general" class="w-full">
|
||||
|
||||
<div class="min-h-[400px]">
|
||||
|
||||
<Tabs.Content value="general" class="space-y-4 pt-4">
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="grid gap-2">
|
||||
<Label for="rfc">RFC <span class="text-destructive">*</span></Label>
|
||||
<Input id="rfc" bind:value={formData.rfc} placeholder="XAXX010101000" maxlength={13} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="type">Tipo de Relación <span class="text-destructive">*</span></Label>
|
||||
<Select.Root type="single" bind:value={formData.client_or_provider}>
|
||||
<Select.Trigger id="type">
|
||||
{typeLabels[formData.client_or_provider] || "Selecciona un tipo"}
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
<Select.Item value="client" label="Cliente">Cliente</Select.Item>
|
||||
<Select.Item value="provider" label="Proveedor">Proveedor</Select.Item>
|
||||
<Select.Item value="both" label="Ambos">Ambos</Select.Item>
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<div class="md:col-span-3 grid gap-2">
|
||||
<Label for="name">Razón Social <span class="text-destructive">*</span></Label>
|
||||
<Input id="name" bind:value={formData.name} placeholder="Nombre completo" maxlength={256} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="short_name">Nombre Corto</Label>
|
||||
<Input id="short_name" bind:value={formData.short_name} placeholder="Alias" maxlength={10} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="grid gap-2">
|
||||
<Label for="curp">CURP (Opcional)</Label>
|
||||
<Input id="curp" bind:value={formData.curp} maxlength={18} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="type_nat">Tipo Origen</Label>
|
||||
<Select.Root type="single" bind:value={formData.type_nat_foreign}>
|
||||
<Select.Trigger id="type_nat">
|
||||
{formData.type_nat_foreign === 'N' ? 'Nacional' : formData.type_nat_foreign === 'E' ? 'Extranjero' : 'Seleccione'}
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
<Select.Item value="N" label="Nacional">Nacional</Select.Item>
|
||||
<Select.Item value="E" label="Extranjero">Extranjero</Select.Item>
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="grid gap-2">
|
||||
<Label for="responsible">Responsable</Label>
|
||||
<Input id="responsible" bind:value={formData.responsible} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="position">Puesto</Label>
|
||||
<Input id="position" bind:value={formData.position} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
</Tabs.Content>
|
||||
|
||||
<Tabs.Content value="address" class="space-y-4 pt-4">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="grid gap-2">
|
||||
<Label for="street">Calle</Label>
|
||||
<Input id="street" bind:value={formData.streets} maxlength={100} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div class="grid gap-2">
|
||||
<Label for="ext">No. Exterior</Label>
|
||||
<Input id="ext" bind:value={formData.exterior_number} maxlength={20} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="int">No. Interior</Label>
|
||||
<Input id="int" bind:value={formData.interior_number} maxlength={20} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div class="grid gap-2">
|
||||
<Label for="col">Colonia</Label>
|
||||
<Input id="col" bind:value={formData.neighborhood} maxlength={40} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="cp">C.P.</Label>
|
||||
<Input id="cp" bind:value={formData.postal_code} maxlength={15} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="mun">Municipio</Label>
|
||||
<Input id="mun" bind:value={formData.municipality} maxlength={150} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div class="grid gap-2">
|
||||
<Label for="city">Ciudad</Label>
|
||||
<Input id="city" bind:value={formData.city} maxlength={30} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="state">Estado</Label>
|
||||
<Input id="state" bind:value={formData.state} maxlength={30} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="country">País (ISO)</Label>
|
||||
<Input id="country" bind:value={formData.country} placeholder="MEX" maxlength={3} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 pt-4 border-t">
|
||||
<div class="grid gap-2">
|
||||
<Label for="email">Email de Contacto</Label>
|
||||
<Input id="email" type="email" bind:value={formData.email} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="phone">Teléfono</Label>
|
||||
<Input id="phone" bind:value={formData.phone} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
</Tabs.Content>
|
||||
|
||||
<Tabs.Content value="programs" class="space-y-4 pt-4">
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="grid gap-2">
|
||||
<Label for="program">Programa</Label>
|
||||
<Input id="program" bind:value={formData.program} placeholder="IMMEX" maxlength={7} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="program_num">Número de Programa</Label>
|
||||
<Input id="program_num" bind:value={formData.program_number} maxlength={40} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div class="grid gap-2">
|
||||
<Label for="auth_date">Fecha Autorización</Label>
|
||||
<Input id="auth_date" type="date" bind:value={formData.authorization_date_str} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="tax_id">Tax ID (Extranjero)</Label>
|
||||
<Input id="tax_id" bind:value={formData.tax_id} maxlength={30} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="man_id">Manufacturer ID</Label>
|
||||
<Input id="man_id" bind:value={formData.manufacturer_id} maxlength={25} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="grid gap-2">
|
||||
<Label for="ctpat">C-TPAT / SVI</Label>
|
||||
<Input id="ctpat" bind:value={formData.ctpat_svi} maxlength={100} disabled={loading} />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="prosec">PROSEC (Sector)</Label>
|
||||
<Input id="prosec" type="number" bind:value={formData.prosec} disabled={loading} />
|
||||
</div>
|
||||
</div>
|
||||
</Tabs.Content>
|
||||
|
||||
<Tabs.Content value="config" class="space-y-4 pt-4">
|
||||
<div class="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
<div class="flex items-center gap-3 p-4 border rounded-lg bg-card">
|
||||
<Switch id="is_active" bind:checked={formData.is_active} disabled={loading} />
|
||||
<div class="grid gap-0.5">
|
||||
<Label for="is_active">Registro Activo</Label>
|
||||
<p class="text-xs text-muted-foreground">Habilitar o deshabilitar este socio comercial</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-3 p-4 border rounded-lg bg-card">
|
||||
<Switch id="is_national" bind:checked={formData.is_national_provider} disabled={loading} />
|
||||
<div class="grid gap-0.5">
|
||||
<Label for="is_national">Proveedor Nacional</Label>
|
||||
<p class="text-xs text-muted-foreground">Marcar si es un proveedor nacional</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Tabs.Content>
|
||||
</div>
|
||||
|
||||
<Tabs.List class="grid grid-cols-4 fixed bottom-24 left-1/2 -translate-x-1/2 w-[95%] max-w-2xl z-40 shadow-2xl bg-background border p-1 rounded-xl">
|
||||
<Tabs.Trigger value="general" class="flex gap-2 items-center justify-center">
|
||||
<Building2 class="h-4 w-4 hidden sm:block" /> General
|
||||
</Tabs.Trigger>
|
||||
<Tabs.Trigger value="address" class="flex gap-2 items-center justify-center">
|
||||
<MapPin class="h-4 w-4 hidden sm:block" /> Dirección
|
||||
</Tabs.Trigger>
|
||||
<Tabs.Trigger value="programs" class="flex gap-2 items-center justify-center">
|
||||
<FileText class="h-4 w-4 hidden sm:block" /> Programas
|
||||
</Tabs.Trigger>
|
||||
<Tabs.Trigger value="config" class="flex gap-2 items-center justify-center">
|
||||
<Settings class="h-4 w-4 hidden sm:block" /> Config
|
||||
</Tabs.Trigger>
|
||||
</Tabs.List>
|
||||
|
||||
</Tabs.Root>
|
||||
</Card.Content>
|
||||
</Card.Root>
|
||||
|
||||
<div class="fixed bottom-0 right-0 left-0 md:left-64 p-4 border-t bg-background/95 backdrop-blur z-50">
|
||||
<div class="max-w-6xl mx-auto flex justify-end gap-4">
|
||||
<Button type="button" variant="ghost" onclick={() => goto('/dashboard/clients_and_providers')} disabled={loading}>
|
||||
Cancelar
|
||||
</Button>
|
||||
|
||||
{#if !isEditing}
|
||||
<Button type="button" variant="outline" onclick={() => formData = getEmptyForm()} disabled={loading}>
|
||||
Limpiar
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
<Button type="submit" disabled={loading} class="min-w-[140px]">
|
||||
{#if loading}
|
||||
<LoaderCircle class="mr-2 h-4 w-4 animate-spin" />
|
||||
{:else}
|
||||
<Save class="mr-2 h-4 w-4" />
|
||||
{/if}
|
||||
{isEditing ? 'Actualizar' : 'Guardar'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
Reference in New Issue
Block a user