Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 440913af9c | |||
| 66d01afe6e | |||
| ad4a399dc8 | |||
| 2137bf7702 | |||
| 47bdf7b505 | |||
| 669bffa955 | |||
| 05c5381a06 | |||
| e623e3ad1a | |||
| c43a2f639a | |||
| e66e5b7724 | |||
| adfd70fe98 | |||
| ebebcacdc9 | |||
| 3299c13181 | |||
| 2661f8ae36 | |||
| 091cfdcc99 | |||
| 9771dc4c25 | |||
| c0db2c5c1e | |||
| 2ecb113918 | |||
| 966cac280f | |||
| 2749707546 | |||
| f1bf36bcb9 | |||
| 3322e2f6bd | |||
| 9ef929dbd5 | |||
| dc33aaad49 | |||
| 15cf09f326 | |||
| 1e099ec8b6 | |||
| e8f7815d8d | |||
| bfaebf17d0 | |||
| d314ed4a16 |
@@ -0,0 +1,4 @@
|
||||
# Don't track .vscode directory
|
||||
.vscode
|
||||
!.vscode/launch.json
|
||||
|
||||
@@ -116,6 +116,21 @@ services:
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
### Install on Kubernetes
|
||||
|
||||
You can install Hammond on Kubernetes by using Helm. The
|
||||
[Helm chart for Hammond](https://github.com/djjudas21/charts/tree/main/charts/hammond)
|
||||
is maintained by djjudas21.
|
||||
|
||||
Check out the default [`values.yaml`](https://github.com/djjudas21/charts/blob/main/charts/hammond/values.yaml)
|
||||
to see what you can override.
|
||||
|
||||
```console
|
||||
helm repo add djjudas21 https://djjudas21.github.io/charts/
|
||||
helm repo update djjudas21
|
||||
helm install djjudas21/hammond
|
||||
```
|
||||
|
||||
### Build from Source / Ubuntu Installation
|
||||
|
||||
Although personally I feel that using the docker container is the best way of using
|
||||
|
||||
+2
-1
@@ -14,6 +14,7 @@
|
||||
|
||||
# MS VSCode
|
||||
.vscode
|
||||
!.vscode/launch.json
|
||||
__debug_bin
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
@@ -22,4 +23,4 @@ assets/*
|
||||
keys/*
|
||||
backups/*
|
||||
nodemon.json
|
||||
dist/*
|
||||
dist/*
|
||||
|
||||
@@ -25,6 +25,33 @@ func RandString(n int) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// A helper to convert from litres to gallon
|
||||
func LitreToGallon(litres float32) float32 {
|
||||
gallonConversionFactor := 0.21997
|
||||
return litres * float32(gallonConversionFactor);
|
||||
}
|
||||
|
||||
// A helper to convert from gallon to litres
|
||||
func GallonToLitre(gallons float32) float32 {
|
||||
litreConversionFactor := 3.785412
|
||||
return gallons * float32(litreConversionFactor);
|
||||
}
|
||||
|
||||
|
||||
// A helper to convert from km to miles
|
||||
func KmToMiles(km float32) float32 {
|
||||
kmConversionFactor := 0.62137119
|
||||
return km * float32(kmConversionFactor);
|
||||
}
|
||||
|
||||
// A helper to convert from miles to km
|
||||
func MilesToKm(miles float32) float32 {
|
||||
milesConversionFactor := 1.609344
|
||||
return miles * float32(milesConversionFactor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// A Util function to generate jwt_token which can be used in the request header
|
||||
func GenToken(id string, role db.Role) (string, string) {
|
||||
jwt_token := jwt.New(jwt.GetSigningMethod("HS256"))
|
||||
|
||||
@@ -2,6 +2,7 @@ package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/akhilrex/hammond/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -9,6 +10,7 @@ import (
|
||||
|
||||
func RegisteImportController(router *gin.RouterGroup) {
|
||||
router.POST("/import/fuelly", fuellyImport)
|
||||
router.POST("/import/drivvo", drivvoImport)
|
||||
}
|
||||
|
||||
func fuellyImport(c *gin.Context) {
|
||||
@@ -24,3 +26,28 @@ func fuellyImport(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
}
|
||||
|
||||
func drivvoImport(c *gin.Context) {
|
||||
bytes, err := getFileBytes(c, "file")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnprocessableEntity, err)
|
||||
return
|
||||
}
|
||||
vehicleId := c.PostForm("vehicleID")
|
||||
if vehicleId == "" {
|
||||
c.JSON(http.StatusUnprocessableEntity, "Missing Vehicle ID")
|
||||
return
|
||||
}
|
||||
importLocation, err := strconv.ParseBool(c.PostForm("importLocation"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnprocessableEntity, "Please include importLocation option.")
|
||||
return
|
||||
}
|
||||
|
||||
errors := service.DrivvoImport(bytes, c.MustGet("userId").(string), vehicleId, importLocation)
|
||||
if len(errors) > 0 {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"errors": errors})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func getMileageForVehicle(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
fillups, err := service.GetMileageByVehicleId(searchByIdQuery.Id, model.Since)
|
||||
fillups, err := service.GetMileageByVehicleId(searchByIdQuery.Id, model.Since, model.MileageOption)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnprocessableEntity, common.NewError("getMileageForVehicle", err))
|
||||
return
|
||||
|
||||
@@ -14,7 +14,7 @@ type MileageModel struct {
|
||||
FuelQuantity float32 `form:"fuelQuantity" json:"fuelQuantity" binding:"required"`
|
||||
PerUnitPrice float32 `form:"perUnitPrice" json:"perUnitPrice" binding:"required"`
|
||||
Currency string `json:"currency"`
|
||||
|
||||
DistanceUnit db.DistanceUnit `form:"distanceUnit" json:"distanceUnit"`
|
||||
Mileage float32 `form:"mileage" json:"mileage" binding:"mileage"`
|
||||
CostPerMile float32 `form:"costPerMile" json:"costPerMile" binding:"costPerMile"`
|
||||
OdoReading int `form:"odoReading" json:"odoReading" binding:"odoReading"`
|
||||
@@ -35,4 +35,5 @@ func (b *MileageModel) MarshalJSON() ([]byte, error) {
|
||||
|
||||
type MileageQueryModel struct {
|
||||
Since time.Time `json:"since" query:"since" form:"since"`
|
||||
MileageOption string `json:"mileageOption" query:"mileageOption" form:"mileageOption"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/akhilrex/hammond/db"
|
||||
)
|
||||
|
||||
func DrivvoParseExpenses(content []byte, user *db.User, vehicle *db.Vehicle) ([]db.Expense, []string) {
|
||||
expenseReader := csv.NewReader(bytes.NewReader(content))
|
||||
expenseReader.Comment = '#'
|
||||
// Read headers (there is a trailing comma at the end, that's why we have to read the first line)
|
||||
expenseReader.Read()
|
||||
expenseReader.FieldsPerRecord = 6
|
||||
expenseRecords, err := expenseReader.ReadAll()
|
||||
|
||||
var errors []string
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
println(err.Error())
|
||||
return nil, errors
|
||||
}
|
||||
|
||||
var expenses []db.Expense
|
||||
for index, record := range expenseRecords {
|
||||
date, err := time.Parse("2006-01-02 15:04:05", record[1])
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid date/time at service/expense row "+strconv.Itoa(index+1))
|
||||
}
|
||||
|
||||
totalCost, err := strconv.ParseFloat(record[2], 32)
|
||||
if err != nil {
|
||||
errors = append(errors, "Found and invalid total cost at service/expense row "+strconv.Itoa(index+1))
|
||||
}
|
||||
|
||||
odometer, err := strconv.Atoi(record[0])
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid odometer reading at service/expense row "+strconv.Itoa(index+1))
|
||||
}
|
||||
|
||||
notes := fmt.Sprintf("Location: %s\nNotes: %s\n", record[4], record[5])
|
||||
|
||||
expenses = append(expenses, db.Expense{
|
||||
UserID: user.ID,
|
||||
VehicleID: vehicle.ID,
|
||||
Date: date,
|
||||
OdoReading: odometer,
|
||||
Amount: float32(totalCost),
|
||||
ExpenseType: record[3],
|
||||
Currency: user.Currency,
|
||||
DistanceUnit: user.DistanceUnit,
|
||||
Comments: notes,
|
||||
Source: "Drivvo",
|
||||
})
|
||||
}
|
||||
|
||||
return expenses, errors
|
||||
}
|
||||
|
||||
func DrivvoParseRefuelings(content []byte, user *db.User, vehicle *db.Vehicle, importLocation bool) ([]db.Fillup, []string) {
|
||||
refuelingReader := csv.NewReader(bytes.NewReader(content))
|
||||
refuelingReader.Comment = '#'
|
||||
refuelingRecords, err := refuelingReader.ReadAll()
|
||||
|
||||
var errors []string
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
println(err.Error())
|
||||
return nil, errors
|
||||
}
|
||||
|
||||
var fillups []db.Fillup
|
||||
for index, record := range refuelingRecords {
|
||||
// Skip column titles
|
||||
if index == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
date, err := time.Parse("2006-01-02 15:04:05", record[1])
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid date/time at refuel row "+strconv.Itoa(index+1))
|
||||
}
|
||||
|
||||
totalCost, err := strconv.ParseFloat(record[4], 32)
|
||||
if err != nil {
|
||||
errors = append(errors, "Found and invalid total cost at refuel row "+strconv.Itoa(index+1))
|
||||
}
|
||||
|
||||
odometer, err := strconv.Atoi(record[0])
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid odometer reading at refuel row "+strconv.Itoa(index+1))
|
||||
}
|
||||
|
||||
location := ""
|
||||
if importLocation {
|
||||
location = record[17]
|
||||
}
|
||||
|
||||
pricePerUnit, err := strconv.ParseFloat(record[3], 32)
|
||||
if err != nil {
|
||||
unit := strings.ToLower(db.FuelUnitDetails[vehicle.FuelUnit].Key)
|
||||
errors = append(errors, fmt.Sprintf("Found an invalid cost per %s at refuel row %d", unit, index+1))
|
||||
}
|
||||
|
||||
quantity, err := strconv.ParseFloat(record[5], 32)
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid quantity at refuel row "+strconv.Itoa(index+1))
|
||||
}
|
||||
|
||||
isTankFull := record[6] == "Yes"
|
||||
|
||||
// Unfortunatly, drivvo doesn't expose this info in their export
|
||||
fal := false
|
||||
|
||||
notes := fmt.Sprintf("Reason: %s\nNotes: %s\nFuel: %s\n", record[18], record[19], record[2])
|
||||
|
||||
fillups = append(fillups, db.Fillup{
|
||||
VehicleID: vehicle.ID,
|
||||
UserID: user.ID,
|
||||
Date: date,
|
||||
HasMissedFillup: &fal,
|
||||
IsTankFull: &isTankFull,
|
||||
FuelQuantity: float32(quantity),
|
||||
PerUnitPrice: float32(pricePerUnit),
|
||||
FillingStation: location,
|
||||
OdoReading: odometer,
|
||||
TotalAmount: float32(totalCost),
|
||||
FuelUnit: vehicle.FuelUnit,
|
||||
Currency: user.Currency,
|
||||
DistanceUnit: user.DistanceUnit,
|
||||
Comments: notes,
|
||||
Source: "Drivvo",
|
||||
})
|
||||
|
||||
}
|
||||
return fillups, errors
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/akhilrex/hammond/db"
|
||||
"github.com/leekchan/accounting"
|
||||
)
|
||||
|
||||
func FuellyParseAll(content []byte, userId string) ([]db.Fillup, []db.Expense, []string) {
|
||||
stream := bytes.NewReader(content)
|
||||
reader := csv.NewReader(stream)
|
||||
records, err := reader.ReadAll()
|
||||
|
||||
var errors []string
|
||||
user, err := GetUserById(userId)
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
return nil, nil, errors
|
||||
}
|
||||
|
||||
vehicles, err := GetUserVehicles(userId)
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
return nil, nil, errors
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
return nil, nil, errors
|
||||
}
|
||||
|
||||
var vehicleMap map[string]db.Vehicle = make(map[string]db.Vehicle)
|
||||
for _, vehicle := range *vehicles {
|
||||
vehicleMap[vehicle.Nickname] = vehicle
|
||||
}
|
||||
|
||||
var fillups []db.Fillup
|
||||
var expenses []db.Expense
|
||||
layout := "2006-01-02 15:04"
|
||||
altLayout := "2006-01-02 3:04 PM"
|
||||
|
||||
for index, record := range records {
|
||||
if index == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var vehicle db.Vehicle
|
||||
var ok bool
|
||||
if vehicle, ok = vehicleMap[record[4]]; !ok {
|
||||
errors = append(errors, "Found an unmapped vehicle entry at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
dateStr := record[2] + " " + record[3]
|
||||
date, err := time.Parse(layout, dateStr)
|
||||
if err != nil {
|
||||
date, err = time.Parse(altLayout, dateStr)
|
||||
}
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid date/time at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
|
||||
totalCostStr := accounting.UnformatNumber(record[9], 3, user.Currency)
|
||||
totalCost64, err := strconv.ParseFloat(totalCostStr, 32)
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid total cost at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
|
||||
totalCost := float32(totalCost64)
|
||||
odoStr := accounting.UnformatNumber(record[5], 0, user.Currency)
|
||||
odoreading, err := strconv.Atoi(odoStr)
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid odo reading at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
location := record[12]
|
||||
|
||||
//Create Fillup
|
||||
if record[0] == "Gas" {
|
||||
rateStr := accounting.UnformatNumber(record[7], 3, user.Currency)
|
||||
ratet64, err := strconv.ParseFloat(rateStr, 32)
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid cost per gallon at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
rate := float32(ratet64)
|
||||
|
||||
quantity64, err := strconv.ParseFloat(record[8], 32)
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid quantity at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
quantity := float32(quantity64)
|
||||
|
||||
notes := fmt.Sprintf("Octane:%s\nGas Brand:%s\nLocation%s\nTags:%s\nPayment Type:%s\nTire Pressure:%s\nNotes:%s\nMPG:%s",
|
||||
record[10], record[11], record[12], record[13], record[14], record[15], record[16], record[1],
|
||||
)
|
||||
|
||||
isTankFull := record[6] == "Full"
|
||||
fal := false
|
||||
fillups = append(fillups, db.Fillup{
|
||||
VehicleID: vehicle.ID,
|
||||
FuelUnit: vehicle.FuelUnit,
|
||||
FuelQuantity: quantity,
|
||||
PerUnitPrice: rate,
|
||||
TotalAmount: totalCost,
|
||||
OdoReading: odoreading,
|
||||
IsTankFull: &isTankFull,
|
||||
Comments: notes,
|
||||
FillingStation: location,
|
||||
HasMissedFillup: &fal,
|
||||
UserID: userId,
|
||||
Date: date,
|
||||
Currency: user.Currency,
|
||||
DistanceUnit: user.DistanceUnit,
|
||||
Source: "Fuelly",
|
||||
})
|
||||
|
||||
}
|
||||
if record[0] == "Service" {
|
||||
notes := fmt.Sprintf("Tags:%s\nPayment Type:%s\nNotes:%s",
|
||||
record[13], record[14], record[16],
|
||||
)
|
||||
expenses = append(expenses, db.Expense{
|
||||
VehicleID: vehicle.ID,
|
||||
Amount: totalCost,
|
||||
OdoReading: odoreading,
|
||||
Comments: notes,
|
||||
ExpenseType: record[17],
|
||||
UserID: userId,
|
||||
Currency: user.Currency,
|
||||
Date: date,
|
||||
DistanceUnit: user.DistanceUnit,
|
||||
Source: "Fuelly",
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
return fillups, expenses, errors
|
||||
}
|
||||
+81
-142
@@ -2,144 +2,12 @@ package service
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/akhilrex/hammond/db"
|
||||
"github.com/leekchan/accounting"
|
||||
)
|
||||
|
||||
func FuellyImport(content []byte, userId string) []string {
|
||||
stream := bytes.NewReader(content)
|
||||
reader := csv.NewReader(stream)
|
||||
records, err := reader.ReadAll()
|
||||
|
||||
func WriteToDB(fillups []db.Fillup, expenses []db.Expense) []string {
|
||||
var errors []string
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
return errors
|
||||
}
|
||||
|
||||
vehicles, err := GetUserVehicles(userId)
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
return errors
|
||||
}
|
||||
user, err := GetUserById(userId)
|
||||
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
return errors
|
||||
}
|
||||
|
||||
var vehicleMap map[string]db.Vehicle = make(map[string]db.Vehicle)
|
||||
for _, vehicle := range *vehicles {
|
||||
vehicleMap[vehicle.Nickname] = vehicle
|
||||
}
|
||||
|
||||
var fillups []db.Fillup
|
||||
var expenses []db.Expense
|
||||
layout := "2006-01-02 15:04"
|
||||
altLayout := "2006-01-02 3:04 PM"
|
||||
|
||||
for index, record := range records {
|
||||
if index == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var vehicle db.Vehicle
|
||||
var ok bool
|
||||
if vehicle, ok = vehicleMap[record[4]]; !ok {
|
||||
errors = append(errors, "Found an unmapped vehicle entry at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
dateStr := record[2] + " " + record[3]
|
||||
date, err := time.Parse(layout, dateStr)
|
||||
if err != nil {
|
||||
date, err = time.Parse(altLayout, dateStr)
|
||||
}
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid date/time at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
|
||||
totalCostStr := accounting.UnformatNumber(record[9], 3, user.Currency)
|
||||
totalCost64, err := strconv.ParseFloat(totalCostStr, 32)
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid total cost at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
|
||||
totalCost := float32(totalCost64)
|
||||
odoStr := accounting.UnformatNumber(record[5], 0, user.Currency)
|
||||
odoreading, err := strconv.Atoi(odoStr)
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid odo reading at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
location := record[12]
|
||||
|
||||
//Create Fillup
|
||||
if record[0] == "Gas" {
|
||||
rateStr := accounting.UnformatNumber(record[7], 3, user.Currency)
|
||||
ratet64, err := strconv.ParseFloat(rateStr, 32)
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid cost per gallon at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
rate := float32(ratet64)
|
||||
|
||||
quantity64, err := strconv.ParseFloat(record[8], 32)
|
||||
if err != nil {
|
||||
errors = append(errors, "Found an invalid quantity at row "+strconv.Itoa(index+1))
|
||||
}
|
||||
quantity := float32(quantity64)
|
||||
|
||||
notes := fmt.Sprintf("Octane:%s\nGas Brand:%s\nLocation%s\nTags:%s\nPayment Type:%s\nTire Pressure:%s\nNotes:%s\nMPG:%s",
|
||||
record[10], record[11], record[12], record[13], record[14], record[15], record[16], record[1],
|
||||
)
|
||||
|
||||
isTankFull := record[6] == "Full"
|
||||
fal := false
|
||||
fillups = append(fillups, db.Fillup{
|
||||
VehicleID: vehicle.ID,
|
||||
FuelUnit: vehicle.FuelUnit,
|
||||
FuelQuantity: quantity,
|
||||
PerUnitPrice: rate,
|
||||
TotalAmount: totalCost,
|
||||
OdoReading: odoreading,
|
||||
IsTankFull: &isTankFull,
|
||||
Comments: notes,
|
||||
FillingStation: location,
|
||||
HasMissedFillup: &fal,
|
||||
UserID: userId,
|
||||
Date: date,
|
||||
Currency: user.Currency,
|
||||
DistanceUnit: user.DistanceUnit,
|
||||
Source: "Fuelly",
|
||||
})
|
||||
|
||||
}
|
||||
if record[0] == "Service" {
|
||||
notes := fmt.Sprintf("Tags:%s\nPayment Type:%s\nNotes:%s",
|
||||
record[13], record[14], record[16],
|
||||
)
|
||||
expenses = append(expenses, db.Expense{
|
||||
VehicleID: vehicle.ID,
|
||||
Amount: totalCost,
|
||||
OdoReading: odoreading,
|
||||
Comments: notes,
|
||||
ExpenseType: record[17],
|
||||
UserID: userId,
|
||||
Currency: user.Currency,
|
||||
Date: date,
|
||||
DistanceUnit: user.DistanceUnit,
|
||||
Source: "Fuelly",
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
if len(errors) != 0 {
|
||||
return errors
|
||||
}
|
||||
|
||||
tx := db.DB.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@@ -150,19 +18,90 @@ func FuellyImport(content []byte, userId string) []string {
|
||||
errors = append(errors, err.Error())
|
||||
return errors
|
||||
}
|
||||
if err := tx.Create(&fillups).Error; err != nil {
|
||||
tx.Rollback()
|
||||
errors = append(errors, err.Error())
|
||||
return errors
|
||||
if fillups != nil {
|
||||
if err := tx.Create(&fillups).Error; err != nil {
|
||||
tx.Rollback()
|
||||
errors = append(errors, err.Error())
|
||||
return errors
|
||||
}
|
||||
}
|
||||
if err := tx.Create(&expenses).Error; err != nil {
|
||||
tx.Rollback()
|
||||
errors = append(errors, err.Error())
|
||||
return errors
|
||||
if expenses != nil {
|
||||
if err := tx.Create(&expenses).Error; err != nil {
|
||||
tx.Rollback()
|
||||
errors = append(errors, err.Error())
|
||||
return errors
|
||||
}
|
||||
}
|
||||
err = tx.Commit().Error
|
||||
err := tx.Commit().Error
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
}
|
||||
return errors
|
||||
|
||||
}
|
||||
|
||||
func DrivvoImport(content []byte, userId string, vehicleId string, importLocation bool) []string {
|
||||
var errors []string
|
||||
user, err := GetUserById(userId)
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
return errors
|
||||
}
|
||||
|
||||
vehicle, err := GetVehicleById(vehicleId)
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
return errors
|
||||
}
|
||||
|
||||
endParseIndex := bytes.Index(content, []byte("#Income"))
|
||||
if endParseIndex == -1 {
|
||||
endParseIndex = bytes.Index(content, []byte("#Route"))
|
||||
if endParseIndex == -1 {
|
||||
endParseIndex = len(content)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
serviceEndIndex := bytes.Index(content, []byte("#Expense"))
|
||||
if serviceEndIndex == -1 {
|
||||
serviceEndIndex = endParseIndex
|
||||
}
|
||||
|
||||
refuelEndIndex := bytes.Index(content, []byte("#Service"))
|
||||
if refuelEndIndex == -1 {
|
||||
refuelEndIndex = serviceEndIndex
|
||||
}
|
||||
|
||||
var fillups []db.Fillup
|
||||
fillups, errors = DrivvoParseRefuelings(content[:refuelEndIndex], user, vehicle, importLocation)
|
||||
|
||||
var allExpenses []db.Expense
|
||||
services, parseErrors := DrivvoParseExpenses(content[refuelEndIndex:serviceEndIndex], user, vehicle)
|
||||
if parseErrors != nil {
|
||||
errors = append(errors, parseErrors...)
|
||||
}
|
||||
allExpenses = append(allExpenses, services...)
|
||||
|
||||
expenses, parseErrors := DrivvoParseExpenses(content[serviceEndIndex:endParseIndex], user, vehicle)
|
||||
if parseErrors != nil {
|
||||
errors = append(errors, parseErrors...)
|
||||
}
|
||||
|
||||
allExpenses = append(allExpenses, expenses...)
|
||||
|
||||
if len(errors) != 0 {
|
||||
return errors
|
||||
}
|
||||
|
||||
return WriteToDB(fillups, allExpenses)
|
||||
}
|
||||
|
||||
func FuellyImport(content []byte, userId string) []string {
|
||||
fillups, expenses, errors := FuellyParseAll(content, userId)
|
||||
if len(errors) != 0 {
|
||||
return errors
|
||||
}
|
||||
|
||||
return WriteToDB(fillups, expenses)
|
||||
}
|
||||
|
||||
@@ -4,11 +4,12 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/akhilrex/hammond/common"
|
||||
"github.com/akhilrex/hammond/db"
|
||||
"github.com/akhilrex/hammond/models"
|
||||
)
|
||||
|
||||
func GetMileageByVehicleId(vehicleId string, since time.Time) (mileage []models.MileageModel, err error) {
|
||||
func GetMileageByVehicleId(vehicleId string, since time.Time, mileageOption string) (mileage []models.MileageModel, err error) {
|
||||
data, err := db.GetFillupsByVehicleIdSince(vehicleId, since)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -36,14 +37,48 @@ func GetMileageByVehicleId(vehicleId string, since time.Time) (mileage []models.
|
||||
PerUnitPrice: currentFillup.PerUnitPrice,
|
||||
OdoReading: currentFillup.OdoReading,
|
||||
Currency: currentFillup.Currency,
|
||||
DistanceUnit: currentFillup.DistanceUnit,
|
||||
Mileage: 0,
|
||||
CostPerMile: 0,
|
||||
}
|
||||
|
||||
if currentFillup.IsTankFull != nil && *currentFillup.IsTankFull && (currentFillup.HasMissedFillup == nil || !(*currentFillup.HasMissedFillup)) {
|
||||
distance := float32(currentFillup.OdoReading - lastFillup.OdoReading)
|
||||
mileage.Mileage = distance / currentFillup.FuelQuantity
|
||||
mileage.CostPerMile = distance / currentFillup.TotalAmount
|
||||
currentOdoReading := float32(currentFillup.OdoReading);
|
||||
lastFillupOdoReading := float32(lastFillup.OdoReading);
|
||||
currentFuelQuantity := float32(currentFillup.FuelQuantity);
|
||||
// If miles per gallon option and distanceUnit is km, convert from km to miles
|
||||
// then check if fuel unit is litres. If it is, convert to gallons
|
||||
if (mileageOption == "mpg" && mileage.DistanceUnit == db.KILOMETERS) {
|
||||
currentOdoReading = common.KmToMiles(currentOdoReading);
|
||||
lastFillupOdoReading = common.KmToMiles(lastFillupOdoReading);
|
||||
if (mileage.FuelUnit == db.LITRE) {
|
||||
currentFuelQuantity = common.LitreToGallon(currentFuelQuantity);
|
||||
}
|
||||
}
|
||||
|
||||
// If km_litre option or litre per 100km and distanceUnit is miles, convert from miles to km
|
||||
// then check if fuel unit is not litres. If it isn't, convert to litres
|
||||
|
||||
if ((mileageOption == "km_litre" || mileageOption == "litre_100km") && mileage.DistanceUnit == db.MILES) {
|
||||
currentOdoReading = common.MilesToKm(currentOdoReading);
|
||||
lastFillupOdoReading = common.MilesToKm(lastFillupOdoReading);
|
||||
|
||||
if (mileage.FuelUnit == db.US_GALLON) {
|
||||
currentFuelQuantity = common.GallonToLitre(currentFuelQuantity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
distance := float32(currentOdoReading - lastFillupOdoReading);
|
||||
if (mileageOption == "litre_100km") {
|
||||
mileage.Mileage = currentFuelQuantity / distance * 100;
|
||||
} else {
|
||||
mileage.Mileage = distance / currentFuelQuantity;
|
||||
}
|
||||
|
||||
mileage.CostPerMile = distance / currentFillup.TotalAmount;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -29,3 +29,8 @@ yarn-error.log*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw*
|
||||
|
||||
#Vs code files
|
||||
.vscode
|
||||
!.vscode/launch.json
|
||||
|
||||
|
||||
Vendored
-30
@@ -1,30 +0,0 @@
|
||||
{
|
||||
"BaseButton": {
|
||||
"scope": "vue-html",
|
||||
"prefix": "BaseButton",
|
||||
"body": ["<BaseButton>", "\t${3}", "</BaseButton>"],
|
||||
"description": "<BaseButton>"
|
||||
},
|
||||
"BaseIcon": {
|
||||
"scope": "vue-html",
|
||||
"prefix": "BaseIcon",
|
||||
"body": ["<BaseIcon name=\"${1}\">", "\t${2}", "</BaseIcon>"],
|
||||
"description": "<BaseIcon>"
|
||||
},
|
||||
"BaseInputText": {
|
||||
"scope": "vue-html",
|
||||
"prefix": "BaseInputText",
|
||||
"body": ["<BaseInputText ${1}/>"],
|
||||
"description": "<BaseInputText>"
|
||||
},
|
||||
"BaseLink": {
|
||||
"scope": "vue-html",
|
||||
"prefix": "BaseLink",
|
||||
"body": [
|
||||
"<BaseLink ${1|name,:to,href|}=\"${2:route}\">",
|
||||
"\t${3}",
|
||||
"</BaseLink>"
|
||||
],
|
||||
"description": "<BaseLink>"
|
||||
}
|
||||
}
|
||||
Vendored
-26
@@ -1,26 +0,0 @@
|
||||
{
|
||||
"script": {
|
||||
"scope": "vue",
|
||||
"prefix": "script",
|
||||
"body": ["<script>", "export default {", "\t${0}", "}", "</script>"],
|
||||
"description": "<script>"
|
||||
},
|
||||
"template": {
|
||||
"scope": "vue",
|
||||
"prefix": "template",
|
||||
"body": ["<template>", "\t${0}", "</template>"],
|
||||
"description": "<template>"
|
||||
},
|
||||
"style": {
|
||||
"scope": "vue",
|
||||
"prefix": "style",
|
||||
"body": [
|
||||
"<style lang=\"scss\" module>",
|
||||
"@import '@design';",
|
||||
"",
|
||||
"${0}",
|
||||
"</style>"
|
||||
],
|
||||
"description": "<style lang=\"scss\" module>"
|
||||
}
|
||||
}
|
||||
Vendored
-37
@@ -1,37 +0,0 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
// Syntax highlighting and more for .vue files
|
||||
// https://github.com/vuejs/vetur
|
||||
"octref.vetur",
|
||||
|
||||
// Peek and go-to-definition for .vue files
|
||||
// https://github.com/fuzinato/vscode-vue-peek
|
||||
"dariofuzinato.vue-peek",
|
||||
|
||||
// Lint-on-save with ESLint
|
||||
// https://github.com/microsoft/vscode-eslint
|
||||
"dbaeumer.vscode-eslint",
|
||||
|
||||
// Lint-on-save with Stylelint
|
||||
// https://github.com/stylelint/vscode-stylelint
|
||||
"stylelint.vscode-stylelint",
|
||||
|
||||
// Lint-on-save markdown in README files
|
||||
// https://github.com/DavidAnson/vscode-markdownlint
|
||||
"DavidAnson.vscode-markdownlint",
|
||||
|
||||
// Format-on-save with Prettier
|
||||
// https://github.com/prettier/prettier-vscode
|
||||
"esbenp.prettier-vscode",
|
||||
|
||||
// SCSS intellisense
|
||||
// https://github.com/mrmlnc/vscode-scss
|
||||
"mrmlnc.vscode-scss",
|
||||
|
||||
// Test `.unit.js` files on save with Jest
|
||||
// https://github.com/jest-community/vscode-jest
|
||||
"Orta.vscode-jest"
|
||||
]
|
||||
}
|
||||
Vendored
-93
@@ -1,93 +0,0 @@
|
||||
{
|
||||
// ===
|
||||
// Spacing
|
||||
// ===
|
||||
|
||||
"editor.insertSpaces": true,
|
||||
"editor.tabSize": 2,
|
||||
"editor.trimAutoWhitespace": true,
|
||||
"files.trimTrailingWhitespace": true,
|
||||
"files.eol": "\n",
|
||||
"files.insertFinalNewline": true,
|
||||
"files.trimFinalNewlines": true,
|
||||
|
||||
// ===
|
||||
// Files
|
||||
// ===
|
||||
|
||||
"files.exclude": {
|
||||
"**/*.log": true,
|
||||
"**/*.log*": true,
|
||||
"**/dist": true,
|
||||
"**/coverage": true
|
||||
},
|
||||
"files.associations": {
|
||||
".markdownlintrc": "jsonc"
|
||||
},
|
||||
|
||||
// ===
|
||||
// Event Triggers
|
||||
// ===
|
||||
|
||||
"editor.formatOnSave": true,
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true,
|
||||
"source.fixAll.stylelint": true,
|
||||
"source.fixAll.markdownlint": true
|
||||
},
|
||||
"eslint.validate": [
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"vue",
|
||||
"vue-html",
|
||||
"html"
|
||||
],
|
||||
"vetur.format.enable": false,
|
||||
"vetur.completion.scaffoldSnippetSources": {
|
||||
"user": "🗒️",
|
||||
"workspace": "💼",
|
||||
"vetur": ""
|
||||
},
|
||||
"prettier.disableLanguages": [],
|
||||
|
||||
// ===
|
||||
// HTML
|
||||
// ===
|
||||
|
||||
"html.format.enable": false,
|
||||
"vetur.validation.template": false,
|
||||
"emmet.triggerExpansionOnTab": true,
|
||||
"emmet.includeLanguages": {
|
||||
"vue-html": "html"
|
||||
},
|
||||
"vetur.completion.tagCasing": "initial",
|
||||
|
||||
// ===
|
||||
// JS(ON)
|
||||
// ===
|
||||
|
||||
"jest.autoEnable": false,
|
||||
"jest.enableCodeLens": false,
|
||||
"javascript.format.enable": false,
|
||||
"json.format.enable": false,
|
||||
"vetur.validation.script": false,
|
||||
|
||||
// ===
|
||||
// CSS
|
||||
// ===
|
||||
|
||||
"stylelint.enable": true,
|
||||
"css.validate": false,
|
||||
"scss.validate": false,
|
||||
"vetur.validation.style": false,
|
||||
|
||||
// ===
|
||||
// MARKDOWN
|
||||
// ===
|
||||
|
||||
"[markdown]": {
|
||||
"editor.wordWrap": "wordWrapColumn",
|
||||
"editor.wordWrapColumn": 80
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,20 @@ import { Line } from 'vue-chartjs'
|
||||
|
||||
import axios from 'axios'
|
||||
import { mapState } from 'vuex'
|
||||
import { string } from 'yargs'
|
||||
export default {
|
||||
extends: Line,
|
||||
props: { vehicle: { type: Object, required: true }, since: { type: Date, default: '' }, user: { type: Object, required: true } },
|
||||
props: {
|
||||
vehicle: { type: Object, required: true },
|
||||
since: { type: Date, default: '' },
|
||||
user: { type: Object, required: true },
|
||||
mileageOption: { type: string, default: 'litre_100km' },
|
||||
},
|
||||
data: function() {
|
||||
return {
|
||||
chartData: [],
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState('utils', ['isMobile']),
|
||||
},
|
||||
@@ -17,20 +28,28 @@ export default {
|
||||
this.fetchMileage()
|
||||
},
|
||||
},
|
||||
data: function() {
|
||||
return {
|
||||
chartData: [],
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.fetchMileage()
|
||||
},
|
||||
methods: {
|
||||
showChart() {
|
||||
let mileageLabel = ''
|
||||
switch (this.mileageOption) {
|
||||
case 'litre_100km':
|
||||
mileageLabel = 'L/100km'
|
||||
break
|
||||
case 'km_litre':
|
||||
mileageLabel = 'km/L'
|
||||
break
|
||||
case 'mpg':
|
||||
mileageLabel = 'mpg'
|
||||
break
|
||||
}
|
||||
|
||||
var labels = this.chartData.map((x) => x.date.substr(0, 10))
|
||||
var dataset = {
|
||||
steppedLine: true,
|
||||
label: `${this.$t('odometer')} (${this.$t('unit.short.' + this.user.distanceUnitDetail.key)}/${this.$t('unit.short.' + this.vehicle.fuelUnitDetail.key)})`,
|
||||
label: `Mileage (${mileageLabel})`,
|
||||
fill: true,
|
||||
data: this.chartData.map((x) => x.mileage),
|
||||
}
|
||||
@@ -41,6 +60,7 @@ export default {
|
||||
.get(`/api/vehicles/${this.vehicle.id}/mileage`, {
|
||||
params: {
|
||||
since: this.since,
|
||||
mileageOption: this.mileageOption,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
|
||||
+16
-16
@@ -13,7 +13,7 @@
|
||||
"addattachment": "Anhang hinzufügen",
|
||||
"sharedwith": "Geteilt mit",
|
||||
"share": "Teile",
|
||||
"you": "Sie",
|
||||
"you": "du",
|
||||
"addfillup": "Tankfüllung erfassen",
|
||||
"createfillup": "Erfasse Tankfüllung",
|
||||
"deletefillup": "Lösche diese Tankfüllung",
|
||||
@@ -28,7 +28,7 @@
|
||||
"changepassword": "Passwort ändern",
|
||||
"oldpassword": "Bisheriges Passwort",
|
||||
"newpassword": "Neues Passwort",
|
||||
"repeatnewpassword": "Neues Passwort wiederhiolen",
|
||||
"repeatnewpassword": "Neues Passwort wiederholen",
|
||||
"passworddontmatch": "Passwörter stimmen nicht überein",
|
||||
"save": "Speichern",
|
||||
"supportthedeveloper": "Unterstütze den Entwickler",
|
||||
@@ -56,7 +56,7 @@
|
||||
"password": "Passwort",
|
||||
"login": "Anmelden",
|
||||
"totalexpenses": "Gesamtausgaben",
|
||||
"fillupcost": "Tank Ausgaben",
|
||||
"fillupcost": "Tank-Ausgaben",
|
||||
"otherexpenses": "Andere Ausgaben",
|
||||
"addvehicle": "Fahrzeug hinzufügen",
|
||||
"editvehicle": "Fahrzeug bearbeiten",
|
||||
@@ -124,17 +124,17 @@
|
||||
"name": "Name",
|
||||
"delete": "Löschen",
|
||||
"importdata": "Importiere Daten in Hammond",
|
||||
"importdatadesc": "Wähle eine der folgenden Optionen um Daten in Hammond zu importieren",
|
||||
"importdatadesc": "Wähle eine der folgenden Optionen, um Daten in Hammond zu importieren",
|
||||
"import": "Importieren",
|
||||
"importcsv": "Wenn du {name} nutzt um deine Fahrzeugdaten zu verwalten, exportiere die CSV Datei aus {name} und klicke hier zum importieren.",
|
||||
"importcsv": "Wenn du {name} nutzt, um deine Fahrzeugdaten zu verwalten, exportiere die CSV Datei aus {name} und klicke hier, um zu importieren.",
|
||||
"choosecsv": "CSV auswählen",
|
||||
"choosephoto": "Foto auswählen",
|
||||
"importsuccessfull": "Daten erfolgreich importiert",
|
||||
"importerror": "Beim importieren der Datei ist ein Fehler aufgetreten. Details findest du in der Fehlermeldung",
|
||||
"importerror": "Beim Importieren der Datei ist ein Fehler aufgetreten. Details findest du in der Fehlermeldung",
|
||||
"importfrom": "Importiere von {name}",
|
||||
"stepstoimport": "Schritte um Daten aus {name} zu importieren",
|
||||
"choosecsvimport": "Wähle die {name} CSV aus und klicke den Button zum importieren.",
|
||||
"dontimportagain": "Achte darauf, dass du die Datei nicht erneut importierst, da dies zu wiederholten Einträgen führen würde.",
|
||||
"stepstoimport": "Schritte, um Daten aus {name} zu importieren",
|
||||
"choosecsvimport": "Wähle die {name} CSV aus und klicke den Button, um zu importieren.",
|
||||
"dontimportagain": "Achte darauf, dass du die Datei nicht erneut importierst, da dies zu mehrfachen Einträgen führen würde.",
|
||||
"checkpointsimportcsv": "Wenn du alle diese Punkte überprüft hast kannst du unten die CSV importieren.",
|
||||
"importhintunits": "Vergewissere dich ebenfalls, dass die <u>Kraftstoffeinheit</u> und der <u>Kraftstofftyp</u> im Fahrzeug richtig eingestellt sind.",
|
||||
"importhintcurrdist": "Stelle sicher, dass die <u>Währung</u> und die <u>Entfernungseinheit</u> in Hammond korrekt eingestellt sind. Der Import erkennt die Währung nicht automatisch aus der CSV-Datei, sondern verwendet die für den Benutzer eingestellte Währung.",
|
||||
@@ -156,11 +156,11 @@
|
||||
"created": "Erstellt",
|
||||
"createnewuser": "Erstelle neuen Benutzer",
|
||||
"cancel": "Abbrechen",
|
||||
"novehicles": "Du hast noch kein Fahrzeug erstellt. Lege jetzt einen Eintrag für das zu Verwaltende Auto an.",
|
||||
"novehicles": "Du hast noch kein Fahrzeug erstellt. Lege jetzt einen Eintrag für das zu verwaltende Fahrzeug an.",
|
||||
"processed": "Bearbeitet",
|
||||
"notfound": "Nicht gefunden",
|
||||
"timeout": "Das Laden der Seite hat eine Zeitüberschreitung verursacht. Bist du sicher, dass du noch mit dem Internet verbunden bist?",
|
||||
"clicktoselect": "Klicke zum auswählen...",
|
||||
"clicktoselect": "Klicke, um auszuwählen...",
|
||||
"expenseby": "Ausgabe von",
|
||||
"selectvehicle": "Wähle ein Fahrzeug aus",
|
||||
"expensedate": "Datum der Ausgabe",
|
||||
@@ -168,11 +168,11 @@
|
||||
"fillmoredetails": "Weitere Details ausfüllen",
|
||||
"markquickentryprocessed": "Markiere gewählten Schnelleintrag als bearbeitet",
|
||||
"referquickentry": "Wähle Schnelleintrag",
|
||||
"deletequickentry": "Willst du diesen Schnelleintrag wirklcih Löschen? Diese Aktion kann nicht rückgängig gemacht werden.",
|
||||
"deletequickentry": "Willst du diesen Schnelleintrag wirklich löschen? Diese Aktion kann nicht rückgängig gemacht werden!",
|
||||
"fuelunit": "Kraftstoffeinheit",
|
||||
"fillingstation": "Tankstelle",
|
||||
"comments": "Kommentare",
|
||||
"missfillupbefore": "Hast du vergessen die vorherige Tankfüllung zu erfassen?",
|
||||
"missfillupbefore": "Hast du vergessen, die vorherige Tankfüllung zu erfassen?",
|
||||
"fillupdate": "Tankdatum",
|
||||
"fillupsavedsuccessfully": "Tankfüllung erfolgreich gespeichert",
|
||||
"expensesavedsuccessfully": "Ausgabe erfolgreich gespeichert",
|
||||
@@ -184,7 +184,7 @@
|
||||
"make": "Marke",
|
||||
"model": "Modell",
|
||||
"yearmanufacture": "Jahr der Erstzulassung",
|
||||
"enginesize": "Hubraum (in cc)",
|
||||
"enginesize": "Hubraum (in ccm)",
|
||||
"testconn": "Teste Verbindung",
|
||||
"migrate": "Migrieren",
|
||||
"init": {
|
||||
@@ -199,7 +199,7 @@
|
||||
"fresh": {
|
||||
"setupadminuser": "Erstelle einen Administrator",
|
||||
"yourpassword": "Dein Passwort",
|
||||
"youremail": "Deine E-Mail Adresse",
|
||||
"youremail": "Deine E-Mail-Adresse",
|
||||
"yourname": "Dein Name",
|
||||
"success": "Du hast dich erfolgreich registriert. Du wirst in kürze zur Anmeldung weitergeleitet und kannst Anfangen Hammond zu verwenden."
|
||||
}
|
||||
@@ -214,4 +214,4 @@
|
||||
"disable": "Sperren",
|
||||
"confirm": "Bestätigen",
|
||||
"labelforfile": "Bezeichnung für diese Datei"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,6 +410,15 @@ export default [
|
||||
},
|
||||
props: (route) => ({ user: store.state.auth.currentUser || {} }),
|
||||
},
|
||||
{
|
||||
path: '/import/drivvo',
|
||||
name: 'import-drivvo',
|
||||
component: () => lazyLoadView(import('@views/import-drivvo.vue')),
|
||||
meta: {
|
||||
authRequired: true,
|
||||
},
|
||||
props: (route) => ({ user: store.state.auth.currentUser || {} }),
|
||||
},
|
||||
{
|
||||
path: '/logout',
|
||||
name: 'logout',
|
||||
|
||||
@@ -140,7 +140,7 @@ export default {
|
||||
<b-field :label="this.$t('registration') + `*`">
|
||||
<b-input v-model="vehicleModel.registration" type="text" expanded required></b-input>
|
||||
</b-field>
|
||||
<b-field label="VIN">
|
||||
<b-field label="VIN">
|
||||
<b-input v-model="vehicleModel.vin" type="text" expanded></b-input>
|
||||
</b-field>
|
||||
<b-field :label="this.$t('fueltype') + `*`">
|
||||
@@ -168,13 +168,21 @@ export default {
|
||||
<b-field :label="this.$t('yearmanufacture') + `*`">
|
||||
<b-input v-model.number="vehicleModel.yearOfManufacture" type="number" expanded number></b-input>
|
||||
</b-field>
|
||||
<b-field :label="this.$t('yearmanufacture')">
|
||||
<b-field :label="this.$t('enginesize')">
|
||||
<b-input v-model.number="vehicleModel.engineSize" type="number" expanded number></b-input>
|
||||
</b-field>
|
||||
|
||||
<br />
|
||||
<b-field>
|
||||
<b-button tag="input" native-type="submit" :disabled="tryingToCreate" type="is-primary" :value="this.$t('save')" :label="this.$t('createvehicle')" expanded>
|
||||
<b-button
|
||||
tag="input"
|
||||
native-type="submit"
|
||||
:disabled="tryingToCreate"
|
||||
type="is-primary"
|
||||
:value="this.$t('save')"
|
||||
:label="this.$t('createvehicle')"
|
||||
expanded
|
||||
>
|
||||
<BaseIcon v-if="tryingToCreate" name="sync" spin />
|
||||
</b-button>
|
||||
<p v-if="authError">
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
<script>
|
||||
import Layout from '@layouts/main.vue'
|
||||
import { mapState } from 'vuex'
|
||||
import axios from 'axios'
|
||||
|
||||
export default {
|
||||
page: {
|
||||
title: 'Import Drivvo',
|
||||
meta: [{ name: 'description', content: 'The Import Drivvo page.' }],
|
||||
},
|
||||
components: { Layout },
|
||||
props: {
|
||||
user: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
data: function() {
|
||||
return {
|
||||
myVehicles: [],
|
||||
file: null,
|
||||
selectedVehicle: null,
|
||||
tryingToCreate: false,
|
||||
errors: [],
|
||||
importLocation: true,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState('utils', ['isMobile']),
|
||||
...mapState('vehicles', ['vehicles']),
|
||||
uploadButtonLabel() {
|
||||
if (this.isMobile) {
|
||||
if (this.file == null) {
|
||||
return 'Choose Photo'
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
} else {
|
||||
if (this.file == null) {
|
||||
return 'Choose CSV'
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.myVehicles = this.vehicles
|
||||
},
|
||||
methods: {
|
||||
importDrivvo() {
|
||||
console.log('Import from drivvo')
|
||||
if (this.file == null) {
|
||||
return
|
||||
}
|
||||
this.tryingToCreate = true
|
||||
this.errorMessage = ''
|
||||
const formData = new FormData()
|
||||
formData.append('vehicleID', this.selectedVehicle)
|
||||
formData.append('importLocation', this.importLocation)
|
||||
formData.append('file', this.file, this.file.name)
|
||||
axios
|
||||
.post(`/api/import/drivvo`, formData)
|
||||
.then((data) => {
|
||||
this.$buefy.toast.open({
|
||||
message: 'Data Imported Successfully',
|
||||
type: 'is-success',
|
||||
duration: 3000,
|
||||
})
|
||||
this.file = null
|
||||
setTimeout(() => this.$router.push({ name: 'home' }), 1000)
|
||||
})
|
||||
.catch((ex) => {
|
||||
this.$buefy.toast.open({
|
||||
duration: 5000,
|
||||
message: 'There was some issue with importing the file. Please check the error message',
|
||||
position: 'is-bottom',
|
||||
type: 'is-danger',
|
||||
})
|
||||
if (ex.response && ex.response.data.errors) {
|
||||
this.errors = ex.response.data.errors
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.tryingToCreate = false
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Layout>
|
||||
<div class="columns box">
|
||||
<div class="column">
|
||||
<h1 class="title">Import from Drivvo</h1>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<p class="subtitle"> Steps to import data from Drivvo</p>
|
||||
<ol>
|
||||
<li>Export your data from Drivvo in the CSV format.</li>
|
||||
<li>Select the vehicle the exported data is for. You may need to create the vehicle in Hammond first if you haven't already done so</li>
|
||||
<li
|
||||
>Make sure that the <u>Currency</u> and <u>Distance Unit</u> are set correctly in Hammond. Drivvo does not include this information in
|
||||
their export, instead Hammond will use the values set for the user.</li
|
||||
>
|
||||
<li>Similiarly, make sure that the <u>Fuel Unit</u> and <u>Fuel Type</u> are correctly set in the Vehicle.</li>
|
||||
<li>Once you have checked all these points, select the vehicle and import the CSV below.</li>
|
||||
<li><b>Make sure that you do not import the file again as that will create repeat entries.</b></li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
<p
|
||||
><b>PS:</b> If you have <em>'income'</em> and <em>'trips'</em> in your export, they will not be imported to Hammond. The fields
|
||||
<em>'Second fuel'</em> and <em>'Third fuel'</em> are are are also ignored as the use case for these is not understood by us. If you have a use
|
||||
case for this, please open a issue on
|
||||
<a href="https://github.com/akhilrex/hammond/issues">issue tracker</a>
|
||||
</p>
|
||||
<div class="section box">
|
||||
<div class="columns is-multiline">
|
||||
<div class="column is-full"> <p class="subtitle">Choose the vehicle, then select the Drivvo CSV and press the import button.</p></div>
|
||||
<div class="column is-full is-flex is-align-content-center">
|
||||
<form @submit.prevent="importDrivvo">
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<b-field label="Vehicle" label-position="on-border">
|
||||
<b-select v-model="selectedVehicle" placeholder="Select Vehicle" required>
|
||||
<option v-for="vehicle in myVehicles" :key="vehicle.id" :value="vehicle.id">{{ vehicle.nickname }}</option>
|
||||
</b-select>
|
||||
</b-field>
|
||||
</div>
|
||||
<div class="column">
|
||||
<b-field>
|
||||
<b-tooltip label="Whether to import the location for fillups and services or not." multilined>
|
||||
<b-checkbox v-model="importLocation">Import Location?</b-checkbox>
|
||||
</b-tooltip>
|
||||
</b-field>
|
||||
</div>
|
||||
|
||||
<div class="column">
|
||||
<b-field class="file is-primary" :class="{ 'has-name': !!file }">
|
||||
<b-upload v-model="file" class="file-label" accept=".csv" required>
|
||||
<span class="file-cta">
|
||||
<b-icon class="file-icon" icon="upload"></b-icon>
|
||||
<span class="file-label">{{ uploadButtonLabel }}</span>
|
||||
</span>
|
||||
<span v-if="file" class="file-name" :class="isMobile ? 'file-name-mobile' : 'file-name-desktop'">
|
||||
{{ file.name }}
|
||||
</span>
|
||||
</b-upload>
|
||||
</b-field>
|
||||
</div>
|
||||
<div class="column">
|
||||
<b-button tag="input" native-type="submit" :disabled="tryingToCreate" type="is-primary" value="Upload File" class="control">
|
||||
Import
|
||||
</b-button>
|
||||
</div></div
|
||||
>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<b-message v-if="errors.length" type="is-danger">
|
||||
<ul>
|
||||
<li v-for="error in errors" :key="error">{{ error }}</li>
|
||||
</ul>
|
||||
</b-message>
|
||||
</Layout>
|
||||
</template>
|
||||
@@ -58,6 +58,7 @@ export default {
|
||||
duration: 3000,
|
||||
})
|
||||
this.file = null
|
||||
setTimeout(() => this.$router.push({ name: 'home' }), 1000)
|
||||
})
|
||||
.catch((ex) => {
|
||||
this.$buefy.toast.open({
|
||||
@@ -108,7 +109,7 @@ export default {
|
||||
<div class="columns"
|
||||
><div class="column">
|
||||
<b-field class="file is-primary" :class="{ 'has-name': !!file }">
|
||||
<b-upload v-model="file" class="file-label" accept=".csv">
|
||||
<b-upload v-model="file" class="file-label" accept=".csv" required>
|
||||
<span class="file-cta">
|
||||
<b-icon class="file-icon" icon="upload"></b-icon>
|
||||
<span class="file-label">{{ uploadButtonLabel }}</span>
|
||||
|
||||
@@ -26,11 +26,22 @@ export default {
|
||||
>
|
||||
<br />
|
||||
<div class="columns">
|
||||
<div class="box column is-one-third" to="/import-fuelly">
|
||||
<h1 class="title">Fuelly</h1>
|
||||
<p>{{ $t('importcsv', { 'name': 'Fuelly' }) }}</p>
|
||||
<br />
|
||||
<b-button type="is-primary" tag="router-link" to="/import/fuelly">{{ $t('import') }}</b-button>
|
||||
<div class="column is-one-third">
|
||||
<div class="box">
|
||||
<h1 class="title">Fuelly</h1>
|
||||
<p>If you have been using Fuelly to store your vehicle data, export the CSV file from Fuelly and click here to import.</p>
|
||||
<br />
|
||||
<b-button type="is-primary" tag="router-link" to="/import/fuelly">{{ $t('import') }}</b-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column is-one-third" to="/import-fuelly">
|
||||
<div class="box">
|
||||
<h1 class="title">Drivvo</h1>
|
||||
<p>{{ $t('importcsv', { 'name': 'Fuelly' }) }}</p>
|
||||
<br />
|
||||
<b-button type="is-primary" tag="router-link" to="/import/drivvo">{{ $t('import') }}</b-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
|
||||
@@ -48,6 +48,12 @@ export default {
|
||||
{ label: this.$t('alltime'), value: 'all_time' },
|
||||
],
|
||||
dateRangeOption: 'past_30_days',
|
||||
mileageOptions: [
|
||||
{ label: 'L/100km', value: 'litre_100km' },
|
||||
{ label: 'km/L', value: 'km_litre' },
|
||||
{ label: 'mpg', value: 'mpg' },
|
||||
],
|
||||
mileageOption: 'litre_100km',
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -529,14 +535,25 @@ export default {
|
||||
<div class="columns">
|
||||
<div class="column" :class="isMobile ? 'has-text-centered' : ''"> <h1 class="title">{{ $t('statistics') }}</h1></div>
|
||||
<div class="column">
|
||||
<b-select v-model="dateRangeOption" class="is-pulled-right is-medium">
|
||||
<option v-for="option in dateRangeOptions" :key="option.value" :value="option.value">
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</b-select></div
|
||||
>
|
||||
<div class="columns is-pulled-right is-medium">
|
||||
<div class="column">
|
||||
<b-select v-model="mileageOption">
|
||||
<option v-for="option in mileageOptions" :key="option.value" :value="option.value">
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</b-select>
|
||||
</div>
|
||||
<div class="column">
|
||||
<b-select v-model="dateRangeOption">
|
||||
<option v-for="option in dateRangeOptions" :key="option.value" :value="option.value">
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</b-select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<MileageChart :vehicle="vehicle" :since="getStartDate()" :user="me" :height="300" />
|
||||
<MileageChart :vehicle="vehicle" :since="getStartDate()" :user="me" :height="300" :mileage-option="mileageOption" />
|
||||
</div>
|
||||
</Layout>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user