Skip to content

Generate an Invoice for every placed order

License

Notifications You must be signed in to change notification settings

bartek-sek/InvoicingPlugin

This branch is 9 commits behind Sylius/InvoicingPlugin:1.0.

Folders and files

NameName
Last commit message
Last commit date
Jan 10, 2025
Nov 20, 2024
Dec 11, 2024
Dec 12, 2024
Jun 15, 2018
Mar 1, 2024
Nov 20, 2024
Dec 6, 2024
Nov 25, 2024
Dec 11, 2024
Nov 20, 2024
Aug 26, 2018
Aug 20, 2021
Dec 3, 2024
Nov 18, 2024
Oct 30, 2024
Dec 12, 2024
Dec 11, 2024
Nov 15, 2024
Nov 18, 2024
Nov 6, 2024
Jun 15, 2018
Jun 15, 2018
Nov 6, 2024
Jun 6, 2019

Repository files navigation

Sylius Logo.

Invoicing Plugin

This plugin creates an invoice related to the order.

SyliusInvoicingPlugin creates new immutable invoice when the order is in given state (default: created) and allows both customer and admin to download invoices related to the order.

Screenshot showing invoice Screenshot showing invoice browsing page in administration panel

Business value

The primary aim of Invoicing Plugin is to create a document representing Customer's will to buy particular products and pay for them.

An Invoice can also be treated as a proof of placing an Order. Thus, it is downloadable as .pdf file and can be sent to Customer manually by the Administrator or automatically once an Order is paid.

Additional feature of the plugin that fulfills Invoicing domain is the ability to set billing data on a Seller.

Installation

Beware!

This installation instruction assumes that you're using Symfony Flex. If you don't, take a look at the legacy installation instruction. However, we strongly encourage you to use Symfony Flex, it's much quicker!

  1. Require plugin with composer:

    composer require sylius/invoicing-plugin

    Remember to allow community recipes with composer config extra.symfony.allow-contrib true or during plugin installation process

  2. Apply migrations to your database:

    bin/console doctrine:migrations:migrate
  3. Default configuration assumes enabled PDF file generation. If you don't want to use that feature change your app configuration:

    # config/packages/sylius_invoicing.yaml
    sylius_invoicing:
        pdf_generator:
            enabled: false

    Otherwise, check if you have wkhtmltopdf binary. If not, you can download it here.

    In case wkhtmltopdf is not located in /usr/local/bin/wkhtmltopdf modify the WKHTMLTOPDF_PATH environment variable in the .env file:

    WKHTMLTOPDF_PATH=/usr/local/bin/wkhtmltopdf # Change this! :)
    
  4. If you want to generate invoices for orders placed before plugin's installation run the following command using your terminal:

    bin/console sylius-invoicing:generate-invoices

Extension points

Majority of actions contained in SyliusInvoicingPlugin is executed once an event after changing the state of the Order.

Here is the example for Winzou State Machine:

winzou_state_machine:
    sylius_payment:
        callbacks:
            after:
                sylius_invoicing_plugin_payment_complete_producer:
                    on: ['complete']
                    do: ['@sylius_invoicing_plugin.event_producer.order_payment_paid', '__invoke']
                    args: ['object']

Code placed above is a part of configuration placed in config.yml file. You can customize this file by adding new state machine events listeners or editing existing ones.

Here is the example for Symfony's workflow:

<service id="sylius_invoicing_plugin.event_listener.workflow.payment.produce_order_payment_paid"
       class="Sylius\InvoicingPlugin\EventListener\Workflow\Payment\ProduceOrderPaymentPaidListener">
   <argument type="service" id="sylius_invoicing_plugin.event_producer.order_payment_paid" />

   <tag name="kernel.event_listener" event="workflow.sylius_payment.completed.complete" priority="100" />
</service>

Apart from that an Invoice model is treated as a Resource.

You can read more about Resources here:

http://docs.sylius.com/en/latest/components_and_bundles/bundles/SyliusResourceBundle/index.html.

Hence, template for displaying the list of Invoices is defined in routing.yml file:

sylius_invoicing_invoice:
    resource: |
        alias: sylius_invoicing.invoice
        section: admin
        templates: "@SyliusAdmin\\Crud"
        only: ['index']
        grid: sylius_invoicing_invoice
        permission: true
        vars:
            all:
                subheader: sylius_invoicing.ui.manage_invoices
            index:
                icon: inbox
    type: sylius.resource

Another aspect that can be both replaced and customized is displaying Invoices list on Order show view. Code responsible for displaying Invoices related to the Order is injected to existing Sylius template using Sonata events. You can read about customizing templates via events here:

http://docs.sylius.com/en/latest/customization/template.html

Invoices files

By default, when the order is paid, an immutable Invoice pdf file is saved on the server. The save directory is specified with %sylius_invoicing.invoice_save_path% parameter, that can be overridden if needed.

There is no direct relation between Sylius\InvoicingPlugin\Entity\Invoice entity and its file. It's resolved based on the Invoice::$number, which is defined in Sylius\InvoicingPlugin\Provider\InvoiceFileProviderInterface service. By overriding this service, you can change a logic that is used to retrieve the invoice file.

Fixtures

You can add ShopBillingData fixtures into a yaml to add Channel ShopBillingData info to your installation. More instructions on the fixtures configuration instructions.

Security issues

If you think that you have found a security issue, please do not use the issue tracker and do not post it publicly. Instead, all security issues must be sent to security@sylius.com.

About

Generate an Invoice for every placed order

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 81.0%
  • Gherkin 10.8%
  • Twig 7.5%
  • JavaScript 0.7%