Se normalizo la tabla de partes para anexo 76 y 24, ademas se parametrizo el formulario

This commit is contained in:
2026-01-08 15:39:40 -06:00
parent cddd64d730
commit 9c2715e8f0
12 changed files with 1244 additions and 961 deletions

View File

@@ -1,9 +1,57 @@
import { api } from '$lib/api';
import type { ApiResponse } from '$lib/api';
export interface FaData {
origin_country?: string | null;
sector?: string | null;
fraction_type?: string | null;
}
export interface InvData {
part_type?: string | null;
material_type?: string | null;
reference_number?: string | null;
flex_reference_number?: string | null;
equivalent_uom?: string | null;
conversion_factor?: number | null;
stock_uom?: string | null;
alternate_uom?: string | null;
conversion_uom?: string | null;
added_value?: number | null;
added_value_type?: string | null;
assigned_client?: string | null;
supplier_code?: string | null;
is_textile?: string | null;
bom_version?: number | null;
is_repair?: string | null;
is_hazardous?: string | null;
emergency_number?: string | null;
danger_class?: string | null;
packaging_group?: string | null;
width?: string | null;
thickness?: string | null;
specification?: string | null;
total_value?: number | null;
direct_labor?: number | null;
general_expenses?: number | null;
total_expenses?: number | null;
depreciation?: number | null;
tooling?: number | null;
material_consumed?: number | null;
profit?: number | null;
us_fraction_alt?: string | null;
ca_fraction?: string | null;
ad_valorem_us?: number | null;
nafta_result?: string | null;
nafta_percentage?: number | null;
dta?: string | null;
dtb?: string | null;
dtg?: string | null;
}
export interface Part {
id: number;
// Llaves foráneas y IDs
tenant_id: number;
company_id: number;
client_id: number;
@@ -11,99 +59,76 @@ export interface Part {
// Identificación
part_number: string;
commercial_part_number: string | null;
part_class: string | null;
material_type?: string | null;
// Descripciones
// Descripciones y Clase
description_spanish: string | null;
description_english: string | null;
part_class: string | null;
unit_of_measure: string | null;
// Físico y Origen
unit_of_measure: string;
alternate_unit_measure: string | null;
country_of_origin: string;
// Costos y Pesos
unit_cost: number | null;
currency_key: string | null;
currency_type: string | null;
unit_weight: number | null;
weight_type: string | null;
part_photo: string | null;
// Clasificación Arancelaria
// Regulatorio
fraction: string | null;
us_fraction: string | null;
// Costos y Valores
unit_cost: number | null;
currency_key: string | null; // currency_type en DB a veces es redundante, usamos key
added_value: number | null;
// Regulatorio y Proveedores
supplier: string | null;
fda_key: string | null;
fcc_key: string | null;
eccn: string | null;
license_code: string | null;
eccn: string | null;
export_code: string | null;
exclusion_symbol: string | null;
// Estado
// Estado y Media
is_active: boolean;
created_at?: string;
updated_at?: string;
part_photo: string | null;
created_at: string;
updated_at: string;
fa_data?: FaData | null;
inv_data?: InvData | null;
}
export interface PartCreate {
company_id: number;
client_id: number;
part_number: string;
// Opcionales
description_spanish?: string | null;
description_english?: string | null;
commercial_part_number?: string | null;
part_class?: string | null;
material_type?: string | null;
unit_of_measure: string;
alternate_unit_measure?: string | null;
country_of_origin?: string;
unit_weight?: number | null;
weight_type?: string | null;
fraction?: string | null;
us_fraction?: string | null;
unit_cost?: number | null;
currency_key?: string | null;
added_value?: number | null;
supplier?: string | null;
fda_key?: string | null;
fcc_key?: string | null;
eccn?: string | null;
license_code?: string | null;
export_code?: string | null;
exclusion_symbol?: string | null;
part_photo?: string | null;
is_active?: boolean;
export interface PartCreate extends Omit<Part, 'id' | 'tenant_id' | 'created_at' | 'updated_at'> {
}
export interface PartUpdate extends Partial<PartCreate> {}
export interface PartListResponse {
items: Part[];
total: number;
page: number;
page_size: number;
pages: number;
}
export const partsApi = {
list: (params: { company_id: number; page?: number; page_size?: number; q?: string }) => {
list: (params: {
company_id: number;
page?: number;
page_size?: number;
q?: string
}) => {
const { company_id, page = 1, page_size = 50, q = '' } = params;
const skip = (page - 1) * page_size;
return api.get<PartListResponse>(
`/v1/a76/parts/?company_id=${company_id}&skip=${skip}&limit=${page_size}&description=${q}`
);
const query = new URLSearchParams({
company_id: company_id.toString(),
skip: skip.toString(),
limit: page_size.toString(),
description: q
});
return api.get<PartListResponse>(`/v1/a76/parts/?${query.toString()}`);
},
get: (id: number, company_id: number) => {
@@ -118,6 +143,7 @@ export const partsApi = {
return api.put<Part>(`/v1/a76/parts/${id}?company_id=${company_id}`, data);
},
delete: (id: number, company_id: number) => {
return api.delete<void>(`/v1/a76/parts/${id}?company_id=${company_id}`);
}