Update _booking_amount_owing to use $person object instead of just a node id

This commit is contained in:
2014-05-14 18:04:29 +10:00
parent 71772edbd5
commit 0bfa363bcd
6 changed files with 38 additions and 30 deletions

View File

@@ -144,30 +144,34 @@ function _booking_process_payment($data) {
->execute();
//Get the person's info
/*
$payment = db_select('booking_person', 'p')
->condition('p.nid', $nid, '=')
->fields('p', array('booking_amount_paid', 'booking_status', 'booking_total_pay_reqd', 'booking_partner_id'))
->execute()
->fetchObject();
*/
$person = node_load($nid);
//check if we found a person matching this payment
if ($payment)
if ($person)
{
watchdog('booking', 'Found matching user with node id: !id; event id: !eid; existing payment !payment', array('!id' => $nid, '!eid' => $eid,
'!payment' => $payment->booking_amount_paid));
'!payment' => $person->booking_amount_paid));
//if successful, update their total payment amount
$total = $payment->booking_amount_paid + $data['mc_gross'];
$total = $person->booking_amount_paid + $data['mc_gross'];
//only recalculate their booking status if this is the initial payment, not a payment of the outstanding balance
if ($balance_payment == FALSE)
{
watchdog('booking', 'Processing an initial payment. Booking status is currently ' . $payment->booking_status);
if ($payment->booking_status == 1)
watchdog('booking', 'Processing an initial payment. Booking status is currently ' . $person->booking_status);
if ($person->booking_status == 1)
{
watchdog('booking', 'This registration has been manually assigned to the booked-in list.');
$status = 1;
}
elseif (_booking_check_bookings_full() == True || $payment->booking_status == 2)
elseif (_booking_check_bookings_full() == True || $person->booking_status == 2)
{
watchdog('booking', 'This registration belongs on the waiting list.');
$status = 2;
@@ -182,8 +186,8 @@ function _booking_process_payment($data) {
{
watchdog('booking', 'Processing a balance payment.');
//if this is a payment of outstanding balance, keep the booking_status the same
$status = $payment->booking_status;
//$status = $payment->booking_status == 2 ? 2 : 1;
$status = $person->booking_status;
//$status = $person->booking_status == 2 ? 2 : 1;
}
//update the database for this person
@@ -196,26 +200,26 @@ function _booking_process_payment($data) {
->execute();
//If there is no outstanding balance, send a payment complete email
$amount_owing = _booking_amount_owing($nid);
//if ($total >= $payment->booking_total_pay_reqd)
$amount_owing = _booking_amount_owing($person);
//if ($total >= $person->booking_total_pay_reqd)
if ($amount_owing == 0)
{
//this should always be a balance payment type email, since that tells the user that their payment is completed
_booking_registration_email($nid, TRUE);
//if we are combining payments, and this person has a linked spouse
if ((variable_get('booking_enable_combined_pricing', 0) == 1) && ($payment->booking_partner_id > 0))
if ((variable_get('booking_enable_combined_pricing', 0) == 1) && ($person->booking_partner_id > 0))
{
//check spouse booking_status and payment info
$spouse = db_select('booking_person', 'p')
->condition('p.nid', $payment->booking_partner_id,'=')
->condition('p.nid', $person->booking_partner_id,'=')
->fields('p', array('booking_amount_paid', 'booking_status', 'booking_total_pay_reqd'))
->execute()
->fetchObject();
//update the spouse's status from "not paid" if required
$spouse_status = $spouse->booking_status == 0 ? 1 : $spouse->booking_status;
watchdog('booking', 'Setting status for spouse id !id to !new from !status', array('!id' => $payment->booking_partner_id,
watchdog('booking', 'Setting status for spouse id !id to !new from !status', array('!id' => $person->booking_partner_id,
'!new' => $spouse_status, '!status' => $spouse->booking_status));
//set the spouse's payment required to be zero or equal to their previous payment total
@@ -229,16 +233,16 @@ function _booking_process_payment($data) {
'booking_total_pay_reqd' => $spouse_new_amount_reqd,
'booking_status' => $spouse_status,
))
->condition('nid', $payment->booking_partner_id)
->condition('nid', $person->booking_partner_id)
->execute();
//send an email to the spouse
_booking_registration_email($payment->booking_partner_id, TRUE);
_booking_registration_email($person->booking_partner_id, TRUE);
}
/*
elseif (variable_get('booking_enable_combined_pricing', 0) == 1)
{
watchdog('booking', 'Combined pricing is enabled, but this person has a partner id of !id.', array('!id' => $payment->booking_partner_id));
watchdog('booking', 'Combined pricing is enabled, but this person has a partner id of !id.', array('!id' => $person->booking_partner_id));
} //end spouse check
*/
}