/** * Build all the reports data * * @access public * @since 1.4 * @return arr $reports_data All the data for customer reports */ public function reports_data() { $stats = new MDJM_Stats(); $dates = mdjm_get_report_dates(); $stats->setup_dates($dates['range']); $cached_reports = false; if (false !== $cached_reports) { $reports_data = $cached_reports; } else { $reports_data = array(); $term_args = array('parent' => 0, 'hierarchical' => 0); $categories = get_terms('enquiry-source', $term_args); foreach ($categories as $category_id => $category) { $conversions = 0; $ratio = 0; $event_count = 0; $category_slugs = array($category->slug); $all_event_args = array('post_status' => 'any', 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'enquiry-source', 'field' => 'slug', 'terms' => $category_slugs)), 'date_query' => array(array('after' => date('Y-m-d', $stats->start_date), 'before' => date('Y-m-d', $stats->end_date), 'inclusive' => true))); $value = 0.0; $events = mdjm_get_events($all_event_args); $statuses = mdjm_active_event_statuses(); $statuses[] = 'mdjm-completed'; $statuses[] = 'mdjm-cancelled'; if ($events) { foreach ($events as $event) { $event_count++; $mdjm_event = new MDJM_Event($event); if (in_array($mdjm_event->post_status, $statuses)) { $current_value = $mdjm_event->get_total_profit(); $value += $current_value; } } } else { continue; } $conversions += $stats->get_conversions($events, 'enquiry-source', $category_slugs, $stats->start_date, $stats->end_date); $ratio = round((double) ($conversions / $event_count) * 100); $reports_data[] = array('ID' => $category->term_id, 'source' => $category->name, 'total_events' => $event_count, 'total_conversions' => $conversions, 'conversion_ratio' => $ratio . '%', 'total_value' => mdjm_currency_filter(mdjm_format_amount($value)), 'total_value_raw' => $value, 'is_child' => false); $this->total_enquiries += $event_count; $this->total_value += $value; $this->total_conversions += $conversions; } } return $reports_data; }
/** * Build all the reports data * * @access public * @since 1.4 * @return arr $reports_data All the data for customer reports */ public function reports_data() { $stats = new MDJM_Stats(); $dates = mdjm_get_report_dates(); $stats->setup_dates($dates['range']); $cached_reports = false; if (false !== $cached_reports) { $reports_data = $cached_reports; } else { $reports_data = array(); $term_args = array('parent' => 0, 'hierarchical' => 0); $categories = get_terms('event-types', $term_args); foreach ($categories as $category_id => $category) { $event_count = 0; $category_slugs = array($category->slug); $all_event_args = array('post_status' => apply_filters('mdjm_events_by_type_statuses', array('mdjm-contract', 'mdjm-approved', 'mdjm-completed')), 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'event-types', 'field' => 'slug', 'terms' => $category_slugs)), 'meta_query' => array(array('key' => '_mdjm_event_date', 'value' => array(date('Y-m-d', $stats->start_date), date('Y-m-d', $stats->end_date)), 'type' => 'date', 'compare' => 'BETWEEN'))); $earnings = 0.0; $avg_earnings = 0.0; $events = mdjm_get_events($all_event_args); if ($events) { foreach ($events as $event) { $event_count++; $mdjm_event = new MDJM_Event($event); $current_average_earnings = $current_earnings = $mdjm_event->get_total_profit(); $received_date = get_post_field('post_date', $event); $diff = abs(current_time('timestamp') - strtotime($received_date)); $months = floor($diff / (30 * 60 * 60 * 24)); // Number of months since publication if ($months > 0) { $current_average_earnings = $current_earnings / $months; //$current_average_events = ( $events / $months ); } $earnings += $current_earnings; $avg_earnings += $current_average_earnings; } } else { continue; } $avg_earnings = round($avg_earnings / $event_count, mdjm_currency_decimal_filter()); $reports_data[] = array('ID' => $category->term_id, 'type' => $category->name, 'total_events' => $event_count, 'total_earnings' => mdjm_currency_filter(mdjm_format_amount($earnings)), 'total_earnings_raw' => $earnings, 'avg_earnings' => mdjm_currency_filter(mdjm_format_amount($avg_earnings)), 'is_child' => false); } } return $reports_data; }