behappy / invoice-plugin
A plugin to generate invoices in Sylius
Installs: 6 016
Dependents: 0
Suggesters: 0
Security: 0
Stars: 13
Watchers: 7
Forks: 4
Open Issues: 0
Type:sylius-plugin
Requires
- php: ^7.1
- behappy/company-data-plugin: ^1.0.1
- knplabs/knp-snappy-bundle: ^1.5
- sylius/sylius: ^1.1
Requires (Dev)
- behat/behat: ^3.3
- behat/mink: ^1.7
- behat/mink-browserkit-driver: ^1.3
- behat/mink-extension: ^2.2
- behat/mink-selenium2-driver: ^1.3
- friends-of-behat/context-service-extension: ^1.0
- friends-of-behat/cross-container-extension: ^1.0
- friends-of-behat/service-container-extension: ^1.0
- friends-of-behat/symfony-extension: ^1.0
- friends-of-behat/variadic-extension: ^1.0
- lakion/mink-debug-extension: ^1.2.3
- phpspec/phpspec: ^3.2
- phpstan/phpstan-shim: ^0.9.2
- phpunit/phpunit: ^6.5
- se/selenium-server-standalone: ^2.52
- sylius-labs/coding-standard: ^1.0
- symplify/easy-coding-standard: ^2.4
This package is not auto-updated.
Last update: 2022-02-01 13:10:19 UTC
README
A Plugin for Sylius to generate invoices
Installation-procedure
$ composer require behappy/invoice-plugin
Informations
This plugin use Knp Snappy Bundle. Please refer to it's documentation for wkhtmltopdf installation (https://github.com/KnpLabs/snappy)
Enable the plugin
Enable those plugins in AppKernel
// in app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Knp\Bundle\SnappyBundle\KnpSnappyBundle(), new \BeHappy\SyliusCompanyDataPlugin\BeHappySyliusCompanyDataPlugin(), new \BeHappy\SyliusInvoicePlugin\BeHappySyliusInvoicePlugin(), ); // ... }
#in app/config/config.yml imports: ... - { resource: "@BeHappySyliusCompanyDataPlugin/Resources/config/config.yml" } - { resource: "@BeHappySyliusInvoicePlugin/Resources/config/config.yml" } ...
# in routing.yml ... behappy_company_data_plugin: resource: '@BeHappySyliusCompanyDataPlugin/Resources/config/routing.yml' behappy_invoice_plugin.admin: resource: '@BeHappySyliusInvoicePlugin/Resources/config/routes/admin.yml' prefix: /admin behappy_invoice_plugin.shop: resource: '@BeHappySyliusInvoicePlugin/Resources/config/routes/shop.yml' prefix: /{_locale}/account requirements: _locale: ^[a-z]{2}(?:_[A-Z]{2})?$ ...
Generate database
Simply launch
php bin/console doctrine:schema:update --dump-sql --force
You might have tables referring to BeHappySyliusCompanyDataPlugin if you did not enabled it before requiring this plugin
Optional : generate invoices
In order to have invoices for previously placed orders, you can run this command :
php bin/console behappy:invoices:generate
This command will generate invoices for all orders in state FULFILLED with no invoices attached
That's it !
From now on, each and every time an order is fulfilled, the event listener will create a new invoice and copy (if needed) company data information into a separate table to make them static.
A new block is also displayed in admin under the shipment section of orders that have an invoice linked.
In the account section for your customers, a link is also displayed for every invoice linked to their orders.
Configuration
Invoice number
By default, invoices will be generated with a 12 digits number filled with 0 (str_pad(12, '0', STR_PAD_LEFT))
You can redefine this length definition by overriding this :
# in app/config.yml parameters: ... behappy_invoice_plugin.invoice_number.length: 14 ...
Now every invoice will be 14 digits long.
In a near future, this plugin will use a number generator that you'll be free to override according to your needs.
Events
During the invoice creation, 2 events are fired with the order as argument.
behappy_invoice_plugin.event.invoice.pre_create behappy_invoice_plugin.event.invoice.post_create
You can subscribe to those events and do whatever you need
Override
In order to override the pdf template file, you simply have to create the following file : app/Resources/BeHappySyliusInvoicePlugin/views/Invoice/pdf.html.twig
Thanks
This plugin is partially inspired by BitBagCommerce/SyliusInvoicingPlugin (https://github.com/BitBagCommerce/SyliusInvoicingPlugin).
Feel free to contribute
You can also ask your questions at the mail address in the composer.json mentioning this package.
Other
You can also check our other packages (including Sylius plugins) at https://github.com/BeHappyCommunication