fleetmap-reports 1.0.233 → 1.0.237

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/src/index.js CHANGED
@@ -23,7 +23,7 @@ function Reports(config, axios) {
23
23
  return require('./speeding-report').createSpeedingReport(from, to, userData, this.traccar, roadSpeedLimits)
24
24
  }
25
25
 
26
- this.speedingReportToPDF = (userData, reportData) => {
26
+ this.speedingReportToPDF = async (userData, reportData) => {
27
27
  return require('./speeding-report').exportSpeedingReportToPDF(userData, reportData)
28
28
  }
29
29
 
package/src/index.test.js CHANGED
@@ -1,27 +1,22 @@
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();
1
+ const {getReports} = require("./tests");
7
2
 
8
- axiosCookieJarSupport(axios)
3
+ describe('speedingReport', function() {
4
+ this.timeout(500000)
5
+ it('test speeding', async () => {
6
+ const report = await getReports()
7
+ const userData = await report.getUserData()
9
8
 
10
- test('speedingReport', async () => {
11
- const traccarConfig = {
12
- basePath: 'https://api.pinme.io/api',
13
- baseOptions: {
14
- withCredentials: true,
15
- jar: cookieJar
16
- }
17
- }
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
+ const reportData = await reports.kmsReport(new Date(2021, 10, 1), new Date(2021, 10, 3),
18
+ userData)
18
19
 
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)
20
+ await reports.kmsReportToPDF(userData, reportData[0])
21
+ })
22
+ })
package/src/kms-report.js CHANGED
@@ -6,6 +6,7 @@ const {getStyle} = require("./reportStyle");
6
6
  const {headerFromUser,addTable} = require("./util/pdfDocument");
7
7
  const {getUserPartner} = require("fleetmap-partners");
8
8
  const automaticReports = require("./automaticReports");
9
+ const {jsPDFOptions} = require("jspdf");
9
10
 
10
11
 
11
12
  let traccarInstance
@@ -28,7 +29,9 @@ async function createKmsReportByDevice(from, to, userData) {
28
29
  const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
29
30
  let data = []
30
31
  for (const a of arrayOfArrays) {
32
+ console.log('getting',from,to,a.map(a => a.id))
31
33
  const response = await traccarInstance.reports.reportsRouteGet(from, to, a.map(d => d.id))
34
+ console.log('concat', response.data.length)
32
35
  data = data.concat(response.data)
33
36
  }
34
37
 
@@ -132,8 +135,8 @@ async function exportKmsReportToPDF(userData, reportData) {
132
135
  }
133
136
  if (kmsData) {
134
137
  let first = true
135
- const doc = userData.groupByDay ? new jsPDF.jsPDF() : new jsPDF.jsPDF('l')
136
- await headerFromUser(doc, translations.report.titleKmsReport, userData.user)
138
+ const doc = userData.groupByDay ? new jsPDF.jsPDF('p') : new jsPDF.jsPDF('l')
139
+ await headerFromUser(doc, translations.report.titleKmsReport, userData.user, 'p')
137
140
 
138
141
  if (userData.groupByDay) {
139
142
  for (const d of kmsData) {
@@ -156,7 +159,7 @@ async function exportKmsReportToPDF(userData, reportData) {
156
159
  const data = []
157
160
  d.days.forEach(day => {
158
161
  const temp = [
159
- new Date(day.date).toLocaleDateString(),
162
+ day.date,
160
163
  (day.kms/1000).toFixed(0)
161
164
  ]
162
165
 
@@ -240,6 +243,7 @@ function exportKmsReportToExcel(userData, reportData) {
240
243
  if(userData.groupByDay) {
241
244
  headers.push(
242
245
  {label: translations.report.vehicle, value: 'name'},
246
+ {label: translations.report.licensePlate, value: 'licenseplate'},
243
247
  {label: translations.report.group, value: 'group'},
244
248
  {label: translations.report.date, value: 'date'},
245
249
  {label: translations.report.distance, value: 'distance'})
@@ -250,8 +254,8 @@ function exportKmsReportToExcel(userData, reportData) {
250
254
  {label: translations.report.distance, value: 'distance'})
251
255
  } else {
252
256
  headers.push(
253
- {label: translations.report.driver, value: 'name'},
254
- {label: translations.settings.vehicle_licenseplate, value: 'licenseplate'},
257
+ {label: translations.report.vehicle, value: 'name'},
258
+ {label: translations.report.licensePlate, value: 'licenseplate'},
255
259
  {label: translations.report.group, value: 'group'},
256
260
  {label: translations.report.distance, value: 'distance'})
257
261
  }
@@ -262,25 +266,25 @@ function exportKmsReportToExcel(userData, reportData) {
262
266
  const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.driver.id)) :
263
267
  userData.groups.find(g => d.device.groupId === g.id)
264
268
 
265
- if (userData.groupByDay) {
266
- data = data.concat([{}])
267
- data = data.concat(d.days.map(a => {
268
- return {
269
- name: userData.byDriver ? d.driver.name : d.device.name,
270
- group: group ? group.name : '',
271
- licenseplate: d.device.attributes.license_plate,
272
- date: a.date,
273
- distance: Number((a.kms / 1000).toFixed(0))
274
- }
275
- }))
276
- } else {
277
- data = data.concat([{
278
- name: userData.byDriver ? d.driver.name : d.summary.deviceName,
269
+ if (userData.groupByDay) {
270
+ data = data.concat([{}])
271
+ data = data.concat(d.days.map(a => {
272
+ return {
273
+ name: d.device.name,
279
274
  group: group ? group.name : '',
280
275
  licenseplate: d.device.attributes.license_plate,
281
- distance: Number((d.summary.distance / 1000).toFixed(0))
282
- }])
283
- }
276
+ date: a.date,
277
+ distance: Number((a.kms / 1000).toFixed(0))
278
+ }
279
+ }))
280
+ } else {
281
+ data = data.concat([{
282
+ name: userData.byDriver ? d.driver.name : d.summary.deviceName,
283
+ group: group ? group.name : '',
284
+ licenseplate: userData.byDriver ? '' : d.device.attributes.license_plate,
285
+ distance: Number((d.summary.distance / 1000).toFixed(0))
286
+ }])
287
+ }
284
288
  })
285
289
 
286
290
  return {
@@ -139,7 +139,7 @@ async function exportLocationReportToPDF(userData, reportData) {
139
139
  doc.text(new Date(d.from).toLocaleString() + ' - ' + new Date(d.to).toLocaleString(), 20, space + 25)
140
140
  d.positions.map(a => {
141
141
  const temp = [
142
- a.fixTime,
142
+ getLocationDate(a, userData.user),
143
143
  a.address,
144
144
  Math.round(a.speed * 1.85200),
145
145
  a.attributes.ignition ? translations.report.ignitionOn : translations.report.ignitionOff,
@@ -0,0 +1,22 @@
1
+ const {SessionApi} = require("traccar-api");
2
+ const axios = require('axios')
3
+ const axiosCookieJarSupport = require('axios-cookiejar-support').default;
4
+ const tough = require('tough-cookie');
5
+ const Index = require('../index');
6
+ const cookieJar = new tough.CookieJar();
7
+ const traccarConfig = {
8
+ basePath: 'https://api.pinme.io/api',
9
+ baseOptions: {
10
+ withCredentials: true,
11
+ jar: cookieJar
12
+ }
13
+ }
14
+
15
+ axiosCookieJarSupport(axios)
16
+
17
+ exports.getReports = async() => {
18
+ await new SessionApi(traccarConfig, null, axios).sessionPost(process.env.email, process.env.password)
19
+ return new Index(traccarConfig, axios)
20
+ }
21
+
22
+
@@ -3,7 +3,7 @@ const {getStyle} = require("../reportStyle");
3
3
  const {getUserPartner} = require("fleetmap-partners");
4
4
  const {getImgFromUrl} = require("./utils")
5
5
 
6
- async function header(doc, title, hostname, style) {
6
+ async function header(doc, title, hostname, style, orientation) {
7
7
  doc.setFontSize(16)
8
8
  doc.setFont('helvetica', 'bold')
9
9
  doc.text(title, 15, 15 )
@@ -12,7 +12,7 @@ async function header(doc, title, hostname, style) {
12
12
  try{
13
13
  const image = await getImgFromUrl(hostname)
14
14
  if(image){
15
- doc.addImage(image, 'PNG', 220 + (style.imgWidth < 50 ? 25 : 0), 5, style.imgWidth, style.imgHeight)
15
+ doc.addImage(image, 'PNG', (orientation === 'l' ? 220 : 135) + (style.imgWidth < 50 ? 25 : 0), 5, style.imgWidth, style.imgHeight)
16
16
  }
17
17
  } catch (e) {
18
18
  }
@@ -20,9 +20,9 @@ async function header(doc, title, hostname, style) {
20
20
  doc.setFont('helvetica', 'normal')
21
21
  }
22
22
 
23
- async function headerFromUser(doc, title, user) {
23
+ async function headerFromUser(doc, title, user, orientation='l') {
24
24
  const partner = getUserPartner(user)
25
- return header(doc, title, partner.host, getStyle(partner))
25
+ return header(doc, title, partner.host, getStyle(partner), orientation)
26
26
  }
27
27
 
28
28
  function addTable(doc, headers, data, footValues, style, startY){
@@ -1,7 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <code_scheme name="Project" version="173">
3
- <ScalaCodeStyleSettings>
4
- <option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
5
- </ScalaCodeStyleSettings>
6
- </code_scheme>
7
- </component>
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
- </state>
5
- </component>
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="JavaScriptLibraryMappings">
4
- <file url="file://$PROJECT_DIR$" libraries="{Node.js Core}" />
5
- </component>
6
- </project>