30
JunThis package is very beneficial for developing debit/credit accounting journals that render a simple drop-in trait to manage accruing balances for a given model. It can also be employed to create double entry-based projects where you would want to credit one journal and debit another. It acknowledges you to keep line-item balances historical debits and credits on a per-model object basis.
It also enables you to trace per-line-item memos and reference a foreign class object directly. Its version v0.2.0 permits you to utilize a “ledger” system that makes it feasible to run queries against expense, income. Another peculiarity is that it provides you an environment in which you can build out a double-entry system. It doesn’t replace any financial recording system which you may be using.
To get started, install the package through Composer:
composer require "scottlaurent/accounting"
After installation, you’ve to publish the package configuration.
php artisan vendor:publish
It will install 3 new tables in your database.
Append the trait to any model that you want to retain for a journal.
Mostly you will want to append the $model->initJournal() into the static::created() method of your model so that a journal is built when you create the model object itself.
If you are using double-entry, then you’ve to append Scottlaurent\Accounting\Services\Accounting::class to your service providers
// locate a user (or any Model that implementes the AccountingJournal trait)
$user = User::find(1);
// locate a product (optional)
$product = Product::find(1)
// init a journal for this user (do this only once)
$user->initJournal();
// credit the user and reference the product
$transaction_1 = $user->journal->creditDollars(100);
$transaction_1->referencesObject($product);
// check our balance (should be 100)
$current_balance = $user->journal->getCurrentBalanceInDollars();
// debit the user
$transaction_2 = $user->journal->debitDollars(75);
// check our balance (should be 25)
$current_balance = $user->journal->getCurrentBalanceInDollars();
//get the product referenced in the journal (optional)
$product_copy = $transaction_1->getReferencedObject()
The trait consists of functions to initialize a new journal for your model object and b) to return that journal. Generally, systems have one journal per user or account and one general journal for the company if they are practicing a double-entry system.
This accounting system utilizes the Money PHP class which directs with indivisible currency. For example, the unified currency of USD is the penny. So $1 equals 100 penny. This prevents loss of currency by division/rounding errors.
For more details, you can view its full documentation here.
scottlaurent / accounting
Published at : 30-06-2021
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project