PHP code example of icomefromthenet / ledger

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

    

icomefromthenet / ledger example snippets


use Doctrine\DBAL\Connection;
use Monolog\Logger;
use Monolog\Handler\TestHandler;
use Symfony\Component\EventDispatcher\EventDispatcher;
use IComeFromTheNet\GeneralLedger\LedgerContainer;
use IComeFromTheNet\GeneralLedger\TransactionBuilder;


# instance the Library DI Container.

$oAppLog   = new new Logger('test-ledger',array(new TestHandler()));
$oDatabase = new Connection(array());
$oEvent    = new EventDispatcher();

$oLedgerContainer = new LedgerContainer($oEvent, $oDatabase, $oAppLog);
$oLedgerContainer->boot();

# fetch processing date from the database 

$oProcessingDate = $oLedgerContainer->getNow(); 

# instance the Transaction Builder and configure our builder with transaction.

$oTBuilder = new TransactionBuilder($oLedgerContainer);

$oTBuilder->setProcessingDate($oProcessingDate); 
$oTBuilder->setOccuredDate(new DateTime('now - 6 day'));
$oTBuilder->setOrgUnit('homeoffice');
$oTBuilder->setVoucherNumber('10004');
$oTBuilder->setJournalType('sales_journal');
$oTBuilder->setUser('586DB7DF-57C3-F7D5-639D-0A9779AF79BD');


# Add Some account movements

$oTBuilder->addAccountMovement('2-1120',100);
$oTBuilder->addAccountMovement('2-1121',-100);

# process the transaction, if no exceptions then we have a sucessful transaction

$oTBuilder->processTransaction();
       
$oTransaction = $oTBuilder->getTransactionHeader();

echo 'Transaction ID'  . $oTransaction->iTransactionID;



use Doctrine\DBAL\Connection;
use Monolog\Logger;
use Monolog\Handler\TestHandler;
use Symfony\Component\EventDispatcher\EventDispatcher;
use IComeFromTheNet\GeneralLedger\LedgerContainer;
use IComeFromTheNet\GeneralLedger\TransactionBuilder;

$oAppLog   = new new Logger('test-ledger',array(new TestHandler()));
$oDatabase = new Connection(array());
$oEvent    = new EventDispatcher();

$oLedgerContainer = new LedgerContainer($oEvent, $oDatabase, $oAppLog);
$oLedgerContainer->boot();

# fetch processing date from the database 

$oProcessingDate = $oLedgerContainer->getNow(); 

# instance the Transaction Builder and configure our builder with transaction.

$oTBuilder = new TransactionBuilder($oLedgerContainer);

        
$oTBuilder->setProcessingDate($oProcessingDate); 
$oTBuilder->setOccuredDate(new DateTime('now - 6 day'));
$oTBuilder->setOrgUnit('homeoffice');
$oTBuilder->setVoucherNumber('10004');
$oTBuilder->setJournalType('sales_journal');
$oTBuilder->setUser('586DB7DF-57C3-F7D5-639D-0A9779AF79BD');


# process the reversal transaction, if no exceptions then we have
# a sucessful transaction.

$oGateway = getGatewayCollection()->getGateway('ledger_transaction');

$oTransaction = $oGateway->selectQuery()
             ->start()
                ->where('transaction_id = :iTransactionId')
                ->setParameter(':iTransactionId',1,'integer')
             ->end()
           ->findOne();

$oTBuilder->processAdjustment($oTransaction);
       
$oAdjTransaction = $oTBuilder->getTransactionHeader();

echo 'Adjustment Transaction ID'  . $oAdjTransaction->iTransactionID;
ehco 'Original Transaction references adj'. $oTransaction->iAdjustmentID;


use Doctrine\DBAL\Connection;
use Monolog\Logger;
use Monolog\Handler\TestHandler;
use Symfony\Component\EventDispatcher\EventDispatcher;
use IComeFromTheNet\GeneralLedger\LedgerContainer;
use IComeFromTheNet\GeneralLedger\TrialBalance;
use IComeFromTheNet\GeneralLedger\TrialBalanceOrgUnit;
use IComeFromTheNet\GeneralLedger\TrialBalanceUser;


$oAppLog   = new new Logger('test-ledger',array(new TestHandler()));
$oDatabase = new Connection(array());
$oEvent    = new EventDispatcher();

$oLedgerContainer = new LedgerContainer($oEvent, $oDatabase, $oAppLog);
$oLedgerContainer->boot();

# pick a to date.

$oProcessingDate = new DateTime('now - 1 day') 
$bUseAggSource   = true;
$iOrgUnit        = 1;
$iUser           = 1;

# You need to do a lookup to map human name for User or OrgUnit to database id.

$oTrialBal        = new TrialBalance($oLedgerContainer, $oProcessingDate,$bUseAggSource);
$oUserTrialBal    = new TrialBalanceOrgUnit($oLedgerContainer, $oProcessingDate,$iUser,$bUseAggSource);
$oOrgUnitTrialBal = new TrialBalanceUser($oLedgerContainer, $oProcessingDate,$iOrgUnit,$bUseAggSource);

# execute the balance, will throw and exception if something goes wrong.

$oTrialBalance = $oTrialBal->getTrialBalance();


# print the results

foreach($oTrialBalance => $oLedgerBalance) {
    echo $oLedgerBalance->sAccountNumber;
    echo $oLedgerBalance->sAccountName;
    echo $oLedgerBalance->fDebit;
    echo $oLedgerBalance->fCredit;
    
}