s-mcdonald / luca-accounts
Double Entry Transactions for PHP
1.4.2
2023-05-05 12:04 UTC
Requires
- php: ^8.1
Requires (Dev)
- mockery/mockery: 1.5.1
- phpunit/phpunit: ^10
This package is auto-updated.
Last update: 2024-09-05 14:49:28 UTC
README
Luca Accounting is a Double Entry Accounting
system that can easily be implemented into your application.
It validates and sorts transactions prior to committing them to your Database.
// Create a Transaction $txn = new Transaction( $date , 'Capital Contribution', [ new TransactionLine($cash_account_1, 100.00, 00.00), new TransactionLine($eqty_account_2, 00.00, 100.00), ] ); // Process the Transaction $system->transact($txn);
Documentation
Features
- Follows Double Entry based accounting rules.
- Built-in validation of transactions.
- Sorts transaction (Dr|Cr) entries automatically prior to committing to the db.
- Separate Debit and Credit entries.
Installation
Via Composer. Run the following command from your project's root.
composer require s-mcdonald/luca-accounts
Dependencies
- Php 8.1
Quick-Start
- Extend the abstract
AccountSystem
class and then Implement theAccountInterface
to yourAccount
model or entity.
// Your\App\AccountSystem.php class AccountSystem extends \SamMcDonald\LucaAccounts\AbstractAccountSystem { ... } // Your\App\Account.php class Account implements \SamMcDonald\LucaAccounts\Contracts\AccountInterface { ... }
Example
<?php namespace Your\App; use Your\App\AccountSystem; use SamMcDonald\LucaAccounts\Components\Transaction; use SamMcDonald\LucaAccounts\Components\TransactionLine; class YourAccountingProgram { public static function simpleTransaction() { // Get a new instance of the Accounting System $system = new AccountSystem(); // Register the transact function $system->register('transact', static function(Transaction $txn) { // Your logic to commit the transaction to DB }); /* * Load the accounts you want to use in the Transaction. * This will most likely be a Model or Entity object. */ $acc1 = Account::fetch('cash-account'); $acc2 = Account::fetch('acc-rec-account'); $acc3 = Account::fetch('inventory-account'); /* * Make a purchase of stock request */ $txn = new Transaction( new DateTimeImmutable('now') , 'Purchase of inventory', [ new TransactionLine($acc1, 000.00, 50.00), new TransactionLine($acc2, 000.00, 150.00), new TransactionLine($acc3, 200.00, 0.00), ] ); /* * Perform the transaction */ $system->transact($txn); } }
Files
s-mcdonald/luca-accounts/
│
└ src/
│
├── Components/
│ │
│ ├── Transaction.php
│ │
│ └── TransactionLine.php
│
│
├── Contracts/
│ │
│ ├── AccountInterface.php
│ │
│ ├── TransactionInterface.php
│ │
│ └── TransactionLineInterface.php
│
│
├── Exceptions/
│ │
│ └── DoubleEntryException.php
│ │
│ └── InvalidTransactionLineEntryException.php
│
│
├── Enums/
│ │
│ └── AccountType.php
│
├── Util/
│ │
│ └── EntryFormatter.php
│
│
└── AbstractAccountSystem.php
License
Luca-Accounts is licensed under the terms of the MIT License (See LICENSE file for details).
Name of Luca
Luca-Accounting was named after Luca Pacioli (The father of Accounting). He popularized the DoubleEntry book-keeping system.