Installation (updated for Laravel 11+ and PHP 8.2+):
composer require ekmungai/eloquent-ifrs:^6.0
Publish migrations and config:
php artisan vendor:publish --provider="EkmunGai\EloquentIfrs\EloquentIfrsServiceProvider" --tag="migrations"
php artisan vendor:publish --provider="EkmunGai\EloquentIfrs\EloquentIfrsServiceProvider" --tag="config"
Run migrations (note: remove_vat_id_column migration now handles modern SQLite drivers):
php artisan migrate
First Use Case (unchanged):
use EkmunGai\EloquentIfrs\Models\Entity;
use EkmunGai\EloquentIfrs\Models\Account;
$entity = Entity::create(['name' => 'My Company']);
$cashAccount = Account::create([
'entity_id' => $entity->id,
'code' => '1000',
'name' => 'Cash',
'type' => 'asset',
]);
Record a Transaction (unchanged):
use EkmunGai\EloquentIfrs\Models\Transaction;
$transaction = Transaction::create([
'entity_id' => $entity->id,
'date' => now(),
'description' => 'Initial cash deposit',
'entries' => [
['account_id' => $cashAccount->id, 'debit' => 1000.00],
['account_id' => $cashAccount->id, 'credit' => 1000.00],
],
]);
$transaction->validate()->save();
Verify Integrity (now with deterministic validation):
$transaction->validate(); // Throws exception if debits ≠ credits
config/eloquent-ifrs.php (now tested with Laravel 11/12/13)EkmunGai\EloquentIfrs\Models\ (PHP 8.2+ compatible)EkmunGai\EloquentIfrs\Reports\ (now deterministic due to seeded PRNG)phpunit.xml schema for PHPUnit 10/11$entity = Entity::find(1);
$accounts = $entity->accounts()->where('type', 'asset')->get();
Transaction::createBatch([
[
'entity_id' => $entity->id,
'date' => now(),
'entries' => [['account_id' => $cashAccount->id, 'debit' => 500.00]], // No zero values
],
]);
$transaction = Transaction::create([
'entity_id' => $entity->id,
'date' => now(),
'entries' => [
['account_id' => $cashAccount->id, 'debit' => 1200.00],
['account_id' => $vatAccount->id, 'credit' => 200.00],
],
'vat_rate' => config('eloquent-ifrs.default_vat_rate'),
]);
use EkmunGai\EloquentIfrs\Models\OpeningBalance;
OpeningBalance::create([
'entity_id' => $entity->id,
'account_id' => $cashAccount->id,
'amount' => 5000.00,
'year' => 2025,
]);
use EkmunGai\EloquentIfrs\Reports\TrialBalance;
$report = new TrialBalance($entity, 2025);
$data = $report->generate(); // Deterministic output
// In AppServiceProvider@boot()
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../../vendor/ekmungai/eloquent-ifrs/config/eloquent-ifrs.php' => config_path('eloquent-ifrs.php'),
], 'eloquent-ifrs-config');
}
class CustomAccount extends Account
{
protected $casts = [
'is_tax_deductible' => 'boolean',
'created_at' => 'datetime:Y-m-d H:i:s', // Explicit casting
];
}
use OwlLabs\Auditing\Contracts\Auditable;
class Transaction extends \EkmunGai\EloquentIfrs\Models\Transaction implements Auditable
{
use \OwlLabs\Auditing\Auditable;
}
// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('eloquent-ifrs:reconcile')->dailyAt('02:00');
}
class Transaction extends \EkmunGai\EloquentIfrs\Models\Transaction
{
protected float $exchange_rate = 1.0;
protected array $entries = [];
public function getTotalDebit(): float
{
return array_sum(array_column($this->entries, 'debit'));
}
}
$accountSchedule = AccountSchedule::where('account_id', $account->id)
->where('start_date', '<=', now())
->where('end_date', '>=', now())
->first();
// Age calculation now works for Carbon 3 (returns signed float)
$daysActive = $accountSchedule->age_in_days();
PHP Version Mismatch:
Class 'Stringable' not found.# Example .tool-versions file
php 8.4.0
Laravel Version Drop:
composer require laravel/framework:^11.0
Zero-Balance Accounts:
Account::where('balance', 0)->whereNotNull('opening_balance')->update([
'opening_balance' => 1.00, // Minimum non-zero value
]);
SQLite Migration Issues:
remove_vat_id_column migration may fail on modern SQLite.php artisan db:seed --class=FixVatColumnMigration
Deterministic Testing:
// In tests/bootstrap.php
mt_srand(12345); // Seeded for deterministic results
Carbon Version Conflicts:
diffInDays() returns signed float in Carbon 3.abs() or handle signed values:
$days = abs($accountSchedule->age_in_days());
Laravel 11+ Booting:
config/app.php under providers array:
EkmunGai\EloquentIfrs\EloquentIfrsServiceProvider::class,
PHP 8.2+ Features:
class Transaction
{
public function __construct(
public readonly int $entity_id,
public readonly string $description,
) {}
}
How can I help you explore Laravel packages today?