PHPackages                             illuminatech/balance - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. illuminatech/balance

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

illuminatech/balance
====================

Provides support for Balance accounting system based on debit and credit principle

1.3.4(1mo ago)16137.4k↓24.7%25BSD-3-ClausePHPCI passing

Since Feb 19Pushed 1mo ago8 watchersCompare

[ Source](https://github.com/illuminatech/balance)[ Packagist](https://packagist.org/packages/illuminatech/balance)[ GitHub Sponsors](https://github.com/klimov-paul)[ Patreon](https://www.patreon.com/klimov_paul)[ RSS](/packages/illuminatech-balance/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (11)Used By (0)

 [ ![](https://avatars1.githubusercontent.com/u/47185924) ](https://github.com/illuminatech)

Balance Accounting System extension for Laravel
===============================================

[](#balance-accounting-system-extension-for-laravel)

This extension provides basic support for balance accounting (bookkeeping) system based on [debit and credit](https://en.wikipedia.org/wiki/Debits_and_credits) principle.

For license information check the [LICENSE](LICENSE.md)-file.

[![Latest Stable Version](https://camo.githubusercontent.com/10211341584491ef68288b39cd5a5cf9eb156d41e855437a856d4c62b413fcf2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696c6c756d696e61746563682f62616c616e63652e737667)](https://packagist.org/packages/illuminatech/balance)[![Total Downloads](https://camo.githubusercontent.com/a25aedb2901a6a0bd8c6f7e754528870ee5c14dbeddfa136b58c15122999beaf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696c6c756d696e61746563682f62616c616e63652e737667)](https://packagist.org/packages/illuminatech/balance)[![Build Status](https://github.com/illuminatech/balance/workflows/build/badge.svg)](https://github.com/illuminatech/balance/actions)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist illuminatech/balance

```

or add

```
"illuminatech/balance": "*"
```

to the require section of your composer.json.

Usage
-----

[](#usage)

This extension provides basic support for balance accounting (bookkeeping) system based on [debit and credit](https://en.wikipedia.org/wiki/Debits_and_credits) principle. Balance system is usually used for the accounting (bookkeeping) and money operations. However, it may also be used for any resource transferring from one location to another. For example: transferring goods from storehouse to the shop and so on.

There 2 main terms related to the balance system:

- account - virtual storage of the resources, which have some logical meaning.
- transaction - represents actual transfer of the resources to or from the particular account.

Lets assume we have a system, which provides virtual money balance for the user. Money on the balance can be used for the goods purchasing, user can top up his balance via some payment gateway. In such example, each user should have 3 virtual balance accounts: 'virtual-money', 'payment-gateway' and 'purchases'. When user tops up his virtual balance, our system should remove money from 'payment-gateway' and add them to 'virtual-money'. When user purchases an item, our system should remove money from 'virtual-money' and add them to 'purchases'. The trick is: if you sum current amount over all user related accounts ('payment-gateway' + 'virtual-money' + 'purchases'), it will always be equal to zero. Such check allows you to verify is something went wrong any time.

This extension introduces term 'balance manager' as a service, which should handle all balance transactions. Public contract for such manager is determined by `\Illuminatech\Balance\BalanceContract` interface. Following particular implementations are provided:

- [\\Illuminatech\\Balance\\BalanceDb](src/BalanceDb.php) - uses a relational database as a data storage.

Please refer to the particular manager class for more details.

This extension provides `\Illuminatech\Balance\BalanceServiceProvider` service provider, which binds `\Illuminatech\Balance\BalanceContract`as a singleton in DI container. Thus you can get balance manager via automatic DI injections or via container instance. For example:

```
