fleetmap-reports 1.0.612 → 1.0.613

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": "1.0.612",
3
+ "version": "1.0.613",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -152,19 +152,20 @@ async function exportSpeedingReportToPDF (userData, reportData) {
152
152
  doc.text(group, 200, space + 20)
153
153
  doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space + 25)
154
154
 
155
+ const headerEventTypes = []
156
+ userData.eventTypes.forEach(e => {
157
+ const data = e.startsWith('alarm') ? { type: 'alarm', attributes: { alarm: e.slice(6) } } : { type: e }
158
+ const value = e.startsWith('alarm') ? d.alerts.filter(a => a.attributes.alarm === data.attributes.alarm).length : d.alerts.filter(a => a.type === e).length
159
+ headerEventTypes.push([getEventType(data, translations, d.device), value])
160
+ })
161
+
155
162
  doc.autoTable({
156
163
  head: ['', '', '', '', ''],
157
164
  body: [
158
- [translations.report.event_ignitionOn, translations.report.event_ignitionOff, translations.report.event_geofenceEnter,
159
- translations.report.event_geofenceExit, translations.report.event_deviceOverspeed],
160
- [d.alerts.filter(a => a.type === 'ignitionOn').length, d.alerts.filter(a => a.type === 'ignitionOff').length,
161
- d.alerts.filter(a => a.type === 'geofenceEnter').length, d.alerts.filter(a => a.type === 'geofenceExit').length,
162
- d.alerts.filter(a => a.type === 'deviceOverspeed').length],
163
- [translations.report.event_driverChanged, translations.report.event_powerOn, translations.report.event_sos,
164
- translations.report.event_deviceFuelDrop, translations.report.eve],
165
- [d.alerts.filter(a => a.type === 'driverChanged').length, d.alerts.filter(a => a.type === 'powerOn').length,
166
- d.alerts.filter(a => a.type === 'sos').length, d.alerts.filter(a => a.type === 'deviceFuelDrop').length,
167
- d.alerts.filter(a => a.type === 'powerCut').length]
165
+ headerEventTypes.slice(0, 6).map(a => a[0]),
166
+ headerEventTypes.slice(0, 6).map(a => a[1]),
167
+ headerEventTypes.slice(7).map(a => a[0]),
168
+ headerEventTypes.slice(7).map(a => a[1])
168
169
  ],
169
170
  startY: space + 30,
170
171
  showHead: false,
@@ -173,9 +174,7 @@ async function exportSpeedingReportToPDF (userData, reportData) {
173
174
  })
174
175
  d.alerts.forEach(a => {
175
176
  const temp = [
176
- a.type === 'alarm'
177
- ? getEventType(a, translations, d.device)
178
- : translations.report['event_' + a.type],
177
+ getEventType(a, translations, d.device),
179
178
  getAlertDate(userData.user, a),
180
179
  a.geofenceName || (a.position ? a.position.address : ''),
181
180
  getAlertInfo(userData.drivers, a, d.device, translations)
@@ -217,9 +216,13 @@ async function exportSpeedingReportToPDF (userData, reportData) {
217
216
  }
218
217
 
219
218
  function getEventType (a, translations, device) {
220
- let sensor
221
- if (a.attributes.alarm === 'sensor') { sensor = device.attributes.sensor1 }
222
- return sensor || translations.report['event_' + a.attributes.alarm] || a.attributes.alarm
219
+ if (a.type === 'alarm') {
220
+ let sensor
221
+ if (a.attributes.alarm === 'sensor') { sensor = device.attributes.sensor1 }
222
+ return sensor || translations.report['event_' + a.attributes.alarm] || a.attributes.alarm
223
+ } else {
224
+ return translations.report['event_' + a.type]
225
+ }
223
226
  }
224
227
 
225
228
  function exportSpeedingReportToExcel (userData, reportData) {
@@ -247,9 +250,7 @@ function exportSpeedingReportToExcel (userData, reportData) {
247
250
  data = data.concat(d.alerts.map(a => {
248
251
  return {
249
252
  name: d.device.name,
250
- eventType: a.type === 'alarm'
251
- ? getEventType(a, translations, d.device)
252
- : translations.report['event_' + a.type],
253
+ eventType: getEventType(a, translations, d.device),
253
254
  fixTime: getAlertDate(userData.user, a),
254
255
  address: a.geofenceName || (a.position ? a.position.address : ''),
255
256
  info: getAlertInfo(userData.drivers, a, d.device, translations),