diff --git a/booking.emails.inc b/booking.emails.inc index d85281f..a3dfc90 100644 --- a/booking.emails.inc +++ b/booking.emails.inc @@ -321,8 +321,8 @@ function _booking_travelform_confirmation_email($nid) global $user; $language = user_preferred_language($user); - //load the node matching this id - $node = node_load($nid); + //load the node matching this id from the database, ignoring the cache + $node = node_load($nid, NULL, TRUE); $tokens = booking_define_personspecific_tokens($node); watchdog('booking', 'Sending travelform confirmation email to !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname)); diff --git a/booking.helper.inc b/booking.helper.inc index 1298ff0..70bbcfe 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -552,27 +552,15 @@ function _booking_amount_paid($nid, $person = NULL) } /** - * Function to calculate the amount outstanding for a person/married couple + * Function to calculate the total amount a person is required to pay * - * @param $nid - the node id relating to the registration node - * @param $amount_paid - if we have previously calculated the amount paid, this can be passed as a value - * @param $include_paypal_fees - boolean to indicate whether we want the net amount or the amount owing including paypal fees + * @param $person - the populated node object representing this person including related price information * @return amount owing as a decimal value */ -function _booking_amount_owing($nid, $amount_paid = 0, $include_paypal_fees = TRUE) +function _booking_total_due($person) { - //$amount_paid = 0; - $total_due = 0; + $total_due = 0.00; - //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 " . - "FROM {booking_person} person, {booking_price} price " . - "WHERE person.nid = :nid " . - "AND person.booking_payment_id = price.pid", - array(':nid' => $nid)) - ->fetchObject(); - //determine what rate this person needs to pay if ($person->booking_welfare_required == 'Y') { @@ -587,11 +575,45 @@ function _booking_amount_owing($nid, $amount_paid = 0, $include_paypal_fees = TR else $total_due = $person->booking_late_price; + return $total_due; +} + + +/** + * Function to calculate the amount outstanding for a person/married couple + * + * @param $nid - the node id relating to the registration node + * @param $amount_paid - if we have previously calculated the amount paid, this can be passed as a value + * @param $include_paypal_fees - boolean to indicate whether we want the net amount or the amount owing including paypal fees + * @return amount owing as a decimal value + */ +function _booking_amount_owing($nid, $amount_paid = 0, $include_paypal_fees = TRUE) +{ + //$amount_paid = 0; + //$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 " . + "FROM {booking_person} person, {booking_price} price " . + "WHERE person.nid = :nid " . + "AND person.booking_payment_id = price.pid", + array(':nid' => $nid)) + ->fetchObject(); + + //quick sanity check + if (! $person) { + watchdog('booking', "Unable to find matching person relating to registration id '" . $nid . "' ."); + return 0.00; + } + + $total_due = _booking_total_due($person); + //if we didn't get the amount paid as a command line parameter, check it now if ($amount_paid == 0) { $amount_paid = _booking_amount_paid($nid, $person); - } + } //check if there is anything outstanding //use the original total amount required rather than the late-rate, to cater for people that paid before the late rate diff --git a/booking.register.inc b/booking.register.inc index 5351075..be5c176 100644 --- a/booking.register.inc +++ b/booking.register.inc @@ -869,7 +869,7 @@ function _booking_validate($node, &$form_state) { //verify that a state has been entered if "Other" was selected if (($form_state['booking_state'] == 'Other' ) && ($form_state['booking_other_state'] == '')) - form_set_error('booking_other_state', t('You must enter your State in the address section of the Contact details.')); + form_set_error('booking_other_state', t('You must enter your State in the address section of the Contact details. Please put N/A if your country does not have states.')); } function booking_form_submit($form, &$form_state) { @@ -1092,7 +1092,7 @@ 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 } diff --git a/booking.reports.inc b/booking.reports.inc index 19a64a2..2eca91f 100644 --- a/booking.reports.inc +++ b/booking.reports.inc @@ -36,7 +36,7 @@ function booking_report_summary() { array('data' => t('Name'), 'field' => 'booking_lastname'), array('data' => t('Email'), 'field' => 'booking_email'), array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'), - array('data' => t('Total Payment Required'), 'field' => 'booking_total_pay_reqd'), + array('data' => t('Total Payment Required')), array('data' => t('Fully paid?')), array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required'), ); @@ -93,7 +93,7 @@ function booking_report_summary() { foreach ($result as $person) { - $amount_owing = _booking_amount_owing($person->nid); + $amount_owing = _booking_amount_owing($person->nid, 0, FALSE); $rows[] = array( l(t('!id', array('!id' => $person->nid)), t('node/!id', array('!id' => $person->nid))), @@ -103,7 +103,7 @@ function booking_report_summary() { ), t('!email', array('!email' => $person->booking_email)), t('!payment', array('!payment' => $person->booking_amount_paid)), - t('!payment', array('!payment' => $person->booking_total_pay_reqd)), + 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'), ); @@ -509,7 +509,10 @@ function booking_csv_report() { if ($key == 'nid') { $output[] = $value; - $output[] = _booking_amount_owing($value); + //this is really hacky since it does another massive database query for each person + //$person = node_load($value); + $output[] = _booking_amount_owing($value, 0, FALSE); + //$output[] = _booking_amount_owing($value); continue; } diff --git a/booking.tokens.inc b/booking.tokens.inc index 6267b70..1274a22 100644 --- a/booking.tokens.inc +++ b/booking.tokens.inc @@ -531,7 +531,11 @@ function booking_token_info() { $info['tokens']['booking']['travel-summary'] = array( 'name' => t('Registration Travel Summary'), 'description' => t('Summary of travel details from user registration.') - ); + ); + $info['tokens']['booking']['travel-link'] = array( + 'name' => t('Travel form Link'), + 'description' => t('Link to the person\'s travel form.') + ); return $info; } @@ -640,6 +644,7 @@ function booking_define_personspecific_tokens($node) $tokens['payment-transaction-desc'] = $node->nid . ' ' . $node->booking_lastname; $tokens['balance-payment-link'] = url('balance/' . $tempid, array('absolute' => TRUE)); $tokens['confirm-payment-link'] = url('confirm/' . $tempid, array('absolute' => TRUE)); + $tokens['travel-link'] = url('travel/' . $tempid, array('absolute' => TRUE)); $tokens['paypal-total-amount'] = _booking_amount_owing($node->nid, $amount_paid); $tokens['paypal-deposit-amount'] = _booking_deposit_amount(); $tokens['regn-summary'] = _booking_details_email_summary($node);