fleetmap-reports 1.0.208 → 1.0.212

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.
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="RunConfigurationProducerService">
4
+ <option name="ignoredProducers">
5
+ <set>
6
+ <option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
7
+ </set>
8
+ </option>
9
+ </component>
10
+ </project>
@@ -0,0 +1,193 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ChangeListManager">
4
+ <list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="try catch on pdf addImage">
5
+ <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
6
+ <change beforePath="$PROJECT_DIR$/src/activity-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/activity-report.js" afterDir="false" />
7
+ <change beforePath="$PROJECT_DIR$/src/index.test.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.test.js" afterDir="false" />
8
+ <change beforePath="$PROJECT_DIR$/src/kms-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/kms-report.js" afterDir="false" />
9
+ <change beforePath="$PROJECT_DIR$/src/util/pdfDocument.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/util/pdfDocument.js" afterDir="false" />
10
+ </list>
11
+ <option name="SHOW_DIALOG" value="false" />
12
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
13
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
14
+ <option name="LAST_RESOLUTION" value="IGNORE" />
15
+ </component>
16
+ <component name="Git.Settings">
17
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
18
+ </component>
19
+ <component name="ProjectId" id="20NIxbej0qfi8RaO3jr1XOU0xol" />
20
+ <component name="ProjectViewState">
21
+ <option name="hideEmptyMiddlePackages" value="true" />
22
+ <option name="showLibraryContents" value="true" />
23
+ </component>
24
+ <component name="PropertiesComponent">
25
+ <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
26
+ <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
27
+ <property name="WebServerToolWindowFactoryState" value="false" />
28
+ <property name="last_opened_file_path" value="$PROJECT_DIR$" />
29
+ <property name="nodejs.mocha.mocha_node_package_dir" value="$PROJECT_DIR$/node_modules/mocha" />
30
+ <property name="nodejs_package_manager_path" value="npm" />
31
+ <property name="ts.external.directory.path" value="$APPLICATION_HOME_DIR$/plugins/JavaScriptLanguage/jsLanguageServicesImpl/external" />
32
+ <property name="vue.rearranger.settings.migration" value="true" />
33
+ </component>
34
+ <component name="RunManager" selected="Mocha.test reports">
35
+ <configuration name="here" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
36
+ <node-interpreter>project</node-interpreter>
37
+ <node-options />
38
+ <mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
39
+ <working-directory>$PROJECT_DIR$</working-directory>
40
+ <pass-parent-env>true</pass-parent-env>
41
+ <ui>bdd</ui>
42
+ <extra-mocha-options />
43
+ <test-kind>SUITE</test-kind>
44
+ <test-file>$PROJECT_DIR$/src/index.test.js</test-file>
45
+ <test-names>
46
+ <name value="here" />
47
+ </test-names>
48
+ <method v="2" />
49
+ </configuration>
50
+ <configuration name="report" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
51
+ <node-interpreter>project</node-interpreter>
52
+ <node-options />
53
+ <mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
54
+ <working-directory>$PROJECT_DIR$</working-directory>
55
+ <pass-parent-env>true</pass-parent-env>
56
+ <ui>bdd</ui>
57
+ <extra-mocha-options />
58
+ <test-kind>SUITE</test-kind>
59
+ <test-file>$PROJECT_DIR$/src/index.test.js</test-file>
60
+ <test-names>
61
+ <name value="report" />
62
+ </test-names>
63
+ <method v="2" />
64
+ </configuration>
65
+ <configuration name="speedingReport" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
66
+ <node-interpreter>project</node-interpreter>
67
+ <node-options />
68
+ <mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
69
+ <working-directory>$PROJECT_DIR$</working-directory>
70
+ <pass-parent-env>true</pass-parent-env>
71
+ <ui>bdd</ui>
72
+ <extra-mocha-options />
73
+ <test-kind>TEST</test-kind>
74
+ <test-file>$PROJECT_DIR$/src/index.test.js</test-file>
75
+ <test-names>
76
+ <name value="speedingReport" />
77
+ </test-names>
78
+ <method v="2" />
79
+ </configuration>
80
+ <configuration name="test reports" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
81
+ <node-interpreter>project</node-interpreter>
82
+ <node-options />
83
+ <mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
84
+ <working-directory>$PROJECT_DIR$</working-directory>
85
+ <pass-parent-env>true</pass-parent-env>
86
+ <ui>bdd</ui>
87
+ <extra-mocha-options />
88
+ <test-kind>SUITE</test-kind>
89
+ <test-file>$PROJECT_DIR$/src/index.test.js</test-file>
90
+ <test-names>
91
+ <name value="test reports" />
92
+ </test-names>
93
+ <method v="2" />
94
+ </configuration>
95
+ <configuration name="test reports.test queue" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
96
+ <node-interpreter>project</node-interpreter>
97
+ <node-options />
98
+ <mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
99
+ <working-directory>$PROJECT_DIR$</working-directory>
100
+ <pass-parent-env>true</pass-parent-env>
101
+ <ui>bdd</ui>
102
+ <extra-mocha-options />
103
+ <test-kind>TEST</test-kind>
104
+ <test-file>$PROJECT_DIR$/src/index.test.js</test-file>
105
+ <test-names>
106
+ <name value="test reports" />
107
+ <name value="test queue" />
108
+ </test-names>
109
+ <method v="2" />
110
+ </configuration>
111
+ <recent_temporary>
112
+ <list>
113
+ <item itemvalue="Mocha.test reports" />
114
+ <item itemvalue="Mocha.test reports.test queue" />
115
+ <item itemvalue="Mocha.speedingReport" />
116
+ <item itemvalue="Mocha.report" />
117
+ <item itemvalue="Mocha.here" />
118
+ </list>
119
+ </recent_temporary>
120
+ </component>
121
+ <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
122
+ <component name="TaskManager">
123
+ <task active="true" id="Default" summary="Default task">
124
+ <changelist id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="" />
125
+ <created>1635878866368</created>
126
+ <option name="number" value="Default" />
127
+ <option name="presentableId" value="Default" />
128
+ <updated>1635878866368</updated>
129
+ <workItem from="1635878870054" duration="105000" />
130
+ <workItem from="1635943211865" duration="371000" />
131
+ <workItem from="1636030918716" duration="808000" />
132
+ <workItem from="1636366400735" duration="3018000" />
133
+ <workItem from="1636371409243" duration="45000" />
134
+ <workItem from="1636371621773" duration="4750000" />
135
+ <workItem from="1636623371114" duration="675000" />
136
+ <workItem from="1636624396937" duration="1987000" />
137
+ <workItem from="1636627666406" duration="1616000" />
138
+ <workItem from="1636647112207" duration="1748000" />
139
+ <workItem from="1636981640447" duration="4315000" />
140
+ <workItem from="1637009407292" duration="1470000" />
141
+ <workItem from="1637012863006" duration="5376000" />
142
+ <workItem from="1637087797229" duration="5701000" />
143
+ <workItem from="1637227826845" duration="1275000" />
144
+ <workItem from="1637441942952" duration="4543000" />
145
+ <workItem from="1637670815688" duration="2973000" />
146
+ <workItem from="1637674107929" duration="8163000" />
147
+ </task>
148
+ <task id="LOCAL-00001" summary="Fix getStyle">
149
+ <created>1636983717385</created>
150
+ <option name="number" value="00001" />
151
+ <option name="presentableId" value="LOCAL-00001" />
152
+ <option name="project" value="LOCAL" />
153
+ <updated>1636983717385</updated>
154
+ </task>
155
+ <task id="LOCAL-00002" summary="Fix getStyle in all reports">
156
+ <created>1637020728356</created>
157
+ <option name="number" value="00002" />
158
+ <option name="presentableId" value="LOCAL-00002" />
159
+ <option name="project" value="LOCAL" />
160
+ <updated>1637020728356</updated>
161
+ </task>
162
+ <task id="LOCAL-00003" summary="try catch on pdf addImage">
163
+ <created>1637247013210</created>
164
+ <option name="number" value="00003" />
165
+ <option name="presentableId" value="LOCAL-00003" />
166
+ <option name="project" value="LOCAL" />
167
+ <updated>1637247013211</updated>
168
+ </task>
169
+ <option name="localTasksCounter" value="4" />
170
+ <servers />
171
+ </component>
172
+ <component name="TypeScriptGeneratedFilesManager">
173
+ <option name="version" value="3" />
174
+ </component>
175
+ <component name="Vcs.Log.Tabs.Properties">
176
+ <option name="TAB_STATES">
177
+ <map>
178
+ <entry key="MAIN">
179
+ <value>
180
+ <State />
181
+ </value>
182
+ </entry>
183
+ </map>
184
+ </option>
185
+ <option name="oldMeFiltersMigrated" value="true" />
186
+ </component>
187
+ <component name="VcsManagerConfiguration">
188
+ <MESSAGE value="Fix getStyle" />
189
+ <MESSAGE value="Fix getStyle in all reports" />
190
+ <MESSAGE value="try catch on pdf addImage" />
191
+ <option name="LAST_COMMIT_MESSAGE" value="try catch on pdf addImage" />
192
+ </component>
193
+ </project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.208",
3
+ "version": "1.0.212",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -2,11 +2,11 @@ const automaticReports = require("./automaticReports")
2
2
  const messages = require('../lang')
3
3
  const {convertMS} = require("./util/utils")
4
4
  const jsPDF = require('jspdf')
5
- const autotable = require('jspdf-autotable')
6
- const reportStyle = require("./reportStyle")
5
+ require('jspdf-autotable')
7
6
  const drivers = require("./util/driver");
8
- const {header} = require("./util/pdfDocument");
7
+ const {headerFromUser} = require("./util/pdfDocument");
9
8
  const {getStyle} = require("./reportStyle");
9
+ const {getUserPartner} = require("fleetmap-partners");
10
10
 
11
11
  let traccarInstance
12
12
 
@@ -71,18 +71,18 @@ async function createActivityReportByGroup(from, to, userData){
71
71
 
72
72
  async function createActivityReportByDevice(from, to, userData){
73
73
  const groupIds = userData.groups.map(g => g.id)
74
- const withoutGroupDevices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
74
+ const devicesToProcess = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
75
75
 
76
76
  const allData = {
77
77
  devices: [],
78
- xpert: withoutGroupDevices.filter(d => d.attributes.xpert).length > 0,
78
+ xpert: devicesToProcess.filter(d => d.attributes.xpert).length > 0,
79
79
  from: from,
80
80
  to: to
81
81
  }
82
82
 
83
- withoutGroupDevices.sort((a, b) => (a.name > b.name) ? 1 : -1)
84
- const devicesToSlice = withoutGroupDevices.slice()
85
-
83
+ //Get report data from traccar
84
+ devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
85
+ const devicesToSlice = devicesToProcess.slice()
86
86
  const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
87
87
  let data = []
88
88
  let trips = []
@@ -96,12 +96,11 @@ async function createActivityReportByDevice(from, to, userData){
96
96
 
97
97
  console.log('Summary:' + data.length)
98
98
 
99
- if (data.length === 0) {
100
- return allData
99
+ //Process report data
100
+ if (data.length > 0) {
101
+ allData.devices = processDevices(devicesToProcess, data, trips)
101
102
  }
102
103
 
103
- allData.devices = processDevices(withoutGroupDevices, data, trips)
104
-
105
104
  return allData
106
105
  }
107
106
 
@@ -173,8 +172,6 @@ async function exportActivityReportToPDF(userData, reportData) {
173
172
 
174
173
  const lang = userData.user.attributes.lang
175
174
  const translations = messages[lang] ? messages[lang] : messages['en-GB']
176
- const hostname = userData.user.attributes.lastHost
177
- const style = getStyle(hostname)
178
175
 
179
176
  const headers = []
180
177
  if(userData.byDriver) {
@@ -196,7 +193,7 @@ async function exportActivityReportToPDF(userData, reportData) {
196
193
  }
197
194
  if (reportData.devices || reportData.drivers) {
198
195
  const doc = new jsPDF.jsPDF('l')
199
- await header(doc, translations.report.titleActivityReport, hostname, style)
196
+ await headerFromUser(doc, translations.report.titleActivityReport, userData.user)
200
197
 
201
198
  let data = []
202
199
  doc.setFontSize(10)
@@ -253,6 +250,7 @@ async function exportActivityReportToPDF(userData, reportData) {
253
250
  )
254
251
  }
255
252
 
253
+ const style = getStyle(getUserPartner(userData.user))
256
254
  doc.autoTable({
257
255
  head: [headers],
258
256
  body: data,
@@ -1,10 +1,10 @@
1
1
  const automaticReports = require("./automaticReports")
2
2
  const messages = require('../lang')
3
3
  const jsPDF = require('jspdf')
4
- const autotable = require('jspdf-autotable')
5
- const reportStyle = require("./reportStyle")
4
+ require('jspdf-autotable')
6
5
  const {getStyle} = require("./reportStyle");
7
- const {header} = require("./util/pdfDocument");
6
+ const {headerFromUser} = require("./util/pdfDocument");
7
+ const {getUserPartner} = require("fleetmap-partners");
8
8
 
9
9
  const fileName = 'EventReport'
10
10
 
@@ -121,8 +121,6 @@ async function exportSpeedingReportToPDF(userData, reportData) {
121
121
 
122
122
  const lang = userData.user.attributes.lang
123
123
  const translations = messages[lang] ? messages[lang] : messages['en-GB']
124
- const hostname = userData.user.attributes.lastHost
125
- const style = getStyle(hostname)
126
124
 
127
125
  const headers = [
128
126
  translations.report.eventType,
@@ -133,7 +131,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
133
131
  if (reportData.devices) {
134
132
  let first = true
135
133
  const doc = new jsPDF.jsPDF('l');
136
- await header(doc, translations.report.titleEventsReport, hostname, style)
134
+ await headerFromUser(doc, translations.report.titleEventsReport, userData.user)
137
135
 
138
136
  reportData.devices.forEach(d => {
139
137
  let data = []
@@ -181,6 +179,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
181
179
  '','',''
182
180
  ]
183
181
 
182
+ const style = getStyle(getUserPartner(userData.user))
184
183
  doc.autoTable({
185
184
  head: [headers],
186
185
  body: data,
package/src/index.test.js CHANGED
@@ -3,25 +3,42 @@ const {SessionApi} = require("traccar-api");
3
3
  const axios = require('axios')
4
4
  const axiosCookieJarSupport = require('axios-cookiejar-support').default;
5
5
  const tough = require('tough-cookie');
6
+ const style = require("./reportStyle");
6
7
  const cookieJar = new tough.CookieJar();
7
8
 
8
9
  axiosCookieJarSupport(axios)
9
10
 
10
- test('speedingReport', async () => {
11
- const traccarConfig = {
12
- basePath: 'https://api.pinme.io/api',
13
- baseOptions: {
14
- withCredentials: true,
15
- jar: cookieJar
11
+
12
+ describe('test reports', function() {
13
+ this.timeout(9000000)
14
+ it('test queue', async () => {
15
+ const traccarConfig = {
16
+ basePath: 'https://api.fleetmap.io/api',
17
+ baseOptions: {
18
+ withCredentials: true,
19
+ jar: cookieJar
20
+ }
16
21
  }
17
- }
18
22
 
19
- await new SessionApi(traccarConfig, null, axios).sessionPost('-','-')
20
- const report = new Index(traccarConfig, axios)
21
- const userData = await report.getUserData()
23
+ await new SessionApi(traccarConfig, null, axios).sessionPost('jppenas@gmail.com', 'penas46881')
24
+ const report = new Index(traccarConfig, axios)
25
+ const userData = await report.getUserData()
26
+ userData.groupByDay = true
27
+ const reportData = await report.kmsReport(new Date(2021, 10, 19, 0, 0, 0, 0),
28
+ new Date(2021, 10, 21, 23, 59, 59, 0),
29
+ userData)
30
+
31
+ const reportResult = reportData[0]
32
+ reportResult.devices.forEach(d => {
33
+ console.log(d.device.name)
34
+ d.days.forEach(day => {
35
+ console.log(day.date + ' - ' + day.kms)
36
+ })
37
+ })
38
+
22
39
 
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)
40
+ //const pdf = report.tripReportToPDF(userData, reportData)
26
41
 
27
- }, 10000)
42
+ //console.log(pdf)
43
+ })
44
+ })
package/src/kms-report.js CHANGED
@@ -2,29 +2,124 @@ const {createActivityReport} = require("./activity-report");
2
2
  const messages = require('../lang')
3
3
  const jsPDF = require('jspdf')
4
4
  require('jspdf-autotable')
5
- const reportStyle = require("./reportStyle")
6
5
  const {getStyle} = require("./reportStyle");
7
- const {header} = require("./util/pdfDocument");
6
+ const {headerFromUser,addTable} = require("./util/pdfDocument");
7
+ const {getUserPartner} = require("fleetmap-partners");
8
+ const automaticReports = require("./automaticReports");
9
+ const {convertMS} = require("./util/utils");
8
10
 
9
11
 
10
12
  let traccarInstance
11
13
 
12
14
  const fileName = 'KmsReport'
13
15
 
16
+ async function createKmsReportByDevice(from, to, userData) {
17
+ const groupIds = userData.groups.map(g => g.id)
18
+ const devicesToProcess = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
19
+
20
+ const allData = {
21
+ devices: []
22
+ }
23
+
24
+ devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
25
+ const devicesToSlice = devicesToProcess.slice()
26
+
27
+ const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
28
+ let data = []
29
+ for (const a of arrayOfArrays) {
30
+ const response = await traccarInstance.reports.reportsRouteGet(from, to, a.map(d => d.id))
31
+ data = data.concat(response.data)
32
+ }
33
+
34
+ console.log('locations:' + data.length)
35
+
36
+ if (data.length > 0) {
37
+ allData.devices = processDevices(from, to, devicesToProcess, data)
38
+ }
39
+
40
+ return allData
41
+ }
42
+
43
+ async function createKmsReportByDriver(from, to, userData) {
44
+
45
+ }
46
+
47
+ async function createKmsReportByGroup(from, to, userData) {
48
+
49
+ }
50
+
51
+ function processDevices(from, to, devices, data) {
52
+ const devicesResult = []
53
+
54
+ for (const d of devices) {
55
+ const locations = data.filter(t => t.deviceId === d.id)
56
+
57
+ if (locations.length > 0) {
58
+ locations.forEach(l => l.locationDate = l.fixTime.substring(0, 10))
59
+ const groupedLocations = locations.reduce(
60
+ (entryMap, e) => entryMap.set(e.locationDate, [...entryMap.get(e.locationDate)||[], e]),
61
+ new Map()
62
+ )
63
+
64
+ const days = []
65
+ const keys = Array.from(groupedLocations.keys())
66
+
67
+ keys.forEach(key => {
68
+ const dayLocations = groupedLocations.get(key)
69
+ const day = {
70
+ date: key,
71
+ kms: dayLocations.reduce((a, b) => a + b.attributes.distance, 0)
72
+ }
73
+ days.push(day)
74
+ })
75
+
76
+ devicesResult.push({
77
+ device: d,
78
+ days: days
79
+ })
80
+ }
81
+ }
82
+
83
+ return devicesResult
84
+ }
85
+
14
86
  async function createKmsReport(from, to, userData, traccar) {
15
87
  console.log('Create KmsReport')
16
88
  traccarInstance = traccar
17
- return await createActivityReport(from, to, userData, traccar)
89
+ if(userData.groupByDay){
90
+ const reportData = []
91
+
92
+ if(userData.byDriver){
93
+ const allData = await createKmsReportByDriver(from, to, userData)
94
+ reportData.push(allData)
95
+ }
96
+ else if(userData.byGroup){
97
+ const allGroupsData = await createKmsReportByGroup(from, to, userData)
98
+ allGroupsData.forEach(data => reportData.push(data))
99
+ const withoutGroupDevices = await createKmsReportByDevice(from, to, userData)
100
+ reportData.push(withoutGroupDevices)
101
+ } else {
102
+ const allData = await createKmsReportByDevice(from, to, userData)
103
+ reportData.push(allData)
104
+ }
105
+
106
+ return reportData
107
+ } else {
108
+ return await createActivityReport(from, to, userData, traccar)
109
+ }
18
110
  }
19
111
 
20
112
  async function exportKmsReportToPDF(userData, reportData) {
21
113
  const lang = userData.user.attributes.lang
22
114
  const translations = messages[lang] ? messages[lang] : messages['en-GB']
23
- const hostname = userData.user.attributes.lastHost
24
- const style = getStyle(hostname)
115
+ const kmsData = userData.byDriver ? reportData.drivers : reportData.devices
25
116
 
26
117
  const headers = []
27
- if(userData.byDriver) {
118
+ if(userData.groupByDay) {
119
+ headers.push(translations.report.date,
120
+ translations.report.distance)
121
+ }
122
+ else if(userData.byDriver) {
28
123
  headers.push(translations.report.driver,
29
124
  translations.report.group,
30
125
  translations.report.distance)
@@ -34,77 +129,82 @@ async function exportKmsReportToPDF(userData, reportData) {
34
129
  translations.report.group,
35
130
  translations.report.distance)
36
131
  }
37
- if (reportData.devices || reportData.drivers) {
38
- const doc = new jsPDF.jsPDF('l');
39
- await header(doc, translations.report.titleKmsReport, hostname, style)
132
+ if (kmsData) {
133
+ const doc = userData.groupByDay ? new jsPDF.jsPDF() : new jsPDF.jsPDF('l')
134
+ await headerFromUser(doc, translations.report.titleSpeedingReport, userData.user)
135
+
136
+ if (userData.groupByDay) {
137
+ for (const d of kmsData) {
138
+ const name = userData.byDriver ? d.driver.name : deviceName(d.device)
139
+ const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.id)) : userData.groups.find(g => d.device.groupId === g.id)
40
140
 
41
- let data = []
42
- doc.setFontSize(10)
43
- doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, 30 )
44
- if(userData.byDriver) {
45
- reportData.drivers.forEach(d => {
46
- const group = userData.groups.find(g => g.drivers.includes(d.driver.id))
141
+ let space = 0
142
+ if (!first) {
143
+ doc.addPage()
144
+ } else {
145
+ first = false
146
+ space = 8
147
+ }
148
+ doc.setFontSize(13)
149
+ doc.text(name, 20, space + 20)
150
+ doc.setFontSize(11)
151
+ doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space + 20)
152
+ doc.text(new Date(d.from).toLocaleString() + ' - ' + new Date(d.to).toLocaleString(), 20, space + 25)
47
153
 
154
+ const data = []
48
155
  const temp = [
49
156
  d.driver.name,
50
157
  group ? group.name : '',
51
158
  Number((d.summary.distance / 1000).toFixed(0)),
52
159
  ]
53
160
  data.push(temp)
54
- })
161
+ }
55
162
  } else {
56
- reportData.devices.forEach(d => {
57
- const group = userData.groups.find(g => d.device.groupId === g.id)
163
+ if (userData.byDriver) {
164
+ reportData.drivers.forEach(d => {
165
+ const group = userData.groups.find(g => g.drivers.includes(d.driver.id))
58
166
 
59
- const temp = [
60
- d.summary.deviceName,
61
- d.device.model,
62
- group ? group.name : '',
63
- Number((d.summary.distance / 1000).toFixed(0))
64
- ]
65
- data.push(temp)
66
- })
67
- }
167
+ const temp = [
168
+ d.driver.name,
169
+ group ? group.name : '',
170
+ Number((d.summary.distance / 1000).toFixed(0)),
171
+ ]
172
+ data.push(temp)
173
+ })
174
+ } else {
175
+ reportData.devices.forEach(d => {
176
+ const group = userData.groups.find(g => d.device.groupId === g.id)
68
177
 
69
- const footValues = []
70
- if(userData.byDriver) {
71
- footValues.push(
72
- 'Total:' + reportData.drivers.length,
73
- '',
74
- (reportData.drivers.reduce((a, b) => a + b.summary.distance, 0)/1000).toFixed(0)
75
- )
76
- } else {
77
- footValues.push(
78
- 'Total:' + reportData.devices.length,
79
- '',
80
- '',
81
- (reportData.devices.reduce((a, b) => a + b.summary.distance, 0)/1000).toFixed(0),
82
- )
83
- }
178
+ const temp = [
179
+ d.summary.deviceName,
180
+ d.device.model,
181
+ group ? group.name : '',
182
+ Number((d.summary.distance / 1000).toFixed(0))
183
+ ]
184
+ data.push(temp)
185
+ })
186
+ }
84
187
 
85
- doc.autoTable({
86
- head: [headers],
87
- body: data,
88
- foot: [footValues],
89
- showFoot: 'lastPage',
90
- headStyles: {
91
- fillColor: style.pdfHeaderColor,
92
- textColor: style.pdfHeaderTextColor,
93
- fontSize: 10
94
- },
95
- bodyStyles: {
96
- fillColor: style.pdfBodyColor,
97
- textColor: style.pdfBodyTextColor,
98
- fontSize: 8
99
- },
100
- footStyles: {
101
- fillColor: style.pdfFooterColor,
102
- textColor: style.pdfFooterTextColor,
103
- fontSize: 9
104
- },
105
- startY: 35 });
106
-
107
- return doc
188
+ const footValues = []
189
+ if(userData.byDriver) {
190
+ footValues.push(
191
+ 'Total:' + reportData.drivers.length,
192
+ '',
193
+ (reportData.drivers.reduce((a, b) => a + b.summary.distance, 0)/1000).toFixed(0)
194
+ )
195
+ } else {
196
+ footValues.push(
197
+ 'Total:' + reportData.devices.length,
198
+ '',
199
+ '',
200
+ (reportData.devices.reduce((a, b) => a + b.summary.distance, 0)/1000).toFixed(0),
201
+ )
202
+ }
203
+
204
+ const style = getStyle(getUserPartner(userData.user))
205
+
206
+ return addTable(doc, headers, data, footValues, style, 35)
207
+ }
108
208
  }
109
209
  }
110
210
 
@@ -121,55 +221,48 @@ function exportKmsReportToExcel(userData, reportData) {
121
221
 
122
222
  const headers = []
123
223
 
124
- if(userData.byDriver) {
224
+ if(userData.groupByDay){
125
225
  headers.push(
126
- {label: translations.report.driver, value: 'driver'},
226
+ {label: translations.report.vehicle, value: 'name'},
127
227
  {label: translations.report.group, value: 'group'},
228
+ {label: translations.report.date, value: 'date'},
128
229
  {label: translations.report.distance, value: 'distance'})
129
- } else {
230
+ } else if(userData.byDriver) {
130
231
  headers.push(
131
- {label: translations.report.vehicle, value: 'name'},
232
+ {label: translations.report.driver, value: 'name'},
132
233
  {label: translations.report.group, value: 'group'},
133
234
  {label: translations.report.distance, value: 'distance'})
134
235
  }
135
236
 
136
237
  let data = []
137
- if(userData.byDriver){
138
- if (reportData.drivers) {
139
- reportData.drivers.forEach(d => {
140
- const group = userData.groups.find(g => g.drivers.includes(d.driver.id))
238
+ const info = userData.byDriver ? reportData.drivers : reportData.devices
239
+ info.forEach(d => {
240
+ const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.driver.id)) :
241
+ userData.groups.find(g => d.device.groupId === g.id)
141
242
 
243
+ if(userData.groupByDay) {
244
+ data = data.concat([{}])
245
+ data = data.concat(d.days.map(a => {
246
+ return {
247
+ name: userData.byDriver ? d.driver.name : d.summary.deviceName,
248
+ group: group ? group.name : '',
249
+ date: a.date,
250
+ distance: Number((a.kms / 1000).toFixed(0))
251
+ }
252
+ }))
253
+ } else {
142
254
  data = data.concat([{
143
- driver: d.driver.name,
255
+ name: userData.byDriver ? d.driver.name : d.summary.deviceName,
144
256
  group: group ? group.name : '',
145
257
  distance: Number((d.summary.distance / 1000).toFixed(0))
146
258
  }])
147
- })
148
- console.log(data)
149
- return {
150
- headers,
151
- data,
152
- settings
153
259
  }
154
- }
155
- } else {
156
- if (reportData.devices) {
157
- reportData.devices.forEach(d => {
158
- const group = userData.groups.find(g => d.device.groupId === g.id)
260
+ })
159
261
 
160
- data = data.concat([{
161
- name: d.summary.deviceName,
162
- group: group ? group.name : '',
163
- distance: Number((d.summary.distance / 1000).toFixed(0))
164
- }])
165
- })
166
- console.log(data)
167
- return {
168
- headers,
169
- data,
170
- settings
171
- }
172
- }
262
+ return {
263
+ headers,
264
+ data,
265
+ settings
173
266
  }
174
267
  }
175
268
 
@@ -2,8 +2,9 @@ const automaticReports = require("./automaticReports");
2
2
  const messages = require('../lang')
3
3
  const jsPDF = require('jspdf')
4
4
  require('jspdf-autotable')
5
- const {header} = require("./util/pdfDocument");
5
+ const {headerFromUser} = require("./util/pdfDocument");
6
6
  const {getStyle} = require("./reportStyle")
7
+ const {getUserPartner} = require("fleetmap-partners");
7
8
 
8
9
  const fileName = 'LocationReport'
9
10
 
@@ -104,8 +105,6 @@ async function exportLocationReportToPDF(userData, reportData) {
104
105
 
105
106
  const lang = userData.user.attributes.lang
106
107
  const translations = messages[lang] ? messages[lang] : messages['en-GB']
107
- const hostname = userData.user.attributes.lastHost
108
- const style = getStyle(hostname)
109
108
 
110
109
  const headers = [
111
110
  translations.report.date,
@@ -119,7 +118,7 @@ async function exportLocationReportToPDF(userData, reportData) {
119
118
  if (reportData.devices) {
120
119
  let first = true
121
120
  const doc = new jsPDF.jsPDF('l');
122
- await header(doc, translations.report.titleLocationReport, hostname, style)
121
+ await headerFromUser(doc, translations.report.titleLocationReport, userData.user)
123
122
 
124
123
  reportData.devices.forEach(d => {
125
124
  let data = []
@@ -155,6 +154,7 @@ async function exportLocationReportToPDF(userData, reportData) {
155
154
  '', getMaxSpeed(d.positions)
156
155
  ]
157
156
 
157
+ const style = getStyle(getUserPartner(userData.user))
158
158
  doc.autoTable({
159
159
  head: [headers],
160
160
  body: data,
@@ -1,9 +1,4 @@
1
- const {getPartnerData} = require("fleetmap-partners");
2
-
3
- function getStyle(hostname) {
4
- console.log(hostname)
5
- const partnerData = getPartnerData(hostname)
6
-
1
+ function getStyle(partnerData) {
7
2
  const reportStyleData = {
8
3
  pdfHeaderColor: [105, 105, 105],
9
4
  pdfHeaderTextColor: [256, 256, 256],
@@ -2,7 +2,7 @@ const automaticReports = require("./automaticReports")
2
2
  const messages = require('../lang')
3
3
  const jsPDF = require('jspdf')
4
4
  const {convertMS} = require("./util/utils")
5
- const {header} = require("./util/pdfDocument")
5
+ const {headerFromUser} = require("./util/pdfDocument")
6
6
  require('jspdf-autotable')
7
7
  const { parse } = require('wkt')
8
8
  const turf = require('turf')
@@ -10,6 +10,7 @@ const {getStyle} = require("./reportStyle")
10
10
  const drivers = require("./util/driver")
11
11
  const {distance, point} = require('turf')
12
12
  const here = require('./here')
13
+ const {getUserPartner} = require("fleetmap-partners");
13
14
 
14
15
  let traccarInstance
15
16
 
@@ -266,9 +267,6 @@ async function exportSpeedingReportToPDF(userData, reportData) {
266
267
 
267
268
  const lang = userData.user.attributes.lang
268
269
  const translations = messages[lang] ? messages[lang] : messages['en-GB']
269
- const hostname = userData.user.attributes.lastHost
270
- const style = getStyle(hostname)
271
-
272
270
 
273
271
  const overspeedData = userData.byDriver ? reportData.drivers : reportData.devices
274
272
 
@@ -294,7 +292,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
294
292
  if (overspeedData) {
295
293
  let first = true
296
294
  const doc = new jsPDF.jsPDF('l');
297
- await header(doc, translations.report.titleSpeedingReport, hostname, style)
295
+ await headerFromUser(doc, translations.report.titleSpeedingReport, userData.user)
298
296
 
299
297
  overspeedData.forEach(d => {
300
298
  try {
@@ -349,6 +347,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
349
347
  footValues.splice(2, 0, '')
350
348
  }
351
349
 
350
+ const style = getStyle(getUserPartner(userData.user))
352
351
  doc.autoTable({
353
352
  head: [headers],
354
353
  body: data,
@@ -2,7 +2,7 @@ const automaticReports = require("./automaticReports")
2
2
  const messages = require('../lang')
3
3
  const jsPDF = require('jspdf')
4
4
  const {convertMS} = require("./util/utils")
5
- const autotable = require('jspdf-autotable')
5
+ require('jspdf-autotable')
6
6
  const {coordsDistance} = require("./util/utils")
7
7
  const drivers = require("./util/driver")
8
8
  const {getUserPartner} = require("fleetmap-partners");
@@ -303,7 +303,7 @@ async function exportTripReportToPDF(userData, reportData) {
303
303
  getMaxSpeed(d.trips))
304
304
  }
305
305
 
306
- const style = getStyle(getUserPartner(userData.user).host)
306
+ const style = getStyle(getUserPartner(userData.user))
307
307
  doc.autoTable({
308
308
  head: [headers],
309
309
  body: data,
@@ -1,3 +1,4 @@
1
+ require('jspdf-autotable')
1
2
  const {getStyle} = require("../reportStyle");
2
3
  const {getUserPartner} = require("fleetmap-partners");
3
4
  const {getImgFromUrl} = require("./utils")
@@ -8,16 +9,46 @@ async function header(doc, title, hostname, style) {
8
9
  doc.text(title, 15, 15 )
9
10
 
10
11
  if(style.imgWidth && style.imgHeight) {
11
- const image = await getImgFromUrl(hostname)
12
- doc.addImage(image, 'PNG', 220 + (style.imgWidth < 50 ? 25 : 0), 5, style.imgWidth, style.imgHeight)
12
+ try{
13
+ const image = await getImgFromUrl(hostname)
14
+ if(image){
15
+ doc.addImage(image, 'PNG', 220 + (style.imgWidth < 50 ? 25 : 0), 5, style.imgWidth, style.imgHeight)
16
+ }
17
+ } catch (e) {
18
+ }
13
19
  }
14
20
  doc.setFont('helvetica', 'normal')
15
21
  }
16
22
 
17
23
  async function headerFromUser(doc, title, user) {
18
24
  const partner = getUserPartner(user)
19
- return header(doc, title, partner.host, getStyle(partner.host))
25
+ return header(doc, title, partner.host, getStyle(partner))
26
+ }
27
+
28
+ function addTable(doc, headers, data, footValues, style, startY){
29
+ doc.autoTable({
30
+ head: [headers],
31
+ body: data,
32
+ foot: [footValues],
33
+ showFoot: 'lastPage',
34
+ headStyles: {
35
+ fillColor: style.pdfHeaderColor,
36
+ textColor: style.pdfHeaderTextColor,
37
+ fontSize: 10
38
+ },
39
+ bodyStyles: {
40
+ fillColor: style.pdfBodyColor,
41
+ textColor: style.pdfBodyTextColor,
42
+ fontSize: 8
43
+ },
44
+ footStyles: {
45
+ fillColor: style.pdfFooterColor,
46
+ textColor: style.pdfFooterTextColor,
47
+ fontSize: 9
48
+ },
49
+ startY: startY });
20
50
  }
21
51
 
22
52
  exports.header = header
23
53
  exports.headerFromUser = headerFromUser
54
+ exports.addTable = addTable
package/src/util/utils.js CHANGED
@@ -38,7 +38,6 @@ async function getImgFromUrl(hostname) {
38
38
  const response = await axios.get('https://' + hostname + '/img/logos/' + hostname + '.png', { responseType: 'arraybuffer' })
39
39
  return Buffer.from(response.data, 'binary').toString('base64')
40
40
  }
41
-
42
41
  }
43
42
 
44
43
  exports.getImgFromUrl = getImgFromUrl
@@ -4,8 +4,9 @@ const automaticReports = require("./automaticReports");
4
4
  const {convertMS} = require("./util/utils")
5
5
  const jsPDF = require('jspdf')
6
6
  require('jspdf-autotable')
7
- const {header} = require("./util/pdfDocument");
7
+ const {headerFromUser} = require("./util/pdfDocument");
8
8
  const {getStyle} = require("./reportStyle")
9
+ const {getUserPartner} = require("fleetmap-partners");
9
10
 
10
11
  const fileName = 'ZoneReport'
11
12
 
@@ -150,11 +151,6 @@ async function exportZoneReportToPDF(userData, reportData) {
150
151
 
151
152
  const lang = userData.user.attributes.lang
152
153
  const translations = messages[lang] ? messages[lang] : messages['en-GB']
153
- const hostname = userData.user.attributes.lastHost
154
-
155
- console.log(userData.user)
156
-
157
- const style = getStyle(hostname)
158
154
 
159
155
  const headers = [
160
156
  translations.report.enter,
@@ -166,7 +162,7 @@ async function exportZoneReportToPDF(userData, reportData) {
166
162
  if (reportData.devices) {
167
163
  let first = true
168
164
  const doc = new jsPDF.jsPDF('l')
169
- await header(doc, translations.report.titleZoneReport, hostname, style)
165
+ await headerFromUser(doc, translations.report.titleZoneReport, userData.user)
170
166
 
171
167
  reportData.devices.forEach(d => {
172
168
  let data = []
@@ -200,6 +196,7 @@ async function exportZoneReportToPDF(userData, reportData) {
200
196
  'Total:' + d.geofences.length
201
197
  ]
202
198
 
199
+ const style = getStyle(getUserPartner(userData.user))
203
200
  doc.autoTable({
204
201
  head: [headers],
205
202
  body: data,
@@ -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>