Sequential invoice numbers

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
I need order invoices to be sequential but playing around with the checkout process I see that the order itself is used as an invoice (or am I mistaken?) which made me worry about this scenario:

A customer tries to make the payment with paypal (using the redirect approach) but fails for whatever reason and abandons the process. Since the cart was turned into an order that wasn't fulfilled the next time a successful order is made it will skip a number. This will cause the accounting report to have a non-sequential series of invoice numbers that would cause our accountant all kinds of delays.

Am I correct or does nop generates an invoice/order sequential number only for fulfilled orders?

Thanks,
Jose
9 years ago
josemarmolejos wrote:
I need order invoices to be sequential but playing around with the checkout process I see that the order itself is used as an invoice (or am I mistaken?) which made me worry about this scenario:

A customer tries to make the payment with paypal (using the redirect approach) but fails for whatever reason and abandons the process. Since the cart was turned into an order that wasn't fulfilled the next time a successful order is made it will skip a number. This will cause the accounting report to have a non-sequential series of invoice numbers that would cause our accountant all kinds of delays.

Am I correct or does nop generates an invoice/order sequential number only for fulfilled orders?

Thanks,
Jose

Hi José:
You are right. The order number will skip orders with payments not concluded (Papal CC, check, COD, etc.) and it is the same used in invoices.
9 years ago
Thanks for the reply man, I just tested out and confirmed this (not that I doubted you :P ). So what are my options then? I was thinking about cloning and modifying the paypal plugin to generate an invoice after the whole process was completed successfully as I cannot think of a better place to put the invoice generating code.

Any thoughts, pointers, warnings will be appreciated.
9 years ago
It gets even uglier if you're using SQL Server 2012
https://www.nopcommerce.com/boards/t/22778/order-id-jupt-form-940-to-1940.aspx
https://www.nopcommerce.com/boards/t/26423/sql-server-2012-identity-problem-huge-gaps-after-restarting-server.aspx
9 years ago
Indeed New York! And get a bit uglier when you got two stores running on the same implementation. I got a prototype working by saving a numbers series to the settings tables on the plugin's Install() method and then consuming the OrderPaid event to grab the first number from the series, remove it and save back the series as a string in the settings table. This number is attached to the order entity as a generic attribute. Here's the code:

https://gist.github.com/jmarmolejos/4f619bd53074d141f517

Regards,
Jose
9 years ago
If you need sequential numbers, then I don't see the point of a "series".  Just store one number; read it, use it, increment it, store it back.  However, your method is not thread safe (multiple simultaneous requests could use the same number).  Probably should use a SEQUENCE in the database (although even with NO CACHE it's possible to get small gaps).

(Also why using IConsumer<AdminTabStripCreated>?)
9 years ago
Yep, it is very prone to concurrency issues so I'll try to hack in some table locking bits into it. I forgot to remove the tabcreated event bits from the gist, it's used for something else. Thanks for the idea on storing just the last number used, I'll definitely try it out.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.