PHP code example of mohamedhekal / ledgercore

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

    

mohamedhekal / ledgercore example snippets


use Hekal\LedgerCore\Models\Account;
use Hekal\LedgerCore\Models\FiscalPeriod;
use Hekal\LedgerCore\Enums\AccountType;

FiscalPeriod::create([
    'name' => '2026',
    'starts_on' => '2026-01-01',
    'ends_on' => '2026-12-31',
]);

$cash = Account::create(['code' => '1000', 'name' => 'Cash', 'type' => AccountType::Asset]);
$sales = Account::create(['code' => '4000', 'name' => 'Sales', 'type' => AccountType::Revenue]);

use Hekal\LedgerCore\Facades\Ledger;
use Hekal\LedgerCore\Support\JournalLineDraft;

$journal = Ledger::post('2026-03-15', [
    new JournalLineDraft($cash->id, debit: 10_000),
    new JournalLineDraft($sales->id, credit: 10_000),
], memo: 'Cash sale');

Ledger::reverse($journal);
$tb = Ledger::trialBalance(); // totals.balanced === true
bash
composer vendor:publish --tag=ledgercore-config
php artisan migrate