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

@@ -209,6 +209,14 @@ function booking_admin() {
'#size' => 150,
'#maxlength' => 2000,
);
$form['misc']['booking_import_include_fields'] = array (
'#type' => 'textfield',
'#title' => t('Fields to import from an uploaded CSV file'),
'#default_value' => variable_get('booking_import_include_fields', ''),
'#description' => 'Separate each field with a semi-colon. Field names as per database schema, case sensitive. Nid and booking_status fields compulsory.',
'#size' => 150,
'#maxlength' => 2000,
);
return system_settings_form($form);
}
@@ -302,6 +310,7 @@ function booking_manual_email()
foreach($result as $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))),
'booking_name' => $data->booking_firstname . " " . $data->booking_lastname,
@@ -310,15 +319,17 @@ function booking_manual_email()
'booking_status' => _booking_status_generate($data->booking_status),
'amount_paid' => $data->booking_amount_paid,
'amount_reqd' => $data->booking_total_pay_reqd,
'booking_fully_paid' => _booking_amount_owing($data->nid) == 0 ? 'Yes' : 'No',
'booking_fully_paid' => $paid == 0 ? 'Yes' : 'No',
'welfare_required' => $data->booking_welfare_required == 'Y' ? 'Yes' : 'No',
);
//$values[$data->nid] = ($paid == 0 || $data->booking_status != 1) ? FALSE : TRUE;
}
$form['table'] = array (
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
//'#default_value' => $values,
'#empty' => t('No attendees found.'),
'#attributes' => array('id' => 'sort-table'),
);

View File

@@ -329,7 +329,7 @@ function _booking_travelform_confirmation_email($nid)
//calculate the from email address
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
'!email' => variable_get('booking_contact_email', variable_get('site_mail', ini_get('sendmail_from')))
'!email' => variable_get('booking_logistics_email', variable_get('site_mail', ini_get('sendmail_from')))
));
//calculate the remaining parameters

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')

View File

@@ -11,7 +11,9 @@ function booking_import_data_admin()
{
global $event;
$prefix = "<p>Upload csv file containing data to import. Minimum fields present should be <strong>nid,booking_status,booking_total_pay_reqd,booking_amount_paid</strong> with column names matching that exactly (case sensitive).</p>";
$prefix = t("<p>Upload csv file containing data to import. Minimum fields present should be <strong>nid</strong>, " .
" along with user-specified fields of <strong>!config</strong>. CSV Column names should match exactly (case sensitive).</p>",
array('!config' => variable_get('booking_import_include_fields', '')));
$form = array();
@@ -59,12 +61,16 @@ function booking_import_data_admin_submit($form, &$form_state)
{
global $event;
$array = array();
$expected_fields = array('nid', 'booking_amount_paid', 'booking_total_pay_reqd', 'booking_status');
//$expected_fields = array('nid', 'booking_amount_paid', 'booking_total_pay_reqd', 'booking_status');
$error = false;
$update_counter = 0;
$delimiter = ",";
$result_array = array();
$builtin_fields_to_import = array('nid', 'booking_status');
$custom_fields_to_import = explode(";", variable_get('booking_import_include_fields', ''));
$fields_to_import = array_merge($builtin_fields_to_import, $custom_fields_to_import);
//get the file name from temporary storage field
$file = $form_state['storage']['file'];
// We are done with the file, remove it from storage.
@@ -82,7 +88,7 @@ function booking_import_data_admin_submit($form, &$form_state)
$headerRecord = $rowData;
} else {
foreach( $rowData as $key => $value) {
$array[ $rowCounter - 1][ $headerRecord[ $key] ] = $value;
$array[$rowCounter - 1][ $headerRecord[$key] ] = $value;
}
}
$rowCounter++;
@@ -95,14 +101,18 @@ function booking_import_data_admin_submit($form, &$form_state)
return;
}
//watchdog('booking', "<pre>Import data:\n@info</pre>", array('@info' => print_r( $array, true)));
//process the input data
foreach ($array as $record)
{
//watchdog('booking', 'Processing user record: @info', array ('@info' => $record['nid']));
//watchdog('booking', "<pre>Processing row data:\n@info</pre>", array('@info' => print_r( $record, true)));
$update_counter++;
$update_text = "";
$update_array = array();
//do some error checking
foreach($expected_fields as $field)
foreach($fields_to_import as $field)
{
/*
if (! isset($record[$field]))
@@ -110,17 +120,44 @@ function booking_import_data_admin_submit($form, &$form_state)
if ($record[$field] == '')
watchdog('booking', 'Blank field !field: !info', array ('!field' => $field, '!info' => var_export($record, TRUE)));
*/
if ( (! isset($record[$field])) || $record[$field] == '' )
//make sure to skip the nid field since we can't update that
if ($field == 'nid')
{
drupal_set_message("Error: Unable to locate expected field '$field' in input file for record number $update_counter.", 'error', FALSE);
//do nothing
}
//convert the booking status to the number used internally
elseif ($field == 'booking_status')
{
$update_array[$field] = _booking_status_lookup($record[$field]);
}
elseif ( (! isset($record[$field])) || $record[$field] == '' )
{
//drupal_set_message("Error: Unable to locate expected field '$field' in input file for record number $update_counter.", 'error', FALSE);
//watchdog('booking', 'Processing user record: @info', array ('@info' => $record['nid']));
//$error = true;
//skip to the next record
continue 2;
//continue 2;
}
else
{
$update_text .= " set '" . $field . "' to '" . $record[$field] . "'; ";
$update_array[$field] = $record[$field];
}
}
drupal_set_message(t("Updating record !nid as follows: !update", array('!nid' => $record['nid'], '!update' => $update_text)));
$query = db_update('booking_person')
->fields($update_array)
->condition('nid', $record['nid']);
$rows = $query->execute();
//$args = $query->getArguments();
watchdog('booking', "Update Query:<br />@info<br />Rows affected<br />@rows", array('@info' => (string) $query, '@rows' => $rows));
/*
$result_array[] = t('Setting payment for id !nid to $!price of total required $!total and status to !status',
array('!nid' => $record['nid'],
'!price' => $record['booking_amount_paid'],
@@ -128,6 +165,8 @@ function booking_import_data_admin_submit($form, &$form_state)
'!status' => _booking_status_lookup($record['booking_status'])
)
);
*/
/*
//TODO: output this from $result_array
drupal_set_message(t('Setting payment for id !nid to $!price of total required $!total and status to !status',
array('!nid' => $record['nid'],
@@ -135,10 +174,12 @@ function booking_import_data_admin_submit($form, &$form_state)
'!total' => $record['booking_total_pay_reqd'],
'!status' => _booking_status_lookup($record['booking_status']))
));
*/
// watchdog('booking', 'Setting payment for regn id !nid to $!price and status to !status',
// array('!nid' => $record['nid'], '!price' => $record['booking_amount_paid'], '!status' => _booking_status_lookup($record['booking_status'])));
/*
db_update('booking_person')
->fields(array(
'booking_amount_paid' => $record['booking_amount_paid'],
@@ -147,11 +188,12 @@ function booking_import_data_admin_submit($form, &$form_state)
))
->condition('nid', $record['nid'])
->execute();
*/
} //end processing input data
//output our results to watchdog
watchdog('booking', '<pre>@print_r</pre>', array('@print_r', print_r( $result_array, TRUE)));
//watchdog('booking', '<pre>@print_r</pre>', array('@print_r', print_r( $result_array, TRUE)));
//delete the uploaded file
file_delete($file);

View File

@@ -281,6 +281,25 @@ function booking_update_7211() {
db_add_field( 'booking_person', 'booking_bf_gf_nid', $spec);
}
/**
* Add refund fields to booking registration table
*/
function booking_update_7212() {
$spec = array('type' => 'numeric', 'not null' => FALSE, 'default' => 0, 'precision' => '7', 'scale' => '2');
db_add_field( 'booking_person', 'booking_amount_refunded', $spec);
$spec2 = array('type' => 'varchar', 'length' => '1', 'not null' => FALSE, 'default' => 'N');
db_add_field( 'booking_person', 'booking_refund_processed', $spec2);
}
/**
* Rename refund field
*/
function booking_update_7213() {
$spec = array('type' => 'numeric', 'not null' => FALSE, 'default' => 0, 'precision' => '7', 'scale' => '2');
db_change_field('booking_person', 'booking_amount_refunded', 'booking_refund_due', $spec);
}
/**
* Implementation of hook_install().
*/
@@ -317,39 +336,6 @@ $result = db_insert('booking_price')
))
->execute();
$result = db_insert('booking_price')
->fields(array(
'booking_eventid' => 1,
'booking_price' => '300.00',
'booking_price_descrip' => 'Worker',
'booking_buttonid' => 'R7PR6FASQMHSS',
'booking_price_active' => 1,
'booking_depositonly' => 0,
))
->execute();
$result = db_insert('booking_price')
->fields(array(
'booking_eventid' => 1,
'booking_price' => '260.00',
'booking_price_descrip' => 'Non-Worker',
'booking_buttonid' => 'R2CF3G96WX4XA',
'booking_price_active' => 1,
'booking_depositonly' => 0,
))
->execute();
$result = db_insert('booking_price')
->fields(array(
'booking_eventid' => 1,
'booking_price' => '540.00',
'booking_price_descrip' => 'Married Couple',
'booking_buttonid' => 'QST6YCMZFYEN4',
'booking_price_active' => 1,
'booking_depositonly' => 0,
))
->execute();
$result = db_insert('booking_event')
->fields(array(
'booking_eventname' => 'Study Weekend 2012',

View File

@@ -160,8 +160,7 @@ 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
);
);
} //end inserting check for booking status
//tshirts
@@ -314,7 +313,21 @@ function booking_form($node, &$form_state, $inserting = FALSE) {
'#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',
'#title' => t('Barcode'),
@@ -943,6 +956,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_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'];
$node->booking_help_praying = empty($values['booking_help_praying']) ? '' : $values['booking_help_praying'];
@@ -1201,6 +1216,8 @@ function _booking_insert($node) {
'booking_skills_other_details' => $node->booking_skills_other_details,
'booking_status' => $node->booking_status,
'booking_welfare_required' => $node->booking_welfare_required,
'booking_refund_due' => $node->booking_refund_due,
'booking_refund_processed' => $node->booking_refund_processed,
))
->execute();
}
@@ -1259,7 +1276,8 @@ function _booking_update($node) {
'booking_tempid' => $node->booking_tempid,
'booking_payment_id' => $node->booking_payment_id,
'booking_total_pay_reqd' => $node->booking_total_pay_reqd,
'booking_amount_paid' => $node->booking_amount_paid,
'booking_amount_paid' => $node->booking_amount_paid,
'booking_refund_due' => $node->booking_refund_due,
'booking_guardian_name' => $node->booking_guardian_name,
'booking_guardian_type' => $node->booking_guardian_type,
'booking_guardian_phone' => $node->booking_guardian_phone,
@@ -1280,14 +1298,15 @@ function _booking_update($node) {
'booking_skills_language_details' => $node->booking_skills_language_details,
'booking_skills_other' => ($node->booking_skills_other == 1 ? 'Y' : 'N'),
'booking_skills_other_details' => $node->booking_skills_other_details,
'booking_welfare_required' => ($node->booking_welfare_required == 1 ? 'Y' : 'N'),
'booking_welfare_required' => ($node->booking_welfare_required == 1 ? 'Y' : 'N'),
'booking_refund_processed' => ($node->booking_refund_processed == 1 ? 'Y' : 'N'),
'booking_status' => $node->booking_status,
))
->condition('nid', $node->nid)
->execute();
//now process some post-update triggers
//***now process some post-update triggers***
//if booking_partner_id is set, make sure the nid it refers to has this node as its booking_partner_id
if ($node->booking_partner_id != 0)
@@ -1321,6 +1340,9 @@ function _booking_update($node) {
$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)));
//Remove from any study groups
_booking_studygroups_cleanup($node->nid);
//check if there is room on the booked-in list
if (_booking_check_bookings_full() == False)
@@ -1352,6 +1374,9 @@ function _booking_update($node) {
$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)));
//Remove from any study groups
_booking_studygroups_cleanup($node->nid);
}
//if we're not automatically sending emails on registration
//and someone moved from not-paid to booked-in (ie, manual payment process)
@@ -1512,6 +1537,9 @@ function booking_view($node, $view_mode) {
$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)));
$rows[] = array(t('Refund Due:'), t('!amount_due', array('!amount_due' => $node->booking_refund_due)));
$rows[] = array(t('Refund Processed:'), t('!ans', array('!ans' => ($node->booking_refund_processed == 'Y' ? 'Yes' : 'No'))));
$rows[] = array(t('Reading Group:'), t('!group', array('!group' => $node->booking_readinggroup)));
if (variable_get('booking_enable_tshirts', 0) == 1)

View File

@@ -682,6 +682,13 @@ function booking_studygroups_calculate() {
$group_mapping = $group_mapping_query->fetchAllAssoc('sid');
//TODO: search for entries already in the mapping table that have a booking_status of 3 (not coming) and remove them from the mapping table
$to_remove_query = db_query("SELECT m.* FROM {booking_studygroup_mapping} m
inner join {booking_person} p on p.nid = m.booking_node_id
WHERE booking_eventid = :eid AND p.booking_status = 3",
array(':eid' => $event->eid));
$to_remove = $to_remove_query->fetchAll();
watchdog('booking', "<pre>Study group mappings to remove:\n@info</pre>", array('@info' => print_r( $to_remove, true)));
//iterate over the attendee associative array and add some fields
foreach ($attendees as $person)
@@ -889,9 +896,9 @@ function booking_studygroups_calculate() {
foreach($working_list as $person)
{
watchdog('booking', "<pre>Working list person:\n@info</pre>", array('@info' => print_r( $person, true)));
//watchdog('booking', "<pre>Working list person:\n@info</pre>", array('@info' => print_r( $person, true)));
//TODO: a check to update existing records rather than inserting new one
//check to update existing records rather than inserting new one
// if already in $group_mapping then just run an update query here
$found = FALSE;
@@ -941,7 +948,7 @@ function booking_studygroups_calculate() {
}
$insert_query->execute();
watchdog('booking', "<pre>Session statistics list:\n@info</pre>", array('@info' => print_r( $session_count, true)));
//watchdog('booking', "<pre>Session statistics list:\n@info</pre>", array('@info' => print_r( $session_count, true)));
//clear the arrays we've been using for this iteration
unset($session_count);
@@ -1029,6 +1036,7 @@ function booking_studygroups_printview_form($node, &$form_state, $group_id) {
'booking_session_id' => array('data' => t('Study Group Session'), 'field' => 'm.booking_session_id'),
'booking_name' => array('data' => t('Name'), 'field' => 'p.booking_lastname', 'sort' => 'asc'),
'booking_mobilenum' => array('data' => t('Mobile Number'), 'field' => 'p.booking_mobile'),
'booking_email' => array('data' => t('Email'), 'field' => 'p.booking_email'),
'booking_studygroup_role' => array('data' => t('Role')),
);
@@ -1075,6 +1083,7 @@ function booking_studygroups_printview_form($node, &$form_state, $group_id) {
$data->booking_session_id,
$data->booking_firstname . " " . $data->booking_lastname,
$data->booking_mobile,
$data->booking_email,
$role,
),
'class' => array($class),