diff --git a/booking.admin.inc b/booking.admin.inc index d907968..7e5312a 100644 --- a/booking.admin.inc +++ b/booking.admin.inc @@ -110,7 +110,7 @@ function booking_admin() { '#options' => _booking_country_options(), '#default_value' => variable_get('booking_default_country', 'Australia'), ); - //TODO: reverse the logic of the values + $form['misc']['booking_auto_confirm_email'] = array ( '#type' => 'radios', '#title' => t('Automatic Registration Email'), @@ -118,6 +118,13 @@ function booking_admin() { '#options' => array (0 => t('No'), t('Yes')), '#default_value' => variable_get('booking_auto_confirm_email', 0), ); + $form['misc']['booking_auto_workflow_email'] = array ( + '#type' => 'radios', + '#title' => t('Automatic Workflow Email'), + '#description' => t('Automatically send workflow emails such as status changes, travel details received, etc'), + '#options' => array (0 => t('No'), t('Yes')), + '#default_value' => variable_get('booking_auto_workflow_email', 0), + ); $form['misc']['booking_auto_show_on_lists'] = array ( '#type' => 'radios', '#title' => t('Show on lists once booked in?'), @@ -201,6 +208,14 @@ function booking_admin() { '#options' => array (0 => t('No'), t('Yes')), '#default_value' => variable_get('booking_enable_studygroups', 0), ); + $form['misc']['booking_studygroup_count'] = array ( + '#type' => 'textfield', + '#title' => t('Number of study groups'), + '#description' => t("Total number of study groups in use."), + '#size' => 3, + '#maxlength' => 3, + '#default_value' => variable_get('booking_studygroup_count','0'), + ); $form['misc']['booking_csv_exclude_fields'] = array ( '#type' => 'textfield', '#title' => t('Fields to exclude from CSV report'), @@ -310,6 +325,7 @@ function booking_manual_email() foreach($result as $data) { + //$paid = _booking_amount_owing($data); $paid = _booking_amount_owing($data->nid); $options[$data->nid] = array ( 'booking_nid' => l(t('!id', array('!id' => $data->nid)), t('node/!id', array('!id' => $data->nid))), diff --git a/booking.emails.inc b/booking.emails.inc index 3d61134..3f836a0 100644 --- a/booking.emails.inc +++ b/booking.emails.inc @@ -254,6 +254,13 @@ function _booking_promoted_from_waitinglist_email($nid) global $user; $language = user_preferred_language($user); + //return without doing anything if we shouldn't send workflow emails + if (variable_get('booking_auto_workflow_email', 0) == 0) + { + watchdog('booking', 'Not sending promoted-from-waitinglist email since that feature is currently disabled.'); + return; + } + //load the node matching this id $node = node_load($nid); $tokens = booking_define_personspecific_tokens($node); @@ -287,6 +294,13 @@ function _booking_demoted_to_notcoming_email($nid) global $user; $language = user_preferred_language($user); + //return without doing anything if we shouldn't send workflow emails + if (variable_get('booking_auto_workflow_email', 0) == 0) + { + watchdog('booking', 'Not sending not-coming email since that feature is currently disabled.'); + return; + } + //load the node matching this id $node = node_load($nid); $tokens = booking_define_personspecific_tokens($node); @@ -321,6 +335,13 @@ function _booking_travelform_confirmation_email($nid) global $user; $language = user_preferred_language($user); + //return without doing anything if we shouldn't send workflow emails + if (variable_get('booking_auto_workflow_email', 0) == 0) + { + watchdog('booking', 'Not sending travelform confirmation email since that feature is currently disabled.'); + return; + } + //load the node matching this id from the database, ignoring the cache $node = node_load($nid, NULL, TRUE); $tokens = booking_define_personspecific_tokens($node); diff --git a/booking.helper.inc b/booking.helper.inc index 9fb5894..301a16f 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -614,7 +614,7 @@ function _booking_total_due($person) $total_due = 0.00; //determine what rate this person needs to pay - if ($person->booking_welfare_required == 'Y') + if ($person->booking_welfare_required == 'Y' || $person->booking_committee_member == 'Y') { //cater for any manual adjustment //watchdog('booking', "This registration is eligible for welfare rates"); @@ -622,10 +622,14 @@ function _booking_total_due($person) } //the early bird rate will be defined by default for the registration elseif (_booking_is_earlybird() == TRUE) + { $total_due = $person->booking_total_pay_reqd; + } //finally we must be in the late-fee period else + { $total_due = $person->booking_late_price; + } return $total_due; } @@ -645,14 +649,17 @@ function _booking_amount_owing($nid, $amount_paid = 0, $include_paypal_fees = TR //$total_due = 0; //fetch details about the person + $person = db_query("SELECT price.booking_price, price.booking_late_price, person.booking_payment_id, " . - "person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id, person.booking_country, person.booking_welfare_required " . + "person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id, person.booking_country, person.booking_welfare_required, person.booking_committee_member " . "FROM {booking_person} person, {booking_price} price " . "WHERE person.nid = :nid " . "AND person.booking_payment_id = price.pid", array(':nid' => $nid)) ->fetchObject(); + //$person = node_load($nid); + //quick sanity check if (! $person) { watchdog('booking', "Unable to find matching person relating to registration id '" . $nid . "' ."); @@ -684,6 +691,7 @@ function _booking_amount_owing($nid, $amount_paid = 0, $include_paypal_fees = TR if ($person->booking_country === "Australia") $amount_owing = $amount_owing / (1 - 0.024); //paypal charges 3.4 percent if they're doing a currency conversion + //assume that everyone not based in Australia will be doing a currency conversion else { $amount_owing = $amount_owing / (1 - 0.034); @@ -725,8 +733,8 @@ function _booking_process_refund($person) watchdog('booking', "Processing refund due to !first !last. Calculated as $!refund", array('!first' => $person->booking_firstname, '!last' => $person->booking_lastname, '!refund' => $refund)); - $refund_due = $person->booking_amount_paid - $refund; - if ($refund_due == 0) + //$refund_due = $person->booking_amount_paid - $refund; + if ($refund == 0) { //mark the refund as processed since no action is required and don't add an entry into the manual payments table db_update('booking_person') @@ -742,7 +750,7 @@ function _booking_process_refund($person) //update booking_amount_paid db_update('booking_person') ->fields(array( - 'booking_refund_due' => $refund_due, + 'booking_refund_due' => $refund, )) ->condition('nid', $person->nid) ->execute(); diff --git a/booking.install b/booking.install index c466e7e..02e6c5b 100644 --- a/booking.install +++ b/booking.install @@ -300,6 +300,15 @@ function booking_update_7213() { db_change_field('booking_person', 'booking_amount_refunded', 'booking_refund_due', $spec); } +/** +* Add flag to indicate committee member +*/ +function booking_update_7214() { + $spec = array('type' => 'varchar', 'length' => '1', 'not null' => FALSE, 'default' => 'N'); + db_add_field('booking_person', 'booking_committee_member', $spec); + +} + /** * Implementation of hook_install(). */ diff --git a/booking.register.inc b/booking.register.inc index 144a553..08cf2be 100644 --- a/booking.register.inc +++ b/booking.register.inc @@ -160,7 +160,45 @@ function booking_form($node, &$form_state, $inserting = FALSE) { '#title' => t('Welfare Required?'), '#description' => t('Select to mark this attendee as requiring special financial consideration'), '#default_value' => (!empty($data->booking_welfare_required) && $data->booking_welfare_required == 'Y') ? 1 : 0 - ); + ); + + $form['your-details']['booking_committee_member'] = array( + '#type' => 'checkbox', + '#title' => t('Committee Member?'), + '#description' => t('Select to identify this attendee as being on the committee'), + '#default_value' => (!empty($data->booking_committee_member) && $data->booking_committee_member == 'Y') ? 1 : 0 + ); + + $form['your-details']['booking_amount_paid'] = array( + '#type' => 'textfield', + '#title' => t('Amount Paid'), + '#maxlength' => 10, + '#required' => FALSE, + '#default_value' => !empty($data->booking_amount_paid) ? $data->booking_amount_paid : '' + ); + + $form['your-details']['booking_total_pay_reqd'] = array( + '#type' => 'textfield', + '#title' => t('Total Amount Due'), + '#maxlength' => 10, + '#required' => FALSE, + '#default_value' => !empty($data->booking_total_pay_reqd) ? $data->booking_total_pay_reqd : '0.00' + ); + //refund info + $form['your-details']['booking_refund_processed'] = array( + '#type' => 'checkbox', + '#title' => t('Refund Processed?'), + '#description' => t('Select to mark the processing of any applicable refund as complete'), + '#default_value' => (!empty($data->booking_refund_processed) && $data->booking_refund_processed == 'Y') ? 1 : 0 + ); + $form['your-details']['booking_refund_due'] = array( + '#type' => 'textfield', + '#title' => t('Refund Amount Due'), + '#maxlength' => 10, + '#required' => FALSE, + '#default_value' => !empty($data->booking_refund_due) ? $data->booking_refund_due : '0.00' + ); + } //end inserting check for booking status //tshirts @@ -298,35 +336,6 @@ function booking_form($node, &$form_state, $inserting = FALSE) { '#value' => 1, ); - $form['your-details']['booking_amount_paid'] = array( - '#type' => 'textfield', - '#title' => t('Amount Paid'), - '#maxlength' => 10, - '#required' => FALSE, - '#default_value' => !empty($data->booking_amount_paid) ? $data->booking_amount_paid : '' - ); - - $form['your-details']['booking_total_pay_reqd'] = array( - '#type' => 'textfield', - '#title' => t('Total Amount Due'), - '#maxlength' => 10, - '#required' => FALSE, - '#default_value' => !empty($data->booking_total_pay_reqd) ? $data->booking_total_pay_reqd : '0.00' - ); - //refund info - $form['your-details']['booking_refund_processed'] = array( - '#type' => 'checkbox', - '#title' => t('Refund Processed?'), - '#description' => t('Select to mark the processing of any applicable refund as complete'), - '#default_value' => (!empty($data->booking_refund_processed) && $data->booking_refund_processed == 'Y') ? 1 : 0 - ); - $form['your-details']['booking_refund_due'] = array( - '#type' => 'textfield', - '#title' => t('Refund Amount Due'), - '#maxlength' => 10, - '#required' => FALSE, - '#default_value' => !empty($data->booking_refund_due) ? $data->booking_refund_due : '0.00' - ); $form['your-details']['booking_barcode'] = array( '#type' => 'textfield', @@ -956,7 +965,8 @@ function booking_form_submit($form, &$form_state) { //fields that may or may not have been present in the initial form $node->booking_welfare_required = empty($values['booking_welfare_required']) ? 'N' : ($values['booking_welfare_required'] == 1 ? 'Y' : 'N'); - $node->booking_refund_processed = empty($values['booking_refund_processed']) ? 'N' : ($values['booking_refund_processed'] == 1 ? 'Y' : 'N'); + $node->booking_committee_member = empty($values['booking_committee_member']) ? 'N' : ($values['booking_committee_member'] == 1 ? 'Y' : 'N'); + $node->booking_welfare_required = empty($values['booking_welfare_required']) ? 'N' : ($values['booking_welfare_required'] == 1 ? 'Y' : 'N'); $node->booking_refund_due = empty($values['booking_refund_due']) ? '' : $values['booking_refund_due']; $node->booking_help_music = empty($values['booking_help_music']) ? '' : $values['booking_help_music']; $node->booking_help_meditations = empty($values['booking_help_meditations']) ? '' : $values['booking_help_meditations']; @@ -1058,14 +1068,16 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE) if (variable_get('booking_enable_studygroups', 0) == 1) { //work out how many study groups there are - $studygroups = db_query("SELECT count(*) as numgroups from {booking_studygroup_list} s INNER JOIN {booking_event} e ON s.booking_eventid = e.eid WHERE e.booking_event_active = 1") - ->fetchObject(); + //$studygroups = db_query("SELECT count(*) as numgroups from {booking_studygroup_list} s INNER JOIN {booking_event} e ON s.booking_eventid = e.eid WHERE e.booking_event_active = 1") + // ->fetchObject(); //$studygroups = db_query("SELECT s.* from {booking_studygroup_list} s INNER JOIN {booking_event} e ON s.booking_eventid = e.eid WHERE e.booking_event_active = 1") // ->fetchAllAssoc('sid'); //watchdog('booking', "
Loading node studygroups query output:\n@info", array('@info' => print_r( $studygroups, true))); + + $studygroup_count = variable_get('booking_studygroup_count','0'); //for ($i = 1; $i <= STUDYGROUP_COUNT; $i++) - for ($i = 1; $i <= $studygroups->numgroups; $i++) + for ($i = 1; $i <= $studygroup_count; $i++) { $query->leftJoin('booking_studygroup_mapping', 's' . $i, 'p.nid = s' . $i . '.booking_node_id and s' . $i . '.booking_studygroup_id = ' . $i); @@ -1087,7 +1099,7 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE) ->fields('pr', array('booking_price', 'booking_price_descrip','booking_late_price')); //now add the study group fields - for ($i = 1; $i <= $studygroups->numgroups; $i++) + for ($i = 1; $i <= $studygroup_count; $i++) { //$label = "Group_" . $studygroups[$i]->booking_studygroup_descrip; $query->addField('s' . $i, 'booking_session_id', 'session' . $i); @@ -1145,13 +1157,15 @@ function booking_load($nodes) { } } - watchdog('booking', 'Final loaded node: @info', array('@info' => var_export($nodes, TRUE))); + //watchdog('booking', 'Final loaded node: @info', array('@info' => var_export($nodes, TRUE))); // no return necessary since $nodes array members reference objects global to this function } function _booking_insert($node) { //watchdog('booking', 'Inserting node: @info', array('@info' => var_export($node, TRUE))); + //TODO: Generalise this by using the keys from $node instead of hard coding everything + db_insert('booking_person') ->fields(array( 'nid' => $node->nid, @@ -1218,6 +1232,7 @@ function _booking_insert($node) { 'booking_welfare_required' => $node->booking_welfare_required, 'booking_refund_due' => $node->booking_refund_due, 'booking_refund_processed' => $node->booking_refund_processed, + 'booking_committee_member' => $node->booking_committee_member, )) ->execute(); } @@ -1300,6 +1315,7 @@ function _booking_update($node) { 'booking_skills_other_details' => $node->booking_skills_other_details, 'booking_welfare_required' => ($node->booking_welfare_required == 1 ? 'Y' : 'N'), 'booking_refund_processed' => ($node->booking_refund_processed == 1 ? 'Y' : 'N'), + 'booking_committee_member' => ($node->booking_committee_member == 1 ? 'Y' : 'N'), 'booking_status' => $node->booking_status, )) @@ -1533,7 +1549,7 @@ function booking_view($node, $view_mode) { $rows[] = array(t('Passport Exact Issued Name:'), $node->booking_passport_issue_name); $rows[] = array(t('Passport Issue Location:'), $node->booking_passport_issue_location); } - + $rows[] = array(t('Committee Member:'), t('!ans', array('!ans' => ($node->booking_committee_member == 'Y' ? 'Yes' : 'No')))); $rows[] = array(t('Payment Type Selected:'), t('!amount_paid', array('!amount_paid' => $payment_type))); $rows[] = array(t('Amount Paid:'), t('!amount_paid', array('!amount_paid' => $node->booking_amount_paid))); $rows[] = array(t('Total Amount Due:'), t('!amount_paid', array('!amount_paid' => $node->booking_total_pay_reqd))); @@ -1651,7 +1667,7 @@ function booking_view($node, $view_mode) { array(':eid' => $event->eid)); $studygroups = $studygroups_query->fetchAllAssoc('sid'); - watchdog('booking', "
Displaying node studygroups query output:\n@info", array('@info' => print_r( $studygroups, true))); + //watchdog('booking', "
Displaying node studygroups query output:\n@info", array('@info' => print_r( $studygroups, true))); for ($i = 1; $i <= STUDYGROUP_COUNT; $i++) { diff --git a/booking.reports.inc b/booking.reports.inc index 318d686..0684e36 100644 --- a/booking.reports.inc +++ b/booking.reports.inc @@ -18,6 +18,7 @@ function booking_report_summary() { $baptised_count = 0; $married_count = 0; $total_paid = 0; + $total_refunds = 0; $dob_total = 0; $male_dob_total = 0; $female_dob_total = 0; @@ -25,6 +26,7 @@ function booking_report_summary() { $welfare_count = 0; $fullypaid_count = 0; $travelform_count = 0; + $committee_count = 0; $stats_attributes = array('style' => 'max-width:30%'); @@ -35,12 +37,16 @@ function booking_report_summary() { $header = array( array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'), array('data' => t('Name'), 'field' => 'booking_lastname'), + array('data' => t('Booking Status'), 'field' => 'booking_status'), array('data' => t('Edit Studygroups')), array('data' => t('Email'), 'field' => 'booking_email'), array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'), array('data' => t('Total Payment Required')), array('data' => t('Fully paid?')), + array('data' => t('Refund Processed?'), 'field' => 'booking_refund_processed'), + array('data' => t('Refund Due'), 'field' => 'booking_refund_due'), array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required'), + array('data' => t('Committee?'), 'field' => 'booking_committee_member'), ); $rows = array(); @@ -105,16 +111,27 @@ function booking_report_summary() { l(t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))), t('node/!id/edit', array('!id' => $person->nid)) ), - l(t('Edit'), t('admin/booking/!id/edit-studygroup', array('!id' => $person->nid))), + _booking_status_generate($person->booking_status), + l(t('Edit Groups'), t('admin/booking/!id/edit-studygroup', array('!id' => $person->nid))), t('!email', array('!email' => $person->booking_email)), t('!payment', array('!payment' => $person->booking_amount_paid)), t('!payment', array('!payment' => $amount_owing == 0 ? $person->booking_total_pay_reqd : _booking_total_due($person))), t('!fullypaid', array('!fullypaid' => $amount_owing == 0 ? 'Yes' : 'No')), - t($person->booking_welfare_required == 'Y' ? 'Yes' : 'No'), + t('!reqd', array('!reqd' => $person->booking_refund_processed == 'Y' ? 'Yes' : 'No')), + t('!payment', array('!payment' => $person->booking_refund_due)), + t($person->booking_welfare_required == 'Y' ? 'Yes' : 'No'), + t($person->booking_committee_member == 'Y' ? 'Yes' : 'No'), ); //add up the total paid $total_paid += $person->booking_amount_paid; + //subtract any refund + if ($person->booking_refund_processed == 'Y' && $person->booking_refund_due > 0) + { + $total_refunds += $person->booking_refund_due; + } + + //travel form completed? if (! empty($person->tid)) $travelform_count++; @@ -132,6 +149,10 @@ function booking_report_summary() { //welfare if ($person->booking_welfare_required == 'Y') $welfare_count++; + + //committee? + if ($person->booking_committee_member == 'Y') + $committee_count++; //fully paid? if ($amount_owing == 0) @@ -168,13 +189,15 @@ function booking_report_summary() { array('!average' => _booking_avg_age($dob_total, $person_count, $event->booking_event_start), '!maleaverage' => _booking_avg_age($male_dob_total, $male_count, $event->booking_event_start), '!femaleaverage' => _booking_avg_age($female_dob_total, $female_count, $event->booking_event_start) )); - $output .= t("There are !bookedin registrations currently booked in, !waiting on waiting list, !notpaid haven't paid, and !notcoming are no longer coming, which comes to a total of !total people who have filled in the registration form.", + $output .= t("There are !bookedin registrations currently booked in, !waiting on waiting list, !notpaid haven't paid, " . + "and !notcoming are no longer coming, which comes to a total of !total people who have filled in the registration form.", array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter, '!total' => $person_count, '!notcoming' => $notcoming_counter)); - $output .= t("
There are !welfare people with special financial consideration approved. !fullypaid people have completed their payments and !travel people have filled in their travel form.
",
- array('!welfare' => $welfare_count, '!fullypaid' => $fullypaid_count, '!travel' => $travelform_count,
+ $output .= t("
There are !welfare people with special financial consideration approved, and !committee people on the committee. " .
+ "!fullypaid people have completed their payments and !travel people have filled in their travel form.
",
+ array('!welfare' => $welfare_count, '!fullypaid' => $fullypaid_count, '!travel' => $travelform_count, '!committee' => $committee_count,
));
- $output .= t("Total amount paid: $!paid