myio-js-library 0.1.41 → 0.1.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -6902,7 +6902,7 @@ function attachFilterOrderingModal(props) {
6902
6902
  }
6903
6903
 
6904
6904
  // src/components/premium-modals/report-all/AllReportModal.ts
6905
- var AllReportModal = class {
6905
+ var AllReportModal = class _AllReportModal {
6906
6906
  constructor(params) {
6907
6907
  this.params = params;
6908
6908
  this.authClient = new AuthClient({
@@ -6910,6 +6910,15 @@ var AllReportModal = class {
6910
6910
  clientSecret: params.api.clientSecret,
6911
6911
  base: params.api.dataApiBaseUrl
6912
6912
  });
6913
+ this.debugLog("\u{1F680} AllReportModal initialized", {
6914
+ customerId: params.customerId,
6915
+ itemsListLength: params.itemsList?.length || 0,
6916
+ itemsList: params.itemsList,
6917
+ apiConfig: {
6918
+ hasIngestionToken: !!params.api.ingestionToken,
6919
+ dataApiBaseUrl: params.api.dataApiBaseUrl
6920
+ }
6921
+ });
6913
6922
  }
6914
6923
  modal;
6915
6924
  authClient;
@@ -6926,6 +6935,14 @@ var AllReportModal = class {
6926
6935
  filterModal = null;
6927
6936
  selectedStoreIds = /* @__PURE__ */ new Set();
6928
6937
  currentSortMode = "CONSUMPTION_DESC";
6938
+ // Debug logging flag - can be enabled globally
6939
+ static DEBUG_ENABLED = globalThis.MYIO_DEBUG_ALLREPORT || true;
6940
+ // Debug logging helper
6941
+ debugLog(message, data) {
6942
+ if (_AllReportModal.DEBUG_ENABLED) {
6943
+ console.log(`[AllReportModal DEBUG] ${message}`, data || "");
6944
+ }
6945
+ }
6929
6946
  // Helper: normalize identifiers (upper, strip spaces and non-alphanum)
6930
6947
  normalizeId(v) {
6931
6948
  return (v || "").toString().normalize("NFKC").toUpperCase().replace(/\s+/g, "").replace(/[^A-Z0-9]/g, "");
@@ -7059,6 +7076,7 @@ var AllReportModal = class {
7059
7076
  }
7060
7077
  async loadData() {
7061
7078
  if (this.isLoading) return;
7079
+ this.debugLog("\u{1F4CA} Starting loadData process");
7062
7080
  const loadBtn = document.getElementById("load-btn");
7063
7081
  const exportBtn = document.getElementById("export-btn");
7064
7082
  const spinner = document.getElementById("load-spinner");
@@ -7072,28 +7090,44 @@ var AllReportModal = class {
7072
7090
  spinner.style.display = "inline-block";
7073
7091
  try {
7074
7092
  const { startISO, endISO } = this.dateRangePicker.getDates();
7093
+ this.debugLog("\u{1F4C5} Date range selected", { startISO, endISO });
7075
7094
  if (!startISO || !endISO) {
7076
7095
  this.showError("Selecione um per\xEDodo v\xE1lido");
7077
7096
  return;
7078
7097
  }
7079
7098
  const startDate = startISO.split("T")[0];
7080
7099
  const endDate = endISO.split("T")[0];
7100
+ this.debugLog("\u{1F310} Fetching customer totals from API...");
7081
7101
  const customerTotalsData = await this.fetchCustomerTotals(startISO, endISO);
7102
+ this.debugLog("\u2705 API response received", customerTotalsData);
7103
+ this.debugLog("\u{1F504} Processing API response...");
7082
7104
  this.data = this.mapCustomerTotalsResponse(customerTotalsData);
7105
+ this.debugLog("\u2705 Data mapping completed", {
7106
+ mappedDataLength: this.data.length,
7107
+ mappedData: this.data,
7108
+ totalConsumption: this.calculateTotalConsumption()
7109
+ });
7083
7110
  this.selectedStoreIds = new Set(
7084
7111
  this.data.map((store) => this.generateStoreId(store.name))
7085
7112
  );
7113
+ this.debugLog("\u{1F3AF} Store IDs initialized", {
7114
+ selectedStoreIdsSize: this.selectedStoreIds.size,
7115
+ selectedStoreIds: Array.from(this.selectedStoreIds)
7116
+ });
7086
7117
  this.currentPage = 1;
7118
+ this.debugLog("\u{1F3A8} Rendering UI components...");
7087
7119
  this.renderSummary();
7088
7120
  this.renderTable();
7089
7121
  this.renderPagination();
7090
7122
  exportBtn.disabled = false;
7123
+ this.debugLog("\u{1F389} Load process completed successfully");
7091
7124
  this.emit("loaded", {
7092
7125
  date: { start: startDate, end: endDate },
7093
7126
  stores: this.data.length,
7094
7127
  totalConsumption: this.calculateTotalConsumption()
7095
7128
  });
7096
7129
  } catch (error) {
7130
+ this.debugLog("\u274C Error in loadData", error);
7097
7131
  this.showError("Erro ao carregar dados: " + error.message);
7098
7132
  console.error("Error loading data:", error);
7099
7133
  this.emit("error", { message: error.message, context: "loadData" });
@@ -7432,46 +7466,90 @@ var AllReportModal = class {
7432
7466
  return data;
7433
7467
  }
7434
7468
  mapCustomerTotalsResponse(apiResponse) {
7469
+ this.debugLog("\u{1F50D} Starting mapCustomerTotalsResponse", { apiResponse });
7435
7470
  const apiArray = Array.isArray(apiResponse?.data) ? apiResponse.data : Array.isArray(apiResponse) ? apiResponse : [];
7471
+ this.debugLog("\u{1F4CB} API data array extracted", {
7472
+ isDataProperty: !!apiResponse?.data,
7473
+ isDirectArray: Array.isArray(apiResponse),
7474
+ apiArrayLength: apiArray.length,
7475
+ firstFewItems: apiArray.slice(0, 3)
7476
+ });
7436
7477
  if (!apiArray.length) {
7478
+ this.debugLog("\u26A0\uFE0F Empty API array, returning empty result");
7437
7479
  console.warn("[AllReportModal] Empty/invalid API response:", apiResponse);
7438
7480
  return [];
7439
7481
  }
7440
7482
  const sumByApiId = /* @__PURE__ */ new Map();
7441
7483
  let apiItemsWithoutId = 0;
7442
- for (const item of apiArray) {
7484
+ this.debugLog("\u{1F528} Building ID index from API data...");
7485
+ for (const [index, item] of apiArray.entries()) {
7443
7486
  const consumption = this.pickConsumption(item);
7487
+ this.debugLog(`\u{1F4CA} Processing API item ${index}`, {
7488
+ item,
7489
+ extractedConsumption: consumption,
7490
+ hasId: !!item?.id
7491
+ });
7444
7492
  if (item?.id) {
7445
7493
  const id = String(item.id);
7446
- sumByApiId.set(id, (sumByApiId.get(id) || 0) + consumption);
7494
+ const previousSum = sumByApiId.get(id) || 0;
7495
+ sumByApiId.set(id, previousSum + consumption);
7496
+ this.debugLog(`\u2705 Added to ID index: ${id} = ${previousSum} + ${consumption} = ${previousSum + consumption}`);
7447
7497
  } else {
7448
7498
  apiItemsWithoutId++;
7499
+ this.debugLog(`\u274C API item without ID:`, item);
7449
7500
  }
7450
7501
  }
7502
+ this.debugLog("\u{1F4CA} ID index built", {
7503
+ sumByApiIdSize: sumByApiId.size,
7504
+ sumByApiIdEntries: Array.from(sumByApiId.entries()),
7505
+ apiItemsWithoutId
7506
+ });
7451
7507
  let matchedById = 0, matchedBySubstring = 0;
7452
- const rows = this.params.itemsList.map((listItem) => {
7508
+ this.debugLog("\u{1F3AF} Starting itemsList mapping...");
7509
+ const rows = this.params.itemsList.map((listItem, index) => {
7510
+ this.debugLog(`\u{1F50D} Processing listItem ${index}`, listItem);
7453
7511
  let consumption = sumByApiId.get(listItem.id) ?? 0;
7512
+ this.debugLog(`\u{1F3AF} Primary ID match for ${listItem.id}: ${consumption}`);
7454
7513
  if (consumption > 0) {
7455
7514
  matchedById++;
7515
+ this.debugLog(`\u2705 Matched by ID: ${listItem.id} -> ${consumption}`);
7456
7516
  } else {
7457
- for (const apiItem of apiArray) {
7517
+ this.debugLog(`\u{1F504} No ID match, trying substring fallback for identifier: ${listItem.identifier}`);
7518
+ for (const [apiIndex, apiItem] of apiArray.entries()) {
7458
7519
  const assetName = apiItem?.assetName || "";
7459
7520
  const name = apiItem?.name || "";
7460
- if (assetName.includes(listItem.identifier) || name.includes(listItem.identifier)) {
7461
- consumption += this.pickConsumption(apiItem);
7521
+ const assetNameMatch = assetName.includes(listItem.identifier);
7522
+ const nameMatch = name.includes(listItem.identifier);
7523
+ if (assetNameMatch || nameMatch) {
7524
+ const itemConsumption = this.pickConsumption(apiItem);
7525
+ consumption += itemConsumption;
7526
+ this.debugLog(`\u2705 Substring match found in API item ${apiIndex}`, {
7527
+ listItemIdentifier: listItem.identifier,
7528
+ apiItemAssetName: assetName,
7529
+ apiItemName: name,
7530
+ assetNameMatch,
7531
+ nameMatch,
7532
+ itemConsumption,
7533
+ totalConsumption: consumption
7534
+ });
7462
7535
  }
7463
7536
  }
7464
7537
  if (consumption > 0) {
7465
7538
  matchedBySubstring++;
7539
+ this.debugLog(`\u2705 Matched by substring: ${listItem.identifier} -> ${consumption}`);
7540
+ } else {
7541
+ this.debugLog(`\u274C No match found for: ${listItem.identifier}`);
7466
7542
  }
7467
7543
  }
7468
- return {
7544
+ const result = {
7469
7545
  identifier: listItem.identifier,
7470
7546
  name: listItem.label,
7471
7547
  consumption: Math.round(consumption * 100) / 100
7472
7548
  };
7549
+ this.debugLog(`\u{1F4DD} Final row for ${listItem.identifier}:`, result);
7550
+ return result;
7473
7551
  });
7474
- console.log("[AllReportModal] Mapping stats:", {
7552
+ const stats = {
7475
7553
  apiItems: apiArray.length,
7476
7554
  uniqueApiIds: sumByApiId.size,
7477
7555
  itemsInList: this.params.itemsList.length,
@@ -7479,7 +7557,9 @@ var AllReportModal = class {
7479
7557
  matchedBySubstring,
7480
7558
  unmatched: this.params.itemsList.length - matchedById - matchedBySubstring,
7481
7559
  apiItemsWithoutId
7482
- });
7560
+ };
7561
+ this.debugLog("\u{1F4CA} Final mapping stats:", stats);
7562
+ console.log("[AllReportModal] Mapping stats:", stats);
7483
7563
  return rows;
7484
7564
  }
7485
7565
  parseConsumptionValue(item) {
package/dist/index.js CHANGED
@@ -6835,7 +6835,7 @@ function attachFilterOrderingModal(props) {
6835
6835
  }
6836
6836
 
6837
6837
  // src/components/premium-modals/report-all/AllReportModal.ts
6838
- var AllReportModal = class {
6838
+ var AllReportModal = class _AllReportModal {
6839
6839
  constructor(params) {
6840
6840
  this.params = params;
6841
6841
  this.authClient = new AuthClient({
@@ -6843,6 +6843,15 @@ var AllReportModal = class {
6843
6843
  clientSecret: params.api.clientSecret,
6844
6844
  base: params.api.dataApiBaseUrl
6845
6845
  });
6846
+ this.debugLog("\u{1F680} AllReportModal initialized", {
6847
+ customerId: params.customerId,
6848
+ itemsListLength: params.itemsList?.length || 0,
6849
+ itemsList: params.itemsList,
6850
+ apiConfig: {
6851
+ hasIngestionToken: !!params.api.ingestionToken,
6852
+ dataApiBaseUrl: params.api.dataApiBaseUrl
6853
+ }
6854
+ });
6846
6855
  }
6847
6856
  modal;
6848
6857
  authClient;
@@ -6859,6 +6868,14 @@ var AllReportModal = class {
6859
6868
  filterModal = null;
6860
6869
  selectedStoreIds = /* @__PURE__ */ new Set();
6861
6870
  currentSortMode = "CONSUMPTION_DESC";
6871
+ // Debug logging flag - can be enabled globally
6872
+ static DEBUG_ENABLED = globalThis.MYIO_DEBUG_ALLREPORT || true;
6873
+ // Debug logging helper
6874
+ debugLog(message, data) {
6875
+ if (_AllReportModal.DEBUG_ENABLED) {
6876
+ console.log(`[AllReportModal DEBUG] ${message}`, data || "");
6877
+ }
6878
+ }
6862
6879
  // Helper: normalize identifiers (upper, strip spaces and non-alphanum)
6863
6880
  normalizeId(v) {
6864
6881
  return (v || "").toString().normalize("NFKC").toUpperCase().replace(/\s+/g, "").replace(/[^A-Z0-9]/g, "");
@@ -6992,6 +7009,7 @@ var AllReportModal = class {
6992
7009
  }
6993
7010
  async loadData() {
6994
7011
  if (this.isLoading) return;
7012
+ this.debugLog("\u{1F4CA} Starting loadData process");
6995
7013
  const loadBtn = document.getElementById("load-btn");
6996
7014
  const exportBtn = document.getElementById("export-btn");
6997
7015
  const spinner = document.getElementById("load-spinner");
@@ -7005,28 +7023,44 @@ var AllReportModal = class {
7005
7023
  spinner.style.display = "inline-block";
7006
7024
  try {
7007
7025
  const { startISO, endISO } = this.dateRangePicker.getDates();
7026
+ this.debugLog("\u{1F4C5} Date range selected", { startISO, endISO });
7008
7027
  if (!startISO || !endISO) {
7009
7028
  this.showError("Selecione um per\xEDodo v\xE1lido");
7010
7029
  return;
7011
7030
  }
7012
7031
  const startDate = startISO.split("T")[0];
7013
7032
  const endDate = endISO.split("T")[0];
7033
+ this.debugLog("\u{1F310} Fetching customer totals from API...");
7014
7034
  const customerTotalsData = await this.fetchCustomerTotals(startISO, endISO);
7035
+ this.debugLog("\u2705 API response received", customerTotalsData);
7036
+ this.debugLog("\u{1F504} Processing API response...");
7015
7037
  this.data = this.mapCustomerTotalsResponse(customerTotalsData);
7038
+ this.debugLog("\u2705 Data mapping completed", {
7039
+ mappedDataLength: this.data.length,
7040
+ mappedData: this.data,
7041
+ totalConsumption: this.calculateTotalConsumption()
7042
+ });
7016
7043
  this.selectedStoreIds = new Set(
7017
7044
  this.data.map((store) => this.generateStoreId(store.name))
7018
7045
  );
7046
+ this.debugLog("\u{1F3AF} Store IDs initialized", {
7047
+ selectedStoreIdsSize: this.selectedStoreIds.size,
7048
+ selectedStoreIds: Array.from(this.selectedStoreIds)
7049
+ });
7019
7050
  this.currentPage = 1;
7051
+ this.debugLog("\u{1F3A8} Rendering UI components...");
7020
7052
  this.renderSummary();
7021
7053
  this.renderTable();
7022
7054
  this.renderPagination();
7023
7055
  exportBtn.disabled = false;
7056
+ this.debugLog("\u{1F389} Load process completed successfully");
7024
7057
  this.emit("loaded", {
7025
7058
  date: { start: startDate, end: endDate },
7026
7059
  stores: this.data.length,
7027
7060
  totalConsumption: this.calculateTotalConsumption()
7028
7061
  });
7029
7062
  } catch (error) {
7063
+ this.debugLog("\u274C Error in loadData", error);
7030
7064
  this.showError("Erro ao carregar dados: " + error.message);
7031
7065
  console.error("Error loading data:", error);
7032
7066
  this.emit("error", { message: error.message, context: "loadData" });
@@ -7365,46 +7399,90 @@ var AllReportModal = class {
7365
7399
  return data;
7366
7400
  }
7367
7401
  mapCustomerTotalsResponse(apiResponse) {
7402
+ this.debugLog("\u{1F50D} Starting mapCustomerTotalsResponse", { apiResponse });
7368
7403
  const apiArray = Array.isArray(apiResponse?.data) ? apiResponse.data : Array.isArray(apiResponse) ? apiResponse : [];
7404
+ this.debugLog("\u{1F4CB} API data array extracted", {
7405
+ isDataProperty: !!apiResponse?.data,
7406
+ isDirectArray: Array.isArray(apiResponse),
7407
+ apiArrayLength: apiArray.length,
7408
+ firstFewItems: apiArray.slice(0, 3)
7409
+ });
7369
7410
  if (!apiArray.length) {
7411
+ this.debugLog("\u26A0\uFE0F Empty API array, returning empty result");
7370
7412
  console.warn("[AllReportModal] Empty/invalid API response:", apiResponse);
7371
7413
  return [];
7372
7414
  }
7373
7415
  const sumByApiId = /* @__PURE__ */ new Map();
7374
7416
  let apiItemsWithoutId = 0;
7375
- for (const item of apiArray) {
7417
+ this.debugLog("\u{1F528} Building ID index from API data...");
7418
+ for (const [index, item] of apiArray.entries()) {
7376
7419
  const consumption = this.pickConsumption(item);
7420
+ this.debugLog(`\u{1F4CA} Processing API item ${index}`, {
7421
+ item,
7422
+ extractedConsumption: consumption,
7423
+ hasId: !!item?.id
7424
+ });
7377
7425
  if (item?.id) {
7378
7426
  const id = String(item.id);
7379
- sumByApiId.set(id, (sumByApiId.get(id) || 0) + consumption);
7427
+ const previousSum = sumByApiId.get(id) || 0;
7428
+ sumByApiId.set(id, previousSum + consumption);
7429
+ this.debugLog(`\u2705 Added to ID index: ${id} = ${previousSum} + ${consumption} = ${previousSum + consumption}`);
7380
7430
  } else {
7381
7431
  apiItemsWithoutId++;
7432
+ this.debugLog(`\u274C API item without ID:`, item);
7382
7433
  }
7383
7434
  }
7435
+ this.debugLog("\u{1F4CA} ID index built", {
7436
+ sumByApiIdSize: sumByApiId.size,
7437
+ sumByApiIdEntries: Array.from(sumByApiId.entries()),
7438
+ apiItemsWithoutId
7439
+ });
7384
7440
  let matchedById = 0, matchedBySubstring = 0;
7385
- const rows = this.params.itemsList.map((listItem) => {
7441
+ this.debugLog("\u{1F3AF} Starting itemsList mapping...");
7442
+ const rows = this.params.itemsList.map((listItem, index) => {
7443
+ this.debugLog(`\u{1F50D} Processing listItem ${index}`, listItem);
7386
7444
  let consumption = sumByApiId.get(listItem.id) ?? 0;
7445
+ this.debugLog(`\u{1F3AF} Primary ID match for ${listItem.id}: ${consumption}`);
7387
7446
  if (consumption > 0) {
7388
7447
  matchedById++;
7448
+ this.debugLog(`\u2705 Matched by ID: ${listItem.id} -> ${consumption}`);
7389
7449
  } else {
7390
- for (const apiItem of apiArray) {
7450
+ this.debugLog(`\u{1F504} No ID match, trying substring fallback for identifier: ${listItem.identifier}`);
7451
+ for (const [apiIndex, apiItem] of apiArray.entries()) {
7391
7452
  const assetName = apiItem?.assetName || "";
7392
7453
  const name = apiItem?.name || "";
7393
- if (assetName.includes(listItem.identifier) || name.includes(listItem.identifier)) {
7394
- consumption += this.pickConsumption(apiItem);
7454
+ const assetNameMatch = assetName.includes(listItem.identifier);
7455
+ const nameMatch = name.includes(listItem.identifier);
7456
+ if (assetNameMatch || nameMatch) {
7457
+ const itemConsumption = this.pickConsumption(apiItem);
7458
+ consumption += itemConsumption;
7459
+ this.debugLog(`\u2705 Substring match found in API item ${apiIndex}`, {
7460
+ listItemIdentifier: listItem.identifier,
7461
+ apiItemAssetName: assetName,
7462
+ apiItemName: name,
7463
+ assetNameMatch,
7464
+ nameMatch,
7465
+ itemConsumption,
7466
+ totalConsumption: consumption
7467
+ });
7395
7468
  }
7396
7469
  }
7397
7470
  if (consumption > 0) {
7398
7471
  matchedBySubstring++;
7472
+ this.debugLog(`\u2705 Matched by substring: ${listItem.identifier} -> ${consumption}`);
7473
+ } else {
7474
+ this.debugLog(`\u274C No match found for: ${listItem.identifier}`);
7399
7475
  }
7400
7476
  }
7401
- return {
7477
+ const result = {
7402
7478
  identifier: listItem.identifier,
7403
7479
  name: listItem.label,
7404
7480
  consumption: Math.round(consumption * 100) / 100
7405
7481
  };
7482
+ this.debugLog(`\u{1F4DD} Final row for ${listItem.identifier}:`, result);
7483
+ return result;
7406
7484
  });
7407
- console.log("[AllReportModal] Mapping stats:", {
7485
+ const stats = {
7408
7486
  apiItems: apiArray.length,
7409
7487
  uniqueApiIds: sumByApiId.size,
7410
7488
  itemsInList: this.params.itemsList.length,
@@ -7412,7 +7490,9 @@ var AllReportModal = class {
7412
7490
  matchedBySubstring,
7413
7491
  unmatched: this.params.itemsList.length - matchedById - matchedBySubstring,
7414
7492
  apiItemsWithoutId
7415
- });
7493
+ };
7494
+ this.debugLog("\u{1F4CA} Final mapping stats:", stats);
7495
+ console.log("[AllReportModal] Mapping stats:", stats);
7416
7496
  return rows;
7417
7497
  }
7418
7498
  parseConsumptionValue(item) {
@@ -6824,7 +6824,7 @@
6824
6824
  }
6825
6825
 
6826
6826
  // src/components/premium-modals/report-all/AllReportModal.ts
6827
- var AllReportModal = class {
6827
+ var AllReportModal = class _AllReportModal {
6828
6828
  constructor(params) {
6829
6829
  this.params = params;
6830
6830
  this.authClient = new AuthClient({
@@ -6832,6 +6832,15 @@
6832
6832
  clientSecret: params.api.clientSecret,
6833
6833
  base: params.api.dataApiBaseUrl
6834
6834
  });
6835
+ this.debugLog("\u{1F680} AllReportModal initialized", {
6836
+ customerId: params.customerId,
6837
+ itemsListLength: params.itemsList?.length || 0,
6838
+ itemsList: params.itemsList,
6839
+ apiConfig: {
6840
+ hasIngestionToken: !!params.api.ingestionToken,
6841
+ dataApiBaseUrl: params.api.dataApiBaseUrl
6842
+ }
6843
+ });
6835
6844
  }
6836
6845
  modal;
6837
6846
  authClient;
@@ -6848,6 +6857,14 @@
6848
6857
  filterModal = null;
6849
6858
  selectedStoreIds = /* @__PURE__ */ new Set();
6850
6859
  currentSortMode = "CONSUMPTION_DESC";
6860
+ // Debug logging flag - can be enabled globally
6861
+ static DEBUG_ENABLED = globalThis.MYIO_DEBUG_ALLREPORT || true;
6862
+ // Debug logging helper
6863
+ debugLog(message, data) {
6864
+ {
6865
+ console.log(`[AllReportModal DEBUG] ${message}`, data || "");
6866
+ }
6867
+ }
6851
6868
  // Helper: normalize identifiers (upper, strip spaces and non-alphanum)
6852
6869
  normalizeId(v) {
6853
6870
  return (v || "").toString().normalize("NFKC").toUpperCase().replace(/\s+/g, "").replace(/[^A-Z0-9]/g, "");
@@ -6981,6 +6998,7 @@
6981
6998
  }
6982
6999
  async loadData() {
6983
7000
  if (this.isLoading) return;
7001
+ this.debugLog("\u{1F4CA} Starting loadData process");
6984
7002
  const loadBtn = document.getElementById("load-btn");
6985
7003
  const exportBtn = document.getElementById("export-btn");
6986
7004
  const spinner = document.getElementById("load-spinner");
@@ -6994,28 +7012,44 @@
6994
7012
  spinner.style.display = "inline-block";
6995
7013
  try {
6996
7014
  const { startISO, endISO } = this.dateRangePicker.getDates();
7015
+ this.debugLog("\u{1F4C5} Date range selected", { startISO, endISO });
6997
7016
  if (!startISO || !endISO) {
6998
7017
  this.showError("Selecione um per\xEDodo v\xE1lido");
6999
7018
  return;
7000
7019
  }
7001
7020
  const startDate = startISO.split("T")[0];
7002
7021
  const endDate = endISO.split("T")[0];
7022
+ this.debugLog("\u{1F310} Fetching customer totals from API...");
7003
7023
  const customerTotalsData = await this.fetchCustomerTotals(startISO, endISO);
7024
+ this.debugLog("\u2705 API response received", customerTotalsData);
7025
+ this.debugLog("\u{1F504} Processing API response...");
7004
7026
  this.data = this.mapCustomerTotalsResponse(customerTotalsData);
7027
+ this.debugLog("\u2705 Data mapping completed", {
7028
+ mappedDataLength: this.data.length,
7029
+ mappedData: this.data,
7030
+ totalConsumption: this.calculateTotalConsumption()
7031
+ });
7005
7032
  this.selectedStoreIds = new Set(
7006
7033
  this.data.map((store) => this.generateStoreId(store.name))
7007
7034
  );
7035
+ this.debugLog("\u{1F3AF} Store IDs initialized", {
7036
+ selectedStoreIdsSize: this.selectedStoreIds.size,
7037
+ selectedStoreIds: Array.from(this.selectedStoreIds)
7038
+ });
7008
7039
  this.currentPage = 1;
7040
+ this.debugLog("\u{1F3A8} Rendering UI components...");
7009
7041
  this.renderSummary();
7010
7042
  this.renderTable();
7011
7043
  this.renderPagination();
7012
7044
  exportBtn.disabled = false;
7045
+ this.debugLog("\u{1F389} Load process completed successfully");
7013
7046
  this.emit("loaded", {
7014
7047
  date: { start: startDate, end: endDate },
7015
7048
  stores: this.data.length,
7016
7049
  totalConsumption: this.calculateTotalConsumption()
7017
7050
  });
7018
7051
  } catch (error) {
7052
+ this.debugLog("\u274C Error in loadData", error);
7019
7053
  this.showError("Erro ao carregar dados: " + error.message);
7020
7054
  console.error("Error loading data:", error);
7021
7055
  this.emit("error", { message: error.message, context: "loadData" });
@@ -7354,46 +7388,90 @@
7354
7388
  return data;
7355
7389
  }
7356
7390
  mapCustomerTotalsResponse(apiResponse) {
7391
+ this.debugLog("\u{1F50D} Starting mapCustomerTotalsResponse", { apiResponse });
7357
7392
  const apiArray = Array.isArray(apiResponse?.data) ? apiResponse.data : Array.isArray(apiResponse) ? apiResponse : [];
7393
+ this.debugLog("\u{1F4CB} API data array extracted", {
7394
+ isDataProperty: !!apiResponse?.data,
7395
+ isDirectArray: Array.isArray(apiResponse),
7396
+ apiArrayLength: apiArray.length,
7397
+ firstFewItems: apiArray.slice(0, 3)
7398
+ });
7358
7399
  if (!apiArray.length) {
7400
+ this.debugLog("\u26A0\uFE0F Empty API array, returning empty result");
7359
7401
  console.warn("[AllReportModal] Empty/invalid API response:", apiResponse);
7360
7402
  return [];
7361
7403
  }
7362
7404
  const sumByApiId = /* @__PURE__ */ new Map();
7363
7405
  let apiItemsWithoutId = 0;
7364
- for (const item of apiArray) {
7406
+ this.debugLog("\u{1F528} Building ID index from API data...");
7407
+ for (const [index, item] of apiArray.entries()) {
7365
7408
  const consumption = this.pickConsumption(item);
7409
+ this.debugLog(`\u{1F4CA} Processing API item ${index}`, {
7410
+ item,
7411
+ extractedConsumption: consumption,
7412
+ hasId: !!item?.id
7413
+ });
7366
7414
  if (item?.id) {
7367
7415
  const id = String(item.id);
7368
- sumByApiId.set(id, (sumByApiId.get(id) || 0) + consumption);
7416
+ const previousSum = sumByApiId.get(id) || 0;
7417
+ sumByApiId.set(id, previousSum + consumption);
7418
+ this.debugLog(`\u2705 Added to ID index: ${id} = ${previousSum} + ${consumption} = ${previousSum + consumption}`);
7369
7419
  } else {
7370
7420
  apiItemsWithoutId++;
7421
+ this.debugLog(`\u274C API item without ID:`, item);
7371
7422
  }
7372
7423
  }
7424
+ this.debugLog("\u{1F4CA} ID index built", {
7425
+ sumByApiIdSize: sumByApiId.size,
7426
+ sumByApiIdEntries: Array.from(sumByApiId.entries()),
7427
+ apiItemsWithoutId
7428
+ });
7373
7429
  let matchedById = 0, matchedBySubstring = 0;
7374
- const rows = this.params.itemsList.map((listItem) => {
7430
+ this.debugLog("\u{1F3AF} Starting itemsList mapping...");
7431
+ const rows = this.params.itemsList.map((listItem, index) => {
7432
+ this.debugLog(`\u{1F50D} Processing listItem ${index}`, listItem);
7375
7433
  let consumption = sumByApiId.get(listItem.id) ?? 0;
7434
+ this.debugLog(`\u{1F3AF} Primary ID match for ${listItem.id}: ${consumption}`);
7376
7435
  if (consumption > 0) {
7377
7436
  matchedById++;
7437
+ this.debugLog(`\u2705 Matched by ID: ${listItem.id} -> ${consumption}`);
7378
7438
  } else {
7379
- for (const apiItem of apiArray) {
7439
+ this.debugLog(`\u{1F504} No ID match, trying substring fallback for identifier: ${listItem.identifier}`);
7440
+ for (const [apiIndex, apiItem] of apiArray.entries()) {
7380
7441
  const assetName = apiItem?.assetName || "";
7381
7442
  const name = apiItem?.name || "";
7382
- if (assetName.includes(listItem.identifier) || name.includes(listItem.identifier)) {
7383
- consumption += this.pickConsumption(apiItem);
7443
+ const assetNameMatch = assetName.includes(listItem.identifier);
7444
+ const nameMatch = name.includes(listItem.identifier);
7445
+ if (assetNameMatch || nameMatch) {
7446
+ const itemConsumption = this.pickConsumption(apiItem);
7447
+ consumption += itemConsumption;
7448
+ this.debugLog(`\u2705 Substring match found in API item ${apiIndex}`, {
7449
+ listItemIdentifier: listItem.identifier,
7450
+ apiItemAssetName: assetName,
7451
+ apiItemName: name,
7452
+ assetNameMatch,
7453
+ nameMatch,
7454
+ itemConsumption,
7455
+ totalConsumption: consumption
7456
+ });
7384
7457
  }
7385
7458
  }
7386
7459
  if (consumption > 0) {
7387
7460
  matchedBySubstring++;
7461
+ this.debugLog(`\u2705 Matched by substring: ${listItem.identifier} -> ${consumption}`);
7462
+ } else {
7463
+ this.debugLog(`\u274C No match found for: ${listItem.identifier}`);
7388
7464
  }
7389
7465
  }
7390
- return {
7466
+ const result = {
7391
7467
  identifier: listItem.identifier,
7392
7468
  name: listItem.label,
7393
7469
  consumption: Math.round(consumption * 100) / 100
7394
7470
  };
7471
+ this.debugLog(`\u{1F4DD} Final row for ${listItem.identifier}:`, result);
7472
+ return result;
7395
7473
  });
7396
- console.log("[AllReportModal] Mapping stats:", {
7474
+ const stats = {
7397
7475
  apiItems: apiArray.length,
7398
7476
  uniqueApiIds: sumByApiId.size,
7399
7477
  itemsInList: this.params.itemsList.length,
@@ -7401,7 +7479,9 @@
7401
7479
  matchedBySubstring,
7402
7480
  unmatched: this.params.itemsList.length - matchedById - matchedBySubstring,
7403
7481
  apiItemsWithoutId
7404
- });
7482
+ };
7483
+ this.debugLog("\u{1F4CA} Final mapping stats:", stats);
7484
+ console.log("[AllReportModal] Mapping stats:", stats);
7405
7485
  return rows;
7406
7486
  }
7407
7487
  parseConsumptionValue(item) {