PHP code example of scottlaurent / accounting
1. Go to this page and download the library: Download scottlaurent/accounting library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
scottlaurent / accounting example snippets
// 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()