Download the PHP package illuminatech/balance without Composer

On this page you can find all versions of the php package illuminatech/balance. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package balance

Balance Accounting System extension for Laravel


This extension provides basic support for balance accounting (bookkeeping) system based on debit and credit principle.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json.

Usage

This extension provides basic support for balance accounting (bookkeeping) system based on debit and credit 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:

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:

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:

You may as well use \Illuminatech\Balance\Facades\Balance facade. For example:

In these documentation facade is used in code snippets for simplicity.

Application configuration

This extension uses illuminatech/array-factory for configuration. Make sure you are familiar with 'array factory' concept before configuring this extension. Configuration is stored at 'config/balance.php' file.

You can publish predefined configuration file using following console command:

In case you are using \Illuminatech\Balance\BalanceDb, you can publish predefined database migration for it using following console command:

Basic operations

In order to increase (debit) balance at particular account, \Illuminatech\Balance\BalanceContract::increase() method is used:

In order to decrease (credit) balance at particular account, \Illuminatech\Balance\BalanceContract:decrease() method is used:

Tip: actually, method decrease() is redundant, you can call increase() with negative amount in order to achieve the same result.

It is unlikely you will use plain increase() and decrease() methods in your application. In most cases there is a need to transfer money from one account to another at once. Method \Illuminatech\Balance\BalanceContract::transfer() can be used for this:

Note that method transfer() creates 2 separated transactions: one per each affected account. Thus you can easily fetch all money transfer history for particular account, simply selecting all transactions linked to it. 'Debit' transactions will have positive amount, while 'credit' ones - negative.

Note: If you wish each transaction created by transfer() remember another account involved in the process, you'll need to setup \Illuminatech\Balance\Balance::$extraAccountLinkAttribute.

You may revert particular transaction using \Illuminatech\Balance\BalanceContract::revert() method:

This method will not remove original transaction, but create a new one, which compensates it.

Querying accounts

Using account IDs for the balance manager is not very practical. In our above example, each system user have 3 virtual accounts, each of which has its own unique ID. However, while performing purchase, we operate user ID and account type, so we need to query actual account ID before using balance manager. Thus there is an ability to specify account for the balance manager methods using their attributes set. For example:

In this example balance manager will find ID of the affected accounts automatically, using provided attributes as a filter.

You may enable \Illuminatech\Balance\Balance::$autoCreateAccount, allowing automatic creation of the missing accounts, if they are specified as attributes set. This allows accounts creation on the fly, by demand only, eliminating necessity of their pre-creation.

Heads up! Actually 'account' entity is redundant at balance system, and its usage can be avoided. However, its presence provides more flexibility and saves performance. Storing of account data is not mandatory for this extension, you can configure your balance manager in the way it is not used.

Finding account current balance

Current money amount at particular account can always be calculated as a sum of amounts over related transactions. You can use \Illuminatech\Balance\BalanceContract::calculateBalance() method for that:

However, calculating current balance each time you need it, is not efficient. Thus you can specify an attribute of account entity, which will be used to store current account balance. This can be done via \Illuminatech\Balance\Balance::$accountBalanceAttribute. Each time balance manager performs a transaction, it will update this attribute accordingly:

Saving extra transaction data

Usually there is a necessity to save extra information along with the transaction. For example: we may need to save payment ID received from payment gateway. This can be achieved in following way:

The way extra attributes are stored in the data storage depends on particular balance manager implementation. For example: \Illuminatech\Balance\BalanceDb will try to store extra data inside transaction table columns, if their name equals the parameter name. You may as well setup special data field via \Illuminatech\Balance\BalanceDb::$dataAttribute, which will store all extra parameters, which have no matching column, in serialized state.

Note: watch for the keys you use in transaction data: make sure they do not conflict with columns, which are reserved for other purposes, like primary keys.

Saving balance amount per transaction

There is a common accounting (bookkeeping) practice to record new balance amount per each performed transaction. Such approach simplifies recreation of the balance transfers dynamics and search for possible errors. You can achieve such behavior by setting \Illuminatech\Balance\Balance::$newBalanceAttribute value with the name of transaction entity attribute, which should store account balance, which appears after this transaction has been performed. For example:

Events

\Illuminatech\Balance\Balance provides several events, which can be handled via event listener:

For example:


All versions of balance with dependencies

PHP Build Version
Package Version
Requires illuminate/database Version ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
illuminatech/array-factory Version ^1.2.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package illuminatech/balance contains the following files

Loading the files please wait ....