PHP code example of azaharizaman / nexus-financial-statements

1. Go to this page and download the library: Download azaharizaman/nexus-financial-statements 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-financial-statements example snippets


interface FinancialStatementInterface
{
    public function getId(): string;
    public function getTenantId(): string;
    public function getPeriodId(): string;
    public function getType(): StatementType;
    public function getGeneratedAt(): \DateTimeImmutable;
    public function getSections(): array;
    public function getMetadata(): StatementMetadata;
}

interface StatementBuilderInterface
{
    /**
     * Build a financial statement of the specified type
     *
     * @param StatementType $type The type of statement to build
     * @param array<AccountBalance> $balances Account balances to        array $balances,
        StatementPeriod $period,
        ComplianceFramework $framework
    ): FinancialStatementInterface;
}

interface StatementTemplateInterface
{
    public function getStatementType(): StatementType;
    public function getFramework(): ComplianceFramework;
    public function getSectionDefinitions(): array;
    public function getLineItemOrder(): array;
    public function getSubtotalRules(): array;
}

interface StatementValidatorInterface
{
    /**
     * Validate a financial statement
     *
     * @param FinancialStatementInterface $statement
     * @return ValidationResult
     * @throws StatementImbalanceException
     */
    public function validate(FinancialStatementInterface $statement): ValidationResult;
    
    /**
     * Check if statement meets compliance 

interface ComplianceTemplateInterface
{
    public function getFramework(): ComplianceFramework;
    public function getRequiredSections(): array;
    public function getRequiredDisclosures(): array;
    public function getAccountMappings(): array;
}

interface StatementDataProviderInterface
{
    /**
     * Get account balances for a period
     *
     * @return array<AccountBalance>
     */
    public function getAccountBalances(
        string $tenantId,
        string $periodId,
        \DateTimeImmutable $asOfDate
    ): array;
    
    /**
     * Get comparative period balances
     */
    public function getComparativeBalances(
        string $tenantId,
        string $periodId,
        int $periodsBack = 1
    ): array;
}

interface StatementExportAdapterInterface
{
    public function export(
        FinancialStatementInterface $statement,
        StatementFormat $format,
        array $options = []
    ): ExportResult;
    
    public function supportsFormat(StatementFormat $format): bool;
}

final readonly class LineItem
{
    public function __construct(
        public string $accountId,
        public string $accountName,
        public string $accountCode,
        public Money $amount,
        public Money $comparativeAmount,
        public int $displayOrder,
        public bool $isSubtotal = false
    ) {}
}

final readonly class AccountBalance
{
    public function __construct(
        public string $accountId,
        public string $accountCode,
        public string $accountName,
        public AccountCategory $category,
        public Money $debitBalance,
        public Money $creditBalance,
        public Money $netBalance
    ) {}
}

final readonly class StatementMetadata
{
    public function __construct(
        public string $preparedBy,
        public \DateTimeImmutable $preparedAt,
        public ?string $approvedBy,
        public ?\DateTimeImmutable $approvedAt,
        public ComplianceFramework $framework,
        public string $currency,
        public array $notes = []
    ) {}
}

final readonly class StatementPeriod
{
    public function __construct(
        public string $periodId,
        public \DateTimeImmutable $startDate,
        public \DateTimeImmutable $endDate,
        public string $periodName,
        public bool $isClosed = false
    ) {}
}

final readonly class ComplianceStandard
{
    public function __construct(
        public ComplianceFramework $framework,
        public string $version,
        public \DateTimeImmutable $effectiveDate,
        public array $

enum StatementType: string
{
    case BALANCE_SHEET = 'balance_sheet';
    case INCOME_STATEMENT = 'income_statement';
    case CASH_FLOW = 'cash_flow';
    case CHANGES_IN_EQUITY = 'changes_in_equity';
    case NOTES = 'notes';
    case TRIAL_BALANCE = 'trial_balance';
}

enum StatementFormat: string
{
    case PDF = 'pdf';
    case EXCEL = 'excel';
    case HTML = 'html';
    case JSON = 'json';
    case CSV = 'csv';
}

enum AccountCategory: string
{
    case ASSET = 'asset';
    case LIABILITY = 'liability';
    case EQUITY = 'equity';
    case REVENUE = 'revenue';
    case EXPENSE = 'expense';
}

enum CashFlowMethod: string
{
    case DIRECT = 'direct';
    case INDIRECT = 'indirect';
}

enum ComplianceFramework: string
{
    case GAAP = 'gaap';
    case IFRS = 'ifrs';
    case LOCAL = 'local';
    case CUSTOM = 'custom';
}

use Nexus\FinancialStatements\Contracts\StatementBuilderInterface;
use Nexus\FinancialStatements\Contracts\StatementDataProviderInterface;
use Nexus\FinancialStatements\Enums\StatementType;
use Nexus\FinancialStatements\Enums\ComplianceFramework;
use Nexus\FinancialStatements\ValueObjects\StatementPeriod;

final readonly class BalanceSheetGenerator
{
    public function __construct(
        private StatementBuilderInterface $builder,
        private StatementDataProviderInterface $dataProvider
    ) {}
    
    public function generate(string $tenantId, string $periodId): BalanceSheet
    {
        // Get account balances from consuming application
        $balances = $this->dataProvider->getAccountBalances(
            $tenantId,
            $periodId,
            new \DateTimeImmutable()
        );
        
        // Define the reporting period
        $period = new StatementPeriod(
            periodId: $periodId,
            startDate: new \DateTimeImmutable('2024-01-01'),
            endDate: new \DateTimeImmutable('2024-12-31'),
            periodName: 'FY 2024'
        );
        
        // Build the balance sheet
        return $this->builder->build(
            type: StatementType::BALANCE_SHEET,
            balances: $balances,
            period: $period,
            framework: ComplianceFramework::IFRS
        );
    }
}