SyliusInvoicingPlugin icon indicating copy to clipboard operation
SyliusInvoicingPlugin copied to clipboard

[FR] Generate invoices at «complete» Order state and invoice number template

Open ambroisemaupate opened this issue 7 years ago • 4 comments

I will try to create a PR for this.

French law requires e-commerce resellers to:

  • send invoices for their customers even if they’re not professional and even without VAT number,
  • have unique and consecutive invoice numbers for the same selling unit (channel)

So I suggest to enhance this plugin to subscribe to the Sylius order completed state to generate invoice only if payment has succeded, not to generate invoices all the time (kind of boring to generate cancelled invoices if user changes his mind before payment). In this case, invoices are acting like order receipts that resellers have to print and include into the shipping box at least, but it occurs after payment and not before.

For the unique and consecutive invoice numbers, I suggest to add configurable and automatic number template. For example: WEB-YYYY-XXXXX should stand for WEB-2018-00001 for the first invoice generated in 2018. We can even use channel code such as in $channel-YYYY-XXXXX. This invoice number template could be editable in the config.yml or, even better, in the CompanyData entity.

  • I can provide this invoice number generator feature in a Composer lib as I’ve already developed this for an other PHP project.

These features may lead too far from this original plugin goal, but we can add this as an optional and configurable features.

Sorry for the long issue… 🥔

ambroisemaupate avatar Feb 28 '18 19:02 ambroisemaupate

Hi! Thanks, that's a lot of information. First, I think we should consider making CompanyData aware of Channels. I also believe that we should be able to configure whether the VAT number for this specific channel should be validated and if it should be sent to the customer after the payment has proceeded. Doing it the same way as it's done in the channel config with skip payment/shipment step if one available would be perfect. We should remember that it's a plugin and it should solve more than one problem, as there might be users who would need to use it in another way the French law allows.

Secondary, although payment event is great, you should consider a state machine callback for this purpose. Payments are not being managed through resource events, they do through the state machine though.

What do you think?

bitbager avatar Feb 28 '18 23:02 bitbager

Hi @bitbager
Thanks for you interest !

Making CompanyData aware of Channels is a great idea, so we could add:

  • channel OneToOne field to CompanyData
  • invoiceNumberTemplate string to CompanyData
  • validateCustomerVatNumber boolean to CompanyData or Channel?
  • generateInvoiceAfterPaymentSuccess boolean to CompanyData or Channel?

It’s my first project with Sylius, so I’m new with their payment state machine.

See https://github.com/ambroisemaupate/SyliusInvoicingPlugin/commits/channel-aware WIP branch.

ambroisemaupate avatar Mar 01 '18 08:03 ambroisemaupate

I think that all of these data should be assofisted with CompanyData model. Also allowing string template path is not a good idea. Let’s make it a ChoiceType of constants and for customization, we will include a reference to Symfony FormExtension documentation. How is the progress btw? 😉

bitbager avatar Mar 09 '18 08:03 bitbager

Progress is good!
Invoice generation and email sending is done on Payment state-machine transition, I’ve added all fields into CompanyData. I need now to make invoice number configurable and improve invoice template to display VAT, Shipping and reductions.

I’ll publish my PR when I’m back on this project. 🤞
Do not hesitate to have a look on my branch… https://github.com/ambroisemaupate/SyliusInvoicingPlugin/commits/channel-aware

ambroisemaupate avatar Mar 09 '18 17:03 ambroisemaupate