fleetmap-reports 1.0.920 → 1.0.922
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 +1 -1
- package/src/kms-report.js +23 -15
- package/src/tests/zones.test.js +9 -8
- package/src/trip-report.js +1 -1
- package/src/util/utils.js +12 -0
package/package.json
CHANGED
package/src/kms-report.js
CHANGED
|
@@ -7,7 +7,7 @@ const {
|
|
|
7
7
|
} = require('./util/pdfDocument')
|
|
8
8
|
const { getUserPartner } = require('fleetmap-partners')
|
|
9
9
|
const traccar = require('./util/traccar')
|
|
10
|
-
const { getDates, getTranslations } = require('./util/utils')
|
|
10
|
+
const { getDates, getTranslations, isClientSide, executeServerSide } = require('./util/utils')
|
|
11
11
|
const drivers = require('./util/driver')
|
|
12
12
|
const { isInsideTimetable, isPartialInsideTimetable, calculateTrip, getDataByDay, checkTripsKms } = require('./util/trips')
|
|
13
13
|
const traccarHelper = require('./util/traccar')
|
|
@@ -43,21 +43,29 @@ async function createKmsReportByDevice (from, to, userData, traccarInstance) {
|
|
|
43
43
|
to
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
if (isClientSide() && allDevices.length > 50 && userData.groupByDay) {
|
|
47
|
+
const sliced = automaticReports.sliceArray(allDevices, 20)
|
|
48
|
+
await executeServerSide('kms-report', allData, sliced, from, to, userData, allDevices.length)
|
|
49
|
+
} else {
|
|
50
|
+
let deviceCount = 0
|
|
51
|
+
const sliced = automaticReports.sliceArray(allDevices, 20)
|
|
52
|
+
for (const devices of sliced) {
|
|
53
|
+
const needRoute = !userData.allWeek
|
|
54
|
+
const {
|
|
55
|
+
trips,
|
|
56
|
+
route
|
|
57
|
+
} = await traccar.getAllInOne(traccarInstance, from, to, devices, needRoute, true, false, false, deviceCount, allDevices.length, 10, 2)
|
|
58
|
+
|
|
59
|
+
// Process report data
|
|
60
|
+
if (trips.length) {
|
|
61
|
+
checkTripsKms(traccarInstance, from, to, allDevices, { trips, route })
|
|
62
|
+
allData.devices = allData.devices.concat(await processDevices(from, to, allDevices, {
|
|
63
|
+
trips,
|
|
64
|
+
route
|
|
65
|
+
}, userData, traccarInstance))
|
|
66
|
+
}
|
|
67
|
+
deviceCount += devices.length
|
|
59
68
|
}
|
|
60
|
-
deviceCount += devices.length
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
return allData
|
package/src/tests/zones.test.js
CHANGED
|
@@ -45,18 +45,19 @@ describe('zones', function () {
|
|
|
45
45
|
|
|
46
46
|
// eslint-disable-next-line no-undef
|
|
47
47
|
it('works with casais zones in columns', async () => {
|
|
48
|
-
const report = await getReports(
|
|
48
|
+
const report = await getReports('fleetmap.joao.penas2@gmail.com', 'penas46881')
|
|
49
49
|
const userData = await report.getUserData()
|
|
50
50
|
userData.zonesByColumn = true
|
|
51
|
-
userData.devices = userData.devices.filter(d => d.
|
|
52
|
-
userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde '
|
|
53
|
-
|
|
51
|
+
userData.devices = userData.devices.filter(d => d.id === 81202)
|
|
52
|
+
userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde ' ||
|
|
53
|
+
g.name === 'baliza 2 - raio amarelo')
|
|
54
|
+
userData.onlyWithKmsOut = false
|
|
54
55
|
const result = await report.zoneReport(
|
|
55
|
-
new Date(Date.UTC(2023,
|
|
56
|
-
new Date(Date.UTC(2023,
|
|
56
|
+
new Date(Date.UTC(2023, 6, 13, 0, 0, 0, 0)),
|
|
57
|
+
new Date(Date.UTC(2023, 6, 13, 23, 59, 59, 0)),
|
|
57
58
|
userData)
|
|
58
|
-
const first = result[0].devices[0]
|
|
59
|
+
const first = result[0].devices[0]
|
|
59
60
|
console.log(first)
|
|
60
|
-
assert.equal(first.distanceOut,
|
|
61
|
+
assert.equal(first.days[0].distanceOut, 28)
|
|
61
62
|
}, 4000000)
|
|
62
63
|
})
|
package/src/trip-report.js
CHANGED
|
@@ -343,7 +343,7 @@ async function exportTripReportToPDF (userData, reportData) {
|
|
|
343
343
|
doc.text(name, 20, space + 20)
|
|
344
344
|
doc.setFontSize(11)
|
|
345
345
|
doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space + 20)
|
|
346
|
-
doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space + 25)
|
|
346
|
+
doc.text(convertToLocaleString(d.from, lang, timezone, userData.user) + ' - ' + convertToLocaleString(d.to, lang, timezone, userData.user), 20, space + 25)
|
|
347
347
|
if (!userData.allWeek && userData.weekDays) {
|
|
348
348
|
doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '') +
|
|
349
349
|
(userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '') +
|
package/src/util/utils.js
CHANGED
|
@@ -224,6 +224,18 @@ function weekDaySelected (date, weekDays) {
|
|
|
224
224
|
(date.getDay() === 6 && weekDays.saturday))
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
async function executeServerSide (type, allData, sliced, from, to, userData, totalDevices) {
|
|
228
|
+
let deviceCount = 0
|
|
229
|
+
for (const devices of sliced) {
|
|
230
|
+
const url = `https://${process.env.SERVER_HOST}/reports/${type}`
|
|
231
|
+
const data = await axios.post(url, { from, to, userData: { ...userData, devices } }, { withCredentials: true }).then(d => d.data)
|
|
232
|
+
allData.devices.push(...(data[0].devices))
|
|
233
|
+
deviceCount = deviceCount + devices.length
|
|
234
|
+
console.log(`PROGRESS_PERC:${deviceCount / totalDevices * 100}`)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
exports.executeServerSide = executeServerSide
|
|
227
239
|
exports.getImgFromUrl = getImgFromUrl
|
|
228
240
|
exports.convertMS = convertMS
|
|
229
241
|
exports.coordsDistance = coordsDistance
|