PHP code example of ekmungai / eloquent-ifrs

1. Go to this page and download the library: Download ekmungai/eloquent-ifrs 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/ */

    

ekmungai / eloquent-ifrs example snippets


composer 



use IFRS\IFRSServiceProvider;

----------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not 

php artisan migrate

git clone [email protected]/ekmungai/eloquent-ifrs eloquent-ifrs
cd eloquent-ifrs
composer update

cd eloquent-ifrs
vendor/bin/phpunit

php artisan vendor:publish



use IFRS\Traits\IFRSUser;
use IFRS\Traits\Recycling;

use IFRS\Interfaces\Recyclable;
...

class User ... implements Recyclable {
  ...
  use IFRSUser;
  use Recycling;
  ...
}
...

use IFRS\Models\Entity;
use IFRS\Models\Currency;

$entity = Entity::create([
    "name" => "Example Company",
]);

//Entities orting Currency 
$entity->currency_id = $currency->id;
$entity->save();

use IFRS\Models\Vat;

$outputVat = Vat::create([
    'name' => "Standard Output Vat",
    'code' => "O",
    'rate' => 20,
    'account_id' => Account::create([
        'name' => "Sales VAT Account",
        'account_type' => Account::CONTROL,
    ])
]);

$inputVat = Vat::create([
    'name' => "Standard Input Vat",
    'code' => "I",
    'rate' => 10,
    'account_id' =>  Account::create([
        'name' => "Input VAT Account",
        'account_type' => Account::CONTROL,
    ])
]);

use IFRS\Models\Account;

$bankAccount = Account::create([
    'name' => "Bank Account",
    'account_type' => Account::BANK,
]);

$revenueAccount = Account::create([
    'name' => "Sales Account",
    'account_type' => Account::OPERATING_REVENUE,
]);

$clientAccount = Account::create([
    'name' => "Example Client Account",
    'account_type' => Account::RECEIVABLE,
]);

$supplierAccount = Account::create([
    'name' => "Example Supplier Account",
    'account_type' => Account::PAYABLE,
]);

$opexAccount = Account::create([
    'name' => "Operations Expense Account",
    'account_type' => Account::OPERATING_EXPENSE,
]);

$assetAccount = Account::create([
    'name' => "Office Equipment Account",
    'account_type' => Account::NON_CURRENT_ASSET,
]);


use IFRS\Models\ReportingPeriod;

$period = ReportingPeriod::create([
    'period_count' => 1,
    'calendar_year' => 2022,
]);


use IFRS\Transactions\CashSale;

$cashSale = CashSale::create([
    'account_id' => $bankAccount->id,
    'date' => Carbon::now(),
    'narration' => "Example Cash Sale",
]); // Intermediate save does not record the transaction in the Ledger

use IFRS\models\LineItem;

$cashSaleLineItem = LineItem::create([
    'account_id' => $revenueAccount->id,
    'narration' => "Example Cash Sale Line Item",
    'quantity' => 1,
    'amount' => 100,
]);

$cashSaleLineItem->addVat($outputVat);
$cashSale->addLineItem($cashSaleLineItem);
$cashSale->post(); // This posts the Transaction to the Ledger


use IFRS\Transactions\ClientInvoice;

$clientInvoice = ClientInvoice::create([
    'account_id' => $clientAccount->id,
    'date' => Carbon::now(),
    'narration' => "Example Credit Sale",
]);

$clientInvoiceLineItem = LineItem::create([
    'account_id' => $revenueAccount->id,
    'narration' => "Example Credit Sale Line Item",
    'quantity' => 2,
    'amount' => 50,
]);

$clientInvoiceLineItem->addVat($outputVat);
$clientInvoice->addLineItem($clientInvoiceLineItem);

//Transaction save may be skipped as post() saves the Transaction automatically
$clientInvoice->post();

use IFRS\Transactions\CashPurchase;

$cashPurchase = CashPurchase::create([
    'account_id' => $clientAccount->id,
    'date' => Carbon::now(),
    'narration' => "Example Cash Purchase",
]);

$cashPurchaseLineItem = LineItem::create([
    'account_id' => $opexAccount->id,
    'narration' => "Example Cash Purchase Line Item",
    'quantity' => 4,
    'amount' => 25,
]);


$cashPurchaseLineItem->addVat($inputVat);
$cashPurchase->addLineItem($cashPurchaseLineItem);
$cashPurchase->post();

use IFRS\Transactions\SupplierBill;

$supplierBill = SupplierBill::create([
    'account_id' => $supplierAccount->id,
    'date' => Carbon::now(),
    'narration' => "Example Credit Purchase",
]);

$supplierBillLineItem = LineItem::create([
    'vat_id' => $inputVat->id,
    'account_id' => $assetAccount->id,
    'narration' => "Example Credit Purchase Line Item",
    'quantity' => 4,
    'amount' => 25,
]);

$supplierBillLineItem->addVat($inputVat);
$supplierBill->addLineItem($supplierBillLineItem);
$supplierBill->post();

use IFRS\Transactions\ClientReceipt;

$clientReceipt = ClientReceipt::create([
    'account_id' => $clientAccount->id,
    'date' => Carbon::now(),
    'narration' => "Example Client Payment",
]);

$clientReceiptLineItem = LineItem::create([
    'account_id' => $bankAccount->id,
    'narration' => "Part payment for Client Invoice",
    'quantity' => 1,
    'amount' => 50,
]);

$clientReceipt->addLineItem($clientReceiptLineItem);
$clientReceipt->post();

use IFRS\Models\Assignment;

echo $clientInvoice->clearedAmount; //0: Currently the Invoice has not been cleared at all
echo $clientReceipt->balance; //50: The Receipt has not been assigned to clear any transaction

$assignment = Assignment::create([
    'assignment_date'=> Carbon::now(),
    'transaction_id' => $clientReceipt->id,
    'cleared_id' => $clientInvoice->id,
    'cleared_type'=> $clientInvoice->clearedType,
    'amount' => 50,
]);

echo $clientInvoice->clearedAmount; //50
echo $clientReceipt->balance; //0: The Receipt has been assigned fully to the Invoice


use IFRS\Reports\IncomeStatement;

$incomeStatement = new IncomeStatement(
    "2021-01-01",   // Report start date
    "2021-12-31",   // Report end date
)->getSections();// Fetch balances from the ledger and store them internally

/**
* this function is only for demonstration and
* debugging use and should never be called in production
*/
dd($incomeStatement->toString());

Example Company
Income Statement
For the Period: Jan 01 2021 to Dec 31 2021

Operating Revenues
    Operating Revenue        200 (100 cash sales + 100 credit sales)

Operating Expenses
    Operating Expense        100 (cash purchase)
                        ---------------
Operations Gross Profit      100

Non Operating Revenues
    Non Operating Revenue    0
                        ---------------
Total Revenue                100

Non Operating Expenses
    Direct Expense           0
    Overhead Expense         0
    Other Expense            0
                        ---------------
Total Expenses               0
                        ---------------
Net Profit                   100
                        ===============


use IFRS\Reports\BalanceSheet;

$balanceSheet = new BalanceSheet(
    "2021-12-31"  // Report end date
)->getSections();

/**
* again to emphasize, this function is only for demonstration and
* debugging use and should never be called in production
*/
dd($balanceSheet->toString());

Example Company
Balance Sheet
As at: Dec 31 2021

Assets
    Non Current Asset        120 (asset purchase)
    Receivables              70  (100 credit sale + 20 VAT - 50 client receipt)
    Bank                     50  (120 cash sale - 120 cash purchase + 50 client receipt)
                        ---------------
Total Assets                 240

Liabilities
    Control Account          20  (VAT: 20 cash sale + 20 credit sale - 10 cash purchase - 10 credit purchase)
    Payable                  120 (100 credit purchase + 20 VAT)
                        ---------------
Total Liabilities            140

                        ---------------
Net Assets                   100
                        ===============

Equity
    Income Statement         100
                        ---------------
Total Equity                 100
                        ===============


use IFRS\Reports\AccountStatement;
use IFRS\Reports\AccountSchedule;

$transactions = new AccountStatement($clientAccount)->getTransactions();

dd($transactions);

array:2[
  ["transaction" => ClientInvoice, "debit" => 120, "credit" => 0, "balance" => 120],
  ["transaction" => ClientReceipt, "debit" => 0, "credit" => 50, "balance" => 70]
]

$transactions = new AccountSchedule($clientAccount, $currency)->getTransactions();

dd($transactions);

array:1[
  ["transaction" => ClientInvoice, "amount" => 120, "cleared" => 50, "balance" => 70],
]