Sequential Invoice Numbers

Hi there

I've been very impressed so far with this plugin, which almost exactly fits my client's needs.

The one thing that is a huge barrier for us is the way it numbers invoices. UK (and in some EU countries like Germany) legislation states that invoices should have a continuous sequential series. From what I can see the plugin numbers invoices based on the next available post id which is not sequential.

I've managed to fix this by making use of the various filters that I've found, but unfortunately I've run into another stumbling block, and that's that the plugin creates the next year's invoice before the previous one has even been paid. This causes issues because for my client, renewals won't be negotiated until a month before, and means there'll be large gaps in the invoice sequence if he deletes the automatically generated invoices for the next period.

Is there any way to disable the automatic generation of the next invoice or have these invoices generated X number of days before the current subscription period elapses?

  • Dimitris

    Hey there Ben Coates,

    hope you're doing good and thanks for reaching us!

    I really appreciate the feedback here but this kind of question really surpasses the scope of this forum and it should be considered custom development. For this kind of work, feel free to advise our Jobs & Pros section (no WPMUDEV staff members included).

    Despite that, I forwarded this request to our Second Level Support guys, just in case there is any kind of hotfix that could be provided here. I'll keep you posted here as soon as I've got any valuable feedback from them.

    Finally, I could actually move this thread to Features & Feedback for more member engagement and consideration from our dev team. I really can't promise anything here or provide any kind of ETA on this.

    Warm regards,
    Dimitris

    PS. If you could share your workaround about the sequential invoice numbers it would be awesome for other member too I guess!

  • Ben Coates

    Hi Dimitris

    Thanks so much for getting back to me on this one, and my apologies for the delay in reply.

    I think I've worked out what causes the problem for us, and that's because I am hooking into the point at which the invoice is created (even if it is created in draft)

    Ideally, I'd need to hook into the point in the code where an invoice is actually SENT to the customer... I'm new to the plugin, so I don't know when this happens or how to control it - is the invoice sent automatically when the subscription is renewed again after the initial period expires?

    My workaround to get the invoices to display a sequential number used the following functions (just pasted into my functions.php in this case but they could easily be used in a custom plugin)

    add_filter('ms_model_invoice_create_before_save', 'bcwpmu_mod_invoice', 10, 2);
    add_filter('ms_model_invoice_the_number', 'bcwpmu_mod_inv_no', 10, 2);
    
    function bcwpmu_mod_invoice($invoice, $subscription) {
    
    	if ( ! get_option('bcwpmu_inv_counter') )
    	{
    
    		add_option('bcwpmu_inv_counter', 1000);
    
    	}
    
    	$invoice_number = get_option('bcwpmu_inv_counter');
    
    	$invoice->invoice_seq_number = $invoice_number;
    	$invoice_number++;
    
    	update_option('bcwpmu_inv_counter', $invoice_number );
    
    	return $invoice;
    
    }
    
    function bcwpmu_mod_inv_no($identifier, $invoice) {
    
    	return "#WMS-".$invoice->invoice_seq_number;
    
    }

    I did have to modify the class-ms-model-invoice.php file to introduce an extra meta field called 'invoice_seq_number' as I wasn't sure about modifying the actual invoice numbers in case this interferes with the logic of the plugin.

    The first function is hooked onto the ms_model_invoice_create_before_save hook - and this is where the problem emerges

    The Membership Pro plugin seems to create a draft of the next invoice in the sequence at the point of the current invoice being created (not immediately but it seems to run some kind of wpcron task to do this) - when I log into the admin after an hour or two of creating a membership, there's an invoice for the current period, and then another in drafts which has the next sequential number up from the one initially created.

    What I want to be able to do is hook my custom function in LATER in the process, so it's fine for Membership Pro to create a draft invoice with the default numbering system, but then just before the point at which the invoice is actually SENT to the customer, I wondered if there is a hook that I can use to modify the invoice number at that point. That way my sequence would stay intact with no gaps and would be sequential at the point the invoices are sent, rather than when they are generated.

    I hope you can follow what I am trying to achieve. I've looked at the API docs and I can't see an actual list of hooks that are available - which means reading through - and understanding - all of the code for this plugin. Maybe you could give me some kind of head-start, and then if I get to a solution, I can post it in full for other users.

    many thanks
    Ben

  • Adam Czajczyk

    Hello Ben!

    I have forwarded this thread to one of my colleagues who's been involved a bit in Membership 2 Pro coding/updates so I believe he should be able to lend us a helping hand on this. Please note though that he's just going back to work after his vacation so he might be a little overloaded with tasks so I'd really appreciate a tiny bit of patience on this

    I'll update this thread for you as soon as I get a replay.

    Best regards,
    Adam

  • Adam Czajczyk

    Hello Ben!

    I just got an information on that and it seems that it's not possible to modify an invoice "on send" and the next invoice must be created in "the previous state of recurring" which means that if for example the billing period is one year then this year the system will create next year's invoice.

    As for disabling the automatic generation of the next invoice or having them created a number of days before current subscription period ends. That is currently not an option and introducing it would require further customization of plugin's core.

    Kind regards,
    Adam

  • Ben Coates

    Hi Mahlamusa

    Thanks for getting in touch. Yea, I did get the response, I was a little overwhelmed at the time and because of the way the plugin works and the lack of ability to hook into the invoice creation process, it's unfortunately not going to work for us, we are investigating other solutions instead.

    In my opinion, a better way of creating recurring invoices would be to do them on a cron schedule where you can set the number of days in advance to generate the next invoice in the sequence.

    This is really important for companies in Europe where we have to have sequential invoice numbers - plus it would not make sense for us to have an invoice generated a whole calendar year in advance of the service to which it relates.

    Hopefully some useful feedback that you can pass on, as I say, because of these things the plugin just won't fit our use case unfortunately.

    Thanks again

  • Adam Czajczyk

    Hello Ben,

    thank you for your reply.

    I see the point of that "numbering structure", though I'm not aware if there are already any plans to implement it. I have moved this thread to our "Features and Feedback" forum in order to get it into the attention of developers and other members. Let's hope that this idea gets more feedback and support and our developers will then put it on development roadmap.

    Best regards,
    Adam