PHP code example of azaharizaman / nexus-general-ledger

1. Go to this page and download the library: Download azaharizaman/nexus-general-ledger 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/ */

    

azaharizaman / nexus-general-ledger example snippets


use Nexus\GeneralLedger\Services\LedgerService;
use Nexus\GeneralLedger\Enums\LedgerType;

// $ledgerService should be injected via IdGeneratorInterface
$ledger = $ledgerService->createLedger(
    tenantId: 'tenant-123',
    name: 'Statutory Ledger',
    type: LedgerType::STATUTORY,
    currency: 'USD',
    description: 'Main statutory ledger'
);

echo $ledger->id; // generated ID string

use Nexus\GeneralLedger\Services\TransactionService;

$balance = $transactionService->getAccountBalance(
    $account->id,
    new DateTimeImmutable('2024-01-31')
);

echo $balance->getAmount()->getAmount(); // Account balance as of date
echo $balance->balanceType->value; // debit or credit

$trialBalance = $trialBalanceService->generateTrialBalance(
    $ledger->id,
    'period-2024-01'
);

echo $trialBalance->totalDebits->getAmount();
echo $trialBalance->totalCredits->getAmount();
echo $trialBalance->isBalanced; // true if debits = credits

foreach ($trialBalance->lines as $line) {
    // Correctly access TrialBalanceLine properties
    $balance = $line->getNetBalance();
    echo $line->accountCode . ': ' . $balance->getAmount();
}