PHP code example of cod-glo / cgaccounting

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

    

cod-glo / cgaccounting example snippets


use CodGlo\CGAccounting\Services\AccountingService;

$accountingService = new AccountingService();
$result = $accountingService->credit(
    'fromAccount',    // Source account name
    'toAccount',      // Destination account name
    100.0,           // Amount
    'ref123',        // Reference ID (optional)
    'type1',         // Reference type (optional)
    'Description',   // Transaction description (optional)
    '2024-01-01'     // Transaction date (optional)
);

if ($result === true) {
    echo "Transaction successful!";
} else {
    echo "Error: " . $result;
}

use CodGlo\CGAccounting\Services\AccountingService;

$accountingService = new AccountingService();
$result = $accountingService->debit(
    'fromAccount',    // Source account name
    'toAccount',      // Destination account name
    50.0,            // Amount
    'ref456',        // Reference ID (optional)
    'type2',         // Reference type (optional)
    'Refund',        // Transaction description (optional)
    '2024-01-02'     // Transaction date (optional)
);

$account = $accountingService->getAccount('Cash');

$transactions = $accountingService->getAccountTransactions(
    $account->id,
    '2024-01-01', // Start date (optional)
    '2024-12-31', // End date (optional)
    20            // Results per page (optional)
);

$ledger = $accountingService->getGeneralLedger(
    '2024-01-01', // Start date (optional)
    '2024-12-31', // End date (optional)
    50            // Results per page (optional)
);

use CodGlo\CGAccounting\Models\Cheque;

$cheque = new Cheque([
    'cheque_number' => '123456',
    'cheque_date' => '2024-12-31',
    'type' => 'out',
    'amount' => 5000,
    'payee_name' => 'Supplier Name',
    // ... other fields
]);
$cheque->save();

// Update status
$cheque->updateStatus('cleared');

use CodGlo\CGAccounting\Services\AccountingReportService;

$reportService = new AccountingReportService(
    'Company Name',
    'Company Address',
    'Phone Number',
    'Email Address'
);

$reportUrl = $reportService->generateProfitAndLossReport(
    '2024-01-01',    // Start date
    '2024-12-31',    // End date
    'output/path',   // Optional output path
    'pdf'            // Optional format (pdf/html)
);

$reportUrl = $reportService->generateCashFlow(
    '2024-01-01',    // Start date
    '2024-12-31'     // End date
);

$reportUrl = $reportService->generateBalanceSheet(
    '2024-12-31'     // As of date
);

$reportUrl = $reportService->generateTrialBalanceSheet(
    '2024-12-31',    // As of date
    'output/path',   // Optional output path
    'pdf'            // Optional format (pdf/html)
);
sh
php artisan migrate
sh
php artisan db:seed --class=CodGlo\\CGAccounting\\Seeders\\AccountSeeder