fleetmap-reports 1.0.213 → 1.0.214

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.
@@ -4,6 +4,7 @@
4
4
  <list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="try catch on pdf addImage">
5
5
  <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
6
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.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.js" afterDir="false" />
7
8
  <change beforePath="$PROJECT_DIR$/src/index.test.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.test.js" afterDir="false" />
8
9
  <change beforePath="$PROJECT_DIR$/src/kms-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/kms-report.js" afterDir="false" />
9
10
  <change beforePath="$PROJECT_DIR$/src/util/pdfDocument.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/util/pdfDocument.js" afterDir="false" />
@@ -143,7 +144,7 @@
143
144
  <workItem from="1637227826845" duration="1275000" />
144
145
  <workItem from="1637441942952" duration="4543000" />
145
146
  <workItem from="1637670815688" duration="2973000" />
146
- <workItem from="1637674107929" duration="9187000" />
147
+ <workItem from="1637674107929" duration="10975000" />
147
148
  </task>
148
149
  <task id="LOCAL-00001" summary="Fix getStyle">
149
150
  <created>1636983717385</created>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.213",
3
+ "version": "1.0.214",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
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
@@ -37,7 +37,7 @@ describe('test reports', function() {
37
37
  })
38
38
 
39
39
 
40
- const pdf = report.kmsReportToExcel(userData, reportResult)
40
+ const pdf = report.kmsReportToPDF(userData, reportResult)
41
41
 
42
42
  console.log(pdf)
43
43
  })
package/src/kms-report.js CHANGED
@@ -135,7 +135,7 @@ async function exportKmsReportToPDF(userData, reportData) {
135
135
 
136
136
  if (userData.groupByDay) {
137
137
  for (const d of kmsData) {
138
- const name = userData.byDriver ? d.driver.name : deviceName(d.device)
138
+ const name = userData.byDriver ? d.driver.name : d.device.name
139
139
  const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.id)) : userData.groups.find(g => d.device.groupId === g.id)
140
140
 
141
141
  let space = 0
@@ -152,12 +152,24 @@ async function exportKmsReportToPDF(userData, reportData) {
152
152
  doc.text(new Date(d.from).toLocaleString() + ' - ' + new Date(d.to).toLocaleString(), 20, space + 25)
153
153
 
154
154
  const data = []
155
- const temp = [
156
- d.driver.name,
157
- group ? group.name : '',
158
- Number((d.summary.distance / 1000).toFixed(0)),
159
- ]
155
+ d.days.forEach(day => {
156
+ const temp = [
157
+ new Date(day).toLocaleDateString(),
158
+ (day.kms/1000).toFixed(0)
159
+ ]
160
+ })
161
+
160
162
  data.push(temp)
163
+
164
+ const footValues = []
165
+ footValues.push(
166
+ '',
167
+ (d.days.reduce((a, b) => a + b.kms, 0)/1000).toFixed(0)
168
+ )
169
+
170
+ const style = getStyle(getUserPartner(userData.user))
171
+
172
+ addTable(doc, headers, data, footValues, style, 35)
161
173
  }
162
174
  } else {
163
175
  if (userData.byDriver) {
@@ -203,8 +215,9 @@ async function exportKmsReportToPDF(userData, reportData) {
203
215
 
204
216
  const style = getStyle(getUserPartner(userData.user))
205
217
 
206
- return addTable(doc, headers, data, footValues, style, 35)
218
+ addTable(doc, headers, data, footValues, style, 35)
207
219
  }
220
+ return doc
208
221
  }
209
222
  }
210
223