diff --git a/booking.reports.inc b/booking.reports.inc index c908b6b..b5b2b90 100644 --- a/booking.reports.inc +++ b/booking.reports.inc @@ -12,9 +12,9 @@ function booking_report_summary() { $notpaid_counter = 0; $waiting_counter = 0; $total_paid = 0; + $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", @@ -24,20 +24,40 @@ function booking_report_summary() { //first the summary of states $state_header = array('State', 'Count'); $state_rows = array(); - $state_stats = db_select('booking_person', 'p') - ->fields('p', array('booking_state')) - ->condition('p.booking_event_id', $event->eid, '=') - ->addExpression('COUNT(booking_state)', 'state_count') - ->execute(); + $non_australia_count = 0; + $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'); + $state_stats = $query->execute(); foreach ($state_stats as $state) { - $state_rows[] = array($state->booking_state, $state->state_count); + if (strcmp($state->booking_country,'Australia') == 0 ) + $state_rows[] = array($state->booking_state, $state->state_count); + else + $non_australia_count += $state->state_count; } - $output .= t("

Bookings by state

"); - $output .= theme('table', array('header' => $state_header, 'rows' => $state_rows)); - + //non australian states + $state_rows[] = array('International',$non_australia_count); + + //bookings by ecclesia + $ecclesia_heaeder = array('Ecclesia', 'Count'); + $ecclesia_rows = array(); + $query = db_select('booking_person', 'p') + ->fields('p', array('booking_ecclesia')) + ->condition('p.booking_event_id', $event->eid, '='); + $query->groupBy('p.booking_ecclesia'); + $query->addExpression('COUNT(p.booking_ecclesia)', 'ecclesia_count'); + $stats = $query->execute(); + + foreach ($stats as $ecclesia) { + $ecclesia_rows[] = array($ecclesia->booking_ecclesia, $ecclesia->ecclesia_count); + } + + //more detailed summary $output .= t("

The following table presents a summary of payments that have been made for !event.

", array('!event' => $event->booking_eventname)); foreach ($result as $person) { $rows[] = array( @@ -57,7 +77,11 @@ function booking_report_summary() { $waiting_counter++; } - + //output everything + $output .= t("

Bookings by state

"); + $output .= theme('table', array('header' => $state_header, 'rows' => $state_rows, 'attributes' => $stats_attributes)); + $output .= t("

Bookings by ecclesia

"); + $output .= theme('table', array('header' => $ecclesia_heaeder, 'rows' => $ecclesia_rows, 'attributes' => $stats_attributes)); $output .= theme('table', array('header' => $header, 'rows' => $rows)); $output .= t("

Total of !bookedin registrations currently booked in, !waiting on waiting list, and !notpaid haven't paid.

", array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter));