Refund feature added
This commit is contained in:
@@ -424,7 +424,7 @@ function _booking_datepaid_ts($nid)
|
||||
/**
|
||||
* Helper function to return the amount for a booking deposit, if there is one
|
||||
*/
|
||||
function _booking_deposit_amount()
|
||||
function _booking_deposit_amount($include_fees = TRUE)
|
||||
{
|
||||
global $event;
|
||||
|
||||
@@ -436,7 +436,7 @@ function _booking_deposit_amount()
|
||||
if ($deposit)
|
||||
{
|
||||
//if we're using paypal, add the transaction fee
|
||||
if (variable_get('booking_use_paypal', 0) == 1)
|
||||
if (variable_get('booking_use_paypal', 0) == 1 && $include_fees == TRUE)
|
||||
{
|
||||
//add the 30 cent fixed cost
|
||||
$amount_owing = $deposit->booking_price + 0.3;
|
||||
@@ -523,9 +523,10 @@ function _booking_amount_paid($nid, $person = NULL)
|
||||
$amount_paid = $person->booking_amount_paid;
|
||||
//watchdog('booking', "Total amount paid for individual based on totals in booking_person table is " . $amount_paid);
|
||||
}
|
||||
|
||||
//end combined payments check
|
||||
}
|
||||
}
|
||||
//no spouse found
|
||||
else
|
||||
{
|
||||
//Check if there are payment records in the paypal transaction table for this unmarried person
|
||||
@@ -546,7 +547,7 @@ function _booking_amount_paid($nid, $person = NULL)
|
||||
// $amount_paid = $person->booking_amount_paid;
|
||||
}
|
||||
|
||||
//watchdog('booking', "Total amount already paid for this registration " . $nid . " is " . $amount_paid);
|
||||
watchdog('booking', "Total amount already paid for this registration " . $nid . " is " . $amount_paid);
|
||||
|
||||
return $amount_paid;
|
||||
}
|
||||
@@ -643,6 +644,62 @@ function _booking_amount_owing($nid, $amount_paid = 0, $include_paypal_fees = TR
|
||||
return number_format($amount_owing, 2, '.', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to process the amount to refund a person when they withdraw their registration
|
||||
*
|
||||
* @param $person - the populated node object representing this person including related price information
|
||||
* @return amount to be refunded for this registration
|
||||
*/
|
||||
function _booking_process_refund($person)
|
||||
{
|
||||
global $event;
|
||||
|
||||
//calculate amount to be refunded
|
||||
$paid = _booking_amount_paid($person->nid, $person);
|
||||
if ($paid > 0)
|
||||
{
|
||||
//calculate the refund due
|
||||
//don't include paypal fees in the deposit amount
|
||||
$refund = $paid - _booking_deposit_amount(FALSE);
|
||||
}
|
||||
|
||||
watchdog('booking', "Processing refund due to !first !last. Calculated as $!refund",
|
||||
array('!first' => $person->booking_firstname, '!last' => $person->booking_lastname, '!refund' => $refund));
|
||||
|
||||
//update booking_amount_paid
|
||||
db_update('booking_person')
|
||||
->fields(array(
|
||||
'booking_amount_paid' => $person->booking_amount_paid - $refund,
|
||||
))
|
||||
->condition('nid', $person->nid)
|
||||
->execute();
|
||||
|
||||
//add manual payment entry for refund
|
||||
$result = db_insert('booking_payment')
|
||||
->fields(array(
|
||||
'booking_person_nid' => $person->nid,
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_mc_gross' => $refund * -1,
|
||||
'booking_mc_currency' => 'AUD',
|
||||
'booking_mc_fee' => '0.00',
|
||||
'booking_quantity' => 1,
|
||||
'booking_invoice' => 'Refund',
|
||||
'booking_payer_id' => '',
|
||||
'booking_payment_date' => REQUEST_TIME,
|
||||
'booking_payment_status' => '',
|
||||
'booking_first_name' => $person->booking_firstname,
|
||||
'booking_last_name' => $person->booking_lastname,
|
||||
'booking_buyer_email' => '',
|
||||
'booking_payer_status' => '',
|
||||
'booking_item_name' => 'Refund',
|
||||
'booking_ipn_track_id' => '',
|
||||
))
|
||||
->execute();
|
||||
|
||||
//return the amount to refund this person
|
||||
return $refund;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to cycle through a list without getting in an endless loop
|
||||
* Used for calculating study groups and maybe readings groups
|
||||
|
@@ -1277,9 +1277,12 @@ function _booking_update($node) {
|
||||
watchdog('booking', 'Detected person moving from Booked In list to No Longer Coming');
|
||||
|
||||
//let this person know their request has been processed
|
||||
_booking_demoted_to_notcoming_email($node->nid);
|
||||
_booking_demoted_to_notcoming_email($node->nid);
|
||||
|
||||
//TODO: Calculate refund
|
||||
//Calculate refund
|
||||
$refund = _booking_process_refund($node);
|
||||
drupal_set_message(t('Refund calculated for !first !last is $!refund.',
|
||||
array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname, '!refund' => $refund)));
|
||||
|
||||
//check if there is room on the booked-in list
|
||||
if (_booking_check_bookings_full() == False)
|
||||
|
Reference in New Issue
Block a user