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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -100,15 +100,6 @@
// Función para cargar información // Función para cargar información
console.log('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> </script>
{#if invoiceType !== 'MEX'} {#if invoiceType !== 'MEX'}

View File

@@ -85,8 +85,6 @@
try { try {
const response = await permissionsAPI.list(); const response = await permissionsAPI.list();
allPermissions = response.items || []; allPermissions = response.items || [];
console.log('Total permissions loaded:', allPermissions.length);
console.log('Unique permission IDs:', new Set(allPermissions.map(p => p.id)).size);
if (selectedRole) { if (selectedRole) {
updateAvailablePermissions(); updateAvailablePermissions();
} }
@@ -118,17 +116,12 @@
const assignedIds = rolePermissions.map((rp) => rp.permission_id); const assignedIds = rolePermissions.map((rp) => rp.permission_id);
availablePermissions = allPermissions.filter((p) => !assignedIds.includes(p.id)); availablePermissions = allPermissions.filter((p) => !assignedIds.includes(p.id));
console.log('Available permissions:', availablePermissions.length);
console.log('Unique available IDs:', new Set(availablePermissions.map(p => p.id)).size);
updatePermissionsByModule(); updatePermissionsByModule();
} }
function updatePermissionsByModule() { function updatePermissionsByModule() {
const grouped = new Map<string, Permission[]>(); const grouped = new Map<string, Permission[]>();
console.log('Grouping permissions:', availablePermissions.length);
// Filtrar por búsqueda // Filtrar por búsqueda
const filtered = availablePermissions.filter((p) => { const filtered = availablePermissions.filter((p) => {
if (!permissionSearchQuery.trim()) return true; if (!permissionSearchQuery.trim()) return true;
@@ -147,8 +140,6 @@
grouped.get(p.module)!.push(p); grouped.get(p.module)!.push(p);
}); });
console.log('Grouped by module:', Array.from(grouped.entries()).map(([k, v]) => `${k}: ${v.length}`));
permissionsByModule = grouped; permissionsByModule = grouped;
} }

View File

@@ -115,13 +115,10 @@
const currentId = $page.params.id; const currentId = $page.params.id;
const companyId = companyStore.activeCompany?.id; const companyId = companyStore.activeCompany?.id;
console.log('DEBUG: Effect triggered', { currentId, companyId });
if (currentId && companyId) { if (currentId && companyId) {
console.log('DEBUG: Calling loadDoda with', currentId);
loadDoda(Number(currentId)); loadDoda(Number(currentId));
} else if (!currentId) { } else if (!currentId) {
console.log('DEBUG: No ID, resetting form');
formData = getEmptyForm(); formData = getEmptyForm();
error = null; error = null;
} }
@@ -131,15 +128,8 @@
loading = true; loading = true;
try { try {
const companyId = companyStore.activeCompany?.id; const companyId = companyStore.activeCompany?.id;
console.log('DEBUG: loadDoda executing', { dodaId, companyId });
if (!companyId) {
console.error('DEBUG: No company ID available in loadDoda');
return;
}
const data = await getDoda(dodaId, companyId); const data = await getDoda(dodaId, companyId);
console.log('DEBUG: getDoda response', data);
if (data) { if (data) {
formData = { formData = {

View File

@@ -183,6 +183,7 @@
cantidad_guias_embarque: null, cantidad_guias_embarque: null,
destino_origen: '', destino_origen: '',
puerto_entrada: '', puerto_entrada: '',
vehicle_data: '',
fue_revisado_equipo: false, fue_revisado_equipo: false,
sub_division: false, sub_division: false,
funge_como_cd: false, funge_como_cd: false,
@@ -191,7 +192,16 @@
semaforo_verde_aduana_mexicana: false, semaforo_verde_aduana_mexicana: false,
semaforo_verde_aduana_americana: false, semaforo_verde_aduana_americana: false,
semaforo_rojo_aduana_mexicana: false, semaforo_rojo_aduana_mexicana: false,
semaforo_rojo_aduana_americana: false semaforo_rojo_aduana_americana: false,
// Export fields
is_mixed: false,
reason_export: '1',
purchase_order: '',
payment_terms: '',
handling_fees: 0,
cfdi_uuid: '',
path_pdf: '',
path_xml: ''
}; };
function ensureItemsFormData(initial?: any) { function ensureItemsFormData(initial?: any) {

View File

@@ -86,14 +86,6 @@
function handleRowClick(pedimento: Pedimento) { function handleRowClick(pedimento: Pedimento) {
// Toggle: si ya está seleccionado, deseleccionar; si no, seleccionar // Toggle: si ya está seleccionado, deseleccionar; si no, seleccionar
selectedId = selectedId === pedimento.id ? null : pedimento.id; selectedId = selectedId === pedimento.id ? null : pedimento.id;
console.log(
'🔘 Row clicked, pedimento.id:',
pedimento.id,
'selectedId:',
selectedId,
'hasSelection:',
hasSelection
);
} }
function handleEditSelected() { function handleEditSelected() {