aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-11-06 10:36:16 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-11-06 10:36:16 +1300
commit313a51dbf23ca3ee0d5ac1d1dc37d0ff05cb2abd (patch)
tree50d3fe461d4d9d26f3e730b255001208b0b4a959 /src/org/traccar
parent395249ddf82bafec4ec1bf879a6d7282cbdc2ea9 (diff)
downloadtraccar-server-313a51dbf23ca3ee0d5ac1d1dc37d0ff05cb2abd.tar.gz
traccar-server-313a51dbf23ca3ee0d5ac1d1dc37d0ff05cb2abd.tar.bz2
traccar-server-313a51dbf23ca3ee0d5ac1d1dc37d0ff05cb2abd.zip
Use distance units in Excel reports
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/reports/Events.java2
-rw-r--r--src/org/traccar/reports/ReportUtils.java24
-rw-r--r--src/org/traccar/reports/Route.java2
-rw-r--r--src/org/traccar/reports/Summary.java2
-rw-r--r--src/org/traccar/reports/Trips.java2
5 files changed, 28 insertions, 4 deletions
diff --git a/src/org/traccar/reports/Events.java b/src/org/traccar/reports/Events.java
index 0ad6ab309..9d82b97a5 100644
--- a/src/org/traccar/reports/Events.java
+++ b/src/org/traccar/reports/Events.java
@@ -116,6 +116,8 @@ public final class Events {
jxlsContext.putVar("geofenceNames", geofenceNames);
jxlsContext.putVar("from", from);
jxlsContext.putVar("to", to);
+ jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId));
+ jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId));
jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]");
Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream);
List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build();
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index 6cbda0ede..7fcc767e9 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -16,20 +16,36 @@
*/
package org.traccar.reports;
+import org.traccar.Context;
+import org.traccar.helper.Log;
+import org.traccar.model.Position;
+
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collection;
-import org.traccar.Context;
-import org.traccar.helper.Log;
-import org.traccar.model.Position;
-
public final class ReportUtils {
private ReportUtils() {
}
+ public static String getDistanceUnit(long userId) {
+ String unit = Context.getPermissionsManager().getUser(userId).getDistanceUnit();
+ if (unit == null) {
+ unit = Context.getPermissionsManager().getServer().getDistanceUnit();
+ }
+ return unit != null ? unit : "km";
+ }
+
+ public static String getSpeedUnit(long userId) {
+ String unit = Context.getPermissionsManager().getUser(userId).getSpeedUnit();
+ if (unit == null) {
+ unit = Context.getPermissionsManager().getServer().getSpeedUnit();
+ }
+ return unit != null ? unit : "kn";
+ }
+
public static Collection<Long> getDeviceList(Collection<Long> deviceIds, Collection<Long> groupIds) {
Collection<Long> result = new ArrayList<>();
result.addAll(deviceIds);
diff --git a/src/org/traccar/reports/Route.java b/src/org/traccar/reports/Route.java
index 9ac183aea..b29e04b2e 100644
--- a/src/org/traccar/reports/Route.java
+++ b/src/org/traccar/reports/Route.java
@@ -83,6 +83,8 @@ public final class Route {
jxlsContext.putVar("sheetNames", sheetNames);
jxlsContext.putVar("from", from);
jxlsContext.putVar("to", to);
+ jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId));
+ jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId));
jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]");
Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream);
List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build();
diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java
index d008f5d88..95a3737a1 100644
--- a/src/org/traccar/reports/Summary.java
+++ b/src/org/traccar/reports/Summary.java
@@ -91,6 +91,8 @@ public final class Summary {
jxlsContext.putVar("summaries", summaries);
jxlsContext.putVar("from", from);
jxlsContext.putVar("to", to);
+ jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId));
+ jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId));
JxlsHelper.getInstance().setUseFastFormulaProcessor(false)
.processTemplate(inputStream, outputStream, jxlsContext);
}
diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java
index 5a3a9a355..91a080d45 100644
--- a/src/org/traccar/reports/Trips.java
+++ b/src/org/traccar/reports/Trips.java
@@ -202,6 +202,8 @@ public final class Trips {
jxlsContext.putVar("sheetNames", sheetNames);
jxlsContext.putVar("from", from);
jxlsContext.putVar("to", to);
+ jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId));
+ jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId));
Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream);
List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build();
for (Area xlsArea : xlsAreas) {