fleetmap-reports 1.0.284 → 1.0.288

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.
@@ -3,7 +3,7 @@ const moment = require('moment')
3
3
  function sliceArray(longArray) {
4
4
  const arrayToSlice = longArray.slice()
5
5
 
6
- const size = 10
6
+ const size = 200
7
7
  const arrayOfArrays = []
8
8
  for (let i=0; i<arrayToSlice.length; i+=size) {
9
9
  arrayOfArrays.push(arrayToSlice.slice(i,i+size));
@@ -1,11 +1,8 @@
1
1
  const automaticReports = require("./automaticReports")
2
2
  const messages = require('../lang')
3
3
  const jsPDF = require('jspdf')
4
- require('jspdf-autotable')
5
- const {getStyle} = require("./reportStyle");
6
- const {headerFromUser} = require("./util/pdfDocument");
7
- const {getUserPartner} = require("fleetmap-partners");
8
- const {convertToLocaleString} = require("./util/utils");
4
+ const autotable = require('jspdf-autotable')
5
+ const reportStyle = require("./reportStyle")
9
6
 
10
7
  const fileName = 'EventReport'
11
8
 
@@ -117,11 +114,10 @@ async function processDevices(from, to, devices, geofences, drivers, data) {
117
114
  return devicesResult
118
115
  }
119
116
 
120
- async function exportSpeedingReportToPDF(userData, reportData) {
117
+ function exportSpeedingReportToPDF(userData, reportData) {
121
118
  console.log('Export to PDF')
122
119
 
123
120
  const lang = userData.user.attributes.lang
124
- const timezone = userData.user.attributes.timezone
125
121
  const translations = messages[lang] ? messages[lang] : messages['en-GB']
126
122
 
127
123
  const headers = [
@@ -133,7 +129,8 @@ async function exportSpeedingReportToPDF(userData, reportData) {
133
129
  if (reportData.devices) {
134
130
  let first = true
135
131
  const doc = new jsPDF.jsPDF('l');
136
- await headerFromUser(doc, translations.report.titleEventsReport, userData.user)
132
+ doc.setFontSize(14)
133
+ doc.text(translations.report.titleEventsReport, 15, 15 )
137
134
 
138
135
  reportData.devices.forEach(d => {
139
136
  let data = []
@@ -147,11 +144,12 @@ async function exportSpeedingReportToPDF(userData, reportData) {
147
144
  first = false
148
145
  space = 10
149
146
  }
150
- doc.setFontSize(13)
147
+ doc.setFontSize(12)
148
+
151
149
  doc.text(name, 20, space+20 )
152
- doc.setFontSize(11)
150
+ doc.setFontSize(10)
153
151
  doc.text(group, 200, space+20 )
154
- doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space+25 )
152
+ doc.text(new Date(d.from).toLocaleString() + ' - ' + new Date(d.to).toLocaleString(), 20, space+25 )
155
153
 
156
154
  doc.autoTable(['','','','',''], [
157
155
  [translations.report.event_ignitionOn,translations.report.event_ignitionOff, translations.report.event_geofenceEnter,
@@ -160,10 +158,9 @@ async function exportSpeedingReportToPDF(userData, reportData) {
160
158
  d.alerts.filter(a => a.type === 'geofenceEnter').length,d.alerts.filter(a => a.type === 'geofenceExit').length,
161
159
  d.alerts.filter(a => a.type === 'deviceOverspeed').length],
162
160
  [translations.report.event_driverChanged,translations.report.event_powerOn, translations.report.event_sos,
163
- translations.report.event_deviceFuelDrop, translations.report.eve],
161
+ translations.report.event_deviceFuelDrop],
164
162
  [d.alerts.filter(a => a.type === 'driverChanged').length,d.alerts.filter(a => a.type === 'powerOn').length,
165
- d.alerts.filter(a => a.type === 'sos').length,d.alerts.filter(a => a.type === 'deviceFuelDrop').length,
166
- d.alerts.filter(a => a.type === 'powerCut').length]
163
+ d.alerts.filter(a => a.type === 'sos').length,d.alerts.filter(a => a.type === 'deviceFuelDrop').length]
167
164
  ], { startY: space+30 , showHead: false, bodyStyles: { fillColor: [256, 256, 256], textColor: [30, 30, 30], halign: 'center', valign: 'middle' } , alternateRowStyles: {fillColor: [256, 256, 256], valign: 'bottom'}});
168
165
 
169
166
  d.alerts.map(a => {
@@ -181,26 +178,22 @@ async function exportSpeedingReportToPDF(userData, reportData) {
181
178
  '','',''
182
179
  ]
183
180
 
184
- const style = getStyle(getUserPartner(userData.user))
185
181
  doc.autoTable({
186
182
  head: [headers],
187
183
  body: data,
188
184
  foot: [footValues],
189
185
  showFoot: 'lastPage',
190
186
  headStyles: {
191
- fillColor: style.pdfHeaderColor,
192
- textColor: style.pdfHeaderTextColor,
193
- fontSize: 10
187
+ fillColor: reportStyle.pdfHeaderColor,
188
+ textColor: reportStyle.pdfHeaderTextColor
194
189
  },
195
190
  bodyStyles: {
196
- fillColor: style.pdfBodyColor,
197
- textColor: style.pdfBodyTextColor,
198
- fontSize: 8
191
+ fillColor: reportStyle.pdfBodyColor,
192
+ textColor: reportStyle.pdfBodyTextColor
199
193
  },
200
194
  footStyles: {
201
- fillColor: style.pdfFooterColor,
202
- textColor: style.pdfFooterTextColor,
203
- fontSize: 9
195
+ fillColor: reportStyle.pdfFooterColor,
196
+ textColor: reportStyle.pdfFooterTextColor
204
197
  },
205
198
  startY: space + 65
206
199
  })
@@ -272,7 +265,10 @@ function getAlertInfo(drivers, alert) {
272
265
 
273
266
  function getAlertDate(user, alert) {
274
267
  if(alert.position) {
275
- return convertToLocaleString(alert.position.fixTime, user.attributes.lang, user.attributes.timezone)
268
+ return new Date(alert.position.fixTime).toLocaleString(user.attributes.lang, {
269
+ timeZone: user.attributes.timezone,
270
+ hour12: false
271
+ })
276
272
  }
277
273
  }
278
274
 
package/src/here.js CHANGED
@@ -97,10 +97,10 @@ function fillGeocoding(rows) {
97
97
  }*/
98
98
 
99
99
  exports.routeMatch = async (rows) => {
100
- console.log('here sending', rows.length)
101
100
  const csv = generateCSV(rows)
102
101
  const response = await axios.post(calcRoute, csv, { headers: { 'Content-Type': 'application/binary' }})
103
102
  const hereData = response.data
103
+ console.dir(hereData, {depth: null})
104
104
  const route = hereData.response.route[0]
105
105
  const results = []
106
106
  const wayPoints = route.waypoint
package/src/index.js CHANGED
@@ -19,8 +19,8 @@ function Reports(config, axios) {
19
19
  byGroup: false
20
20
  }
21
21
  }
22
- this.speedingReport = (from, to, userData) => {
23
- return require('./speeding-report').createSpeedingReport(from, to, userData, this.traccar)
22
+ this.speedingReport = (from, to, userData, roadSpeedLimits) => {
23
+ return require('./speeding-report').createSpeedingReport(from, to, userData, this.traccar, roadSpeedLimits)
24
24
  }
25
25
 
26
26
  this.speedingReportToPDF = (userData, reportData) => {
@@ -124,16 +124,6 @@ function Reports(config, axios) {
124
124
  this.vistaWasteActivityReportToExcel = (userData, reportData) => {
125
125
  return require('./custom/vistawasteActivity-report').exportVistaWasteActivityReportToExcel(userData, reportData)
126
126
  }
127
-
128
- this.idleReport = (from, to, userData) => {
129
- return require('./idle-report').createIdleReport(from, to, userData, this.traccar)
130
- }
131
- this.idleReportToPDF = (userData, reportData) => {
132
- return require('./idle-report').exportIdleReportToPDF(userData, reportData)
133
- }
134
- this.idleReportToExcel = (userData, reportData) => {
135
- return require('./idle-report').exportIdleReportToExcel(userData, reportData)
136
- }
137
127
  }
138
128
  module.exports = Reports
139
129
 
package/src/index.test.js CHANGED
@@ -1,20 +1,27 @@
1
- const {getReports} = require("./tests");
1
+ const Index = require('./index')
2
+ const {SessionApi} = require("traccar-api");
3
+ const axios = require('axios')
4
+ const axiosCookieJarSupport = require('axios-cookiejar-support').default;
5
+ const tough = require('tough-cookie');
6
+ const cookieJar = new tough.CookieJar();
2
7
 
3
- describe('speedingReport', function() {
4
- this.timeout(500000)
5
- it('test speeding', async () => {
6
- const report = await getReports()
7
- const userData = await report.getUserData()
8
+ axiosCookieJarSupport(axios)
8
9
 
9
- await report.speedingReport(new Date(2021, 2, 30, 0, 0, 0, 0),
10
- new Date(2021, 2, 30, 23, 59, 59, 0),
11
- userData)
12
- })
13
- it('test kmsReport by day', async () => {
14
- const reports = await getReports()
15
- const userData = await reports.getUserData()
16
- userData.groupByDay = true
17
- await reports.kmsReport(new Date(2021, 9), new Date(2021, 10),
18
- userData)
19
- })
20
- })
10
+ test('speedingReport', async () => {
11
+ const traccarConfig = {
12
+ basePath: 'https://api.pinme.io/api',
13
+ baseOptions: {
14
+ withCredentials: true,
15
+ jar: cookieJar
16
+ }
17
+ }
18
+
19
+ await new SessionApi(traccarConfig, null, axios).sessionPost('-','-')
20
+ const report = new Index(traccarConfig, axios)
21
+ const userData = await report.getUserData()
22
+
23
+ await report.speedingReport(new Date(2021, 2, 30, 0, 0, 0, 0),
24
+ new Date(2021, 2, 30, 23, 59, 59, 0),
25
+ userData)
26
+
27
+ }, 10000)