fix(invoices): simplify operation type handling in invoice payload and server load

This commit is contained in:
Galindo97
2026-01-23 11:44:13 -06:00
parent 1f01d926c2
commit 123310badd
3 changed files with 5 additions and 15 deletions

View File

@@ -110,9 +110,7 @@ function buildInvoicePayload(formData: FormDataSet): CreateInvoiceData | UpdateI
const payload: any = {
// Datos generales desde InvoiceTopFieldsFormData
system: 'fixed_asset',
operation_type: InvoiceTopFieldsFormData?.operation_type !== null && InvoiceTopFieldsFormData?.operation_type !== undefined
? (InvoiceTopFieldsFormData.operation_type === 1 ? 'exp' : 'imp') as OperationType
: undefined,
operation_type: InvoiceTopFieldsFormData?.operation_type || undefined,
invoice_type: InvoiceTopFieldsFormData?.invoice_type || undefined,
document_type: generalFormData?.document_type || undefined,
invoice_number: InvoiceTopFieldsFormData?.invoice_number || undefined,

View File

@@ -427,11 +427,6 @@
function handleCreateClick() {
const params = new URLSearchParams(window.location.search);
const operationType = params.get('operation_type');
if (operationType) {
const operationTypeNumber = operationType === 'exp' ? 1 : 2;
params.set('operation_type', operationTypeNumber.toString());
}
const queryString = params.toString();
const url = queryString

View File

@@ -20,13 +20,10 @@ export const load: PageServerLoad = async ({ params, cookies, fetch, url }) => {
const operationTypeParam = url.searchParams.get('operation_type');
const invoiceTypeParam = url.searchParams.get('invoice_type');
// Parsear operation_type de forma segura
let parsedOperationType: number | null = null;
if (operationTypeParam) {
const parsed = parseInt(operationTypeParam, 10);
if (!isNaN(parsed)) {
parsedOperationType = parsed;
}
// Validar que operation_type sea 'exp' o 'imp'
let parsedOperationType: string | null = null;
if (operationTypeParam && (operationTypeParam === 'exp' || operationTypeParam === 'imp')) {
parsedOperationType = operationTypeParam;
}
// Cargar datos de referencia necesarios