Initial project add

This commit is contained in:
2013-09-30 12:01:07 +10:00
commit 1598a272c4
18 changed files with 6897 additions and 0 deletions

404
booking.reports.inc Normal file
View File

@@ -0,0 +1,404 @@
<?php
// $Id: booking.confirm.inc,v 0.1 2011/07/12
/**
* List people and how much they have paid
*/
function booking_report_payments() {
global $event;
$text = "";
$output = "";
$bookedin_counter = 0;
$notpaid_counter = 0;
$waiting_counter = 0;
$total_paid = 0;
$header = array('Id', 'Name', 'Email', 'Payment To Date', 'Total Payment Required');
$rows = array();
$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++;
}
/*
return array(
'first_para' => array(
'#type' => 'markup',
'#markup' => t("<p>The following table presents a summary"),
),
'table' => theme('table', array(
'header' => $header,
'rows' => $rows,
)),
);*/
$output .= t("<p>The following table presents a summary of payments that have been made for !event.</p>", array('!event' => $event->booking_eventname));
$output .= theme('table', array('header' => $header, 'rows' => $rows));
$output .= t("<p>Total of !bookedin registrations currently booked in, !waiting on waiting list, and !notpaid haven't paid.</p>",
array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter));
$output .= t("<p>Total amount paid: $!paid</p>", array('!paid' => $total_paid));
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);
}