|
1 | 1 | <p align="center"> |
2 | | - <p align="center"> |
3 | | - <img src="https://github.com/user-attachments/assets/197c404c-06b1-4fd4-8a26-624f1d481966" width="140" height="140" /> |
4 | | - </p> |
5 | | - <p align="center"> |
6 | | - Accounting & Invoicing Extension for Fleetbase |
7 | | - </p> |
| 2 | + <a href="https://fleetbase.io"> |
| 3 | + <img src="https://github.com/user-attachments/assets/197c404c-06b1-4fd4-8a26-624f1d481966" width="120" height="120" alt="Fleetbase Ledger" /> |
| 4 | + </a> |
8 | 5 | </p> |
9 | 6 |
|
10 | | ---- |
| 7 | +<h1 align="center">Fleetbase Ledger</h1> |
| 8 | + |
| 9 | +<p align="center"> |
| 10 | + Accounting, invoicing, wallets, payments, and financial reporting for Fleetbase. |
| 11 | +</p> |
| 12 | + |
| 13 | +<p align="center"> |
| 14 | + <a href="https://github.com/fleetbase/ledger/blob/main/LICENSE.md"><img src="https://img.shields.io/badge/license-AGPL--3.0--or--later-blue.svg" alt="License: AGPL-3.0-or-later" /></a> |
| 15 | + <a href="https://github.com/fleetbase/ledger/actions/workflows/server.yml"><img src="https://github.com/fleetbase/ledger/actions/workflows/server.yml/badge.svg" alt="PHP CI" /></a> |
| 16 | + <a href="https://github.com/fleetbase/ledger/actions/workflows/ember.yml"><img src="https://github.com/fleetbase/ledger/actions/workflows/ember.yml/badge.svg" alt="Ember CI" /></a> |
| 17 | + <a href="https://packagist.org/packages/fleetbase/ledger-api"><img src="https://img.shields.io/packagist/v/fleetbase/ledger-api.svg" alt="Packagist version" /></a> |
| 18 | + <a href="https://www.npmjs.com/package/@fleetbase/ledger-engine"><img src="https://img.shields.io/npm/v/@fleetbase/ledger-engine.svg" alt="npm version" /></a> |
| 19 | + <a href="https://www.fleetbase.io/docs/ledger"><img src="https://img.shields.io/badge/docs-ledger-111827.svg" alt="Ledger documentation" /></a> |
| 20 | +</p> |
| 21 | + |
| 22 | +<p align="center"> |
| 23 | + <a href="https://www.fleetbase.io/images/screenshots/ledger/ledger-dashboard.webp"> |
| 24 | + <img src="https://www.fleetbase.io/images/screenshots/ledger/ledger-dashboard.webp" alt="Fleetbase Ledger dashboard" /> |
| 25 | + </a> |
| 26 | +</p> |
11 | 27 |
|
12 | 28 | ## Overview |
13 | 29 |
|
14 | | -This monorepo contains both the frontend and backend components of the Ledger extension for Fleetbase. The frontend is built using Ember.js and the backend is implemented in PHP. |
| 30 | +Ledger is the finance and billing extension for Fleetbase. It adds a complete financial management layer to the Fleetbase console, including double-entry bookkeeping, customer invoicing, invoice templates, digital wallets, payment gateway processing, immutable transaction history, and standard financial reports. |
15 | 31 |
|
16 | | -* PHP 7.3.0 or above |
17 | | -* Ember.js v4.8 or above |
18 | | -* Ember CLI v4.8 or above |
19 | | -* Node.js v18 or above |
| 32 | +Ledger ships as both a Laravel package and an Ember engine. The backend package provides the accounting models, services, routes, gateway drivers, events, observers, migrations, and console commands. The frontend engine provides the Ledger console experience for billing, payments, accounting, reports, and settings. |
20 | 33 |
|
21 | | -## Structure |
| 34 | +Ledger is included with standard Fleetbase installations. See the [Fleetbase Ledger documentation](https://www.fleetbase.io/docs/ledger) for the product guide, concepts, and setup walkthroughs. |
22 | 35 |
|
23 | | -``` |
24 | | -├── addon |
25 | | -├── app |
26 | | -├── assets |
27 | | -├── translations |
28 | | -├── config |
29 | | -├── node_modules |
30 | | -├── server |
31 | | -│ ├── config |
32 | | -│ ├── data |
33 | | -│ ├── migrations |
34 | | -│ ├── resources |
35 | | -│ ├── src |
36 | | -│ ├── tests |
37 | | -│ └── vendor |
38 | | -├── tests |
39 | | -├── testem.js |
40 | | -├── index.js |
41 | | -├── package.json |
42 | | -├── phpstan.neon.dist |
43 | | -├── phpunit.xml.dist |
44 | | -├── pnpm-lock.yaml |
45 | | -├── ember-cli-build.js |
46 | | -├── composer.json |
47 | | -├── CONTRIBUTING.md |
48 | | -├── LICENSE.md |
49 | | -├── README.md |
50 | | -``` |
| 36 | +## Contents |
| 37 | + |
| 38 | +- [Features](#features) |
| 39 | +- [Architecture](#architecture) |
| 40 | +- [Requirements](#requirements) |
| 41 | +- [Installation](#installation) |
| 42 | +- [Development](#development) |
| 43 | +- [API and Extension Points](#api-and-extension-points) |
| 44 | +- [Documentation](#documentation) |
| 45 | +- [Contributing](#contributing) |
| 46 | +- [Security](#security) |
| 47 | +- [License](#license) |
| 48 | + |
| 49 | +## Features |
| 50 | + |
| 51 | +### Accounting |
| 52 | + |
| 53 | +- Chart of accounts for asset, liability, equity, revenue, and expense accounts. |
| 54 | +- Double-entry journal entries with debit and credit accounts. |
| 55 | +- Cached account balances with recalculation support. |
| 56 | +- General ledger views per account and across the company. |
| 57 | +- System-created and manual journal entries for operational accounting workflows. |
| 58 | + |
| 59 | +### Billing and Invoicing |
| 60 | + |
| 61 | +- Customer invoices with line items, tax, subtotal, total, balance, due date, notes, and terms. |
| 62 | +- Invoice lifecycle support for draft, sent, viewed, paid, overdue, cancelled, refunded, and void states. |
| 63 | +- Invoice templates with company branding and registered template context variables. |
| 64 | +- Invoice previews, rendered PDFs, invoice emails, and public customer invoice pages. |
| 65 | +- Manual payment recording and invoice transaction history. |
| 66 | +- Fleet-Ops purchase-rate integration for automatically generating draft invoices from orders. |
| 67 | + |
| 68 | +### Wallets and Transactions |
| 69 | + |
| 70 | +- Digital wallets for companies, users, customers, drivers, and other Fleetbase subjects. |
| 71 | +- Wallet operations for top-ups, credits, transfers, payouts, freezes, unfreezes, and recalculation. |
| 72 | +- Atomic balance changes through `WalletService`. |
| 73 | +- Immutable transaction records for wallet activity, payment activity, and operational money movement. |
| 74 | +- Direction-aware transaction history for credits, debits, deposits, payouts, transfers, refunds, and reversals. |
| 75 | + |
| 76 | +### Payment Gateways |
| 77 | + |
| 78 | +- Built-in gateway drivers for Stripe, QPay, and Cash/manual payments. |
| 79 | +- Gateway configuration with encrypted credentials at rest. |
| 80 | +- Sandbox and live environments. |
| 81 | +- Purchases, refunds, setup intents, tokenization where supported, and gateway transaction history. |
| 82 | +- Public gateway webhook endpoint with driver-level signature verification. |
| 83 | +- Idempotent gateway processing through `GatewayTransaction` records. |
| 84 | + |
| 85 | +### Reports and Dashboard |
| 86 | + |
| 87 | +- Financial dashboard with KPIs, revenue trends, cash flow summaries, invoice status, AR aging, wallet balances, and activity. |
| 88 | +- Standard financial reports for balance sheet, income statement, cash flow statement, trial balance, AR aging, wallet summary, and general ledger. |
| 89 | +- Report services built around double-entry accounting data and Fleetbase transaction records. |
| 90 | + |
| 91 | +### Fleetbase Integrations |
| 92 | + |
| 93 | +- Fleet-Ops integration for purchase-rate invoice creation and order accounting. |
| 94 | +- Storefront integration for direct storefront sale journal entries. |
| 95 | +- Company and user observers that provision default accounts and wallets automatically. |
| 96 | +- Invoice, payment, and accounting settings inside the Fleetbase console. |
| 97 | + |
| 98 | +## Architecture |
| 99 | + |
| 100 | +Ledger is split into two distributable packages: |
| 101 | + |
| 102 | +| Package | Runtime | Description | |
| 103 | +| --- | --- | --- | |
| 104 | +| [`fleetbase/ledger-api`](https://packagist.org/packages/fleetbase/ledger-api) | Laravel / PHP | Backend models, routes, services, migrations, gateway drivers, observers, events, resources, reports, and console commands. | |
| 105 | +| [`@fleetbase/ledger-engine`](https://www.npmjs.com/package/@fleetbase/ledger-engine) | Ember | Fleetbase console engine for the Ledger dashboard, billing, payments, accounting, reports, and settings screens. | |
| 106 | + |
| 107 | +Backend routes are mounted under the configured Ledger API prefix, which defaults to `ledger`. |
| 108 | + |
| 109 | +| Route group | Authentication | Purpose | |
| 110 | +| --- | --- | --- | |
| 111 | +| `POST /ledger/webhooks/{driver}` | Public, driver verified | Payment gateway webhook callbacks. | |
| 112 | +| `/ledger/public/invoices/{public_id}` | Public | Customer invoice view, gateway list, and payment flow. | |
| 113 | +| `/ledger/v1/wallet/*` | API key | Customer and driver wallet API endpoints. | |
| 114 | +| `/ledger/int/v1/*` | Fleetbase session | Console APIs for accounts, invoices, journals, wallets, transactions, gateways, settings, and reports. | |
| 115 | + |
| 116 | +The Ember engine mounts at the Fleetbase extension route `ledger` and exposes console sections for billing, payments, accounting, reports, and settings. |
| 117 | + |
| 118 | +## Requirements |
| 119 | + |
| 120 | +- PHP `^8.0` |
| 121 | +- Composer |
| 122 | +- Fleetbase Core API |
| 123 | +- Fleetbase FleetOps API |
| 124 | +- Node.js `>=18` |
| 125 | +- pnpm |
| 126 | +- Ember CLI compatible with the workspace |
51 | 127 |
|
52 | 128 | ## Installation |
53 | 129 |
|
54 | | -### Backend |
| 130 | +Ledger comes pre-installed with Fleetbase. In a standard Fleetbase instance, open the console sidebar and navigate to Ledger to begin. Default accounts and wallets are provisioned automatically for new companies and users. |
55 | 131 |
|
56 | | -Install the PHP packages using Composer: |
| 132 | +For package-level installation: |
57 | 133 |
|
58 | 134 | ```bash |
59 | | -composer require fleetbase/core-api |
60 | | -composer require fleetbase/fleetops-api |
61 | 135 | composer require fleetbase/ledger-api |
62 | 136 | ``` |
63 | | -### Frontend |
64 | | - |
65 | | -Install the Ember.js Engine/Addon: |
66 | 137 |
|
67 | 138 | ```bash |
68 | 139 | pnpm install @fleetbase/ledger-engine |
69 | 140 | ``` |
70 | 141 |
|
71 | | -## Usage |
| 142 | +If you are adding Ledger to an existing Fleetbase installation, run migrations through your normal Fleetbase deployment flow, then provision defaults for existing records: |
| 143 | + |
| 144 | +```bash |
| 145 | +php artisan ledger:provision |
| 146 | +``` |
| 147 | + |
| 148 | +## Development |
| 149 | + |
| 150 | +### Fleetbase workspace linking |
72 | 151 |
|
73 | | -### Backend |
| 152 | +When working on Ledger inside a full Fleetbase checkout, use Fleetbase's package linker from the repository root instead of hand-editing `console/package.json`, `api/composer.json`, or `console/pnpm-workspace.yaml`. |
| 153 | + |
| 154 | +Install the linker once from the Fleetbase repository root: |
74 | 155 |
|
75 | | -🧹 Keep a modern codebase with **PHP CS Fixer**: |
76 | 156 | ```bash |
77 | | -composer lint |
| 157 | +npm link |
78 | 158 | ``` |
79 | 159 |
|
80 | | -⚗️ Run static analysis using **PHPStan**: |
| 160 | +Enable Ledger as a local development package: |
| 161 | + |
81 | 162 | ```bash |
82 | | -composer test:types |
| 163 | +flb-package-linker enable ledger |
| 164 | +flb-package-linker install ledger |
83 | 165 | ``` |
84 | 166 |
|
85 | | -✅ Run unit tests using **PEST** |
| 167 | +Use `--install` to let the linker run the required package-manager commands immediately: |
| 168 | + |
86 | 169 | ```bash |
87 | | -composer test:unit |
| 170 | +flb-package-linker enable ledger --install |
88 | 171 | ``` |
89 | 172 |
|
90 | | -🚀 Run the entire test suite: |
| 173 | +Check link state with: |
| 174 | + |
91 | 175 | ```bash |
92 | | -composer test |
| 176 | +flb-package-linker status |
| 177 | +flb-package-linker doctor |
93 | 178 | ``` |
94 | 179 |
|
95 | | -### Frontend |
| 180 | +See the [Fleetbase development setup guide](https://www.fleetbase.io/docs/platform/quickstart/development-setup) for Docker mounts, local Ember dev server setup, package-linker details, and unlink/reset commands. Fleetbase runs Laravel Octane, so reload the API worker after PHP changes: |
96 | 181 |
|
97 | | -🧹 Keep a modern codebase with **ESLint**: |
98 | 182 | ```bash |
99 | | -pnpm lint |
| 183 | +docker compose exec application php artisan octane:reload |
100 | 184 | ``` |
101 | 185 |
|
102 | | -✅ Run unit tests using **Ember/QUnit** |
| 186 | +### Package-level development |
| 187 | + |
| 188 | +Install dependencies: |
| 189 | + |
103 | 190 | ```bash |
104 | | -pnpm test |
105 | | -pnpm test:ember |
106 | | -pnpm test:ember-compatibility |
| 191 | +composer install |
| 192 | +pnpm install |
107 | 193 | ``` |
108 | 194 |
|
109 | | -🚀 Start the Ember Addon/Engine |
| 195 | +Run the Ember engine locally: |
| 196 | + |
110 | 197 | ```bash |
111 | 198 | pnpm start |
112 | 199 | ``` |
113 | 200 |
|
114 | | -🔨 Build the Ember Addon/Engine |
| 201 | +Frontend checks: |
| 202 | + |
115 | 203 | ```bash |
| 204 | +pnpm lint |
| 205 | +pnpm test |
116 | 206 | pnpm build |
117 | 207 | ``` |
118 | 208 |
|
| 209 | +Backend checks: |
| 210 | + |
| 211 | +```bash |
| 212 | +composer test:lint |
| 213 | +composer test:types |
| 214 | +composer test:unit |
| 215 | +composer test |
| 216 | +``` |
| 217 | + |
| 218 | +Ledger Artisan commands: |
| 219 | + |
| 220 | +```bash |
| 221 | +php artisan ledger:provision |
| 222 | +php artisan ledger:backfill-direction |
| 223 | +php artisan ledger:update-overdue-invoices |
| 224 | +``` |
| 225 | + |
| 226 | +`ledger:provision` is idempotent and can target all companies, one company, accounts only, or wallets only. `ledger:backfill-direction` fills missing transaction directions on older transaction rows. `ledger:update-overdue-invoices` marks sent or viewed invoices as overdue when their due date has passed. |
| 227 | + |
| 228 | +## API and Extension Points |
| 229 | + |
| 230 | +Ledger exposes backend services for accounting, wallets, invoices, and payments: |
| 231 | + |
| 232 | +- `LedgerService` creates double-entry journal entries and powers financial reports. |
| 233 | +- `WalletService` manages wallet provisioning and balance-changing operations. |
| 234 | +- `InvoiceService` creates and manages invoices, including order-based invoice creation. |
| 235 | +- `PaymentService` coordinates gateway charges, refunds, setup intents, events, and gateway transaction persistence. |
| 236 | +- `PaymentGatewayManager` resolves and initializes configured payment gateway drivers. |
| 237 | + |
| 238 | +Custom payment gateways can extend `AbstractGatewayDriver` and implement the `GatewayDriverInterface` contract. Gateway drivers provide a code, name, capability list, configuration schema, purchase/refund behavior, and optional webhook or tokenization support. |
| 239 | + |
| 240 | +Ledger also registers invoice template context variables with Fleetbase's template rendering system so invoice templates can reference invoice, transaction, account, and wallet data during rendering. |
| 241 | + |
| 242 | +## Documentation |
| 243 | + |
| 244 | +- [Ledger documentation](https://www.fleetbase.io/docs/ledger) |
| 245 | +- [Core concepts](https://www.fleetbase.io/docs/ledger/getting-started/core-concepts) |
| 246 | +- [Payment gateways](https://www.fleetbase.io/docs/ledger/payments/gateways) |
| 247 | +- [Adding a payment gateway driver](https://www.fleetbase.io/docs/extension-development/recipes/adding-a-payment-gateway-driver) |
| 248 | +- [Fleetbase development setup](https://www.fleetbase.io/docs/platform/quickstart/development-setup) |
| 249 | + |
119 | 250 | ## Contributing |
120 | | -See the Contributing Guide for details on how to contribute to this project. |
| 251 | + |
| 252 | +Contributions are welcome. Please read the [contributing guide](CONTRIBUTING.md) before opening a pull request. |
| 253 | + |
| 254 | +For local changes, keep frontend and backend checks focused on the area you touched and include relevant test output in your pull request. |
| 255 | + |
| 256 | +## Security |
| 257 | + |
| 258 | +Please do not report security issues in public GitHub issues. Contact Fleetbase at [hello@fleetbase.io](mailto:hello@fleetbase.io) with details so the team can coordinate a responsible fix. |
121 | 259 |
|
122 | 260 | ## License |
123 | | -This project is licensed under the MIT License. |
| 261 | + |
| 262 | +Fleetbase Ledger is open-source software licensed under the [AGPL-3.0-or-later](LICENSE.md). |
0 commit comments