Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions demo/seed.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- Fictional bookkeeping sample for an isolated demo. No real companies, people or accounts.
INSERT INTO company (id,name,vat_number,chamber_number,country,address_line1,postal_code,city,email,default_currency,default_due_days) VALUES
(1,'Northlight Studio B.V.','NL000000000B00','00000000','NL','Voorbeeldstraat 1','1000 AA','Amsterdam','billing@northlight.example.test','EUR',30);

-- The RGS starter chart, as "Load starter" would insert it.
INSERT INTO accounts (rgs_code,reknr,parent_code,nivo,omskort,omslang,dc,bw,sortimentcode,is_leaf) VALUES
('B',NULL,NULL,1,'Balans','Balansrekeningen',NULL,'B',NULL,0),
('BIva',NULL,'B',2,'Imm. vaste activa','Immateriële vaste activa','D','B',NULL,0),
('BMva',NULL,'B',2,'Mat. vaste activa','Materiële vaste activa','D','B',NULL,0),
('BFva',NULL,'B',2,'Fin. vaste activa','Financiële vaste activa','D','B',NULL,0),
('BVrd',NULL,'B',2,'Voorraden','Voorraden','D','B',NULL,0),
('BPro',NULL,'B',2,'Onderh. projecten','Onderhanden projecten in opdracht van derden','D','B',NULL,0),
('BVor',NULL,'B',2,'Vorderingen','Vorderingen','D','B',NULL,0),
('BEff',NULL,'B',2,'Effecten','Effecten','D','B',NULL,0),
('BLim',NULL,'B',2,'Liquide middelen','Liquide middelen','D','B',NULL,0),
('BEiv',NULL,'B',2,'Eigen vermogen','Eigen vermogen','C','B',NULL,0),
('BVrz',NULL,'B',2,'Voorzieningen','Voorzieningen','C','B',NULL,0),
('BLas',NULL,'B',2,'Langlop. schulden','Langlopende schulden','C','B',NULL,0),
('BKas',NULL,'B',2,'Kortlop. schulden','Kortlopende schulden','C','B',NULL,0),
('W',NULL,NULL,1,'Winst & verlies','Winst- en verliesrekening',NULL,'W',NULL,0),
('WOmz',NULL,'W',2,'Netto-omzet','Netto-omzet','C','W',NULL,0),
('WWiv',NULL,'W',2,'Wijz. voorraden','Wijziging in voorraden gereed product en onderhanden werk','C','W',NULL,0),
('WGec',NULL,'W',2,'Geac. productie','Geactiveerde productie eigen bedrijf','C','W',NULL,0),
('WOvb',NULL,'W',2,'Ov. bedr.opbrengst','Overige bedrijfsopbrengsten','C','W',NULL,0),
('WKpr',NULL,'W',2,'Kostprijs omzet','Kostprijs van de omzet','D','W',NULL,0),
('WPer',NULL,'W',2,'Personeelskosten','Personeelskosten','D','W',NULL,0),
('WAfs',NULL,'W',2,'Afschrijvingen','Afschrijvingen op vaste activa','D','W',NULL,0),
('WBwv',NULL,'W',2,'Bijz. waardeverm.','Bijzondere waardeverminderingen','D','W',NULL,0),
('WOvk',NULL,'W',2,'Ov. bedr.kosten','Overige bedrijfskosten','D','W',NULL,0),
('WFbl',NULL,'W',2,'Fin. baten/lasten','Financiële baten en lasten','D','W',NULL,0),
('WBel',NULL,'W',2,'Belastingen','Belastingen over de winst','D','W',NULL,0);

INSERT INTO parties (id,kind,name,contact_name,email,vat_number,country,address_line1,postal_code,city,currency) VALUES
(1,'customer','Harbour Coffee Roasters','Sam Jansen','accounts@harbour-coffee.example.test',NULL,'NL','Kade 12','3511 AB','Utrecht','EUR'),
(2,'customer','Atelier Verde','Lina Peeters','finance@atelier-verde.example.test','BE0000000000','BE','Groenstraat 4','2000','Antwerpen','EUR'),
(3,'customer','Kestrel Logistics','Noor de Wit','ap@kestrel.example.test',NULL,'NL','Havenweg 88','3089 JH','Rotterdam','EUR'),
(4,'supplier','Pixel Print Works','Ties Bakker','invoices@pixelprint.example.test',NULL,'NL','Drukkerijlaan 3','5611 AA','Eindhoven','EUR');

INSERT INTO products (id,kind,sku,name,description,price_cents,vat_rate,unit,income_account) VALUES
(1,'service','WS-01','Brand workshop','One-day brand strategy workshop',95000,21,'day','WOmz'),
(2,'service','MT-01','Website maintenance','Monthly updates and monitoring',45000,21,'month','WOmz'),
(3,'service','PH-01','Photography session','Half-day product shoot',60000,21,'session','WOmz');

-- Totals follow recomputeTotals: Atelier Verde is an EU business with a VAT id, so its line is reverse charged.
INSERT INTO invoices (id,type,party_id,issue_date,due_date,subtotal_cents,vat_cents,total_cents,reverse_charge,reference,notes) VALUES
(1,'invoice',1,date('now','-40 days'),date('now','-10 days'),185000,38850,223850,0,'PO-4471','Thank you for your business.'),
(2,'invoice',2,date('now','-12 days'),date('now','+18 days'),60000,0,60000,1,NULL,'Reverse charge: VAT to be accounted for by the recipient.'),
(3,'invoice',3,NULL,NULL,45000,9450,54450,0,NULL,NULL);

INSERT INTO invoice_lines (invoice_id,position,product_id,description,quantity,unit,unit_price_cents,vat_rate,account_code,subtotal_cents,vat_cents,total_cents) VALUES
(1,1,1,'Brand workshop',1,'day',95000,21,'WOmz',95000,19950,114950),
(1,2,2,'Website maintenance',2,'month',45000,21,'WOmz',90000,18900,108900),
(2,1,3,'Photography session',1,'session',60000,21,'WOmz',60000,0,60000),
(3,1,2,'Website maintenance',1,'month',45000,21,'WOmz',45000,9450,54450);

-- Issuing through the ledger triggers numbers the invoices and posts their balanced journal entries.
UPDATE invoices SET status = 'issued', mutation_actor = 'Sample data', mutation_actor_kind = 'system' WHERE id IN (1, 2);
UPDATE invoices SET status = 'paid' WHERE id = 1;
UPDATE invoices SET status = 'sent' WHERE id = 2;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
},
"dependencies": {
"@clawnify/app": "^0.2.1",
"@clawnify/db": "^0.4.1",
"@clawnify/db": "^0.4.2",
"@hono/zod-openapi": "^0.18.0",
"@phosphor-icons/react": "^2.1.10",
"hono": "^4.13.7",
"react": "^19.0.0",
"react-dom": "^19.0.0"
Expand Down
32 changes: 24 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 39 additions & 1 deletion src/client/app.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { useEffect } from "react";
import { AppNav, embedded, reportLocation } from "@clawnify/app/client";
import { Notice } from "./notice";
import { AccountsPage } from "./pages/accounts";
import { HomePage } from "./pages/home";
import { InvoiceEditorPage } from "./pages/invoice-editor";
Expand All @@ -7,7 +10,7 @@ import { PartiesPage } from "./pages/parties";
import { ProductsPage } from "./pages/products";
import { ReportsPage } from "./pages/reports";
import { SettingsPage } from "./pages/settings";
import { Link, usePath } from "./router";
import { Link, navigate, usePath } from "./router";

const NAV: { to: string; label: string }[] = [
{ to: "/invoices", label: "Invoices" },
Expand All @@ -19,11 +22,44 @@ const NAV: { to: string; label: string }[] = [
{ to: "/accounts", label: "Accounts" },
];

// Embedded in the Clawnify workspace, the dashboard sidebar draws these and the
// in-page header is hidden. Standalone keeps the header below.
const HOST_NAV = [
{ items: [
{ id: "home", label: "Home", icon: "home", href: "/", home: true },
{ id: "invoices", label: "Invoices", icon: "file-text", href: "/invoices", color: "blue" as const },
{ id: "customers", label: "Customers", icon: "users", href: "/customers", color: "green" as const },
{ id: "suppliers", label: "Suppliers", icon: "truck", href: "/suppliers", color: "orange" as const },
{ id: "products", label: "Products", icon: "package", href: "/products", color: "violet" as const },
{ id: "journals", label: "Journal", icon: "book-open", href: "/journals", color: "sky" as const },
{ id: "reports", label: "Reports", icon: "bar-chart-3", href: "/reports", color: "red" as const },
{ id: "accounts", label: "Accounts", icon: "list", href: "/accounts", color: "amber" as const },
] },
{ label: "Admin", items: [
{ id: "settings", label: "Settings", icon: "settings", href: "/settings", color: "pink" as const },
] },
];

function activeNavId(path: string): string {
const section = path.split("/")[1] ?? "";
return section === "" ? "home" : section;
}

export function App() {
const path = usePath();

useEffect(() => {
reportLocation(path + window.location.search);
}, [path]);

return (
<div className="max-w-3xl mx-auto px-4 pb-20">
{embedded ? (
<div className="pt-8">
<AppNav title="Books" icon="book-open" groups={HOST_NAV} active={activeNavId(path)}
onNavigate={(item) => item.href && navigate(item.href)} />
</div>
) : (
<header className="flex items-baseline gap-6 mt-8 mb-8 pb-4 border-b border-gray-100 flex-wrap">
<Link to="/" className="text-xl font-semibold text-gray-900 hover:no-underline">
open-books
Expand All @@ -39,6 +75,8 @@ export function App() {
Settings
</Link>
</header>
)}
<Notice />
<main>{renderRoute(path)}</main>
</div>
);
Expand Down
65 changes: 65 additions & 0 deletions src/client/notice.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { useEffect, useState } from "react";

/**
* In-page messages.
*
* Native alert() and confirm() are blocked when the app runs inside the
* Clawnify workspace iframe, so a message shown that way silently never
* appears. `notify` shows it in the page instead.
*/
const EVENT = "clw:notice";

export function notify(message: string) {
window.dispatchEvent(new CustomEvent<string>(EVENT, { detail: message }));
}

export function Notice() {
const [message, setMessage] = useState<string | null>(null);
useEffect(() => {
const onNotice = (e: Event) => setMessage((e as CustomEvent<string>).detail);
window.addEventListener(EVENT, onNotice);
return () => window.removeEventListener(EVENT, onNotice);
}, []);
if (!message) return null;
return (
<div role="status" className="mb-6 flex items-start gap-3 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900">
<p className="flex-1">{message}</p>
<button onClick={() => setMessage(null)} className="text-amber-700 hover:text-amber-900" aria-label="Dismiss">×</button>
</div>
);
}

/** A destructive button that asks for confirmation inline before acting. */
export function ConfirmButton({
prompt,
confirmLabel = "Delete",
onConfirm,
className,
title,
disabled,
children,
}: {
prompt: string;
confirmLabel?: string;
onConfirm: () => void;
className?: string;
title?: string;
disabled?: boolean;
children: React.ReactNode;
}) {
const [asking, setAsking] = useState(false);
if (asking) {
return (
<span role="group" aria-label={prompt} className="inline-flex items-center gap-2 text-xs">
<span className="text-gray-600">{prompt}</span>
<button onClick={() => { setAsking(false); onConfirm(); }} className="font-medium text-red-600 hover:underline">{confirmLabel}</button>
<button onClick={() => setAsking(false)} className="text-gray-500 hover:underline">Cancel</button>
</span>
);
}
return (
<button onClick={() => setAsking(true)} className={className} title={title} disabled={disabled}>
{children}
</button>
);
}
13 changes: 8 additions & 5 deletions src/client/pages/accounts.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useEffect, useState } from "react";
import { ConfirmButton } from "../notice";
import { refused } from "../refusal";

interface AccountNode {
rgs_code: string;
Expand Down Expand Up @@ -35,9 +37,8 @@ export function AccountsPage() {
}

async function clearAll() {
if (!confirm("Clear all accounts?")) return;
setLoading(true);
await fetch("/api/accounts", { method: "DELETE" });
await refused(await fetch("/api/accounts", { method: "DELETE" }));
await load();
setLoading(false);
}
Expand All @@ -56,13 +57,15 @@ export function AccountsPage() {
{count === 0 ? "Load starter chart" : "Reload starter chart"}
</button>
{count !== null && count > 0 && (
<button
onClick={clearAll}
<ConfirmButton
prompt="Clear all accounts?"
confirmLabel="Clear"
onConfirm={clearAll}
disabled={loading}
className="px-3 py-1.5 rounded-lg border border-gray-200 text-sm text-gray-600 hover:bg-gray-50 disabled:opacity-50"
>
Clear
</button>
</ConfirmButton>
)}
{count !== null && (
<span className="text-xs text-gray-400 ml-auto">{count} accounts</span>
Expand Down
6 changes: 3 additions & 3 deletions src/client/pages/invoice-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
import { ConfirmButton, notify } from "../notice";
import { refused } from "../refusal";
import { Link, navigate } from "../router";

Expand Down Expand Up @@ -168,7 +169,7 @@ export function InvoiceEditorPage({ id }: { id: number }) {

async function issue() {
if (invoice!.lines.length === 0) {
alert("Add at least one line before issuing.");
notify("Add at least one line before issuing.");
return;
}
const res = await fetch(`/api/invoices/${id}/issue`, { method: "POST" });
Expand All @@ -187,7 +188,6 @@ export function InvoiceEditorPage({ id }: { id: number }) {
}

async function remove() {
if (!confirm("Delete this draft?")) return;
const res = await fetch(`/api/invoices/${id}`, { method: "DELETE" });
if (await refused(res)) return;
navigate("/invoices");
Expand Down Expand Up @@ -380,7 +380,7 @@ export function InvoiceEditorPage({ id }: { id: number }) {
<button onClick={() => setStatus("cancelled")} className="px-3 py-1.5 rounded-lg border border-gray-200 text-sm text-gray-600 hover:bg-gray-50">Cancel</button>
)}
{invoice.status === "draft" && (
<button onClick={remove} className="ml-auto px-3 py-1.5 rounded-lg border border-red-200 text-sm text-red-600 hover:bg-red-50">Delete</button>
<span className="ml-auto"><ConfirmButton prompt="Delete this draft?" onConfirm={remove} className="px-3 py-1.5 rounded-lg border border-red-200 text-sm text-red-600 hover:bg-red-50">Delete</ConfirmButton></span>
)}
</section>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/client/pages/invoices.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
import { ConfirmButton } from "../notice";
import { refused } from "../refusal";
import { Link, navigate } from "../router";

Expand Down Expand Up @@ -74,7 +75,6 @@ export function InvoicesPage() {
}

async function remove(id: number) {
if (!confirm("Delete this draft (and all lines)?")) return;
const res = await fetch(`/api/invoices/${id}`, { method: "DELETE" });
if (await refused(res)) return;
load();
Expand Down Expand Up @@ -170,7 +170,7 @@ export function InvoicesPage() {
</button>
)}
{inv.status === "draft" && (
<button onClick={() => remove(inv.id)} className="text-gray-300 hover:text-red-600 text-lg leading-none px-1" title="Delete draft">×</button>
<ConfirmButton prompt="Delete this draft and its lines?" onConfirm={() => remove(inv.id)} className="text-gray-300 hover:text-red-600 text-lg leading-none px-1" title="Delete draft">×</ConfirmButton>
)}
</div>
</li>
Expand Down
3 changes: 2 additions & 1 deletion src/client/pages/journals.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
import { notify } from "../notice";

interface JournalLine {
id: number;
Expand Down Expand Up @@ -54,7 +55,7 @@ export function JournalsPage() {
const data: { created: number } = await res.json();
setBackfilling(false);
if (data.created > 0) await load();
alert(`Backfilled ${data.created} journal ${data.created === 1 ? "entry" : "entries"}.`);
notify(`Backfilled ${data.created} journal ${data.created === 1 ? "entry" : "entries"}.`);
}

const totalDebit = trial.reduce((s, r) => s + r.debit_cents, 0);
Expand Down
Loading