This bundle provides a double-entry accounting system for Symfony2.
Installation is a 3 step process:
- Download BSPAccountingBundle using composer
- Enable the Bundle
- Configure the bundle
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/D3r3ck/BSPAccountingBundle"
}
],
"require": {
"d3r3ck/bsp-accounting-bundle": "v1.0.*"
}
}
Now tell composer to download the bundle by running the command:
$ php composer.phar update d3r3ck/bsp-accounting-bundle
Composer will install the bundle to your project's vendor/d3r3ck/bsp-accounting-bundle
directory.
Enable the bundle in the kernel:
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new BSP\AccountingBundle\BSPAccountingBundle(),
);
}
Add the following lines to your config.yml
# app/config/config.yml
bsp_accounting:
db_driver: mongodb # Currently only works with mongodb, we are working on orm
secret: mysecretkey
system_accounts: path/to/my/system/accounts.yml
And you are done!
This bundle works basically by a transactions manipulator:
$manipulator = $this->get('bsp_accounting.manipulator');
In order to create an account you only have to do:
$manipulator->createAccount( 'My Account', 'EUR' );
You can specify a provider for the ID generation.
The default one is uniqid()
but there are 2 more:
$manipulator->createAccount( 'My Account', 'EUR', 'mongodb' );
and
$manipulator->createAccount( 'My Account', 'EUR', 'manual', array( 'id' => 'ABC30045' ) );
$manipulator->createTransaction( 'My Transaction' );
You can pass extra information you need as second parameter
$manipulator->createTransaction( 'My Transaction', array( 'book' => 'Foo', ... ) );
You can add a accounting movement by doing the following
use BSP\AccountingBundle\Model\AccountingEntryInterface;
$manipulator->addAccountingEntry( 'My Transaction', 'My Account', AccountingEntryInterface::TRANSACTION_TYPE_APPROVE, 1000 );
Supported transaction types are:
- TRANSACTION_TYPE_APPROVE
- TRANSACTION_TYPE_APPROVE_AND_DEPOSIT
- TRANSACTION_TYPE_CREDIT
- TRANSACTION_TYPE_DEPOSIT
- TRANSACTION_TYPE_REVERSE_APPROVAL
- TRANSACTION_TYPE_REVERSE_CREDIT
- TRANSACTION_TYPE_REVERSE_DEPOSIT
use BSP\AccountingBundle\Model\ExtendedDataInterface
$manipulator->closeTransaction( 'My Transaction', ExtendedDataInterface::STATE_SUCCESS );
Supported status are:
- STATE_CANCELED
- STATE_FAILED
- STATE_PENDING
- STATE_SUCCESS
You can also cancel a transaction by this function
$manipulator->cancelTransaction( 'My Transaction' );
This bundle includes some functionalities that you can use with manipulator or with console command. Those are:
php app/console bsp:accounting:check:transactions
This command checks the transactions looking for the unclosed ones
php app/console bsp:accounting:balance "My Account"
This command gives you the account's balance
php app/console bsp:accounting:load
This commands loads your system accounts from your yaml file specified in config.yml
and saves them into the database