Compare commits

..

16 Commits

Author SHA1 Message Date
e83fb7abb8 Enable scroll through time with mousewheel 2024-08-19 14:40:24 +02:00
3ca12139cd Default display to last month
Since we pay bills for the last month in the current month...
2024-08-19 14:34:47 +02:00
236b113c10 Rename application 2024-08-19 14:03:44 +02:00
4ee622e65e Enable marking as paid 2024-08-19 14:00:35 +02:00
2ac082f230 Add force redraw on navigate 2024-08-19 13:55:10 +02:00
45030f8634 More better displaying 2024-08-19 13:51:00 +02:00
79b89a01e5 Refresh payment stores on time frame change 2024-08-19 13:09:14 +02:00
37a0c52464 Fix scrolling in frame 2024-08-19 13:09:06 +02:00
f018459818 Rework "nowStore" to scrollingTimeFrameStore that contains both from and to dates 2024-08-19 12:45:37 +02:00
c5613ee0cc Make formatting a bit more better
Display dates for months in view
2024-08-19 12:33:26 +02:00
8c10540309 Hook up tailwind to style 2024-08-19 12:08:28 +02:00
f96c0ba8b5 Implement some sort of very basic display 2024-08-19 11:55:38 +02:00
46b50b6bd3 Add payment stores 2024-08-19 11:37:03 +02:00
e33dea3e4b Add logs to service 2024-08-19 11:35:31 +02:00
5b00b68a88 Add Nowstore 2024-08-19 11:19:07 +02:00
69eee93cff Add billsstore 2024-08-19 11:10:57 +02:00
15 changed files with 309 additions and 22 deletions

View File

@@ -1,12 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>wails-template</title>
<meta charset="UTF-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>bill-manager</title>
</head>
<body>
<div id="app"></div>
<script src="./src/main.ts" type="module"></script>
<div id="app"></div>
<script src="./src/main.ts" type="module"></script>
</body>
</html>
</html>

View File

@@ -1,22 +1,36 @@
<script lang="ts">
import { Toaster } from "svelte-sonner";
import Header from "$lib/components/Header.svelte";
import Router from "$lib/router/Router.svelte";
import { Close } from '$wails/main/App'
function keyDown(event: KeyboardEvent) {
if (event.ctrlKey && event.key == "r") {
window.location.reload();
import { Close } from "$wails/main/App";
import { scrollingTimeFrameStore } from "$lib/store/scrollingTimeFrameStore";
function keyDown(event: KeyboardEvent) {
if (event.ctrlKey && event.key == "r") {
window.location.reload();
}
if (event.ctrlKey && event.key == "w") {
Close();
}
if (event.key == "ArrowLeft") {
scrollingTimeFrameStore.prev();
}
if (event.key == "ArrowRight") {
scrollingTimeFrameStore.next();
}
}
if (event.ctrlKey && event.key == "w") {
Close();
function scroll(event: WheelEvent) {
if (event.deltaY < 0) {
scrollingTimeFrameStore.next();
} else {
scrollingTimeFrameStore.prev();
}
}
}
</script>
<svelte:window on:keydown={keyDown} />
<svelte:window on:keydown={keyDown} on:wheel={scroll} />
<Toaster theme="dark" expand visibleToasts={9} />
<template>
<Header />
<!-- <Header /> -->
<main class="flex-1">
<Router />
</main>

View File

@@ -0,0 +1,45 @@
<script lang="ts">
import { type PaymentBill } from "$lib/types";
import { SetPaid } from "$wails/main/App";
import { toast } from "svelte-sonner";
export let paymentBill: PaymentBill = {
id: -1,
name: "none",
payment: null,
};
export let monthFor: Date = new Date();
let paymentDate: string = "";
$: {
if (!!paymentBill.payment?.paymentDate) {
// @ts-ignore Yes split exists... The type is time.Time but it's actually a string
// Because typescript is a worthless waste of bytes
// And I don't know how to properly convert time.Time to Date or String
// So I'm doing this bullshit
paymentDate = paymentBill.payment!.paymentDate.split("T")[0];
}
}
async function doPaid(event: MouseEvent) {
const res = await SetPaid(paymentBill.id, monthFor);
if (!res.success) {
toast.error(`failed setting paid for ${paymentBill.id} and month ${monthFor} with error ${res.error}`);
return;
}
paymentBill.payment = res.data;
}
</script>
<template>
<div class="grid grid-cols-2 w-full text-start px-3 text-xl">
<p class={paymentBill.payment == null ? "text-red-700" : ""}>{paymentBill.name}</p>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<p
class="h-[1.6em] cursor-pointer border-2 border-transparent hover:border-solid hover:border-sky-500"
on:click={doPaid}
>
{paymentDate}
</p>
</div>
</template>

View File

@@ -0,0 +1,49 @@
<script lang="ts">
import { billsStore } from "$lib/store/billsStore";
import { type PaymentBill } from "$lib/types";
import { main } from "$wails/models";
import { toast } from "svelte-sonner";
import PaymentBillComp from "./PaymentBillComp.svelte";
export let payments: main.Payment[] = [];
export let date: Date = new Date();
let dateString: string = date.toISOString()
$: {
dateString = date.toISOString().split("T")[0]
dateString = dateString.split("-").slice(0, 2).join("-");
}
const paymentsModel: { [key: number]: PaymentBill } = {};
for (const bill of $billsStore) {
paymentsModel[bill[1].id] = {
id: bill[1].id,
name: bill[1].name,
payment: null,
};
}
for (const payment of payments) {
const bill = $billsStore.get(payment.billId);
if (!!!bill) {
toast.error(`Bill not found for id ${payment.billId}`);
continue;
}
paymentsModel[bill.id] = {
id: bill.id,
name: bill.name,
payment: payment,
};
}
</script>
<template>
<div class="border-double border-2 border-gray-500 m-1">
<div class="text-4xl font-bold">
{dateString}
</div>
<div class="">
{#each Object.values(paymentsModel) as payment}
<PaymentBillComp paymentBill={payment} monthFor={date} />
{/each}
</div>
</div>
</template>

View File

@@ -1,7 +1,26 @@
<script lang="ts">
import Payments from "$lib/components/Payments.svelte";
import { scrollingTimeFrameStore } from "$lib/store/scrollingTimeFrameStore";
import { lastMonthPaymentsStore } from "$lib/store/lastMonthPaymentsStore";
import { thisMonthPaymentsStore } from "$lib/store/thisMonthPaymentsStore";
let forceupdate = false;
thisMonthPaymentsStore.subscribe(() => {
forceupdate = !forceupdate;
});
lastMonthPaymentsStore.subscribe(() => {
forceupdate = !forceupdate;
});
</script>
<template>
Hello, world
</template>
<div class="grid grid-cols-2">
{#if forceupdate}
<Payments date={$scrollingTimeFrameStore.from} payments={$lastMonthPaymentsStore} />
<Payments date={$scrollingTimeFrameStore.to} payments={$thisMonthPaymentsStore} />
{:else}
<Payments date={$scrollingTimeFrameStore.from} payments={$lastMonthPaymentsStore} />
<Payments date={$scrollingTimeFrameStore.to} payments={$thisMonthPaymentsStore} />
{/if}
</div>
</template>

View File

@@ -0,0 +1,37 @@
import { type Writable, writable } from "svelte/store";
import { GetBills } from "$wails/main/App";
import { main } from "$wails/models";
import { toast } from "svelte-sonner";
async function createStore(): Promise<Writable<Map<number, main.Bill>> & { refresh: Function }> {
const bills: Map<number, main.Bill> = new Map<number, main.Bill>();
const res = await GetBills();
if (!res.success) {
toast.error("Error getting bills " + res.error);
} else {
for (let i = 0; i < res.data.length; i++) {
const bill = res.data[i];
bills.set(bill.id, bill);
}
}
const { subscribe, update, set } = writable(bills);
return {
subscribe,
update,
set,
refresh: async () => {
const res = await GetBills();
if (!res.success) {
toast.error("Error getting bills " + res.error);
} else {
for (let i = 0; i < res.data.length; i++) {
const bill = res.data[i];
bills.set(bill.id, bill);
}
}
},
};
}
export const billsStore = await createStore();

View File

@@ -0,0 +1,34 @@
import { get, type Writable, writable } from "svelte/store";
import { GetPaymentsForMonth } from "$wails/main/App";
import { main } from "$wails/models";
import { toast } from "svelte-sonner";
import { scrollingTimeFrameStore } from "$lib/store/scrollingTimeFrameStore";
async function createStore(): Promise<Writable<main.Payment[]>> {
const payments: main.Payment[] = [];
const res = await GetPaymentsForMonth(get(scrollingTimeFrameStore).from);
if (!res.success) {
toast.error("Error getting payments " + res.error);
} else {
payments.push(...res.data);
}
const { subscribe, update, set } = writable(payments);
return {
subscribe,
update,
set,
};
}
const lastMonthPaymentsStore = await createStore();
scrollingTimeFrameStore.subscribe(async (timeframe) => {
const res = await GetPaymentsForMonth(timeframe.from);
if (!res.success) {
toast.error("Error getting payments " + res.error);
return;
}
lastMonthPaymentsStore.set(res.data);
});
export { lastMonthPaymentsStore };

View File

@@ -0,0 +1,32 @@
import { type ScrollingTimeframe } from "$lib/types";
import { type Writable, writable } from "svelte/store";
async function createStore(): Promise<Writable<ScrollingTimeframe> & { next: Function; prev: Function }> {
const thism = new Date();
const lastm = new Date();
thism.setMonth(thism.getMonth() - 1);
lastm.setMonth(lastm.getMonth() - 2);
const { subscribe, update, set } = writable({ from: lastm, to: thism });
return {
subscribe,
update,
set,
next: () => {
update((frame: ScrollingTimeframe) => {
frame.from.setMonth(frame.from.getMonth() + 1);
frame.to.setMonth(frame.to.getMonth() + 1);
return frame;
});
},
prev: () => {
update((frame: ScrollingTimeframe) => {
frame.from.setMonth(frame.from.getMonth() - 1);
frame.to.setMonth(frame.to.getMonth() - 1);
return frame;
});
},
};
}
export const scrollingTimeFrameStore = await createStore();

View File

@@ -0,0 +1,34 @@
import { get, type Writable, writable } from "svelte/store";
import { GetPaymentsForMonth } from "$wails/main/App";
import { main } from "$wails/models";
import { toast } from "svelte-sonner";
import { scrollingTimeFrameStore } from "$lib/store/scrollingTimeFrameStore";
async function createStore(): Promise<Writable<main.Payment[]>> {
const payments: main.Payment[] = [];
const res = await GetPaymentsForMonth(get(scrollingTimeFrameStore).to);
if (!res.success) {
toast.error("Error getting payments " + res.error);
} else {
payments.push(...res.data);
}
const { subscribe, update, set } = writable(payments);
return {
subscribe,
update,
set,
};
}
const thisMonthPaymentsStore = await createStore();
scrollingTimeFrameStore.subscribe(async (timeframe) => {
const res = await GetPaymentsForMonth(timeframe.to);
if (!res.success) {
toast.error("Error getting payments " + res.error);
return;
}
thisMonthPaymentsStore.set(res.data);
});
export { thisMonthPaymentsStore };

11
frontend/src/lib/types.ts Normal file
View File

@@ -0,0 +1,11 @@
import { main } from "$wails/models";
export type PaymentBill = {
id: number;
name: string;
payment: main.Payment|null;
};
export type ScrollingTimeframe = {
from: Date;
to: Date;
}

View File

@@ -1,3 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
html {
background-color: rgba(27, 38, 54, 1);
text-align: center;

2
go.mod
View File

@@ -1,4 +1,4 @@
module wails-template
module bill-manager
go 1.21

View File

@@ -61,7 +61,7 @@ func main() {
// Create application with options
err = wails.Run(&options.App{
Title: "bill-manager-w",
Title: "bill-manager",
Width: 1024,
Height: 768,
AssetServer: &assetserver.Options{

View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"log"
"time"
)
@@ -14,6 +15,7 @@ const paymentColumns = "id, billid, monthFor, paymentDate"
const billColumns = "id, name"
func (s *BillService) GetPaymentsForDate(date time.Time) ([]Payment, error) {
log.Printf("GetPaymentsForDate for %v", date)
res := []Payment{}
if s == nil {
return res, fmt.Errorf("calling GetPaymentsFor on nil BillService")
@@ -45,6 +47,7 @@ WHERE monthFor = date(strftime('%%Y-%%m-01', ?));
}
func (s *BillService) GetPaymentForBillAndDate(billid int64, date time.Time) (Payment, error) {
log.Printf("GetPaymentForBillAndDate for %d and %s", billid, date)
res := Payment{}
if s == nil {
return res, fmt.Errorf("calling GetPaymentsFor on nil BillService")
@@ -68,6 +71,7 @@ WHERE billid = ? AND monthFor = date(strftime('%%Y-%%m-01', ?));
}
func (s *BillService) GetAllBills() ([]Bill, error) {
log.Printf("GetAllBills")
res := []Bill{}
if s == nil {
return res, fmt.Errorf("calling GetAllBills on nil BillService")
@@ -100,6 +104,7 @@ func (s *BillService) GetAllBills() ([]Bill, error) {
}
func (s *BillService) MarkPaid(billid int64, monthFor time.Time, when time.Time) (Payment, error) {
log.Printf("MarkPaid for %d, %v and %v", billid, monthFor, when)
res := Payment{}
if s == nil {
return res, fmt.Errorf("calling MarkPaid on nil BillService")

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://wails.io/schemas/config.v2.json",
"name": "wails-template",
"outputfilename": "wails-template",
"name": "bill-manager",
"outputfilename": "bill-manager",
"frontend:install": "pnpm install",
"frontend:build": "pnpm build",
"frontend:dev:watcher": "pnpm dev",