Renamed function _split_date, added average age calculation to summary report

This commit is contained in:
2013-10-02 15:29:25 +10:00
parent e135ef9883
commit bb5dc7322e
3 changed files with 54 additions and 33 deletions

View File

@@ -6,8 +6,9 @@
*/
function booking_report_summary() {
global $event;
$text = "";
//$text = "";
$output = "";
$non_australia_count = 0;
$bookedin_counter = 0;
$notpaid_counter = 0;
$waiting_counter = 0;
@@ -16,19 +17,22 @@ function booking_report_summary() {
$baptised_count = 0;
$married_count = 0;
$total_paid = 0;
$dob_total = 0;
$person_count = 0;
$average = 0;
$average_age = "";
//$year = 60 * 60 * 24 * 365.25;
$stats_attributes = array('style' => 'max-width:30%');
$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));
//do some analysis about the people booked in
//first the summary of states
$rows = array();
$state_header = array('State', 'Count');
$state_rows = array();
$non_australia_count = 0;
$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, '=');
@@ -43,16 +47,19 @@ function booking_report_summary() {
$non_australia_count += $state->state_count;
}
//non australian states
$state_rows[] = array('International',$non_australia_count);
$state_rows[] = array('International', $non_australia_count);
//general stats
$query = db_select('booking_person', 'p')
->fields('p', array('booking_baptised', 'booking_married', 'booking_gender'))
->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++;
else
@@ -64,10 +71,13 @@ function booking_report_summary() {
if ($person->booking_married == 'Y')
$married_count++;
}
//calculate the average age timestamp
$average = $dob_total / $person_count;
//convert that to years
$average_age = floor((time() - $average) / (60 * 60 * 24 * 365.25));
//bookings by ecclesia
$ecclesia_heaeder = array('State','Ecclesia', 'Count');
$ecclesia_rows = array();
$query = db_select('booking_person', 'p')
->fields('p', array('booking_ecclesia','booking_state'))
->condition('p.booking_event_id', $event->eid, '=');
@@ -82,6 +92,8 @@ function booking_report_summary() {
}
//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))),
@@ -101,17 +113,19 @@ function booking_report_summary() {
}
//output everything
$output .= t("<p>There are !boys males and !girls females registered. Of these, !baptised are baptised and !married are married.</p>",
array('!boys' => $male_count, '!girls' => $female_count, '!baptised' => $baptised_count, '!married' => $married_count));
$output .= t("<p>Bookings by state</p>");
$output .= theme('table', array('header' => $state_header, 'rows' => $state_rows, 'attributes' => $stats_attributes));
$output .= t("<p>Bookings by ecclesia</p>");
$output .= theme('table', array('header' => $ecclesia_heaeder, 'rows' => $ecclesia_rows, 'attributes' => $stats_attributes));
$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>",
$output .= t("<p>There are !boys males and !girls females registered. Of these, !baptised are baptised and !married are married. The average age is !average years.",
array('!boys' => $male_count, '!girls' => $female_count, '!baptised' => $baptised_count, '!married' => $married_count
'!average' => $average_age));
$output .= t("Total of !bookedin registrations currently booked in, !waiting on waiting list, and !notpaid haven't paid.<br />",
array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter));
$output .= t("<p>Total amount paid: $!paid</p>", array('!paid' => $total_paid));
$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;
}