fleetmap-reports 1.0.248 → 1.0.249

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.
@@ -1,7 +1,7 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="ChangeListManager">
4
- <list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="refactor speeding and trip report">
4
+ <list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="Kms report with time period">
5
5
  <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
6
6
  <change beforePath="$PROJECT_DIR$/src/index.test.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.test.js" afterDir="false" />
7
7
  <change beforePath="$PROJECT_DIR$/src/kms-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/kms-report.js" afterDir="false" />
@@ -192,7 +192,10 @@
192
192
  <workItem from="1638792860278" duration="2140000" />
193
193
  <workItem from="1638839462028" duration="50000" />
194
194
  <workItem from="1638840110567" duration="597000" />
195
- <workItem from="1638888787940" duration="18005000" />
195
+ <workItem from="1638888787940" duration="19894000" />
196
+ <workItem from="1639074912454" duration="257000" />
197
+ <workItem from="1639090037682" duration="2514000" />
198
+ <workItem from="1639135460686" duration="2390000" />
196
199
  </task>
197
200
  <task id="LOCAL-00001" summary="Fix getStyle">
198
201
  <created>1636983717385</created>
@@ -257,7 +260,14 @@
257
260
  <option name="project" value="LOCAL" />
258
261
  <updated>1638288337135</updated>
259
262
  </task>
260
- <option name="localTasksCounter" value="10" />
263
+ <task id="LOCAL-00010" summary="Kms report with time period">
264
+ <created>1639057192380</created>
265
+ <option name="number" value="00010" />
266
+ <option name="presentableId" value="LOCAL-00010" />
267
+ <option name="project" value="LOCAL" />
268
+ <updated>1639057192382</updated>
269
+ </task>
270
+ <option name="localTasksCounter" value="11" />
261
271
  <servers />
262
272
  </component>
263
273
  <component name="TypeScriptGeneratedFilesManager">
@@ -285,6 +295,7 @@
285
295
  <MESSAGE value="Kms Report - Calculate distance with traccar trips" />
286
296
  <MESSAGE value="fix speeding report" />
287
297
  <MESSAGE value="refactor speeding and trip report" />
288
- <option name="LAST_COMMIT_MESSAGE" value="refactor speeding and trip report" />
298
+ <MESSAGE value="Kms report with time period" />
299
+ <option name="LAST_COMMIT_MESSAGE" value="Kms report with time period" />
289
300
  </component>
290
301
  </project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.248",
3
+ "version": "1.0.249",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/kms-report.js CHANGED
@@ -6,6 +6,7 @@ const {getStyle} = require("./reportStyle");
6
6
  const {headerFromUser,addTable} = require("./util/pdfDocument");
7
7
  const {getUserPartner} = require("fleetmap-partners");
8
8
  const traccar = require("./util/traccar");
9
+ const {getDates} = require("./util/utils");
9
10
 
10
11
 
11
12
  let traccarInstance
@@ -57,9 +58,20 @@ function processDevices(from, to, devices, route, trips) {
57
58
  new Map()
58
59
  )
59
60
 
61
+ const allDates = getDates(from, to)
62
+
60
63
  const days = []
61
- const keys = Array.from(groupedTrips.keys())
62
- keys.forEach(key => {
64
+ let keys = Array.from(groupedTrips.keys())
65
+ allDates.forEach(d => {
66
+ const day = d.toISOString().split('T')[0] + ' 12:00 PM'
67
+ if(!keys.includes(day)){
68
+ groupedTrips.set(day, [])
69
+ }
70
+ })
71
+
72
+ keys = Array.from(groupedTrips.keys())
73
+ keys.sort((a,b)=>new Date(a).getTime()-new Date(b).getTime());
74
+ keys.forEach(key => {
63
75
  const currentDate = new Date(key)
64
76
  let dayTrips = groupedTrips.get(key)
65
77
  const day = {
package/src/util/utils.js CHANGED
@@ -29,6 +29,21 @@ function coordsDistance(lon1, lat1, lon2, lat2) {
29
29
  return (turf.distance(from, to, 'meters'))
30
30
  }
31
31
 
32
+ function getDates(startDate, endDate) {
33
+ const dates = []
34
+ let currentDate = startDate
35
+ const addDays = function (days) {
36
+ const date = new Date(this.valueOf())
37
+ date.setDate(date.getDate() + days)
38
+ return date
39
+ }
40
+ while (currentDate <= endDate) {
41
+ dates.push(currentDate)
42
+ currentDate = addDays.call(currentDate, 1)
43
+ }
44
+ return dates
45
+ }
46
+
32
47
  async function getImgFromUrl(hostname) {
33
48
  try {
34
49
  const img = new Image()
@@ -43,4 +58,5 @@ async function getImgFromUrl(hostname) {
43
58
  exports.getImgFromUrl = getImgFromUrl
44
59
  exports.convertMS = convertMS
45
60
  exports.coordsDistance = coordsDistance
61
+ exports.getDates = getDates
46
62