PHPackages                             icomefromthenet/ledger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. icomefromthenet/ledger

ActiveLibrary

icomefromthenet/ledger
======================

Finance and Accounting Library

v1.1.0(7y ago)347323[1 issues](https://github.com/icomefromthenet/GeneralLedger/issues)[1 PRs](https://github.com/icomefromthenet/GeneralLedger/pulls)MITPHP

Since Jan 24Pushed 6y ago5 watchersCompare

[ Source](https://github.com/icomefromthenet/GeneralLedger)[ Packagist](https://packagist.org/packages/icomefromthenet/ledger)[ RSS](/packages/icomefromthenet-ledger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (7)Used By (0)

GeneralLedger [![Build Status](https://camo.githubusercontent.com/0766832398fc0c6cd6e42469137f0d340cc5cb2b816e06f1c1d7badf9c7e8722/68747470733a2f2f7472617669732d63692e6f72672f69636f6d6566726f6d7468656e65742f47656e6572616c4c65646765722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/icomefromthenet/GeneralLedger)
====================================================================================================================================================================================================================================================================================================================================

[](#generalledger--)

General Ledger for PHP and MySql.

A [general ledger](https://www.google.com.au/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8&client=ubuntu#q=define%3Ageneral%20ledger) is a complete record of financial transactions over the life of a company. The ledger holds account information that is needed to prepare financial statements, and includes accounts for assets, liabilities, owners' equity, revenues and expenses.

Installing
----------

[](#installing)

Step 1. You can install this library using composer.

```
    icomefromthenet/ledger : 1.0.*
```

Step 2. Create a new database called 'general\_ledger' and run the database build script under database/database.sql

```
    mysql general_ledger  I use my own database migration tool called [Migrations](https://github.com/icomefromthenet/Migrations) but I have included a sql file for convenience.

Terms and conventions
---------------------

[](#terms-and-conventions)

### 1. Debits / Credit.

[](#1-debits--credit)

A debit is a value with a positive sign, a credit is a value with a negative sign.

### 2. Transaction

[](#2-transaction)

For purposes of this library a transaction is represented by a single entry into the general ledger with each transaction having 1 to many account movements.

### 3. Organisation Unit (Cost Center)

[](#3-organisation-unit-cost-center)

Organisation Units are used to group transactions with each having a relation to ONE and therefore should be mutually exclusive. For example departments in an organisation.

### 4. Ledger User.

[](#4-ledger-user)

Each transaction is subscribed to a single user this most likely your application users.

### 5. Ledger Entry / Account movement.

[](#5-ledger-entry--account-movement)

Each entry represents an allocation to a ledger account.

### 6. Ledger Account

[](#6-ledger-account)

Each account can hold one to many child accounts think of it like a tree.

### 6. Trail Balance

[](#6-trail-balance)

Aggerates all enteries which are then split into debits and credits. The ledger is said to be in balance if debits equals credit.

### 7. Adjustments

[](#7-adjustments)

To make a correction a transaction must be adjusted through a reversal and a re-issue we do NOT delete transactions in our ledgers.

Create a Transaction
--------------------

[](#create-a-transaction)

1. Instance the library DI container.
2. Instance the transaction builder.
3. Fetch the current date from the database.
4. Set transaction details and run.

```
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;
```

> You really should not assume your webserver and database server running same date settings.

Create a Adjustment
-------------------

[](#create-a-adjustment)

1. Instance the library DI container.
2. Instance the transaction builder.
3. Fetch the current date from the database.
4. Fetch the transaction that were looking to reverse.
5. Process an adjustment and then do the replacement.

```
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;
```

> Should give them replacement transaction the same occured date as the original so if a list is made in date order you see them grouped together.

Run a Trail Balance
-------------------

[](#run-a-trail-balance)

1. Decide if you want to use the AGG tables or the entry tables.
2. Pick if you want a trail balance for everyone or a single user/organistation unit.

```
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;

}
```

Chart of Accounts
-----------------

[](#chart-of-accounts)

1. First account at id 1 will be a root account.
2. Need one or more accounts with is\_left = true (Debit) and one or more accounts with is\_right = true (credit).
3. Other accounts should inherit from these top level accounts.
4. Yep its a tree.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 85.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~187 days

Recently: every ~233 days

Total

6

Last Release

2822d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bf07079383d640a4a434d2133398f4c6f9bbc1a5752798b939ddd698bea699f7?d=identicon)[icomefromthenet](/maintainers/icomefromthenet)

---

Top Contributors

[![icomefromthenet](https://avatars.githubusercontent.com/u/746782?v=4)](https://github.com/icomefromthenet "icomefromthenet (69 commits)")[![dataforce-lewis](https://avatars.githubusercontent.com/u/71356963?v=4)](https://github.com/dataforce-lewis "dataforce-lewis (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/icomefromthenet-ledger/health.svg)

```
[![Health](https://phpackages.com/badges/icomefromthenet-ledger/health.svg)](https://phpackages.com/packages/icomefromthenet-ledger)
```

###  Alternatives

[elgg/elgg

Elgg is an award-winning social networking engine, delivering the building blocks that enable businesses, schools, universities and associations to create their own fully-featured social networks and applications.

1.7k15.7k3](/packages/elgg-elgg)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[api-platform/metadata

API Resource-oriented metadata attributes and factories

223.5M96](/packages/api-platform-metadata)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[flowwow/cloudpayments-php-client

cloudpayments api client

2188.2k](/packages/flowwow-cloudpayments-php-client)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
