fleetmap-reports 1.0.526 → 1.0.528
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/lang/enGB.js +3 -0
- package/lang/esCL.js +3 -0
- package/lang/ptBR.js +3 -0
- package/lang/ptPT.js +3 -0
- package/package.json +1 -1
- package/src/fuelconsumption-report.js +74 -8
- package/src/kms-report.js +1 -1
package/lang/enGB.js
CHANGED
|
@@ -221,6 +221,9 @@ module.exports = {
|
|
|
221
221
|
vehicles: 'Vehicles',
|
|
222
222
|
vehicle: 'Vehicle',
|
|
223
223
|
licensePlate: 'License Plate',
|
|
224
|
+
consumption: 'Consumption (L)',
|
|
225
|
+
avg_consumption: 'Avg. Consumption (L/100)',
|
|
226
|
+
avg_consumption_by_liters: 'Avg. Consumption (Kms/L)',
|
|
224
227
|
odometer: 'Odometer',
|
|
225
228
|
startOdometer: 'Start (Km)',
|
|
226
229
|
endOdometer: 'End (Km)',
|
package/lang/esCL.js
CHANGED
|
@@ -210,6 +210,9 @@ module.exports = {
|
|
|
210
210
|
duration: 'Duracción',
|
|
211
211
|
vehicles: 'Vehículos',
|
|
212
212
|
vehicle: 'Vehículo',
|
|
213
|
+
consumption: 'Consumo (L)',
|
|
214
|
+
avg_consumption: 'Consumo (L/100)',
|
|
215
|
+
avg_consumption_by_liters: 'Consumo (Kms/L)',
|
|
213
216
|
odometer: 'Km',
|
|
214
217
|
startOdometer: 'Start (Km)',
|
|
215
218
|
endOdometer: 'End (Km)',
|
package/lang/ptBR.js
CHANGED
|
@@ -212,6 +212,9 @@ module.exports = {
|
|
|
212
212
|
duration: 'Duração',
|
|
213
213
|
vehicles: 'Veículos',
|
|
214
214
|
vehicle: 'Veículo',
|
|
215
|
+
consumption: 'Consumo (L)',
|
|
216
|
+
avg_consumption: 'Consumo (L/100)',
|
|
217
|
+
avg_consumption_by_liters: 'Consumo (Kms/L)',
|
|
215
218
|
licensePlate: 'Placa',
|
|
216
219
|
odometer: 'Conta-Quilómetros',
|
|
217
220
|
startOdometer: 'Início (Km)',
|
package/lang/ptPT.js
CHANGED
|
@@ -218,6 +218,9 @@ module.exports = {
|
|
|
218
218
|
duration: 'Duração',
|
|
219
219
|
vehicles: 'Veículos',
|
|
220
220
|
vehicle: 'Veículo',
|
|
221
|
+
consumption: 'Consumo (L)',
|
|
222
|
+
avg_consumption: 'Consumo (L/100)',
|
|
223
|
+
avg_consumption_by_liters: 'Consumo (Kms/L)',
|
|
221
224
|
licensePlate: 'Matrícula',
|
|
222
225
|
odometer: 'Conta-Quilómetros',
|
|
223
226
|
startOdometer: 'Início (Km)',
|
package/package.json
CHANGED
|
@@ -3,7 +3,11 @@ const refuelingReport = require('./refueling-report')
|
|
|
3
3
|
const traccarHelper = require('./util/traccar')
|
|
4
4
|
const odoo = require('./util/odoo')
|
|
5
5
|
const { devicesToProcess } = require('./util/device')
|
|
6
|
-
const { getTranslations } = require('./util/utils')
|
|
6
|
+
const { getTranslations, convertToLocaleString, getLanguage } = require('./util/utils')
|
|
7
|
+
const { getStyle } = require('./reportStyle')
|
|
8
|
+
const { getUserPartner } = require('fleetmap-partners')
|
|
9
|
+
const { addTable, headerFromUser } = require('./util/pdfDocument')
|
|
10
|
+
const jsPDF = require('jspdf')
|
|
7
11
|
|
|
8
12
|
async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
9
13
|
console.log('Create FuelConsumption Report')
|
|
@@ -66,7 +70,7 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
66
70
|
date: day,
|
|
67
71
|
distance,
|
|
68
72
|
spentFuel,
|
|
69
|
-
avgConsumption: userData.withOdooServices ? odooAvgConsumption : getCanAvgConsumption(
|
|
73
|
+
avgConsumption: userData.withOdooServices ? odooAvgConsumption : getCanAvgConsumption(distance, spentFuel),
|
|
70
74
|
endOdometer: dayTrips.slice(-1)[0].endOdometer,
|
|
71
75
|
duration: dayTrips.reduce((a, b) => a + b.duration, 0),
|
|
72
76
|
refueling: (dayRefueling && dayRefueling.length > 0) ? dayRefueling.reduce((a, b) => a + b.diff, 0) : 0
|
|
@@ -99,7 +103,7 @@ function getOdooAvgConsumption (refuelingPositions, trips) {
|
|
|
99
103
|
return { byKms: odooTotalfuel * 100 / (totalKms / 1000), byLiters: (totalKms / 1000) / odooTotalfuel }
|
|
100
104
|
}
|
|
101
105
|
|
|
102
|
-
function getCanAvgConsumption (
|
|
106
|
+
function getCanAvgConsumption (distance, spentFuel) {
|
|
103
107
|
if (distance === 0 || spentFuel === 0) { return { byKms: 0, byLiters: 0 } }
|
|
104
108
|
|
|
105
109
|
return { byKms: Math.round(spentFuel * 100 / (distance / 1000)), byLiters: Math.round((distance / 1000) / spentFuel) }
|
|
@@ -117,19 +121,20 @@ function calculateConsumption (userData, d, day, avgConsumption, data) {
|
|
|
117
121
|
|
|
118
122
|
function exportFuelConsumptionReportToExcel (userData, reportData) {
|
|
119
123
|
const translations = getTranslations(userData)
|
|
124
|
+
const lang = getLanguage(userData)
|
|
120
125
|
|
|
121
126
|
const settings = {
|
|
122
127
|
sheetName: 'FuelConsumptionReport', // The name of the sheet
|
|
123
128
|
fileName: 'FuelConsumptionReport' // The name of the spreadsheet
|
|
124
129
|
}
|
|
125
130
|
const headers = [
|
|
126
|
-
{ label: translations.report.
|
|
131
|
+
{ label: translations.report.vehicle, value: 'name' },
|
|
127
132
|
{ label: translations.report.date, value: 'date' },
|
|
128
|
-
{ label: translations.report.
|
|
133
|
+
{ label: translations.report.distance, value: 'kms' },
|
|
129
134
|
{ label: translations.report.consumption, value: 'consumption' },
|
|
130
135
|
{ label: translations.report.avg_consumption, value: 'avg_consumption' },
|
|
131
136
|
{ label: translations.report.duration, value: 'duration' },
|
|
132
|
-
{ label: translations.report.
|
|
137
|
+
{ label: translations.report.odometer, value: 'accumulated_kms' },
|
|
133
138
|
{ label: translations.report.refueling, value: 'refueling' }
|
|
134
139
|
]
|
|
135
140
|
let data = []
|
|
@@ -141,7 +146,7 @@ function exportFuelConsumptionReportToExcel (userData, reportData) {
|
|
|
141
146
|
date: r.date,
|
|
142
147
|
kms: (r.distance / 1000).toFixed(2),
|
|
143
148
|
consumption: r.spentFuel > 0 ? r.spentFuel : 0,
|
|
144
|
-
avg_consumption: r.avgConsumption,
|
|
149
|
+
avg_consumption: lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms,
|
|
145
150
|
duration: new Date(r.duration).toLocaleTimeString(),
|
|
146
151
|
accumulated_kms: (r.endOdometer / 1000).toFixed(2),
|
|
147
152
|
refueling: r.refueling
|
|
@@ -156,8 +161,69 @@ function exportFuelConsumptionReportToExcel (userData, reportData) {
|
|
|
156
161
|
}
|
|
157
162
|
}
|
|
158
163
|
|
|
159
|
-
function exportFuelConsumptionReportToPDF (userData, reportData) {
|
|
164
|
+
async function exportFuelConsumptionReportToPDF (userData, reportData) {
|
|
160
165
|
console.log('Export to PDF')
|
|
166
|
+
const timezone = userData.user.attributes.timezone
|
|
167
|
+
const translations = getTranslations(userData)
|
|
168
|
+
const lang = getLanguage(userData)
|
|
169
|
+
|
|
170
|
+
const doc = new jsPDF.jsPDF('l')
|
|
171
|
+
await headerFromUser(doc, translations.report.titleFuelConsumptionReport, userData.user)
|
|
172
|
+
|
|
173
|
+
const headers = [
|
|
174
|
+
translations.report.date,
|
|
175
|
+
translations.report.distance,
|
|
176
|
+
translations.report.consumption,
|
|
177
|
+
translations.report.avg_consumption,
|
|
178
|
+
translations.report.duration,
|
|
179
|
+
translations.report.odometer,
|
|
180
|
+
translations.report.refueling
|
|
181
|
+
]
|
|
182
|
+
|
|
183
|
+
if (reportData.devices) {
|
|
184
|
+
reportData.devices.forEach((d, index) => {
|
|
185
|
+
const data = []
|
|
186
|
+
const name = deviceName(d.device)
|
|
187
|
+
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
188
|
+
|
|
189
|
+
const space = index === 0 ? 8 : 0
|
|
190
|
+
if (index) {
|
|
191
|
+
doc.addPage()
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
doc.setFontSize(13)
|
|
195
|
+
doc.text(name, 20, space + 20)
|
|
196
|
+
doc.setFontSize(11)
|
|
197
|
+
doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space + 20)
|
|
198
|
+
doc.text(convertToLocaleString(reportData.from, lang, timezone) + ' - ' + convertToLocaleString(reportData.to, lang, timezone), 20, space + 25)
|
|
199
|
+
|
|
200
|
+
console.log(d.days)
|
|
201
|
+
d.days.forEach(r =>
|
|
202
|
+
data.push([
|
|
203
|
+
r.date,
|
|
204
|
+
(r.distance / 1000).toFixed(2),
|
|
205
|
+
r.spentFuel > 0 ? r.spentFuel : 0,
|
|
206
|
+
lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms,
|
|
207
|
+
new Date(r.duration).toLocaleTimeString(),
|
|
208
|
+
(r.endOdometer / 1000).toFixed(2),
|
|
209
|
+
r.refueling
|
|
210
|
+
]))
|
|
211
|
+
console.log(data)
|
|
212
|
+
const footValues = [
|
|
213
|
+
'Total:' + d.days.length,
|
|
214
|
+
'', '', '', '', '', '', ''
|
|
215
|
+
]
|
|
216
|
+
|
|
217
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
218
|
+
addTable(doc, headers, data, footValues, style, space + (userData.allWeek ? 40 : 45))
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
return doc
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function deviceName (device) {
|
|
226
|
+
return device.name + (device.attributes.license_plate ? ', ' + device.attributes.license_plate : '') + (device.model ? ', ' + device.model : '')
|
|
161
227
|
}
|
|
162
228
|
|
|
163
229
|
exports.createFuelConsumptionReport = createFuelConsumptionReport
|
package/src/kms-report.js
CHANGED
|
@@ -375,7 +375,7 @@ function exportKmsReportToExcel (userData, reportData) {
|
|
|
375
375
|
if (userData.groupByDay) {
|
|
376
376
|
headers.push(
|
|
377
377
|
{ label: translations.report.vehicle, value: 'name' },
|
|
378
|
-
{ label: translations.
|
|
378
|
+
{ label: translations.settings.vehicle_licenseplate, value: 'licenseplate' },
|
|
379
379
|
{ label: translations.report.group, value: 'group' },
|
|
380
380
|
{ label: translations.report.date, value: 'date' },
|
|
381
381
|
{ label: translations.report.weekDay, value: 'weekday' },
|