/**
  * 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);
         $employees = mdjm_get_employees();
         foreach ($employees as $employee) {
             $event_count = 0;
             $employee_id = $employee->ID;
             $event_args = array('post_status' => apply_filters('mdjm_events_by_type_statuses', array('mdjm-contract', 'mdjm-approved', 'mdjm-completed')), 'fields' => 'ids', 'meta_query' => array('relation' => 'AND', 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'), array('relation' => 'OR', array('key' => '_mdjm_event_dj', 'value' => $employee_id, 'compare' => '=', 'type' => 'numeric'), array('key' => '_mdjm_event_employees', 'value' => sprintf(':"%s";', $employee_id), 'compare' => 'LIKE'))));
             $wages = 0.0;
             $paid = 0.0;
             $owed = 0.0;
             $events = mdjm_get_events($event_args);
             if ($events) {
                 foreach ($events as $event) {
                     $event_count++;
                     $payment_status = mdjm_event_employees_paid($event, $employee_id);
                     $current_wages = mdjm_get_employees_event_wage($event, $employee_id);
                     $current_paid_wages = 0;
                     $current_owed_wages = 0;
                     $wages += $current_wages;
                     $paid += $payment_status ? $current_wages : 0.0;
                     $owed += $payment_status ? 0.0 : $current_wages;
                 }
             } else {
                 continue;
             }
             $reports_data[] = array('ID' => $employee->ID, 'employee' => $employee->display_name, 'total_events' => $event_count, 'total_wages' => mdjm_currency_filter(mdjm_format_amount($wages)), 'total_wages_raw' => $wages, 'wages_paid' => mdjm_currency_filter(mdjm_format_amount($paid)), 'wages_owed' => mdjm_currency_filter(mdjm_format_amount($owed)), 'is_child' => false);
         }
     }
     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);
         $packages = mdjm_get_packages();
         if ($packages) {
             foreach ($packages as $package) {
                 $event_count = 0;
                 $total_value = 0;
                 $event_args = array('fields' => 'ids', 'meta_query' => array('relation' => 'AND', array('key' => '_mdjm_event_package', 'value' => $package->ID, 'type' => 'NUMERIC'), 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')));
                 $events = mdjm_get_events($event_args);
                 if ($events) {
                     foreach ($events as $event) {
                         $event_count++;
                         $event_date = get_post_meta($event, '_mdjm_event_date', true);
                         $total_value += mdjm_get_package_price($package->ID, $event_date);
                     }
                 } else {
                     continue;
                 }
                 $reports_data[] = array('ID' => $package->ID, 'package' => mdjm_get_package_name($package->ID), 'events' => $event_count, 'value' => mdjm_currency_filter(mdjm_format_amount($total_value)), 'value_raw' => $total_value);
             }
         }
     }
     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('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('transaction-types', $term_args);
         foreach ($categories as $category_id => $category) {
             $category_slugs = array($category->slug);
             $txn_args = array('post_status' => array('mdjm-income', 'mdjm-expenditure'), 'fields' => 'ids', 'meta_key' => '_mdjm_txn_status', 'meta_value' => 'Completed', 'tax_query' => array(array('taxonomy' => 'transaction-types', '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)));
             $txn_count = 0;
             $total_value = 0;
             $total_income = 0;
             $total_expense = 0;
             $txns = mdjm_get_txns($txn_args);
             if ($txns) {
                 foreach ($txns as $txn) {
                     $txn_count++;
                     $mdjm_txn = new MDJM_Txn($txn);
                     if ('mdjm-income' == $mdjm_txn->post_status) {
                         $total_income += $mdjm_txn->price;
                     } else {
                         $total_expense += $mdjm_txn->price;
                     }
                     $total_value += $mdjm_txn->price;
                 }
             } else {
                 continue;
             }
             $reports_data[] = array('ID' => $category->term_id, 'type' => $category->name, 'total_transactions' => $txn_count, 'total_income' => mdjm_currency_filter(mdjm_format_amount($total_income)), 'total_income_raw' => $total_income, 'total_expense' => mdjm_currency_filter(mdjm_format_amount($total_expense)), 'total_expense_raw' => $total_expense, 'total_value' => mdjm_currency_filter(mdjm_format_amount($total_value)), 'total_value_raw' => $total_value, 'is_child' => false);
             $this->total_txn_count += $txn_count;
             $this->total_txn_income += $total_income;
             $this->total_txn_expense += $total_expense;
         }
     }
     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;
 }