arnaugm/band-accounting-bundle
Install the Bundle
composer require arnaugm/band-accounting-bundle
Enable Bundles
Add to AppKernel.php:
new ArnauGM\BandAccountingBundle\ArnauGMBandAccountingBundle(),
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
Configure Locale & Doctrine Extensions
# app/config/config.yml
stof_doctrine_extensions:
default_locale: en_US # Adjust to your locale
orm:
default:
timestampable: true
Load Routes
# app/config/routing.yml
band_accounting:
resource: "@ArnauGMBandAccountingBundle/Resources/config/routing.yml"
prefix: /admin/accounting
Install Assets
php app/console assets:install --symlink
First Use Case: Create a Band
Use the provided CRUD interface at /admin/accounting/band to register a band. The bundle likely includes:
Band Management
/admin/accounting/band route to create/update bands.Band entity (e.g., src/ArnauGM/BandAccountingBundle/Entity/Band.php) to add custom fields (e.g., taxId, genre).Accounting Entries
/admin/accounting/entry with:
$entry = new Entry();
$entry->setBand($band);
$entry->setType(Entry::TYPE_EXPENSE);
$entry->setAmount(150.00);
$entry->setDate(new \DateTime());
$entry->setDescription("Guitar strings");
$em->persist($entry);
$em->flush();
Reports
$qb = $em->createQueryBuilder();
$qb->select('e')
->from('ArnauGMBandAccountingBundle:Entry', 'e')
->where('e.band = :band')
->andWhere('e.date BETWEEN :start AND :end')
->setParameter('band', $band)
->setParameter('start', $startDate)
->setParameter('end', $endDate);
Forms
EntryType) to add fields:
// src/ArnauGM/BandAccountingBundle/Form/EntryType.php
$builder->add('category', EntityType::class, [
'class' => Category::class,
'placeholder' => 'Select category',
]);
Frontend Integration
client/:
cd client
npm install
grunt watch # Auto-reload during development
prePersist/preUpdate on Entry to auto-calculate totals or validate amounts.
$em->getEventManager()->addEventListener(
Entry::class,
new EntryLifecycleListener()
);
ROLE_ADMIN in security.yml:
access_control:
- { path: ^/admin/accounting, roles: ROLE_ADMIN }
// src/AppBundle/Controller/Api/EntryController.php
class EntryController extends Controller {
public function getBandEntries(Band $band) {
return $this->json($this->getDoctrine()->getRepository(Entry::class)->findBy(['band' => $band]));
}
}
Symfony 2.7 Dependency
make:controller).php app/console generate:controller for legacy compatibility.Locale Configuration
stof_doctrine_extensions for timestampable entities. Ensure default_locale matches your app’s locale (e.g., en_US).STOF_DOCTRINE_EXTENSIONS_DEFAULT_LOCALE in app/config/parameters.yml if timestamps fail.Asset Pipeline
grunt and npm. If missing:
npm install -g grunt-cli
cd client && npm install && grunt
grunt watch in development to auto-compile SCSS/JS.Database Schema
php app/console doctrine:schema:update --force
Routing Conflicts
/admin/accounting prefix may clash with existing routes. Use _controller in routing.yml to override:
band_accounting_entry:
path: /accounting/entries
defaults: { _controller: ArnauGMBandAccountingBundle:Entry:list }
config.yml:
doctrine:
dbal:
logging: true
$form->handleRequest($request);
if ($form->isSubmitted() && !$form->isValid()) {
dump($form->getErrors(true)); // Debug form errors
}
Custom Entities
Band or Entry in your app’s Entity/ folder and update orm.xml:
<entity name="AppBundle\Entity\ExtendedBand" extends="ArnauGM\BandAccountingBundle\Entity\Band">
<field name="taxId" type="string" length="20" />
</entity>
Event Listeners
Entry events (e.g., prePersist to auto-calculate totals):
// src/AppBundle/EventListener/EntryListener.php
class EntryListener {
public function prePersist(Entry $entry) {
if ($entry->getType() === Entry::TYPE_EXPENSE) {
$entry->setIsTaxDeductible(true);
}
}
}
Register in services.yml:
services:
app.entry_listener:
class: AppBundle\EventListener\EntryListener
tags:
- { name: doctrine.event_listener, event: prePersist, entity: ArnauGMBandAccountingBundle\Entity\Entry }
Custom Reports
// src/AppBundle/Repository/CustomEntryRepository.php
class CustomEntryRepository extends ServiceEntityRepository {
public function findByBandAndCategory(Band $band, $category) {
return $this->createQueryBuilder('e')
->where('e.band = :band')
->andWhere('e.category = :category')
->setParameter('band', $band)
->setParameter('category', $category)
->getQuery()
->getResult();
}
}
API Integration
# config/routing.yml
app_entry_api:
path: /api/entries/{id}
defaults: { _controller: 'FOSRestBundle:Default:getItem' }
requirements:
id: \d+
How can I help you explore Laravel packages today?