fleetmap-reports 1.0.684 → 1.0.685
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/package.json +1 -1
- package/src/fuelconsumption-report.js +26 -12
- package/src/util/utils.js +1 -1
package/package.json
CHANGED
|
@@ -55,12 +55,11 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
55
55
|
new Map()
|
|
56
56
|
)
|
|
57
57
|
|
|
58
|
-
const odooAvgConsumption = useOdooFuelData(d, route) ? getOdooAvgConsumption(refuelingPositions, trips) : 0
|
|
59
|
-
|
|
60
58
|
const days = []
|
|
61
59
|
const keys = Array.from(groupedTripsByDay.keys())
|
|
62
60
|
|
|
63
61
|
keys.forEach(day => {
|
|
62
|
+
const odooAvgConsumption = useOdooFuelData(d, route) ? getOdooAvgConsumption(day, refuelingPositions, trips) : 0
|
|
64
63
|
const dayTrips = groupedTripsByDay.get(day)
|
|
65
64
|
const dayRefueling = groupedRefuelingsByDay.get(day)
|
|
66
65
|
const distance = dayTrips.reduce((a, b) => a + b.distance, 0)
|
|
@@ -94,13 +93,21 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
94
93
|
return reportData
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
function getOdooAvgConsumption (
|
|
98
|
-
const
|
|
99
|
-
|
|
96
|
+
function getOdooAvgConsumption (day, allRefuelingPositions, trips) {
|
|
97
|
+
const refuelingData = allRefuelingPositions.filter(r => new Date(r.date).getTime() > new Date(day).getTime())
|
|
98
|
+
let odooFuel
|
|
99
|
+
let kms
|
|
100
|
+
if (!refuelingData.length) {
|
|
101
|
+
odooFuel = allRefuelingPositions.reduce((a, b) => a + b.diff, 0)
|
|
102
|
+
kms = trips.reduce((a, b) => a + b.distance, 0)
|
|
103
|
+
} else {
|
|
104
|
+
odooFuel = allRefuelingPositions.filter(r => new Date(r.date).getTime() <= new Date(refuelingData[0].date).getTime()).reduce((a, b) => a + b.diff, 0)
|
|
105
|
+
kms = trips.filter(t => new Date(t.startDate).getTime() < new Date(refuelingData[0].date).getTime()).reduce((a, b) => a + b.distance, 0)
|
|
106
|
+
}
|
|
100
107
|
|
|
101
|
-
if (
|
|
108
|
+
if (kms === 0 || odooFuel === 0) { return { byKms: 0, byLiters: 0 } }
|
|
102
109
|
|
|
103
|
-
return calculateAvgConsumption(
|
|
110
|
+
return calculateAvgConsumption(odooFuel, kms)
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
function getCanAvgConsumption (distance, spentFuel) {
|
|
@@ -110,7 +117,7 @@ function getCanAvgConsumption (distance, spentFuel) {
|
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
function calculateAvgConsumption (fuel, distance) {
|
|
113
|
-
return { byKms:
|
|
120
|
+
return { byKms: fuel * 100 / (distance / 1000), byLiters: (distance / 1000) / fuel }
|
|
114
121
|
}
|
|
115
122
|
|
|
116
123
|
function calculateConsumption (userData, d, day, avgConsumption, data) {
|
|
@@ -118,7 +125,7 @@ function calculateConsumption (userData, d, day, avgConsumption, data) {
|
|
|
118
125
|
return automaticReports.calculateXpertSpentFuel(day, data.route)
|
|
119
126
|
}
|
|
120
127
|
if (useOdooFuelData(d, data.route)) {
|
|
121
|
-
return
|
|
128
|
+
return (avgConsumption.byKms * (data.trips.reduce((a, b) => a + b.distance, 0) / 1000) / 100)
|
|
122
129
|
}
|
|
123
130
|
return automaticReports.calculateSpentFuel(data.trips.reduce((a, b) => a + b.spentFuel, 0), d)
|
|
124
131
|
}
|
|
@@ -212,7 +219,6 @@ async function exportFuelConsumptionReportToPDF (userData, reportData) {
|
|
|
212
219
|
doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space + 20)
|
|
213
220
|
doc.text(convertToLocaleString(reportData.from, lang, timezone) + ' - ' + convertToLocaleString(reportData.to, lang, timezone), 20, space + 25)
|
|
214
221
|
|
|
215
|
-
console.log(d.days)
|
|
216
222
|
d.days.forEach(r =>
|
|
217
223
|
data.push([
|
|
218
224
|
r.date,
|
|
@@ -223,7 +229,7 @@ async function exportFuelConsumptionReportToPDF (userData, reportData) {
|
|
|
223
229
|
(r.endOdometer / 1000).toFixed(1),
|
|
224
230
|
r.refueling
|
|
225
231
|
]))
|
|
226
|
-
|
|
232
|
+
|
|
227
233
|
const footValues = [
|
|
228
234
|
'Total:' + d.days.length,
|
|
229
235
|
getTotalKms(userData.user, d.days),
|
|
@@ -235,7 +241,15 @@ async function exportFuelConsumptionReportToPDF (userData, reportData) {
|
|
|
235
241
|
]
|
|
236
242
|
|
|
237
243
|
const style = getStyle(getUserPartner(userData.user))
|
|
238
|
-
addTable(doc, headers, data, footValues, style, space + (userData.allWeek ? 40 : 45)
|
|
244
|
+
addTable(doc, headers, data, footValues, style, space + (userData.allWeek ? 40 : 45),
|
|
245
|
+
{
|
|
246
|
+
1: { halign: 'right' },
|
|
247
|
+
2: { halign: 'right' },
|
|
248
|
+
3: { halign: 'right' },
|
|
249
|
+
4: { halign: 'right' },
|
|
250
|
+
5: { halign: 'right' },
|
|
251
|
+
6: { halign: 'right' }
|
|
252
|
+
})
|
|
239
253
|
})
|
|
240
254
|
|
|
241
255
|
return doc
|
package/src/util/utils.js
CHANGED
|
@@ -39,7 +39,7 @@ function convertMS (duration, withSeconds) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
exports.formatNumber = function formatNumber (value, lang) {
|
|
42
|
-
return Intl.NumberFormat(lang, { maximumFractionDigits: 1 }).format(value)
|
|
42
|
+
return Intl.NumberFormat(lang, { maximumFractionDigits: 1, minimumFractionDigits: 1 }).format(value)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function coordsDistance (lon1, lat1, lon2, lat2) {
|