DCInterSrvc Posted October 21, 2015 Share Posted October 21, 2015 Hello, I would like to know if there is a solution to generate sequential invoice numbers by using 2 whmcs installations. Example Site A and Site B. Site A generates invoice 2, the next invoice number that should be generated on Site A or B should be invoice 3, and so on. As a workaround I had the following idea: The SequentialInvoiceNumberValue entry in the tblConfigurations keeps the next invoice number which I think could could help by keeping this value synchronized between the whmcs installations. I could create a hook on each installation using InvoicePaid "event" where I could update the other installations with the new value by opening mysql remote access and running the update SQL Any thoughts or different ideas? 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted October 21, 2015 Share Posted October 21, 2015 Hi, Of course it's possible with a customized solution. Few months ago I started to work on this matter but it's trickier than it looks at first sight. I personally managed to create an interface in one of my modules where you can insert all your WHMCS systems (one per line) and then enjoy the synchronization of invoice numbers but, even if it works, you can't use it in a real scenario it's not so easy in fact I have never released this feature. The most obvious problem is that in reality you need to +1 when invoices become paid and -1 when they're deleted on all WHMCS systems simultaneously and with "simultaneously" I mean in the same exact time and this is impossible to achieve with an hook-based system. What if one of your systems is offline or not reachable even for a very short time? All invoices become immediately unsynchronized and it doesn't matter how hard you try to force an automatic resync because the damage is done not to mention that you're not allowed by law to change the number of an invoice. In addition to this, you also need to reset the sequential number to 1 the first day of every year on all systems and update this number everytime you manually change the Sequential Invoice Number from the configuration page of one of your WHMCS installations. That said, it's clear that an hook-based solution is not possible because it is not fault-tolerant. As soon as something goes wrong in the chain it's gameover and a total mess. To me the only possible approach to achive this goal is to develop a centralized system totally unlinked from the dataflow and procedures of all your WHMCS installations. This system only has to give the right invoice number when requested and +1 or -1 after a confirmation. Basically it's a customized API with 4 functions: GetCurrentInvoiceNumber ConfirmInvoicePaid (+1) ConfirmInvoiceDeleted (-1) OverwriteCurrentInvoiceNumber You have to GetCurrentInvoiceNumber() when an invoice becomes paid, apply the given number to your invoice and return a ConfirmInvoicePaid() to +1 the number. Similarly you have to ConfirmInvoiceDeleted() to -1 the number when you delete an invoice. In case for some reason the API doesn't respond, you have to locally save the all events as "Pending", leave invoices untouched and process them later with the daily CRON. It's doable but a pain Maybe I'm overthinking it but I can't find a different solution. 0 Quote Link to comment Share on other sites More sharing options...
DCInterSrvc Posted October 22, 2015 Author Share Posted October 22, 2015 Thank you for the inputs I did not think of it very deeply, without a proper error handling it is likely to fail. Implementing a separate system could be a solution but right now I won't go with that. Maybe by chance someone already implemented such a system ... 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.