diff --git a/src/.pgenv b/src/.pgenv
new file mode 100644
index 0000000..1c801b8
--- /dev/null
+++ b/src/.pgenv
@@ -0,0 +1,4 @@
+PGDATA=/var/lib/postgresql/data
+POSTGRES_USER=expdbuser
+POSTGRES_PASSWORD=expDBPass
+POSTGRES_DB=expenses
diff --git a/src/Makefile b/src/Makefile
index 76f4d0d..2714dcd 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -13,6 +13,18 @@ build_release_alpine:
mkdir -p $(build)/data/
find $(build) -name "*.ttf" ! -name DejaVuSansMono.ttf -delete
+devdb_start:
+ podman compose up database --force-recreate
+
+devdb_clear:
+ podman compose down -v database
+
+devdb_status:
+ podman compose stats database
+
+devdb_stop:
+ podman compose stop database
+
build_image: build_release_alpine
docker buildx build -t $(registry)/$(repo)/expensesweb:$(tag) .
diff --git a/src/assets/css/aesthetic.css b/src/assets/css/aesthetic.css
index e892130..4d6397d 100644
--- a/src/assets/css/aesthetic.css
+++ b/src/assets/css/aesthetic.css
@@ -27,17 +27,17 @@
@keyframes flicker {
0% {
- opacity: 1.1;
+ opacity: 0.9;
}
20% {
- opacity: 0.9;
- }
- 40% {
opacity: 1.1;
}
- 60% {
+ 40% {
opacity: 0.9;
}
+ 60% {
+ opacity: 1;
+ }
80% {
opacity: 1;
}
@@ -302,6 +302,35 @@ code {
color: var(--url-color);
}
+.table-container {
+ overflow-x: auto;
+ width: 0;
+ min-width: 100%;
+}
+
+.table-container table {
+ min-width: max-content;
+ border-collapse: collapse;
+}
+
+.table-container th {
+ border-bottom: 2px solid var(--text-color);
+ padding: 2px 4px;
+}
+
+.table-container td {
+ padding: 2px 4px;
+}
+
+.table-container th:not(:last-child),
+.table-container td:not(:last-child) {
+ border-right: 1px solid var(--text-color);
+}
+
+.table-container tr.negative-row {
+ background-color: var(--warning-color);
+}
+
/* CSS for centering images */
.centeredImgContainer {
max-width: 80%;
@@ -344,6 +373,7 @@ dt {
}
#container {
+ max-width: 100%;
width: 100%;
margin: auto;
display: flex;
@@ -369,6 +399,8 @@ dt {
}
.main-container-content {
+ width: 100%;
+ max-width: 100%;
height: 100%;
overflow-y: auto;
/* IE and Edge */
diff --git a/src/assets/css/aesthetic.css.map b/src/assets/css/aesthetic.css.map
index ec0b832..ba0039c 100644
--- a/src/assets/css/aesthetic.css.map
+++ b/src/assets/css/aesthetic.css.map
@@ -1 +1 @@
-{"version":3,"sourceRoot":"","sources":["crt.scss","expensesTable.scss","forms.scss","modals.scss","main.scss"],"names":[],"mappings":";AAMA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGA;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;EAIA;EACA;EACA;EACA;EAEA;;;AAGF;EAII;IACE;;EADF;IACE;;EADF;IACE;;EADF;IACE;;EADF;IACE;;EADF;IACE;;;AAKN;EACE;IACE;;;AAIJ;EACE;IACE;;EAGF;IACE;;EAGF;IACE;;;AAIJ;EACE;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;;ACtJJ;EACE;EACA;EACA;;;AAGF;EACE;;;ACPF;EACE;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;;;AAGF;AAAA;EAEE;EACA;;;AC1DF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;;;AAGF;EACE;EACA;EACA;EACA;;;AAGF;EACE;EACA;;;ACnBF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;;AAGF;EACE;EACA;EACA;EAEA;EAEA;EACA;AAEA;EACA;EACA;;;AAGF;EACE;EACA;EACA;EAEA;EAEA;;;AAGF;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;;;AAGF;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;;;AAGF;AACA;EACE;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;;;AAGF;AAEA;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;AAAA;EAEE;EACA,aACE;;;AAGJ;EACE;;;AAGF;EACE;EACA;EAEA;EACA;;;AAGF;AACE;EACA;EACA;EACA;EACA;EACA;AAEA;EACA;EACA;EACA;EACA;EAEA;EACA;EAEA;EAEA;;;AAGF;EACE;EAEA;AAEA;EACA;AACA;EACA;EAEA;;;AAGF;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;;;AAGF;AACA;AACA;AACA;EACE;;;AAGF;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;;;AAGF;EACE;IACE;;;AAIJ;EACE;;;AAGF;EACE;EAGA;EACA","file":"aesthetic.css"}
\ No newline at end of file
+{"version":3,"sourceRoot":"","sources":["crt.scss","expensesTable.scss","forms.scss","modals.scss","main.scss"],"names":[],"mappings":";AAMA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGA;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;EAIA;EACA;EACA;EACA;EAEA;;;AAGF;EAII;IACE;;EADF;IACE;;EADF;IACE;;EADF;IACE;;EADF;IACE;;EADF;IACE;;;AAKN;EACE;IACE;;;AAIJ;EACE;IACE;;EAGF;IACE;;EAGF;IACE;;;AAIJ;EACE;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;EAGF;IACE;;;ACtJJ;EACE;EACA;EACA;;;AAGF;EACE;;;ACPF;EACE;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;;;AAGF;AAAA;EAEE;EACA;;;AC1DF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;;;AAGF;EACE;EACA;EACA;EACA;;;AAGF;EACE;EACA;;;ACnBF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;;AAGF;EACE;EACA;EACA;EAEA;EAEA;EACA;AAEA;EACA;EACA;;;AAGF;EACE;EACA;EACA;EAEA;EAEA;;;AAGF;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;;;AAGF;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;;;AAIF;EACE;EACA;EACA;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;;;AAGF;EACE;;;AAGF;AAAA;EAEE;;;AAGF;EACE;;;AAIF;AACA;EACE;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;;;AAGF;AAEA;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;AAAA;EAEE;EACA,aACE;;;AAGJ;EACE;;;AAGF;EACE;EACA;EACA;EAEA;EACA;;;AAGF;AACE;EACA;EACA;EACA;EACA;EACA;AAEA;EACA;EACA;EACA;EACA;EAEA;EACA;EAEA;EAEA;;;AAGF;EACE;EACA;EACA;EAEA;AAEA;EACA;AACA;EACA;EAEA;;;AAGF;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;;;AAGF;AACA;AACA;AACA;EACE;;;AAGF;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;;;AAGF;EACE;IACE;;;AAIJ;EACE;;;AAGF;EACE;EAGA;EACA","file":"aesthetic.css"}
\ No newline at end of file
diff --git a/src/assets/css/main.scss b/src/assets/css/main.scss
index 6e58a37..32ed6f3 100644
--- a/src/assets/css/main.scss
+++ b/src/assets/css/main.scss
@@ -88,6 +88,37 @@ code {
color: var(--url-color);
}
+// Table stuff
+.table-container {
+ overflow-x: auto;
+ width: 0;
+ min-width: 100%;
+}
+
+.table-container table {
+ min-width: max-content;
+ border-collapse: collapse;
+}
+
+.table-container th {
+ border-bottom: 2px solid var(--text-color);
+ padding: 2px 4px;
+}
+
+.table-container td {
+ padding: 2px 4px;
+}
+
+.table-container th:not(:last-child),
+.table-container td:not(:last-child) {
+ border-right: 1px solid var(--text-color);
+}
+
+.table-container tr.negative-row {
+ background-color: var(--warning-color);
+}
+// End of table stuff
+
/* CSS for centering images */
.centeredImgContainer {
max-width: 80%;
@@ -132,6 +163,7 @@ dt {
}
#container {
+ max-width: 100%;
width: 100%;
margin: auto;
@@ -162,6 +194,8 @@ dt {
}
.main-container-content {
+ width: 100%;
+ max-width: 100%;
height: 100%;
overflow-y: auto;
diff --git a/src/assets/htmx/analysis.html b/src/assets/htmx/analysis.html
index 018b110..9fa004e 100644
--- a/src/assets/htmx/analysis.html
+++ b/src/assets/htmx/analysis.html
@@ -1,115 +1,13 @@
{{ define "analysis" }}
-
-
-
-
-
-
-
-
-
-
-
+
+ -
+
+
+
{{ end }}
diff --git a/src/assets/htmx/analysisDashboard.html b/src/assets/htmx/analysisDashboard.html
new file mode 100644
index 0000000..3865dd4
--- /dev/null
+++ b/src/assets/htmx/analysisDashboard.html
@@ -0,0 +1,44 @@
+{{ define "analysis-filtered" }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{{ end }}
diff --git a/src/assets/htmx/analysisDashboardResults.html b/src/assets/htmx/analysisDashboardResults.html
new file mode 100644
index 0000000..e78f2b5
--- /dev/null
+++ b/src/assets/htmx/analysisDashboardResults.html
@@ -0,0 +1,54 @@
+{{ define "analysis-filtered-results" }}
+
+
+
+{{ end }}
diff --git a/src/assets/htmx/expensesTable.html b/src/assets/htmx/expensesTable.html
index 5f717fc..2d0b979 100644
--- a/src/assets/htmx/expensesTable.html
+++ b/src/assets/htmx/expensesTable.html
@@ -1,22 +1,24 @@
{{ define "expensesTable" }}
-
-
- | ID |
- OWNER |
- DESC |
- PRICE |
- DATE |
- Category |
-
- {{ range .expenses }}
-
- | {{ .ExpID }} |
- {{ .Owner.UserName }} |
- {{ .Description }} |
- {{ formatPrice .Value }} |
- {{ formatDate .Date }} |
- {{ .Category.CategoryName }} |
-
- {{ end }}
-
+
+
+
+ | ID |
+ OWNER |
+ DESC |
+ PRICE |
+ DATE |
+ Category |
+
+ {{ range .expenses }}
+
+ | {{ .ExpID }} |
+ {{ .Owner.UserName }} |
+ {{ .Description }} |
+ {{ formatPrice .Value }} |
+ {{ formatDate .Date }} |
+ {{ .Category.CategoryName }} |
+
+ {{ end }}
+
+
{{ end }}
diff --git a/src/assets/htmx/mainPage.html b/src/assets/htmx/mainPage.html
index e3e8589..0e290a8 100644
--- a/src/assets/htmx/mainPage.html
+++ b/src/assets/htmx/mainPage.html
@@ -1,4 +1,7 @@
{{ define "mainPage" }}
{{ template "expensesFilterBox" . }}
+
+Table
+
{{ template "expensesTable" . }}
{{ end }}
diff --git a/src/assets/htmx/terminal.html b/src/assets/htmx/terminal.html
index d86cb66..050b4cd 100644
--- a/src/assets/htmx/terminal.html
+++ b/src/assets/htmx/terminal.html
@@ -70,6 +70,8 @@
{{ template "overview" . }}
{{ else if eq .content "analysis" }}
{{ template "analysis" . }}
+ {{ else if eq .content "analysis-filtered" }}
+ {{ template "analysis-filtered" . }}
{{ else if eq .content "stores" }}
{{ template "stores" . }}
{{ else if eq .content "store" }}
diff --git a/src/assets/js/analysis.js b/src/assets/js/analysis.js
new file mode 100644
index 0000000..43482b4
--- /dev/null
+++ b/src/assets/js/analysis.js
@@ -0,0 +1,125 @@
+(function() {
+ function loadScript(src, callback) {
+ if (window.Chart && src.includes('chart.js')) {
+ callback();
+ return;
+ }
+ if (document.querySelector(`script[src="${src}"]`)) {
+ if (window.Chart) {
+ callback();
+ } else {
+ const existingScript = document.querySelector(`script[src="${src}"]`);
+ existingScript.addEventListener('load', callback);
+ }
+ return;
+ }
+
+ const script = document.createElement('script');
+ script.src = src;
+ script.onload = callback;
+ document.head.appendChild(script);
+ }
+
+ // Load Chart.js first, then the plugin, then render charts
+ loadScript('/assets/js/chart.js', function() {
+ loadScript('/assets/js/chartjs-plugin-datalabels.js', function() {
+ renderAnalysisCharts();
+ });
+ });
+
+ function renderAnalysisCharts() {
+ // Read the global data injected by the HTML template
+ const monthlyBalanceData = window.analysisBalanceData || [];
+ const mTotalData = window.analysisTotalData || [];
+
+ // --- Monthly Balance Chart ---
+ const mBalanceChart = document.getElementById('monthlyBalance');
+ const labels = monthlyBalanceData.map(entry =>
+ new Date(2000, entry.month, 1).toLocaleString('en', {month: 'short'})
+ );
+ const values = monthlyBalanceData.map(entry => Number(entry.total));
+
+ new Chart(mBalanceChart, {
+ type: 'bar',
+ data: {
+ labels: labels,
+ datasets: [{
+ label: 'Monthly Balance',
+ data: values,
+ backgroundColor: (ctx) => {
+ const value = ctx.raw;
+ return value < 0 ? 'rgb(231 144 234 / 50%)' : 'rgb(67 149 84 / 50%)';
+ },
+ borderColor: (ctx) => {
+ const value = ctx.raw;
+ return value < 0 ? 'rgb(231 144 234 / 100%)' : 'rgb(67 149 84 / 100%)';
+ },
+ borderWidth: 1
+ }]
+ },
+ options: {
+ plugins: {
+ datalabels: {
+ anchor: "end",
+ align: "end",
+ formatter: (value) => value,
+ color: (context) => {
+ const value = context.dataset.data[context.dataIndex];
+ return value < 0 ? 'rgb(231 144 234 / 100%)' : 'rgb(67 149 84 / 100%)';
+ },
+ font: { weight: 'bold' }
+ }
+ },
+ scales: {
+ y: { beginAtZero: true }
+ }
+ },
+ plugins: [ChartDataLabels]
+ });
+
+ // --- Total Chart ---
+ const mTotalChart = document.getElementById('monthlyTotal');
+ const mTotalLabels = mTotalData.map(entry =>
+ new Date(2000, entry.month, 1).toLocaleString('en', {month: 'short'})
+ );
+ const mTotalValues = mTotalData.map(entry => Number(entry.total));
+
+ new Chart(mTotalChart, {
+ type: 'line',
+ data: {
+ labels: mTotalLabels,
+ datasets: [{
+ label: 'Monthly Total',
+ data: mTotalValues,
+ backgroundColor: (ctx) => {
+ const value = ctx.raw;
+ return value < 0 ? 'rgb(231 144 234 / 50%)' : 'rgb(67 149 84 / 50%)';
+ },
+ borderColor: (ctx) => {
+ const value = ctx.raw;
+ return value < 0 ? 'rgb(231 144 234 / 100%)' : 'rgb(67 149 84 / 100%)';
+ },
+ borderWidth: 1
+ }]
+ },
+ options: {
+ plugins: {
+ datalabels: {
+ anchor: "end",
+ align: "end",
+ formatter: (value) => value,
+ color: (context) => {
+ const value = context.dataset.data[context.dataIndex];
+ return value < 0 ? 'rgb(231 144 234 / 100%)' : 'rgb(67 149 84 / 100%)';
+ },
+ font: { weight: 'bold' }
+ }
+ },
+ scales: {
+ y: { beginAtZero: true }
+ }
+ },
+ plugins: [ChartDataLabels]
+ });
+ }
+ })();
diff --git a/src/cmd/server.go b/src/cmd/server.go
index 61bf967..91a5742 100644
--- a/src/cmd/server.go
+++ b/src/cmd/server.go
@@ -2,6 +2,10 @@ package cmd
import (
"encoding/json"
+ "html/template"
+ "log"
+ "net/http"
+ "time"
"github.com/ESilva15/expenses/api"
"github.com/ESilva15/expenses/config"
@@ -14,11 +18,7 @@ import (
"github.com/shopspring/decimal"
"github.com/spf13/cobra"
- "html/template"
- "log"
- "net/http"
fp "path/filepath"
- "time"
"github.com/gin-gonic/gin"
)
@@ -73,6 +73,7 @@ func setRoutes(router *gin.RouterGroup, eng *gin.Engine) {
pages.RouteShares(router)
pages.RouteOverview(router)
pages.RouteAnalysis(router)
+ pages.RouteAnalysisDashboard(router)
// This are for the engine, I really need to rethink this
pages.RouteLogin(eng)
diff --git a/src/config.yaml b/src/config.yaml
index a624e0e..6b2cbd1 100644
--- a/src/config.yaml
+++ b/src/config.yaml
@@ -2,9 +2,9 @@ assets: "./assets/"
port: 8081
postgres:
user: expdbuser
- pass: thepass
- db: thedb
- host: /home/esilva/Desktop/projetos/expenses/src/pgImage/pgSocket/
- port: 5432
+ pass: expDBPass
+ db: expenses
+ host: "127.0.0.1"
+ port: 5431
migrationsPath: "file://expenses/repo/pgdb/migrations/"
migCustomScripts: "./expenses/repo/pgdb/migrations/custom/"
diff --git a/src/development.md b/src/development.md
new file mode 100644
index 0000000..47642c8
--- /dev/null
+++ b/src/development.md
@@ -0,0 +1,29 @@
+# Database stuff
+## Download a production database's data
+```bash
+docker exec -i \
+ pg_dump -U -a -d > outputfile.sql
+```
+
+## Start a local development database
+```bash
+# Use to clean the volumens and kill the current running database
+podman compose down -v database
+# Use to recreate database
+podman compose up database --force-recreate
+
+# Alternatively, to down the service and clear it
+make devdb_clear
+
+# And to start it
+make devdb_start
+```
+
+## Upload a database
+```bash
+# Don't forget to devdb_clear the current existing database
+psql -h 127.0.0.1 -p 5431 -U expdbuser -d expenses -f ./data.sql
+```
+
+# CSS
+Go to `assets/css` and run `sass --watch main.scss aesthetic.css`
diff --git a/src/docker-compose.yaml b/src/docker-compose.yaml
new file mode 100644
index 0000000..83f0704
--- /dev/null
+++ b/src/docker-compose.yaml
@@ -0,0 +1,10 @@
+services:
+ database:
+ image: docker.io/library/postgres:16
+ container_name: expenses-dev-db
+ hostname: expenses-dev-db
+ env_file:
+ - .pgenv
+ ports:
+ - "5431:5432"
+ restart: unless-stopped
diff --git a/src/expenses/app.go b/src/expenses/app.go
index b36d217..d8ce6c9 100644
--- a/src/expenses/app.go
+++ b/src/expenses/app.go
@@ -3,40 +3,43 @@ package expenses
import (
"context"
+ "errors"
"fmt"
"log"
+ "strings"
"github.com/ESilva15/expenses/config"
"github.com/ESilva15/expenses/expenses/repo"
+ "github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
lua "github.com/yuin/gopher-lua"
)
// ExpApp is the data structure for the main runtime of this application.
type ExpApp struct {
- Lua *lua.LState
- ExpRepo repo.ExpenseRepository
- CategoryRepo repo.CategoryRepository
- UserRepo repo.UserRepository
- StoreRepo repo.StoreRepository
- TypeRepo repo.TypeRepository
+ Lua *lua.LState
+ FinancialRepo repo.FinancialRepository
+ ExpRepo repo.ExpenseRepository
+ CategoryRepo repo.CategoryRepository
+ UserRepo repo.UserRepository
+ StoreRepo repo.StoreRepository
+ TypeRepo repo.TypeRepository
}
-var (
- // App provides access to the expenses main service.
- App *ExpApp
-)
+// App provides access to the expenses main service.
+var App *ExpApp
// NewExpenseApp returns a new instance of our core App.
func NewExpenseApp(dbPool *pgxpool.Pool, luaVM *lua.LState) *ExpApp {
return &ExpApp{
- ExpRepo: repo.NewPgExpRepo(dbPool),
- CategoryRepo: repo.NewPgCatRepo(dbPool),
- UserRepo: repo.NewPgUserRepo(dbPool),
- StoreRepo: repo.NewPgStoreRepo(dbPool),
- TypeRepo: repo.NewPgTypeRepo(dbPool),
- Lua: luaVM,
+ FinancialRepo: repo.NewPgFinancialRepo(dbPool),
+ ExpRepo: repo.NewPgExpRepo(dbPool),
+ CategoryRepo: repo.NewPgCatRepo(dbPool),
+ UserRepo: repo.NewPgUserRepo(dbPool),
+ StoreRepo: repo.NewPgStoreRepo(dbPool),
+ TypeRepo: repo.NewPgTypeRepo(dbPool),
+ Lua: luaVM,
}
}
@@ -59,25 +62,73 @@ func getPgConnString(cfg *config.Configuration) string {
cfg.PgCfg.User, cfg.PgCfg.Pass, cfg.PgCfg.DB, cfg.PgCfg.Host, cfg.PgCfg.Port)
}
+func createTargetDatabase(cfg *config.Configuration) error {
+ // Connect to the default 'postgres' database instead of cfg.PgCfg.DB
+ adminConnStr := fmt.Sprintf("postgres://%s:%s@/%s?host=%s&port=%s&sslmode=disable",
+ cfg.PgCfg.User, cfg.PgCfg.Pass, "postgres", cfg.PgCfg.Host, cfg.PgCfg.Port)
+
+ ctx := context.Background()
+ pool, err := pgxpool.New(ctx, adminConnStr)
+ if err != nil {
+ return fmt.Errorf("failed to connect to default postgres db: %w", err)
+ }
+ defer pool.Close()
+
+ // Execute CREATE DATABASE (Note: database identifiers cannot be parameterized with $1)
+ query := fmt.Sprintf("CREATE DATABASE %s", cfg.PgCfg.DB)
+ _, err = pool.Exec(ctx, query)
+ if err != nil {
+ return fmt.Errorf("failed to create database: %w", err)
+ }
+
+ log.Printf("Database %q created successfully!", cfg.PgCfg.DB)
+ return nil
+}
+
func runMigrations(luaVM *lua.LState) error {
cfg := config.GetInstance()
pgStr := getPgConnString(cfg)
migrator, err := repo.NewPgMigrator(pgStr)
if err != nil {
- return err
+ // Check if error is due to database not existing
+ if isDatabaseNotFoundError(err) {
+ log.Printf("Database %q does not exist. Creating it...", cfg.PgCfg.DB)
+ if createErr := createTargetDatabase(cfg); createErr != nil {
+ return fmt.Errorf("failed to create missing database: %w", createErr)
+ }
+
+ // Retry creating the migrator after the database is created
+ migrator, err = repo.NewPgMigrator(pgStr)
+ if err != nil {
+ return err
+ }
+ } else {
+ return err
+ }
}
err = migrator.RunMigrations(luaVM)
if err != nil {
- log.Fatalf("Failed to apply migrations: %v", err)
+ migrator.Close()
+ return fmt.Errorf("failed to apply migrations: %w", err)
}
migrator.Close()
-
return nil
}
+// Helper to check for PostgreSQL code "3D000" or text fallback
+func isDatabaseNotFoundError(err error) bool {
+ var pgErr *pgconn.PgError
+ if errors.As(err, &pgErr) && pgErr.Code == "3D000" {
+ return true
+ }
+
+ // Fallback string check if wrapped differently by the repo layer
+ return strings.Contains(err.Error(), "does not exist")
+}
+
// GoToMigration provides a way to force moving to the specified migration.
func (a *ExpApp) GoToMigration(id uint) error {
cfg := config.GetInstance()
@@ -103,12 +154,43 @@ func createPGXPoolConn(ctx context.Context) (*pgxpool.Pool, error) {
var result int
err = conn.QueryRow(ctx, "SELECT 1").Scan(&result)
if err != nil {
- panic("connection test query failed: " + err.Error())
+ return nil, err
}
return conn, nil
}
+func PrepareDB(ctx context.Context, luaVM *lua.LState) error {
+ // Attempt to prepare the database
+ err := runMigrations(luaVM)
+ if err != nil {
+ log.Fatalf("Unable to run migrations: %v", err)
+ }
+
+ return nil
+}
+
+func CheckDatabase(ctx context.Context, luaVM *lua.LState) error {
+ cfg := config.GetInstance()
+ pgStr := getPgConnString(cfg)
+
+ conn, err := pgxpool.New(ctx, pgStr)
+ if err != nil {
+ // Unable to create the database
+ return err
+ }
+
+ var result int
+ err = conn.QueryRow(ctx, "SELECT status,version FROM dbstat").Scan(&result)
+ if err != nil {
+ if err := PrepareDB(ctx, luaVM); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
// StartApp will configure and open the required connections to run this app.
func StartApp() error {
config.SetConfig("./config.yaml")
@@ -120,13 +202,13 @@ func StartApp() error {
return err
}
- // Run the migrations
+ // Run migrations (will automatically create the database if it doesn't exist)
err = runMigrations(luaVM)
if err != nil {
- log.Printf("Unable to run migrations: %v", err)
+ log.Fatalf("Unable to run migrations: %v", err)
}
- // Create our final app thing
+ // Create our final app pool connection
conn, err := createPGXPoolConn(ctx)
if err != nil {
log.Fatalf("Failed to open DB: %v", err)
diff --git a/src/expenses/financial.go b/src/expenses/financial.go
new file mode 100644
index 0000000..9384221
--- /dev/null
+++ b/src/expenses/financial.go
@@ -0,0 +1,21 @@
+package expenses
+
+import (
+ "context"
+
+ mod "github.com/ESilva15/expenses/expenses/models"
+)
+
+func (a *ExpApp) GetMonthlySummary(
+ ctx context.Context,
+ filter *mod.Filter,
+) ([]mod.MonthlySummary, error) {
+ return a.FinancialRepo.GetMonthlySummary(ctx, filter)
+}
+
+func (a *ExpApp) GetMonthlySavingsAverage(
+ ctx context.Context,
+ filter *mod.Filter,
+) (mod.MonthlySavingsAverage, error) {
+ return a.FinancialRepo.GetMonthlySavingsAverage(ctx, filter)
+}
diff --git a/src/expenses/models/financial.go b/src/expenses/models/financial.go
new file mode 100644
index 0000000..90bdf0a
--- /dev/null
+++ b/src/expenses/models/financial.go
@@ -0,0 +1,50 @@
+package models
+
+import (
+ "time"
+
+ dec "github.com/shopspring/decimal"
+)
+
+type MonthlySummary struct {
+ MonthYear string `json:"month_year"`
+ Despesa dec.Decimal `json:"despesa"`
+ Salario dec.Decimal `json:"salario"`
+ CartaoRefeicao dec.Decimal `json:"cartao_refeicao"`
+ Reembolso dec.Decimal `json:"reembolso"`
+ Prenda dec.Decimal `json:"prenda"`
+ Investment dec.Decimal `json:"investment"`
+ Adjustment dec.Decimal `json:"adjustment"`
+ AdjustmentLiquid dec.Decimal `json:"adjustment_liquid"`
+ Poupanca dec.Decimal `json:"poupanca"`
+ PoupancaLiquid dec.Decimal `json:"poupanca_liquid"`
+ RunningBalance dec.Decimal `json:"running_balance"`
+ RunningBalanceLiquid dec.Decimal `json:"running_balance_liquid"`
+}
+
+type MonthlySavingsAverage struct {
+ AvgPoupanca dec.Decimal `json:"avg_poupanca"`
+ AvgPoupancaLiquid dec.Decimal `json:"avg_poupanca_liquid"`
+}
+
+// ExpFilter has the fields required to query the database.
+type Filter struct {
+ Start *time.Time // Start is the earliest an expense can be
+ End *time.Time // End is the latest an expense can be
+ UserIDs int32 // UserIDs is a list of IDs to match against
+ CatIDs []int32 // CatIDs is a list of categories to match against
+ StoreIDs []int32 // StoreIDs is a list of stores to match against
+ TypeIDs []int32 // TypeIDs is a list of types to match against
+}
+
+// NewExpFilter returns a newly initialized ExpFilter.
+func NewFilter() Filter {
+ return Filter{
+ Start: nil,
+ End: nil,
+ UserIDs: -1,
+ CatIDs: nil,
+ StoreIDs: nil,
+ TypeIDs: nil,
+ }
+}
diff --git a/src/expenses/repo/financialRepo.go b/src/expenses/repo/financialRepo.go
new file mode 100644
index 0000000..41f362b
--- /dev/null
+++ b/src/expenses/repo/financialRepo.go
@@ -0,0 +1,14 @@
+package repo
+
+import (
+ "context"
+
+ mod "github.com/ESilva15/expenses/expenses/models"
+)
+
+// CategoryRepository defines the repository for the category data model.
+type FinancialRepository interface {
+ GetMonthlySummary(context.Context, *mod.Filter) ([]mod.MonthlySummary, error)
+ GetMonthlySavingsAverage(context.Context, *mod.Filter) (mod.MonthlySavingsAverage, error)
+ Close()
+}
diff --git a/src/expenses/repo/pg_financialMapper.go b/src/expenses/repo/pg_financialMapper.go
new file mode 100644
index 0000000..defa566
--- /dev/null
+++ b/src/expenses/repo/pg_financialMapper.go
@@ -0,0 +1,39 @@
+package repo
+
+import (
+ mod "github.com/ESilva15/expenses/expenses/models"
+ pgsqlc "github.com/ESilva15/expenses/expenses/repo/pgdb/pgsqlc"
+)
+
+func mapRepoMonthlySummary(r pgsqlc.GetMonthlySummaryRow) mod.MonthlySummary {
+ return mod.MonthlySummary{
+ MonthYear: r.MonthYear,
+ Despesa: pgNumericToDecimal(r.Despesa),
+ Salario: pgNumericToDecimal(r.Salario),
+ CartaoRefeicao: pgNumericToDecimal(r.CartaoRefeicao),
+ Reembolso: pgNumericToDecimal(r.Reembolso),
+ Prenda: pgNumericToDecimal(r.Prenda),
+ Investment: pgNumericToDecimal(r.Investment),
+ Adjustment: pgNumericToDecimal(r.Adjustment),
+ AdjustmentLiquid: pgNumericToDecimal(r.AdjustmentLiquid),
+ Poupanca: pgNumericToDecimal(r.Poupanca),
+ PoupancaLiquid: pgNumericToDecimal(r.PoupancaLiquid),
+ RunningBalance: pgNumericToDecimal(r.RunningBalance),
+ RunningBalanceLiquid: pgNumericToDecimal(r.RunningBalanceLiquid),
+ }
+}
+
+func mapRepoMonthlySummaries(rows []pgsqlc.GetMonthlySummaryRow) []mod.MonthlySummary {
+ summaries := make([]mod.MonthlySummary, len(rows))
+ for i, row := range rows {
+ summaries[i] = mapRepoMonthlySummary(row)
+ }
+ return summaries
+}
+
+func mapRepoMonthlySavingsAverage(r pgsqlc.GetMonthlySavingsAverageRow) mod.MonthlySavingsAverage {
+ return mod.MonthlySavingsAverage{
+ AvgPoupanca: pgNumericToDecimal(r.AvgPoupanca),
+ AvgPoupancaLiquid: pgNumericToDecimal(r.AvgPoupancaLiquid),
+ }
+}
diff --git a/src/expenses/repo/pg_financialRepo.go b/src/expenses/repo/pg_financialRepo.go
new file mode 100644
index 0000000..36ee615
--- /dev/null
+++ b/src/expenses/repo/pg_financialRepo.go
@@ -0,0 +1,61 @@
+package repo
+
+import (
+ "context"
+
+ mod "github.com/ESilva15/expenses/expenses/models"
+ "github.com/ESilva15/expenses/expenses/repo/pgdb/pgsqlc"
+ "github.com/jackc/pgx/v5/pgtype"
+ "github.com/jackc/pgx/v5/pgxpool"
+)
+
+type PgFinancialRepo struct {
+ DB *pgxpool.Pool
+}
+
+func NewPgFinancialRepo(db *pgxpool.Pool) PgFinancialRepo {
+ return PgFinancialRepo{DB: db}
+}
+
+func (f PgFinancialRepo) Close() {
+ f.DB.Close()
+}
+
+func (p PgFinancialRepo) GetMonthlySummary(
+ ctx context.Context,
+ filter *mod.Filter,
+) ([]mod.MonthlySummary, error) {
+ queries := pgsqlc.New(p.DB)
+
+ var pgStart, pgEnd pgtype.Timestamp
+ if filter.Start != nil {
+ pgStart = pgtype.Timestamp{Time: *filter.Start, Valid: true}
+ }
+ if filter.End != nil {
+ pgEnd = pgtype.Timestamp{Time: *filter.End, Valid: true}
+ }
+
+ rows, err := queries.GetMonthlySummary(ctx, pgsqlc.GetMonthlySummaryParams{
+ Startdate: pgStart,
+ Enddate: pgEnd,
+ UserID: filter.UserIDs,
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return mapRepoMonthlySummaries(rows), nil
+}
+
+func (p PgFinancialRepo) GetMonthlySavingsAverage(
+ ctx context.Context,
+ filter *mod.Filter,
+) (mod.MonthlySavingsAverage, error) {
+ queries := pgsqlc.New(p.DB)
+ res, err := queries.GetMonthlySavingsAverage(ctx)
+ if err != nil {
+ return mod.MonthlySavingsAverage{}, err
+ }
+
+ return mapRepoMonthlySavingsAverage(res), nil
+}
diff --git a/src/expenses/repo/pgdb/migrations/0001_baseline.down.sql b/src/expenses/repo/pgdb/migrations/0001_baseline.down.sql
deleted file mode 100644
index fc49089..0000000
--- a/src/expenses/repo/pgdb/migrations/0001_baseline.down.sql
+++ /dev/null
@@ -1 +0,0 @@
-SELECT * FROM expenses;
diff --git a/src/expenses/repo/pgdb/migrations/0001_baseline.up.sql b/src/expenses/repo/pgdb/migrations/0001_baseline.up.sql
deleted file mode 100644
index fc49089..0000000
--- a/src/expenses/repo/pgdb/migrations/0001_baseline.up.sql
+++ /dev/null
@@ -1 +0,0 @@
-SELECT * FROM expenses;
diff --git a/src/expenses/repo/pgdb/migrations/0001_initial_schema.down.sql b/src/expenses/repo/pgdb/migrations/0001_initial_schema.down.sql
new file mode 100644
index 0000000..3b95016
--- /dev/null
+++ b/src/expenses/repo/pgdb/migrations/0001_initial_schema.down.sql
@@ -0,0 +1,7 @@
+DROP TABLE IF EXISTS public."expensesShares";
+DROP TABLE IF EXISTS public."expensesPayments";
+DROP TABLE IF EXISTS public.expenses;
+DROP TABLE IF EXISTS public.stores;
+DROP TABLE IF EXISTS public."expenseTypes";
+DROP TABLE IF EXISTS public.users;
+DROP TABLE IF EXISTS public.categories;
diff --git a/src/expenses/repo/pgdb/migrations/0001_initial_schema.up.sql b/src/expenses/repo/pgdb/migrations/0001_initial_schema.up.sql
new file mode 100644
index 0000000..e0a781e
--- /dev/null
+++ b/src/expenses/repo/pgdb/migrations/0001_initial_schema.up.sql
@@ -0,0 +1,69 @@
+-- Create base lookup/independent tables first
+CREATE TABLE public.categories (
+ "CategoryID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+ "CategoryName" text NOT NULL,
+ CONSTRAINT categories_pkey PRIMARY KEY ("CategoryID")
+);
+
+CREATE TABLE public.users (
+ "UserID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+ "UserName" text NOT NULL,
+ "UserPass" text NOT NULL,
+ CONSTRAINT users_pkey PRIMARY KEY ("UserID")
+);
+
+CREATE TABLE public."expenseTypes" (
+ "TypeID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+ "TypeName" text NOT NULL,
+ CONSTRAINT "expenseTypes_pkey" PRIMARY KEY ("TypeID")
+);
+
+CREATE TABLE public.stores (
+ "StoreID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+ "StoreName" text NOT NULL,
+ "NIF" text DEFAULT ''::text,
+ CONSTRAINT stores_pkey PRIMARY KEY ("StoreID")
+);
+
+-- Create main expenses table including the 'qr' column
+CREATE TABLE public.expenses (
+ "ExpID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+ "Description" text NOT NULL,
+ "Value" numeric(12,2) DEFAULT 0 NOT NULL,
+ "StoreID" integer DEFAULT 0 NOT NULL,
+ "CategoryID" integer DEFAULT 0 NOT NULL,
+ "OwnerUserID" integer DEFAULT 0 NOT NULL,
+ "TypeID" integer DEFAULT 0 NOT NULL,
+ "ExpDate" timestamp without time zone NOT NULL,
+ "CreationDate" timestamp without time zone NOT NULL,
+ "PaidOff" boolean DEFAULT false,
+ "SharesEven" boolean DEFAULT false,
+ qr text DEFAULT ''::text,
+ CONSTRAINT expenses_pkey PRIMARY KEY ("ExpID"),
+ CONSTRAINT "expenses_StoreID_fkey" FOREIGN KEY ("StoreID") REFERENCES public.stores("StoreID") ON DELETE RESTRICT,
+ CONSTRAINT "expenses_CategoryID_fkey" FOREIGN KEY ("CategoryID") REFERENCES public.categories("CategoryID") ON DELETE RESTRICT,
+ CONSTRAINT "expenses_OwnerUserID_fkey" FOREIGN KEY ("OwnerUserID") REFERENCES public.users("UserID") ON DELETE RESTRICT,
+ CONSTRAINT "expenses_TypeID_fkey" FOREIGN KEY ("TypeID") REFERENCES public."expenseTypes"("TypeID") ON DELETE RESTRICT
+);
+
+-- Create dependent relationship tables
+CREATE TABLE public."expensesPayments" (
+ "ExpPaymID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+ "ExpID" integer NOT NULL,
+ "UserID" integer NOT NULL,
+ "Payed" numeric(12,2) DEFAULT 0 NOT NULL,
+ CONSTRAINT "expensesPayments_pkey" PRIMARY KEY ("ExpPaymID"),
+ CONSTRAINT "expensesPayments_ExpID_fkey" FOREIGN KEY ("ExpID") REFERENCES public.expenses("ExpID") ON DELETE RESTRICT,
+ CONSTRAINT "expensesPayments_UserID_fkey" FOREIGN KEY ("UserID") REFERENCES public.users("UserID") ON DELETE RESTRICT
+);
+
+CREATE TABLE public."expensesShares" (
+ "ExpShareID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+ "ExpID" integer NOT NULL,
+ "UserID" integer NOT NULL,
+ "Share" numeric(6,2) DEFAULT 0.5 NOT NULL,
+ "Calculated" numeric(12,2) DEFAULT 0 NOT NULL,
+ CONSTRAINT "expensesShares_pkey" PRIMARY KEY ("ExpShareID"),
+ CONSTRAINT "expensesShares_ExpID_fkey" FOREIGN KEY ("ExpID") REFERENCES public.expenses("ExpID") ON DELETE RESTRICT,
+ CONSTRAINT "expensesShares_UserID_fkey" FOREIGN KEY ("UserID") REFERENCES public.users("UserID") ON DELETE RESTRICT
+);
diff --git a/src/expenses/repo/pgdb/migrations/0002_qr_feature.down.sql b/src/expenses/repo/pgdb/migrations/0002_qr_feature.down.sql
deleted file mode 100644
index e312407..0000000
--- a/src/expenses/repo/pgdb/migrations/0002_qr_feature.down.sql
+++ /dev/null
@@ -1,4 +0,0 @@
---- 0001_qr_feature.down.sql
-
-ALTER TABLE expenses DROP COLUMN "qr";
-ALTER TABLE stores DROP COLUMN "NIF";
diff --git a/src/expenses/repo/pgdb/migrations/0002_qr_feature.up.sql b/src/expenses/repo/pgdb/migrations/0002_qr_feature.up.sql
deleted file mode 100644
index 07988d8..0000000
--- a/src/expenses/repo/pgdb/migrations/0002_qr_feature.up.sql
+++ /dev/null
@@ -1,4 +0,0 @@
---- 0001_qr_feature.up.sql
-
-ALTER TABLE expenses ADD qr TEXT DEFAULT '';
-ALTER TABLE stores ADD "NIF" TEXT DEFAULT '';
diff --git a/src/expenses/repo/pgdb/pgsqlc/categories.sql.go b/src/expenses/repo/pgdb/pgsqlc/categories.sql.go
index 0c07049..7d4a2cf 100644
--- a/src/expenses/repo/pgdb/pgsqlc/categories.sql.go
+++ b/src/expenses/repo/pgdb/pgsqlc/categories.sql.go
@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
-// sqlc v1.30.0
+// sqlc v1.31.1
// source: categories.sql
package pgsqlc
diff --git a/src/expenses/repo/pgdb/pgsqlc/db.go b/src/expenses/repo/pgdb/pgsqlc/db.go
index 03ff426..8a1bc66 100644
--- a/src/expenses/repo/pgdb/pgsqlc/db.go
+++ b/src/expenses/repo/pgdb/pgsqlc/db.go
@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
-// sqlc v1.30.0
+// sqlc v1.31.1
package pgsqlc
diff --git a/src/expenses/repo/pgdb/pgsqlc/expenses.sql.go b/src/expenses/repo/pgdb/pgsqlc/expenses.sql.go
index 3727467..38f454e 100644
--- a/src/expenses/repo/pgdb/pgsqlc/expenses.sql.go
+++ b/src/expenses/repo/pgdb/pgsqlc/expenses.sql.go
@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
-// sqlc v1.30.0
+// sqlc v1.31.1
// source: expenses.sql
package pgsqlc
@@ -84,6 +84,59 @@ func (q *Queries) GetExpense(ctx context.Context, expid int32) (GetExpenseRow, e
return i, err
}
+const getExpenseSum = `-- name: GetExpenseSum :one
+SELECT "ExpID", "Description", "Value", "StoreID", "CategoryID", "OwnerUserID", "TypeID", "ExpDate", "CreationDate", "PaidOff", "SharesEven", qr, "ExpShareID", "ExpID", "UserID", "Share", "Calculated" from "expenses"
+JOIN "expensesShares" ON "expenses"."ExpID" = "expensesShares"."ExpID"
+WHERE
+ "expenses"."ExpID" = 673 AND
+ "expensesShares"."UserID" = 1
+`
+
+type GetExpenseSumRow struct {
+ ExpID int32
+ Description string
+ Value pgtype.Numeric
+ StoreID int32
+ CategoryID int32
+ OwnerUserID int32
+ TypeID int32
+ ExpDate pgtype.Timestamp
+ CreationDate pgtype.Timestamp
+ PaidOff pgtype.Bool
+ SharesEven pgtype.Bool
+ Qr string
+ ExpShareID int32
+ ExpID_2 int32
+ UserID int32
+ Share pgtype.Numeric
+ Calculated pgtype.Numeric
+}
+
+func (q *Queries) GetExpenseSum(ctx context.Context) (GetExpenseSumRow, error) {
+ row := q.db.QueryRow(ctx, getExpenseSum)
+ var i GetExpenseSumRow
+ err := row.Scan(
+ &i.ExpID,
+ &i.Description,
+ &i.Value,
+ &i.StoreID,
+ &i.CategoryID,
+ &i.OwnerUserID,
+ &i.TypeID,
+ &i.ExpDate,
+ &i.CreationDate,
+ &i.PaidOff,
+ &i.SharesEven,
+ &i.Qr,
+ &i.ExpShareID,
+ &i.ExpID_2,
+ &i.UserID,
+ &i.Share,
+ &i.Calculated,
+ )
+ return i, err
+}
+
const getExpenses = `-- name: GetExpenses :many
SELECT
expenses."ExpID", expenses."Description", expenses."Value", expenses."StoreID", expenses."CategoryID", expenses."OwnerUserID", expenses."TypeID", expenses."ExpDate", expenses."CreationDate", expenses."PaidOff", expenses."SharesEven", expenses.qr,
@@ -182,6 +235,45 @@ func (q *Queries) GetExpenses(ctx context.Context, arg GetExpensesParams) ([]Get
return items, nil
}
+const getMonthlyTotalPaid = `-- name: GetMonthlyTotalPaid :many
+SELECT
+ EXTRACT(MONTH FROM e."ExpDate") AS month,
+ SUM(ep."Payed") AS monthly_total_paid
+FROM "expensesPayments" ep
+JOIN
+ expenses e ON ep."ExpID" = e."ExpID"
+WHERE
+ ep."UserID" = 1
+ AND e."TypeID" = 0
+GROUP BY EXTRACT(MONTH FROM e."ExpDate")
+ORDER BY month
+`
+
+type GetMonthlyTotalPaidRow struct {
+ Month pgtype.Numeric
+ MonthlyTotalPaid int64
+}
+
+func (q *Queries) GetMonthlyTotalPaid(ctx context.Context) ([]GetMonthlyTotalPaidRow, error) {
+ rows, err := q.db.Query(ctx, getMonthlyTotalPaid)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []GetMonthlyTotalPaidRow
+ for rows.Next() {
+ var i GetMonthlyTotalPaidRow
+ if err := rows.Scan(&i.Month, &i.MonthlyTotalPaid); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
const insertExpense = `-- name: InsertExpense :one
INSERT INTO expenses(
"Description",
diff --git a/src/expenses/repo/pgdb/pgsqlc/financial.sql.go b/src/expenses/repo/pgdb/pgsqlc/financial.sql.go
new file mode 100644
index 0000000..e3127aa
--- /dev/null
+++ b/src/expenses/repo/pgdb/pgsqlc/financial.sql.go
@@ -0,0 +1,168 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+// sqlc v1.31.1
+// source: financial.sql
+
+package pgsqlc
+
+import (
+ "context"
+
+ "github.com/jackc/pgx/v5/pgtype"
+)
+
+const getMonthlySavingsAverage = `-- name: GetMonthlySavingsAverage :one
+WITH monthly_summary AS (
+ SELECT
+ TO_CHAR(e."ExpDate", 'MM/YYYY') AS month_year,
+ DATE_TRUNC('month', e."ExpDate") AS month_sort,
+ SUM(CASE WHEN e."TypeID" = 0 THEN ep."Payed" ELSE 0 END)::NUMERIC AS despesa,
+ SUM(CASE WHEN e."TypeID" = 1 THEN ep."Payed" ELSE 0 END)::NUMERIC AS salario,
+ SUM(CASE WHEN e."TypeID" = 2 THEN ep."Payed" ELSE 0 END)::NUMERIC AS cartao_refeicao,
+ SUM(CASE WHEN e."TypeID" = 3 THEN ep."Payed" ELSE 0 END)::NUMERIC AS reembolso,
+ SUM(CASE WHEN e."TypeID" = 4 THEN ep."Payed" ELSE 0 END)::NUMERIC AS prenda,
+ SUM(CASE WHEN e."TypeID" = 5 THEN ep."Payed" ELSE 0 END)::NUMERIC AS investment,
+ SUM(CASE WHEN e."TypeID" = 6 THEN ep."Payed" ELSE 0 END)::NUMERIC AS adjustment,
+ SUM(CASE WHEN e."TypeID" = 7 THEN ep."Payed" ELSE 0 END)::NUMERIC AS adjustment_liquid
+ FROM "expensesPayments" ep
+ JOIN expenses e ON ep."ExpID" = e."ExpID"
+ WHERE ep."UserID" = 1
+ GROUP BY
+ TO_CHAR(e."ExpDate", 'MM/YYYY'),
+ DATE_TRUNC('month', e."ExpDate")
+),
+calculated_summary AS (
+ SELECT
+ ((salario + cartao_refeicao + reembolso) - (despesa + prenda))::NUMERIC AS poupanca,
+ ((salario + cartao_refeicao + reembolso) - (despesa + investment + prenda))::NUMERIC AS poupanca_liquid
+ FROM monthly_summary
+)
+SELECT
+ TRUNC(AVG(poupanca), 2)::NUMERIC AS avg_poupanca,
+ TRUNC(AVG(poupanca_liquid), 2)::NUMERIC AS avg_poupanca_liquid
+FROM calculated_summary
+`
+
+type GetMonthlySavingsAverageRow struct {
+ AvgPoupanca pgtype.Numeric
+ AvgPoupancaLiquid pgtype.Numeric
+}
+
+func (q *Queries) GetMonthlySavingsAverage(ctx context.Context) (GetMonthlySavingsAverageRow, error) {
+ row := q.db.QueryRow(ctx, getMonthlySavingsAverage)
+ var i GetMonthlySavingsAverageRow
+ err := row.Scan(&i.AvgPoupanca, &i.AvgPoupancaLiquid)
+ return i, err
+}
+
+const getMonthlySummary = `-- name: GetMonthlySummary :many
+WITH monthly_summary AS (
+ SELECT
+ TO_CHAR(e."ExpDate", 'MM/YYYY') AS month_year,
+ DATE_TRUNC('month', e."ExpDate") AS month_sort,
+ SUM(CASE WHEN e."TypeID" = 0 THEN ep."Payed" ELSE 0 END)::NUMERIC AS despesa,
+ SUM(CASE WHEN e."TypeID" = 1 THEN ep."Payed" ELSE 0 END)::NUMERIC AS salario,
+ SUM(CASE WHEN e."TypeID" = 2 THEN ep."Payed" ELSE 0 END)::NUMERIC AS cartao_refeicao,
+ SUM(CASE WHEN e."TypeID" = 3 THEN ep."Payed" ELSE 0 END)::NUMERIC AS reembolso,
+ SUM(CASE WHEN e."TypeID" = 4 THEN ep."Payed" ELSE 0 END)::NUMERIC AS prenda,
+ SUM(CASE WHEN e."TypeID" = 5 THEN ep."Payed" ELSE 0 END)::NUMERIC AS investment,
+ SUM(CASE WHEN e."TypeID" = 6 THEN ep."Payed" ELSE 0 END)::NUMERIC AS adjustment,
+ SUM(CASE WHEN e."TypeID" = 7 THEN ep."Payed" ELSE 0 END)::NUMERIC AS adjustment_liquid
+ FROM "expensesPayments" ep
+ JOIN expenses e ON ep."ExpID" = e."ExpID"
+ WHERE ep."UserID" = $1
+ AND ($2::timestamp IS NULL OR e."ExpDate" >= $2::timestamp)
+ AND ($3::timestamp IS NULL OR e."ExpDate" <= $3::timestamp)
+ GROUP BY
+ TO_CHAR(e."ExpDate", 'MM/YYYY'),
+ DATE_TRUNC('month', e."ExpDate")
+),
+calculated_summary AS (
+ SELECT
+ month_year,
+ month_sort,
+ despesa,
+ salario,
+ cartao_refeicao,
+ reembolso,
+ prenda,
+ investment,
+ adjustment,
+ adjustment_liquid,
+ ((salario + cartao_refeicao + reembolso) - (despesa + prenda))::NUMERIC AS poupanca,
+ ((salario + cartao_refeicao + reembolso) - (despesa + investment + prenda))::NUMERIC AS poupanca_liquid
+ FROM monthly_summary
+)
+SELECT
+ month_year,
+ despesa,
+ salario,
+ cartao_refeicao,
+ reembolso,
+ prenda,
+ investment,
+ adjustment,
+ adjustment_liquid,
+ poupanca,
+ poupanca_liquid,
+ (SUM(poupanca) OVER (ORDER BY month_sort ASC) + SUM(adjustment) OVER (ORDER BY month_sort ASC) + SUM(adjustment_liquid) OVER (ORDER BY month_sort ASC))::NUMERIC AS running_balance,
+ (SUM(poupanca_liquid) OVER (ORDER BY month_sort ASC) + SUM(adjustment_liquid) OVER (ORDER BY month_sort ASC))::NUMERIC AS running_balance_liquid
+FROM calculated_summary
+ORDER BY month_sort ASC
+`
+
+type GetMonthlySummaryParams struct {
+ UserID int32
+ Startdate pgtype.Timestamp
+ Enddate pgtype.Timestamp
+}
+
+type GetMonthlySummaryRow struct {
+ MonthYear string
+ Despesa pgtype.Numeric
+ Salario pgtype.Numeric
+ CartaoRefeicao pgtype.Numeric
+ Reembolso pgtype.Numeric
+ Prenda pgtype.Numeric
+ Investment pgtype.Numeric
+ Adjustment pgtype.Numeric
+ AdjustmentLiquid pgtype.Numeric
+ Poupanca pgtype.Numeric
+ PoupancaLiquid pgtype.Numeric
+ RunningBalance pgtype.Numeric
+ RunningBalanceLiquid pgtype.Numeric
+}
+
+func (q *Queries) GetMonthlySummary(ctx context.Context, arg GetMonthlySummaryParams) ([]GetMonthlySummaryRow, error) {
+ rows, err := q.db.Query(ctx, getMonthlySummary, arg.UserID, arg.Startdate, arg.Enddate)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []GetMonthlySummaryRow
+ for rows.Next() {
+ var i GetMonthlySummaryRow
+ if err := rows.Scan(
+ &i.MonthYear,
+ &i.Despesa,
+ &i.Salario,
+ &i.CartaoRefeicao,
+ &i.Reembolso,
+ &i.Prenda,
+ &i.Investment,
+ &i.Adjustment,
+ &i.AdjustmentLiquid,
+ &i.Poupanca,
+ &i.PoupancaLiquid,
+ &i.RunningBalance,
+ &i.RunningBalanceLiquid,
+ ); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
diff --git a/src/expenses/repo/pgdb/pgsqlc/models.go b/src/expenses/repo/pgdb/pgsqlc/models.go
index 50503b9..7f0fe90 100644
--- a/src/expenses/repo/pgdb/pgsqlc/models.go
+++ b/src/expenses/repo/pgdb/pgsqlc/models.go
@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
-// sqlc v1.30.0
+// sqlc v1.31.1
package pgsqlc
diff --git a/src/expenses/repo/pgdb/pgsqlc/payments.sql.go b/src/expenses/repo/pgdb/pgsqlc/payments.sql.go
index 6da6980..b1ef021 100644
--- a/src/expenses/repo/pgdb/pgsqlc/payments.sql.go
+++ b/src/expenses/repo/pgdb/pgsqlc/payments.sql.go
@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
-// sqlc v1.30.0
+// sqlc v1.31.1
// source: payments.sql
package pgsqlc
diff --git a/src/expenses/repo/pgdb/pgsqlc/shares.sql.go b/src/expenses/repo/pgdb/pgsqlc/shares.sql.go
index 953db11..6efbd38 100644
--- a/src/expenses/repo/pgdb/pgsqlc/shares.sql.go
+++ b/src/expenses/repo/pgdb/pgsqlc/shares.sql.go
@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
-// sqlc v1.30.0
+// sqlc v1.31.1
// source: shares.sql
package pgsqlc
diff --git a/src/expenses/repo/pgdb/pgsqlc/stores.sql.go b/src/expenses/repo/pgdb/pgsqlc/stores.sql.go
index 00adb80..098a7a0 100644
--- a/src/expenses/repo/pgdb/pgsqlc/stores.sql.go
+++ b/src/expenses/repo/pgdb/pgsqlc/stores.sql.go
@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
-// sqlc v1.30.0
+// sqlc v1.31.1
// source: stores.sql
package pgsqlc
diff --git a/src/expenses/repo/pgdb/pgsqlc/types.sql.go b/src/expenses/repo/pgdb/pgsqlc/types.sql.go
index b385bd6..02314b2 100644
--- a/src/expenses/repo/pgdb/pgsqlc/types.sql.go
+++ b/src/expenses/repo/pgdb/pgsqlc/types.sql.go
@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
-// sqlc v1.30.0
+// sqlc v1.31.1
// source: types.sql
package pgsqlc
diff --git a/src/expenses/repo/pgdb/pgsqlc/users.sql.go b/src/expenses/repo/pgdb/pgsqlc/users.sql.go
index 42e1e67..070418e 100644
--- a/src/expenses/repo/pgdb/pgsqlc/users.sql.go
+++ b/src/expenses/repo/pgdb/pgsqlc/users.sql.go
@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
-// sqlc v1.30.0
+// sqlc v1.31.1
// source: users.sql
package pgsqlc
diff --git a/src/expenses/repo/pgdb/queries/expenses.sql b/src/expenses/repo/pgdb/queries/expenses.sql
index 5a06ff0..dbff381 100644
--- a/src/expenses/repo/pgdb/queries/expenses.sql
+++ b/src/expenses/repo/pgdb/queries/expenses.sql
@@ -87,3 +87,23 @@ SET
"qr" = $9,
"ExpDate" = $10
WHERE "ExpID" = $11;
+
+-- name: GetExpenseSum :one
+SELECT * from "expenses"
+JOIN "expensesShares" ON "expenses"."ExpID" = "expensesShares"."ExpID"
+WHERE
+ "expenses"."ExpID" = 673 AND
+ "expensesShares"."UserID" = 1;
+
+-- name: GetMonthlyTotalPaid :many
+SELECT
+ EXTRACT(MONTH FROM e."ExpDate") AS month,
+ SUM(ep."Payed") AS monthly_total_paid
+FROM "expensesPayments" ep
+JOIN
+ expenses e ON ep."ExpID" = e."ExpID"
+WHERE
+ ep."UserID" = 1
+ AND e."TypeID" = 0
+GROUP BY EXTRACT(MONTH FROM e."ExpDate")
+ORDER BY month;
diff --git a/src/expenses/repo/pgdb/queries/financial.sql b/src/expenses/repo/pgdb/queries/financial.sql
new file mode 100644
index 0000000..903f5e2
--- /dev/null
+++ b/src/expenses/repo/pgdb/queries/financial.sql
@@ -0,0 +1,85 @@
+-- name: GetMonthlySummary :many
+WITH monthly_summary AS (
+ SELECT
+ TO_CHAR(e."ExpDate", 'MM/YYYY') AS month_year,
+ DATE_TRUNC('month', e."ExpDate") AS month_sort,
+ SUM(CASE WHEN e."TypeID" = 0 THEN ep."Payed" ELSE 0 END)::NUMERIC AS despesa,
+ SUM(CASE WHEN e."TypeID" = 1 THEN ep."Payed" ELSE 0 END)::NUMERIC AS salario,
+ SUM(CASE WHEN e."TypeID" = 2 THEN ep."Payed" ELSE 0 END)::NUMERIC AS cartao_refeicao,
+ SUM(CASE WHEN e."TypeID" = 3 THEN ep."Payed" ELSE 0 END)::NUMERIC AS reembolso,
+ SUM(CASE WHEN e."TypeID" = 4 THEN ep."Payed" ELSE 0 END)::NUMERIC AS prenda,
+ SUM(CASE WHEN e."TypeID" = 5 THEN ep."Payed" ELSE 0 END)::NUMERIC AS investment,
+ SUM(CASE WHEN e."TypeID" = 6 THEN ep."Payed" ELSE 0 END)::NUMERIC AS adjustment,
+ SUM(CASE WHEN e."TypeID" = 7 THEN ep."Payed" ELSE 0 END)::NUMERIC AS adjustment_liquid
+ FROM "expensesPayments" ep
+ JOIN expenses e ON ep."ExpID" = e."ExpID"
+ WHERE ep."UserID" = $1
+ AND (sqlc.narg(StartDate)::timestamp IS NULL OR e."ExpDate" >= sqlc.narg(StartDate)::timestamp)
+ AND (sqlc.narg(EndDate)::timestamp IS NULL OR e."ExpDate" <= sqlc.narg(EndDate)::timestamp)
+ GROUP BY
+ TO_CHAR(e."ExpDate", 'MM/YYYY'),
+ DATE_TRUNC('month', e."ExpDate")
+),
+calculated_summary AS (
+ SELECT
+ month_year,
+ month_sort,
+ despesa,
+ salario,
+ cartao_refeicao,
+ reembolso,
+ prenda,
+ investment,
+ adjustment,
+ adjustment_liquid,
+ ((salario + cartao_refeicao + reembolso) - (despesa + prenda))::NUMERIC AS poupanca,
+ ((salario + cartao_refeicao + reembolso) - (despesa + investment + prenda))::NUMERIC AS poupanca_liquid
+ FROM monthly_summary
+)
+SELECT
+ month_year,
+ despesa,
+ salario,
+ cartao_refeicao,
+ reembolso,
+ prenda,
+ investment,
+ adjustment,
+ adjustment_liquid,
+ poupanca,
+ poupanca_liquid,
+ (SUM(poupanca) OVER (ORDER BY month_sort ASC) + SUM(adjustment) OVER (ORDER BY month_sort ASC) + SUM(adjustment_liquid) OVER (ORDER BY month_sort ASC))::NUMERIC AS running_balance,
+ (SUM(poupanca_liquid) OVER (ORDER BY month_sort ASC) + SUM(adjustment_liquid) OVER (ORDER BY month_sort ASC))::NUMERIC AS running_balance_liquid
+FROM calculated_summary
+ORDER BY month_sort ASC;
+
+-- name: GetMonthlySavingsAverage :one
+WITH monthly_summary AS (
+ SELECT
+ TO_CHAR(e."ExpDate", 'MM/YYYY') AS month_year,
+ DATE_TRUNC('month', e."ExpDate") AS month_sort,
+ SUM(CASE WHEN e."TypeID" = 0 THEN ep."Payed" ELSE 0 END)::NUMERIC AS despesa,
+ SUM(CASE WHEN e."TypeID" = 1 THEN ep."Payed" ELSE 0 END)::NUMERIC AS salario,
+ SUM(CASE WHEN e."TypeID" = 2 THEN ep."Payed" ELSE 0 END)::NUMERIC AS cartao_refeicao,
+ SUM(CASE WHEN e."TypeID" = 3 THEN ep."Payed" ELSE 0 END)::NUMERIC AS reembolso,
+ SUM(CASE WHEN e."TypeID" = 4 THEN ep."Payed" ELSE 0 END)::NUMERIC AS prenda,
+ SUM(CASE WHEN e."TypeID" = 5 THEN ep."Payed" ELSE 0 END)::NUMERIC AS investment,
+ SUM(CASE WHEN e."TypeID" = 6 THEN ep."Payed" ELSE 0 END)::NUMERIC AS adjustment,
+ SUM(CASE WHEN e."TypeID" = 7 THEN ep."Payed" ELSE 0 END)::NUMERIC AS adjustment_liquid
+ FROM "expensesPayments" ep
+ JOIN expenses e ON ep."ExpID" = e."ExpID"
+ WHERE ep."UserID" = 1
+ GROUP BY
+ TO_CHAR(e."ExpDate", 'MM/YYYY'),
+ DATE_TRUNC('month', e."ExpDate")
+),
+calculated_summary AS (
+ SELECT
+ ((salario + cartao_refeicao + reembolso) - (despesa + prenda))::NUMERIC AS poupanca,
+ ((salario + cartao_refeicao + reembolso) - (despesa + investment + prenda))::NUMERIC AS poupanca_liquid
+ FROM monthly_summary
+)
+SELECT
+ TRUNC(AVG(poupanca), 2)::NUMERIC AS avg_poupanca,
+ TRUNC(AVG(poupanca_liquid), 2)::NUMERIC AS avg_poupanca_liquid
+FROM calculated_summary;
diff --git a/src/pages/analysis.go b/src/pages/analysis.go
deleted file mode 100644
index 873c907..0000000
--- a/src/pages/analysis.go
+++ /dev/null
@@ -1,158 +0,0 @@
-package pages
-
-import (
- "net/http"
- "sync"
-
- exp "github.com/ESilva15/expenses/expenses"
- mod "github.com/ESilva15/expenses/expenses/models"
- val "github.com/ESilva15/expenses/expenses/values"
- dec "github.com/shopspring/decimal"
-
- "github.com/gin-gonic/gin"
-)
-
-// MonthlyTotal holds the data for the MonthlyTotal plot.
-type MonthlyTotal struct {
- Month int `json:"month"`
- Total dec.Decimal `json:"total"`
-}
-
-func getMonthlyBalance(expenses mod.Expenses, uID int32) ([]MonthlyTotal, error) {
- monthlyBalance := make([]MonthlyTotal, val.MonthsPerYear)
- for k := range val.MonthsPerYear {
- monthlyBalance[k].Month = k
- }
-
- for _, e := range expenses {
- month := e.Date.Month() - 1
- t := e.Type.TypeName
-
- // Get the current expenses value and make it negative if its an expense
- // It's not the value, its what we paid on it (our payments)
- // I don't like this like this - takes too long, we should load it from DB
- // at the start, and cache it too
- _ = exp.App.LoadExpensePayments(&e)
- value := exp.App.PaidByUser(e, uID)
- // value := e.Value
- if t == "Despesa" {
- value = value.Neg()
- }
-
- // Store the data on the montly balance list
- monthlyBalance[month].Total = monthlyBalance[month].Total.Add(value)
- }
-
- return monthlyBalance, nil
-}
-
-func getMonthlyTotal(expenses mod.Expenses, uID int32) ([]MonthlyTotal, error) {
- mTotal := make([]MonthlyTotal, val.MonthsPerYear)
- for k := range mTotal {
- mTotal[k].Month = k
- }
-
- // Step 1: net total for each month
- for _, e := range expenses {
- month := int(e.Date.Month()) - 1 // Jan = 0
- // Same as on the other one here
- _ = exp.App.LoadExpensePayments(&e)
- value := exp.App.PaidByUser(e, uID)
- if e.Type.TypeName == "Despesa" {
- value = value.Neg()
- }
- mTotal[month].Total = mTotal[month].Total.Add(value)
- }
-
- // Step 2: cumulative balance
- for i := 1; i < len(mTotal); i++ {
- mTotal[i].Total = mTotal[i].Total.Add(mTotal[i-1].Total)
- }
-
- return mTotal, nil
-}
-
-func getAnalysisDataWG(c *gin.Context) (map[string]any, error) {
- ctx, err := getLoggedInUserCTX(c)
- if err != nil {
- return map[string]any{}, err
- }
- user := *ctx.Value("user").(*mod.User)
-
- filter, err := expenseFilterFromQuery(c)
- if err != nil {
- return map[string]any{}, err
- }
-
- queriedExpenses, err := exp.App.GetAllExpenses(ctx, filter)
- if err != nil {
- return map[string]any{}, err
- }
-
- var (
- mBalance []MonthlyTotal
- mTotal []MonthlyTotal
- bErr error
- tErr error
- wg sync.WaitGroup
- )
-
- wg.Add(2)
- go func() {
- defer wg.Done()
- mBalance, bErr = getMonthlyBalance(queriedExpenses, user.UserID)
- }()
- go func() {
- defer wg.Done()
- mTotal, tErr = getMonthlyTotal(queriedExpenses, user.UserID)
- }()
- wg.Wait()
-
- if tErr != nil {
- return map[string]any{}, tErr
- }
- if bErr != nil {
- return map[string]any{}, bErr
- }
-
- plotData := map[string]any{
- "mBalance": mBalance,
- "mTotal": mTotal,
- }
-
- return plotData, nil
-}
-
-func analysisPartialPage(c *gin.Context) {
- // TODO - this is repeated code with the analysisPage one, figure something
- data, err := getAnalysisDataWG(c)
- if err != nil {
- ServerErrorView(c, "failed to compiled analysis data")
- return
- }
-
- c.HTML(http.StatusOK, "analysis", gin.H{
- "plotData": data,
- })
-}
-
-func analysisPage(c *gin.Context) {
- data, err := getAnalysisDataWG(c)
- if err != nil {
- ServerErrorView(c, "failed to compiled analysis data")
- return
- }
-
- c.HTML(http.StatusOK, "terminal", gin.H{
- "page": "analysis",
- "renderNavBar": true,
- "content": "analysis",
- "plotData": data,
- })
-}
-
-// RouteAnalysis routes the endpoints for analysis stuff.
-func RouteAnalysis(router *gin.RouterGroup) {
- router.GET("/analysis", analysisPage)
- router.POST("/analysis", analysisPartialPage)
-}
diff --git a/src/pages/expensesHelper.go b/src/pages/expensesHelper.go
index acf48f7..9c158ce 100644
--- a/src/pages/expensesHelper.go
+++ b/src/pages/expensesHelper.go
@@ -15,6 +15,54 @@ import (
"github.com/shopspring/decimal"
)
+func filterFromQuery(c *gin.Context) (mod.Filter, error) {
+ var err error
+ var start, end time.Time
+ filter := mod.NewFilter()
+
+ startDate := c.Query("range-start")
+ if startDate != "" {
+ startDate += " 00:00:00"
+ start, err = time.ParseInLocation("02-Jan-2006 15:04:05", startDate, time.UTC)
+ if err != nil {
+ log.Printf("error startDate: %v", err)
+ return mod.Filter{}, nil
+ }
+ filter.Start = &start
+ }
+
+ endDate := c.Query("range-end")
+ if endDate != "" {
+ endDate += " 00:00:00"
+ end, err = time.ParseInLocation("02-Jan-2006 15:04:05", endDate, time.UTC)
+ if err != nil {
+ log.Printf("error endDate: %v", err)
+ return mod.Filter{}, nil
+ }
+ filter.End = &end
+ }
+
+ filter.CatIDs, err = ginaux.QueryIntArray(c, "cat-dropdown[]")
+ if err != nil {
+ log.Printf("Failed to retrieve IDs from cat-dropdown[] %+v", err)
+ return mod.Filter{}, nil
+ }
+
+ filter.StoreIDs, err = ginaux.QueryIntArray(c, "store-dropdown[]")
+ if err != nil {
+ log.Printf("Failed to retrieve IDs from store-dropdown[] %+v", err)
+ return mod.Filter{}, nil
+ }
+
+ filter.TypeIDs, err = ginaux.QueryIntArray(c, "type-dropdown[]")
+ if err != nil {
+ log.Printf("Failed to retrieve IDs from type-dropdown[] %+v", err)
+ return mod.Filter{}, nil
+ }
+
+ return filter, nil
+}
+
func expenseFilterFromQuery(c *gin.Context) (repo.ExpFilter, error) {
var err error
var start, end time.Time
diff --git a/src/pages/financial.go b/src/pages/financial.go
new file mode 100644
index 0000000..b6ed994
--- /dev/null
+++ b/src/pages/financial.go
@@ -0,0 +1,25 @@
+package pages
+
+import (
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+)
+
+func analysisPage(c *gin.Context) {
+ c.HTML(http.StatusOK, "terminal", gin.H{
+ "page": "analysis",
+ "renderNavBar": true,
+ "content": "analysis",
+ })
+}
+
+func analysisPartialPage(c *gin.Context) {
+ c.HTML(http.StatusOK, "analysis", gin.H{})
+}
+
+// RouteAnalysis routes the endpoints for analysis stuff.
+func RouteAnalysis(router *gin.RouterGroup) {
+ router.GET("/analysis", analysisPage)
+ router.POST("/analysis", analysisPartialPage)
+}
diff --git a/src/pages/financialDashboard.go b/src/pages/financialDashboard.go
new file mode 100644
index 0000000..db6c484
--- /dev/null
+++ b/src/pages/financialDashboard.go
@@ -0,0 +1,67 @@
+package pages
+
+import (
+ "log"
+ "net/http"
+
+ exp "github.com/ESilva15/expenses/expenses"
+ mod "github.com/ESilva15/expenses/expenses/models"
+ "github.com/gin-gonic/gin"
+)
+
+func getSummaryData(c *gin.Context) ([]mod.MonthlySummary, error) {
+ ctx, err := getLoggedInUserCTX(c)
+ if err != nil {
+ log.Printf("error getting user from context: %+v", err)
+ ServerErrorView(c, "Could not get logged in user")
+ return nil, nil
+ }
+
+ filter, err := filterFromQuery(c)
+ if err != nil {
+ log.Printf("error parsing filters from query: %+v", err)
+ ServerErrorView(c, "Could not get logged in user")
+ return nil, nil
+ }
+ filter.UserIDs = *&ctx.Value("user").(*mod.User).UserID
+ summary, err := exp.App.GetMonthlySummary(ctx, &filter)
+ if err != nil {
+ log.Printf("error retrieving monthly summary from DB: %+v", err)
+ c.Header("HX-Redirect", "/500")
+ return nil, err
+ }
+
+ return summary, nil
+}
+
+func analysisDashboardPage(c *gin.Context) {
+ c.HTML(http.StatusOK, "terminal", gin.H{
+ "page": "analysis-filtered",
+ "renderNavBar": true,
+ "content": "analysis-filtered",
+ })
+}
+
+func analysisDashboardPagePartial(c *gin.Context) {
+ c.HTML(http.StatusOK, "analysis-filtered", gin.H{
+ // "plotData": data,
+ })
+}
+
+func analysisDashboardQuery(c *gin.Context) {
+ data, err := getSummaryData(c)
+ if err != nil {
+ log.Printf("error: %+v", err)
+ ServerErrorView(c, "failed to compile analysis data")
+ return
+ }
+
+ c.HTML(http.StatusOK, "analysis-filtered-results", data)
+}
+
+// RouteAnalysis routes the endpoints for analysis stuff.
+func RouteAnalysisDashboard(router *gin.RouterGroup) {
+ router.GET("/filtered-analysis", analysisDashboardPage)
+ router.GET("/filtered-analysis/filters", analysisDashboardQuery)
+ router.POST("/filtered-analysis", analysisDashboardPagePartial)
+}
diff --git a/src/pgImage/.gitignore b/src/pgImage/.gitignore
deleted file mode 100644
index cad00c8..0000000
--- a/src/pgImage/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-schema.sql
-.env
-pgsql-data-dev/
-pgSocket/
diff --git a/src/pgImage/Dockerfile b/src/pgImage/Dockerfile
deleted file mode 100644
index 275a1f1..0000000
--- a/src/pgImage/Dockerfile
+++ /dev/null
@@ -1,33 +0,0 @@
-FROM dir.esilva.org/esilva/esilva-alpine:v1.0.0
-
-
-# Required ENV variables for pg
-ENV LANG=en_GB.utf8
-
-
-# Downloads the required packages for the webserver
-RUN apk --no-cache add su-exec zsh \
- postgresql16 \
- && rm -rf /tmp/*
-
-
-# Directory for the pg socket
-RUN mkdir -p /run/postgresql && \
- chown -R $UNAME:$UNAME /run/postgresql
-RUN mkdir -p /var/lib/postgresql/data && \
- chown -R $UNAME:$UNAME /var/lib/postgresql
-
-
-COPY ./schema.sql /schema.sql
-
-
-# Expose the pgsql port
-EXPOSE 5431
-
-
-# Copies the start script
-COPY ./start.sh /start.sh
-COPY ./healthcheck.sh /healthcheck.sh
-USER $UNAME
-STOPSIGNAL SIGTERM
-ENTRYPOINT [ "/start.sh" ]
diff --git a/src/pgImage/Makefile b/src/pgImage/Makefile
deleted file mode 100644
index c61110f..0000000
--- a/src/pgImage/Makefile
+++ /dev/null
@@ -1,38 +0,0 @@
-include ../vars.mk
-service = expenses-pgdb
-image = $(service)
-container = $(image)-container
-
-.PHONY: clean attach-test test
-
-clean:
- @docker image inspect $(image) > /dev/null 2>&1 && \
- docker image rm $(image) || true
-
-build:
- cp ../expenses/repo/pgdb/schema.sql .
- docker buildx build \
- -t $(registry)/$(repo)/expensesdb:$(tag) .
-
-push_image:
- docker push $(registry)/$(repo)/expensesdb:$(tag)
-
-attach:
- docker exec -it $(container) zsh
-
-attach-test:
- docker exec -it $(container)-dev zsh
-
-remove-dev-container:
- docker container rm $(container)-dev --force > /dev/null 2>&1
-
-test: remove-dev-container
- docker run -p 5431:5432 \
- --name $(container)-dev \
- --env-file .env \
- -v ./pgsql-data-dev/:/var/lib/postgresql/data/ \
- -v ./pgSocket:/run/postgresql \
- -it $(registry)/$(repo)/expensesdb:v0.0.91-alpha
-
-build_image:
- make -C ./
diff --git a/src/pgImage/README.md b/src/pgImage/README.md
deleted file mode 100644
index 98596f1..0000000
--- a/src/pgImage/README.md
+++ /dev/null
@@ -1,9 +0,0 @@
-# README
-
-Requires a `.env` file with the following fields:
-```
-PGDATA=
-ExpDB_USER=
-ExpDB_PASS=
-ExpDB_NAME=
-```
diff --git a/src/pgImage/expenses_pg_2025-09-06_00:16:43.bak b/src/pgImage/expenses_pg_2025-09-06_00:16:43.bak
deleted file mode 100644
index 69f7052..0000000
--- a/src/pgImage/expenses_pg_2025-09-06_00:16:43.bak
+++ /dev/null
@@ -1,1043 +0,0 @@
---
--- PostgreSQL database dump
---
-
-\restrict YD6WOUPNPjmsw55mlY0y3tJ8W2L6YjUXHMPUkdckfUq4elWGHIrGHkeyf7x1D0N
-
--- Dumped from database version 16.10
--- Dumped by pg_dump version 16.10
-
-SET statement_timeout = 0;
-SET lock_timeout = 0;
-SET idle_in_transaction_session_timeout = 0;
-SET client_encoding = 'UTF8';
-SET standard_conforming_strings = on;
-SELECT pg_catalog.set_config('search_path', '', false);
-SET check_function_bodies = false;
-SET xmloption = content;
-SET client_min_messages = warning;
-SET row_security = off;
-
---
--- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: expdbuser
---
-
-COPY public.categories ("CategoryID", "CategoryName") FROM stdin;
-0 No Category
-1 Forester
-2 Starlet
-3 Restaurant
-4 Tools
-5 Hardware
-6 Recibo
-7 Finanças
-8 Casa
-9 Karting
-10 3DP
-11 Server
-12 Renda
-13 Groceries
-14 Electricity
-15 Simracing
-16 Internet
-17 Hotels
-18 Entretenimento
-19 Investements
-20 Prenda
-21 Tap Water
-22 Office
-25 Health
-\.
-
-
---
--- Data for Name: expenseTypes; Type: TABLE DATA; Schema: public; Owner: expdbuser
---
-
-COPY public."expenseTypes" ("TypeID", "TypeName") FROM stdin;
-0 Despesa
-1 Salário
-2 Cartão Refeição
-3 Reembolso
-4 Prenda
-5 Investment
-\.
-
-
---
--- Data for Name: stores; Type: TABLE DATA; Schema: public; Owner: expdbuser
---
-
-COPY public.stores ("StoreID", "StoreName") FROM stdin;
-0 No Store
-1 Velocix
-2 Estado
-3 Borges e Almeida
-4 Kartódromo Viana
-5 Cabo do Mundo
-6 Kartcenter Matosinhos
-7 Decathlon
-8 Landlord
-9 Nortenha
-10 Via Verde
-11 Galp
-12 Endesa
-13 Evolt
-14 iRacing
-15 UZO
-16 Aliexpress
-17 Sportzone
-18 OLX
-19 Norauto
-20 Prio
-21 BP
-22 Cinemax
-23 Degiro
-24 Leroy Merlin
-25 About You
-26 BK
-27 Pasta e Basta
-28 Penafiel Verde
-29 Continente
-30 Mercadona
-31 Auto Irmãos Ferreira
-32 Note
-33 Subarak
-34 Escape6
-35 Tranquilidade
-36 LIDL
-37 OZ Energia
-38 Q8
-39 Prio
-40 La Trattoria Di
-41 IKEA
-42 Hugo Atlantis
-43 Wells
-44 Gumroad
-45 Inovpeças
-\.
-
-
---
--- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: expdbuser
---
-
-COPY public.users ("UserID", "UserName", "UserPass") FROM stdin;
-1 esilva $2y$10$P1sAIsnyD6byXzwPaXay9uP8Rmddz9BQkjl0fiEDHSktzj4ATyrfK
-2 kika $2y$10$P1sAIsnyD6byXzwPaXay9uP8Rmddz9BQkjl0fiEDHSktzj4ATyrfK
-\.
-
-
---
--- Data for Name: expenses; Type: TABLE DATA; Schema: public; Owner: expdbuser
---
-
-COPY public.expenses ("ExpID", "Description", "Value", "StoreID", "CategoryID", "OwnerUserID", "TypeID", "ExpDate", "CreationDate", "PaidOff", "SharesEven") FROM stdin;
-1 Oil 93.47 0 0 1 0 2025-01-02 00:00:00 2025-07-21 00:00:00 t t
-2 Karting 32.00 5 9 1 0 2025-01-02 00:00:00 2025-07-21 00:00:00 t t
-3 Dinner 9.98 26 3 1 0 2025-01-02 00:00:00 2025-07-21 00:00:00 t t
-4 LPG 40.43 0 1 1 0 2025-01-02 00:00:00 2025-07-21 00:00:00 t t
-5 Anti-Fog 11.00 0 9 1 0 2025-01-02 00:00:00 2025-07-21 00:00:00 t t
-6 Decathlon 5.90 0 0 1 0 2025-01-03 00:00:00 2025-07-21 00:00:00 t t
-7 Casaco Impermeável 19.99 17 9 1 0 2025-01-03 00:00:00 2025-07-21 00:00:00 t t
-8 Water 14.00 0 13 1 0 2025-01-04 00:00:00 2025-07-21 00:00:00 t t
-9 Lunch 12.62 0 3 1 0 2025-01-04 00:00:00 2025-07-21 00:00:00 t t
-10 GoPro 230.00 18 9 1 0 2025-01-04 00:00:00 2025-07-21 00:00:00 t t
-11 LPG 45.39 0 1 1 0 2025-01-09 00:00:00 2025-07-21 00:00:00 t t
-12 Groceries 197.99 0 13 1 0 2025-01-10 00:00:00 2025-07-21 00:00:00 t t
-13 Internet Janeiro 2025 35.00 15 16 1 0 2025-01-10 00:00:00 2025-07-21 00:00:00 t t
-14 Karting 32.00 5 9 1 0 2025-01-12 00:00:00 2025-07-21 00:00:00 t t
-15 Petrol 64.45 0 0 1 0 2025-01-12 00:00:00 2025-07-21 00:00:00 t t
-16 AutoDetailing 163.08 0 0 1 0 2025-01-16 00:00:00 2025-07-21 00:00:00 t t
-17 Parking 10.50 0 0 1 0 2025-01-21 00:00:00 2025-07-21 00:00:00 t t
-18 Luz Janeiro 2025 133.15 12 14 1 0 2025-01-22 00:00:00 2025-07-21 00:00:00 t t
-19 Forester 9.84 0 0 1 0 2025-01-22 00:00:00 2025-07-21 00:00:00 t t
-20 LPG 38.72 0 1 1 0 2025-01-22 00:00:00 2025-07-21 00:00:00 t t
-21 Parking 7.20 0 0 1 0 2025-01-23 00:00:00 2025-07-21 00:00:00 t t
-22 Hardware 5.52 0 0 1 0 2025-01-23 00:00:00 2025-07-21 00:00:00 t t
-23 Forester 7.95 0 0 1 0 2025-01-23 00:00:00 2025-07-21 00:00:00 t t
-24 Renda Janeiro 2025 450.00 8 12 1 0 2025-01-24 00:00:00 2025-07-21 00:00:00 t t
-25 Parking 10.50 0 0 1 0 2025-01-27 00:00:00 2025-07-21 00:00:00 t t
-26 Petrol 73.38 0 0 1 0 2025-01-27 00:00:00 2025-07-21 00:00:00 t t
-27 Hotel SKO 2025 14.00 0 17 1 0 2025-01-28 00:00:00 2025-07-21 00:00:00 t t
-28 LPG 41.31 0 1 1 0 2025-01-28 00:00:00 2025-07-21 00:00:00 t t
-29 Salary 1769.64 1 6 1 1 2025-01-29 00:00:00 2025-07-21 00:00:00 t t
-30 Parking 15.00 0 0 1 0 2025-01-29 00:00:00 2025-07-21 00:00:00 t t
-31 LPG 45.40 0 1 1 0 2025-01-29 00:00:00 2025-07-21 00:00:00 t t
-32 Dinner 20.49 0 0 1 0 2025-01-29 00:00:00 2025-07-21 00:00:00 t t
-33 Cartão Refeição 165.00 1 6 1 2 2025-01-29 00:00:00 2025-07-21 00:00:00 t t
-34 Calças/casaco impermeável 38.50 7 9 1 0 2025-01-31 00:00:00 2025-07-21 00:00:00 t t
-35 Forester 32.73 0 0 1 0 2025-01-31 00:00:00 2025-07-21 00:00:00 t t
-36 Forester 49.20 0 0 1 0 2025-01-31 00:00:00 2025-07-21 00:00:00 t t
-37 Petrol 59.09 0 0 1 0 2025-01-31 00:00:00 2025-07-21 00:00:00 t t
-38 Legal 50.00 0 0 1 0 2025-01-31 00:00:00 2025-07-21 00:00:00 t t
-39 Breakfast 6.00 0 0 1 0 2025-01-31 00:00:00 2025-07-21 00:00:00 t t
-40 ViaVerde 44.25 0 0 1 0 2025-01-31 00:00:00 2025-07-21 00:00:00 t t
-41 Ikea 12.98 0 0 1 0 2025-02-01 00:00:00 2025-07-21 00:00:00 t t
-42 Lunch 18.20 0 0 1 0 2025-02-01 00:00:00 2025-07-21 00:00:00 t t
-43 Karting 25.00 0 0 1 0 2025-02-01 00:00:00 2025-07-21 00:00:00 t t
-44 Water 17.51 0 0 1 0 2025-02-04 00:00:00 2025-07-21 00:00:00 t t
-45 Forester 316.45 0 0 1 0 2025-02-05 00:00:00 2025-07-21 00:00:00 t t
-46 Groceries 232.55 0 0 1 0 2025-02-05 00:00:00 2025-07-21 00:00:00 t t
-47 Dinner 9.98 0 0 1 0 2025-02-06 00:00:00 2025-07-21 00:00:00 t t
-48 Forester 68.57 0 0 1 0 2025-02-06 00:00:00 2025-07-21 00:00:00 t t
-49 Karting 49.00 0 0 1 0 2025-02-08 00:00:00 2025-07-21 00:00:00 t t
-50 Lunch 31.00 0 0 1 0 2025-02-08 00:00:00 2025-07-21 00:00:00 t t
-51 Tools 14.99 0 0 1 0 2025-02-10 00:00:00 2025-07-21 00:00:00 t t
-52 Hardware 21.07 0 0 1 0 2025-02-10 00:00:00 2025-07-21 00:00:00 t t
-53 Petrol 84.66 0 0 1 0 2025-02-10 00:00:00 2025-07-21 00:00:00 t t
-54 Tools 5.00 0 0 1 0 2025-02-12 00:00:00 2025-07-21 00:00:00 t t
-55 Hardawre 27.95 0 0 1 0 2025-02-12 00:00:00 2025-07-21 00:00:00 t t
-56 Hardaware 7.95 0 0 1 0 2025-02-13 00:00:00 2025-07-21 00:00:00 t t
-57 Karting 50.00 0 0 1 0 2025-02-14 00:00:00 2025-07-21 00:00:00 t t
-58 Tools 136.97 0 0 1 0 2025-02-14 00:00:00 2025-07-21 00:00:00 t t
-59 Hardware 17.85 0 0 1 0 2025-02-16 00:00:00 2025-07-21 00:00:00 t t
-60 Hardware 36.90 0 0 1 0 2025-02-17 00:00:00 2025-07-21 00:00:00 t t
-61 Renda Fevereiro 2025 450.00 8 12 1 0 2025-02-18 00:00:00 2025-07-21 00:00:00 t t
-62 Forester 104.00 0 0 1 0 2025-02-19 00:00:00 2025-07-21 00:00:00 t t
-63 Starlet 63.55 0 0 1 0 2025-02-20 00:00:00 2025-07-21 00:00:00 t t
-64 Hardware 19.95 0 0 1 0 2025-02-20 00:00:00 2025-07-21 00:00:00 t t
-65 Brake Fluid 17.97 0 0 1 0 2025-02-20 00:00:00 2025-07-21 00:00:00 t t
-66 Endesa 148.05 12 14 1 0 2025-02-21 00:00:00 2025-07-21 00:00:00 t t
-67 Tools 23.43 0 0 1 0 2025-02-21 00:00:00 2025-07-21 00:00:00 t t
-68 Karting 32.00 0 0 1 0 2025-02-22 00:00:00 2025-07-21 00:00:00 t t
-69 Petrol 57.23 0 0 1 0 2025-02-22 00:00:00 2025-07-21 00:00:00 t t
-70 Dinner 70.70 0 0 1 0 2025-02-25 00:00:00 2025-07-21 00:00:00 t t
-71 Salary 1867.06 1 6 1 1 2025-02-27 00:00:00 2025-07-21 00:00:00 t t
-72 Cartão Refeição 150.00 1 6 1 2 2025-02-27 00:00:00 2025-07-21 00:00:00 t t
-73 Parking 8.40 0 0 1 0 2025-02-28 00:00:00 2025-07-21 00:00:00 t t
-74 ViaVerde 28.65 0 0 1 0 2025-02-28 00:00:00 2025-07-21 00:00:00 t t
-75 Petrol 73.00 0 1 1 0 2025-03-01 00:00:00 2025-07-21 00:00:00 t t
-76 Lunch 12.62 0 0 1 0 2025-03-01 00:00:00 2025-07-21 00:00:00 t t
-77 Endesa 78.90 12 14 1 0 2025-03-03 00:00:00 2025-07-21 00:00:00 t t
-78 Groceries 233.00 0 0 1 0 2025-03-05 00:00:00 2025-07-21 00:00:00 t t
-79 Water 14.60 0 0 1 0 2025-03-05 00:00:00 2025-07-21 00:00:00 t t
-80 Forester 70.00 0 0 1 0 2025-03-07 00:00:00 2025-07-21 00:00:00 t t
-81 Breakfast 5.70 0 0 1 0 2025-03-07 00:00:00 2025-07-21 00:00:00 t t
-82 iRacing 39.64 0 0 1 0 2025-03-12 00:00:00 2025-07-21 00:00:00 t t
-83 Internet 35.00 15 16 1 0 2025-03-12 00:00:00 2025-07-21 00:00:00 t t
-84 Petrol 30.47 0 0 1 0 2025-03-15 00:00:00 2025-07-21 00:00:00 t t
-85 Lunch 15.75 0 0 1 0 2025-03-15 00:00:00 2025-07-21 00:00:00 t t
-86 Karting 40.00 0 0 1 0 2025-03-16 00:00:00 2025-07-21 00:00:00 t t
-87 Starletu 29.85 0 0 1 0 2025-03-16 00:00:00 2025-07-21 00:00:00 t t
-88 Petrol 47.12 0 0 1 0 2025-03-16 00:00:00 2025-07-21 00:00:00 t t
-89 Starlet 10.00 0 0 1 0 2025-03-20 00:00:00 2025-07-21 00:00:00 t t
-90 Starlet 81.01 0 0 1 0 2025-03-20 00:00:00 2025-07-21 00:00:00 t t
-91 Galp 31.10 0 0 1 0 2025-03-21 00:00:00 2025-07-21 00:00:00 t t
-92 Rent 450.00 0 0 1 0 2025-03-21 00:00:00 2025-07-21 00:00:00 t t
-93 Starlet 105.74 0 0 1 0 2025-03-24 00:00:00 2025-07-21 00:00:00 t t
-94 Karting 50.00 0 0 1 0 2025-03-24 00:00:00 2025-07-21 00:00:00 t t
-95 Lunch 15.75 0 0 1 0 2025-03-27 00:00:00 2025-07-21 00:00:00 t t
-96 Cartão Refeição 157.50 1 0 1 2 2025-03-27 00:00:00 2025-07-21 00:00:00 t t
-97 Salary 3077.19 1 6 1 1 2025-03-28 00:00:00 2025-07-21 00:00:00 t t
-98 Hardware 67.50 0 0 1 0 2025-03-29 00:00:00 2025-07-21 00:00:00 t t
-99 Lunch 10.98 0 0 1 0 2025-03-29 00:00:00 2025-07-21 00:00:00 t t
-100 Starlet 145.00 0 0 1 0 2025-03-29 00:00:00 2025-07-21 00:00:00 t t
-101 Karting 40.00 0 0 1 0 2025-03-30 00:00:00 2025-07-21 00:00:00 t t
-102 Petrol 40.95 0 0 1 0 2025-03-30 00:00:00 2025-07-21 00:00:00 t t
-103 ViaVerde 31.99 0 0 1 0 2025-03-31 00:00:00 2025-07-21 00:00:00 t t
-104 Groceries 245.97 0 0 1 0 2025-04-02 00:00:00 2025-07-21 00:00:00 t t
-105 Hardware 27.00 0 0 1 0 2025-04-03 00:00:00 2025-07-21 00:00:00 t t
-106 Water 12.90 0 0 1 0 2025-04-03 00:00:00 2025-07-21 00:00:00 t t
-107 Petrol 26.30 0 0 1 0 2025-04-04 00:00:00 2025-07-21 00:00:00 t t
-108 Lunch 34.00 0 0 1 0 2025-04-05 00:00:00 2025-07-21 00:00:00 t t
-109 Glasses 199.00 0 0 1 0 2025-04-08 00:00:00 2025-07-21 00:00:00 t t
-110 Petrol 43.70 0 0 1 0 2025-04-13 00:00:00 2025-07-21 00:00:00 t t
-111 IRS 1370.64 2 7 1 3 2025-04-14 00:00:00 2025-07-21 00:00:00 t t
-112 Battery 34.75 0 0 1 0 2025-04-14 00:00:00 2025-07-21 00:00:00 t t
-113 Dinner 11.82 0 3 1 0 2025-04-14 00:00:00 2025-07-21 00:00:00 t t
-114 Karting 32.00 0 0 1 0 2025-04-16 00:00:00 2025-07-21 00:00:00 t t
-115 Karting 50.00 0 0 1 0 2025-04-17 00:00:00 2025-07-21 00:00:00 t t
-116 Parking 24.90 0 0 1 0 2025-04-17 00:00:00 2025-07-21 00:00:00 t t
-117 Petrol 46.64 0 0 1 0 2025-04-19 00:00:00 2025-07-21 00:00:00 t t
-118 Galp 96.89 0 0 1 0 2025-04-21 00:00:00 2025-07-21 00:00:00 t t
-119 Pharmacy 9.94 0 0 1 0 2025-04-23 00:00:00 2025-07-21 00:00:00 t t
-120 Rent 480.00 0 0 1 0 2025-04-24 00:00:00 2025-07-21 00:00:00 t t
-121 Karting 50.00 0 0 1 0 2025-04-24 00:00:00 2025-07-21 00:00:00 t t
-122 Groceries 17.06 0 0 1 0 2025-04-24 00:00:00 2025-07-21 00:00:00 t t
-123 Office Supplies 75.20 0 0 1 0 2025-04-24 00:00:00 2025-07-21 00:00:00 t t
-124 Lunch 13.90 0 0 1 0 2025-04-25 00:00:00 2025-07-21 00:00:00 t t
-125 Petrol 48.06 0 0 1 0 2025-04-29 00:00:00 2025-07-21 00:00:00 t t
-126 Salary 1710.81 1 6 1 1 2025-04-29 00:00:00 2025-07-21 00:00:00 t t
-127 Cartão Refeição 150.00 1 6 1 2 2025-04-29 00:00:00 2025-07-21 00:00:00 t t
-128 Starlet 36.64 0 0 1 0 2025-04-30 00:00:00 2025-07-21 00:00:00 t t
-129 Groceries 122.99 0 0 1 0 2025-04-30 00:00:00 2025-07-21 00:00:00 t t
-130 ViaVerde 31.69 0 0 1 0 2025-04-30 00:00:00 2025-07-21 00:00:00 t t
-131 Reimbursment – Kika 398.63 0 8 1 3 2025-05-01 00:00:00 2025-07-21 00:00:00 t t
-132 Fidelidade 357.75 0 0 1 0 2025-05-02 00:00:00 2025-07-21 00:00:00 t t
-133 UAB 162.50 0 0 1 0 2025-05-05 00:00:00 2025-07-21 00:00:00 t t
-134 PTServidor 12.00 0 0 1 0 2025-05-12 00:00:00 2025-07-21 00:00:00 t t
-135 Internet Maio 2025 23.76 15 16 1 0 2025-05-14 00:00:00 2025-07-21 00:00:00 t t
-136 Water 15.94 0 0 1 0 2025-05-15 00:00:00 2025-07-21 00:00:00 t t
-137 Petrol 43.74 0 0 1 0 2025-05-15 00:00:00 2025-07-21 00:00:00 t t
-138 karting 40.00 0 0 1 0 2025-05-16 00:00:00 2025-07-21 00:00:00 t t
-139 Petrol 45.25 0 0 1 0 2025-05-17 00:00:00 2025-07-21 00:00:00 t t
-140 Festa da Terra 10.00 0 0 1 0 2025-05-19 00:00:00 2025-07-21 00:00:00 t t
-141 Rent 480.00 0 0 1 0 2025-05-20 00:00:00 2025-07-21 00:00:00 t t
-142 Galp 87.65 0 0 1 0 2025-05-20 00:00:00 2025-07-21 00:00:00 t t
-143 Server 118.49 0 0 1 0 2025-05-20 00:00:00 2025-07-21 00:00:00 t t
-144 Groceries 4.77 0 0 1 0 2025-05-22 00:00:00 2025-07-21 00:00:00 t t
-145 Groceries 11.08 0 0 1 0 2025-05-24 00:00:00 2025-07-21 00:00:00 t t
-146 IUC 12.55 2 2 1 0 2025-05-26 00:00:00 2025-07-21 00:00:00 t t
-147 Filamentos 53.43 13 10 1 0 2025-05-26 00:00:00 2025-07-21 00:00:00 t t
-148 Salary 1832.91 1 6 1 1 2025-05-29 00:00:00 2025-07-21 00:00:00 t t
-149 Cartão Refeição 157.50 1 6 1 2 2025-05-30 00:00:00 2025-07-21 00:00:00 t t
-150 ViaVerde 40.33 0 0 1 0 2025-05-31 00:00:00 2025-07-21 00:00:00 t t
-151 iRacing - Car 13.00 14 15 1 0 2025-06-01 00:00:00 2025-07-21 00:00:00 t t
-152 Reimbursment – Kika 641.11 0 8 1 3 2025-06-02 00:00:00 2025-07-21 00:00:00 t t
-153 Server 388.82 0 0 1 0 2025-06-02 00:00:00 2025-07-21 00:00:00 t t
-154 Petrol 40.96 0 0 1 0 2025-06-02 00:00:00 2025-07-21 00:00:00 t t
-155 Groceries 20.52 0 0 1 0 2025-06-03 00:00:00 2025-07-21 00:00:00 t t
-156 Karting - CMC 50.00 5 9 1 0 2025-06-04 00:00:00 2025-07-21 00:00:00 t t
-157 Kitchen 13.00 0 0 1 0 2025-06-04 00:00:00 2025-07-21 00:00:00 t t
-158 Forester 1200.00 0 0 1 0 2025-06-05 00:00:00 2025-07-21 00:00:00 t t
-159 Domain 22.90 0 11 1 0 2025-06-07 00:00:00 2025-07-21 00:00:00 t t
-160 Hostinger 129.56 0 11 1 0 2025-06-07 00:00:00 2025-07-21 00:00:00 t t
-161 Petrol 47.78 0 0 1 0 2025-06-07 00:00:00 2025-07-21 00:00:00 t t
-162 Water 14.60 0 0 1 0 2025-06-10 00:00:00 2025-07-21 00:00:00 t t
-163 Internet Junho 2025 23.00 15 16 1 0 2025-06-11 00:00:00 2025-07-21 00:00:00 t t
-164 Mobo Z370M Servidor 76.14 16 11 1 0 2025-06-16 00:00:00 2025-07-21 00:00:00 t t
-165 Luz Junho 2025 68.26 11 14 1 0 2025-06-23 00:00:00 2025-07-21 00:00:00 t t
-166 Renda Junho 2025 480.00 8 12 1 0 2025-06-25 00:00:00 2025-07-21 00:00:00 t t
-167 Petrol 31.36 0 2 1 0 2025-06-25 00:00:00 2025-07-21 00:00:00 t t
-168 Salário Jun 2025 1710.81 1 6 1 1 2025-06-27 00:00:00 2025-07-21 00:00:00 t t
-169 Cartão Refeição 135.00 1 6 1 2 2025-06-27 00:00:00 2025-07-21 00:00:00 t t
-170 Petrol 34.56 0 2 1 0 2025-06-30 00:00:00 2025-07-21 00:00:00 t t
-171 Petrol 47.50 0 2 1 0 2025-07-01 00:00:00 2025-07-21 00:00:00 t t
-172 Starlet 20.00 0 0 1 0 2025-07-01 00:00:00 2025-07-21 00:00:00 t t
-173 Petrol 78.95 0 1 1 0 2025-07-02 00:00:00 2025-07-21 00:00:00 t t
-174 Forester 1300.00 3 1 1 0 2025-07-02 00:00:00 2025-07-21 00:00:00 t t
-175 Starlet Problemas Ignição 120.00 3 2 1 0 2025-07-02 00:00:00 2025-07-21 00:00:00 t t
-176 Forester 729.51 9 1 1 0 2025-07-02 00:00:00 2025-07-21 00:00:00 t t
-178 Reimbursment – Kika 989.95 0 8 1 3 2025-07-03 00:00:00 2025-07-21 00:00:00 t t
-179 Dinner 19.60 0 3 1 0 2025-07-03 00:00:00 2025-07-21 00:00:00 t t
-180 Água Junho 2025 16.82 28 21 1 0 2025-07-07 00:00:00 2025-07-21 00:00:00 t t
-181 Renda Julho 2025 480.00 8 12 1 0 2025-07-10 00:00:00 2025-07-21 00:00:00 t t
-182 Petrol 86.38 0 1 1 0 2025-07-08 00:00:00 2025-07-21 00:00:00 t t
-183 Dinner 16.00 0 3 1 0 2025-07-10 00:00:00 2025-07-21 00:00:00 t t
-184 Forester 94.88 33 1 1 0 2025-07-11 00:00:00 2025-07-21 00:00:00 t t
-185 Forester 57.47 34 1 1 0 2025-07-12 00:00:00 2025-07-21 00:00:00 t t
-186 Medidor Pressão Pneus 14.99 19 4 1 0 2025-07-19 00:00:00 1970-01-01 00:00:00 t t
-187 Petrol Forester 80.00 20 1 1 0 2025-07-17 00:00:00 1970-01-01 00:00:00 t t
-188 Petrol Forester 81.16 21 1 1 0 2025-07-14 00:00:00 1970-01-01 00:00:00 t t
-189 Snacks e Molas 13.75 0 8 1 0 2025-07-12 00:00:00 1970-01-01 00:00:00 t t
-190 Cinema - F1 22.55 22 18 1 0 2025-07-17 00:00:00 1970-01-01 00:00:00 t t
-191 ETF 391.00 23 19 1 5 2025-07-15 00:00:00 1970-01-01 00:00:00 t t
-192 Peças Mangueira 7.49 24 5 1 0 2025-07-14 00:00:00 1970-01-01 00:00:00 t t
-193 Sapatos Castanhos Kika 89.90 25 20 1 0 2025-07-12 00:00:00 1970-01-01 00:00:00 t t
-194 Pizza 13.50 27 3 1 0 2025-07-19 00:00:00 1970-01-01 00:00:00 t t
-195 Lunch 19.94 26 3 1 0 2025-07-19 00:00:00 1970-01-01 00:00:00 t t
-196 Continente 97.08 29 13 1 0 2025-07-02 00:00:00 1970-01-01 00:00:00 t t
-197 Mercadona 141.94 30 13 1 0 2025-07-02 00:00:00 1970-01-01 00:00:00 t t
-198 Revisão LPG Forester 125.56 31 1 1 0 2025-07-23 00:00:00 2025-07-23 00:00:00 t t
-199 LGP Forester 33.89 31 1 1 0 2025-07-23 00:00:00 2025-07-23 00:00:00 t t
-200 Groceries 19.38 29 13 1 0 2025-07-23 00:00:00 2025-07-25 00:00:00 t t
-201 Notebook 11.88 32 22 1 0 2025-07-24 00:00:00 2025-07-25 00:00:00 t t
-202 Cooling Sys Stuff 76.77 3 2 1 0 2025-07-18 00:00:00 2025-07-25 00:00:00 t t
-203 Seguro Starlet 81.47 35 2 1 0 2025-07-16 00:00:00 2025-07-25 00:00:00 t t
-204 Prenda Avó 10.00 0 20 1 4 2025-07-24 00:00:00 2025-07-25 00:00:00 t t
-205 Prenda Mãe 60.00 0 20 1 4 2025-07-24 00:00:00 2025-07-25 00:00:00 t t
-206 Internet Julho 2025 23.00 15 16 1 0 2025-07-09 00:00:00 2025-07-25 00:00:00 t t
-207 Luz Julho 2025 79.87 11 14 1 0 2025-07-21 00:00:00 2025-07-25 00:00:00 t t
-209 Salário Jul 2025 3410.62 0 6 1 1 2025-07-30 00:00:00 2025-07-30 00:00:00 t t
-210 CRefeição Jul 2025 172.25 0 6 1 2 2025-07-30 00:00:00 2025-07-30 00:00:00 f f
-211 Groceries Mercadona 119.45 30 13 1 0 2025-07-31 00:00:00 2025-07-31 00:00:00 t t
-212 Groceries Continente 121.81 29 13 1 0 2025-07-31 00:00:00 2025-07-31 00:00:00 t t
-213 Reimb. - Torres Vedras 91.35 0 0 1 3 2025-07-31 00:00:00 2025-07-31 00:00:00 t t
-214 iRacing - Porsche GT3 12.77 14 15 1 0 2025-07-30 00:00:00 2025-08-01 00:00:00 t t
-215 ETF 2175.00 23 19 1 5 2025-07-30 00:00:00 2025-08-01 00:00:00 t t
-216 ETF 1000.00 23 19 1 5 2025-08-01 00:00:00 2025-08-01 00:00:00 t t
-217 Alicates 51.45 36 4 1 0 2025-07-31 00:00:00 2025-08-01 00:00:00 t t
-218 Petrol 50.00 39 1 1 0 2025-07-29 00:00:00 2025-08-01 00:00:00 t t
-219 LPG 34.93 37 1 1 0 2025-07-29 00:00:00 2025-08-01 00:00:00 t t
-220 Dinner AMI 16.60 40 3 1 0 2025-08-07 00:00:00 2025-08-08 00:00:00 t t
-221 Internet Aug 2025 23.00 15 16 1 0 2025-08-08 00:00:00 2025-08-08 00:00:00 t t
-222 Armário Escritório 260.00 41 8 1 0 2025-08-05 00:00:00 2025-08-08 00:00:00 t t
-223 LPG Fozzie 30.08 37 1 1 0 2025-08-07 00:00:00 2025-08-08 00:00:00 t t
-224 Dinner 14.10 41 3 1 0 2025-08-05 00:00:00 2025-08-08 00:00:00 t t
-225 Água Julho 2025 17.49 28 21 1 0 2025-08-11 00:00:00 2025-08-09 00:00:00 t t
-226 Stereo Starlet 124.00 19 2 1 0 2025-07-29 00:00:00 2025-08-10 00:00:00 t t
-227 Petrol 46.28 39 2 1 0 2025-08-02 00:00:00 2025-08-18 00:00:00 t t
-228 Florester 250.80 42 1 1 0 2025-08-22 00:00:00 2025-08-22 00:00:00 t t
-229 Glasses 108.10 43 25 1 0 2025-08-21 00:00:00 2025-08-22 00:00:00 t t
-230 Dinner AMI 19.85 40 3 1 0 2025-08-21 00:00:00 2025-08-22 00:00:00 t t
-231 Luz Aug 2025 88.91 11 14 1 0 2025-08-18 00:00:00 2025-08-22 00:00:00 t t
-232 Beamng Cars 10.89 44 15 1 0 2025-08-21 00:00:00 2025-08-22 00:00:00 t t
-233 Groceries 34.01 29 13 1 0 2025-08-20 00:00:00 2025-08-22 00:00:00 t t
-234 Rent Aug 2025 480.00 8 12 1 0 2025-08-22 00:00:00 2025-08-22 00:00:00 t t
-235 Óleo DA 12.85 45 1 1 0 2025-08-25 00:00:00 2025-08-27 00:00:00 t t
-236 Salário Aug 2025 1798.81 1 6 1 1 2025-08-28 00:00:00 2025-08-28 00:00:00 t t
-237 CRefeição Aug 2025 150.00 1 6 1 2 2025-08-28 00:00:00 2025-08-28 00:00:00 t t
-238 Degiro ETF 535.00 23 19 1 0 2025-08-29 00:00:00 2025-08-29 00:00:00 t f
-240 Petrol Starlet 46.67 38 2 1 0 2025-08-28 00:00:00 2025-08-31 00:00:00 t f
-241 Dinner AMI 13.00 0 3 1 0 2025-08-28 00:00:00 2025-08-31 00:00:00 t f
-242 Degiro ETF 965.00 23 19 1 0 2025-09-01 00:00:00 2025-09-01 00:00:00 t f
-243 Água Agosto 2025 14.93 28 21 1 0 2025-09-03 00:00:00 2025-09-03 15:05:34.566841 t f
-244 Luz Sep 2025 108.03 11 14 1 0 2025-09-18 00:00:00 2025-09-03 15:18:59.046393 t f
-245 Dinner AMI 13.40 0 3 1 0 2025-09-04 00:00:00 2025-09-05 10:37:35.120408 t f
-\.
-
-
---
--- Data for Name: expensesPayments; Type: TABLE DATA; Schema: public; Owner: expdbuser
---
-
-COPY public."expensesPayments" ("ExpPaymID", "ExpID", "UserID", "Payed") FROM stdin;
-1 1 1 93.47
-2 2 1 32.00
-3 3 1 9.98
-4 4 1 40.43
-5 5 1 11.00
-6 6 1 5.90
-7 7 1 19.99
-8 8 1 7.00
-9 8 2 7.00
-10 9 1 12.62
-11 10 1 230.00
-12 11 1 45.39
-13 12 1 99.00
-14 12 2 98.99
-15 13 1 17.50
-16 13 2 17.50
-17 14 1 32.00
-18 15 1 64.45
-19 16 1 163.08
-20 17 1 10.50
-21 18 1 66.58
-22 18 2 66.57
-23 19 1 9.84
-24 20 1 38.72
-25 21 1 7.20
-26 22 1 5.52
-27 23 1 7.95
-28 24 1 225.00
-29 24 2 225.00
-30 25 1 10.50
-31 26 1 73.38
-32 27 1 14.00
-33 28 1 41.31
-34 29 1 1769.64
-35 30 1 15.00
-36 31 1 45.40
-37 32 1 20.49
-38 33 1 165.00
-39 34 1 38.50
-40 35 1 32.73
-41 36 1 49.20
-42 37 1 59.09
-43 38 1 50.00
-44 39 1 6.00
-45 40 1 44.25
-46 41 1 12.98
-47 42 1 18.20
-48 43 1 25.00
-49 44 1 8.76
-50 44 2 8.75
-51 45 1 316.45
-52 46 1 116.28
-53 46 2 116.27
-54 47 1 9.98
-55 48 1 68.57
-56 49 1 49.00
-57 50 1 31.00
-58 51 1 14.99
-59 52 1 21.07
-60 53 1 84.66
-61 54 1 5.00
-62 55 1 27.95
-63 56 1 7.95
-64 57 1 50.00
-65 58 1 136.97
-66 59 1 17.85
-67 60 1 36.90
-68 61 1 225.00
-69 61 2 225.00
-70 62 1 104.00
-71 63 1 63.55
-72 64 1 19.95
-73 65 1 17.97
-74 66 1 74.03
-75 66 2 74.02
-76 67 1 23.43
-77 68 1 32.00
-78 69 1 57.23
-79 70 1 70.70
-80 71 1 1867.06
-81 72 1 150.00
-82 73 1 8.40
-83 74 1 28.65
-84 75 1 73.00
-85 76 1 12.62
-86 77 1 39.45
-87 77 2 39.45
-88 78 1 116.50
-89 78 2 116.50
-90 79 1 7.30
-91 79 2 7.30
-92 80 1 70.00
-93 81 1 5.70
-94 82 1 39.64
-95 83 1 17.50
-96 83 2 17.50
-97 84 1 30.47
-98 85 1 15.75
-99 86 1 40.00
-100 87 1 29.85
-101 88 1 47.12
-102 89 1 10.00
-103 90 1 81.01
-104 91 1 15.55
-105 91 2 15.55
-106 92 1 225.00
-107 92 2 225.00
-108 93 1 105.74
-109 94 1 50.00
-110 95 1 15.75
-111 96 1 157.50
-112 97 1 3077.19
-113 98 1 67.50
-114 99 1 10.98
-115 100 1 145.00
-116 101 1 40.00
-117 102 1 40.95
-118 103 1 31.99
-119 104 1 122.99
-120 104 2 122.98
-121 105 1 27.00
-122 106 1 6.45
-123 106 2 6.45
-124 107 1 26.30
-125 108 1 34.00
-126 109 1 199.00
-127 110 1 43.70
-128 111 1 1370.64
-129 112 1 34.75
-130 113 1 11.82
-131 114 1 32.00
-132 115 1 50.00
-133 116 1 24.90
-134 117 1 46.64
-135 118 1 48.45
-136 118 2 48.44
-137 119 1 9.94
-138 120 1 240.00
-139 120 2 240.00
-140 121 1 50.00
-141 122 1 8.53
-142 122 2 8.53
-143 123 1 75.20
-144 124 1 13.90
-145 125 1 48.06
-146 126 1 1710.81
-147 127 1 150.00
-148 128 1 36.64
-149 129 1 61.50
-150 129 2 61.49
-151 130 1 31.69
-152 131 2 398.63
-153 132 1 357.75
-154 133 1 162.50
-155 134 1 12.00
-156 135 1 11.88
-157 135 2 11.88
-158 136 1 7.97
-159 136 2 7.97
-160 137 1 43.74
-161 138 1 40.00
-162 139 1 45.25
-163 140 1 10.00
-164 141 1 240.00
-165 141 2 240.00
-166 142 1 43.83
-167 142 2 43.82
-168 143 1 118.49
-169 144 1 4.77
-170 145 1 11.08
-171 146 1 12.55
-172 147 1 53.43
-173 148 1 1832.91
-174 149 1 157.50
-175 150 1 40.33
-176 151 1 13.00
-177 152 2 641.11
-178 153 1 388.82
-179 154 1 40.96
-180 155 1 10.26
-181 155 2 10.26
-182 156 1 50.00
-183 157 1 13.00
-184 158 1 1200.00
-185 159 1 22.90
-186 160 1 129.56
-187 161 1 47.78
-188 162 1 7.30
-189 162 2 7.30
-190 163 1 11.50
-191 163 2 11.50
-192 164 1 76.14
-193 165 1 34.13
-194 165 2 34.13
-195 166 1 240.00
-196 166 2 240.00
-197 167 1 31.36
-198 168 1 1710.81
-199 169 1 135.00
-200 170 1 34.56
-201 171 1 47.50
-202 172 1 20.00
-203 173 1 78.95
-204 174 1 1300.00
-205 175 1 120.00
-206 176 1 729.51
-209 178 2 989.95
-210 179 1 19.60
-211 180 1 8.41
-212 180 2 8.41
-213 181 1 240.00
-214 181 2 240.00
-215 182 1 86.38
-216 183 1 16.00
-217 184 1 94.88
-218 185 1 57.47
-219 186 1 14.99
-220 187 1 80.00
-221 188 1 81.16
-222 189 1 13.75
-223 190 1 22.55
-224 191 1 391.00
-225 192 1 7.49
-226 193 1 89.90
-227 194 1 13.50
-228 195 1 19.94
-229 196 1 48.54
-230 196 2 48.54
-231 197 1 70.97
-232 197 2 70.97
-233 198 1 125.56
-234 199 1 33.89
-235 200 1 19.38
-236 201 1 11.88
-237 202 1 76.77
-238 203 1 81.47
-239 204 1 10.00
-240 205 1 60.00
-241 206 1 11.50
-242 206 2 11.50
-243 207 1 39.94
-244 207 2 39.93
-246 211 1 59.73
-247 211 2 59.72
-248 212 1 60.91
-249 212 2 60.90
-250 213 2 91.35
-251 214 1 12.77
-252 215 1 2175.00
-253 216 1 1000.00
-254 217 1 51.45
-255 218 1 50.00
-256 219 1 34.93
-257 220 1 16.60
-258 221 1 11.50
-259 221 2 11.50
-260 222 1 130.00
-261 222 2 130.00
-262 223 1 30.08
-263 224 1 14.10
-264 225 1 8.75
-265 225 2 8.74
-266 226 1 124.00
-267 209 1 3410.62
-268 227 1 46.28
-269 228 1 250.80
-270 229 1 108.10
-271 230 1 19.85
-272 231 1 44.46
-273 231 2 44.45
-274 232 1 10.89
-275 233 1 17.01
-276 233 2 17.00
-277 234 1 240.00
-278 234 2 240.00
-279 235 1 12.85
-280 236 1 1798.81
-281 237 1 150.00
-282 238 1 535.00
-284 131 1 0.00
-285 152 1 0.00
-286 178 1 0.00
-287 210 1 0.00
-288 213 1 0.00
-289 240 1 46.67
-290 241 1 13.00
-291 242 1 965.00
-292 243 1 14.93
-293 243 2 0.00
-294 244 1 108.03
-295 244 2 0.00
-296 245 1 13.40
-\.
-
-
---
--- Data for Name: expensesShares; Type: TABLE DATA; Schema: public; Owner: expdbuser
---
-
-COPY public."expensesShares" ("ExpShareID", "ExpID", "UserID", "Share", "Calculated") FROM stdin;
-1 1 1 1.00 93.47
-2 2 1 1.00 32.00
-3 3 1 1.00 9.98
-4 4 1 1.00 40.43
-5 5 1 1.00 11.00
-6 6 1 1.00 5.90
-7 7 1 1.00 19.99
-8 8 1 0.50 7.00
-9 8 2 0.50 7.00
-10 9 1 1.00 12.62
-11 10 1 1.00 230.00
-12 11 1 1.00 45.39
-13 12 1 0.50 99.00
-14 12 2 0.50 98.99
-15 13 1 0.50 17.50
-16 13 2 0.50 17.50
-17 14 1 1.00 32.00
-18 15 1 1.00 64.45
-19 16 1 1.00 163.08
-20 17 1 1.00 10.50
-21 18 1 0.50 66.58
-22 18 2 0.50 66.57
-23 19 1 1.00 9.84
-24 20 1 1.00 38.72
-25 21 1 1.00 7.20
-26 22 1 1.00 5.52
-27 23 1 1.00 7.95
-28 24 1 0.50 225.00
-29 24 2 0.50 225.00
-30 25 1 1.00 10.50
-31 26 1 1.00 73.38
-32 27 1 1.00 14.00
-33 28 1 1.00 41.31
-34 29 1 1.00 1769.64
-35 30 1 1.00 15.00
-36 31 1 1.00 45.40
-37 32 1 1.00 20.49
-38 33 1 1.00 165.00
-39 34 1 1.00 38.50
-40 35 1 1.00 32.73
-41 36 1 1.00 49.20
-42 37 1 1.00 59.09
-43 38 1 1.00 50.00
-44 39 1 1.00 6.00
-45 40 1 1.00 44.25
-46 41 1 1.00 12.98
-47 42 1 1.00 18.20
-48 43 1 1.00 25.00
-49 44 1 0.50 8.76
-50 44 2 0.50 8.75
-51 45 1 1.00 316.45
-52 46 1 0.50 116.28
-53 46 2 0.50 116.27
-54 47 1 1.00 9.98
-55 48 1 1.00 68.57
-56 49 1 1.00 49.00
-57 50 1 1.00 31.00
-58 51 1 1.00 14.99
-59 52 1 1.00 21.07
-60 53 1 1.00 84.66
-61 54 1 1.00 5.00
-62 55 1 1.00 27.95
-63 56 1 1.00 7.95
-64 57 1 1.00 50.00
-65 58 1 1.00 136.97
-66 59 1 1.00 17.85
-67 60 1 1.00 36.90
-68 61 1 0.50 225.00
-69 61 2 0.50 225.00
-70 62 1 1.00 104.00
-71 63 1 1.00 63.55
-72 64 1 1.00 19.95
-73 65 1 1.00 17.97
-74 66 1 0.50 74.03
-75 66 2 0.50 74.02
-76 67 1 1.00 23.43
-77 68 1 1.00 32.00
-78 69 1 1.00 57.23
-79 70 1 1.00 70.70
-80 71 1 1.00 1867.06
-81 72 1 1.00 150.00
-82 73 1 1.00 8.40
-83 74 1 1.00 28.65
-84 75 1 1.00 73.00
-85 76 1 1.00 12.62
-86 77 1 0.50 39.45
-87 77 2 0.50 39.45
-88 78 1 0.50 116.50
-89 78 2 0.50 116.50
-90 79 1 0.50 7.30
-91 79 2 0.50 7.30
-92 80 1 1.00 70.00
-93 81 1 1.00 5.70
-94 82 1 1.00 39.64
-95 83 1 0.50 17.50
-96 83 2 0.50 17.50
-97 84 1 1.00 30.47
-98 85 1 1.00 15.75
-99 86 1 1.00 40.00
-100 87 1 1.00 29.85
-101 88 1 1.00 47.12
-102 89 1 1.00 10.00
-103 90 1 1.00 81.01
-104 91 1 0.50 15.55
-105 91 2 0.50 15.55
-106 92 1 0.50 225.00
-107 92 2 0.50 225.00
-108 93 1 1.00 105.74
-109 94 1 1.00 50.00
-110 95 1 1.00 15.75
-111 96 1 1.00 157.50
-112 97 1 1.00 3077.19
-113 98 1 1.00 67.50
-114 99 1 1.00 10.98
-115 100 1 1.00 145.00
-116 101 1 1.00 40.00
-117 102 1 1.00 40.95
-118 103 1 1.00 31.99
-119 104 1 0.50 122.99
-120 104 2 0.50 122.98
-121 105 1 1.00 27.00
-122 106 1 0.50 6.45
-123 106 2 0.50 6.45
-124 107 1 1.00 26.30
-125 108 1 1.00 34.00
-126 109 1 1.00 199.00
-127 110 1 1.00 43.70
-128 111 1 1.00 1370.64
-129 112 1 1.00 34.75
-130 113 1 1.00 11.82
-131 114 1 1.00 32.00
-132 115 1 1.00 50.00
-133 116 1 1.00 24.90
-134 117 1 1.00 46.64
-135 118 1 0.50 48.45
-136 118 2 0.50 48.44
-137 119 1 1.00 9.94
-138 120 1 0.50 240.00
-139 120 2 0.50 240.00
-140 121 1 1.00 50.00
-141 122 1 0.50 8.53
-142 122 2 0.50 8.53
-143 123 1 1.00 75.20
-144 124 1 1.00 13.90
-145 125 1 1.00 48.06
-146 126 1 1.00 1710.81
-147 127 1 1.00 150.00
-148 128 1 1.00 36.64
-149 129 1 0.50 61.50
-150 129 2 0.50 61.49
-151 130 1 1.00 31.69
-152 131 2 1.00 398.63
-153 132 1 1.00 357.75
-154 133 1 1.00 162.50
-155 134 1 1.00 12.00
-156 135 1 0.50 11.88
-157 135 2 0.50 11.88
-158 136 1 0.50 7.97
-159 136 2 0.50 7.97
-160 137 1 1.00 43.74
-161 138 1 1.00 40.00
-162 139 1 1.00 45.25
-163 140 1 1.00 10.00
-164 141 1 0.50 240.00
-165 141 2 0.50 240.00
-166 142 1 0.50 43.83
-167 142 2 0.50 43.82
-168 143 1 1.00 118.49
-169 144 1 1.00 4.77
-170 145 1 1.00 11.08
-171 146 1 1.00 12.55
-172 147 1 1.00 53.43
-173 148 1 1.00 1832.91
-174 149 1 1.00 157.50
-175 150 1 1.00 40.33
-176 151 1 1.00 13.00
-177 152 2 1.00 641.11
-178 153 1 1.00 388.82
-179 154 1 1.00 40.96
-180 155 1 0.50 10.26
-181 155 2 0.50 10.26
-182 156 1 1.00 50.00
-183 157 1 1.00 13.00
-184 158 1 1.00 1200.00
-185 159 1 1.00 22.90
-186 160 1 1.00 129.56
-187 161 1 1.00 47.78
-188 162 1 0.50 7.30
-189 162 2 0.50 7.30
-190 163 1 0.50 11.50
-191 163 2 0.50 11.50
-192 164 1 1.00 76.14
-193 165 1 0.50 34.13
-194 165 2 0.50 34.13
-195 166 1 0.50 240.00
-196 166 2 0.50 240.00
-197 167 1 1.00 31.36
-198 168 1 1.00 1710.81
-199 169 1 1.00 135.00
-200 170 1 1.00 34.56
-201 171 1 1.00 47.50
-202 172 1 1.00 20.00
-203 173 1 1.00 78.95
-204 174 1 1.00 1300.00
-205 175 1 1.00 120.00
-206 176 1 1.00 729.51
-209 178 2 1.00 989.95
-210 179 1 1.00 19.60
-211 180 1 0.50 8.41
-212 180 2 0.50 8.41
-213 181 1 0.50 240.00
-214 181 2 0.50 240.00
-215 182 1 1.00 86.38
-216 183 1 1.00 16.00
-217 184 1 1.00 94.88
-218 185 1 1.00 57.47
-219 186 1 1.00 14.99
-220 187 1 1.00 80.00
-221 188 1 1.00 81.16
-222 189 1 1.00 13.75
-223 190 1 1.00 22.55
-224 191 1 1.00 391.00
-225 192 1 1.00 7.49
-226 193 1 1.00 89.90
-227 194 1 1.00 13.50
-228 195 1 1.00 19.94
-229 196 1 0.50 48.54
-230 196 2 0.50 48.54
-231 197 1 0.50 70.97
-232 197 2 0.50 70.97
-233 198 1 1.00 125.56
-234 199 1 1.00 33.89
-235 200 1 1.00 19.38
-236 201 1 1.00 11.88
-237 202 1 1.00 76.77
-238 203 1 1.00 81.47
-239 204 1 1.00 10.00
-240 205 1 1.00 60.00
-241 206 1 0.50 11.50
-242 206 2 0.50 11.50
-243 207 1 0.50 39.94
-244 207 2 0.50 39.93
-246 211 1 0.50 59.73
-247 211 2 0.50 59.72
-248 212 1 0.50 60.91
-249 212 2 0.50 60.90
-250 213 2 1.00 91.35
-251 214 1 1.00 12.77
-252 215 1 1.00 2175.00
-253 216 1 1.00 1000.00
-254 217 1 1.00 51.45
-255 218 1 1.00 50.00
-257 219 1 1.00 34.93
-259 220 1 1.00 16.60
-260 221 1 0.50 11.50
-261 221 2 0.50 11.50
-262 222 1 0.50 130.00
-263 222 2 0.50 130.00
-264 223 1 1.00 30.08
-265 224 1 1.00 14.10
-266 225 1 0.50 8.75
-267 225 2 0.50 8.74
-268 226 1 1.00 124.00
-269 209 1 1.00 3410.62
-270 227 1 1.00 46.28
-271 228 1 1.00 250.80
-272 229 1 1.00 108.10
-273 230 1 1.00 19.85
-274 231 1 0.50 44.46
-275 231 2 0.50 44.45
-276 232 1 1.00 10.89
-277 233 1 0.50 17.01
-278 233 2 0.50 17.00
-279 234 1 0.50 240.00
-280 234 2 0.50 240.00
-281 235 1 1.00 12.85
-282 236 1 1.00 1798.81
-283 237 1 1.00 150.00
-284 238 1 1.00 535.00
-286 131 1 0.00 0.00
-287 152 1 0.00 0.00
-288 178 1 0.00 0.00
-289 210 1 0.00 0.00
-290 213 1 0.00 0.00
-291 240 1 1.00 46.67
-292 241 1 1.00 13.00
-293 242 1 1.00 965.00
-294 243 1 0.50 7.47
-295 243 2 0.50 7.46
-296 244 1 0.50 54.02
-297 244 2 0.50 54.01
-298 245 1 1.00 13.40
-\.
-
-
---
--- Data for Name: schema_migrations; Type: TABLE DATA; Schema: public; Owner: expdbuser
---
-
-COPY public.schema_migrations (version, dirty) FROM stdin;
-\.
-
-
---
--- Name: categories_CategoryID_seq; Type: SEQUENCE SET; Schema: public; Owner: expdbuser
---
-
-SELECT pg_catalog.setval('public."categories_CategoryID_seq"', 25, true);
-
-
---
--- Name: expenseTypes_TypeID_seq; Type: SEQUENCE SET; Schema: public; Owner: expdbuser
---
-
-SELECT pg_catalog.setval('public."expenseTypes_TypeID_seq"', 5, true);
-
-
---
--- Name: expensesPayments_ExpPaymID_seq; Type: SEQUENCE SET; Schema: public; Owner: expdbuser
---
-
-SELECT pg_catalog.setval('public."expensesPayments_ExpPaymID_seq"', 296, true);
-
-
---
--- Name: expensesShares_ExpShareID_seq; Type: SEQUENCE SET; Schema: public; Owner: expdbuser
---
-
-SELECT pg_catalog.setval('public."expensesShares_ExpShareID_seq"', 298, true);
-
-
---
--- Name: expenses_ExpID_seq; Type: SEQUENCE SET; Schema: public; Owner: expdbuser
---
-
-SELECT pg_catalog.setval('public."expenses_ExpID_seq"', 245, true);
-
-
---
--- Name: stores_StoreID_seq; Type: SEQUENCE SET; Schema: public; Owner: expdbuser
---
-
-SELECT pg_catalog.setval('public."stores_StoreID_seq"', 45, true);
-
-
---
--- Name: users_UserID_seq; Type: SEQUENCE SET; Schema: public; Owner: expdbuser
---
-
-SELECT pg_catalog.setval('public."users_UserID_seq"', 2, true);
-
-
---
--- PostgreSQL database dump complete
---
-
-\unrestrict YD6WOUPNPjmsw55mlY0y3tJ8W2L6YjUXHMPUkdckfUq4elWGHIrGHkeyf7x1D0N
-
diff --git a/src/pgImage/healthcheck.sh b/src/pgImage/healthcheck.sh
deleted file mode 100755
index 2c292b2..0000000
--- a/src/pgImage/healthcheck.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-set -e
-
-pg_isready -U "$ExpDB_USER" -d "$ExpDB_NAME"
diff --git a/src/pgImage/start.sh b/src/pgImage/start.sh
deleted file mode 100755
index e509645..0000000
--- a/src/pgImage/start.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/sh
-set -e
-
-if [ -z "$(ls -A "$PGDATA")" ]; then
- echo "Creating database with:"
- echo "DIR: $PGDATA"
- echo "USER: $ExpDB_USER"
- echo "PASS: $ExpDB_PASS"
- echo "NAME: $ExpDB_NAME"
- # Initiate PG data directory
- initdb \
- --locale=C.UTF-8 \
- --encoding=UTF8 \
- -D "$PGDATA" \
- --data-checksums \
- --username="$UNAME"
-
- # Set PG to listen on all addresses
- sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
-
- # Start PG to add the NC DB
- pg_ctl -D "$PGDATA" \
- -o "-c listen_addresses=''" \
- -w start
-
- # Create the NC database
- createUser="CREATE USER $ExpDB_USER WITH PASSWORD '$ExpDB_PASS';"
- createDB="CREATE DATABASE $ExpDB_NAME TEMPLATE template0 ENCODING 'UNICODE';"
- alterDB="ALTER DATABASE $ExpDB_NAME OWNER TO $ExpDB_USER;"
- grantPriv="GRANT ALL PRIVILEGES ON DATABASE $ExpDB_NAME TO $ExpDB_USER;"
- psql -d postgres -c "${createUser}"
- psql -d postgres -c "${createDB}"
- psql -d postgres -c "${alterDB}"
- psql -d postgres -c "${grantPriv}"
-
- # Execute the initial schema
- psql -U "$ExpDB_USER" -d "$ExpDB_NAME" -a -f /schema.sql
-
- pg_ctl -D "$PGDATA" -m fast -w stop
-
- { echo; echo "host all all 0.0.0.0/0 md5"; } >> "$PGDATA"/pg_hba.conf
-fi
-
-postgres "$@"