$event->eid,)); //empty payment option $payment_type_options[0] = ''; foreach($result as $row) { $price = $early_price_applies == true ? $row->booking_price : $row->booking_late_price; $payment_type_options[$row->pid] = $row->booking_price_descrip . ' ($' . $price . ')'; } //any html to put at the start of the form $prefix = t("

Manually enter payment details.
Note that this adds to the total amount paid already by each person - the choice below is not yet implemented.

"); $form['booking_earlybird'] = array ( '#type' => 'hidden', '#value' => $early_price_applies, ); $form['payment-type'] = array( '#type' => 'select', '#title' => t('Payment Type'), '#required' => TRUE, '#default_value' => '0', '#options' => $payment_type_options, ); $form['payment-custom-amount'] = array( '#type' => 'textfield', '#title' => t('Custom Amount Paid'), '#maxlength' => 10, '#field_prefix' => '$', '#required' => FALSE, '#default_value' => '0.00' ); $form['payment-balance-type'] = array( '#type' => 'radios', '#title' => t('Balance or total payment?'), '#description' => t('If this is a total payment, the amount selected above will be added to any existing payment. ' . 'For balance payments, the amount paid is the total above minus any previous payments.
Select balance if the person had already paid their deposit and now has manually paid any outstanding balance.') '#options' => $payment_balance_options, '#default_value' => 0, '#required' => TRUE ); $header = array ( 'booking_nid' => array('data' => t('Booking ID')), 'booking_name' => array('data' => t('Name')), 'booking_email' => array('data' => t('Email Address')), 'amount_paid' => array('data' => t('Amount Paid To Date')), 'amount_reqd' => array('data' => t('Gross Payment Required')), 'booking_status' => t('Status'), 'booking_fully_paid' => t('Fully Paid?'), 'welfare_required' => t('Welfare Required?'), ); $result = db_query("SELECT * FROM {booking_person} WHERE booking_event_id = :eid", array(':eid' => $event->eid)); foreach($result as $data) { $options[$data->nid] = array ( 'booking_nid' => l(t('!id', array('!id' => $data->nid)), t('node/!id', array('!id' => $data->nid))), 'booking_name' => $data->booking_firstname . " " . $data->booking_lastname, 'booking_email' => $data->booking_email, 'amount_paid' => $data->booking_amount_paid, 'amount_reqd' => $data->booking_total_pay_reqd, 'booking_status' => _booking_status_generate($data->booking_status), 'booking_fully_paid' => $data->booking_amount_paid < $data->booking_total_pay_reqd ? 'No' : 'Yes', 'welfare_required' => $data->booking_welfare_required == 'Y' ? 'Yes' : 'No', ); } $form['table'] = array ( '#type' => 'tableselect', '#header' => $header, '#options' => $options, ); $form['submit'] = array ( '#type' => 'submit', '#value' => t('Update'), ); return array ( 'first_para' => array ( '#type' => 'markup', '#markup' => $prefix, ), 'form' => $form, ); } function booking_manual_payment_admin_submit($form, &$form_state) { global $event; $counter = 0; $price = 0; $fully_paid = 'N'; $payment_date = REQUEST_TIME; $checkboxes = $form_state['values']['table']; //$values['booking_price_active']; //watchdog('booking', 'Formstate when setting buttons: @info', array ('@info' => var_export($form_state['values'], TRUE))); //watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE))); //watchdog('booking', 'Manual payment form contents: @info', array('@info' => var_export($form_state['values'], TRUE))); //check if there is a pre-defined payment type selected if ($form_state['values']['payment-type'] != '' && $form_state['values']['payment-custom-amount'] == '0.00') { //look up the price relating to the price id selected $price_query = db_query("SELECT price.booking_price, price.booking_late_price, price.booking_price_descrip " . "FROM {booking_price} price " . "WHERE price.pid = :pid ", array(':pid' => $form_state['values']['payment-type'])) ->fetchObject(); $price = $form_state['values']['booking_earlybird'] == true ? $price_query->booking_price : $price_query->booking_late_price; $description = $price_query->booking_price_descrip; } elseif ($form_state['values']['payment-custom-amount'] != '0.00' && is_numeric($form_state['values']['payment-custom-amount'])) { $price = $form_state['values']['payment-custom-amount']; $description = "Custom Amount"; } else { drupal_set_message("Error: Could not determine payment amount to update user(s).", 'error', FALSE); return; } //loop through the list of attendees foreach($checkboxes as $key => $value) { //if an attendee's checkbox was ticked, then process their payment if (is_numeric($key) && $value != 0) { //check if they exist in the database first /* $person = db_query("SELECT person.nid, person.booking_firstname, person.booking_lastname, person.booking_status, " . "person.booking_partner_id, person.booking_amount_paid " . "FROM {booking_person} person " . "WHERE nid = :nid", array(':nid' => $key)) ->fetchObject(); */ $person = node_load($key); if ($person) { //add this payment to their existing balance $total_paid = $person->booking_amount_paid + $price; //check if they have now fully paid if ($total_paid >= _booking_total_due($person)) { $fully_paid = 'Y'; } //work out what their booking status is now if ($person->booking_status == 1 || _booking_check_bookings_full() == FALSE) { //either they were already booked in, or there is room on the booked-in list $status = 1; } else { //there must be a waiting list, so put them on that $status = 2; } /* //determine what their booking status is now if (_booking_check_bookings_full() == True || $person->booking_status == 2) $status = 2; else $status = 1; */ watchdog('booking', 'Setting payment for regn id !nid to $!price and status to !status', array('!nid' => $key, '!price' => $price, '!status' => $status)); db_update('booking_person') ->fields(array( 'booking_amount_paid' => $total_paid, 'booking_status' => $status, 'booking_payment_complete' => $fully_paid, )) ->condition('nid', $key) ->execute(); //Create a payment record entry for this update $result = db_insert('booking_payment') ->fields(array( 'booking_person_nid' => $key, 'booking_eventid' => $event->eid, 'booking_mc_gross' => $price, 'booking_mc_currency' => 'AUD', 'booking_mc_fee' => '0.00', 'booking_quantity' => 1, 'booking_invoice' => 'ManualPayment', 'booking_payer_id' => '', 'booking_payment_date' => $payment_date, 'booking_payment_status' => '', 'booking_first_name' => $person->booking_firstname, 'booking_last_name' => $person->booking_lastname, 'booking_buyer_email' => '', 'booking_payer_status' => '', 'booking_item_name' => $description, 'booking_ipn_track_id' => '', )) ->execute(); $counter++; } else drupal_set_message("Error: Unable to find person with registration ID " . $key, 'error', FALSE); } } drupal_set_message("Added manual payments for $counter people of " . '$' . "$price.", 'status', FALSE); }