Repository navigation
Expand file tree
/
Copy pathcpa.js
More file actions
122 lines (99 loc) · 5.29 KB
/
Copy pathcpa.js
File metadata and controls
122 lines (99 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
document.getElementById('button-cpa').addEventListener('click', function () {
document.getElementById('input-cpa').click();
});
document.getElementById('input-cpa').addEventListener('change', function (event) {
const file = event.target.files[0];
if (file) {
Papa.parse(file, {
header: false,
skipEmptyLines: true,
complete: function (results) {
const rows = results.data;
//const tableBody = document.getElementById('data-table').getElementsByTagName('tbody')[0];
// tableBody.innerHTML = ''; // Limpiar la tabla existente
const uniqueData = new Set();
const domData = [];
rows.forEach(function (cols, index) {
if (index === 0) return; // Ignorar la primera fila (encabezado)
cols.forEach(function (col, colIndex) {
//const cell = newRow.insertCell(colIndex);
if (colIndex === 2) {
const dateObj = new Date(col);
if (!isNaN(dateObj)) {
dateObj.setMinutes(0, 0, 0); // Redondear minutos
const year = dateObj.getFullYear();
const month = String(dateObj.getMonth() + 1).padStart(2, '0');
const day = String(dateObj.getDate()).padStart(2, '0');
const hours = String(dateObj.getHours()).padStart(2, '0');
const formattedDate = `${year}-${month}-${day} ${hours}:00:00`;
//cell.textContent = formattedDate;
uniqueData.add(formattedDate);
const setData = {
LeadId: cols[0],
DateCreated: cols[1],
DateModified: formattedDate,
Phone: cols[3],
Vendor: cols[4],
Touched: cols[5],
ModifierName: cols[6],
StatusDescription: cols[7]
};
domData.push(setData);
} else {
//cell.textContent = col; // Si no es una fecha válida
}
} else {
//cell.textContent = col;
}
});
});
// Guardar las fechas únicas y la data
localStorage.setItem("unique-cpa", JSON.stringify([...uniqueData]));
// Recuperar las fechas únicas
const storedDates = JSON.parse(localStorage.getItem("unique-cpa")) || [];
storedDates.sort();
// Mostrar las fechas únicas ordenadas
const uniqueTableBody = document.getElementById('calls-cpa').getElementsByTagName('tbody')[0];
uniqueTableBody.innerHTML = ''; // Limpiar la tabla antes de agregar datos
const countNewByDate = (storedDates, domData) => {
const dataByDate = domData.reduce((acc, item) => {
if (!acc[item.DateModified]) {
acc[item.DateModified] = { countConverted: 0, countAll: 0 };
}
acc[item.DateModified].countAll += 1;
if (item.StatusDescription === "Converted") {
acc[item.DateModified].countConverted += 1;
}
return acc;
}, {});
const result = storedDates.map(date => {
const { countConverted = 0, countAll = 0 } = dataByDate[date] || {};
return { date, countConverted, countAll };
});
localStorage.setItem("dataByDate", JSON.stringify(result));
return result;
};
const renderTableRows = (data, tableBody) => {
data.forEach(item => {
const row = document.createElement('tr');
if (item.date.includes("10:00:00") || item.date.includes("19:00:00")) {
row.classList.add("marked-row");
}
row.innerHTML = `
<td scope="row">${item.date}</td>
<td>${item.countConverted}</td>
<td>${item.countAll}</td>
<td><button disabled type="button" class="btn btn-primary btn-sm copy-clipboard-cpa"><i class="fa-regular fa-copy"></i></button></td>
`;
tableBody.appendChild(row);
});
};
const data = countNewByDate(storedDates, domData);
renderTableRows(data, uniqueTableBody);
},
error: function () {
alert('Error al analizar el archivo CSV');
},
});
}
});