Compare commits
61 Commits
Author | SHA1 | Date | |
---|---|---|---|
7435ac3667 | |||
55dffbbe89 | |||
212c81ab81 | |||
5b5b8215c3 | |||
79c0fceafe | |||
1ea3590fd6 | |||
5bb2c9c8b8 | |||
f9e512c593 | |||
4f72351ee9 | |||
9ed4df7053 | |||
78389e4beb | |||
8ac3c22826 | |||
ab07d3472d | |||
466df523ab | |||
f51807e459 | |||
03d1d1e520 | |||
d09f5be69b | |||
b5a03b40db | |||
966c0ce0eb | |||
635f4de402 | |||
ddf51b5922 | |||
bbbeff92e8 | |||
5ccec61465 | |||
696fbee7cc | |||
7c694fb32c | |||
5f746f5889 | |||
24e5b18ded | |||
253ecd1720 | |||
f445f19233 | |||
ea6d198bff | |||
28c20aacd3 | |||
d89a8f4e2e | |||
dae9abeeea | |||
510c91205d | |||
f93888cbbc | |||
674bef667b | |||
fffc91269e | |||
c3175b9be6 | |||
1d81aa2fb3 | |||
e5cf439231 | |||
cfd2388de0 | |||
0dfa698ada | |||
b4aec52d4f | |||
b5e3e7bea0 | |||
e98e0d4779 | |||
6686904539 | |||
0478d82c1f | |||
34b6e450de | |||
bc65249c03 | |||
e0dc7800af | |||
a7cd3512bb | |||
ece610419f | |||
27188e2e27 | |||
4c7c61e820 | |||
2adb70fa01 | |||
eeb2d425e5 | |||
484b1062e1 | |||
a4ca21bb37 | |||
ffabf1bca9 | |||
e9d4ed1b3e | |||
4085868cd7 |
@ -13,6 +13,7 @@ linters:
|
|||||||
- exhaustivestruct
|
- exhaustivestruct
|
||||||
- gci # not working, shows errors on freshly formatted file
|
- gci # not working, shows errors on freshly formatted file
|
||||||
- varnamelen
|
- varnamelen
|
||||||
|
- lll
|
||||||
linters-settings:
|
linters-settings:
|
||||||
errcheck:
|
errcheck:
|
||||||
exclude-functions:
|
exclude-functions:
|
||||||
|
@ -65,6 +65,7 @@ tasks:
|
|||||||
desc: Run CI build
|
desc: Run CI build
|
||||||
cmds:
|
cmds:
|
||||||
- task: build-prod
|
- task: build-prod
|
||||||
|
- go test ./...
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
desc: Build vue frontend
|
desc: Build vue frontend
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
FROM alpine as godeps
|
FROM alpine as godeps
|
||||||
RUN apk add go
|
RUN apk --no-cache add go
|
||||||
RUN go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
|
RUN go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
|
||||||
RUN go install github.com/go-task/task/v3/cmd/task@latest
|
RUN go install github.com/go-task/task/v3/cmd/task@latest
|
||||||
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||||
|
|
||||||
FROM alpine
|
FROM alpine
|
||||||
RUN apk add go
|
RUN apk --no-cache add go nodejs yarn bash curl git git-perl tmux
|
||||||
RUN apk add nodejs yarn bash curl git git-perl tmux
|
|
||||||
ADD docker/build.sh /
|
ADD docker/build.sh /
|
||||||
RUN yarn global add @vue/cli
|
RUN yarn global add @vue/cli
|
||||||
ENV PATH="/root/.yarn/bin/:${PATH}"
|
ENV PATH="/root/.yarn/bin/:${PATH}"
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
ADD web/package.json /src/web/
|
ADD web/package.json web/yarn.lock /src/web/
|
||||||
RUN yarn
|
RUN yarn
|
||||||
COPY --from=godeps /root/go/bin/task /root/go/bin/sqlc /root/go/bin/golangci-lint /usr/local/bin/
|
COPY --from=godeps /root/go/bin/task /root/go/bin/sqlc /root/go/bin/golangci-lint /usr/local/bin/
|
||||||
CMD /build.sh
|
CMD /build.sh
|
||||||
|
@ -6,6 +6,7 @@ package postgres
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ type GetAccountsWithBalanceRow struct {
|
|||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
Name string
|
Name string
|
||||||
OnBudget bool
|
OnBudget bool
|
||||||
Balance Numeric
|
Balance numeric.Numeric
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetAccountsWithBalance(ctx context.Context, budgetID uuid.UUID) ([]GetAccountsWithBalanceRow, error) {
|
func (q *Queries) GetAccountsWithBalance(ctx context.Context, budgetID uuid.UUID) ([]GetAccountsWithBalanceRow, error) {
|
||||||
@ -127,3 +128,76 @@ func (q *Queries) GetAccountsWithBalance(ctx context.Context, budgetID uuid.UUID
|
|||||||
}
|
}
|
||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const searchAccounts = `-- name: SearchAccounts :many
|
||||||
|
SELECT accounts.id, accounts.budget_id, accounts.name, true as is_account FROM accounts
|
||||||
|
WHERE accounts.budget_id = $1
|
||||||
|
AND accounts.name LIKE $2
|
||||||
|
ORDER BY accounts.name
|
||||||
|
`
|
||||||
|
|
||||||
|
type SearchAccountsParams struct {
|
||||||
|
BudgetID uuid.UUID
|
||||||
|
Search string
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchAccountsRow struct {
|
||||||
|
ID uuid.UUID
|
||||||
|
BudgetID uuid.UUID
|
||||||
|
Name string
|
||||||
|
IsAccount bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) SearchAccounts(ctx context.Context, arg SearchAccountsParams) ([]SearchAccountsRow, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, searchAccounts, arg.BudgetID, arg.Search)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []SearchAccountsRow
|
||||||
|
for rows.Next() {
|
||||||
|
var i SearchAccountsRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.BudgetID,
|
||||||
|
&i.Name,
|
||||||
|
&i.IsAccount,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateAccount = `-- name: UpdateAccount :one
|
||||||
|
UPDATE accounts
|
||||||
|
SET name = $1,
|
||||||
|
on_budget = $2
|
||||||
|
WHERE accounts.id = $3
|
||||||
|
RETURNING id, budget_id, name, on_budget
|
||||||
|
`
|
||||||
|
|
||||||
|
type UpdateAccountParams struct {
|
||||||
|
Name string
|
||||||
|
OnBudget bool
|
||||||
|
ID uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) UpdateAccount(ctx context.Context, arg UpdateAccountParams) (Account, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, updateAccount, arg.Name, arg.OnBudget, arg.ID)
|
||||||
|
var i Account
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.BudgetID,
|
||||||
|
&i.Name,
|
||||||
|
&i.OnBudget,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ RETURNING id, category_id, date, memo, amount
|
|||||||
|
|
||||||
type CreateAssignmentParams struct {
|
type CreateAssignmentParams struct {
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Amount Numeric
|
Amount numeric.Numeric
|
||||||
CategoryID uuid.UUID
|
CategoryID uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +54,49 @@ func (q *Queries) DeleteAllAssignments(ctx context.Context, budgetID uuid.UUID)
|
|||||||
return result.RowsAffected()
|
return result.RowsAffected()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getAllAssignments = `-- name: GetAllAssignments :many
|
||||||
|
SELECT assignments.date, categories.name as category, category_groups.name as group, assignments.amount
|
||||||
|
FROM assignments
|
||||||
|
INNER JOIN categories ON categories.id = assignments.category_id
|
||||||
|
INNER JOIN category_groups ON categories.category_group_id = category_groups.id
|
||||||
|
WHERE category_groups.budget_id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
type GetAllAssignmentsRow struct {
|
||||||
|
Date time.Time
|
||||||
|
Category string
|
||||||
|
Group string
|
||||||
|
Amount numeric.Numeric
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) GetAllAssignments(ctx context.Context, budgetID uuid.UUID) ([]GetAllAssignmentsRow, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getAllAssignments, budgetID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []GetAllAssignmentsRow
|
||||||
|
for rows.Next() {
|
||||||
|
var i GetAllAssignmentsRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.Date,
|
||||||
|
&i.Category,
|
||||||
|
&i.Group,
|
||||||
|
&i.Amount,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const getAssignmentsByMonthAndCategory = `-- name: GetAssignmentsByMonthAndCategory :many
|
const getAssignmentsByMonthAndCategory = `-- name: GetAssignmentsByMonthAndCategory :many
|
||||||
SELECT date, category_id, budget_id, amount
|
SELECT date, category_id, budget_id, amount
|
||||||
FROM assignments_by_month
|
FROM assignments_by_month
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,10 +24,10 @@ ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id
|
|||||||
type GetCumultativeBalancesRow struct {
|
type GetCumultativeBalancesRow struct {
|
||||||
Date time.Time
|
Date time.Time
|
||||||
CategoryID uuid.UUID
|
CategoryID uuid.UUID
|
||||||
Assignments Numeric
|
Assignments numeric.Numeric
|
||||||
AssignmentsCum Numeric
|
AssignmentsCum numeric.Numeric
|
||||||
Transactions Numeric
|
Transactions numeric.Numeric
|
||||||
TransactionsCum Numeric
|
TransactionsCum numeric.Numeric
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetCumultativeBalances(ctx context.Context, budgetID uuid.UUID) ([]GetCumultativeBalancesRow, error) {
|
func (q *Queries) GetCumultativeBalances(ctx context.Context, budgetID uuid.UUID) ([]GetCumultativeBalancesRow, error) {
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ type Assignment struct {
|
|||||||
CategoryID uuid.UUID
|
CategoryID uuid.UUID
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Memo sql.NullString
|
Memo sql.NullString
|
||||||
Amount Numeric
|
Amount numeric.Numeric
|
||||||
}
|
}
|
||||||
|
|
||||||
type AssignmentsByMonth struct {
|
type AssignmentsByMonth struct {
|
||||||
@ -81,7 +82,7 @@ type Transaction struct {
|
|||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Memo string
|
Memo string
|
||||||
Amount Numeric
|
Amount numeric.Numeric
|
||||||
AccountID uuid.UUID
|
AccountID uuid.UUID
|
||||||
CategoryID uuid.NullUUID
|
CategoryID uuid.NullUUID
|
||||||
PayeeID uuid.NullUUID
|
PayeeID uuid.NullUUID
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package postgres
|
package numeric
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/jackc/pgtype"
|
"github.com/jackc/pgtype"
|
||||||
)
|
)
|
||||||
@ -11,10 +13,18 @@ type Numeric struct {
|
|||||||
pgtype.Numeric
|
pgtype.Numeric
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewZeroNumeric() Numeric {
|
func Zero() Numeric {
|
||||||
return Numeric{pgtype.Numeric{Exp: 0, Int: big.NewInt(0), Status: pgtype.Present, NaN: false}}
|
return Numeric{pgtype.Numeric{Exp: 0, Int: big.NewInt(0), Status: pgtype.Present, NaN: false}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FromInt64(value int64) Numeric {
|
||||||
|
return Numeric{Numeric: pgtype.Numeric{Int: big.NewInt(value), Status: pgtype.Present}}
|
||||||
|
}
|
||||||
|
|
||||||
|
func FromInt64WithExp(value int64, exp int32) Numeric {
|
||||||
|
return Numeric{Numeric: pgtype.Numeric{Int: big.NewInt(value), Exp: exp, Status: pgtype.Present}}
|
||||||
|
}
|
||||||
|
|
||||||
func (n Numeric) GetFloat64() float64 {
|
func (n Numeric) GetFloat64() float64 {
|
||||||
if n.Status != pgtype.Present {
|
if n.Status != pgtype.Present {
|
||||||
return 0
|
return 0
|
||||||
@ -73,6 +83,10 @@ func (n Numeric) Sub(other Numeric) Numeric {
|
|||||||
panic("Cannot subtract with different exponents")
|
panic("Cannot subtract with different exponents")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n Numeric) Neg() Numeric {
|
||||||
|
return Numeric{pgtype.Numeric{Exp: n.Exp, Int: big.NewInt(-1 * n.Int.Int64()), Status: n.Status}}
|
||||||
|
}
|
||||||
|
|
||||||
func (n Numeric) Add(other Numeric) Numeric {
|
func (n Numeric) Add(other Numeric) Numeric {
|
||||||
left := n
|
left := n
|
||||||
right := other
|
right := other
|
||||||
@ -92,9 +106,50 @@ func (n Numeric) Add(other Numeric) Numeric {
|
|||||||
panic("Cannot add with different exponents")
|
panic("Cannot add with different exponents")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n Numeric) String() string {
|
||||||
|
if n.Int == nil || n.Int.Int64() == 0 {
|
||||||
|
return "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
s := fmt.Sprintf("%d", n.Int)
|
||||||
|
bytes := []byte(s)
|
||||||
|
|
||||||
|
exp := n.Exp
|
||||||
|
for exp > 0 {
|
||||||
|
bytes = append(bytes, byte('0'))
|
||||||
|
exp--
|
||||||
|
}
|
||||||
|
|
||||||
|
if exp == 0 {
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
length := int32(len(bytes))
|
||||||
|
var bytesWithSeparator []byte
|
||||||
|
|
||||||
|
exp = -exp
|
||||||
|
for length <= exp {
|
||||||
|
if n.Int.Int64() < 0 {
|
||||||
|
bytes = append([]byte{bytes[0], byte('0')}, bytes[1:]...)
|
||||||
|
} else {
|
||||||
|
bytes = append([]byte{byte('0')}, bytes...)
|
||||||
|
}
|
||||||
|
length++
|
||||||
|
}
|
||||||
|
|
||||||
|
split := length - exp
|
||||||
|
bytesWithSeparator = append(bytesWithSeparator, bytes[:split]...)
|
||||||
|
if split == 1 && n.Int.Int64() < 0 {
|
||||||
|
bytesWithSeparator = append(bytesWithSeparator, byte('0'))
|
||||||
|
}
|
||||||
|
bytesWithSeparator = append(bytesWithSeparator, byte('.'))
|
||||||
|
bytesWithSeparator = append(bytesWithSeparator, bytes[split:]...)
|
||||||
|
return string(bytesWithSeparator)
|
||||||
|
}
|
||||||
|
|
||||||
func (n Numeric) MarshalJSON() ([]byte, error) {
|
func (n Numeric) MarshalJSON() ([]byte, error) {
|
||||||
if n.Int.Int64() == 0 {
|
if n.Int == nil || n.Int.Int64() == 0 {
|
||||||
return []byte("\"0\""), nil
|
return []byte("0"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s := fmt.Sprintf("%d", n.Int)
|
s := fmt.Sprintf("%d", n.Int)
|
||||||
@ -115,7 +170,11 @@ func (n Numeric) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
exp = -exp
|
exp = -exp
|
||||||
for length <= exp {
|
for length <= exp {
|
||||||
bytes = append(bytes, byte('0'))
|
if n.Int.Int64() < 0 {
|
||||||
|
bytes = append([]byte{bytes[0], byte('0')}, bytes[1:]...)
|
||||||
|
} else {
|
||||||
|
bytes = append([]byte{byte('0')}, bytes...)
|
||||||
|
}
|
||||||
length++
|
length++
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,3 +187,40 @@ func (n Numeric) MarshalJSON() ([]byte, error) {
|
|||||||
bytesWithSeparator = append(bytesWithSeparator, bytes[split:]...)
|
bytesWithSeparator = append(bytesWithSeparator, bytes[split:]...)
|
||||||
return bytesWithSeparator, nil
|
return bytesWithSeparator, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MustParse(text string) Numeric {
|
||||||
|
num, err := Parse(text)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return num
|
||||||
|
}
|
||||||
|
|
||||||
|
func Parse(text string) (Numeric, error) {
|
||||||
|
// Unify decimal separator
|
||||||
|
text = strings.Replace(text, ",", ".", 1)
|
||||||
|
|
||||||
|
num := Numeric{}
|
||||||
|
err := num.Set(text)
|
||||||
|
if err != nil {
|
||||||
|
return num, fmt.Errorf("parse numeric %s: %w", text, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return num, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseCurrency(text string) (Numeric, error) {
|
||||||
|
// Remove trailing currency
|
||||||
|
text = trimLastChar(text)
|
||||||
|
|
||||||
|
return Parse(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
func trimLastChar(s string) string {
|
||||||
|
r, size := utf8.DecodeLastRuneInString(s)
|
||||||
|
if r == utf8.RuneError && (size == 0 || size == 1) {
|
||||||
|
size = 0
|
||||||
|
}
|
||||||
|
return s[:len(s)-size]
|
||||||
|
}
|
118
postgres/numeric/numeric_test.go
Normal file
118
postgres/numeric/numeric_test.go
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
package numeric_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TestCaseMarshalJSON struct {
|
||||||
|
Value numeric.Numeric
|
||||||
|
Result string
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMarshalJSON(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
tests := []TestCaseMarshalJSON{
|
||||||
|
{numeric.Zero(), `0`},
|
||||||
|
{numeric.MustParse("1.23"), "1.23"},
|
||||||
|
{numeric.MustParse("1,24"), "1.24"},
|
||||||
|
{numeric.MustParse("1"), "1"},
|
||||||
|
{numeric.MustParse("10"), "10"},
|
||||||
|
{numeric.MustParse("100"), "100"},
|
||||||
|
{numeric.MustParse("1000"), "1000"},
|
||||||
|
{numeric.MustParse("0.1"), "0.1"},
|
||||||
|
{numeric.MustParse("0.01"), "0.01"},
|
||||||
|
{numeric.MustParse("0.001"), "0.001"},
|
||||||
|
{numeric.MustParse("0.0001"), "0.0001"},
|
||||||
|
{numeric.MustParse("-1"), "-1"},
|
||||||
|
{numeric.MustParse("-10"), "-10"},
|
||||||
|
{numeric.MustParse("-100"), "-100"},
|
||||||
|
{numeric.MustParse("-1000"), "-1000"},
|
||||||
|
{numeric.MustParse("-0.1"), "-0.1"},
|
||||||
|
{numeric.MustParse("-0.01"), "-0.01"},
|
||||||
|
{numeric.MustParse("-0.001"), "-0.001"},
|
||||||
|
{numeric.MustParse("-0.0001"), "-0.0001"},
|
||||||
|
{numeric.MustParse("123456789.12345"), "123456789.12345"},
|
||||||
|
{numeric.MustParse("123456789.12345"), "123456789.12345"},
|
||||||
|
{numeric.MustParse("-1.23"), "-1.23"},
|
||||||
|
{numeric.MustParse("-1,24"), "-1.24"},
|
||||||
|
{numeric.MustParse("-123456789.12345"), "-123456789.12345"},
|
||||||
|
}
|
||||||
|
for i := range tests {
|
||||||
|
test := tests[i]
|
||||||
|
t.Run(test.Result, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
z := test.Value
|
||||||
|
result, err := z.MarshalJSON()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(result) != test.Result {
|
||||||
|
t.Errorf("Expected %s, got %s", test.Result, string(result))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestCaseParse struct {
|
||||||
|
Result numeric.Numeric
|
||||||
|
Value string
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParse(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
tests := []TestCaseParse{
|
||||||
|
{numeric.FromInt64WithExp(0, 0), `0`},
|
||||||
|
{numeric.FromInt64WithExp(1, 0), `1`},
|
||||||
|
{numeric.FromInt64WithExp(1, 1), `10`},
|
||||||
|
{numeric.FromInt64WithExp(1, 2), `100`},
|
||||||
|
{numeric.FromInt64WithExp(1, 3), `1000`},
|
||||||
|
{numeric.FromInt64WithExp(1, -1), `0.1`},
|
||||||
|
{numeric.FromInt64WithExp(1, -2), `0.01`},
|
||||||
|
{numeric.FromInt64WithExp(1, -3), `0.001`},
|
||||||
|
{numeric.FromInt64WithExp(1, -4), `0.0001`},
|
||||||
|
{numeric.FromInt64WithExp(-1, 0), `-1`},
|
||||||
|
{numeric.FromInt64WithExp(-1, 1), `-10`},
|
||||||
|
{numeric.FromInt64WithExp(-1, 2), `-100`},
|
||||||
|
{numeric.FromInt64WithExp(-1, 3), `-1000`},
|
||||||
|
{numeric.FromInt64WithExp(-1, -1), `-0.1`},
|
||||||
|
{numeric.FromInt64WithExp(-1, -2), `-0.01`},
|
||||||
|
{numeric.FromInt64WithExp(-1, -3), `-0.001`},
|
||||||
|
{numeric.FromInt64WithExp(-1, -4), `-0.0001`},
|
||||||
|
{numeric.FromInt64WithExp(123, -2), "1.23"},
|
||||||
|
{numeric.FromInt64WithExp(124, -2), "1,24"},
|
||||||
|
{numeric.FromInt64WithExp(12345678912345, -5), "123456789.12345"},
|
||||||
|
{numeric.FromInt64WithExp(0, 0), `-0`},
|
||||||
|
{numeric.FromInt64WithExp(-1, 0), `-1`},
|
||||||
|
{numeric.FromInt64WithExp(-1, 1), `-10`},
|
||||||
|
{numeric.FromInt64WithExp(-1, 2), `-100`},
|
||||||
|
{numeric.FromInt64WithExp(-123, -2), "-1.23"},
|
||||||
|
{numeric.FromInt64WithExp(-124, -2), "-1,24"},
|
||||||
|
{numeric.FromInt64WithExp(-12345678912345, -5), "-123456789.12345"},
|
||||||
|
}
|
||||||
|
for i := range tests {
|
||||||
|
test := tests[i]
|
||||||
|
t.Run(test.Value, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
result, err := numeric.Parse(test.Value)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if test.Result.Int.Int64() != result.Int.Int64() {
|
||||||
|
t.Errorf("Expected int %d, got %d", test.Result.Int, result.Int)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if test.Result.Exp != result.Exp {
|
||||||
|
t.Errorf("Expected exp %d, got %d", test.Result.Exp, result.Exp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -19,4 +19,17 @@ FROM accounts
|
|||||||
LEFT JOIN transactions ON transactions.account_id = accounts.id AND transactions.date < NOW()
|
LEFT JOIN transactions ON transactions.account_id = accounts.id AND transactions.date < NOW()
|
||||||
WHERE accounts.budget_id = $1
|
WHERE accounts.budget_id = $1
|
||||||
GROUP BY accounts.id, accounts.name
|
GROUP BY accounts.id, accounts.name
|
||||||
ORDER BY accounts.name;
|
ORDER BY accounts.name;
|
||||||
|
|
||||||
|
-- name: SearchAccounts :many
|
||||||
|
SELECT accounts.id, accounts.budget_id, accounts.name, true as is_account FROM accounts
|
||||||
|
WHERE accounts.budget_id = @budget_id
|
||||||
|
AND accounts.name LIKE @search
|
||||||
|
ORDER BY accounts.name;
|
||||||
|
|
||||||
|
-- name: UpdateAccount :one
|
||||||
|
UPDATE accounts
|
||||||
|
SET name = $1,
|
||||||
|
on_budget = $2
|
||||||
|
WHERE accounts.id = $3
|
||||||
|
RETURNING *;
|
@ -15,4 +15,11 @@ WHERE categories.id = assignments.category_id AND category_groups.budget_id = @b
|
|||||||
-- name: GetAssignmentsByMonthAndCategory :many
|
-- name: GetAssignmentsByMonthAndCategory :many
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM assignments_by_month
|
FROM assignments_by_month
|
||||||
WHERE assignments_by_month.budget_id = @budget_id;
|
WHERE assignments_by_month.budget_id = @budget_id;
|
||||||
|
|
||||||
|
-- name: GetAllAssignments :many
|
||||||
|
SELECT assignments.date, categories.name as category, category_groups.name as group, assignments.amount
|
||||||
|
FROM assignments
|
||||||
|
INNER JOIN categories ON categories.id = assignments.category_id
|
||||||
|
INNER JOIN category_groups ON categories.category_group_id = category_groups.id
|
||||||
|
WHERE category_groups.budget_id = @budget_id;
|
@ -22,17 +22,27 @@ WHERE id = $7;
|
|||||||
DELETE FROM transactions
|
DELETE FROM transactions
|
||||||
WHERE id = $1;
|
WHERE id = $1;
|
||||||
|
|
||||||
-- name: GetTransactionsForBudget :many
|
-- name: GetAllTransactionsForBudget :many
|
||||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id, transactions.status,
|
SELECT transactions.id, transactions.date, transactions.memo,
|
||||||
accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
|
transactions.amount, transactions.group_id, transactions.status,
|
||||||
|
accounts.name as account,
|
||||||
|
COALESCE(payees.name, '') as payee,
|
||||||
|
COALESCE(category_groups.name, '') as category_group,
|
||||||
|
COALESCE(categories.name, '') as category,
|
||||||
|
COALESCE((
|
||||||
|
SELECT CONCAT(otherAccounts.name)
|
||||||
|
FROM transactions otherTransactions
|
||||||
|
LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id
|
||||||
|
WHERE otherTransactions.group_id = transactions.group_id
|
||||||
|
AND otherTransactions.id != transactions.id
|
||||||
|
), '')::text as transfer_account
|
||||||
FROM transactions
|
FROM transactions
|
||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
|
LEFT JOIN payees ON payees.id = transactions.payee_id
|
||||||
LEFT JOIN categories ON categories.id = transactions.category_id
|
LEFT JOIN categories ON categories.id = transactions.category_id
|
||||||
LEFT JOIN category_groups ON category_groups.id = categories.category_group_id
|
LEFT JOIN category_groups ON category_groups.id = categories.category_group_id
|
||||||
WHERE accounts.budget_id = $1
|
WHERE accounts.budget_id = $1
|
||||||
ORDER BY transactions.date DESC
|
ORDER BY transactions.date DESC;
|
||||||
LIMIT 200;
|
|
||||||
|
|
||||||
-- name: GetTransactionsForAccount :many
|
-- name: GetTransactionsForAccount :many
|
||||||
SELECT transactions.id, transactions.date, transactions.memo,
|
SELECT transactions.id, transactions.date, transactions.memo,
|
||||||
@ -41,13 +51,13 @@ SELECT transactions.id, transactions.date, transactions.memo,
|
|||||||
COALESCE(payees.name, '') as payee,
|
COALESCE(payees.name, '') as payee,
|
||||||
COALESCE(category_groups.name, '') as category_group,
|
COALESCE(category_groups.name, '') as category_group,
|
||||||
COALESCE(categories.name, '') as category,
|
COALESCE(categories.name, '') as category,
|
||||||
(
|
COALESCE((
|
||||||
SELECT CONCAT(otherAccounts.name)
|
SELECT CONCAT(otherAccounts.name)
|
||||||
FROM transactions otherTransactions
|
FROM transactions otherTransactions
|
||||||
LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id
|
LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id
|
||||||
WHERE otherTransactions.group_id = transactions.group_id
|
WHERE otherTransactions.group_id = transactions.group_id
|
||||||
AND otherTransactions.id != transactions.id
|
AND otherTransactions.id != transactions.id
|
||||||
) as transfer_account
|
), '')::text as transfer_account
|
||||||
FROM transactions
|
FROM transactions
|
||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
|
LEFT JOIN payees ON payees.id = transactions.payee_id
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ RETURNING id, date, memo, amount, account_id, category_id, payee_id, group_id, s
|
|||||||
type CreateTransactionParams struct {
|
type CreateTransactionParams struct {
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Memo string
|
Memo string
|
||||||
Amount Numeric
|
Amount numeric.Numeric
|
||||||
AccountID uuid.UUID
|
AccountID uuid.UUID
|
||||||
PayeeID uuid.NullUUID
|
PayeeID uuid.NullUUID
|
||||||
CategoryID uuid.NullUUID
|
CategoryID uuid.NullUUID
|
||||||
@ -79,6 +80,78 @@ func (q *Queries) DeleteTransaction(ctx context.Context, id uuid.UUID) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getAllTransactionsForBudget = `-- name: GetAllTransactionsForBudget :many
|
||||||
|
SELECT transactions.id, transactions.date, transactions.memo,
|
||||||
|
transactions.amount, transactions.group_id, transactions.status,
|
||||||
|
accounts.name as account,
|
||||||
|
COALESCE(payees.name, '') as payee,
|
||||||
|
COALESCE(category_groups.name, '') as category_group,
|
||||||
|
COALESCE(categories.name, '') as category,
|
||||||
|
COALESCE((
|
||||||
|
SELECT CONCAT(otherAccounts.name)
|
||||||
|
FROM transactions otherTransactions
|
||||||
|
LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id
|
||||||
|
WHERE otherTransactions.group_id = transactions.group_id
|
||||||
|
AND otherTransactions.id != transactions.id
|
||||||
|
), '')::text as transfer_account
|
||||||
|
FROM transactions
|
||||||
|
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||||
|
LEFT JOIN payees ON payees.id = transactions.payee_id
|
||||||
|
LEFT JOIN categories ON categories.id = transactions.category_id
|
||||||
|
LEFT JOIN category_groups ON category_groups.id = categories.category_group_id
|
||||||
|
WHERE accounts.budget_id = $1
|
||||||
|
ORDER BY transactions.date DESC
|
||||||
|
`
|
||||||
|
|
||||||
|
type GetAllTransactionsForBudgetRow struct {
|
||||||
|
ID uuid.UUID
|
||||||
|
Date time.Time
|
||||||
|
Memo string
|
||||||
|
Amount numeric.Numeric
|
||||||
|
GroupID uuid.NullUUID
|
||||||
|
Status TransactionStatus
|
||||||
|
Account string
|
||||||
|
Payee string
|
||||||
|
CategoryGroup string
|
||||||
|
Category string
|
||||||
|
TransferAccount string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) GetAllTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]GetAllTransactionsForBudgetRow, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getAllTransactionsForBudget, budgetID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []GetAllTransactionsForBudgetRow
|
||||||
|
for rows.Next() {
|
||||||
|
var i GetAllTransactionsForBudgetRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Date,
|
||||||
|
&i.Memo,
|
||||||
|
&i.Amount,
|
||||||
|
&i.GroupID,
|
||||||
|
&i.Status,
|
||||||
|
&i.Account,
|
||||||
|
&i.Payee,
|
||||||
|
&i.CategoryGroup,
|
||||||
|
&i.Category,
|
||||||
|
&i.TransferAccount,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const getTransaction = `-- name: GetTransaction :one
|
const getTransaction = `-- name: GetTransaction :one
|
||||||
SELECT id, date, memo, amount, account_id, category_id, payee_id, group_id, status FROM transactions
|
SELECT id, date, memo, amount, account_id, category_id, payee_id, group_id, status FROM transactions
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
@ -142,13 +215,13 @@ SELECT transactions.id, transactions.date, transactions.memo,
|
|||||||
COALESCE(payees.name, '') as payee,
|
COALESCE(payees.name, '') as payee,
|
||||||
COALESCE(category_groups.name, '') as category_group,
|
COALESCE(category_groups.name, '') as category_group,
|
||||||
COALESCE(categories.name, '') as category,
|
COALESCE(categories.name, '') as category,
|
||||||
(
|
COALESCE((
|
||||||
SELECT CONCAT(otherAccounts.name)
|
SELECT CONCAT(otherAccounts.name)
|
||||||
FROM transactions otherTransactions
|
FROM transactions otherTransactions
|
||||||
LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id
|
LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id
|
||||||
WHERE otherTransactions.group_id = transactions.group_id
|
WHERE otherTransactions.group_id = transactions.group_id
|
||||||
AND otherTransactions.id != transactions.id
|
AND otherTransactions.id != transactions.id
|
||||||
) as transfer_account
|
), '')::text as transfer_account
|
||||||
FROM transactions
|
FROM transactions
|
||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
|
LEFT JOIN payees ON payees.id = transactions.payee_id
|
||||||
@ -163,14 +236,14 @@ type GetTransactionsForAccountRow struct {
|
|||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Memo string
|
Memo string
|
||||||
Amount Numeric
|
Amount numeric.Numeric
|
||||||
GroupID uuid.NullUUID
|
GroupID uuid.NullUUID
|
||||||
Status TransactionStatus
|
Status TransactionStatus
|
||||||
Account string
|
Account string
|
||||||
Payee string
|
Payee string
|
||||||
CategoryGroup string
|
CategoryGroup string
|
||||||
Category string
|
Category string
|
||||||
TransferAccount interface{}
|
TransferAccount string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]GetTransactionsForAccountRow, error) {
|
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]GetTransactionsForAccountRow, error) {
|
||||||
@ -208,66 +281,6 @@ func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTransactionsForBudget = `-- name: GetTransactionsForBudget :many
|
|
||||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id, transactions.status,
|
|
||||||
accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
|
|
||||||
FROM transactions
|
|
||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
|
||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
|
|
||||||
LEFT JOIN categories ON categories.id = transactions.category_id
|
|
||||||
LEFT JOIN category_groups ON category_groups.id = categories.category_group_id
|
|
||||||
WHERE accounts.budget_id = $1
|
|
||||||
ORDER BY transactions.date DESC
|
|
||||||
LIMIT 200
|
|
||||||
`
|
|
||||||
|
|
||||||
type GetTransactionsForBudgetRow struct {
|
|
||||||
ID uuid.UUID
|
|
||||||
Date time.Time
|
|
||||||
Memo string
|
|
||||||
Amount Numeric
|
|
||||||
GroupID uuid.NullUUID
|
|
||||||
Status TransactionStatus
|
|
||||||
Account string
|
|
||||||
Payee string
|
|
||||||
CategoryGroup string
|
|
||||||
Category string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]GetTransactionsForBudgetRow, error) {
|
|
||||||
rows, err := q.db.QueryContext(ctx, getTransactionsForBudget, budgetID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
var items []GetTransactionsForBudgetRow
|
|
||||||
for rows.Next() {
|
|
||||||
var i GetTransactionsForBudgetRow
|
|
||||||
if err := rows.Scan(
|
|
||||||
&i.ID,
|
|
||||||
&i.Date,
|
|
||||||
&i.Memo,
|
|
||||||
&i.Amount,
|
|
||||||
&i.GroupID,
|
|
||||||
&i.Status,
|
|
||||||
&i.Account,
|
|
||||||
&i.Payee,
|
|
||||||
&i.CategoryGroup,
|
|
||||||
&i.Category,
|
|
||||||
); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
items = append(items, i)
|
|
||||||
}
|
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return items, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateTransaction = `-- name: UpdateTransaction :exec
|
const updateTransaction = `-- name: UpdateTransaction :exec
|
||||||
UPDATE transactions
|
UPDATE transactions
|
||||||
SET date = $1,
|
SET date = $1,
|
||||||
@ -282,7 +295,7 @@ WHERE id = $7
|
|||||||
type UpdateTransactionParams struct {
|
type UpdateTransactionParams struct {
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Memo string
|
Memo string
|
||||||
Amount Numeric
|
Amount numeric.Numeric
|
||||||
AccountID uuid.UUID
|
AccountID uuid.UUID
|
||||||
PayeeID uuid.NullUUID
|
PayeeID uuid.NullUUID
|
||||||
CategoryID uuid.NullUUID
|
CategoryID uuid.NullUUID
|
||||||
|
144
postgres/ynab-export.go
Normal file
144
postgres/ynab-export.go
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
package postgres
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/csv"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type YNABExport struct {
|
||||||
|
queries *Queries
|
||||||
|
budgetID uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewYNABExport(context context.Context, queries *Queries, budgetID uuid.UUID) (*YNABExport, error) {
|
||||||
|
return &YNABExport{
|
||||||
|
queries: queries,
|
||||||
|
budgetID: budgetID,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImportAssignments expects a TSV-file as exported by YNAB in the following format:
|
||||||
|
// "Month" "Category Group/Category" "Category Group" "Category" "Budgeted" "Activity" "Available"
|
||||||
|
// "Apr 2019" "Income: Next Month" "Income" "Next Month" 0,00€ 0,00€ 0,00€
|
||||||
|
//
|
||||||
|
// Activity and Available are not imported, since they are determined by the transactions and historic assignments.
|
||||||
|
func (ynab *YNABExport) ExportAssignments(context context.Context, w io.Writer) error {
|
||||||
|
csv := csv.NewWriter(w)
|
||||||
|
csv.Comma = '\t'
|
||||||
|
|
||||||
|
assignments, err := ynab.queries.GetAllAssignments(context, ynab.budgetID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("load assignments: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
count := 0
|
||||||
|
for _, assignment := range assignments {
|
||||||
|
row := []string{
|
||||||
|
assignment.Date.Format("Jan 2006"),
|
||||||
|
assignment.Group + ": " + assignment.Category,
|
||||||
|
assignment.Group,
|
||||||
|
assignment.Category,
|
||||||
|
assignment.Amount.String() + "€",
|
||||||
|
numeric.Zero().String() + "€",
|
||||||
|
numeric.Zero().String() + "€",
|
||||||
|
}
|
||||||
|
|
||||||
|
err := csv.Write(row)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("write assignment: %w", err)
|
||||||
|
}
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
csv.Flush()
|
||||||
|
|
||||||
|
fmt.Printf("Exported %d assignments\n", count)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImportTransactions expects a TSV-file as exported by YNAB in the following format:
|
||||||
|
// "Account" "Flag" "Date" "Payee" "Category Group/Category" "Category Group" "Category" "Memo" "Outflow" "Inflow" "Cleared"
|
||||||
|
// "Cash" "" "11.12.2021" "Transfer : Checking" "" "" "" "Brought to bank" 500,00€ 0,00€ "Cleared".
|
||||||
|
func (ynab *YNABExport) ExportTransactions(context context.Context, w io.Writer) error {
|
||||||
|
csv := csv.NewWriter(w)
|
||||||
|
csv.Comma = '\t'
|
||||||
|
|
||||||
|
transactions, err := ynab.queries.GetAllTransactionsForBudget(context, ynab.budgetID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("load transactions: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
header := []string{
|
||||||
|
"Account",
|
||||||
|
"Flag",
|
||||||
|
"Date",
|
||||||
|
"Payee",
|
||||||
|
"Category Group/Category",
|
||||||
|
"Category Group",
|
||||||
|
"Category",
|
||||||
|
"Memo",
|
||||||
|
"Outflow",
|
||||||
|
"Inflow",
|
||||||
|
"Cleared",
|
||||||
|
}
|
||||||
|
|
||||||
|
err = csv.Write(header)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("write transaction: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
count := 0
|
||||||
|
for _, transaction := range transactions {
|
||||||
|
row := GetTransactionRow(transaction)
|
||||||
|
|
||||||
|
err := csv.Write(row)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("write transaction: %w", err)
|
||||||
|
}
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
|
||||||
|
csv.Flush()
|
||||||
|
|
||||||
|
fmt.Printf("Exported %d transactions\n", count)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTransactionRow(transaction GetAllTransactionsForBudgetRow) []string {
|
||||||
|
row := []string{
|
||||||
|
transaction.Account,
|
||||||
|
"", // Flag
|
||||||
|
transaction.Date.Format("02.01.2006"),
|
||||||
|
}
|
||||||
|
|
||||||
|
if transaction.TransferAccount != "" {
|
||||||
|
row = append(row, "Transfer : "+transaction.TransferAccount)
|
||||||
|
} else {
|
||||||
|
row = append(row, transaction.Payee)
|
||||||
|
}
|
||||||
|
|
||||||
|
if transaction.CategoryGroup != "" && transaction.Category != "" {
|
||||||
|
row = append(row,
|
||||||
|
transaction.CategoryGroup+": "+transaction.Category,
|
||||||
|
transaction.CategoryGroup,
|
||||||
|
transaction.Category)
|
||||||
|
} else {
|
||||||
|
row = append(row, "", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
row = append(row, transaction.Memo)
|
||||||
|
|
||||||
|
if transaction.Amount.IsPositive() {
|
||||||
|
row = append(row, numeric.Zero().String()+"€", transaction.Amount.String()+"€")
|
||||||
|
} else {
|
||||||
|
row = append(row, transaction.Amount.String()[1:]+"€", numeric.Zero().String()+"€")
|
||||||
|
}
|
||||||
|
|
||||||
|
return append(row, string(transaction.Status))
|
||||||
|
}
|
@ -7,8 +7,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -116,7 +116,9 @@ type Transfer struct {
|
|||||||
ToAccount string
|
ToAccount string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImportTransactions expects a TSV-file as exported by YNAB.
|
// ImportTransactions expects a TSV-file as exported by YNAB in the following format:
|
||||||
|
// "Account" "Flag" "Date" "Payee" "Category Group/Category" "Category Group" "Category" "Memo" "Outflow" "Inflow" "Cleared"
|
||||||
|
// "Cash" "" "11.12.2021" "Transfer : Checking" "" "" "" "Brought to bank" 500,00€ 0,00€ "Cleared".
|
||||||
func (ynab *YNABImport) ImportTransactions(context context.Context, r io.Reader) error {
|
func (ynab *YNABImport) ImportTransactions(context context.Context, r io.Reader) error {
|
||||||
csv := csv.NewReader(r)
|
csv := csv.NewReader(r)
|
||||||
csv.Comma = '\t'
|
csv.Comma = '\t'
|
||||||
@ -240,7 +242,7 @@ func (ynab *YNABImport) ImportRegularTransaction(context context.Context, payeeN
|
|||||||
|
|
||||||
func (ynab *YNABImport) ImportTransferTransaction(context context.Context, payeeName string,
|
func (ynab *YNABImport) ImportTransferTransaction(context context.Context, payeeName string,
|
||||||
transaction CreateTransactionParams, openTransfers *[]Transfer,
|
transaction CreateTransactionParams, openTransfers *[]Transfer,
|
||||||
account *Account, amount Numeric) error {
|
account *Account, amount numeric.Numeric) error {
|
||||||
transferToAccountName := payeeName[11:]
|
transferToAccountName := payeeName[11:]
|
||||||
transferToAccount, err := ynab.GetAccount(context, transferToAccountName)
|
transferToAccount, err := ynab.GetAccount(context, transferToAccountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -293,35 +295,22 @@ func (ynab *YNABImport) ImportTransferTransaction(context context.Context, payee
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func trimLastChar(s string) string {
|
func GetAmount(inflow string, outflow string) (numeric.Numeric, error) {
|
||||||
r, size := utf8.DecodeLastRuneInString(s)
|
in, err := numeric.ParseCurrency(inflow)
|
||||||
if r == utf8.RuneError && (size == 0 || size == 1) {
|
|
||||||
size = 0
|
|
||||||
}
|
|
||||||
return s[:len(s)-size]
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetAmount(inflow string, outflow string) (Numeric, error) {
|
|
||||||
// Remove trailing currency
|
|
||||||
inflow = strings.Replace(trimLastChar(inflow), ",", ".", 1)
|
|
||||||
outflow = strings.Replace(trimLastChar(outflow), ",", ".", 1)
|
|
||||||
|
|
||||||
num := Numeric{}
|
|
||||||
err := num.Set(inflow)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return num, fmt.Errorf("parse inflow %s: %w", inflow, err)
|
return in, fmt.Errorf("parse inflow: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !in.IsZero() {
|
||||||
|
return in, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// if inflow is zero, use outflow
|
// if inflow is zero, use outflow
|
||||||
if num.Int.Int64() != 0 {
|
out, err := numeric.ParseCurrency("-" + outflow)
|
||||||
return num, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
err = num.Set("-" + outflow)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return num, fmt.Errorf("parse outflow %s: %w", inflow, err)
|
return out, fmt.Errorf("parse outflow: %w", err)
|
||||||
}
|
}
|
||||||
return num, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ynab *YNABImport) GetAccount(context context.Context, name string) (*Account, error) {
|
func (ynab *YNABImport) GetAccount(context context.Context, name string) (*Account, error) {
|
||||||
|
@ -35,3 +35,37 @@ type TransactionsResponse struct {
|
|||||||
Account postgres.Account
|
Account postgres.Account
|
||||||
Transactions []postgres.GetTransactionsForAccountRow
|
Transactions []postgres.GetTransactionsForAccountRow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type EditAccountRequest struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
OnBudget bool `json:"onBudget"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) editAccount(c *gin.Context) {
|
||||||
|
accountID := c.Param("accountid")
|
||||||
|
accountUUID, err := uuid.Parse(accountID)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var request EditAccountRequest
|
||||||
|
err = c.BindJSON(&request)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
updateParams := postgres.UpdateAccountParams{
|
||||||
|
Name: request.Name,
|
||||||
|
OnBudget: request.OnBudget,
|
||||||
|
ID: accountUUID,
|
||||||
|
}
|
||||||
|
account, err := h.Service.UpdateAccount(c.Request.Context(), updateParams)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusNotFound, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.returnBudgetingData(c, account.BudgetID)
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
@ -22,7 +23,8 @@ func TestRegisterUser(t *testing.T) { //nolint:funlen
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
database, err := postgres.Connect("pgtx", "example")
|
database, err := postgres.Connect("pgtx", "example")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("could not connect to db: %s", err)
|
fmt.Printf("could not connect to db: %s\n", err)
|
||||||
|
t.Skip()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -39,15 +40,33 @@ func (h *Handler) autocompletePayee(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
query := c.Request.URL.Query().Get("s")
|
query := c.Request.URL.Query().Get("s")
|
||||||
searchParams := postgres.SearchPayeesParams{
|
|
||||||
BudgetID: budgetUUID,
|
|
||||||
Search: query + "%",
|
|
||||||
}
|
|
||||||
payees, err := h.Service.SearchPayees(c.Request.Context(), searchParams)
|
|
||||||
if err != nil {
|
|
||||||
c.AbortWithError(http.StatusInternalServerError, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, payees)
|
transferPrefix := "Transfer"
|
||||||
|
if strings.HasPrefix(query, transferPrefix) {
|
||||||
|
searchParams := postgres.SearchAccountsParams{
|
||||||
|
BudgetID: budgetUUID,
|
||||||
|
Search: "%" + strings.Trim(query[len(transferPrefix):], " \t\n:") + "%",
|
||||||
|
}
|
||||||
|
|
||||||
|
accounts, err := h.Service.SearchAccounts(c.Request.Context(), searchParams)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, accounts)
|
||||||
|
} else {
|
||||||
|
searchParams := postgres.SearchPayeesParams{
|
||||||
|
BudgetID: budgetUUID,
|
||||||
|
Search: query + "%",
|
||||||
|
}
|
||||||
|
|
||||||
|
payees, err := h.Service.SearchPayees(c.Request.Context(), searchParams)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, payees)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||||
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
@ -24,10 +25,20 @@ func getFirstOfMonthTime(date time.Time) time.Time {
|
|||||||
|
|
||||||
type CategoryWithBalance struct {
|
type CategoryWithBalance struct {
|
||||||
*postgres.GetCategoriesRow
|
*postgres.GetCategoriesRow
|
||||||
Available postgres.Numeric
|
Available numeric.Numeric
|
||||||
AvailableLastMonth postgres.Numeric
|
AvailableLastMonth numeric.Numeric
|
||||||
Activity postgres.Numeric
|
Activity numeric.Numeric
|
||||||
Assigned postgres.Numeric
|
Assigned numeric.Numeric
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBalance {
|
||||||
|
return CategoryWithBalance{
|
||||||
|
GetCategoriesRow: category,
|
||||||
|
Available: numeric.Zero(),
|
||||||
|
AvailableLastMonth: numeric.Zero(),
|
||||||
|
Activity: numeric.Zero(),
|
||||||
|
Assigned: numeric.Zero(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDate(c *gin.Context) (time.Time, error) {
|
func getDate(c *gin.Context) (time.Time, error) {
|
||||||
@ -91,15 +102,15 @@ func (h *Handler) budgetingForMonth(c *gin.Context) {
|
|||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Categories []CategoryWithBalance
|
Categories []CategoryWithBalance
|
||||||
AvailableBalance postgres.Numeric
|
AvailableBalance numeric.Numeric
|
||||||
}{categoriesWithBalance, availableBalance}
|
}{categoriesWithBalance, availableBalance}
|
||||||
c.JSON(http.StatusOK, data)
|
c.JSON(http.StatusOK, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Handler) getAvailableBalance(categories []postgres.GetCategoriesRow, budget postgres.Budget,
|
func (*Handler) getAvailableBalance(categories []postgres.GetCategoriesRow, budget postgres.Budget,
|
||||||
moneyUsed postgres.Numeric, cumultativeBalances []postgres.GetCumultativeBalancesRow,
|
moneyUsed numeric.Numeric, cumultativeBalances []postgres.GetCumultativeBalancesRow,
|
||||||
firstOfNextMonth time.Time) postgres.Numeric {
|
firstOfNextMonth time.Time) numeric.Numeric {
|
||||||
availableBalance := postgres.NewZeroNumeric()
|
availableBalance := numeric.Zero()
|
||||||
for _, cat := range categories {
|
for _, cat := range categories {
|
||||||
if cat.ID != budget.IncomeCategoryID {
|
if cat.ID != budget.IncomeCategoryID {
|
||||||
continue
|
continue
|
||||||
@ -121,6 +132,11 @@ func (*Handler) getAvailableBalance(categories []postgres.GetCategoriesRow, budg
|
|||||||
return availableBalance
|
return availableBalance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BudgetingResponse struct {
|
||||||
|
Accounts []postgres.GetAccountsWithBalanceRow
|
||||||
|
Budget postgres.Budget
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) budgeting(c *gin.Context) {
|
func (h *Handler) budgeting(c *gin.Context) {
|
||||||
budgetID := c.Param("budgetid")
|
budgetID := c.Param("budgetid")
|
||||||
budgetUUID, err := uuid.Parse(budgetID)
|
budgetUUID, err := uuid.Parse(budgetID)
|
||||||
@ -129,6 +145,10 @@ func (h *Handler) budgeting(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.returnBudgetingData(c, budgetUUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) returnBudgetingData(c *gin.Context, budgetUUID uuid.UUID) {
|
||||||
budget, err := h.Service.GetBudget(c.Request.Context(), budgetUUID)
|
budget, err := h.Service.GetBudget(c.Request.Context(), budgetUUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusNotFound, err)
|
c.AbortWithError(http.StatusNotFound, err)
|
||||||
@ -141,42 +161,22 @@ func (h *Handler) budgeting(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := struct {
|
data := BudgetingResponse{accounts, budget}
|
||||||
Accounts []postgres.GetAccountsWithBalanceRow
|
|
||||||
Budget postgres.Budget
|
|
||||||
}{accounts, budget}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, data)
|
c.JSON(http.StatusOK, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) calculateBalances(budget postgres.Budget,
|
func (h *Handler) calculateBalances(budget postgres.Budget,
|
||||||
firstOfNextMonth time.Time, firstOfMonth time.Time, categories []postgres.GetCategoriesRow,
|
firstOfNextMonth time.Time, firstOfMonth time.Time, categories []postgres.GetCategoriesRow,
|
||||||
cumultativeBalances []postgres.GetCumultativeBalancesRow) ([]CategoryWithBalance, postgres.Numeric) {
|
cumultativeBalances []postgres.GetCumultativeBalancesRow) ([]CategoryWithBalance, numeric.Numeric) {
|
||||||
categoriesWithBalance := []CategoryWithBalance{}
|
categoriesWithBalance := []CategoryWithBalance{}
|
||||||
hiddenCategory := CategoryWithBalance{
|
|
||||||
GetCategoriesRow: &postgres.GetCategoriesRow{
|
|
||||||
Name: "",
|
|
||||||
Group: "Hidden Categories",
|
|
||||||
},
|
|
||||||
Available: postgres.NewZeroNumeric(),
|
|
||||||
AvailableLastMonth: postgres.NewZeroNumeric(),
|
|
||||||
Activity: postgres.NewZeroNumeric(),
|
|
||||||
Assigned: postgres.NewZeroNumeric(),
|
|
||||||
}
|
|
||||||
|
|
||||||
moneyUsed := postgres.NewZeroNumeric()
|
moneyUsed := numeric.Zero()
|
||||||
for i := range categories {
|
for i := range categories {
|
||||||
cat := &categories[i]
|
cat := &categories[i]
|
||||||
// do not show hidden categories
|
// do not show hidden categories
|
||||||
categoryWithBalance := h.CalculateCategoryBalances(cat, cumultativeBalances,
|
categoryWithBalance := h.CalculateCategoryBalances(cat, cumultativeBalances,
|
||||||
firstOfNextMonth, &moneyUsed, firstOfMonth, hiddenCategory, budget)
|
firstOfNextMonth, &moneyUsed, firstOfMonth, budget)
|
||||||
if cat.Group == "Hidden Categories" {
|
|
||||||
hiddenCategory.Available = hiddenCategory.Available.Add(categoryWithBalance.Available)
|
|
||||||
hiddenCategory.AvailableLastMonth = hiddenCategory.AvailableLastMonth.Add(categoryWithBalance.AvailableLastMonth)
|
|
||||||
hiddenCategory.Activity = hiddenCategory.Activity.Add(categoryWithBalance.Activity)
|
|
||||||
hiddenCategory.Assigned = hiddenCategory.Assigned.Add(categoryWithBalance.Assigned)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if cat.ID == budget.IncomeCategoryID {
|
if cat.ID == budget.IncomeCategoryID {
|
||||||
continue
|
continue
|
||||||
@ -185,22 +185,13 @@ func (h *Handler) calculateBalances(budget postgres.Budget,
|
|||||||
categoriesWithBalance = append(categoriesWithBalance, categoryWithBalance)
|
categoriesWithBalance = append(categoriesWithBalance, categoryWithBalance)
|
||||||
}
|
}
|
||||||
|
|
||||||
categoriesWithBalance = append(categoriesWithBalance, hiddenCategory)
|
|
||||||
|
|
||||||
return categoriesWithBalance, moneyUsed
|
return categoriesWithBalance, moneyUsed
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Handler) CalculateCategoryBalances(cat *postgres.GetCategoriesRow,
|
func (*Handler) CalculateCategoryBalances(cat *postgres.GetCategoriesRow,
|
||||||
cumultativeBalances []postgres.GetCumultativeBalancesRow, firstOfNextMonth time.Time,
|
cumultativeBalances []postgres.GetCumultativeBalancesRow, firstOfNextMonth time.Time,
|
||||||
moneyUsed *postgres.Numeric, firstOfMonth time.Time, hiddenCategory CategoryWithBalance,
|
moneyUsed *numeric.Numeric, firstOfMonth time.Time, budget postgres.Budget) CategoryWithBalance {
|
||||||
budget postgres.Budget) CategoryWithBalance {
|
categoryWithBalance := NewCategoryWithBalance(cat)
|
||||||
categoryWithBalance := CategoryWithBalance{
|
|
||||||
GetCategoriesRow: cat,
|
|
||||||
Available: postgres.NewZeroNumeric(),
|
|
||||||
AvailableLastMonth: postgres.NewZeroNumeric(),
|
|
||||||
Activity: postgres.NewZeroNumeric(),
|
|
||||||
Assigned: postgres.NewZeroNumeric(),
|
|
||||||
}
|
|
||||||
for _, bal := range cumultativeBalances {
|
for _, bal := range cumultativeBalances {
|
||||||
if bal.CategoryID != cat.ID {
|
if bal.CategoryID != cat.ID {
|
||||||
continue
|
continue
|
||||||
@ -216,7 +207,7 @@ func (*Handler) CalculateCategoryBalances(cat *postgres.GetCategoriesRow,
|
|||||||
categoryWithBalance.Available = categoryWithBalance.Available.Add(bal.Transactions)
|
categoryWithBalance.Available = categoryWithBalance.Available.Add(bal.Transactions)
|
||||||
if !categoryWithBalance.Available.IsPositive() && bal.Date.Before(firstOfMonth) {
|
if !categoryWithBalance.Available.IsPositive() && bal.Date.Before(firstOfMonth) {
|
||||||
*moneyUsed = moneyUsed.Add(categoryWithBalance.Available)
|
*moneyUsed = moneyUsed.Add(categoryWithBalance.Available)
|
||||||
categoryWithBalance.Available = postgres.NewZeroNumeric()
|
categoryWithBalance.Available = numeric.Zero()
|
||||||
}
|
}
|
||||||
|
|
||||||
if bal.Date.Before(firstOfMonth) {
|
if bal.Date.Before(firstOfMonth) {
|
||||||
|
@ -60,6 +60,7 @@ func (h *Handler) LoadRoutes(router *gin.Engine) {
|
|||||||
authenticated.Use(h.verifyLoginWithForbidden)
|
authenticated.Use(h.verifyLoginWithForbidden)
|
||||||
authenticated.GET("/dashboard", h.dashboard)
|
authenticated.GET("/dashboard", h.dashboard)
|
||||||
authenticated.GET("/account/:accountid/transactions", h.transactionsForAccount)
|
authenticated.GET("/account/:accountid/transactions", h.transactionsForAccount)
|
||||||
|
authenticated.POST("/account/:accountid", h.editAccount)
|
||||||
authenticated.GET("/admin/clear-database", h.clearDatabase)
|
authenticated.GET("/admin/clear-database", h.clearDatabase)
|
||||||
authenticated.GET("/budget/:budgetid", h.budgeting)
|
authenticated.GET("/budget/:budgetid", h.budgeting)
|
||||||
authenticated.GET("/budget/:budgetid/:year/:month", h.budgetingForMonth)
|
authenticated.GET("/budget/:budgetid/:year/:month", h.budgetingForMonth)
|
||||||
@ -67,6 +68,8 @@ func (h *Handler) LoadRoutes(router *gin.Engine) {
|
|||||||
authenticated.GET("/budget/:budgetid/autocomplete/categories", h.autocompleteCategories)
|
authenticated.GET("/budget/:budgetid/autocomplete/categories", h.autocompleteCategories)
|
||||||
authenticated.DELETE("/budget/:budgetid", h.deleteBudget)
|
authenticated.DELETE("/budget/:budgetid", h.deleteBudget)
|
||||||
authenticated.POST("/budget/:budgetid/import/ynab", h.importYNAB)
|
authenticated.POST("/budget/:budgetid/import/ynab", h.importYNAB)
|
||||||
|
authenticated.POST("/budget/:budgetid/export/ynab/transactions", h.exportYNABTransactions)
|
||||||
|
authenticated.POST("/budget/:budgetid/export/ynab/assignments", h.exportYNABAssignments)
|
||||||
authenticated.POST("/budget/:budgetid/settings/clear", h.clearBudget)
|
authenticated.POST("/budget/:budgetid/settings/clear", h.clearBudget)
|
||||||
|
|
||||||
budget := authenticated.Group("/budget")
|
budget := authenticated.Group("/budget")
|
||||||
|
@ -19,7 +19,7 @@ const (
|
|||||||
|
|
||||||
func MustGetToken(c *gin.Context) budgeteer.Token { //nolint:ireturn
|
func MustGetToken(c *gin.Context) budgeteer.Token { //nolint:ireturn
|
||||||
token := c.MustGet(ParamName)
|
token := c.MustGet(ParamName)
|
||||||
if token, ok := token.(budgeteer.Token); !ok {
|
if token, ok := token.(budgeteer.Token); ok {
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||||
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
@ -13,8 +15,9 @@ import (
|
|||||||
type NewTransactionPayload struct {
|
type NewTransactionPayload struct {
|
||||||
Date JSONDate `json:"date"`
|
Date JSONDate `json:"date"`
|
||||||
Payee struct {
|
Payee struct {
|
||||||
ID uuid.NullUUID
|
ID uuid.NullUUID
|
||||||
Name string
|
Name string
|
||||||
|
IsAccount bool
|
||||||
} `json:"payee"`
|
} `json:"payee"`
|
||||||
Category struct {
|
Category struct {
|
||||||
ID uuid.NullUUID
|
ID uuid.NullUUID
|
||||||
@ -35,39 +38,42 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
amount := postgres.Numeric{}
|
amount, err := numeric.Parse(payload.Amount)
|
||||||
err = amount.Set(payload.Amount)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("amount: %w", err))
|
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("amount: %w", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
payeeID := payload.Payee.ID
|
newTransaction := postgres.CreateTransactionParams{
|
||||||
if !payeeID.Valid && payload.Payee.Name != "" {
|
Memo: payload.Memo,
|
||||||
newPayee := postgres.CreatePayeeParams{
|
Date: time.Time(payload.Date),
|
||||||
Name: payload.Payee.Name,
|
Amount: amount,
|
||||||
BudgetID: payload.BudgetID,
|
Status: postgres.TransactionStatus(payload.State),
|
||||||
|
}
|
||||||
|
|
||||||
|
if payload.Payee.IsAccount {
|
||||||
|
newTransaction.GroupID = uuid.NullUUID{UUID: uuid.New(), Valid: true}
|
||||||
|
newTransaction.Amount = amount.Neg()
|
||||||
|
newTransaction.AccountID = payload.Payee.ID.UUID
|
||||||
|
newTransaction.CategoryID = uuid.NullUUID{}
|
||||||
|
|
||||||
|
_, err = h.Service.CreateTransaction(c.Request.Context(), newTransaction)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transfer transaction: %w", err))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
payee, err := h.Service.CreatePayee(c.Request.Context(), newPayee)
|
|
||||||
|
newTransaction.Amount = amount
|
||||||
|
} else {
|
||||||
|
payeeID, err := GetPayeeID(c.Request.Context(), payload, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create payee: %w", err))
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create payee: %w", err))
|
||||||
}
|
}
|
||||||
|
newTransaction.PayeeID = payeeID
|
||||||
payeeID = uuid.NullUUID{
|
|
||||||
UUID: payee.ID,
|
|
||||||
Valid: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newTransaction := postgres.CreateTransactionParams{
|
newTransaction.CategoryID = payload.Category.ID
|
||||||
Memo: payload.Memo,
|
newTransaction.AccountID = payload.AccountID
|
||||||
Date: time.Time(payload.Date),
|
|
||||||
Amount: amount,
|
|
||||||
AccountID: payload.AccountID,
|
|
||||||
PayeeID: payeeID,
|
|
||||||
CategoryID: payload.Category.ID,
|
|
||||||
Status: postgres.TransactionStatus(payload.State),
|
|
||||||
}
|
|
||||||
transaction, err := h.Service.CreateTransaction(c.Request.Context(), newTransaction)
|
transaction, err := h.Service.CreateTransaction(c.Request.Context(), newTransaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
|
||||||
@ -76,3 +82,25 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
|||||||
|
|
||||||
c.JSON(http.StatusOK, transaction)
|
c.JSON(http.StatusOK, transaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetPayeeID(context context.Context, payload NewTransactionPayload, h *Handler) (uuid.NullUUID, error) {
|
||||||
|
payeeID := payload.Payee.ID
|
||||||
|
if payeeID.Valid {
|
||||||
|
return payeeID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if payload.Payee.Name == "" {
|
||||||
|
return uuid.NullUUID{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
newPayee := postgres.CreatePayeeParams{
|
||||||
|
Name: payload.Payee.Name,
|
||||||
|
BudgetID: payload.BudgetID,
|
||||||
|
}
|
||||||
|
payee, err := h.Service.CreatePayee(context, newPayee)
|
||||||
|
if err != nil {
|
||||||
|
return uuid.NullUUID{}, fmt.Errorf("create payee: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return uuid.NullUUID{UUID: payee.ID, Valid: true}, nil
|
||||||
|
}
|
||||||
|
@ -63,3 +63,55 @@ func (h *Handler) importYNAB(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) exportYNABTransactions(c *gin.Context) {
|
||||||
|
budgetID, succ := c.Params.Get("budgetid")
|
||||||
|
if !succ {
|
||||||
|
c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"no budget_id specified"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
budgetUUID, err := uuid.Parse(budgetID)
|
||||||
|
if !succ {
|
||||||
|
c.AbortWithError(http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ynab, err := postgres.NewYNABExport(c.Request.Context(), h.Service.Queries, budgetUUID)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ynab.ExportTransactions(c.Request.Context(), c.Writer)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) exportYNABAssignments(c *gin.Context) {
|
||||||
|
budgetID, succ := c.Params.Get("budgetid")
|
||||||
|
if !succ {
|
||||||
|
c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"no budget_id specified"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
budgetUUID, err := uuid.Parse(budgetID)
|
||||||
|
if !succ {
|
||||||
|
c.AbortWithError(http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ynab, err := postgres.NewYNABExport(c.Request.Context(), h.Service.Queries, budgetUUID)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ynab.ExportAssignments(c.Request.Context(), c.Writer)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,9 +7,11 @@ packages:
|
|||||||
queries: "postgres/queries/"
|
queries: "postgres/queries/"
|
||||||
overrides:
|
overrides:
|
||||||
- go_type:
|
- go_type:
|
||||||
type: "Numeric"
|
import: "git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
|
type: Numeric
|
||||||
db_type: "pg_catalog.numeric"
|
db_type: "pg_catalog.numeric"
|
||||||
- go_type:
|
- go_type:
|
||||||
type: "Numeric"
|
import: "git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
|
type: Numeric
|
||||||
db_type: "pg_catalog.numeric"
|
db_type: "pg_catalog.numeric"
|
||||||
nullable: true
|
nullable: true
|
@ -11,6 +11,7 @@
|
|||||||
"@mdi/font": "5.9.55",
|
"@mdi/font": "5.9.55",
|
||||||
"@vueuse/core": "^7.6.1",
|
"@vueuse/core": "^7.6.1",
|
||||||
"autoprefixer": "^10.4.2",
|
"autoprefixer": "^10.4.2",
|
||||||
|
"file-saver": "^2.0.5",
|
||||||
"pinia": "^2.0.11",
|
"pinia": "^2.0.11",
|
||||||
"postcss": "^8.4.6",
|
"postcss": "^8.4.6",
|
||||||
"tailwindcss": "^3.0.18",
|
"tailwindcss": "^3.0.18",
|
||||||
@ -18,6 +19,7 @@
|
|||||||
"vue-router": "^4.0.12"
|
"vue-router": "^4.0.12"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/file-saver": "^2.0.5",
|
||||||
"@vitejs/plugin-vue": "^2.0.0",
|
"@vitejs/plugin-vue": "^2.0.0",
|
||||||
"@vue/cli-plugin-babel": "5.0.0-beta.7",
|
"@vue/cli-plugin-babel": "5.0.0-beta.7",
|
||||||
"@vue/cli-plugin-typescript": "~4.5.0",
|
"@vue/cli-plugin-typescript": "~4.5.0",
|
||||||
|
@ -48,7 +48,6 @@ function load(text: String) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
function keypress(e: KeyboardEvent) {
|
function keypress(e: KeyboardEvent) {
|
||||||
console.log(e.key);
|
|
||||||
if (e.key == "Enter") {
|
if (e.key == "Enter") {
|
||||||
const selected = Suggestions.value[0];
|
const selected = Suggestions.value[0];
|
||||||
selectElement(selected);
|
selectElement(selected);
|
||||||
|
10
web/src/components/Button.vue
Normal file
10
web/src/components/Button.vue
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<button
|
||||||
|
class="px-4 py-2 text-base font-medium rounded-md shadow-sm focus:outline-none focus:ring-2"
|
||||||
|
>
|
||||||
|
<slot></slot>
|
||||||
|
</button>
|
||||||
|
</template>
|
58
web/src/components/Modal.vue
Normal file
58
web/src/components/Modal.vue
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import Card from '../components/Card.vue';
|
||||||
|
import { ref } from "vue";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
buttonText: string,
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'submit'): void,
|
||||||
|
(e: 'open'): void,
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const visible = ref(false);
|
||||||
|
function closeDialog() {
|
||||||
|
visible.value = false;
|
||||||
|
};
|
||||||
|
function openDialog() {
|
||||||
|
emit("open");
|
||||||
|
visible.value = true;
|
||||||
|
};
|
||||||
|
function submitDialog() {
|
||||||
|
visible.value = false;
|
||||||
|
emit("submit");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<button @click="openDialog">
|
||||||
|
<slot name="placeholder">
|
||||||
|
<Card>
|
||||||
|
<p class="w-24 text-center text-6xl">+</p>
|
||||||
|
<span class="text-lg" dark>{{ buttonText }}</span>
|
||||||
|
</Card>
|
||||||
|
</slot>
|
||||||
|
</button>
|
||||||
|
<div
|
||||||
|
v-if="visible"
|
||||||
|
class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full"
|
||||||
|
>
|
||||||
|
<div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
|
||||||
|
<div class="mt-3 text-center">
|
||||||
|
<h3 class="mt-3 text-lg leading-6 font-medium text-gray-900">{{ buttonText }}</h3>
|
||||||
|
<slot></slot>
|
||||||
|
<div class="grid grid-cols-2 gap-6">
|
||||||
|
<button
|
||||||
|
@click="closeDialog"
|
||||||
|
class="px-4 py-2 bg-red-500 text-white text-base font-medium rounded-md shadow-sm hover:bg-green-600 focus:outline-none focus:ring-2 focus:ring-green-300"
|
||||||
|
>Close</button>
|
||||||
|
<button
|
||||||
|
@click="submitDialog"
|
||||||
|
class="px-4 py-2 bg-green-500 text-white text-base font-medium rounded-md shadow-sm hover:bg-green-600 focus:outline-none focus:ring-2 focus:ring-green-300"
|
||||||
|
>Save</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
@ -15,8 +15,8 @@ const Memo = ref("");
|
|||||||
const Amount = ref("0");
|
const Amount = ref("0");
|
||||||
|
|
||||||
const payload = computed(() => JSON.stringify({
|
const payload = computed(() => JSON.stringify({
|
||||||
budget_id: props.budgetid,
|
budgetId: props.budgetid,
|
||||||
account_id: props.accountid,
|
accountId: props.accountid,
|
||||||
date: TransactionDate.value,
|
date: TransactionDate.value,
|
||||||
payee: Payee.value,
|
payee: Payee.value,
|
||||||
category: Category.value,
|
category: Category.value,
|
||||||
|
@ -1,36 +1,18 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import Card from '../components/Card.vue';
|
import Modal from '../components/Modal.vue';
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { useBudgetsStore } from '../stores/budget';
|
import { useBudgetsStore } from '../stores/budget';
|
||||||
|
|
||||||
const dialog = ref(false);
|
|
||||||
const budgetName = ref("");
|
const budgetName = ref("");
|
||||||
function saveBudget() {
|
function saveBudget() {
|
||||||
useBudgetsStore().NewBudget(budgetName.value);
|
useBudgetsStore().NewBudget(budgetName.value);
|
||||||
dialog.value = false;
|
|
||||||
};
|
|
||||||
function newBudget() {
|
|
||||||
dialog.value = true;
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Card>
|
<Modal button-text="New Budget" @submit="saveBudget">
|
||||||
<p class="w-24 text-center text-6xl">+</p>
|
<div class="mt-2 px-7 py-3">
|
||||||
<button class="text-lg" dark @click="newBudget">New Budget</button>
|
<input class="border-2" type="text" v-model="budgetName" placeholder="Budget name" required />
|
||||||
</Card>
|
|
||||||
<div v-if="dialog" justify="center">
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<span class="text-h5">New Budget</span>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<input type="text" v-model="budgetName" label="Budget name" required />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<button @click="dialog = false">Close</button>
|
|
||||||
<button @click="saveBudget">Save</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Modal>
|
||||||
</template>
|
</template>
|
@ -4,19 +4,54 @@ import Currency from "../components/Currency.vue";
|
|||||||
import TransactionRow from "../components/TransactionRow.vue";
|
import TransactionRow from "../components/TransactionRow.vue";
|
||||||
import TransactionInputRow from "../components/TransactionInputRow.vue";
|
import TransactionInputRow from "../components/TransactionInputRow.vue";
|
||||||
import { useAccountStore } from "../stores/budget-account";
|
import { useAccountStore } from "../stores/budget-account";
|
||||||
|
import Modal from "../components/Modal.vue";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
budgetid: string
|
budgetid: string
|
||||||
accountid: string
|
accountid: string
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const accountStore = useAccountStore();
|
const accountStore = useAccountStore();
|
||||||
const CurrentAccount = computed(() => accountStore.CurrentAccount);
|
const CurrentAccount = computed(() => accountStore.CurrentAccount);
|
||||||
const TransactionsList = computed(() => accountStore.TransactionsList);
|
const TransactionsList = computed(() => accountStore.TransactionsList);
|
||||||
|
|
||||||
|
const accountName = ref("");
|
||||||
|
const accountOnBudget = ref(true);
|
||||||
|
|
||||||
|
function editAccount(e : any) {
|
||||||
|
accountStore.EditAccount(CurrentAccount.value?.ID ?? "", accountName.value, accountOnBudget.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEditAccount(e : any) {
|
||||||
|
accountName.value = CurrentAccount.value?.Name ?? "";
|
||||||
|
accountOnBudget.value = CurrentAccount.value?.OnBudget ?? true;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<h1>{{ CurrentAccount?.Name }}</h1>
|
<h1 class="inline">{{ CurrentAccount?.Name }}</h1>
|
||||||
|
<Modal button-text="Edit Account" @open="openEditAccount" @submit="editAccount">
|
||||||
|
<template v-slot:placeholder>✎</template>
|
||||||
|
<div class="mt-2 px-7 py-3">
|
||||||
|
<input
|
||||||
|
class="border-2"
|
||||||
|
type="text"
|
||||||
|
v-model="accountName"
|
||||||
|
placeholder="Account name"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="mt-2 px-7 py-3">
|
||||||
|
<input
|
||||||
|
class="border-2"
|
||||||
|
type="checkbox"
|
||||||
|
v-model="accountOnBudget"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<label>On Budget</label>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Current Balance:
|
Current Balance:
|
||||||
<Currency :value="CurrentAccount?.Balance" />
|
<Currency :value="CurrentAccount?.Balance" />
|
||||||
|
@ -5,11 +5,6 @@ import { useBudgetsStore } from "../stores/budget"
|
|||||||
import { useAccountStore } from "../stores/budget-account"
|
import { useAccountStore } from "../stores/budget-account"
|
||||||
import { useSettingsStore } from "../stores/settings"
|
import { useSettingsStore } from "../stores/settings"
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
budgetid: string,
|
|
||||||
accountid: string,
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const ExpandMenu = computed(() => useSettingsStore().Menu.Expand);
|
const ExpandMenu = computed(() => useSettingsStore().Menu.Expand);
|
||||||
|
|
||||||
const budgetStore = useBudgetsStore();
|
const budgetStore = useBudgetsStore();
|
||||||
@ -30,7 +25,7 @@ const OffBudgetAccountsBalance = computed(() => accountStore.OffBudgetAccountsBa
|
|||||||
{{CurrentBudgetName}}
|
{{CurrentBudgetName}}
|
||||||
</span>
|
</span>
|
||||||
<span class="bg-orange-200 rounded-lg m-1 p-1 px-3 flex flex-col">
|
<span class="bg-orange-200 rounded-lg m-1 p-1 px-3 flex flex-col">
|
||||||
<router-link :to="'/budget/'+budgetid+'/budgeting'">Budget</router-link><br />
|
<router-link :to="'/budget/'+CurrentBudgetID+'/budgeting'">Budget</router-link><br />
|
||||||
<!--<router-link :to="'/budget/'+CurrentBudgetID+'/reports'">Reports</router-link>-->
|
<!--<router-link :to="'/budget/'+CurrentBudgetID+'/reports'">Reports</router-link>-->
|
||||||
<!--<router-link :to="'/budget/'+CurrentBudgetID+'/all-accounts'">All Accounts</router-link>-->
|
<!--<router-link :to="'/budget/'+CurrentBudgetID+'/all-accounts'">All Accounts</router-link>-->
|
||||||
</span>
|
</span>
|
||||||
@ -40,7 +35,7 @@ const OffBudgetAccountsBalance = computed(() => accountStore.OffBudgetAccountsBa
|
|||||||
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="OnBudgetAccountsBalance" />
|
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="OnBudgetAccountsBalance" />
|
||||||
</div>
|
</div>
|
||||||
<div v-for="account in OnBudgetAccounts" class="flex flex-row justify-between">
|
<div v-for="account in OnBudgetAccounts" class="flex flex-row justify-between">
|
||||||
<router-link :to="'/budget/'+budgetid+'/account/'+account.ID">{{account.Name}}</router-link>
|
<router-link :to="'/budget/'+CurrentBudgetID+'/account/'+account.ID">{{account.Name}}</router-link>
|
||||||
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="account.Balance" />
|
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="account.Balance" />
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
@ -50,7 +45,7 @@ const OffBudgetAccountsBalance = computed(() => accountStore.OffBudgetAccountsBa
|
|||||||
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="OffBudgetAccountsBalance" />
|
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="OffBudgetAccountsBalance" />
|
||||||
</div>
|
</div>
|
||||||
<div v-for="account in OffBudgetAccounts" class="flex flex-row justify-between">
|
<div v-for="account in OffBudgetAccounts" class="flex flex-row justify-between">
|
||||||
<router-link :to="'/budget/'+budgetid+'/account/'+account.ID">{{account.Name}}</router-link>
|
<router-link :to="'/budget/'+CurrentBudgetID+'/account/'+account.ID">{{account.Name}}</router-link>
|
||||||
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="account.Balance" />
|
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="account.Balance" />
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, defineProps, onMounted, watchEffect } from "vue";
|
import { computed, defineProps, onMounted, ref, watchEffect } from "vue";
|
||||||
import Currency from "../components/Currency.vue";
|
import Currency from "../components/Currency.vue";
|
||||||
import { useBudgetsStore } from "../stores/budget";
|
import { useBudgetsStore } from "../stores/budget";
|
||||||
import { useAccountStore } from "../stores/budget-account";
|
import { useAccountStore } from "../stores/budget-account";
|
||||||
@ -14,11 +14,19 @@ const props = defineProps<{
|
|||||||
const budgetsStore = useBudgetsStore();
|
const budgetsStore = useBudgetsStore();
|
||||||
const CurrentBudgetID = computed(() => budgetsStore.CurrentBudgetID);
|
const CurrentBudgetID = computed(() => budgetsStore.CurrentBudgetID);
|
||||||
|
|
||||||
const categoriesForMonth = useAccountStore().CategoriesForMonth;
|
const accountStore = useAccountStore();
|
||||||
const Categories = computed(() => {
|
const categoriesForMonth = accountStore.CategoriesForMonthAndGroup;
|
||||||
return [...categoriesForMonth(selected.value.Year, selected.value.Month)];
|
|
||||||
|
function GetCategories(group : string) {
|
||||||
|
return [...categoriesForMonth(selected.value.Year, selected.value.Month, group)];
|
||||||
|
};
|
||||||
|
|
||||||
|
const groupsForMonth = accountStore.CategoryGroupsForMonth;
|
||||||
|
const GroupsForMonth = computed(() => {
|
||||||
|
return [...groupsForMonth(selected.value.Year, selected.value.Month)];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const previous = computed(() => ({
|
const previous = computed(() => ({
|
||||||
Year: new Date(selected.value.Year, selected.value.Month - 1, 1).getFullYear(),
|
Year: new Date(selected.value.Year, selected.value.Month - 1, 1).getFullYear(),
|
||||||
Month: new Date(selected.value.Year, selected.value.Month - 1, 1).getMonth(),
|
Month: new Date(selected.value.Year, selected.value.Month - 1, 1).getMonth(),
|
||||||
@ -44,6 +52,18 @@ watchEffect(() => {
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
useSessionStore().setTitle("Budget for " + selected.value.Month + "/" + selected.value.Year);
|
useSessionStore().setTitle("Budget for " + selected.value.Month + "/" + selected.value.Year);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
const expandedGroups = ref<Map<string, boolean>>(new Map<string, boolean>())
|
||||||
|
|
||||||
|
function toggleGroup(group : {Name : string, Expand: boolean}) {
|
||||||
|
console.log(expandedGroups.value);
|
||||||
|
expandedGroups.value.set(group.Name, !(expandedGroups.value.get(group.Name) ?? group.Expand))
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGroupState(group : {Name : string, Expand: boolean}) : boolean {
|
||||||
|
return expandedGroups.value.get(group.Name) ?? group.Expand;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -61,7 +81,6 @@ onMounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
<table class="container col-lg-12" id="content">
|
<table class="container col-lg-12" id="content">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Group</th>
|
|
||||||
<th>Category</th>
|
<th>Category</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
@ -70,23 +89,25 @@ onMounted(() => {
|
|||||||
<th>Activity</th>
|
<th>Activity</th>
|
||||||
<th>Available</th>
|
<th>Available</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-for="category in Categories">
|
<tbody v-for="group in GroupsForMonth">
|
||||||
<td>{{ category.Group }}</td>
|
<a class="text-lg font-bold" @click="toggleGroup(group)">{{ (getGroupState(group) ? "−" : "+") + " " + group.Name }}</a>
|
||||||
<td>{{ category.Name }}</td>
|
<tr v-for="category in GetCategories(group.Name)" v-if="getGroupState(group)">
|
||||||
<td></td>
|
<td>{{ category.Name }}</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td class="text-right">
|
<td></td>
|
||||||
<Currency :value="category.AvailableLastMonth" />
|
<td class="text-right">
|
||||||
</td>
|
<Currency :value="category.AvailableLastMonth" />
|
||||||
<td class="text-right">
|
</td>
|
||||||
<Currency :value="category.Assigned" />
|
<td class="text-right">
|
||||||
</td>
|
<Currency :value="category.Assigned" />
|
||||||
<td class="text-right">
|
</td>
|
||||||
<Currency :value="category.Activity" />
|
<td class="text-right">
|
||||||
</td>
|
<Currency :value="category.Activity" />
|
||||||
<td class="text-right">
|
</td>
|
||||||
<Currency :value="category.Available" />
|
<td class="text-right">
|
||||||
</td>
|
<Currency :value="category.Available" />
|
||||||
</tr>
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</template>
|
</template>
|
||||||
|
@ -5,6 +5,7 @@ import { useSessionStore } from "../stores/session";
|
|||||||
|
|
||||||
const error = ref("");
|
const error = ref("");
|
||||||
const login = ref({ user: "", password: "" });
|
const login = ref({ user: "", password: "" });
|
||||||
|
const router = useRouter(); // has to be called in setup
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
useSessionStore().setTitle("Login");
|
useSessionStore().setTitle("Login");
|
||||||
@ -15,7 +16,8 @@ function formSubmit(e: MouseEvent) {
|
|||||||
useSessionStore().login(login.value)
|
useSessionStore().login(login.value)
|
||||||
.then(x => {
|
.then(x => {
|
||||||
error.value = "";
|
error.value = "";
|
||||||
useRouter().replace("/dashboard");
|
router.replace("/dashboard");
|
||||||
|
return x;
|
||||||
})
|
})
|
||||||
.catch(x => error.value = "The entered credentials are invalid!");
|
.catch(x => error.value = "The entered credentials are invalid!");
|
||||||
|
|
||||||
@ -26,23 +28,17 @@ function formSubmit(e: MouseEvent) {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<input
|
<input type="text" v-model="login.user"
|
||||||
type="text"
|
|
||||||
v-model="login.user"
|
|
||||||
placeholder="Username"
|
placeholder="Username"
|
||||||
class="border-2 border-black rounded-lg block px-2 my-2 w-48"
|
class="border-2 border-black rounded-lg block px-2 my-2 w-48" />
|
||||||
/>
|
<input type="password" v-model="login.password"
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
v-model="login.password"
|
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
class="border-2 border-black rounded-lg block px-2 my-2 w-48"
|
class="border-2 border-black rounded-lg block px-2 my-2 w-48" />
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div>{{ error }}</div>
|
<div>{{ error }}</div>
|
||||||
<button type="submit" @click="formSubmit" class="bg-blue-300 rounded-lg p-2 w-48">Login</button>
|
<button type="submit" @click="formSubmit" class="bg-blue-300 rounded-lg p-2 w-48">Login</button>
|
||||||
<p>
|
<p>
|
||||||
New user?
|
New user?
|
||||||
<router-link to="/register">Register</router-link>instead!
|
<router-link to="/register">Register</router-link> instead!
|
||||||
</p>
|
</p>
|
||||||
</template>
|
</template>
|
@ -1,16 +1,25 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from 'vue';
|
import { onMounted, ref } from "vue";
|
||||||
import { useSessionStore } from '../stores/session';
|
import { useRouter } from "vue-router";
|
||||||
|
import { useSessionStore } from "../stores/session";
|
||||||
|
|
||||||
const error = ref("");
|
const error = ref("");
|
||||||
const login = ref({ email: "", password: "", name: "" });
|
const login = ref({ email: "", password: "", name: "" });
|
||||||
const showPassword = ref(false);
|
const router = useRouter(); // has to be called in setup
|
||||||
|
|
||||||
function formSubmit(e: FormDataEvent) {
|
onMounted(() => {
|
||||||
|
useSessionStore().setTitle("Login");
|
||||||
|
});
|
||||||
|
|
||||||
|
function formSubmit(e: MouseEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
useSessionStore().register(login)
|
useSessionStore().register(login.value)
|
||||||
.then(() => error.value = "")
|
.then(x => {
|
||||||
.catch(() => error.value = "Something went wrong!");
|
error.value = "";
|
||||||
|
router.replace("/dashboard");
|
||||||
|
return x;
|
||||||
|
})
|
||||||
|
.catch(x => error.value = "The entered credentials are invalid!");
|
||||||
|
|
||||||
// TODO display invalidCredentials
|
// TODO display invalidCredentials
|
||||||
// TODO redirect to dashboard on success
|
// TODO redirect to dashboard on success
|
||||||
@ -18,44 +27,21 @@ function formSubmit(e: FormDataEvent) {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<v-container>
|
<div>
|
||||||
<v-row>
|
<input type="text" v-model="login.name"
|
||||||
<v-col cols="12">
|
placeholder="Name"
|
||||||
<v-text-field v-model="login.email" type="text" label="E-Mail" />
|
class="border-2 border-black rounded-lg block px-2 my-2 w-48" />
|
||||||
</v-col>
|
<input type="text" v-model="login.email"
|
||||||
<v-col cols="12">
|
placeholder="Email"
|
||||||
<v-text-field v-model="login.name" type="text" label="Name" />
|
class="border-2 border-black rounded-lg block px-2 my-2 w-48" />
|
||||||
</v-col>
|
<input type="password" v-model="login.password"
|
||||||
<v-col cols="6">
|
placeholder="Password"
|
||||||
<v-text-field
|
class="border-2 border-black rounded-lg block px-2 my-2 w-48" />
|
||||||
v-model="login.password"
|
</div>
|
||||||
label="Password"
|
<div>{{ error }}</div>
|
||||||
:append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'"
|
<button type="submit" @click="formSubmit" class="bg-blue-300 rounded-lg p-2 w-48">Register</button>
|
||||||
:type="showPassword ? 'text' : 'password'"
|
<p>
|
||||||
@click:append="showPassword = showPassword"
|
Existing user?
|
||||||
:error-message="error"
|
<router-link to="/login">Login</router-link> instead!
|
||||||
error-count="2"
|
</p>
|
||||||
error
|
</template>
|
||||||
/>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="6">
|
|
||||||
<v-text-field
|
|
||||||
v-model="login.password"
|
|
||||||
label="Repeat password"
|
|
||||||
:append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'"
|
|
||||||
:type="showPassword ? 'text' : 'password'"
|
|
||||||
@click:append="showPassword = showPassword"
|
|
||||||
:error-message="error"
|
|
||||||
error-count="2"
|
|
||||||
error
|
|
||||||
/>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<div class="form-group">{{ error }}</div>
|
|
||||||
<v-btn type="submit" @click="formSubmit">Register</v-btn>
|
|
||||||
<p>
|
|
||||||
Existing user?
|
|
||||||
<router-link to="/login">Login</router-link>instead!
|
|
||||||
</p>
|
|
||||||
</v-container>
|
|
||||||
</template>
|
|
@ -4,6 +4,9 @@ import { useRouter } from "vue-router";
|
|||||||
import { DELETE, POST } from "../api";
|
import { DELETE, POST } from "../api";
|
||||||
import { useBudgetsStore } from "../stores/budget";
|
import { useBudgetsStore } from "../stores/budget";
|
||||||
import { useSessionStore } from "../stores/session";
|
import { useSessionStore } from "../stores/session";
|
||||||
|
import Card from "../components/Card.vue";
|
||||||
|
import Button from "../components/Button.vue";
|
||||||
|
import { saveAs } from 'file-saver';
|
||||||
|
|
||||||
const transactionsFile = ref<File | undefined>(undefined);
|
const transactionsFile = ref<File | undefined>(undefined);
|
||||||
const assignmentsFile = ref<File | undefined>(undefined);
|
const assignmentsFile = ref<File | undefined>(undefined);
|
||||||
@ -13,6 +16,10 @@ onMounted(() => {
|
|||||||
useSessionStore().setTitle("Settings");
|
useSessionStore().setTitle("Settings");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const budgetStore = useBudgetsStore();
|
||||||
|
const CurrentBudgetID = computed(() => budgetStore.CurrentBudgetID);
|
||||||
|
const CurrentBudgetName = computed(() => budgetStore.CurrentBudgetName);
|
||||||
|
|
||||||
function gotAssignments(e: Event) {
|
function gotAssignments(e: Event) {
|
||||||
const input = (<HTMLInputElement>e.target);
|
const input = (<HTMLInputElement>e.target);
|
||||||
if (input.files != null)
|
if (input.files != null)
|
||||||
@ -24,19 +31,17 @@ function gotTransactions(e: Event) {
|
|||||||
transactionsFile.value = input.files[0];
|
transactionsFile.value = input.files[0];
|
||||||
};
|
};
|
||||||
function deleteBudget() {
|
function deleteBudget() {
|
||||||
const currentBudgetID = useBudgetsStore().CurrentBudgetID;
|
if (CurrentBudgetID.value == null)
|
||||||
if (currentBudgetID == null)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DELETE("/budget/" + currentBudgetID);
|
DELETE("/budget/" + CurrentBudgetID.value);
|
||||||
|
|
||||||
const budgetStore = useSessionStore();
|
const budgetStore = useSessionStore();
|
||||||
budgetStore.Budgets.delete(currentBudgetID);
|
budgetStore.Budgets.delete(CurrentBudgetID.value);
|
||||||
useRouter().push("/")
|
useRouter().push("/")
|
||||||
};
|
};
|
||||||
function clearBudget() {
|
function clearBudget() {
|
||||||
const currentBudgetID = useBudgetsStore().CurrentBudgetID;
|
POST("/budget/" + CurrentBudgetID.value + "/settings/clear", null)
|
||||||
POST("/budget/" + currentBudgetID + "/settings/clear", null)
|
|
||||||
};
|
};
|
||||||
function cleanNegative() {
|
function cleanNegative() {
|
||||||
// <a href="/budget/{{.Budget.ID}}/settings/clean-negative">Fix all historic negative category-balances</a>
|
// <a href="/budget/{{.Budget.ID}}/settings/clean-negative">Fix all historic negative category-balances</a>
|
||||||
@ -51,75 +56,70 @@ function ynabImport() {
|
|||||||
const budgetStore = useBudgetsStore();
|
const budgetStore = useBudgetsStore();
|
||||||
budgetStore.ImportYNAB(formData);
|
budgetStore.ImportYNAB(formData);
|
||||||
};
|
};
|
||||||
|
function ynabExport() {
|
||||||
|
const timeStamp = new Date().toISOString();
|
||||||
|
POST("/budget/"+CurrentBudgetID.value+"/export/ynab/assignments", "")
|
||||||
|
.then(x => x.text())
|
||||||
|
.then(x => {
|
||||||
|
var blob = new Blob([x], {type: "text/plain;charset=utf-8"});
|
||||||
|
saveAs(blob, timeStamp + " " + CurrentBudgetName.value + " - Budget.tsv");
|
||||||
|
})
|
||||||
|
POST("/budget/"+CurrentBudgetID.value+"/export/ynab/transactions", "")
|
||||||
|
.then(x => x.text())
|
||||||
|
.then(x => {
|
||||||
|
var blob = new Blob([x], {type: "text/plain;charset=utf-8"});
|
||||||
|
saveAs(blob, timeStamp + " " + CurrentBudgetName.value + " - Transactions.tsv");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<v-container>
|
<div>
|
||||||
<h1>Danger Zone</h1>
|
<h1>Danger Zone</h1>
|
||||||
<v-row>
|
<div class="grid md:grid-cols-2 gap-6">
|
||||||
<v-col cols="12" md="6" xl="3">
|
<Card class="flex-col p-3">
|
||||||
<v-card>
|
<h2 class="text-lg font-bold">Clear Budget</h2>
|
||||||
<v-card-header>
|
<p>This removes transactions and assignments to start from scratch. Accounts and categories are kept. Not undoable!</p>
|
||||||
<v-card-header-text>
|
|
||||||
<v-card-title>Clear Budget</v-card-title>
|
|
||||||
<v-card-subtitle>This removes transactions and assignments to start from scratch. Accounts and categories are kept. Not undoable!</v-card-subtitle>
|
|
||||||
</v-card-header-text>
|
|
||||||
</v-card-header>
|
|
||||||
<v-card-actions class="justify-center">
|
|
||||||
<v-btn @click="clearBudget">Clear budget</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" md="6" xl="3">
|
|
||||||
<v-card>
|
|
||||||
<v-card-header>
|
|
||||||
<v-card-header-text>
|
|
||||||
<v-card-title>Delete Budget</v-card-title>
|
|
||||||
<v-card-subtitle>This deletes the whole bugdet including all transactions, assignments, accounts and categories. Not undoable!</v-card-subtitle>
|
|
||||||
</v-card-header-text>
|
|
||||||
</v-card-header>
|
|
||||||
<v-card-actions class="justify-center">
|
|
||||||
<v-btn @click="deleteBudget">Delete budget</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" md="6" xl="3">
|
|
||||||
<v-card>
|
|
||||||
<v-card-header>
|
|
||||||
<v-card-header-text>
|
|
||||||
<v-card-title>Fix all historic negative category-balances</v-card-title>
|
|
||||||
<v-card-subtitle>This restores YNABs functionality, that would substract any overspent categories' balances from next months inflows.</v-card-subtitle>
|
|
||||||
</v-card-header-text>
|
|
||||||
</v-card-header>
|
|
||||||
<v-card-actions class="justify-center">
|
|
||||||
<v-btn @click="cleanNegative">Fix negative</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" xl="6">
|
|
||||||
<v-card>
|
|
||||||
<v-card-header>
|
|
||||||
<v-card-header-text>
|
|
||||||
<v-card-title>Import YNAB Budget</v-card-title>
|
|
||||||
</v-card-header-text>
|
|
||||||
</v-card-header>
|
|
||||||
|
|
||||||
<label for="transactions_file">
|
<Button class="bg-red-500" @click="clearBudget">Clear budget</Button>
|
||||||
Transaktionen:
|
</Card>
|
||||||
<input type="file" @change="gotTransactions" accept="text/*" />
|
<Card class="flex-col p-3">
|
||||||
</label>
|
<h2 class="text-lg font-bold">Delete Budget</h2>
|
||||||
<br />
|
<p>This deletes the whole bugdet including all transactions, assignments, accounts and categories. Not undoable!</p>
|
||||||
<label for="assignments_file">
|
<Button class="bg-red-500" @click="deleteBudget">Delete budget</button>
|
||||||
Budget:
|
</Card>
|
||||||
<input type="file" @change="gotAssignments" accept="text/*" />
|
<Card class="flex-col p-3">
|
||||||
</label>
|
<h2 class="text-lg font-bold">Fix all historic negative category-balances</h2>
|
||||||
|
<p>This restores YNABs functionality, that would substract any overspent categories' balances from next months inflows.</p>
|
||||||
|
<Button class="bg-orange-500" @click="cleanNegative">Fix negative</button>
|
||||||
|
</Card>
|
||||||
|
<Card class="flex-col p-3">
|
||||||
|
<h2 class="text-lg font-bold">Import YNAB Budget</h2>
|
||||||
|
|
||||||
|
<div class="flex flex-row">
|
||||||
|
<div>
|
||||||
|
<label for="transactions_file">
|
||||||
|
Transaktionen:
|
||||||
|
<input type="file" @change="gotTransactions" accept="text/*" />
|
||||||
|
</label>
|
||||||
|
<br />
|
||||||
|
<label for="assignments_file">
|
||||||
|
Budget:
|
||||||
|
<input type="file" @change="gotAssignments" accept="text/*" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<v-card-actions class="justify-center">
|
<Button class="bg-blue-500" :disabled="filesIncomplete" @click="ynabImport">Importieren</Button>
|
||||||
<v-btn :disabled="filesIncomplete" @click="ynabImport">Importieren</v-btn>
|
</div>
|
||||||
</v-card-actions>
|
</Card>
|
||||||
</v-card>
|
<Card class="flex-col p-3">
|
||||||
</v-col>
|
<h2 class="text-lg font-bold">Export as YNAB TSV</h2>
|
||||||
</v-row>
|
|
||||||
<v-card></v-card>
|
<div class="flex flex-row">
|
||||||
</v-container>
|
<Button class="bg-blue-500" @click="ynabExport">Export</Button>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
@ -1,5 +1,6 @@
|
|||||||
import { defineStore } from "pinia"
|
import { defineStore } from "pinia"
|
||||||
import { GET, POST } from "../api";
|
import { GET, POST } from "../api";
|
||||||
|
import { useBudgetsStore } from "./budget";
|
||||||
import { useSessionStore } from "./session";
|
import { useSessionStore } from "./session";
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
@ -54,12 +55,33 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
AccountsList(state) {
|
AccountsList(state) {
|
||||||
return [...state.Accounts.values()];
|
return [...state.Accounts.values()];
|
||||||
},
|
},
|
||||||
CategoriesForMonth: (state) => (year: number, month: number) => {
|
AllCategoriesForMonth: (state) => (year: number, month: number) => {
|
||||||
const yearMap = state.Months.get(year);
|
const yearMap = state.Months.get(year);
|
||||||
const monthMap = yearMap?.get(month);
|
const monthMap = yearMap?.get(month);
|
||||||
console.log("MTH", monthMap)
|
|
||||||
return [...monthMap?.values() || []];
|
return [...monthMap?.values() || []];
|
||||||
},
|
},
|
||||||
|
CategoryGroupsForMonth(state) {
|
||||||
|
return (year: number, month: number) => {
|
||||||
|
const categories = this.AllCategoriesForMonth(year, month);
|
||||||
|
const categoryGroups = [];
|
||||||
|
let prev = undefined;
|
||||||
|
for (const category of categories) {
|
||||||
|
if(category.Group != prev)
|
||||||
|
categoryGroups.push({
|
||||||
|
Name: category.Group,
|
||||||
|
Expand: category.Group != "Hidden Categories",
|
||||||
|
});
|
||||||
|
prev = category.Group;
|
||||||
|
}
|
||||||
|
return categoryGroups;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CategoriesForMonthAndGroup(state) {
|
||||||
|
return (year: number, month: number, group : string) => {
|
||||||
|
const categories = this.AllCategoriesForMonth(year, month);
|
||||||
|
return categories.filter(x => x.Group == group);
|
||||||
|
}
|
||||||
|
},
|
||||||
CurrentAccount(state): Account | undefined {
|
CurrentAccount(state): Account | undefined {
|
||||||
if (state.CurrentAccountID == null)
|
if (state.CurrentAccountID == null)
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -102,8 +124,15 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
async FetchMonthBudget(budgetid: string, year: number, month: number) {
|
async FetchMonthBudget(budgetid: string, year: number, month: number) {
|
||||||
const result = await GET("/budget/" + budgetid + "/" + year + "/" + month);
|
const result = await GET("/budget/" + budgetid + "/" + year + "/" + month);
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
if(response.Categories == undefined || response.Categories.length <= 0)
|
||||||
|
return;
|
||||||
this.addCategoriesForMonth(year, month, response.Categories);
|
this.addCategoriesForMonth(year, month, response.Categories);
|
||||||
},
|
},
|
||||||
|
async EditAccount(accountid : string, name : string, onBudget : boolean) {
|
||||||
|
const result = await POST("/account/" + accountid, JSON.stringify({name: name, onBudget: onBudget}));
|
||||||
|
const response = await result.json();
|
||||||
|
useBudgetsStore().MergeBudgetingData(response);
|
||||||
|
},
|
||||||
addCategoriesForMonth(year: number, month: number, categories: Category[]): void {
|
addCategoriesForMonth(year: number, month: number, categories: Category[]): void {
|
||||||
this.$patch((state) => {
|
this.$patch((state) => {
|
||||||
const yearMap = state.Months.get(year) || new Map<number, Map<string, Category>>();
|
const yearMap = state.Months.get(year) || new Map<number, Map<string, Category>>();
|
||||||
|
@ -51,6 +51,9 @@ export const useBudgetsStore = defineStore('budget', {
|
|||||||
async FetchBudget(budgetid: string) {
|
async FetchBudget(budgetid: string) {
|
||||||
const result = await GET("/budget/" + budgetid);
|
const result = await GET("/budget/" + budgetid);
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
this.MergeBudgetingData(response);
|
||||||
|
},
|
||||||
|
MergeBudgetingData(response : any) {
|
||||||
for (const account of response.Accounts || []) {
|
for (const account of response.Accounts || []) {
|
||||||
useAccountStore().Accounts.set(account.ID, account);
|
useAccountStore().Accounts.set(account.ID, account);
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,12 @@ export interface Budget {
|
|||||||
|
|
||||||
export const useSessionStore = defineStore('session', {
|
export const useSessionStore = defineStore('session', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
Session: useStorage<Session>('session', null, undefined, { serializer: StorageSerializers.object }),
|
Session: useStorage<Session | null>('session', null, undefined, { serializer: StorageSerializers.object }),
|
||||||
Budgets: useStorage<Map<string, Budget>>('budgets', new Map<string, Budget>(), undefined, { serializer: StorageSerializers.map }),
|
Budgets: useStorage<Map<string, Budget>>('budgets', new Map<string, Budget>(), undefined, { serializer: StorageSerializers.map }),
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
BudgetsList: (state) => [ ...state.Budgets.values() ],
|
BudgetsList: (state) => [ ...state.Budgets.values() ],
|
||||||
AuthHeaders: (state) => ({'Authorization': 'Bearer ' + state.Session.Token}),
|
AuthHeaders: (state) => ({'Authorization': 'Bearer ' + state.Session?.Token}),
|
||||||
LoggedIn: (state) => state.Session != null,
|
LoggedIn: (state) => state.Session != null,
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@ -36,21 +36,26 @@ export const useSessionStore = defineStore('session', {
|
|||||||
this.Session = {
|
this.Session = {
|
||||||
User: x.User,
|
User: x.User,
|
||||||
Token: x.Token,
|
Token: x.Token,
|
||||||
},
|
}
|
||||||
this.Budgets = x.Budgets;
|
for (const budget of x.Budgets) {
|
||||||
|
this.Budgets.set(budget.ID, budget);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async login(login: any) {
|
async login(login: any) {
|
||||||
const response = await POST("/user/login", JSON.stringify(login));
|
const response = await POST("/user/login", JSON.stringify(login));
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
return this.loginSuccess(result);
|
this.loginSuccess(result);
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
async register(login : any) {
|
async register(login : any) {
|
||||||
const response = await POST("/user/register", JSON.stringify(login));
|
const response = await POST("/user/register", JSON.stringify(login));
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
return this.loginSuccess(result);
|
this.loginSuccess(result);
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
logout() {
|
logout() {
|
||||||
this.$reset()
|
this.Session = null;
|
||||||
|
this.Budgets.clear();
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
@ -1141,6 +1141,11 @@
|
|||||||
"@types/qs" "*"
|
"@types/qs" "*"
|
||||||
"@types/serve-static" "*"
|
"@types/serve-static" "*"
|
||||||
|
|
||||||
|
"@types/file-saver@^2.0.5":
|
||||||
|
version "2.0.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/file-saver/-/file-saver-2.0.5.tgz#9ee342a5d1314bb0928375424a2f162f97c310c7"
|
||||||
|
integrity sha512-zv9kNf3keYegP5oThGLaPk8E081DFDuwfqjtiTzm6PoxChdJ1raSuADf2YGCVIyrSynLrgc8JWv296s7Q7pQSQ==
|
||||||
|
|
||||||
"@types/glob@^7.1.1":
|
"@types/glob@^7.1.1":
|
||||||
version "7.2.0"
|
version "7.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
|
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
|
||||||
@ -4137,6 +4142,11 @@ figures@^2.0.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
escape-string-regexp "^1.0.5"
|
escape-string-regexp "^1.0.5"
|
||||||
|
|
||||||
|
file-saver@^2.0.5:
|
||||||
|
version "2.0.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.5.tgz#d61cfe2ce059f414d899e9dd6d4107ee25670c38"
|
||||||
|
integrity sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==
|
||||||
|
|
||||||
file-uri-to-path@1.0.0:
|
file-uri-to-path@1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
|
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
|
||||||
|
Reference in New Issue
Block a user