Compare commits

...

23 Commits

Author SHA1 Message Date
e016dd7851 Rework the fuck of everything 2025-10-19 15:17:36 +02:00
123b2961a2 Reverse mouse scroll direction
I found myself scrolling in the wrong direction... This should help
2024-08-31 12:10:57 +02:00
f1c8c394c9 Default scrolling payment date to first of month 2024-08-31 11:59:57 +02:00
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
9cbaf7880b Add close and refresh keybinds 2024-08-19 11:02:15 +02:00
c17e25c358 Add json tags to types 2024-08-19 10:51:31 +02:00
de7c2cc82c Update model 2024-08-19 10:25:40 +02:00
5e94f44e27 Add go files from previous project 2024-08-19 10:23:12 +02:00
26 changed files with 1650 additions and 105 deletions

4
.gitignore vendored
View File

@@ -1,3 +1,7 @@
node_modules
frontend/dist
build
bills.db
main.log
bills.db-shm
bills.db-wal

114
app.go
View File

@@ -2,6 +2,9 @@ package main
import (
"context"
"time"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
@@ -19,3 +22,114 @@ func NewApp() *App {
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
func (a *App) Close() {
runtime.Quit(a.ctx)
}
func (a *App) GetBills() WailsBills {
res := WailsBills{}
bills, err := service.GetAllBills()
if err != nil {
res.Success = false
res.Error = err.Error()
return res
}
res.Success = true
res.Data = bills
return res
}
func (a *App) GetPaymentsForMonth(month time.Time) WailsPayments {
res := WailsPayments{}
payments, err := service.GetPaymentsForDate(month)
if err != nil {
res.Success = false
res.Error = err.Error()
return res
}
res.Success = true
res.Data = payments
return res
}
func (a *App) SetPaid(billid int64, month time.Time) WailsPayment {
res := WailsPayment{}
payment, err := service.MarkPaid(billid, month, time.Now())
if err!= nil {
res.Success = false
res.Error = err.Error()
return res
}
res.Success = true
res.Data = payment
return res
}
func (a *App) SetPaidWithDate(billid int64, month time.Time, paymentDate time.Time) WailsPayment {
res := WailsPayment{}
payment, err := service.MarkPaid(billid, month, paymentDate)
if err!= nil {
res.Success = false
res.Error = err.Error()
return res
}
res.Success = true
res.Data = payment
return res
}
func (a *App) MovePayment(billid int64, fromMonth time.Time, toMonth time.Time) WailsPayment {
res := WailsPayment{}
payment, err := service.MovePayment(billid, fromMonth, toMonth)
if err!= nil {
res.Success = false
res.Error = err.Error()
return res
}
res.Success = true
res.Data = payment
return res
}
func (a *App) AddBill(name string) WailsBill {
res := WailsBill{}
bill, err := service.AddBill(name)
if err != nil {
res.Success = false
res.Error = err.Error()
return res
}
res.Success = true
res.Data = bill
return res
}
func (a *App) RemoveBill(billid int64) WailsVoid {
res := WailsVoid{}
err := service.RemoveBill(billid)
if err != nil {
res.Success = false
res.Error = err.Error()
return res
}
res.Success = true
return res
}
func (a *App) UnmarkPaid(billid int64, month time.Time) WailsVoid {
res := WailsVoid{}
err := service.UnmarkPaid(billid, month)
if err != nil {
res.Success = false
res.Error = err.Error()
return res
}
res.Success = true
return res
}
// These exist only so that wails generates models for Bill and Payment
func (a *App) EmptyBill() Bill {
return Bill{}
}
func (a *App) EmptyPayment() Payment {
return Payment{}
}

134
db.go Normal file
View File

@@ -0,0 +1,134 @@
package main
import (
"database/sql"
"fmt"
"log"
"os"
"time"
_ "github.com/mattn/go-sqlite3"
)
type DB struct {
Ready bool
path string
readConn *sql.DB
writeConn *sql.DB
}
func (db *DB) Open() error {
if db.path == "" {
return fmt.Errorf("database path not set")
}
file, err := os.Open(db.path)
if err != nil {
if os.IsNotExist(err) {
log.Printf("Database file does not exist at %s, creating", db.path)
file, err := os.Create(db.path)
if err != nil {
return fmt.Errorf("failed to create database file: %v", err)
}
log.Printf("Database created at %s", db.path)
file.Close()
} else {
return fmt.Errorf("failed to open database file: %v", err)
}
}
file.Close()
writeConn, err := sql.Open("sqlite3", db.path+"?_journal=WAL&_synchronous=NORMAL")
if err != nil {
Error.Printf("%++v", err)
return err
}
writeConn.SetMaxOpenConns(1)
writeConn.SetConnMaxIdleTime(30 * time.Second)
writeConn.SetConnMaxLifetime(30 * time.Second)
db.writeConn = writeConn
readConn, err := sql.Open("sqlite3", db.path+"?mode=ro&_journal=WAL&_synchronous=NORMAL&_mode=ro")
if err != nil {
Error.Printf("%++v", err)
return err
}
readConn.SetMaxOpenConns(4)
readConn.SetConnMaxIdleTime(30 * time.Second)
readConn.SetConnMaxLifetime(30 * time.Second)
db.readConn = readConn
db.Ready = true
return nil
}
func (db *DB) Init(ddl string) error {
if !db.Ready {
return fmt.Errorf("database not ready")
}
var rows map[string]struct{} = make(map[string]struct{})
// TODO: Maybe make this better one day...
var expected = map[string]struct{}{
"Bill": {},
"Payment": {},
}
res, err := db.readConn.Query("SELECT name FROM sqlite_master WHERE type='table';")
if err != nil {
Error.Printf("%++v", err)
return err
}
defer res.Close()
for res.Next() {
var name string
err := res.Scan(&name)
if err != nil {
Error.Printf("%++v", err)
return err
}
rows[name] = struct{}{}
}
var needsInit bool
for table := range expected {
if _, ok := rows[table]; !ok {
log.Printf("Table %s not found, initializing", table)
needsInit = true
break
}
}
if !needsInit {
log.Printf("Database already initialized")
return nil
}
_, err = db.writeConn.Exec(ddl)
if err != nil {
Error.Printf("%++v", err)
log.Printf("%#v", "Rolling back")
_, err2 := db.writeConn.Exec("ROLLBACK;")
if err2 != nil {
Error.Printf("Error rolling back! %++v", err)
}
return err
}
log.Printf("Database init OK")
return nil
}
func (db *DB) Close() error {
err := db.writeConn.Close()
if err != nil {
return err
}
err = db.readConn.Close()
if err != nil {
return err
}
return nil
}

19
ddl.sql Normal file
View File

@@ -0,0 +1,19 @@
begin transaction;
create table Bill (
id integer PRIMARY KEY AUTOINCREMENT,
name TEXT not null
);
create index Bill_name on Bill (name);
create table Payment (
id integer PRIMARY KEY AUTOINCREMENT,
billid integer,
monthFor date not null,
paymentDate date
);
create unique index Payment_billid_monthFor_unique on Payment (billid, monthFor);
create index Payment_billid on Payment (billid);
create index Payment_monthFor on Payment (monthFor);
commit;

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>

View File

@@ -1,11 +1,92 @@
<script lang="ts">
import Header from "$lib/components/Header.svelte";
import { Toaster } from "svelte-sonner";
import Router from "$lib/router/Router.svelte";
</script>
import { Close } from "$wails/main/App";
import { scrollingTimeFrameStore } from "$lib/store/scrollingTimeFrameStore";
import BillManager from "$lib/components/BillManager.svelte";
let showSettings = false;
function keyDown(event: KeyboardEvent) {
if (event.ctrlKey && event.key == "r") {
window.location.reload();
}
if (event.ctrlKey && event.key == "w") {
Close();
}
}
function scroll(event: WheelEvent) {
event.preventDefault();
// Don't navigate if settings modal is open
if (showSettings) return;
if (event.deltaY < 0) {
scrollingTimeFrameStore.prev();
} else {
scrollingTimeFrameStore.next();
}
}
</script>
<svelte:window on:keydown={keyDown} on:wheel|preventDefault={scroll} />
<Toaster theme="dark" expand visibleToasts={9} />
<Header />
<main class="flex-1">
<template>
<header class="glass-morphism border-b border-white/10 px-6 py-3">
<div class="max-w-7xl mx-auto flex items-center justify-between">
<div class="flex items-center space-x-4">
<div class="w-8 h-8 rounded-lg bg-gradient-to-br from-blue-500 to-purple-600 flex items-center justify-center">
<svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
<h1 class="text-xl font-bold bg-gradient-to-r from-blue-400 to-purple-400 bg-clip-text text-transparent">
Bill Manager
</h1>
</div>
<div class="flex items-center space-x-3">
<div class="text-xs text-white/60">
Use mouse scroll to navigate months
</div>
<button class="action-button text-xs px-3 py-1" on:click={() => showSettings = true}>
Settings
</button>
<button class="action-button text-xs px-3 py-1" on:click={() => window.location.reload()}>
Refresh
</button>
</div>
</div>
</header>
<main class="flex-1 overflow-hidden p-0">
<Router />
</main>
<!-- Settings Modal -->
{#if showSettings}
<div
class="fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50"
on:click={() => showSettings = false}
on:keydown={(e) => e.key === 'Escape' && (showSettings = false)}
role="dialog"
aria-modal="true"
aria-labelledby="settings-title"
tabindex="0"
>
<div class="glass-morphism rounded-xl p-6 max-w-2xl w-full max-h-[80vh] overflow-y-auto m-4" on:click|stopPropagation>
<div class="flex items-center justify-between mb-4">
<h2 id="settings-title" class="text-2xl font-bold text-white">Settings</h2>
<button
class="w-8 h-8 rounded-lg bg-white/10 hover:bg-white/20 flex items-center justify-center text-white"
on:click={() => showSettings = false}
on:keydown={(e) => e.key === 'Enter' && (showSettings = false)}
aria-label="Close settings"
>
</button>
</div>
<BillManager />
</div>
</div>
{/if}

View File

@@ -0,0 +1,108 @@
<script lang="ts">
import { AddBill, RemoveBill } from "$wails/main/App";
import { billsStore } from "$lib/store/billsStore";
import { toast } from "svelte-sonner";
let showAddForm = false;
let newBillName = "";
async function addBill() {
if (!newBillName.trim()) {
toast.error("Please enter a bill name");
return;
}
const res = await AddBill(newBillName.trim());
if (!res.success) {
toast.error(`Failed to add bill: ${res.error}`);
return;
}
// Refresh the bills store
billsStore.refresh();
toast.success(`Bill "${newBillName}" added successfully`);
newBillName = "";
showAddForm = false;
}
async function removeBill(billId: number, billName: string) {
if (!confirm(`Are you sure you want to remove "${billName}"? This will also delete all payment history for this bill.`)) {
return;
}
const res = await RemoveBill(billId);
if (!res.success) {
toast.error(`Failed to remove bill: ${res.error}`);
return;
}
// Refresh the bills store
billsStore.refresh();
toast.success(`Bill "${billName}" removed successfully`);
}
</script>
<div class="glass-morphism rounded-xl p-6 mb-6">
<div class="flex items-center justify-between mb-4">
<h2 class="text-2xl font-bold text-white">Bill Management</h2>
<button
class="action-button text-sm px-4 py-2"
on:click={() => showAddForm = !showAddForm}
>
{showAddForm ? 'Cancel' : 'Add New Bill'}
</button>
</div>
{#if showAddForm}
<div class="mb-6 p-4 bg-white/5 rounded-lg border border-white/10">
<div class="flex flex-col space-y-3">
<label for="bill-name-input" class="text-sm font-medium text-white/80">New Bill Name:</label>
<input
id="bill-name-input"
type="text"
bind:value={newBillName}
placeholder="Enter bill name"
class="date-input"
on:keydown={(e) => e.key === 'Enter' && addBill()}
/>
<div class="flex space-x-2">
<button
class="action-button text-sm px-3 py-1.5"
on:click={addBill}
>
Add Bill
</button>
<button
class="px-3 py-1.5 text-sm rounded-lg font-semibold transition-all duration-200 bg-white/10 hover:bg-white/20 text-white/80"
on:click={() => { showAddForm = false; newBillName = ""; }}
>
Cancel
</button>
</div>
</div>
</div>
{/if}
<div class="space-y-2">
<h3 class="text-lg font-semibold text-white/80 mb-3">Current Bills:</h3>
{#if Array.from($billsStore.values()).length === 0}
<div class="text-center py-8 text-white/50">
<p>No bills found. Add your first bill to get started!</p>
</div>
{:else}
{#each Array.from($billsStore.values()) as bill}
<div class="flex items-center justify-between p-3 bg-white/5 rounded-lg border border-white/10">
<span class="text-white font-medium">{bill.name}</span>
<button
class="px-3 py-1 text-sm rounded-lg font-semibold transition-all duration-200 bg-red-500/20 hover:bg-red-500/30 text-red-400 border border-red-500/30"
on:click={() => removeBill(bill.id, bill.name)}
>
Remove
</button>
</div>
{/each}
{/if}
</div>
</div>

View File

@@ -0,0 +1,123 @@
<script lang="ts">
import { type PaymentBill } from "$lib/types";
import { SetPaid, SetPaidWithDate, UnmarkPaid } 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 showDatePicker = false;
let selectedDate = "";
let paymentDate: string = "";
$: {
if (paymentBill.payment && paymentBill.payment.paymentDate) {
// @ts-ignore Yes split exists... The type is time.Time but it's actually a string
paymentDate = paymentBill.payment.paymentDate.split("T")[0];
selectedDate = paymentDate;
}
}
async function doPaid(event: MouseEvent) {
const res = await SetPaid(paymentBill.id, monthFor);
if (!res.success) {
throw new Error(`failed setting paid for ${paymentBill.id} and month ${monthFor} with error ${res.error}`);
}
paymentBill.payment = res.data;
showDatePicker = false;
}
async function doPaidWithDate() {
const dateObj = new Date(selectedDate + "T00:00:00");
const res = await SetPaidWithDate(paymentBill.id, monthFor, dateObj);
if (!res.success) {
throw new Error(`failed setting paid for ${paymentBill.id} with custom date: ${res.error}`);
}
paymentBill.payment = res.data;
showDatePicker = false;
}
async function doUnmarkPaid() {
const res = await UnmarkPaid(paymentBill.id, monthFor);
if (!res.success) {
throw new Error(`failed unmarking paid for ${paymentBill.id}: ${res.error}`);
}
paymentBill.payment = null;
}
function openDatePicker() {
if (paymentBill.payment) {
showDatePicker = true;
} else {
doPaid();
}
}
</script>
<template>
<div class="bill-card p-3">
<div class="flex items-center justify-between">
<div class="flex items-center space-x-2">
<div class="w-5 h-5 rounded-full flex items-center justify-center text-xs font-bold {paymentBill.payment == null ? 'bg-red-500' : 'bg-green-500'}">
{paymentBill.payment == null ? "!" : "✓"}
</div>
<div class="min-w-0">
<h3 class="text-sm font-semibold {paymentBill.payment == null ? 'text-red-400' : 'text-white'} truncate">
{paymentBill.name}
</h3>
<p class="text-xs text-white/60">
{paymentBill.payment == null ? 'Unpaid' : paymentDate}
</p>
</div>
</div>
<div class="flex space-x-1">
<!-- svelte-ignore a11y-click-events-have-key-events -->
<button
class="px-2 py-1 text-xs rounded font-medium transition-all duration-200 bg-blue-500/20 hover:bg-blue-500/30 text-blue-400"
on:click={openDatePicker}
>
{paymentBill.payment == null ? 'Pay' : 'Edit'}
</button>
{#if paymentBill.payment}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<button
class="px-2 py-1 text-xs rounded font-medium transition-all duration-200 bg-red-500/20 hover:bg-red-500/30 text-red-400"
on:click={doUnmarkPaid}
>
×
</button>
{/if}
</div>
</div>
{#if showDatePicker}
<div class="mt-2 p-2 bg-white/5 rounded border border-white/10">
<div class="flex flex-col space-y-2">
<input
type="date"
bind:value={selectedDate}
class="px-2 py-1 text-xs rounded bg-white/10 border border-white/20 text-white"
/>
<div class="flex space-x-1">
<button
class="px-2 py-1 text-xs rounded font-medium bg-blue-500/30 text-blue-400"
on:click={doPaidWithDate}
>
Set
</button>
<button
class="px-2 py-1 text-xs rounded font-medium bg-white/10 text-white/70"
on:click={() => showDatePicker = false}
>
Cancel
</button>
</div>
</div>
</div>
{/if}
</div>
</template>

View File

@@ -0,0 +1,74 @@
<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("-");
}
$: paymentsModel = (() => {
console.log('Payments component recalculating...', {
date: dateString,
paymentsCount: payments.length,
billsCount: $billsStore.size
});
const model: { [key: number]: PaymentBill } = {};
// First, create entries for all bills
for (const bill of $billsStore) {
model[bill[1].id] = {
id: bill[1].id,
name: bill[1].name,
payment: null,
};
}
// Then, add payment data for bills that have payments
for (const payment of payments) {
const bill = $billsStore.get(payment.billId);
if (!bill) {
throw new Error(`Bill not found for id ${payment.billId}`);
}
model[bill.id] = {
id: bill.id,
name: bill.name,
payment: payment,
};
console.log(`Payment found: ${bill.name} -> ${payment.paymentDate}`);
}
console.log('Final paymentsModel:', model);
return model;
})();
</script>
<template>
<div class="glass-morphism rounded-xl p-4 h-full flex flex-col">
<div class="month-header text-xl mb-4">
{dateString}
</div>
<div class="flex-1 overflow-y-auto space-y-2">
{#each Object.values(paymentsModel) as payment}
<PaymentBillComp paymentBill={payment} monthFor={date} />
{/each}
</div>
{#if Object.values(paymentsModel).length === 0}
<div class="flex-1 flex items-center justify-center text-white/50">
<div class="text-center">
<svg class="w-12 h-12 mx-auto mb-2 opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path>
</svg>
<p class="text-sm">No bills found</p>
</div>
</div>
{/if}
</div>
</template>

View File

@@ -1,7 +1,28 @@
<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
<div class="h-full p-4">
<div class="grid grid-cols-2 gap-4 h-full">
{#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>
</div>
</template>

View File

@@ -0,0 +1,39 @@
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 {
bills.clear();
for (let i = 0; i < res.data.length; i++) {
const bill = res.data[i];
bills.set(bill.id, bill);
}
set(bills);
}
},
};
}
export const billsStore = await createStore();

View File

@@ -0,0 +1,35 @@
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) => {
console.log('lastMonthPaymentsStore: timeframe updated', timeframe.from);
const res = await GetPaymentsForMonth(timeframe.from);
if (!res.success) {
throw new Error("Error getting payments " + res.error);
}
console.log('lastMonthPaymentsStore: got payments', res.data.length);
lastMonthPaymentsStore.set(res.data);
});
export { lastMonthPaymentsStore };

View File

@@ -0,0 +1,38 @@
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.setDate(1);
lastm.setDate(1);
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) => {
const newFrom = new Date(frame.from);
const newTo = new Date(frame.to);
newFrom.setMonth(newFrom.getMonth() + 1);
newTo.setMonth(newTo.getMonth() + 1);
return { from: newFrom, to: newTo };
});
},
prev: () => {
update((frame: ScrollingTimeframe) => {
const newFrom = new Date(frame.from);
const newTo = new Date(frame.to);
newFrom.setMonth(newFrom.getMonth() - 1);
newTo.setMonth(newTo.getMonth() - 1);
return { from: newFrom, to: newTo };
});
},
};
}
export const scrollingTimeFrameStore = await createStore();

View File

@@ -0,0 +1,35 @@
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) => {
console.log('thisMonthPaymentsStore: timeframe updated', timeframe.to);
const res = await GetPaymentsForMonth(timeframe.to);
if (!res.success) {
throw new Error("Error getting payments " + res.error);
}
console.log('thisMonthPaymentsStore: got payments', res.data.length);
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,15 +1,79 @@
html {
background-color: rgba(27, 38, 54, 1);
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
html {
background: linear-gradient(135deg, #1a1f2e 0%, #2c3e50 50%, #1a1f2e 100%);
text-align: center;
color: white;
}
min-height: 100vh;
}
body {
body {
margin: 0;
color: white;
font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
"Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
background: transparent;
}
}
@layer components {
.glass-morphism {
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.1);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}
.bill-card {
transition: all 300ms ease;
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 0.5rem;
}
.bill-card:hover {
background: rgba(255, 255, 255, 0.06);
box-shadow: 0 4px 20px 0 rgba(31, 38, 135, 0.25);
transform: scale(1.01);
}
.paid-indicator {
@apply inline-flex items-center justify-center w-6 h-6 rounded-full text-xs font-bold;
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}
.unpaid-indicator {
@apply inline-flex items-center justify-center w-6 h-6 rounded-full text-xs font-bold;
background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}
.month-header {
@apply text-3xl font-bold mb-6 pb-3 border-b border-white/20;
background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.action-button {
@apply px-4 py-2 rounded-lg font-semibold transition-all duration-200 transform hover:scale-105 active:scale-95;
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}
.action-button:hover {
box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}
.date-input {
@apply px-3 py-2 rounded-lg bg-white/10 border border-white/20 text-white placeholder-white/50 focus:outline-none focus:border-blue-400 focus:bg-white/15 transition-all duration-200;
}
}
@font-face {
@@ -23,4 +87,24 @@ body {
#app {
height: 100vh;
text-align: center;
display: flex;
flex-direction: column;
}
/* Custom scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: rgba(255, 255, 255, 0.05);
}
::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.2);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: rgba(255, 255, 255, 0.3);
}

26
frontend/wailsjs/go/main/App.d.ts vendored Normal file
View File

@@ -0,0 +1,26 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {main} from '../models';
import {time} from '../models';
export function AddBill(arg1:string):Promise<main.WailsBill>;
export function Close():Promise<void>;
export function EmptyBill():Promise<main.Bill>;
export function EmptyPayment():Promise<main.Payment>;
export function GetBills():Promise<main.WailsBills>;
export function GetPaymentsForMonth(arg1:time.Time):Promise<main.WailsPayments>;
export function MovePayment(arg1:number,arg2:time.Time,arg3:time.Time):Promise<main.WailsPayment>;
export function RemoveBill(arg1:number):Promise<main.WailsVoid>;
export function SetPaid(arg1:number,arg2:time.Time):Promise<main.WailsPayment>;
export function SetPaidWithDate(arg1:number,arg2:time.Time,arg3:time.Time):Promise<main.WailsPayment>;
export function UnmarkPaid(arg1:number,arg2:time.Time):Promise<main.WailsVoid>;

View File

@@ -0,0 +1,47 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function AddBill(arg1) {
return window['go']['main']['App']['AddBill'](arg1);
}
export function Close() {
return window['go']['main']['App']['Close']();
}
export function EmptyBill() {
return window['go']['main']['App']['EmptyBill']();
}
export function EmptyPayment() {
return window['go']['main']['App']['EmptyPayment']();
}
export function GetBills() {
return window['go']['main']['App']['GetBills']();
}
export function GetPaymentsForMonth(arg1) {
return window['go']['main']['App']['GetPaymentsForMonth'](arg1);
}
export function MovePayment(arg1, arg2, arg3) {
return window['go']['main']['App']['MovePayment'](arg1, arg2, arg3);
}
export function RemoveBill(arg1) {
return window['go']['main']['App']['RemoveBill'](arg1);
}
export function SetPaid(arg1, arg2) {
return window['go']['main']['App']['SetPaid'](arg1, arg2);
}
export function SetPaidWithDate(arg1, arg2, arg3) {
return window['go']['main']['App']['SetPaidWithDate'](arg1, arg2, arg3);
}
export function UnmarkPaid(arg1, arg2) {
return window['go']['main']['App']['UnmarkPaid'](arg1, arg2);
}

View File

@@ -0,0 +1,222 @@
export namespace main {
export class Bill {
id: number;
name: string;
static createFrom(source: any = {}) {
return new Bill(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.id = source["id"];
this.name = source["name"];
}
}
export class Payment {
id: number;
billId: number;
monthFor: time.Time;
paymentDate: time.Time;
static createFrom(source: any = {}) {
return new Payment(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.id = source["id"];
this.billId = source["billId"];
this.monthFor = this.convertValues(source["monthFor"], time.Time);
this.paymentDate = this.convertValues(source["paymentDate"], time.Time);
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
export class WailsBill {
data: Bill;
success: boolean;
error: string;
static createFrom(source: any = {}) {
return new WailsBill(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.data = this.convertValues(source["data"], Bill);
this.success = source["success"];
this.error = source["error"];
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
export class WailsBills {
data: Bill[];
success: boolean;
error: string;
static createFrom(source: any = {}) {
return new WailsBills(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.data = this.convertValues(source["data"], Bill);
this.success = source["success"];
this.error = source["error"];
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
export class WailsPayment {
data: Payment;
success: boolean;
error: string;
static createFrom(source: any = {}) {
return new WailsPayment(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.data = this.convertValues(source["data"], Payment);
this.success = source["success"];
this.error = source["error"];
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
export class WailsPayments {
data: Payment[];
success: boolean;
error: string;
static createFrom(source: any = {}) {
return new WailsPayments(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.data = this.convertValues(source["data"], Payment);
this.success = source["success"];
this.error = source["error"];
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
export class WailsVoid {
success: boolean;
error: string;
static createFrom(source: any = {}) {
return new WailsVoid(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.success = source["success"];
this.error = source["error"];
}
}
}
export namespace time {
export class Time {
static createFrom(source: any = {}) {
return new Time(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
}
}
}

View File

@@ -134,7 +134,7 @@ export function WindowIsFullscreen(): Promise<boolean>;
// [WindowSetSize](https://wails.io/docs/reference/runtime/window#windowsetsize)
// Sets the width and height of the window.
export function WindowSetSize(width: number, height: number): Promise<Size>;
export function WindowSetSize(width: number, height: number): void;
// [WindowGetSize](https://wails.io/docs/reference/runtime/window#windowgetsize)
// Gets the width and height of the window.

47
go.mod
View File

@@ -1,39 +1,42 @@
module wails-template
module bill-manager
go 1.21
go 1.22.0
toolchain go1.23.0
toolchain go1.23.6
require github.com/wailsapp/wails/v2 v2.9.1
require (
github.com/mattn/go-sqlite3 v1.14.22
github.com/wailsapp/wails/v2 v2.10.2
)
require (
github.com/bep/debounce v1.2.1 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
github.com/labstack/echo/v4 v4.10.2 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leaanthony/go-ansi-parser v1.6.0 // indirect
github.com/leaanthony/gosod v1.0.3 // indirect
github.com/labstack/echo/v4 v4.13.3 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leaanthony/go-ansi-parser v1.6.1 // indirect
github.com/leaanthony/gosod v1.0.4 // indirect
github.com/leaanthony/slicer v1.6.0 // indirect
github.com/leaanthony/u v1.1.0 // indirect
github.com/leaanthony/u v1.1.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/tkrajina/go-reflector v0.5.6 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/samber/lo v1.49.1 // indirect
github.com/tkrajina/go-reflector v0.5.8 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/wailsapp/go-webview2 v1.0.10 // indirect
github.com/wailsapp/go-webview2 v1.0.19 // indirect
github.com/wailsapp/mimetype v1.4.1 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
)
// replace github.com/wailsapp/wails/v2 v2.9.1 => C:\Users\Administrator\go\pkg\mod

101
go.sum
View File

@@ -1,94 +1,83 @@
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck=
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=
github.com/labstack/echo/v4 v4.10.2 h1:n1jAhnq/elIFTHr1EYpiYtyKgx4RW9ccVgkqByZaN2M=
github.com/labstack/echo/v4 v4.10.2/go.mod h1:OEyqf2//K1DFdE57vw2DRgWY0M7s65IVQO2FzvI4J5k=
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/leaanthony/debme v1.2.1 h1:9Tgwf+kjcrbMQ4WnPcEIUcQuIZYqdWftzZkBr+i/oOc=
github.com/leaanthony/debme v1.2.1/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA=
github.com/leaanthony/go-ansi-parser v1.6.0 h1:T8TuMhFB6TUMIUm0oRrSbgJudTFw9csT3ZK09w0t4Pg=
github.com/leaanthony/go-ansi-parser v1.6.0/go.mod h1:+vva/2y4alzVmmIEpk9QDhA7vLC5zKDTRwfZGOp3IWU=
github.com/leaanthony/gosod v1.0.3 h1:Fnt+/B6NjQOVuCWOKYRREZnjGyvg+mEhd1nkkA04aTQ=
github.com/leaanthony/gosod v1.0.3/go.mod h1:BJ2J+oHsQIyIQpnLPjnqFGTMnOZXDbvWtRCSG7jGxs4=
github.com/leaanthony/slicer v1.5.0/go.mod h1:FwrApmf8gOrpzEWM2J/9Lh79tyq8KTX5AzRtwV7m4AY=
github.com/leaanthony/go-ansi-parser v1.6.1 h1:xd8bzARK3dErqkPFtoF9F3/HgN8UQk0ed1YDKpEz01A=
github.com/leaanthony/go-ansi-parser v1.6.1/go.mod h1:+vva/2y4alzVmmIEpk9QDhA7vLC5zKDTRwfZGOp3IWU=
github.com/leaanthony/gosod v1.0.4 h1:YLAbVyd591MRffDgxUOU1NwLhT9T1/YiwjKZpkNFeaI=
github.com/leaanthony/gosod v1.0.4/go.mod h1:GKuIL0zzPj3O1SdWQOdgURSuhkF+Urizzxh26t9f1cw=
github.com/leaanthony/slicer v1.6.0 h1:1RFP5uiPJvT93TAHi+ipd3NACobkW53yUiBqZheE/Js=
github.com/leaanthony/slicer v1.6.0/go.mod h1:o/Iz29g7LN0GqH3aMjWAe90381nyZlDNquK+mtH2Fj8=
github.com/leaanthony/u v1.1.0 h1:2n0d2BwPVXSUq5yhe8lJPHdxevE2qK5G99PMStMZMaI=
github.com/leaanthony/u v1.1.0/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI=
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/leaanthony/u v1.1.1 h1:TUFjwDGlNX+WuwVEzDqQwC2lOv0P4uhTQw7CMFdiK7M=
github.com/leaanthony/u v1.1.1/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ=
github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tkrajina/go-reflector v0.5.6 h1:hKQ0gyocG7vgMD2M3dRlYN6WBBOmdoOzJ6njQSepKdE=
github.com/tkrajina/go-reflector v0.5.6/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tkrajina/go-reflector v0.5.8 h1:yPADHrwmUbMq4RGEyaOUpz2H90sRsETNVpjzo3DLVQQ=
github.com/tkrajina/go-reflector v0.5.8/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/wailsapp/go-webview2 v1.0.10 h1:PP5Hug6pnQEAhfRzLCoOh2jJaPdrqeRgJKZhyYyDV/w=
github.com/wailsapp/go-webview2 v1.0.10/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo=
github.com/wailsapp/go-webview2 v1.0.19 h1:7U3QcDj1PrBPaxJNCui2k1SkWml+Q5kvFUFyTImA6NU=
github.com/wailsapp/go-webview2 v1.0.19/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
github.com/wailsapp/wails/v2 v2.9.1 h1:irsXnoQrCpeKzKTYZ2SUVlRRyeMR6I0vCO9Q1cvlEdc=
github.com/wailsapp/wails/v2 v2.9.1/go.mod h1:7maJV2h+Egl11Ak8QZN/jlGLj2wg05bsQS+ywJPT0gI=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
github.com/wailsapp/wails/v2 v2.10.2 h1:29U+c5PI4K4hbx8yFbFvwpCuvqK9VgNv8WGobIlKlXk=
github.com/wailsapp/wails/v2 v2.10.2/go.mod h1:XuN4IUOPpzBrHUkEd7sCU5ln4T/p1wQedfxP7fKik+4=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

48
main.go
View File

@@ -2,22 +2,66 @@ package main
import (
"embed"
"fmt"
"io"
"log"
"os"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
)
var Error *log.Logger
var Warning *log.Logger
func init() {
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
logFile, err := os.Create("main.log")
if err != nil {
log.Printf("Error creating log file: %v", err)
os.Exit(1)
}
logger := io.MultiWriter(os.Stdout, logFile)
log.SetOutput(logger)
Error = log.New(io.MultiWriter(logFile, os.Stderr, os.Stdout),
fmt.Sprintf("%sERROR:%s ", "\033[0;101m", "\033[0m"),
log.Lmicroseconds|log.Lshortfile)
Warning = log.New(io.MultiWriter(logFile, os.Stdout),
fmt.Sprintf("%sWarning:%s ", "\033[0;93m", "\033[0m"),
log.Lmicroseconds|log.Lshortfile)
}
//go:embed all:frontend/dist
var assets embed.FS
//go:embed ddl.sql
var ddl string
var service *BillService
func main() {
db := DB{
path: "bills.db",
}
db.Open()
defer db.Close()
err := db.Init(ddl)
if err != nil {
Error.Printf("Error initializing database: %v", err)
return
}
service = &BillService{
db: &db,
}
// Create an instance of the app structure
app := NewApp()
// Create application with options
err := wails.Run(&options.App{
Title: "wails-template",
err = wails.Run(&options.App{
Title: "bill-manager",
Width: 1024,
Height: 768,
AssetServer: &assetserver.Options{

250
service.go Normal file
View File

@@ -0,0 +1,250 @@
package main
import (
"fmt"
"log"
"time"
)
type BillService struct {
db *DB
bills map[int64]Bill
}
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")
}
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot get payments, db is nil or not ready - %v", s.db)
}
rows, err := s.db.readConn.Query(fmt.Sprintf(`
SELECT %s
FROM Payment
WHERE monthFor = date(strftime('%%Y-%%m-01', ?));
`, paymentColumns), date)
if err != nil {
return res, fmt.Errorf("query for payments of %s failed with error: %v", date, err)
}
for rows.Next() {
payment := Payment{}
err = rows.Scan(&payment.Id, &payment.BillId, &payment.MonthFor, &payment.PaymentDate)
if err != nil {
Error.Printf("failed to scan row: %v", err)
continue
}
res = append(res, payment)
}
return res, nil
}
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")
}
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot get payments, db is nil or not ready - %v", s.db)
}
row := s.db.readConn.QueryRow(fmt.Sprintf(`
SELECT %s
FROM Payment
WHERE billid = ? AND monthFor = date(strftime('%%Y-%%m-01', ?));
`, paymentColumns), billid, date)
err := row.Scan(&res.Id, &res.BillId, &res.MonthFor, &res.PaymentDate)
if err != nil {
return res, fmt.Errorf("failed scanning row: %v", err)
}
return res, nil
}
func (s *BillService) GetAllBills() ([]Bill, error) {
log.Printf("GetAllBills")
res := []Bill{}
if s == nil {
return res, fmt.Errorf("calling GetAllBills on nil BillService")
}
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot get bills, db is nil or not ready - %v", s.db)
}
rows, err := s.db.readConn.Query(fmt.Sprintf(`SELECT %s FROM Bill ORDER BY name`, billColumns))
if err != nil {
return res, fmt.Errorf("failed to query for bills: %w", err)
}
for rows.Next() {
bill := Bill{}
err := rows.Scan(&bill.Id, &bill.Name)
if err != nil {
Error.Printf("failed to scan row: %v", err)
continue
}
res = append(res, bill)
}
s.bills = make(map[int64]Bill)
for _, bill := range res {
s.bills[bill.Id] = bill
}
return res, nil
}
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")
}
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot mark bill paid, db is nil or not ready - %v", s.db)
}
qres, err := s.db.writeConn.Exec(`
INSERT INTO Payment (billid, monthFor, paymentDate)
VALUES (?, date(strftime('%Y-%m-01', ?)), ?)
ON CONFLICT(billid, monthFor) DO UPDATE SET
paymentDate = excluded.paymentDate
WHERE Payment.paymentDate IS NULL
`, billid, monthFor, when)
if err != nil {
return res, fmt.Errorf("failed upserting into payment with error: %w", err)
}
rows, err := qres.RowsAffected()
if err != nil {
return res, fmt.Errorf("failed to get rows affected: %w", err)
}
if rows == 0 {
return res, fmt.Errorf("no rows affected")
}
return s.GetPaymentForBillAndDate(billid, monthFor)
}
func (s *BillService) MovePayment(billid int64, fromMonth time.Time, toMonth time.Time) (Payment, error) {
log.Printf("MovePayment for %d from %v to %v", billid, fromMonth, toMonth)
res := Payment{}
if s == nil {
return res, fmt.Errorf("calling MovePayment on nil BillService")
}
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot move payment, db is nil or not ready - %v", s.db)
}
// First get the existing payment
existingPayment, err := s.GetPaymentForBillAndDate(billid, fromMonth)
if err != nil {
return res, fmt.Errorf("failed to get existing payment: %w", err)
}
// Delete the old payment
_, err = s.db.writeConn.Exec(`
DELETE FROM Payment WHERE billid = ? AND monthFor = date(strftime('%Y-%m-01', ?))
`, billid, fromMonth)
if err != nil {
return res, fmt.Errorf("failed to delete old payment: %w", err)
}
// Create new payment in the target month
payment, err := s.MarkPaid(billid, toMonth, existingPayment.PaymentDate)
if err != nil {
return res, fmt.Errorf("failed to create new payment: %w", err)
}
return payment, nil
}
func (s *BillService) AddBill(name string) (Bill, error) {
log.Printf("AddBill with name %s", name)
res := Bill{}
if s == nil {
return res, fmt.Errorf("calling AddBill on nil BillService")
}
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot add bill, db is nil or not ready - %v", s.db)
}
qres, err := s.db.writeConn.Exec(`
INSERT INTO Bill (name) VALUES (?)
`, name)
if err != nil {
return res, fmt.Errorf("failed to insert bill: %w", err)
}
id, err := qres.LastInsertId()
if err != nil {
return res, fmt.Errorf("failed to get last insert id: %w", err)
}
res.Id = id
res.Name = name
// Refresh the bills cache
_, _ = s.GetAllBills()
return res, nil
}
func (s *BillService) RemoveBill(billid int64) error {
log.Printf("RemoveBill with id %d", billid)
if s == nil {
return fmt.Errorf("calling RemoveBill on nil BillService")
}
if s.db == nil || !s.db.Ready {
return fmt.Errorf("cannot remove bill, db is nil or not ready - %v", s.db)
}
// Delete all payments for this bill first
_, err := s.db.writeConn.Exec(`
DELETE FROM Payment WHERE billid = ?
`, billid)
if err != nil {
return fmt.Errorf("failed to delete payments for bill: %w", err)
}
// Delete the bill
_, err = s.db.writeConn.Exec(`
DELETE FROM Bill WHERE id = ?
`, billid)
if err != nil {
return fmt.Errorf("failed to delete bill: %w", err)
}
// Refresh the bills cache
_, _ = s.GetAllBills()
return nil
}
func (s *BillService) UnmarkPaid(billid int64, month time.Time) error {
log.Printf("UnmarkPaid for %d and %v", billid, month)
if s == nil {
return fmt.Errorf("calling UnmarkPaid on nil BillService")
}
if s.db == nil || !s.db.Ready {
return fmt.Errorf("cannot unmark paid, db is nil or not ready - %v", s.db)
}
_, err := s.db.writeConn.Exec(`
DELETE FROM Payment WHERE billid = ? AND monthFor = date(strftime('%Y-%m-01', ?))
`, billid, month)
if err != nil {
return fmt.Errorf("failed to delete payment: %w", err)
}
return nil
}

41
types.go Normal file
View File

@@ -0,0 +1,41 @@
package main
import "time"
type (
Bill struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
Payment struct {
Id int64 `json:"id"`
BillId int64 `json:"billId"`
MonthFor time.Time `json:"monthFor" time_format:"2006-01-02"`
PaymentDate time.Time `json:"paymentDate" time_format:"2006-01-02T15:04:05"`
}
WailsBills struct {
Data []Bill `json:"data"`
Success bool `json:"success"`
Error string `json:"error"`
}
WailsPayments struct {
Data []Payment `json:"data"`
Success bool `json:"success"`
Error string `json:"error"`
}
WailsPayment struct {
Data Payment `json:"data"`
Success bool `json:"success"`
Error string `json:"error"`
}
WailsBill struct {
Data Bill `json:"data"`
Success bool `json:"success"`
Error string `json:"error"`
}
WailsVoid struct {
Success bool `json:"success"`
Error string `json:"error"`
}
)

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",