fleetmap-reports 1.0.306 → 1.0.307

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/.idea/aws.xml ADDED
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="accountSettings">
4
+ <option name="activeProfile" value="profile:default" />
5
+ <option name="activeRegion" value="us-east-1" />
6
+ <option name="recentlyUsedProfiles">
7
+ <list>
8
+ <option value="profile:default" />
9
+ </list>
10
+ </option>
11
+ <option name="recentlyUsedRegions">
12
+ <list>
13
+ <option value="us-east-1" />
14
+ </list>
15
+ </option>
16
+ </component>
17
+ </project>
@@ -0,0 +1,7 @@
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,8 +1,9 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
2
+ <module type="JAVA_MODULE" version="4">
3
3
  <component name="NewModuleRootManager" inherit-compiler-output="true">
4
4
  <exclude-output />
5
5
  <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="inheritedJdk" />
6
7
  <orderEntry type="sourceFolder" forTests="false" />
7
8
  </component>
8
9
  </module>
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="JavaScriptLibraryMappings">
4
- <includedPredefinedLibrary name="Node.js Core" />
4
+ <file url="file://$PROJECT_DIR$" libraries="{Node.js Core}" />
5
5
  </component>
6
6
  </project>
package/.idea/modules.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <project version="4">
3
3
  <component name="ProjectModuleManager">
4
4
  <modules>
5
- <module fileurl="file://$PROJECT_DIR$/fleetmap-reports.iml" filepath="$PROJECT_DIR$/fleetmap-reports.iml" />
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/fleetmap-reports.iml" filepath="$PROJECT_DIR$/.idea/fleetmap-reports.iml" />
6
6
  </modules>
7
7
  </component>
8
8
  </project>
package/.idea/vcs.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
4
+ <mapping directory="" vcs="Git" />
5
5
  </component>
6
6
  </project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.306",
3
+ "version": "1.0.307",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -8,10 +8,9 @@ const {headerFromUser, addTable} = require("./util/pdfDocument")
8
8
  const {getStyle} = require("./reportStyle")
9
9
  const {getUserPartner} = require("fleetmap-partners")
10
10
  const traccar = require("./util/traccar")
11
- const {createKmsReport} = require("./kms-report");
12
- const {isInsideTimetable} = require("./util/trips");
13
- const { Document, Packer, Paragraph, TextRun } = require("docx")
14
- import { saveAs } from "file-saver"
11
+ const {isInsideTimetable, isPartialInsideTimetable} = require("./util/trips");
12
+ const trips = require("./util/trips");
13
+
15
14
  let traccarInstance
16
15
  let userData
17
16
 
@@ -28,10 +27,8 @@ async function createActivityReport(from, to, reportUserData, traccar) {
28
27
  reportData.push(allData)
29
28
  }
30
29
  else if(userData.byGroup){
31
- const allGroupsData = await createActivityReportByGroup(from, to)
32
- allGroupsData.forEach(data => reportData.push(data))
33
- const withoutGroupDevices = await createActivityReportByDevice(from, to)
34
- reportData.push(withoutGroupDevices)
30
+ const allData = await createActivityReportByGroup(from, to)
31
+ reportData.push(...allData)
35
32
  } else {
36
33
  const allData = await createActivityReportByDevice(from, to)
37
34
  reportData.push(allData)
@@ -56,22 +53,26 @@ async function createActivityReportByGroup(from, to){
56
53
  }
57
54
 
58
55
  const response = await traccarInstance.reports.reportsSummaryGet(from, to, null, [g.id])
59
- const data = response.data
56
+ const summaries = response.data
60
57
 
61
58
  const responseTrips = await traccarInstance.reports.reportsTripsGet(from, to, null, [g.id])
62
59
  const trips = responseTrips.data
63
60
 
64
61
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
65
62
 
66
- if (data.length > 0) {
63
+ if (summaries.length > 0) {
67
64
 
68
- console.log('Summary:' + data.length)
69
- groupData.devices = processDevices(devices, data, trips)
65
+ console.log('Summary:' + summaries.length)
66
+ groupData.devices = processDevices(from, to, devices, {summaries: summaries, trips: trips})
70
67
 
71
68
  reportData.push(groupData)
72
69
  }
73
70
  }
74
71
  }
72
+
73
+ const withoutGroupDevices = await createActivityReportByDevice(from, to)
74
+ reportData.push(withoutGroupDevices)
75
+
75
76
  return reportData
76
77
  }
77
78
 
@@ -89,73 +90,38 @@ async function createActivityReportByDevice(from, to){
89
90
  //Get report data from traccar
90
91
  devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
91
92
 
92
- // use the km report to calculate kms
93
- const kmsReport = await createKmsReport(from, to, userData, traccarInstance)
93
+ let summaries = []
94
+ let routeData = []
95
+ const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
94
96
 
95
- let data = []
96
97
  if(userData.groupByDay) {
98
+ routeData = userData.allWeek ? [] : await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
99
+ console.log('trips:' + tripsData.length)
100
+
101
+ if (tripsData.length > 0) {
102
+ trips.checkTripsKms(traccarInstance, from, to, devicesToProcess, {trips: tripsData, route: routeData})
103
+ }
104
+
97
105
  const dates = getDates(from, to)
98
106
  for(const date of dates){
99
- if(userData.allWeek || !userData.weekDays){
107
+ if(userData.allWeek || !userData.weekDays || !userData.dayHours){
100
108
  const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
101
109
  const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
102
110
 
103
111
  const summary = await traccar.getSummary(traccarInstance, fromByDay, toByDay, devicesToProcess)
104
112
  summary.forEach(s => s.date = date)
105
- data = data.concat(summary)
106
- } else {
107
- if((date.getDay() === 0 && userData.weekDays.sunday) ||
108
- (date.getDay() === 1 && userData.weekDays.monday) ||
109
- (date.getDay() === 2 && userData.weekDays.tuesday) ||
110
- (date.getDay() === 3 && userData.weekDays.wednesday) ||
111
- (date.getDay() === 4 && userData.weekDays.thursday) ||
112
- (date.getDay() === 5 && userData.weekDays.friday) ||
113
- (date.getDay() === 6 && userData.weekDays.saturday)) {
114
-
115
- const fromByDay = new Date(new Date(date).toISOString().split('T')[0] + ' ' + userData.dayHours.startTime)
116
- const toByDay = new Date(new Date(date).toISOString().split('T')[0] + ' ' + userData.dayHours.endTime)
117
-
118
- if(fromByDay.getTime() < toByDay.getTime()) {
119
- const summary = await traccar.getSummary(traccarInstance, new Date(fromByDay.toUTCString()), new Date(toByDay.toUTCString()), devicesToProcess)
120
- summary.forEach(s => s.date = date)
121
- data = data.concat(summary)
122
- } else {
123
- const dayStart = new Date(new Date(date).toISOString().split('T')[0] + ' 00:00:00')
124
- const dayEnd = new Date(new Date(date).toISOString().split('T')[0] + ' 23:59:59')
125
-
126
- const summaryStart = await traccar.getSummary(traccarInstance, new Date(dayStart.toUTCString()), new Date(toByDay.toUTCString()), devicesToProcess)
127
- const summaryEnd = await traccar.getSummary(traccarInstance, new Date(fromByDay.toUTCString()), new Date(dayEnd.toUTCString()), devicesToProcess)
128
-
129
- const summary = []
130
- summaryStart.forEach(s => {
131
- const sEnd = summaryEnd.find(a => s.deviceId === a.deviceId)
132
- summary.push({
133
- date: date,
134
- deviceId: s.deviceId,
135
- averageSpeed: (s.averageSpeed + sEnd.averageSpeed) / 2,
136
- distance: s.distance + sEnd.distance,
137
- engineHours: s.engineHours + sEnd.engineHours,
138
- maxSpeed: s.maxSpeed > sEnd.maxSpeed ? s.maxSpeed : sEnd.maxSpeed,
139
- endOdometer: 0,
140
- startOdometer: 0
141
- })
142
- })
143
- data = data.concat(summary)
144
- }
145
- }else {
146
- data = data.concat({date: date})
147
- }
113
+ summaries = summaries.concat(summary)
148
114
  }
149
115
  }
150
116
  } else {
151
- data = await traccar.getSummary(traccarInstance, from, to, devicesToProcess)
117
+ summaries = await traccar.getSummary(traccarInstance, from, to, devicesToProcess)
152
118
  }
153
119
 
154
- console.log('Summary:' + data.length)
120
+ console.log('Summary:' + summaries.length)
155
121
 
156
122
  //Process report data
157
- if (data.length > 0) {
158
- allData.devices = processDevices(devicesToProcess, data, kmsReport)
123
+ if (summaries.length || tripsData.length) {
124
+ allData.devices = processDevices(from, to, devicesToProcess, {summaries: summaries, trips: tripsData, route: routeData})
159
125
  }
160
126
 
161
127
  return allData
@@ -165,8 +131,10 @@ async function createActivityReportByDriver(from, to){
165
131
  const devices = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
166
132
 
167
133
  let tripsData = []
134
+ let routeData = []
168
135
  if(devices.length > 0) {
169
136
  tripsData = await traccar.getTrips(traccarInstance, from, to, devices)
137
+ routeData = await traccar.getRoute(traccarInstance, from, to, devices)
170
138
  }
171
139
 
172
140
  const allData = {
@@ -175,28 +143,74 @@ async function createActivityReportByDriver(from, to){
175
143
  to: to
176
144
  }
177
145
 
178
- allData.drivers = processDrivers(from, to, userData.drivers, tripsData)
146
+ allData.drivers = processDrivers(from, to, userData.drivers, {trips: tripsData, route: routeData})
179
147
 
180
148
  return allData
181
149
  }
182
150
 
183
- function processDevices(devices, data, kmsReport) {
151
+
152
+ function processDevices(from, to, devices, data) {
184
153
  const devicesResult = []
185
154
 
186
155
  devices.forEach(d => {
187
- const summary = data.filter(s => s.deviceId === d.id)
188
- if (summary) {
189
- summary.forEach(s => {
190
- const deviceKms = kmsReport[0].devices.filter(r => r.device.id === d.id)
191
- s.convertedSpentFuel = automaticReports.calculateSpentFuel(s.spentFuel, d)
192
- s.distance = deviceKms.length ? (userData.groupByDay ? deviceKms[0].days.find(d => d.date.getTime() === s.date.getTime()).kms : deviceKms[0].summary.distance) : 0
193
- })
194
- const deviceData = {
195
- device: d,
196
- summary: summary,
156
+ const summary = []
157
+ if(userData.groupByDay) {
158
+ const route = data.route.filter(t => t.deviceId === d.id)
159
+ const deviceTrips = data.trips.filter(t => t.deviceId === d.id
160
+ && (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
161
+
162
+ const dates = getDates(from, to)
163
+ for(const date of dates){
164
+ const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
165
+ const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
166
+
167
+ const tripsByDay = deviceTrips.filter(t => (new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay))
168
+ const distance = tripsByDay.reduce((a, b) => a + b.distance, 0)
169
+
170
+ if(!userData.allWeek && userData.weekDays && userData.dayHours) {
171
+ summary.push({
172
+ date: date,
173
+ deviceId: d.id,
174
+ averageSpeed: distance > 0 ? ((tripsByDay.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / distance) : 0,
175
+ distance: distance,
176
+ engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
177
+ maxSpeed: tripsByDay.reduce((a, b) => {
178
+ return a > b.maxSpeed ? a : b.maxSpeed
179
+ }, 0),
180
+ endOdometer: 0,
181
+ startOdometer: 0
182
+ })
183
+ } else {
184
+ const summaryCurrentDay = data.summaries.filter(s => {
185
+ console.log(s.date.getTime(), date.getTime(), s.date.getTime() === date.getTime())
186
+ return s.deviceId === d.id && s.date.getTime() === date.getTime()})
187
+
188
+ if (summaryCurrentDay.length) {
189
+ summaryCurrentDay.forEach(s => {
190
+ s.distance = distance
191
+ s.convertedSpentFuel = automaticReports.calculateSpentFuel(s.spentFuel, d)
192
+ })
193
+
194
+ summary.push(...summaryCurrentDay)
195
+ }
196
+ }
197
+ }
198
+ } else {
199
+ summary.push(...data.summaries.filter(s => s.deviceId === d.id))
200
+
201
+ if (summary.length) {
202
+ summary.forEach(s => {
203
+ s.distance = data.trips.filter(t => t.deviceId === d.id).reduce((a, b) => a + b.distance, 0)
204
+ s.convertedSpentFuel = automaticReports.calculateSpentFuel(s.spentFuel, d)
205
+ })
197
206
  }
198
- devicesResult.push(deviceData)
199
207
  }
208
+
209
+ const deviceData = {
210
+ device: d,
211
+ summary: summary,
212
+ }
213
+ devicesResult.push(deviceData)
200
214
  })
201
215
 
202
216
  return devicesResult
@@ -206,7 +220,8 @@ function processDrivers(from, to, drivers, data) {
206
220
  console.log(data)
207
221
  const driversResult = []
208
222
  drivers.forEach(d => {
209
- const trips = data.filter(t => t.driverUniqueId === d.uniqueId)
223
+ const route = data.route.filter(p => p.attributes.driverUniqueId === d.uniqueId)
224
+ const trips = data.trips.filter(t => t.driverUniqueId === d.uniqueId)
210
225
  if (trips.length > 0) {
211
226
  const driverData = {
212
227
  driver: d,
@@ -219,7 +234,7 @@ function processDrivers(from, to, drivers, data) {
219
234
  const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
220
235
 
221
236
  const tripsByDay = trips.filter(t => (new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay)
222
- && (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData)))
237
+ && (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
223
238
 
224
239
  driverData.summary.push({
225
240
  date: date,
@@ -267,34 +282,6 @@ async function exportActivityReportToPDF(userData, reportData) {
267
282
  }
268
283
  }
269
284
 
270
- function exportActivityReportToWord(userData, reportData) {
271
- const doc = new Document({
272
- sections: [{
273
- properties: {},
274
- children: [
275
- new Paragraph({
276
- children: [
277
- new TextRun("Hello World"),
278
- new TextRun({
279
- text: "Foo Bar",
280
- bold: true,
281
- }),
282
- new TextRun({
283
- text: "\tGithub is the best",
284
- bold: true,
285
- }),
286
- ],
287
- }),
288
- ],
289
- }],
290
- })
291
- Packer.toBlob(doc).then(blob => {
292
- console.log(blob);
293
- saveAs(blob, "example.docx");
294
- console.log("Document created successfully");
295
- })
296
- }
297
-
298
285
  function exportActivityReportToPDF_Driver(doc, translations, reportData) {
299
286
  const headers = [translations.report.driver,
300
287
  translations.report.distance,
package/src/index.js CHANGED
@@ -109,9 +109,7 @@ function Reports(config, axios) {
109
109
  return require('./kms-report').exportKmsReportToPDF(userData, reportData)
110
110
  }
111
111
 
112
- this.kmsReportToWord = (userData, reportData) => {
113
- return require('./kms-report').exportKmsReportToWord(userData, reportData)
114
- }
112
+ this.reportToWord = require('./word').reportToWord
115
113
 
116
114
  this.kmsReportToExcel = (userData, reportData) => {
117
115
  return require('./kms-report').exportKmsReportToExcel(userData, reportData)
package/src/kms-report.js CHANGED
@@ -133,8 +133,7 @@ function processDrivers(from, to, drivers, data) {
133
133
  const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
134
134
  const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
135
135
 
136
- const tripsByDay = trips.filter(t => (new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay)
137
- && (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData)))
136
+ const tripsByDay = trips.filter(t => (new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay))
138
137
 
139
138
  driverData.days.push({
140
139
  date: date,
@@ -10,7 +10,6 @@ const {getStyle} = require("./reportStyle")
10
10
  const traccar = require("./util/traccar")
11
11
  const trips = require("./util/trips");
12
12
  const {isInsideTimetable, addNearestPOIs, isPartialInsideTimetable} = require("./util/trips")
13
- const word = require('./word')
14
13
 
15
14
 
16
15
  let traccarInstance
package/src/util/utils.js CHANGED
@@ -1,5 +1,12 @@
1
1
  const axios = require('axios')
2
2
  const turf = require('turf')
3
+ const {getUserPartner} = require("fleetmap-partners")
4
+ const messages = require("../../lang")
5
+
6
+ exports.getTranslations = (userData) => {
7
+ const lang = userData.user.attributes.lang || (navigator && navigator.language)
8
+ return messages[lang] ? messages[lang] : messages['en-GB']
9
+ }
3
10
 
4
11
  function convertMS(duration, withSeconds) {
5
12
 
@@ -31,7 +38,7 @@ function coordsDistance(lon1, lat1, lon2, lat2) {
31
38
 
32
39
  function getDates(startDate, endDate) {
33
40
  const dates = []
34
- let currentDate = new Date(startDate.toISOString().split('T')[0] + ' 12:00 PM')
41
+ let currentDate = new Date(startDate.toISOString().split('T')[0] + ' 12:00:00.000 PM')
35
42
  const addDays = function (days) {
36
43
  const date = new Date(this.valueOf())
37
44
  date.setDate(date.getDate() + days)
@@ -44,19 +51,33 @@ function getDates(startDate, endDate) {
44
51
  return dates
45
52
  }
46
53
 
54
+ function getImage(url) {
55
+ return axios.get(url, {responseType: 'arraybuffer'}).then(d => d.data)
56
+ }
57
+
58
+ async function getImageBase64(url) {
59
+ const response = await getImage(url);
60
+ return Buffer.from(response, 'binary').toString('base64')
61
+ }
62
+
63
+ function getLogoUrl(hostname) {
64
+ const path = `/img/logos/${hostname}.png`
65
+ return window ? path : `https://${hostname}${path}`
66
+ }
67
+
47
68
  async function getImgFromUrl(hostname) {
69
+ const url = getLogoUrl(hostname)
48
70
  try {
49
71
  const img = new Image()
50
- img.src = '/img/logos/' + hostname + '.png'
72
+ img.src = url
51
73
  return img
52
74
  } catch (e) {
53
- const response = await axios.get('https://' + hostname + '/img/logos/' + hostname + '.png', { responseType: 'arraybuffer' })
54
- return Buffer.from(response.data, 'binary').toString('base64')
75
+ return await getImageBase64(url);
55
76
  }
56
77
  }
57
78
 
58
79
  function isClientSide() { return (typeof window !== "undefined") }
59
- exports.isClientSide = isClientSide
80
+
60
81
 
61
82
  function convertToLocaleString(value, lang, timezone){
62
83
  if(isClientSide()){
@@ -98,4 +119,8 @@ exports.getDates = getDates
98
119
  exports.convertToLocaleString = convertToLocaleString
99
120
  exports.convertToLocaleDateString = convertToLocaleDateString
100
121
  exports.convertToLocaleTimeString = convertToLocaleTimeString
101
-
122
+ exports.isClientSide = isClientSide
123
+ exports.getLogo = (user) => {
124
+ const host = window ? window.location.hostname : getUserPartner(user).host
125
+ return getImage(getLogoUrl(host))
126
+ }
package/src/word/index.js CHANGED
@@ -1,33 +1,81 @@
1
- const {Document, Paragraph, Packer, TableRow, TableCell, Table} = require("docx")
1
+ const {Document, Paragraph, Packer, TableRow, TableCell, Table, WidthType, ImageRun, Header, TextRun, HeadingLevel,
2
+ AlignmentType
3
+ } = require("docx")
2
4
  const { saveAs } = require('file-saver')
3
- const kmsReport = require('../kms-report')
4
5
  const utils = require('../util/utils')
6
+ const {getPartnerData} = require("fleetmap-partners");
7
+ const colWidth = 3505
5
8
 
6
- exports.exportKmsReportToWord = (userData, reportData) => {
7
- const excel = kmsReport.exportKmsReportToExcel(userData, reportData)
9
+ function formatCellValue(value) {
10
+ return value.toLocaleDateString ? value.toLocaleDateString() : value + ''
11
+ }
12
+
13
+ exports.reportToWord = async (userData, reportData, excel, title) => {
8
14
  console.log('excel', excel)
15
+ const partnerData = getPartnerData(userData.user)
16
+
9
17
  if (!excel.data.length && utils.isClientSide()) {
10
18
  alert('Não há dados')
11
19
  return
12
20
  }
21
+ const logo = await utils.getLogo(userData.user)
22
+ console.log('logo', logo)
13
23
  const table = new Table({
14
- rows: excel.data.map(r => new TableRow({
15
- children: r.map(c =>
16
- new TableCell({
17
- children: [new Paragraph(c)]
18
- }))
19
- }))
24
+ columnWidths: excel.headers.map(() => colWidth),
25
+ rows: [
26
+ new TableRow({
27
+ children: excel.headers.map(r => new TableCell({
28
+ children: [new Paragraph(r.label)],
29
+ width: {
30
+ size: colWidth,
31
+ type: WidthType.DXA,
32
+ }
33
+ }))}),
34
+ ...excel.data.filter(r=>Object.keys(r).length).map(r => new TableRow({
35
+ children: Object.keys(r).map(k =>
36
+ new TableCell({
37
+ children: [new Paragraph(formatCellValue(r[k]))],
38
+ width: {
39
+ size: colWidth,
40
+ type: WidthType.DXA,
41
+ }
42
+ }))})),
43
+ ]
20
44
  })
21
-
22
45
  const doc = new Document({
23
46
  sections: [{
47
+ headers: {
48
+ default: new Header({
49
+ children: [
50
+ new Paragraph({
51
+ children: [
52
+ new ImageRun({
53
+ data: logo,
54
+ transformation: {
55
+ width: (partnerData.reports && partnerData.reports.logoWidth*2) || 200,
56
+ height: (partnerData.reports && partnerData.reports.logoHeight*2) || 50
57
+ }
58
+ })
59
+ ]
60
+ })
61
+ ]
62
+ })
63
+ },
24
64
  properties: {},
25
65
  children: [
66
+ new Paragraph({
67
+ children: [new TextRun(title)],
68
+ heading: HeadingLevel.HEADING_1,
69
+ alignment: AlignmentType.CENTER,
70
+ }),
71
+ new Paragraph({}),
72
+ new Paragraph(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString()),
73
+ new Paragraph({}),
26
74
  table
27
75
  ],
28
76
  }],
29
77
  })
30
78
  Packer.toBlob(doc).then(blob => {
31
- saveAs(blob, "trip.docx");
79
+ saveAs(blob, "kmsReport.docx");
32
80
  })
33
81
  }