fleetmap-reports 2.0.352 → 2.0.354
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/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const refuelingReport = require('./refueling-report')
|
|
2
2
|
const traccarHelper = require('./util/traccar')
|
|
3
3
|
const odoo = require('./util/odoo')
|
|
4
|
+
const automaticReports = require('./automaticReports')
|
|
4
5
|
const { devicesToProcess } = require('./util/device')
|
|
5
|
-
const { getTranslations, convertToLocaleString, getLanguage, convertMS, formatNumber, getDates } = require('./util/utils')
|
|
6
|
+
const { getTranslations, convertToLocaleString, getLanguage, convertMS, formatNumber, getDates, isClientSide, executeServerSide } = require('./util/utils')
|
|
6
7
|
const { getStyle } = require('./reportStyle')
|
|
7
8
|
const { getUserPartner } = require('fleetmap-partners')
|
|
8
9
|
const { addTable, headerFromUser } = require('./util/pdfDocument')
|
|
@@ -24,6 +25,16 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
24
25
|
|
|
25
26
|
const devices = devicesToProcess(userData)
|
|
26
27
|
|
|
28
|
+
allData.totalDevices = 0
|
|
29
|
+
|
|
30
|
+
if (isClientSide() && (devices.length > 50 || ((new Date(to).getTime() - new Date(from).getTime()) > (1000 * 60 * 60 * 24 * 15)))) {
|
|
31
|
+
const sliced = automaticReports.sliceArray(devices, 1)
|
|
32
|
+
allData.devices = await executeServerSide('fuel-consumption-report', sliced, from, to, userData, devices.length, traccar, 5)
|
|
33
|
+
allData.totalDevices = allData.devices.length
|
|
34
|
+
reportData.push(allData)
|
|
35
|
+
return reportData
|
|
36
|
+
}
|
|
37
|
+
|
|
27
38
|
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devices, true, true, true, false)
|
|
28
39
|
const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
|
|
29
40
|
const summary = await getSummaryByDay(dates, userData, traccar, devices, true, from, to)
|
|
@@ -37,8 +48,6 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
37
48
|
return reportData
|
|
38
49
|
}
|
|
39
50
|
|
|
40
|
-
allData.totalDevices = 0
|
|
41
|
-
|
|
42
51
|
for (const d of devices) {
|
|
43
52
|
const stops = allInOne.stops.filter(t => t.deviceId === d.id)
|
|
44
53
|
const trips = allInOne.trips.filter(t => t.deviceId === d.id)
|
|
@@ -144,7 +153,7 @@ function exportFuelConsumptionReportToExcel (userData, reportData) {
|
|
|
144
153
|
data = data.concat(d.days.map((r) => {
|
|
145
154
|
return {
|
|
146
155
|
name: d.device.name,
|
|
147
|
-
date: r.date.toLocaleDateString(),
|
|
156
|
+
date: new Date(r.date).toLocaleDateString(),
|
|
148
157
|
kms: formatNumber(r.distance / 1000),
|
|
149
158
|
consumption: r.spentFuel > 0 ? formatNumber(r.spentFuel) : 0,
|
|
150
159
|
avg_consumption: formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms),
|
|
@@ -211,7 +220,7 @@ async function exportFuelConsumptionReportToPDF (userData, reportData) {
|
|
|
211
220
|
|
|
212
221
|
d.days.forEach(r =>
|
|
213
222
|
data.push([
|
|
214
|
-
r.date.toLocaleDateString(),
|
|
223
|
+
new Date(r.date).toLocaleDateString(),
|
|
215
224
|
formatNumber(r.distance / 1000),
|
|
216
225
|
r.spentFuel > 0 ? formatNumber(r.spentFuel) : 0,
|
|
217
226
|
formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms),
|
package/src/util/pdfDocument.js
CHANGED
|
@@ -43,10 +43,6 @@ async function header (doc, title, hostname, style, orientation) {
|
|
|
43
43
|
doc.setFont('helvetica', 'bold')
|
|
44
44
|
doc.text(title, 15, 15)
|
|
45
45
|
|
|
46
|
-
doc.setFontSize(8)
|
|
47
|
-
doc.setFont('helvetica', 'normal')
|
|
48
|
-
doc.text(new Date().toLocaleString(), 15, 21)
|
|
49
|
-
|
|
50
46
|
if (style.imgWidth && style.imgHeight) {
|
|
51
47
|
try {
|
|
52
48
|
const image = await getImgFromUrl(hostname)
|
package/src/util/utils.js
CHANGED
|
@@ -259,7 +259,10 @@ async function executeServerSide (type, sliced, from, to, userData, totalItems,
|
|
|
259
259
|
},
|
|
260
260
|
cookie
|
|
261
261
|
}, { withCredentials: true }).then(d => {
|
|
262
|
-
|
|
262
|
+
const result = d.data[0]
|
|
263
|
+
if (result) {
|
|
264
|
+
reportData.push(...((userData.byDriver ? result.drivers : result.devices) || []))
|
|
265
|
+
}
|
|
263
266
|
})
|
|
264
267
|
itemsCount = itemsCount + items.length
|
|
265
268
|
} catch (e) {
|