ttbooking / accounting
Accounting library
Requires
- php: ^8.0
- illuminate/contracts: ^9.31 || ^10.0 || ^11.0
- illuminate/database: ^9.31 || ^10.0 || ^11.0
- illuminate/support: ^9.31 || ^10.0 || ^11.0
- moneyphp/money: ^4.0
- ramsey/uuid: ^4.2.2
- ttbooking/castable-money: ^1.0
- ttbooking/class-factory: ^1.0
- ttbooking/entity-locator: *
- ttbooking/money-serializer: ^1.0
Requires (Dev)
- orchestra/testbench: ^7.0 || ^8.0 || ^9.0
- phpunit/phpunit: ^9.5.10 || ^10.0 || ^11.0
Suggests
- illuminate/console: Required to control cash flow via console commands (^9.31 || ^10.0 || ^11.0).
- illuminate/events: Required to utilize transaction events (^9.31 || ^10.0 || ^11.0).
- dev-master
- v0.0.106
- v0.0.105
- v0.0.104
- v0.0.103
- v0.0.102
- v0.0.101
- v0.0.100
- v0.0.99
- v0.0.98
- v0.0.97
- v0.0.96
- v0.0.95
- v0.0.94
- v0.0.93
- v0.0.92
- v0.0.91
- v0.0.90
- v0.0.89
- v0.0.88
- v0.0.87
- v0.0.86
- v0.0.85
- v0.0.84
- v0.0.83
- v0.0.82
- v0.0.81
- v0.0.80
- v0.0.79
- v0.0.78
- v0.0.77
- v0.0.76
- v0.0.75
- v0.0.74
- v0.0.73
- v0.0.72
- v0.0.71
- v0.0.70
- v0.0.69
- v0.0.68
- v0.0.67
- v0.0.66
- v0.0.65
- v0.0.64
- v0.0.63
- v0.0.62
- v0.0.61
- v0.0.60
- v0.0.59
- v0.0.58
- v0.0.57
- v0.0.56
- v0.0.55
- v0.0.54
- v0.0.53
- v0.0.52
- v0.0.51
- v0.0.50
- v0.0.49
- v0.0.48
- v0.0.47
- v0.0.46
- v0.0.45
- v0.0.44
- v0.0.43
- v0.0.42
- v0.0.41
- v0.0.40
- v0.0.39
- v0.0.38
- v0.0.37
- v0.0.36
- v0.0.35
- v0.0.34
- v0.0.33
- v0.0.32
- v0.0.31
- v0.0.30
- v0.0.29
- v0.0.28
- v0.0.27
- v0.0.26
- v0.0.25
- v0.0.24
- v0.0.23
- v0.0.22
- v0.0.21
- v0.0.20
- v0.0.19
- v0.0.18
- v0.0.17
- v0.0.16
- v0.0.15
- v0.0.14
- v0.0.13
- v0.0.12
- v0.0.11
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
This package is auto-updated.
Last update: 2024-11-21 17:01:02 UTC
README
This Laravel package provides support for robust, transactional money or asset transfers between virtual accounts.
Features
- DBMS based transactions and pessimistic locking
- UUIDs for seamless integration and extension
- Big integer and arbitrary precision math support via MoneyPHP library
- Currency conversion support
- Blockchain for data integrity checking
- Complete control through console commands
Requirements
PHP 8.0 and Laravel 9.31 at least.
RDBMS with native JSON field support (recommended).
Installation
Using Composer:
$ composer require ttbooking/accounting
Configuration
After installation you'll need to configure package, in which case you have 2 options:
- via environment variables (your application's
.env
file) - using package's configuration file
If you choose second option, you'll have to copy configuration file into your app's config directory by issuing following command:
$ artisan vendor:publish --provider=TTBooking\Accounting\AccountingServiceProvider --tag=config
You can look into accounting.php
config file if you need to know more about each option and its usage.
If you need to alter database table names or modify schema, you'll also need to issue following command:
$ artisan vendor:publish --provider=TTBooking\Accounting\AccountingServiceProvider --tag=migrations
If you need to publish both config file and database migrations, you can omit "--tag" option:
$ artisan vendor:publish --provider=TTBooking\Accounting\AccountingServiceProvider
After all database-related modifications are done (if needed), you'll need to execute artisan migrate
command.
It is recommended to also configure morph map for every possible account owner entity type.
See https://laravel.com/docs/10.x/eloquent-relationships#custom-polymorphic-types for more info.
Usage
To create account and link it to existing entity, you can use Account facade (or corresponding AccountManager interface):
$account = Account::create($user);
... will create account for user $user
.
To find existing account by its owner, try this:
$account = Account::find($user);
... will find account of $user
if it exists or fail otherwise.
Note: it won't fail if you've enabled account auto-creation. Instead, it will create missing account.
To transfer money between two accounts, you can use Transaction facade (or corresponding TransactionManager interface):
$transaction = Transaction::create($account1, $account2, new Money(10000, new Currency('USD')));
... will create transaction for transferring $100 from $account1
to $account2
.
When you'll need to commit this transaction, just do $transaction->commit();
.
You can configure autocommit feature if separate transaction create/commit operation is not needed in your project.
To retrieve account or transaction by its UUID, try following:
$account = Account::get($uuid);
... to get account or
$transaction = Transaction::get($uuid);
... to get transaction.