Tweaks to refunds, study groups, travel emails

This commit is contained in:
2014-05-06 14:51:06 +10:00
parent eb3fa7e7bf
commit 5e8e1bd22d
7 changed files with 204 additions and 61 deletions

View File

@@ -354,6 +354,57 @@ function _date_range_to_string($date_start, $date_end) {
return $final_string;
}
/**
* Function for cleaning up study groups for people that have withdrawn their registration
* @param $nid - the node id for the person who has withdrawn their registration
* @return nothing
*/
function _booking_studygroups_cleanup($nid)
{
global $event;
//first of all make sure we need to do anything
if (variable_get('booking_enable_studygroups', 0) == 1)
{
/*
//look up the titles of the study groups
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid",
array(':eid' => $event->eid));
$studygroups = $studygroups_query->fetchAllAssoc('sid');
*/
//query for any groups this person is assigned to
$to_remove_query = db_query("SELECT m.* FROM {booking_studygroup_mapping} m WHERE booking_node_id = :nid",
array(':nid' => $nid));
$to_remove = $to_remove_query->fetchAll();
foreach ($to_remove as $group)
{
$role = "None";
if ($group->booking_is_leader == 'Y')
$role = "Lead group #" . $group->booking_studygroup_id;
elseif ($group->booking_is_helper == 'Y')
$role = "Help group #" . $group->booking_studygroup_id;
elseif ($group->booking_is_reserveleader == 'Y')
$role = "Reserve group #" . $group->booking_studygroup_id;
$message = t("Removing id !nid from group id !group with role !role.", array('!nid' => $nid, '!group' => $group->booking_studygroup_id, '!role' => $role));
watchdog('booking', $message);
drupal_set_message($message, 'status', FALSE);
db_delete('booking_studygroup_mapping')
->condition('booking_eventid', $event->eid)
->condition('booking_node_id', $nid)
->condition('booking_studygroup_id', $group->booking_studygroup_id)
->execute();
}
}
}
/**
* Function for calculating statistics of attendees
*/
@@ -653,6 +704,7 @@ function _booking_amount_owing($nid, $amount_paid = 0, $include_paypal_fees = TR
function _booking_process_refund($person)
{
global $event;
//$refund_due = 0;
//calculate amount to be refunded
$paid = _booking_amount_paid($person->nid, $person);
@@ -673,13 +725,28 @@ 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));
//update booking_amount_paid
db_update('booking_person')
->fields(array(
'booking_amount_paid' => $person->booking_amount_paid - $refund,
))
->condition('nid', $person->nid)
->execute();
$refund_due = $person->booking_amount_paid - $refund;
if ($refund_due == 0)
{
//mark the refund as processed since no action is required
db_update('booking_person')
->fields(array(
'booking_refund_due' => 0,
'booking_refund_processed' => 'Y',
))
->condition('nid', $person->nid)
->execute();
}
else
{
//update booking_amount_paid
db_update('booking_person')
->fields(array(
'booking_refund_due' => $refund_due,
))
->condition('nid', $person->nid)
->execute();
}
//add manual payment entry for refund
$result = db_insert('booking_payment')