Merge branch 'development' of https://git.aduanasoft.com/ADUANASOFT/anexo76 into feature/partePais_BOM
This commit is contained in:
@@ -1,64 +1,84 @@
|
||||
import type { PaginatedResponse } from '$lib/types';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
/** Contexto de uso: Fixed Asset (activo fijo) o inventario */
|
||||
export type LocationSystem = 'fixed_asset' | 'inventory';
|
||||
|
||||
export interface Location {
|
||||
id: number;
|
||||
location_code: string;
|
||||
location_description: string | null;
|
||||
company_id: number;
|
||||
tenant_id: number;
|
||||
clave_localizacion: string;
|
||||
localizacion: string | null;
|
||||
system: LocationSystem;
|
||||
}
|
||||
|
||||
export interface LocationCreate {
|
||||
location_code: string;
|
||||
location_description?: string | null;
|
||||
clave_localizacion: string;
|
||||
localizacion?: string | null;
|
||||
system: LocationSystem;
|
||||
/** Used when system === 'fixed_asset' */
|
||||
department?: string | null;
|
||||
responsible?: string | null;
|
||||
observations?: string | null;
|
||||
}
|
||||
|
||||
export interface LocationUpdate {
|
||||
location_description?: string | null;
|
||||
clave_localizacion?: string;
|
||||
localizacion?: string | null;
|
||||
system?: LocationSystem;
|
||||
}
|
||||
|
||||
export interface LocationListResponse extends PaginatedResponse {
|
||||
export interface LocationListResponse {
|
||||
items: Location[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
}
|
||||
|
||||
export interface LocationFilters {
|
||||
location_code?: string;
|
||||
location_description?: string;
|
||||
clave_localizacion?: string;
|
||||
localizacion?: string;
|
||||
system?: LocationSystem;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
}
|
||||
|
||||
import { portsApi, PortType } from './ports';
|
||||
const BASE_URL = '/v1/a76/locations';
|
||||
|
||||
function buildQuery(companyId: number, params?: LocationFilters): string {
|
||||
const search = new URLSearchParams();
|
||||
search.set('company_id', String(companyId));
|
||||
if (params?.page != null) search.set('page', String(params.page));
|
||||
if (params?.page_size != null) search.set('page_size', String(params.page_size));
|
||||
if (params?.clave_localizacion) search.set('clave_localizacion', params.clave_localizacion);
|
||||
if (params?.localizacion) search.set('localizacion', params.localizacion);
|
||||
if (params?.system) search.set('system', params.system);
|
||||
return search.toString();
|
||||
}
|
||||
|
||||
export async function getLocations(
|
||||
companyId: number,
|
||||
filters?: LocationFilters
|
||||
): Promise<LocationListResponse> {
|
||||
const res = await portsApi.list(companyId, filters || {});
|
||||
return (res.data || res) as unknown as LocationListResponse;
|
||||
const q = buildQuery(companyId, filters);
|
||||
const res = await api.get<LocationListResponse>(`${BASE_URL}/?${q}`);
|
||||
return (res.data ?? res) as LocationListResponse;
|
||||
}
|
||||
|
||||
export async function getLocation(
|
||||
locationId: number,
|
||||
companyId: number
|
||||
): Promise<Location> {
|
||||
const res = await portsApi.get(locationId, companyId);
|
||||
return (res.data || res) as unknown as Location;
|
||||
const q = new URLSearchParams({ company_id: String(companyId) });
|
||||
const res = await api.get<Location>(`${BASE_URL}/${locationId}?${q}`);
|
||||
return (res.data ?? res) as Location;
|
||||
}
|
||||
|
||||
export async function createLocation(
|
||||
data: LocationCreate,
|
||||
companyId: number
|
||||
): Promise<Location> {
|
||||
const res = await portsApi.create({
|
||||
port_code: data.location_code,
|
||||
location_code: data.location_code,
|
||||
description: null,
|
||||
location_description: data.location_description || null,
|
||||
port_type: PortType.ENTRY
|
||||
}, companyId);
|
||||
return (res.data || res) as unknown as Location;
|
||||
const q = new URLSearchParams({ company_id: String(companyId) });
|
||||
const res = await api.post<Location>(`${BASE_URL}/?${q}`, data);
|
||||
return (res.data ?? res) as Location;
|
||||
}
|
||||
|
||||
export async function updateLocation(
|
||||
@@ -66,15 +86,15 @@ export async function updateLocation(
|
||||
data: LocationUpdate,
|
||||
companyId: number
|
||||
): Promise<Location> {
|
||||
const res = await portsApi.update(locationId, {
|
||||
location_description: data.location_description
|
||||
}, companyId);
|
||||
return (res.data || res) as unknown as Location;
|
||||
const q = new URLSearchParams({ company_id: String(companyId) });
|
||||
const res = await api.put<Location>(`${BASE_URL}/${locationId}/?${q}`, data);
|
||||
return (res.data ?? res) as Location;
|
||||
}
|
||||
|
||||
export async function deleteLocation(
|
||||
locationId: number,
|
||||
companyId: number
|
||||
): Promise<void> {
|
||||
await portsApi.delete(locationId, companyId);
|
||||
}
|
||||
const q = new URLSearchParams({ company_id: String(companyId) });
|
||||
await api.delete(`${BASE_URL}/${locationId}?${q}`);
|
||||
}
|
||||
|
||||
@@ -491,5 +491,29 @@ export const invoicesApi = {
|
||||
});
|
||||
return api.delete(`/v1/a76/invoices/${invoiceId}/collections/${collectionId}/?${params.toString()}`);
|
||||
}
|
||||
},
|
||||
|
||||
processInvoice: (invoiceId: number, companyId: number) => {
|
||||
const params = new URLSearchParams({
|
||||
company_id: companyId.toString()
|
||||
});
|
||||
return api.post<{ task_id: string }>(
|
||||
`/v1/a76/invoices/${invoiceId}/process?${params.toString()}`,
|
||||
{}
|
||||
);
|
||||
},
|
||||
|
||||
getProcessStatus: (taskId: string) => {
|
||||
return api.get<{
|
||||
state: 'PROCESSING' | 'SUCCESS' | 'FAILURE';
|
||||
info?: { current: number; status: string };
|
||||
result?: {
|
||||
status: 'success' | 'validation_error' | 'error';
|
||||
invoice_id?: number;
|
||||
message?: string;
|
||||
errors?: Array<{ field: string; message: string; code?: string; solution?: string[] }>;
|
||||
sql_errors?: Array<{ consecutive: number; error: string }>;
|
||||
};
|
||||
}>(`/v1/a76/invoices/process/${taskId}/status`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -156,8 +156,12 @@ export interface Item {
|
||||
// Permits
|
||||
permit_number?: string;
|
||||
page_line?: string;
|
||||
has_fda_code?: boolean;
|
||||
fda_key?: string;
|
||||
fcc_key?: string;
|
||||
has_certificate?: boolean;
|
||||
certificate_number?: string;
|
||||
certificate_end_date?: string;
|
||||
octave_permit?: string;
|
||||
|
||||
// Flags
|
||||
@@ -168,8 +172,14 @@ export interface Item {
|
||||
|
||||
// Payment
|
||||
payment_method?: string;
|
||||
igi_payment_method?: string;
|
||||
igi_amount?: number;
|
||||
|
||||
// Export valuation (Met Valor, Valor Det., Motivo De Uso)
|
||||
valuation_method?: string;
|
||||
valuation_determined_value?: number;
|
||||
valuation_reason?: string;
|
||||
|
||||
// Additional notes
|
||||
wildcard_field?: string;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user