Commit graph

30 commits

Author SHA1 Message Date
35d2057694 Adds comprehensive documentation and patterns
Provides detailed documentation for the Castle Accounting extension, including architecture, transaction flows, balance calculation, API endpoints, and future improvements.

Documents design patterns inspired by Beancount, such as immutable data structures, plugin architecture, and balance assertions, with recommendations for adoption in the Castle extension.

Includes an implementation roadmap, security considerations, performance considerations, and a migration path for existing data.
2025-10-22 23:38:05 +02:00
900ddb553b Adds payable/receivable badges to entries
Improves clarity by displaying "Payable" or "Receivable" badges on entries
in the transaction list.

The badge color depends on whether the user is a superuser, indicating
the direction of the transaction from the user's perspective.
This helps users quickly understand which transactions are owed to them
and which they owe.
2025-10-22 18:46:41 +02:00
d302023477 Enhances user balance display with username
Improves the display of user balances in the admin panel by including the username alongside the user ID. This provides a more user-friendly and easily identifiable representation of user data.

The username is fetched from the user table, and if no username is set the first 16 characters of the user id is shown.
2025-10-22 18:35:19 +02:00
224d520d84 Uses wallet's user ID for account creation
Ensures that account creation utilizes the user ID
associated with the wallet, rather than directly
relying on the wallet identifier. This aligns account
ownership more accurately.
2025-10-22 18:34:51 +02:00
ed38411fc4 Enforces super user role for admin endpoints
Ensures that only the super user can access and modify manual payment requests via the admin API endpoints. This enhances security by preventing unauthorized access to sensitive administrative functions.

Removes dependency on `check_super_user` helper function, instead directly comparing the wallet user with the configured super user in lnbits settings.
2025-10-22 18:19:52 +02:00
246c0a5237 Renames database migration functions.
Renames database migration functions to correct a numbering error.

The original migration `m002_add_metadata_column` was removed in a previous commit,
but the subsequent migrations were not renamed to reflect this, leading to
incorrect numbering. This change corrects the function names to ensure
proper sequential execution during database migrations.
2025-10-22 18:19:46 +02:00
c2d9b39f29 Adds manual payment request functionality
Enables users to request manual payments from the Castle and provides admin functions to approve or reject these requests.

Introduces the `manual_payment_requests` table and related CRUD operations.
Adds API endpoints for creating, retrieving, approving, and rejecting manual payment requests.
Updates the UI to allow users to request payments and for admins to review pending requests.
2025-10-22 18:02:07 +02:00
3a26d963dc Improves super user balance and journal views
For super users, the balance view now displays the net position
(liabilities - receivables) of the Castle. The journal view
shows all entries across all users.

The settings are now loaded first to determine if the user is a
super user.
2025-10-22 17:51:41 +02:00
d7b5259b74 Adds "Pending Payment" badge for receivables
Improves user experience by visually indicating entries that represent outstanding payments owed by users.

This change introduces a "Pending Payment" badge for receivable entries in the transaction list. A receivable entry is determined by checking if the entry contains a debit line item against an account receivable account. This provides immediate visual feedback to the user, highlighting transactions requiring their action.
2025-10-22 17:10:14 +02:00
6d5243b03e Filters journal entries by user account
Updates journal entry retrieval to filter entries based on
the user's accounts rather than the user ID.

This ensures that users only see journal entries that
directly affect their accounts.

Also displays fiat amount in journal entries if available in
the metadata.
2025-10-22 17:08:39 +02:00
b0705fc24a Adds fiat currency balances to user balances
Extends user balance information to include fiat currency balances,
calculated based on entry line metadata and account types.

This allows for a more comprehensive view of user balances,
including both satoshi and fiat currency holdings.

Updates the castle index template and API to display fiat balances.
2025-10-22 16:56:13 +02:00
be386f60ef Fixes payment polling issues
Improves the reliability of payment status updates by ensuring that the payment polling interval is properly cleared when a payment dialog is closed, when a payment is submitted, or when a new payment dialog is opened. This prevents multiple polling intervals from running simultaneously, which could lead to incorrect payment status updates.

Adds a watch to clear interval when the pay dialog closes.
2025-10-22 16:56:07 +02:00
854164614f Enables balance payments via invoice
Adds functionality for users to pay their Castle balance by generating and paying a Lightning invoice.
This includes:
- Adding API endpoints for invoice generation and payment recording.
- Updating the frontend to allow users to initiate the invoice payment process.
- Passing the wallet's `inkey` to the frontend for payment status checks.
2025-10-22 16:48:13 +02:00
ef3e2d9e0d Adds balance payment feature
Implements a feature that allows users to pay their outstanding balance via Lightning.

The changes include:
- Adds the UI elements for invoice generation and display, including QR code.
- Integrates backend endpoints to generate and record payments.
- Adds polling mechanism to track payments and update balance.
- Creates new database models to support manual payment requests.
2025-10-22 16:46:46 +02:00
eb9a3c1600 Replaces user wallet ID with user ID
Updates the receivable entry model and related API endpoints to use the user's ID instead of the user's wallet ID.

This change simplifies user identification and ensures consistency throughout the application.
2025-10-22 16:27:16 +02:00
2a14dd2e62 Adds receivable entry functionality
Implements the ability to record receivables (user owes the castle).

Adds API endpoint for creating receivable entries, which includes currency conversion to satoshis if fiat currency is provided.

Integrates a UI component (receivable dialog) for superusers to record debts owed by users, enhancing financial tracking capabilities.
2025-10-22 16:16:36 +02:00
b7e4e05469 Adds super user balance overview
Implements functionality for super users to view a breakdown of outstanding balances for all users.

This includes:
- Adding an API endpoint to fetch all user balances.
- Updating the frontend to display these balances in a table, accessible only to super users.
- Modifying the balance calculation for the current user to reflect the total owed by or to the castle for super users.

This provides super users with a comprehensive view of the castle's financial position.
2025-10-22 15:24:50 +02:00
cb7e4ee555 Enhances super user experience with Castle wallet
Simplifies the user experience for super users by automatically using the Castle wallet for transactions, removing the need to configure a separate user wallet.

This change streamlines the workflow for super users by:
- Automatically assigning the Castle wallet to super users
- Hiding the user wallet configuration options in the UI
- Reloading user wallet settings to reflect the Castle wallet
2025-10-22 15:11:00 +02:00
f1ada5e290 Changes castle wallet to a select field.
Updates the castle wallet ID input to a select field populated with available wallet options.
This change improves usability by providing a predefined list of wallet options.
It also disables the save button if no wallet is selected.
2025-10-22 15:10:52 +02:00
bb1dbcccd8 Adds per-user wallet configuration
Allows users to configure their own wallet ID, enabling
the system to track expenses and receivables on a per-user basis.

Introduces new database table, models, API endpoints, and UI elements
to manage user-specific wallet settings.
2025-10-22 14:54:25 +02:00
31344607c6 Adds super user and config setup
Adds super user role to restrict settings changes.

Improves the settings screen to only allow super users to make modifications.

Adds a warning banner if the Castle wallet is not configured.

Changes admin key to inkey for fetching settings.
This fixes an issue where settings weren't accessible.

Adds a validation to require the Castle wallet ID when updating settings.
2025-10-22 14:45:18 +02:00
29983cedb7 Adds user settings for the Castle extension
Adds functionality to configure the Castle extension, including a wallet ID.

This allows administrators to customize the extension's behavior by specifying a dedicated wallet for castle operations.
2025-10-22 13:55:52 +02:00
ceabf96f79 Adds metadata column to entry_lines table
Adds a metadata column to the entry_lines table.

This column will store currency conversion data as JSON, allowing for future flexibility in handling different types of metadata.
2025-10-22 13:48:51 +02:00
15da11a606 Stores and retrieves entry line metadata as JSON
Updates journal entry creation to store entry line metadata as a JSON string in the database.

Updates entry line retrieval to parse the JSON string back into a metadata object.

This change allows storing more complex data structures in the metadata field.
2025-10-22 13:45:59 +02:00
e95230c0f4 Consolidates API route prefixes
Removes redundant "/api/v1" prefixes from API router definitions in the backend and updates the corresponding API calls in the frontend. This change streamlines the API structure and improves code maintainability. Additionally, adds console logs in the frontend to aid in debugging the API calls.
2025-10-22 13:38:26 +02:00
cd083114b4 Adds fiat currency support for expenses
Extends expense entry functionality to support fiat currencies.

Users can now specify a currency (e.g., EUR, USD) when creating expense entries. The specified amount is converted to satoshis using exchange rates. The converted amount and currency information are stored in the journal entry metadata. Also adds an API endpoint to retrieve allowed currencies and updates the UI to allow currency selection when creating expense entries.
2025-10-22 13:32:10 +02:00
4bd83d6937 Enhances expense and pay dialogs
Improves the UI of the "Add Expense" and "Pay Balance" dialogs by using `q-input` and `q-select` components with `filled` and `dense` properties.

This provides a cleaner and more modern look and feel.
Ensures dialog content is only rendered when the dialog is visible.
2025-10-22 13:10:33 +02:00
5589d813f0 Simplifies database queries and updates auth
Removes the `castle.` prefix from database table names in queries, streamlining data access.

Updates authentication to use `WalletTypeInfo` dependency injection for retrieving wallet information. This improves security and aligns with LNBits' authentication patterns. Also modifies the main router's tag to uppercase.
2025-10-22 12:52:52 +02:00
cdd0cda001 Fix for sqlite3 : Removes schema from database migrations
Removes the "castle." schema prefix from database table creation and index definitions in the migration file.

This change enhances database portability by allowing the application to function correctly with different database configurations.
2025-10-22 12:52:46 +02:00
95b8af2360 initial commit 2025-10-22 12:33:45 +02:00