Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action(
- 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
- 'act_ee4_assign_invoicenr', 10, 2
- ); // 1, 2
- function act_ee4_assign_invoicenr( $registration, $update_params ) {
- // get registration status. $registration is passed through the hook
- $registration_status = $registration->status_ID();
- $reg_status_value = EEM_Status::instance()->get_var(
- array(
- array(
- 'Registration.STS_ID' => $registration_status
- ),
- 'limit' => 1
- ),
- 'STS_code'
- );
- // get transaction
- $transaction = $registration->transaction();
- $transaction_status = $transaction->status_ID();
- // admin question id
- $invoice_question_id = 21;
- // Assemble custom invoice number if the registration is approved
- if ($registration_status == "RAP") {
- // get invoice number, year and prefix from options table
- $current_year = (int) date( 'Y' );
- $invoice_prefix = "20"; //get_option( 'invoice_prefix' );
- $invoice_year = (int) get_option( 'invoice_year' ); // e.g. 2017
- $invoice_order = (int) get_option( 'invoice_order' ); // e.g. 24
- // increment year value if current year is higher
- if ( $invoice_year != $current_year ) {
- update_option( 'invoice_year', $current_year );
- update_option( 'invoice_order', 1 );
- }
- // increment invoice number for next invoice
- update_option( 'invoice_order', $invoice_order + 1 );
- // assemble invoice number
- $invoice_number = $invoice_prefix . $invoice_year
- . str_pad( $invoice_order, 4, '0', STR_PAD_LEFT );
- }
- else{
- // Otherwise temporarily populate the answer with the Registration Status Value
- $invoice_number = $reg_status_value;
- }
- // Assign Invoice Number
- // Check if there is an answer for this question already
- $prev_answer_value = EEM_Answer::instance()->get_answer_value_to_question($registration, $invoice_question_id, false);
- if( $prev_answer_value ) {
- // If answer exists, update it
- $prev_answer_object = EEM_Answer::instance()->get_registration_question_answer_object($registration, $invoice_question_id, false);
- $prev_answer_object->set('ANS_value', $invoice_number);
- $prev_answer_object->save();
- }
- else{
- // if it doesn't exist insert it
- EEM_Answer::instance()->insert(
- array(
- 'REG_ID' => $registration->ID(),
- 'QST_ID' => $invoice_question_id, // admin only question 'invoice number'
- 'ANS_value' => $invoice_number
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement