Support

Home Forums Event Espresso Premium Sequential invoice numbers – my solution works, almost…

Sequential invoice numbers – my solution works, almost…

Posted: September 16, 2017 at 12:42 pm

Viewing 3 reply threads


sara.bosman

September 16, 2017 at 12:42 pm

In Belgium (like many European countries) sequential invoice numbers are mandatory; therefore they need to be generated right after registration. My code:

// assign invoice number right after registration
add_action( 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'act_ee4_assign_invoicenr', 10, 2); 

function act_ee4_assign_invoicenr( $registration, $update_params ) {
  // get transaction
  $transaction = $registration->transaction();

  // get invoice year and prefix
  $current_year = (int) date( 'Y' ); 
  $invoice_prefix = get_option( 'invoice_prefix' ); // e.g. EE-
  $invoice_year = (int) get_option( 'invoice_year' ); // e.g. 2017

  // happy new year
  if ( $invoice_year != $current_year ) {
    update_option( 'invoice_year', $current_year );
    update_option( 'invoice_order', 1 );
  }

  // get invoice number
  $invoice_order = (int) get_option( 'invoice_order' ); // e.g. 24

  // increment for next invoice
  update_option( 'invoice_order', $invoice_order + 1 );

  // assemble invoice number and assign
  $invoice_number = $invoice_prefix . $invoice_year 
    . str_pad( $invoice_order, 4, '0', STR_PAD_LEFT ); // e.g. EE-20170024
  EEM_Answer::instance()->insert(
    array(
      'REG_ID' => $registration->ID(),
      'QST_ID' => 16, // admin only question 'invoice number'
      'ANS_value' => $invoice_number
    )    
  );
}

Question number 16 is an admin question called ‘invoice number’ added to the user details system group. This works most of the time, but randomly, the invoice number is not filled and remains empty.

Any idea of what’s going wrong?

  • This topic was modified 7 years ago by Tony. Reason: code formatting


sara.bosman

September 17, 2017 at 1:36 pm

An update: a customer (accidentally) subscribed twice for the same event (albeit on two different days). The first time, no invoice number was assigned, the second time, there was. Same code, same event, same user data, different results. Strange.


Tony

  • Support Staff

September 18, 2017 at 5:30 am

Hi there,

I recommend creating an issue here:

https://github.com/eventespresso/event-espresso-core/issues

Our developers can review this there and provide some feedback.


sara.bosman

September 19, 2017 at 3:18 pm

Haha, ok, I got it. Apparently when a user fills out the registration form and proceeds to the payment step, an AJAX call already registers him on the background before completing the payment step. The payment only adds a transaction entry to the registration.

This means that if a user, after completing the user info step, presses the back button before paying, refills the registration form and then pays, he is registered twice for the same event, albeit with only one transaction. We had a user who did that 4 times, so now he is registered 4 times for the same event: 3 incomplete and 1 complete registration.

It’s a little bit strange, but it sort of makes sense.

Viewing 3 reply threads

The support post ‘Sequential invoice numbers – my solution works, almost…’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso