480 lines
18 KiB
PHP
480 lines
18 KiB
PHP
<?php
|
|
// $Id: booking.confirm.inc,v 0.1 2011/07/12
|
|
|
|
/**
|
|
* List people and how much they have paid
|
|
*/
|
|
function booking_report_summary() {
|
|
global $event;
|
|
//$text = "";
|
|
$output = "";
|
|
$non_australia_count = 0;
|
|
$bookedin_counter = 0;
|
|
$notpaid_counter = 0;
|
|
$waiting_counter = 0;
|
|
$male_count = 0;
|
|
$female_count = 0;
|
|
$baptised_count = 0;
|
|
$married_count = 0;
|
|
$total_paid = 0;
|
|
$dob_total = 0;
|
|
$male_dob_total = 0;
|
|
$female_dob_total = 0;
|
|
$person_count = 0;
|
|
|
|
$stats_attributes = array('style' => 'max-width:30%');
|
|
$header = array('Id', 'Name', 'Email', 'Payment To Date', 'Total Payment Required');
|
|
$rows = array();
|
|
$state_header = array('State', 'Count');
|
|
$state_rows = array();
|
|
$ecclesia_heaeder = array('State','Ecclesia', 'Count');
|
|
$ecclesia_rows = array();
|
|
|
|
//do some analysis about the people booked in
|
|
//first the summary of states
|
|
$query = db_select('booking_person', 'p')
|
|
->fields('p', array('booking_state', 'booking_country'))
|
|
->condition('p.booking_event_id', $event->eid, '=');
|
|
$query->groupBy('p.booking_state');
|
|
$query->addExpression('COUNT(p.booking_state)', 'state_count');
|
|
$query->orderBy('state_count', 'DESC');
|
|
$state_stats = $query->execute();
|
|
|
|
foreach ($state_stats as $state) {
|
|
if (strcmp($state->booking_country,'Australia') == 0 )
|
|
$state_rows[] = array($state->booking_state, $state->state_count);
|
|
else
|
|
$non_australia_count += $state->state_count;
|
|
}
|
|
//non australian states
|
|
$state_rows[] = array('International', $non_australia_count);
|
|
|
|
//general stats
|
|
$query = db_select('booking_person', 'p')
|
|
->fields('p', array('booking_baptised', 'booking_married', 'booking_gender', 'booking_dob'))
|
|
->condition('p.booking_event_id', $event->eid, '=');
|
|
$general_stats = $query->execute();
|
|
|
|
foreach ($general_stats as $person)
|
|
{
|
|
$dob_total += $person->booking_dob;
|
|
$person_count++;
|
|
|
|
if ($person->booking_gender == 'M')
|
|
{
|
|
$male_count++;
|
|
$male_dob_total += $person->booking_dob;
|
|
}
|
|
else
|
|
{
|
|
$female_count++;
|
|
$female_dob_total += $person->booking_dob;
|
|
}
|
|
|
|
if ($person->booking_baptised == 'Y')
|
|
$baptised_count++;
|
|
|
|
if ($person->booking_married == 'Y')
|
|
$married_count++;
|
|
}
|
|
|
|
//bookings by ecclesia
|
|
$query = db_select('booking_person', 'p')
|
|
->fields('p', array('booking_ecclesia','booking_state'))
|
|
->condition('p.booking_event_id', $event->eid, '=');
|
|
$query->groupBy('p.booking_ecclesia');
|
|
$query->addExpression('COUNT(p.booking_ecclesia)', 'ecclesia_count');
|
|
$query->orderBy('booking_state')
|
|
->orderBy('ecclesia_count','DESC');
|
|
$stats = $query->execute();
|
|
|
|
foreach ($stats as $ecclesia) {
|
|
$ecclesia_rows[] = array($ecclesia->booking_state,$ecclesia->booking_ecclesia, $ecclesia->ecclesia_count);
|
|
}
|
|
|
|
//more detailed summary
|
|
$result = db_query("SELECT * FROM {booking_person} p WHERE p.booking_event_id = :eid",
|
|
array(':eid' => $event->eid));
|
|
foreach ($result as $person) {
|
|
$rows[] = array(
|
|
l(t('!id', array('!id' => $person->nid)), t('node/!id', array('!id' => $person->nid))),
|
|
t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))),
|
|
t('!email', array('!email' => $person->booking_email)),
|
|
t('!payment', array('!payment' => $person->booking_amount_paid)),
|
|
t('!payment', array('!payment' => $person->booking_total_pay_reqd)),
|
|
);
|
|
$total_paid += $person->booking_amount_paid;
|
|
|
|
if ($person->booking_status == 0)
|
|
$notpaid_counter++;
|
|
elseif ($person->booking_status == 1)
|
|
$bookedin_counter++;
|
|
elseif ($person->booking_status == 2)
|
|
$waiting_counter++;
|
|
}
|
|
|
|
//output everything
|
|
$output .= t("<h3>General Statistics</h3>");
|
|
$output .= t("<p>There are !boys males and !girls females registered. Of these, !baptised are baptised and !married are married.<br />",
|
|
array('!boys' => $male_count, '!girls' => $female_count, '!baptised' => $baptised_count, '!married' => $married_count
|
|
));
|
|
$output .= t("The overall average age at the start of the week will be !average. The male average age will be !maleaverage. The female average age will be !femaleaverage.<br />",
|
|
array('!average' => _booking_avg_age($dob_total, $person_count, $event->booking_event_start), '!maleaverage' => _booking_avg_age($male_dob_total, $male_count, $event->booking_event_start),
|
|
'!femaleaverage' => _booking_avg_age($female_dob_total, $female_count, $event->booking_event_start)
|
|
));
|
|
$output .= t("There are !bookedin registrations currently booked in, !waiting on waiting list, and !notpaid haven't paid, which comes to a total of !total people who have filled in the registration form.<br />",
|
|
array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter, '!total' => $person_count));
|
|
$output .= t("Total amount paid: $!paid</p>", array('!paid' => $total_paid));
|
|
$output .= t("<h3>Bookings by state</h3>");
|
|
$output .= theme('table', array('header' => $state_header, 'rows' => $state_rows, 'attributes' => $stats_attributes));
|
|
$output .= t("<h3>Bookings by ecclesia</h3>");
|
|
$output .= theme('table', array('header' => $ecclesia_heaeder, 'rows' => $ecclesia_rows, 'attributes' => $stats_attributes));
|
|
$output .= t("<h3>Summary of attendees for !event.</h3>", array('!event' => $event->booking_eventname));
|
|
$output .= theme('table', array('header' => $header, 'rows' => $rows));
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* List the contents of the payments table
|
|
*/
|
|
function booking_report_paypal_payments() {
|
|
global $event;
|
|
$text = "";
|
|
$output = "";
|
|
$bookedin_counter = 0;
|
|
$total_paid = 0;
|
|
$total_fees = 0;
|
|
|
|
$header = array('Node Id', 'Name', 'Email', 'Payment Date', 'Gross Payment', 'Currency',
|
|
'Paypal Fee', 'Invoice', 'Payment Status', 'Payer ID', 'Item Name', 'IPN track ID');
|
|
$rows = array();
|
|
|
|
//fetch the payment table
|
|
$query = db_select('booking_payment', 'pa')
|
|
->condition('pa.booking_eventid', $event->eid,'=')
|
|
->fields('pa');
|
|
$result = $query->execute();
|
|
|
|
//$result = db_query("SELECT * FROM {booking_person} p WHERE p.booking_event_id = :eid",
|
|
// array(':eid' => $event->eid));
|
|
|
|
foreach ($result as $person) {
|
|
$rows[] = array(
|
|
l(t('!id', array('!id' => $person->booking_person_nid)), t('node/!id', array('!id' => $person->booking_person_nid))),
|
|
t('!first !last', array('!first' => ucwords($person->booking_first_name), '!last' => ucwords($person->booking_last_name))),
|
|
t('!email', array('!email' => $person->booking_buyer_email)),
|
|
t(_booking_convert_ts($person->booking_payment_date)->format('j F, Y H:i')),
|
|
t('!payment', array('!payment' => $person->booking_mc_gross)),
|
|
t('!currency', array('!currency' => $person->booking_mc_currency)),
|
|
t('!fee', array('!fee' => $person->booking_mc_fee)),
|
|
t('!invoice', array('!invoice' => $person->booking_invoice)),
|
|
t($person->booking_payment_status),
|
|
t($person->booking_payer_id),
|
|
t($person->booking_item_name),
|
|
t($person->booking_ipn_track_id)
|
|
);
|
|
$total_paid += $person->booking_mc_gross;
|
|
$total_fees += $person->booking_mc_fee;
|
|
}
|
|
|
|
$output .= t("<p>The following table presents payment entries from paypal and manual payments that have been made for !event.</p>", array('!event' => $event->booking_eventname));
|
|
$output .= theme('table', array('header' => $header, 'rows' => $rows));
|
|
$output .= t("<p>Gross amount paid: $!paid. Total amount of fees paid: $!fees</p>", array('!paid' => $total_paid, '!fees' => $total_fees));
|
|
return $output;
|
|
}
|
|
|
|
|
|
function booking_coming_page() {
|
|
global $event;
|
|
$output = "";
|
|
$table = "";
|
|
//$header = array('Name', 'Occupation', 'State');
|
|
$header = array('Name', 'State');
|
|
$booking_limit = variable_get('booking_regn_limit','350');
|
|
$rows = array();
|
|
|
|
if (variable_get('booking_auto_show_on_lists', 1) == 1)
|
|
{
|
|
$or = db_or()->condition('p.booking_status', 0)->condition('p.booking_status', 1);
|
|
|
|
$result = db_select('booking_person', 'p')
|
|
->fields('p', array('booking_firstname', 'booking_lastname', 'booking_state', 'booking_readinggroup', 'booking_country'))
|
|
->condition($or)
|
|
->condition('p.booking_event_id', $event->eid, '=')
|
|
->orderBy('booking_country')
|
|
->orderBy('booking_state')
|
|
->orderBy('booking_lastname')
|
|
->orderBy('booking_firstname')
|
|
->execute();
|
|
|
|
}
|
|
else
|
|
{
|
|
$result = db_select('booking_person', 'p')
|
|
->fields('p', array('booking_firstname', 'booking_lastname', 'booking_state', 'booking_readinggroup', 'booking_country'))
|
|
->condition('p.booking_status', 1)
|
|
->condition('p.booking_event_id', $event->eid, '=')
|
|
->orderBy('booking_country')
|
|
->orderBy('booking_state')
|
|
->orderBy('booking_lastname')
|
|
->orderBy('booking_firstname')
|
|
->execute();
|
|
|
|
/*
|
|
$result = db_query('SELECT booking_firstname, booking_lastname, booking_state, booking_readinggroup, booking_country
|
|
FROM (
|
|
SELECT booking_firstname, booking_lastname, booking_state, booking_readinggroup, booking_country
|
|
FROM {booking_person}
|
|
WHERE booking_status = 1 and booking_event_id = :eid
|
|
) AS booking
|
|
ORDER BY booking_state, booking_lastname, booking_firstname',
|
|
array(':eid' => $event->eid));
|
|
*/
|
|
|
|
}
|
|
|
|
//while ($booking = db_fetch_object($result)) {
|
|
|
|
//watchdog('booking', "Who's coming query: @info", array('@info' => var_export($result, TRUE)));
|
|
|
|
foreach ($result as $person) {
|
|
$rows[] = array(
|
|
t('!first !last', array('!first' => ucwords($person->booking_firstname),
|
|
'!last' => ucwords($person->booking_lastname))),
|
|
//only for when we have readings groups
|
|
//t('!group',array('!group' => $person->booking_readinggroup)),
|
|
t('!state', array('!state' => ($person->booking_country === variable_get('booking_default_country')) ? $person->booking_state : $person->booking_country)),
|
|
);
|
|
}
|
|
|
|
//watchdog('booking', "Who's coming formatted: @info", array('@info' => var_export($rows, TRUE)));
|
|
|
|
//output the results
|
|
//check there were some bookings
|
|
if (count($rows) > 0)
|
|
{
|
|
if (count($rows) >= $booking_limit)
|
|
{
|
|
//there is a waiting list
|
|
$output .= token_replace(variable_get('booking_whoscoming_pre_waitlist_text'), booking_define_tokens());
|
|
}
|
|
else
|
|
{
|
|
//there's no waiting list
|
|
$output .= token_replace(variable_get('booking_whoscoming_pre_text'), booking_define_tokens());
|
|
}
|
|
|
|
//theme the table of registrations
|
|
$output .= theme('table', array('header' => $header, 'rows' => $rows));
|
|
}
|
|
else
|
|
{
|
|
//no bookings
|
|
$output .= token_replace(variable_get('booking_whoscoming_pre_noregistrations_text'), booking_define_tokens());
|
|
}
|
|
|
|
//include any post-text
|
|
$output .= token_replace(variable_get('booking_whoscoming_post_text'), booking_define_tokens());
|
|
|
|
return $output;
|
|
}
|
|
|
|
function booking_waitinglist_page() {
|
|
global $event;
|
|
$output = "";
|
|
$table = "";
|
|
$count = 1;
|
|
//$header = array('Name', 'Occupation', 'State');
|
|
$header = array('Name', 'State', 'Position');
|
|
$booking_limit = variable_get('booking_regn_limit','350');
|
|
$rows = array();
|
|
|
|
$result = db_query('SELECT DISTINCT nid, booking_firstname, booking_lastname, booking_state, booking_readinggroup
|
|
FROM (
|
|
SELECT p.nid, p.booking_firstname, p.booking_lastname, p.booking_state, p.booking_readinggroup, pay.booking_payment_date
|
|
FROM {booking_person} p, {booking_payment} pay
|
|
WHERE booking_status = 2 and booking_event_id = :eid and p.nid = pay.booking_person_nid
|
|
) AS booking
|
|
ORDER BY booking_payment_date',
|
|
array(':eid' => $event->eid));
|
|
|
|
//watchdog('booking', "Who's coming query: @info", array('@info' => var_export($result, TRUE)));
|
|
|
|
foreach ($result as $person) {
|
|
$rows[] = array(
|
|
t('!first !last', array('!first' => ucwords($person->booking_firstname),
|
|
'!last' => ucwords($person->booking_lastname))),
|
|
//only for when we have readings groups
|
|
//t('!group',array('!group' => $person->booking_readinggroup)),
|
|
t('!state', array('!state' => $person->booking_state)),
|
|
t($count++),
|
|
);
|
|
}
|
|
//watchdog('booking', "Who's coming formatted: @info", array('@info' => var_export($rows, TRUE)));
|
|
|
|
|
|
//output the results
|
|
//check there were people on the waiting list
|
|
if (count($rows) > 0)
|
|
{
|
|
//include the pre-text
|
|
$output .= token_replace(variable_get('booking_waitingpage_pre_text'), booking_define_tokens());
|
|
|
|
//theme the table of waiting list people
|
|
$output .= theme('table', array('header' => $header, 'rows' => $rows));
|
|
}
|
|
else
|
|
{
|
|
//no one on the waiting list
|
|
$output .= token_replace(variable_get('booking_waitingpage_pre_nowaitlist_text'), booking_define_tokens());
|
|
}
|
|
|
|
//include any post-text
|
|
$output .= token_replace(variable_get('booking_waitingpage_post_text'), booking_define_tokens());
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Generate a CSV file as a report of all current registrations
|
|
*/
|
|
|
|
function booking_csv_report() {
|
|
global $event;
|
|
$name = 'bookings-' . format_date(time(), 'custom', 'Y-m-d-His');
|
|
$filename = file_directory_temp() . '/' . $name;
|
|
|
|
$delimiter = ',';
|
|
$enclosure = '"';
|
|
$encloseAll = true;
|
|
$nullToMysqlNull = true;
|
|
$delimiter_esc = preg_quote($delimiter, '/');
|
|
$enclosure_esc = preg_quote($enclosure, '/');
|
|
|
|
$fields_to_skip = array('booking_payment_id', 'booking_event_id', 'booking_tempid', 'booking_shirt_size');
|
|
|
|
//query the db
|
|
$query = db_select('booking_person', 'p');
|
|
$query->join('booking_price', 'pr', 'p.booking_payment_id = pr.pid');
|
|
$query->condition('p.booking_event_id', $event->eid)
|
|
->fields('p')
|
|
->fields('pr', array('booking_price', 'booking_price_descrip'));
|
|
$result = $query->execute()->fetchAll();
|
|
|
|
//open the filehandle
|
|
$handle = @fopen($filename, 'w');
|
|
|
|
//write the header based on the first result
|
|
$header_array = array();
|
|
foreach ($result[0] as $key => $value)
|
|
{
|
|
if (in_array($key, $fields_to_skip))
|
|
continue;
|
|
$header_array[] = $key;
|
|
}
|
|
|
|
$header = implode( $delimiter, $header_array );
|
|
//watchdog('booking', "CSV header: @info", array('@info' => var_export($header_array, TRUE)));
|
|
@fwrite($handle, $header . "\n");
|
|
|
|
//each record
|
|
foreach ($result as $record) {
|
|
|
|
$output = array();
|
|
//each keypair in the record
|
|
foreach ($record as $key => $value)
|
|
{
|
|
//fields to skip
|
|
if (in_array($key, $fields_to_skip))
|
|
continue;
|
|
|
|
//check for null
|
|
if ($value === NULL && $nullToMysqlNull) {
|
|
$output[] = 'NULL';
|
|
continue;
|
|
}
|
|
|
|
//handle dates
|
|
if ($key == 'booking_dob' || $key == 'booking_passport_expiry_date') {
|
|
$output[] = format_date($value, 'custom', 'd/m/Y');
|
|
continue;
|
|
}
|
|
|
|
//handle more exact dates
|
|
if ($key == 'booking_timestamp') {
|
|
$output[] = format_date($value, 'custom', 'd/m/Y H:i');
|
|
continue;
|
|
}
|
|
|
|
//booking status
|
|
if ($key == 'booking_status') {
|
|
$output[] = _booking_status_generate($value);
|
|
continue;
|
|
}
|
|
|
|
// Enclose fields containing $delimiter, $enclosure or whitespace
|
|
if ( $encloseAll || preg_match( "/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $value ) ) {
|
|
$output[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $value) . $enclosure;
|
|
}
|
|
else {
|
|
$output[] = $field;
|
|
}
|
|
}
|
|
$row = implode($delimiter, $output) . "\n";
|
|
|
|
|
|
//watchdog('booking', "Report filename: " . $filename . ".");
|
|
/*
|
|
|
|
//$header = "Barcode,Timestamp,First Name,Last Name,Gender,Date of Birth,Street,Suburb,Postcode,State,Country,Home Phone Number,Mobile Phone Number,Email,Second Email,Ecclesia,Baptised,Married,Partner Name,Room Mate 1,Room Mate 2,Help Areas,Attending Post Conference,Payment Method,Deposit Payment Deadline,Amount Paid,Discount,Status,T-shirt size";
|
|
$header = "First Name,Last Name,Gender,Date of Birth,Married,Partner Name,Email Address,Mobile Phone,Home Phone,Baptised,";
|
|
|
|
if (variable_get('booking_enable_passport', 1) == 1)
|
|
$header .= "Passport Number,Passport Expiry,Passport Issue Name,Passport Issue Location,";
|
|
|
|
if (variable_get('booking_enable_tshirts', 0) == 1)
|
|
$header .= "T-Shirt size,";
|
|
|
|
$header .= "Ecclesia,Street,Suburb,Post Code,State,Country,Emergency Contact Name,Emergency Contact Type,Emergency Contact Phone," .
|
|
"Emergency Contact Phone Alt,Medicare Number,Help Reading,Help Chairing,Help Music,Dietary Requirements,First Aid,Nurse," .
|
|
"Booking Status,Date Paid,Amount Due,Amount Paid";
|
|
|
|
if (variable_get('booking_enable_skills', 1) == 1)
|
|
$header .= ",Building Skills,Cooking Skills,Child Minding Skills,Other Languages,Mission Experience";
|
|
|
|
$query = db_query("SELECT * FROM {booking_person} p WHERE p.booking_event_id = :eid",
|
|
array(':eid' => $event->eid));
|
|
$result = $query->fetchAll();
|
|
|
|
$music_help = empty($r->booking_help_music) ? '' : $r->booking_help_music;
|
|
$row = ucwords($r->booking_firstname) . ',' . ucwords($r->booking_lastname) . ',' . $r->booking_gender . ',' . format_date($r->booking_dob, 'custom', 'd/m/Y') . ',' .
|
|
$r->booking_married . ',' . $r->booking_partner_name . ',' . $r->booking_email . ',"' . $r->booking_mobile . '","' . $r->booking_phone . '",' .
|
|
$r->booking_baptised . ',';
|
|
|
|
if (variable_get('booking_enable_passport', 1) == 1)
|
|
$row .= $r->booking_passport_num . ',' .
|
|
|
|
$row .= '"' . $r->booking_ecclesia . '","' . $r->booking_street . '","' . $r->booking_suburb . '",' . $r->booking_postcode . ',' .
|
|
$r->booking_state . ',' . $r->booking_country . ',"' .
|
|
$r->booking_guardian_name . '",' . $r->booking_guardian_type . ',"' . $r->booking_guardian_phone . '","' . $r->booking_guardian_phone_alt . '",' .
|
|
$r->booking_medicare . ',' .
|
|
$r->booking_help_reading . ',' . $r->booking_help_chairing . ',"' . $music_help . '","' .
|
|
$r->booking_dietary . '",' . $r->booking_firstaid . ',' . $r->booking_nurse . ',' .
|
|
_booking_status_generate($r->booking_status) . ',' . format_date(_booking_datepaid_ts($r->nid), 'custom', 'd/m/Y H:i') . ',' .
|
|
$r->booking_total_pay_reqd . ',' . $r->booking_amount_paid . "\n";
|
|
*/
|
|
|
|
@fwrite($handle, $row);
|
|
//$index++;
|
|
}
|
|
|
|
@fclose($handle);
|
|
|
|
drupal_add_http_header("Content-type", "application/octet-stream; charset=utf-8");
|
|
drupal_add_http_header("Content-Disposition", "attachment; filename=" . $name . ".csv");
|
|
|
|
@readfile($filename);
|
|
@unlink($filename);
|
|
exit(0);
|
|
} |