fleetmap-reports 1.0.207 → 1.0.211

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,192 @@
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
+ </task>
147
+ <task id="LOCAL-00001" summary="Fix getStyle">
148
+ <created>1636983717385</created>
149
+ <option name="number" value="00001" />
150
+ <option name="presentableId" value="LOCAL-00001" />
151
+ <option name="project" value="LOCAL" />
152
+ <updated>1636983717385</updated>
153
+ </task>
154
+ <task id="LOCAL-00002" summary="Fix getStyle in all reports">
155
+ <created>1637020728356</created>
156
+ <option name="number" value="00002" />
157
+ <option name="presentableId" value="LOCAL-00002" />
158
+ <option name="project" value="LOCAL" />
159
+ <updated>1637020728356</updated>
160
+ </task>
161
+ <task id="LOCAL-00003" summary="try catch on pdf addImage">
162
+ <created>1637247013210</created>
163
+ <option name="number" value="00003" />
164
+ <option name="presentableId" value="LOCAL-00003" />
165
+ <option name="project" value="LOCAL" />
166
+ <updated>1637247013211</updated>
167
+ </task>
168
+ <option name="localTasksCounter" value="4" />
169
+ <servers />
170
+ </component>
171
+ <component name="TypeScriptGeneratedFilesManager">
172
+ <option name="version" value="3" />
173
+ </component>
174
+ <component name="Vcs.Log.Tabs.Properties">
175
+ <option name="TAB_STATES">
176
+ <map>
177
+ <entry key="MAIN">
178
+ <value>
179
+ <State />
180
+ </value>
181
+ </entry>
182
+ </map>
183
+ </option>
184
+ <option name="oldMeFiltersMigrated" value="true" />
185
+ </component>
186
+ <component name="VcsManagerConfiguration">
187
+ <MESSAGE value="Fix getStyle" />
188
+ <MESSAGE value="Fix getStyle in all reports" />
189
+ <MESSAGE value="try catch on pdf addImage" />
190
+ <option name="LAST_COMMIT_MESSAGE" value="try catch on pdf addImage" />
191
+ </component>
192
+ </project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.207",
3
+ "version": "1.0.211",
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,26 +2,115 @@ 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");
8
9
 
9
10
 
10
11
  let traccarInstance
11
12
 
12
13
  const fileName = 'KmsReport'
13
14
 
15
+ async function createKmsReportByDevice(from, to, userData) {
16
+ const groupIds = userData.groups.map(g => g.id)
17
+ const devicesToProcess = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
18
+
19
+ const allData = {
20
+ devices: []
21
+ }
22
+
23
+ devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
24
+ const devicesToSlice = devicesToProcess.slice()
25
+
26
+ const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
27
+ let data = []
28
+ for (const a of arrayOfArrays) {
29
+ const response = await traccarInstance.reports.reportsRouteGet(from, to, a.map(d => d.id))
30
+ data = data.concat(response.data)
31
+ }
32
+
33
+ console.log('locations:' + data.length)
34
+
35
+ if (data.length > 0) {
36
+ allData.devices = processDevices(from, to, devicesToProcess, data)
37
+ }
38
+
39
+ return allData
40
+ }
41
+
42
+ async function createKmsReportByDriver(from, to, userData) {
43
+
44
+ }
45
+
46
+ async function createKmsReportByGroup(from, to, userData) {
47
+
48
+ }
49
+
50
+ function processDevices(from, to, devices, data) {
51
+ const devicesResult = []
52
+
53
+ for (const d of devices) {
54
+ const locations = data.filter(t => t.deviceId === d.id)
55
+
56
+ if (locations.length > 0) {
57
+ locations.forEach(l => l.locationDate = l.fixTime.substring(0, 10))
58
+ const groupedLocations = locations.reduce(
59
+ (entryMap, e) => entryMap.set(e.locationDate, [...entryMap.get(e.locationDate)||[], e]),
60
+ new Map()
61
+ )
62
+
63
+ const days = []
64
+ const keys = Array.from(groupedLocations.keys())
65
+
66
+ keys.forEach(key => {
67
+ const dayLocations = groupedLocations.get(key)
68
+ const day = {
69
+ date: key,
70
+ kms: dayLocations.reduce((a, b) => a + b.attributes.distance, 0)
71
+ }
72
+ days.push(day)
73
+ })
74
+
75
+ devicesResult.push({
76
+ device: d,
77
+ days: days
78
+ })
79
+ }
80
+ }
81
+
82
+ return devicesResult
83
+ }
84
+
14
85
  async function createKmsReport(from, to, userData, traccar) {
15
86
  console.log('Create KmsReport')
16
87
  traccarInstance = traccar
17
- return await createActivityReport(from, to, userData, traccar)
88
+ if(userData.groupByDay){
89
+ const reportData = []
90
+
91
+ if(userData.byDriver){
92
+ const allData = await createKmsReportByDriver(from, to, userData)
93
+ reportData.push(allData)
94
+ }
95
+ else if(userData.byGroup){
96
+ const allGroupsData = await createKmsReportByGroup(from, to, userData)
97
+ allGroupsData.forEach(data => reportData.push(data))
98
+ const withoutGroupDevices = await createKmsReportByDevice(from, to, userData)
99
+ reportData.push(withoutGroupDevices)
100
+ } else {
101
+ const allData = await createKmsReportByDevice(from, to, userData)
102
+ reportData.push(allData)
103
+ }
104
+
105
+ return reportData
106
+ } else {
107
+ return await createActivityReport(from, to, userData, traccar)
108
+ }
18
109
  }
19
110
 
20
111
  async function exportKmsReportToPDF(userData, reportData) {
21
112
  const lang = userData.user.attributes.lang
22
113
  const translations = messages[lang] ? messages[lang] : messages['en-GB']
23
- const hostname = userData.user.attributes.lastHost
24
- const style = getStyle(hostname)
25
114
 
26
115
  const headers = []
27
116
  if(userData.byDriver) {
@@ -36,7 +125,7 @@ async function exportKmsReportToPDF(userData, reportData) {
36
125
  }
37
126
  if (reportData.devices || reportData.drivers) {
38
127
  const doc = new jsPDF.jsPDF('l');
39
- await header(doc, translations.report.titleKmsReport, hostname, style)
128
+ await headerFromUser(doc, translations.report.titleSpeedingReport, userData.user)
40
129
 
41
130
  let data = []
42
131
  doc.setFontSize(10)
@@ -82,29 +171,9 @@ async function exportKmsReportToPDF(userData, reportData) {
82
171
  )
83
172
  }
84
173
 
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
174
+ const style = getStyle(getUserPartner(userData.user))
175
+
176
+ return addTable(doc, headers, data, footValues, style, 35)
108
177
  }
109
178
  }
110
179
 
@@ -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");
@@ -289,7 +289,6 @@ async function exportTripReportToPDF(userData, reportData) {
289
289
  'Total:' + d.trips.length,
290
290
  '','','',
291
291
  convertMS(d.trips.reduce((a, b) => a + b.duration, 0)),
292
-
293
292
  ]
294
293
 
295
294
  if(userData.byDriver) {
@@ -304,7 +303,7 @@ async function exportTripReportToPDF(userData, reportData) {
304
303
  getMaxSpeed(d.trips))
305
304
  }
306
305
 
307
- const style = getStyle(getUserPartner(userData.user).host)
306
+ const style = getStyle(getUserPartner(userData.user))
308
307
  doc.autoTable({
309
308
  head: [headers],
310
309
  body: data,
@@ -1,3 +1,5 @@
1
+ require('jspdf-autotable')
2
+ const {getStyle} = require("../reportStyle");
1
3
  const {getUserPartner} = require("fleetmap-partners");
2
4
  const {getImgFromUrl} = require("./utils")
3
5
 
@@ -7,16 +9,46 @@ async function header(doc, title, hostname, style) {
7
9
  doc.text(title, 15, 15 )
8
10
 
9
11
  if(style.imgWidth && style.imgHeight) {
10
- const image = await getImgFromUrl(hostname)
11
- 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
+ }
12
19
  }
13
20
  doc.setFont('helvetica', 'normal')
14
21
  }
15
22
 
16
23
  async function headerFromUser(doc, title, user) {
17
24
  const partner = getUserPartner(user)
18
- return header(doc, title, partner.host, partner.reports || {})
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 });
19
50
  }
20
51
 
21
52
  exports.header = header
22
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>