Remove unnecessary console logs and improve code readability across multiple components

This commit is contained in:
2026-02-11 20:37:10 -06:00
parent 703014e967
commit 9d27066da1
12 changed files with 57 additions and 151 deletions

View File

@@ -233,8 +233,7 @@
scafReparInvoices = [];
return;
}
console.log('Fetching assigned invoices for:', formData.manifest_number);
lastFetchAttempt = new Date().toLocaleTimeString();
invoicesLoading = true;
const companyId = companyStore.activeCompany.id;
@@ -251,11 +250,7 @@
allDebugInvoicesCount = allInvoices.length;
// Mark all as selected for visual consistency (since they ARE linked)
allInvoices.forEach((inv) => (inv.is_selected = true));
console.log(
`Loaded ${allInvoices.length} export invoices for manifest ${formData.manifest_number}`
);
allInvoices.forEach((inv) => (inv.is_selected = true));
// Helper to normalize system
const getSystem = (s: string | undefined) => {
@@ -297,13 +292,6 @@
isRepar(inv.invoice_type ?? undefined)
);
console.log('Invoices loaded:', {
total: allInvoices.length,
scaiiExp: scaiiExpInvoices.length,
scaiiRepar: scaiiReparInvoices.length,
scafExp: scafExpInvoices.length,
scafRepar: scafReparInvoices.length
});
} catch (e) {
console.error('Error fetching invoices:', e);
toast.error('Error al cargar facturas');
@@ -313,9 +301,7 @@
}
$effect(() => {
console.log('Active tab changed:', activeTab);
if (activeTab === 'facturas_expo') {
console.log('Triggering fetchInvoiceLists');
fetchInvoiceLists();
}
});
@@ -612,38 +598,27 @@
...scafReparInvoices
];
const updatePromises = [];
console.log('Starting batch update for invoices:', allTrackedInvoices.length);
const updatePromises = [];
for (const inv of allTrackedInvoices) {
const currentLink = inv.compliance_mx?.manifest_number;
const shouldLink = inv.is_selected;
console.log(
`Invoice ${inv.invoice_number}: current=${currentLink}, selected=${shouldLink}, target=${formData.manifest_number}`
);
// Case 1: Needs Linking (Selected but not currently linked to this manifest)
if (shouldLink && currentLink !== formData.manifest_number) {
console.log(`Linking invoice ${inv.id} to ${formData.manifest_number}`);
if (shouldLink && currentLink !== formData.manifest_number) {
updatePromises.push(
manifestApi.updateInvoiceCompliance(inv.id, companyId, formData.manifest_number)
);
}
// Case 2: Needs Unlinking (Not Selected but currently linked to this manifest)
else if (!shouldLink && currentLink === formData.manifest_number) {
console.log(`Unlinking invoice ${inv.id}`);
else if (!shouldLink && currentLink === formData.manifest_number) {
updatePromises.push(manifestApi.updateInvoiceCompliance(inv.id, companyId, null));
}
}
if (updatePromises.length > 0) {
console.log('Sending update promises:', updatePromises.length);
if (updatePromises.length > 0) {
await Promise.all(updatePromises);
toast.success(`${updatePromises.length} facturas actualizadas`);
} else {
console.log('No invoices needed update');
toast.success(`${updatePromises.length} facturas actualizadas`);
}
}
@@ -1138,7 +1113,7 @@
<Label class="text-xs font-bold uppercase">Estatus Vehículo</Label>
<Select.Root
type="single"
bind:value={formData.vehicle_status}
value={formData.vehicle_status}
onValueChange={(v) => (formData.vehicle_status = v)}
>
<Select.Trigger class="h-9 px-3 text-xs">

View File

@@ -39,12 +39,10 @@
});
async function loadCurrencies() {
loading = true;
console.log("CurrencySelectorDialog: loading currencies (public)...");
loading = true;
try {
// FIX: Usar API pública, sin company_id
const response = await currencyTypesApi.list(1, 100);
console.log("Respuesta Monedas Public FULL:", response);
const response = await currencyTypesApi.list(1, 100);
if (response.error) {
console.error("CurrencySelectorDialog Error:", response.error);
@@ -54,8 +52,7 @@
if (response.data?.items) {
items = response.data.items;
loaded = true;
console.log("CurrencySelectorDialog: loaded items", items.length);
loaded = true;
} else {
console.warn("No se encontraron monedas (public):", response);
toast.error("No se encontraron monedas");

View File

@@ -251,22 +251,14 @@
delete commonData.sector;
delete commonData.fraction_type;
delete commonData.origin_country;
}
console.log("Submitting Part Data:", {
isEdit,
partId,
commonData
});
}
if (isEdit && partId) {
// TODO: Verify partId is number/string as expected
const res = await partsApi.update(Number(partId), commonData, activeCompanyId);
console.log("Update Response:", res);
const res = await partsApi.update(Number(partId), commonData, activeCompanyId);
if (res.error) throw new Error(res.error);
} else {
const result = await partsApi.create({ ...commonData, company_id: activeCompanyId }, activeCompanyId);
console.log("Create Response:", result);
const result = await partsApi.create({ ...commonData, company_id: activeCompanyId }, activeCompanyId);
if (result.error) { error = result.error; return; }
}
toast.success(isEdit ? "Parte actualizada" : "Parte creada");
@@ -421,7 +413,7 @@
<Label for="fa_weight">Peso Unitario</Label>
<div class="flex gap-2">
<Input type="number" step="0.0001" id="fa_weight" bind:value={formData.unit_weight} placeholder="0.0000" />
<Select.Root type="single" bind:value={formData.weight_type}>
<Select.Root type="single" value={formData.weight_type} onValueChange={(v) => formData.weight_type = v}>
<Select.Trigger class="w-[85px]">{formData.weight_type}</Select.Trigger>
<Select.Content>
<Select.Item value="KG">KG</Select.Item>
@@ -640,7 +632,7 @@
<Label for="unit_weight">Peso Unitario</Label>
<div class="flex gap-2">
<Input type="number" step="0.0001" id="unit_weight" bind:value={formData.unit_weight} placeholder="0.0000" class="bg-background"/>
<Select.Root type="single" bind:value={formData.weight_type}>
<Select.Root type="single" value={formData.weight_type} onValueChange={(v) => formData.weight_type = v}>
<Select.Trigger class="w-[90px] bg-background">{formData.weight_type}</Select.Trigger>
<Select.Content>
<Select.Item value="KG">KG</Select.Item>

View File

@@ -42,8 +42,6 @@
path_pdf: "",
path_xml: "",
// Compliance MX fields
pedimento: "",
pedimento_code: "",
remesa: null as number | null,
aduana: "",
customs_broker_id: "",
@@ -64,7 +62,7 @@
freight: null as number | null,
insurance: null as number | null,
iva_mn: null as number | null,
iva_factor: null as number | null,
iva_factor: null as string | null,
total_quantity: null as number | null,
gross_weight: null as number | null,
net_weight: null as number | null,
@@ -95,15 +93,13 @@
cfdi_uuid: item.cfdi_uuid || "",
path_pdf: item.path_pdf || "",
path_xml: item.path_xml || "",
pedimento: item.compliance_mx?.pedimento || "",
pedimento_code: item.compliance_mx?.pedimento_code || "",
remesa: item.compliance_mx?.remesa || null,
aduana: item.compliance_mx?.aduana || "",
customs_broker_id: item.compliance_mx?.customs_broker_id || "",
provider_id: item.compliance_mx?.provider_id || "",
sold_to_id: item.compliance_mx?.sold_to_id || "",
shipped_to_id: item.compliance_mx?.shipped_to_id || "",
shipped_by_id: item.compliance_mx?.shipped_by_id || "",
customs_broker_id: item.compliance_mx?.customs_broker_id?.toString() || "",
provider_id: item.compliance_mx?.provider_id?.toString() || "",
sold_to_id: item.compliance_mx?.sold_to_id?.toString() || "",
shipped_to_id: item.compliance_mx?.shipped_to_id?.toString() || "",
shipped_by_id: item.compliance_mx?.shipped_by_id?.toString() || "",
is_mixed: item.compliance_mx?.is_mixed || false,
waste_type: item.compliance_mx?.waste_type || "",
appendix_17: item.compliance_mx?.appendix_17 || null,
@@ -145,8 +141,6 @@
cfdi_uuid: "",
path_pdf: "",
path_xml: "",
pedimento: "",
pedimento_code: "",
remesa: null,
aduana: "",
customs_broker_id: "",
@@ -198,6 +192,7 @@
let response;
if (isEditing && item) {
const payload: UpdateInvoiceData = {
id: item.id,
operation_type: formData.operation_type,
invoice_type: formData.invoice_type || null,
invoice_number: formData.invoice_number || null,
@@ -213,18 +208,16 @@
path_pdf: formData.path_pdf || null,
path_xml: formData.path_xml || null,
compliance_mx: {
pedimento: formData.pedimento || null,
pedimento_code: formData.pedimento_code || null,
remesa: formData.remesa,
aduana: formData.aduana || null,
customs_broker_id: formData.customs_broker_id || null,
provider_id: formData.provider_id || null,
sold_to_id: formData.sold_to_id || null,
shipped_to_id: formData.shipped_to_id || null,
shipped_by_id: formData.shipped_by_id || null,
customs_broker_id: formData.customs_broker_id ? parseInt(formData.customs_broker_id) : null,
provider_id: formData.provider_id ? parseInt(formData.provider_id) : null,
sold_to_id: formData.sold_to_id ? parseInt(formData.sold_to_id) : null,
shipped_to_id: formData.shipped_to_id ? parseInt(formData.shipped_to_id) : null,
shipped_by_id: formData.shipped_by_id ? parseInt(formData.shipped_by_id) : null,
is_mixed: formData.is_mixed,
waste_type: formData.waste_type || null,
appendix_17: formData.appendix_17,
appendix_17: formData.appendix_17 || null,
edocument: formData.edocument || null
},
financials: {
@@ -245,10 +238,12 @@
};
response = await invoicesApi.update(item.id, companyStore.activeCompany.id, payload);
} else {
const payload: CreateInvoiceData = {
const payload: CreateInvoiceData = {
system: "a76",
document_type: "invoice",
operation_type: formData.operation_type,
invoice_type: formData.invoice_type || null,
invoice_number: formData.invoice_number || null,
invoice_type: formData.invoice_type,
invoice_number: formData.invoice_number,
project_number: formData.project_number || null,
purchase_order: formData.purchase_order || null,
related_doc_id: formData.related_doc_id,
@@ -261,18 +256,16 @@
path_pdf: formData.path_pdf || null,
path_xml: formData.path_xml || null,
compliance_mx: {
pedimento: formData.pedimento || null,
pedimento_code: formData.pedimento_code || null,
remesa: formData.remesa,
aduana: formData.aduana || null,
customs_broker_id: formData.customs_broker_id || null,
provider_id: formData.provider_id || null,
sold_to_id: formData.sold_to_id || null,
shipped_to_id: formData.shipped_to_id || null,
shipped_by_id: formData.shipped_by_id || null,
customs_broker_id: formData.customs_broker_id ? parseInt(formData.customs_broker_id) : null,
provider_id: formData.provider_id ? parseInt(formData.provider_id) : null,
sold_to_id: formData.sold_to_id ? parseInt(formData.sold_to_id) : null,
shipped_to_id: formData.shipped_to_id ? parseInt(formData.shipped_to_id) : null,
shipped_by_id: formData.shipped_by_id ? parseInt(formData.shipped_by_id) : null,
is_mixed: formData.is_mixed,
waste_type: formData.waste_type || null,
appendix_17: formData.appendix_17,
appendix_17: formData.appendix_17 || null,
edocument: formData.edocument || null
},
financials: {
@@ -307,8 +300,7 @@
: JSON.stringify(response.error);
if (errorStr.includes('No existe un Tipo de Cambio registrado') || errorStr.includes('financials.exchange_rate')) {
// Interceptar error de tipo de cambio
console.log("Interceptor: Exchange rate missing error caught (Invoice).");
// Interceptar error de tipo de cambio
error = null;
const dateMatch = errorStr.match(/(\d{4}-\d{2}-\d{2})/);
@@ -510,24 +502,6 @@
<!-- Compliance Tab -->
<Tabs.Content value="compliance" class="space-y-4">
<div class="grid grid-cols-2 gap-4">
<div class="space-y-2">
<Label for="pedimento">Pedimento</Label>
<Input
id="pedimento"
bind:value={formData.pedimento}
placeholder="Número de pedimento"
/>
</div>
<div class="space-y-2">
<Label for="pedimento_code">Código de Pedimento</Label>
<Input
id="pedimento_code"
bind:value={formData.pedimento_code}
placeholder="R1, K1, etc."
/>
</div>
<div class="space-y-2">
<Label for="remesa">Remesa</Label>
<Input

View File

@@ -27,8 +27,6 @@
});
if (response.ok) {
const data = await response.json();
console.log('Countries data received:', data);
console.log('First country sample:', data[0]);
if (Array.isArray(data)) {
countries = data;
} else if (data.items && Array.isArray(data.items)) {
@@ -37,8 +35,7 @@
console.error('Unexpected data format:', data);
countries = [];
}
filteredCountries = countries;
console.log('Total countries loaded:', countries.length);
filteredCountries = countries;
} else {
error = `Error: ${response.status} - ${response.statusText}`;
console.error('Error response:', await response.text());

View File

@@ -47,8 +47,7 @@
});
if (response.ok) {
const data = await response.json();
console.log('Tariff fractions data received:', data);
const data = await response.json();
if (data.items && Array.isArray(data.items)) {
if (append) {
@@ -58,8 +57,7 @@
}
currentPage = data.page;
totalPages = data.pages;
hasMore = currentPage < totalPages;
console.log(`Loaded page ${currentPage}/${totalPages}, total items: ${fractions.length}`);
hasMore = currentPage < totalPages;
} else {
console.error('Unexpected data format:', data);
if (!append) fractions = [];

View File

@@ -27,8 +27,7 @@
credentials: 'include'
});
if (response.ok) {
const data = await response.json();
console.log('Units data received:', data);
const data = await response.json();
// El backend puede devolver { items: [...] } o directamente un array
if (Array.isArray(data)) {
units = data;

View File

@@ -100,15 +100,6 @@
// Función para cargar información
console.log('Cargar información');
}
$effect(() => {
console.log('OthersTabForm props:', {
invoiceType,
operationType,
isMixed: formData.is_mixed,
rule: formData.rule_3121_parties_ii
});
});
</script>
{#if invoiceType !== 'MEX'}