Compare commits
28 Commits
fc50313907
...
38e21786a7
Author | SHA1 | Date | |
---|---|---|---|
38e21786a7 | |||
971c3d3be5 | |||
946f14c1cc | |||
9ce0da0182 | |||
4c93e4635d | |||
f3a50c790b | |||
0c5f68ed80 | |||
7fdd8bd935 | |||
d4287f8aac | |||
6712af10d9 | |||
70edb382e1 | |||
390a042441 | |||
e8028dae34 | |||
fc249adc9e | |||
c186a14644 | |||
8a27303670 | |||
44e9bb6ec0 | |||
42d431ba8b | |||
3727061065 | |||
c7a8adb3ab | |||
29f534bf10 | |||
15381c84f6 | |||
a0cabbf4f7 | |||
f26ee8f472 | |||
4fb3c2a335 | |||
8899ff5772 | |||
347a0c9e50 | |||
66b8e1f69f |
10
.earthignore
10
.earthignore
@ -1,10 +0,0 @@
|
||||
build/
|
||||
.git/
|
||||
docker-compose.yml
|
||||
README.md
|
||||
Earthfile
|
||||
config.example.json
|
||||
.gitignore
|
||||
.vscode/
|
||||
budgeteer
|
||||
budgeteer.exe
|
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -1,7 +1,11 @@
|
||||
{
|
||||
"files.exclude": {
|
||||
"**/node_modules": true,
|
||||
"**/vendor": true
|
||||
"**/vendor": true,
|
||||
"**/*.sql.go": true,
|
||||
".task/": true,
|
||||
"build/": true,
|
||||
"web/dist/": true
|
||||
},
|
||||
"gopls": {
|
||||
"formatting.gofumpt": true,
|
||||
|
@ -1,23 +0,0 @@
|
||||
pipeline:
|
||||
build:
|
||||
name: Taskfile.dev
|
||||
image: hub.javil.eu/budgeteer:dev
|
||||
pull: true
|
||||
commands:
|
||||
- task ci
|
||||
|
||||
docker:
|
||||
image: plugins/docker
|
||||
secrets: [ docker_username, docker_password ]
|
||||
settings:
|
||||
registry: hub.javil.eu
|
||||
repo: hub.javil.eu/budgeteer
|
||||
context: build
|
||||
dockerfile: build/Dockerfile
|
||||
tags:
|
||||
- latest
|
||||
when:
|
||||
event: [push, tag, deployment]
|
||||
|
||||
image_pull_secrets:
|
||||
- hub.javil.eu
|
21
Earthfile
21
Earthfile
@ -1,21 +0,0 @@
|
||||
FROM golang:1.17
|
||||
WORKDIR /src
|
||||
|
||||
build:
|
||||
COPY go.mod go.sum .
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build go build -o build/budgeteer ./cmd/budgeteer
|
||||
SAVE ARTIFACT build/budgeteer /budgeteer AS LOCAL build/budgeteer
|
||||
|
||||
docker:
|
||||
WORKDIR /app
|
||||
COPY +build/budgeteer .
|
||||
ENTRYPOINT ["/app/budgeteer"]
|
||||
SAVE IMAGE hub.javil.eu/budgeteer:latest
|
||||
|
||||
run:
|
||||
LOCALLY
|
||||
WITH DOCKER --load=+docker
|
||||
RUN docker-compose up -d
|
||||
END
|
@ -96,7 +96,7 @@ tasks:
|
||||
- ./docker/build.sh
|
||||
- ./web/package.json
|
||||
cmds:
|
||||
- docker build -t {{.IMAGE_NAME}}:dev . -f docker/Dockerfile
|
||||
- docker build -t {{.IMAGE_NAME}}:dev . -f docker/Dockerfile.dev
|
||||
- docker push {{.IMAGE_NAME}}:dev
|
||||
|
||||
run:
|
||||
|
@ -1,3 +0,0 @@
|
||||
FROM scratch
|
||||
COPY ./budgeteer /app/budgeteer
|
||||
ENTRYPOINT ["/app/budgeteer"]
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"DatabaseHost": "localhost",
|
||||
"DatabaseUser": "user",
|
||||
"DatabasePassword": "thisismypassword",
|
||||
"DatabaseName": "budgeteer"
|
||||
}
|
@ -1,17 +1,3 @@
|
||||
FROM alpine as godeps
|
||||
RUN apk --no-cache add go
|
||||
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/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
|
||||
FROM alpine
|
||||
RUN apk --no-cache add go nodejs yarn bash curl git git-perl tmux
|
||||
ADD docker/build.sh /
|
||||
RUN yarn global add @vue/cli
|
||||
ENV PATH="/root/.yarn/bin/:${PATH}"
|
||||
WORKDIR /src/web
|
||||
ADD web/package.json web/yarn.lock /src/web/
|
||||
RUN yarn
|
||||
WORKDIR /src
|
||||
COPY --from=godeps /root/go/bin/task /root/go/bin/sqlc /root/go/bin/golangci-lint /usr/local/bin/
|
||||
CMD /build.sh
|
||||
FROM scratch
|
||||
COPY ./budgeteer /app/budgeteer
|
||||
ENTRYPOINT ["/app/budgeteer"]
|
||||
|
17
docker/Dockerfile.dev
Normal file
17
docker/Dockerfile.dev
Normal file
@ -0,0 +1,17 @@
|
||||
FROM alpine as godeps
|
||||
RUN apk --no-cache add go
|
||||
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/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
|
||||
FROM alpine
|
||||
RUN apk --no-cache add go nodejs yarn bash curl git git-perl tmux
|
||||
ADD docker/dev.sh /
|
||||
RUN yarn global add @vue/cli
|
||||
ENV PATH="/root/.yarn/bin/:${PATH}"
|
||||
WORKDIR /src/web
|
||||
ADD web/package.json web/yarn.lock /src/web/
|
||||
RUN yarn
|
||||
WORKDIR /src
|
||||
COPY --from=godeps /root/go/bin/task /root/go/bin/sqlc /root/go/bin/golangci-lint /usr/local/bin/
|
||||
CMD /dev.sh
|
2
go.mod
2
go.mod
@ -11,7 +11,7 @@ require (
|
||||
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa
|
||||
)
|
||||
|
||||
require github.com/DATA-DOG/go-txdb v0.1.5 // indirect
|
||||
require github.com/DATA-DOG/go-txdb v0.1.5
|
||||
|
||||
require (
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
|
1
go.sum
1
go.sum
@ -74,6 +74,7 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+
|
||||
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
|
||||
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
|
||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
|
@ -12,10 +12,11 @@ import (
|
||||
|
||||
// TokenVerifier verifies Tokens.
|
||||
type TokenVerifier struct {
|
||||
secret string
|
||||
Expiration time.Duration
|
||||
secret string
|
||||
}
|
||||
|
||||
var ErrEmptySecret = fmt.Errorf("secret is required")
|
||||
const DefaultExpiration = time.Hour * time.Duration(72)
|
||||
|
||||
func NewTokenVerifier(secret string) (*TokenVerifier, error) {
|
||||
if secret == "" {
|
||||
@ -23,20 +24,16 @@ func NewTokenVerifier(secret string) (*TokenVerifier, error) {
|
||||
}
|
||||
|
||||
return &TokenVerifier{
|
||||
secret: secret,
|
||||
Expiration: DefaultExpiration,
|
||||
secret: secret,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Token contains everything to authenticate a user.
|
||||
type Token struct {
|
||||
username string
|
||||
name string
|
||||
expiry float64
|
||||
id uuid.UUID
|
||||
}
|
||||
|
||||
const (
|
||||
expiration = 72
|
||||
var (
|
||||
ErrUnexpectedSigningMethod = fmt.Errorf("unexpected signing method")
|
||||
ErrInvalidToken = fmt.Errorf("token is invalid")
|
||||
ErrTokenExpired = fmt.Errorf("token has expired")
|
||||
ErrEmptySecret = fmt.Errorf("secret is required")
|
||||
)
|
||||
|
||||
// CreateToken creates a new token from username and name.
|
||||
@ -48,7 +45,7 @@ func (tv *TokenVerifier) CreateToken(user *postgres.User) (string, error) {
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||
"usr": user.Email,
|
||||
"name": user.Name,
|
||||
"exp": time.Now().Add(time.Hour * expiration).Unix(),
|
||||
"exp": time.Now().Add(tv.Expiration).Unix(),
|
||||
"id": user.ID,
|
||||
})
|
||||
|
||||
@ -61,13 +58,7 @@ func (tv *TokenVerifier) CreateToken(user *postgres.User) (string, error) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
var (
|
||||
ErrUnexpectedSigningMethod = fmt.Errorf("unexpected signing method")
|
||||
ErrInvalidToken = fmt.Errorf("token is invalid")
|
||||
ErrTokenExpired = fmt.Errorf("token has expired")
|
||||
)
|
||||
|
||||
// VerifyToken verifys a given string-token.
|
||||
// VerifyToken verifies a given string-token.
|
||||
func (tv *TokenVerifier) VerifyToken(tokenString string) (budgeteer.Token, error) { //nolint:ireturn
|
||||
if tv.secret == "" {
|
||||
return nil, ErrEmptySecret
|
||||
@ -96,36 +87,3 @@ func (tv *TokenVerifier) VerifyToken(tokenString string) (budgeteer.Token, error
|
||||
}
|
||||
return tkn, nil
|
||||
}
|
||||
|
||||
func verifyToken(token *jwt.Token) (jwt.MapClaims, error) {
|
||||
if !token.Valid {
|
||||
return nil, ErrInvalidToken
|
||||
}
|
||||
|
||||
claims, ok := token.Claims.(jwt.MapClaims)
|
||||
if !ok {
|
||||
return nil, ErrInvalidToken
|
||||
}
|
||||
|
||||
if !claims.VerifyExpiresAt(time.Now().Unix(), true) {
|
||||
return nil, ErrTokenExpired
|
||||
}
|
||||
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func (t *Token) GetName() string {
|
||||
return t.name
|
||||
}
|
||||
|
||||
func (t *Token) GetUsername() string {
|
||||
return t.username
|
||||
}
|
||||
|
||||
func (t *Token) GetExpiry() float64 {
|
||||
return t.expiry
|
||||
}
|
||||
|
||||
func (t *Token) GetID() uuid.UUID {
|
||||
return t.id
|
||||
}
|
49
jwt/token.go
Normal file
49
jwt/token.go
Normal file
@ -0,0 +1,49 @@
|
||||
package jwt
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Token contains everything to authenticate a user.
|
||||
type Token struct {
|
||||
username string
|
||||
name string
|
||||
expiry float64
|
||||
id uuid.UUID
|
||||
}
|
||||
|
||||
func verifyToken(token *jwt.Token) (jwt.MapClaims, error) {
|
||||
if !token.Valid {
|
||||
return nil, ErrInvalidToken
|
||||
}
|
||||
|
||||
claims, ok := token.Claims.(jwt.MapClaims)
|
||||
if !ok {
|
||||
return nil, ErrInvalidToken
|
||||
}
|
||||
|
||||
if !claims.VerifyExpiresAt(time.Now().Unix(), true) {
|
||||
return nil, ErrTokenExpired
|
||||
}
|
||||
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func (t *Token) GetName() string {
|
||||
return t.name
|
||||
}
|
||||
|
||||
func (t *Token) GetUsername() string {
|
||||
return t.username
|
||||
}
|
||||
|
||||
func (t *Token) GetExpiry() float64 {
|
||||
return t.expiry
|
||||
}
|
||||
|
||||
func (t *Token) GetID() uuid.UUID {
|
||||
return t.id
|
||||
}
|
@ -15,7 +15,7 @@ const createAccount = `-- name: CreateAccount :one
|
||||
INSERT INTO accounts
|
||||
(name, budget_id)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id, budget_id, name, on_budget
|
||||
RETURNING id, budget_id, name, on_budget, is_open
|
||||
`
|
||||
|
||||
type CreateAccountParams struct {
|
||||
@ -31,12 +31,13 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (A
|
||||
&i.BudgetID,
|
||||
&i.Name,
|
||||
&i.OnBudget,
|
||||
&i.IsOpen,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAccount = `-- name: GetAccount :one
|
||||
SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget FROM accounts
|
||||
SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget, accounts.is_open FROM accounts
|
||||
WHERE accounts.id = $1
|
||||
`
|
||||
|
||||
@ -48,13 +49,15 @@ func (q *Queries) GetAccount(ctx context.Context, id uuid.UUID) (Account, error)
|
||||
&i.BudgetID,
|
||||
&i.Name,
|
||||
&i.OnBudget,
|
||||
&i.IsOpen,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAccounts = `-- name: GetAccounts :many
|
||||
SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget FROM accounts
|
||||
SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget, accounts.is_open FROM accounts
|
||||
WHERE accounts.budget_id = $1
|
||||
AND accounts.is_open = TRUE
|
||||
ORDER BY accounts.name
|
||||
`
|
||||
|
||||
@ -72,6 +75,7 @@ func (q *Queries) GetAccounts(ctx context.Context, budgetID uuid.UUID) ([]Accoun
|
||||
&i.BudgetID,
|
||||
&i.Name,
|
||||
&i.OnBudget,
|
||||
&i.IsOpen,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -87,13 +91,14 @@ func (q *Queries) GetAccounts(ctx context.Context, budgetID uuid.UUID) ([]Accoun
|
||||
}
|
||||
|
||||
const getAccountsWithBalance = `-- name: GetAccountsWithBalance :many
|
||||
SELECT accounts.id, accounts.name, accounts.on_budget,
|
||||
SELECT accounts.id, accounts.name, accounts.on_budget, accounts.is_open,
|
||||
(SELECT MAX(transactions.date) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.status = 'Reconciled')::date as last_reconciled,
|
||||
(SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW())::decimal(12,2) as working_balance,
|
||||
(SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status IN ('Cleared', 'Reconciled'))::decimal(12,2) as cleared_balance,
|
||||
(SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status = 'Reconciled')::decimal(12,2) as reconciled_balance
|
||||
FROM accounts
|
||||
WHERE accounts.budget_id = $1
|
||||
AND accounts.is_open = TRUE
|
||||
ORDER BY accounts.name
|
||||
`
|
||||
|
||||
@ -101,6 +106,7 @@ type GetAccountsWithBalanceRow struct {
|
||||
ID uuid.UUID
|
||||
Name string
|
||||
OnBudget bool
|
||||
IsOpen bool
|
||||
LastReconciled time.Time
|
||||
WorkingBalance numeric.Numeric
|
||||
ClearedBalance numeric.Numeric
|
||||
@ -120,6 +126,7 @@ func (q *Queries) GetAccountsWithBalance(ctx context.Context, budgetID uuid.UUID
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.OnBudget,
|
||||
&i.IsOpen,
|
||||
&i.LastReconciled,
|
||||
&i.WorkingBalance,
|
||||
&i.ClearedBalance,
|
||||
@ -141,6 +148,7 @@ func (q *Queries) GetAccountsWithBalance(ctx context.Context, budgetID uuid.UUID
|
||||
const searchAccounts = `-- name: SearchAccounts :many
|
||||
SELECT accounts.id, accounts.budget_id, accounts.name, 'account' as type FROM accounts
|
||||
WHERE accounts.budget_id = $1
|
||||
AND accounts.is_open = TRUE
|
||||
AND accounts.name LIKE $2
|
||||
ORDER BY accounts.name
|
||||
`
|
||||
@ -188,25 +196,33 @@ func (q *Queries) SearchAccounts(ctx context.Context, arg SearchAccountsParams)
|
||||
const updateAccount = `-- name: UpdateAccount :one
|
||||
UPDATE accounts
|
||||
SET name = $1,
|
||||
on_budget = $2
|
||||
WHERE accounts.id = $3
|
||||
RETURNING id, budget_id, name, on_budget
|
||||
on_budget = $2,
|
||||
is_open = $3
|
||||
WHERE accounts.id = $4
|
||||
RETURNING id, budget_id, name, on_budget, is_open
|
||||
`
|
||||
|
||||
type UpdateAccountParams struct {
|
||||
Name string
|
||||
OnBudget bool
|
||||
IsOpen 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)
|
||||
row := q.db.QueryRowContext(ctx, updateAccount,
|
||||
arg.Name,
|
||||
arg.OnBudget,
|
||||
arg.IsOpen,
|
||||
arg.ID,
|
||||
)
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BudgetID,
|
||||
&i.Name,
|
||||
&i.OnBudget,
|
||||
&i.IsOpen,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ type Account struct {
|
||||
BudgetID uuid.UUID
|
||||
Name string
|
||||
OnBudget bool
|
||||
IsOpen bool
|
||||
}
|
||||
|
||||
type Assignment struct {
|
||||
|
@ -11,27 +11,31 @@ WHERE accounts.id = $1;
|
||||
-- name: GetAccounts :many
|
||||
SELECT accounts.* FROM accounts
|
||||
WHERE accounts.budget_id = $1
|
||||
AND accounts.is_open = TRUE
|
||||
ORDER BY accounts.name;
|
||||
|
||||
-- name: GetAccountsWithBalance :many
|
||||
SELECT accounts.id, accounts.name, accounts.on_budget,
|
||||
SELECT accounts.id, accounts.name, accounts.on_budget, accounts.is_open,
|
||||
(SELECT MAX(transactions.date) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.status = 'Reconciled')::date as last_reconciled,
|
||||
(SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW())::decimal(12,2) as working_balance,
|
||||
(SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status IN ('Cleared', 'Reconciled'))::decimal(12,2) as cleared_balance,
|
||||
(SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status = 'Reconciled')::decimal(12,2) as reconciled_balance
|
||||
FROM accounts
|
||||
WHERE accounts.budget_id = $1
|
||||
AND accounts.is_open = TRUE
|
||||
ORDER BY accounts.name;
|
||||
|
||||
-- name: SearchAccounts :many
|
||||
SELECT accounts.id, accounts.budget_id, accounts.name, 'account' as type FROM accounts
|
||||
WHERE accounts.budget_id = @budget_id
|
||||
AND accounts.is_open = TRUE
|
||||
AND accounts.name LIKE @search
|
||||
ORDER BY accounts.name;
|
||||
|
||||
-- name: UpdateAccount :one
|
||||
UPDATE accounts
|
||||
SET name = $1,
|
||||
on_budget = $2
|
||||
WHERE accounts.id = $3
|
||||
on_budget = $2,
|
||||
is_open = $3
|
||||
WHERE accounts.id = $4
|
||||
RETURNING *;
|
5
postgres/schema/0016_closed-accounts.sql
Normal file
5
postgres/schema/0016_closed-accounts.sql
Normal file
@ -0,0 +1,5 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE accounts ADD COLUMN is_open BOOLEAN NOT NULL DEFAULT TRUE;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE accounts DROP COLUMN is_open;
|
@ -39,6 +39,7 @@ type TransactionsResponse struct {
|
||||
type EditAccountRequest struct {
|
||||
Name string `json:"name"`
|
||||
OnBudget bool `json:"onBudget"`
|
||||
IsOpen bool `json:"isOpen"`
|
||||
}
|
||||
|
||||
func (h *Handler) editAccount(c *gin.Context) {
|
||||
@ -59,6 +60,7 @@ func (h *Handler) editAccount(c *gin.Context) {
|
||||
updateParams := postgres.UpdateAccountParams{
|
||||
Name: request.Name,
|
||||
OnBudget: request.OnBudget,
|
||||
IsOpen: request.IsOpen,
|
||||
ID: accountUUID,
|
||||
}
|
||||
account, err := h.Service.UpdateAccount(c.Request.Context(), updateParams)
|
||||
|
@ -6,7 +6,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite App</title>
|
||||
</head>
|
||||
<body class="bg-slate-200 text-slate-800 dark:bg-slate-800 dark:text-slate-200">
|
||||
<body class="bg-slate-200 text-slate-800 dark:bg-slate-800 dark:text-slate-200 box-border w-full">
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
|
@ -27,39 +27,34 @@ export default defineComponent({
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="box-border w-full">
|
||||
<div class="flex bg-gray-400 dark:bg-gray-600 p-4 m-2 rounded-lg">
|
||||
<span class="flex-1 font-bold text-5xl -my-3 hidden md:inline" @click="toggleMenuSize">≡</span>
|
||||
<span class="flex-1 font-bold text-5xl -my-3 md:hidden" @click="toggleMenu">≡</span>
|
||||
|
||||
<span class="flex-1">{{ CurrentBudgetName }}</span>
|
||||
|
||||
<div class="flex flex-1 flex-row justify-end -mx-4">
|
||||
<router-link class="mx-4" v-if="LoggedIn" to="/dashboard">Dashboard</router-link>
|
||||
<router-link class="mx-4" v-if="!LoggedIn" to="/login">Login</router-link>
|
||||
<a class="mx-4" v-if="LoggedIn" @click="logout">Logout</a>
|
||||
</div>
|
||||
<div class="flex flex-col md:flex-row flex-1">
|
||||
<div
|
||||
:class="[Menu.Expand ? 'md:w-72' : 'md:w-36', Menu.Show ? '' : 'hidden']"
|
||||
class="md:block flex-shrink-0 w-full bg-gray-500 border-r-4 border-black"
|
||||
>
|
||||
<router-view name="sidebar"></router-view>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col md:flex-row flex-1">
|
||||
<div
|
||||
:class="[Menu.Expand ? 'md:w-72' : 'md:w-36', Menu.Show ? '' : 'hidden']"
|
||||
class="md:block flex-shrink-0 w-full"
|
||||
>
|
||||
<router-view name="sidebar"></router-view>
|
||||
<div class="flex-1">
|
||||
<div class="flex bg-gray-400 dark:bg-gray-600 p-4 fixed md:static top-0 left-0 w-full h-14">
|
||||
<span
|
||||
class="flex-1 font-bold text-5xl -my-3 hidden md:inline"
|
||||
@click="toggleMenuSize"
|
||||
>≡</span>
|
||||
<span class="flex-1 font-bold text-5xl -my-3 md:hidden" @click="toggleMenu">≡</span>
|
||||
|
||||
<span class="flex-1">{{ CurrentBudgetName }}</span>
|
||||
|
||||
<div class="flex flex-1 flex-row justify-end -mx-4">
|
||||
<router-link class="mx-4" v-if="LoggedIn" to="/dashboard">Dashboard</router-link>
|
||||
<router-link class="mx-4" v-if="!LoggedIn" to="/login">Login</router-link>
|
||||
<a class="mx-4" v-if="LoggedIn" @click="logout">Logout</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 p-6">
|
||||
<div class="p-3 pl-6">
|
||||
<router-view></router-view>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
#app {
|
||||
font-family: Avenir, Helvetica, Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
</style>
|
||||
</template>
|
@ -7,7 +7,7 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'submit'): void,
|
||||
(e: 'submit', event : {cancel:boolean}): boolean,
|
||||
(e: 'open'): void,
|
||||
}>();
|
||||
|
||||
@ -20,8 +20,12 @@ function openDialog() {
|
||||
visible.value = true;
|
||||
};
|
||||
function submitDialog() {
|
||||
const e = {cancel: false};
|
||||
emit("submit", e);
|
||||
if(e.cancel)
|
||||
return;
|
||||
|
||||
visible.value = false;
|
||||
emit("submit");
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -38,9 +42,9 @@ function submitDialog() {
|
||||
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="relative top-20 mx-auto p-5 w-96 shadow-lg rounded-md bg-white dark:bg-black">
|
||||
<div class="mt-3 text-center">
|
||||
<h3 class="mt-3 text-lg leading-6 font-medium text-gray-900">{{ buttonText }}</h3>
|
||||
<h3 class="mt-3 text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">{{ buttonText }}</h3>
|
||||
<slot></slot>
|
||||
<div class="grid grid-cols-2 gap-6">
|
||||
<button
|
||||
|
@ -3,29 +3,50 @@ import { computed, ref } from 'vue';
|
||||
import Modal from '../components/Modal.vue';
|
||||
import { useAccountStore } from '../stores/budget-account';
|
||||
import Input from '../components/Input.vue';
|
||||
import Checkbox from '../components/Checkbox.vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useBudgetsStore } from '../stores/budget';
|
||||
|
||||
const router = useRouter();
|
||||
const accountStore = useAccountStore();
|
||||
const CurrentAccount = computed(() => accountStore.CurrentAccount);
|
||||
|
||||
const accountName = ref("");
|
||||
const accountOnBudget = ref(true);
|
||||
const accountOpen = ref(true);
|
||||
const error = ref("");
|
||||
|
||||
function editAccount(e : any) {
|
||||
accountStore.EditAccount(CurrentAccount.value?.ID ?? "", accountName.value, accountOnBudget.value);
|
||||
function editAccount(e : {cancel:boolean}) : boolean {
|
||||
if(CurrentAccount.value?.ClearedBalance != 0 && !accountOpen.value){
|
||||
e.cancel = true;
|
||||
error.value = "Cannot close account with balance";
|
||||
return false;
|
||||
}
|
||||
|
||||
error.value = "";
|
||||
accountStore.EditAccount(CurrentAccount.value?.ID ?? "", accountName.value, accountOnBudget.value, accountOpen.value);
|
||||
|
||||
// account closed, move to Budget
|
||||
if(!accountOpen.value){
|
||||
const currentBudgetID = useBudgetsStore().CurrentBudgetID;
|
||||
router.replace('/budget/'+currentBudgetID+'/budgeting');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function openEditAccount(e : any) {
|
||||
accountName.value = CurrentAccount.value?.Name ?? "";
|
||||
accountOnBudget.value = CurrentAccount.value?.OnBudget ?? true;
|
||||
accountOpen.value = CurrentAccount.value?.IsOpen ?? true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal button-text="Edit Account" @open="openEditAccount" @submit="editAccount">
|
||||
<template v-slot:placeholder>✎</template>
|
||||
<template v-slot:placeholder><span class="ml-2">✎</span></template>
|
||||
<div class="mt-2 px-7 py-3">
|
||||
<Input
|
||||
class="border-2"
|
||||
class="border-2 dark:border-gray-700"
|
||||
type="text"
|
||||
v-model="accountName"
|
||||
placeholder="Account name"
|
||||
@ -33,13 +54,23 @@ function openEditAccount(e : any) {
|
||||
/>
|
||||
</div>
|
||||
<div class="mt-2 px-7 py-3">
|
||||
<Input
|
||||
<Checkbox
|
||||
class="border-2"
|
||||
type="checkbox"
|
||||
v-model="accountOnBudget"
|
||||
required
|
||||
/>
|
||||
<label>On Budget</label>
|
||||
</div>
|
||||
<div class="mt-2 px-7 py-3">
|
||||
<Checkbox
|
||||
class="border-2"
|
||||
v-model="accountOpen"
|
||||
required
|
||||
/>
|
||||
<label>Open</label>
|
||||
</div>
|
||||
<div v-if="error != ''" class="dark:text-red-300 text-red-700">
|
||||
{{ error }}
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
@ -8,4 +8,10 @@ h1 {
|
||||
|
||||
a {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#app {
|
||||
font-family: Avenir, Helvetica, Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
@ -43,10 +43,12 @@ function createReconcilationTransaction() {
|
||||
|
||||
<template>
|
||||
<div class="grid grid-cols-[1fr_auto]">
|
||||
<h1 class="inline">
|
||||
{{ accounts.CurrentAccount?.Name }}
|
||||
<div>
|
||||
<h1 class="inline">
|
||||
{{ accounts.CurrentAccount?.Name }}
|
||||
</h1>
|
||||
<EditAccount />
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div class="text-right flex flex-wrap flex-col md:flex-row justify-end gap-2 max-w-sm">
|
||||
<span class="rounded-lg p-1 whitespace-nowrap flex-1">
|
||||
|
@ -30,17 +30,17 @@ function getAccountName(account : Account) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col">
|
||||
<span class="m-1 p-1 px-3 text-xl">
|
||||
<router-link to="/dashboard">⌂</router-link>
|
||||
<div class="flex flex-col mt-14 md:mt-0">
|
||||
<span class="m-2 p-1 px-3 h-10 overflow-hidden" :class="[ExpandMenu ? 'text-2xl' : 'text-md']">
|
||||
<router-link to="/dashboard" style="font-size:150%">⌂</router-link>
|
||||
{{CurrentBudgetName}}
|
||||
</span>
|
||||
<span class="bg-orange-200 dark:bg-orange-700 rounded-lg m-1 p-1 px-3 flex flex-col">
|
||||
<span class="bg-gray-100 dark:bg-gray-700 p-2 px-3 flex flex-col">
|
||||
<router-link :to="'/budget/'+CurrentBudgetID+'/budgeting'">Budget</router-link><br />
|
||||
<!--<router-link :to="'/budget/'+CurrentBudgetID+'/reports'">Reports</router-link>-->
|
||||
<!--<router-link :to="'/budget/'+CurrentBudgetID+'/all-accounts'">All Accounts</router-link>-->
|
||||
</span>
|
||||
<li class="bg-orange-200 dark:bg-orange-700 rounded-lg m-1 p-1 px-3">
|
||||
<li class="bg-slate-200 dark:bg-slate-700 my-2 p-2 px-3">
|
||||
<div class="flex flex-row justify-between font-bold">
|
||||
<span>On-Budget Accounts</span>
|
||||
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="OnBudgetAccountsBalance" />
|
||||
@ -50,7 +50,7 @@ function getAccountName(account : Account) {
|
||||
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="account.ClearedBalance" />
|
||||
</div>
|
||||
</li>
|
||||
<li class="bg-red-200 dark:bg-red-800 rounded-lg m-1 p-1 px-3">
|
||||
<li class="bg-slate-200 dark:bg-slate-700 my-2 p-2 px-3">
|
||||
<div class="flex flex-row justify-between font-bold">
|
||||
<span>Off-Budget Accounts</span>
|
||||
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="OffBudgetAccountsBalance" />
|
||||
@ -60,20 +60,20 @@ function getAccountName(account : Account) {
|
||||
<Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="account.ClearedBalance" />
|
||||
</div>
|
||||
</li>
|
||||
<li class="bg-red-200 dark:bg-red-800 rounded-lg m-1 p-1 px-3">
|
||||
<!--
|
||||
<li class="bg-slate-100 dark:bg-slate-800 my-2 p-2 px-3">
|
||||
<div class="flex flex-row justify-between font-bold">
|
||||
<span>Closed Accounts</span>
|
||||
</div>
|
||||
+ Add Account
|
||||
</li>
|
||||
-->
|
||||
<!--<li>
|
||||
<router-link :to="'/budget/'+CurrentBudgetID+'/accounts'">Edit accounts</router-link>
|
||||
</li>-->
|
||||
<li class="bg-red-200 dark:bg-red-800 rounded-lg m-1 p-1 px-3">
|
||||
+ Add Account
|
||||
</li>
|
||||
<li class="bg-red-200 dark:bg-red-800 rounded-lg m-1 p-1 px-3">
|
||||
<li class="bg-red-100 dark:bg-slate-600 my-2 p-2 px-3">
|
||||
<router-link :to="'/budget/'+CurrentBudgetID+'/settings'">Budget-Settings</router-link>
|
||||
</li>
|
||||
<!--<li><router-link to="/admin">Admin</router-link></li>-->
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
@ -16,6 +16,7 @@ export interface Account {
|
||||
ID: string
|
||||
Name: string
|
||||
OnBudget: boolean
|
||||
IsOpen: boolean
|
||||
ClearedBalance: number
|
||||
WorkingBalance: number
|
||||
ReconciledBalance: number
|
||||
@ -123,10 +124,14 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
return;
|
||||
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 }));
|
||||
async EditAccount(accountid: string, name: string, onBudget: boolean, isOpen: boolean) {
|
||||
const result = await POST("/account/" + accountid, JSON.stringify({ name: name, onBudget: onBudget, isOpen: isOpen }));
|
||||
const response = await result.json();
|
||||
useBudgetsStore().MergeBudgetingData(response);
|
||||
|
||||
if(!isOpen) {
|
||||
this.Accounts.delete(accountid);
|
||||
}
|
||||
},
|
||||
addCategoriesForMonth(year: number, month: number, categories: Category[]): void {
|
||||
this.$patch((state) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user