fleetmap-reports 2.0.143 → 2.0.145

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,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "2.0.143",
3
+ "version": "2.0.145",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -12,7 +12,7 @@ const {
12
12
  const { getStyle } = require('./reportStyle')
13
13
  const { getUserPartner } = require('fleetmap-partners')
14
14
  const traccar = require('./util/traccar')
15
- const { isInsideTimetable, isPartialInsideTimetable, calculateTrip, getDataByDay, getKms } = require('./util/trips')
15
+ const { isInsideTimetable, isPartialInsideTimetable, calculateTrip, getDataByDay, getKms, calculateMultiDayTrips } = require('./util/trips')
16
16
  const { devicesToProcess } = require('./util/device')
17
17
  const { getDriverData } = require('./util/driver')
18
18
  const { calculateConsumption } = require('./util/fuel')
@@ -298,6 +298,8 @@ function processDrivers (from, to, drivers, driversData, userData) {
298
298
  const tripsByDay = trips.filter(t => (new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay) &&
299
299
  (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
300
300
 
301
+ calculateMultiDayTrips(trips, route, tripsByDay, fromByDay, toByDay, userData.devices)
302
+
301
303
  driverData.summary.push({
302
304
  date,
303
305
  distance: tripsByDay.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
package/src/kms-report.js CHANGED
@@ -11,7 +11,7 @@ const { getDates, getTranslations, isClientSide, executeServerSide } = require('
11
11
  const driversUtil = require('./util/driver')
12
12
  const {
13
13
  isInsideTimetable, isPartialInsideTimetable, calculateTrip, getDataByDay, getKms,
14
- getTripTotalKms
14
+ getTripTotalKms, calculateMultiDayTrips
15
15
  } = require('./util/trips')
16
16
  const { devicesToProcess } = require('./util/device')
17
17
  const { getDriverData, reportByDriver } = require('./util/driver')
@@ -183,7 +183,7 @@ async function processDrivers (from, to, userData, data) {
183
183
  const driversResult = []
184
184
 
185
185
  for (const d of userData.drivers) {
186
- const { trips } = await getDriverData(d, data, userData)
186
+ const { trips, route } = await getDriverData(d, data, userData)
187
187
 
188
188
  if (trips.length > 0) {
189
189
  const driverData = {
@@ -198,6 +198,8 @@ async function processDrivers (from, to, userData, data) {
198
198
 
199
199
  const tripsByDay = trips.filter(t => (new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay))
200
200
 
201
+ calculateMultiDayTrips(trips, route, tripsByDay, fromByDay, toByDay, userData.devices)
202
+
201
203
  driverData.days.push({
202
204
  date,
203
205
  kms: tripsByDay.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0)
@@ -2,7 +2,7 @@ const traccarHelper = require('../util/traccar')
2
2
  const { getDriverData } = require('../util/driver')
3
3
  const { getCanDriverStyleMessages, parseCanDriverStyleMessage } = require('../util/xpert')
4
4
  const { calculateRPMSections } = require('./performance-report')
5
- const { getTranslations, isClientSide, convertToLocaleString } = require('../util/utils')
5
+ const { getTranslations, isClientSide, convertToLocaleString, convertMS } = require('../util/utils')
6
6
  const jsPDF = require('jspdf')
7
7
  const { headerFromUser, addTable } = require('../util/pdfDocument')
8
8
  const { getStyle } = require('../reportStyle')
@@ -200,7 +200,7 @@ async function exportToExcel (userData, reportData) {
200
200
  name: row.name,
201
201
  distance: Number(row.distance.toFixed(1)),
202
202
  avgFuelConsumption: Number(row.avgFuelConsumption.toFixed(2)),
203
- highEngineRPM: row.highEngineRPM,
203
+ highEngineRPM: convertMS(row.highEngineRPM, false),
204
204
  hardBraking: row.hardBraking,
205
205
  hardAcceleration: row.hardAcceleration,
206
206
  hardCornering: row.hardCornering,
@@ -257,9 +257,9 @@ async function exportToPDF (userData, reportData) {
257
257
  reportDataRows.forEach(function (row) {
258
258
  const temp = [
259
259
  row.name,
260
- row.distance,
261
- row.avgFuelConsumption,
262
- row.highEngineRPM,
260
+ row.distance.toFixed(1),
261
+ row.avgFuelConsumption.toFixed(2),
262
+ convertMS(row.highEngineRPM, false),
263
263
  row.hardBraking,
264
264
  row.hardAcceleration,
265
265
  row.hardCornering,
@@ -268,7 +268,7 @@ async function exportToPDF (userData, reportData) {
268
268
  row.continuesDrivingAlarm,
269
269
  row.reverseAlarm,
270
270
  row.otherAlarm,
271
- row.score
271
+ row.score.toFixed(2)
272
272
  ]
273
273
  data.push(temp)
274
274
  })
@@ -276,7 +276,20 @@ async function exportToPDF (userData, reportData) {
276
276
 
277
277
  const style = getStyle(getUserPartner(userData.user))
278
278
 
279
- addTable(doc, headers, data, footValues, style, 40)
279
+ addTable(doc, headers, data, footValues, style, 40, {
280
+ 1: { halign: 'right' },
281
+ 2: { halign: 'right' },
282
+ 3: { halign: 'right' },
283
+ 4: { halign: 'right' },
284
+ 5: { halign: 'right' },
285
+ 6: { halign: 'right' },
286
+ 7: { halign: 'right' },
287
+ 8: { halign: 'right' },
288
+ 9: { halign: 'right' },
289
+ 10: { halign: 'right' },
290
+ 11: { halign: 'right' },
291
+ 12: { halign: 'right' }
292
+ })
280
293
  return doc
281
294
  }
282
295
  }
package/src/util/trips.js CHANGED
@@ -152,6 +152,7 @@ function getUncompletedTrip (device, deviceRoute, deviceTrips) {
152
152
  }
153
153
 
154
154
  function calculateTrip (device, route) {
155
+ console.log('route', route.length)
155
156
  const startPos = route[0]
156
157
  const endPos = route[route.length - 1]
157
158
 
@@ -235,6 +236,22 @@ function getTripTotalKms (trip, stop, route) {
235
236
  return distance / 1000
236
237
  }
237
238
 
239
+ function calculateMultiDayTrips (trips, route, tripsByDay, fromByDay, toByDay, devices) {
240
+ const startsOutside = trips.filter(t => (new Date(t.startTime) < fromByDay && new Date(t.endTime) > fromByDay))
241
+ if (startsOutside.length > 0) {
242
+ tripsByDay.push(calculateTrip(devices.find(d => d.id === startsOutside[0].deviceId),
243
+ route.filter(p => new Date(p.fixTime) >= fromByDay &&
244
+ new Date(p.fixTime) <= new Date(startsOutside[0].endTime))))
245
+ }
246
+
247
+ const endsOutside = trips.filter(t => (new Date(t.startTime) < toByDay && new Date(t.endTime) > toByDay))
248
+ if (endsOutside.length > 0) {
249
+ tripsByDay.push(calculateTrip(devices.find(d => d.id === endsOutside[0].deviceId),
250
+ route.filter(p => new Date(p.fixTime) >= new Date(endsOutside[0].startTime) &&
251
+ new Date(p.fixTime) <= toByDay)))
252
+ }
253
+ }
254
+
238
255
  exports.isInsideTimetable = isInsideTimetable
239
256
  exports.isPartialInsideTimetable = isPartialInsideTimetable
240
257
  exports.getDataByDay = getDataByDay
@@ -245,3 +262,4 @@ exports.getTripIdleTime = getTripIdleTime
245
262
  exports.calculateStopDuration = calculateStopDuration
246
263
  exports.getUncompletedTrip = getUncompletedTrip
247
264
  exports.getTripTotalKms = getTripTotalKms
265
+ exports.calculateMultiDayTrips = calculateMultiDayTrips