/**
 * Show report graphs of a specific product
 *
 * @since 1.9
 * @return void
*/
function edd_reports_graph_of_download($download_id = 0)
{
    // Retrieve the queried dates
    $dates = edd_get_report_dates();
    // Determine graph options
    switch ($dates['range']) {
        case 'today':
        case 'yesterday':
            $day_by_day = true;
            break;
        case 'last_year':
            $day_by_day = false;
            break;
        case 'this_year':
            $day_by_day = false;
            break;
        case 'last_quarter':
            $day_by_day = false;
            break;
        case 'this_quarter':
            $day_by_day = false;
            break;
        case 'other':
            if ($dates['m_end'] - $dates['m_start'] >= 2 || $dates['year_end'] > $dates['year']) {
                $day_by_day = false;
            } else {
                $day_by_day = true;
            }
            break;
        default:
            $day_by_day = true;
            break;
    }
    $earnings_totals = (double) 0.0;
    // Total earnings for time period shown
    $sales_totals = 0;
    // Total sales for time period shown
    $include_taxes = empty($_GET['exclude_taxes']) ? true : false;
    $earnings_data = array();
    $sales_data = array();
    $stats = new EDD_Payment_Stats();
    if ($dates['range'] == 'today' || $dates['range'] == 'yesterday') {
        // Hour by hour
        $month = $dates['m_start'];
        $hour = 0;
        $minute = 0;
        $second = 0;
        while ($hour <= 23) {
            if ($hour == 23) {
                $minute = $second = 59;
            }
            $date = mktime($hour, $minute, $second, $month, $dates['day'], $dates['year']);
            $date_end = mktime($hour + 1, $minute, $second, $month, $dates['day'], $dates['year']);
            $sales = $stats->get_sales($download_id, $date, $date_end);
            $sales_totals += $sales;
            $earnings = $stats->get_earnings($download_id, $date, $date_end, $include_taxes);
            $earnings_totals += $earnings;
            $sales_data[] = array($date * 1000, $sales);
            $earnings_data[] = array($date * 1000, $earnings);
            $hour++;
        }
    } elseif ($dates['range'] == 'this_week' || $dates['range'] == 'last_week') {
        $num_of_days = cal_days_in_month(CAL_GREGORIAN, $dates['m_start'], $dates['year']);
        $report_dates = array();
        $i = 0;
        while ($i <= 6) {
            if ($dates['day'] + $i <= $num_of_days) {
                $report_dates[$i] = array('day' => (string) $dates['day'] + $i, 'month' => $dates['m_start'], 'year' => $dates['year']);
            } else {
                $report_dates[$i] = array('day' => (string) $i, 'month' => $dates['m_end'], 'year' => $dates['year_end']);
            }
            $i++;
        }
        foreach ($report_dates as $report_date) {
            $date = mktime(0, 0, 0, $report_date['month'], $report_date['day'], $report_date['year']);
            $date_end = mktime(23, 59, 59, $report_date['month'], $report_date['day'], $report_date['year']);
            $sales = $stats->get_sales($download_id, $date, $date_end);
            $sales_totals += $sales;
            $earnings = $stats->get_earnings($download_id, $date, $date_end, $include_taxes);
            $earnings_totals += $earnings;
            $sales_data[] = array($date * 1000, $sales);
            $earnings_data[] = array($date * 1000, $earnings);
        }
    } else {
        $y = $dates['year'];
        $temp_data = array();
        while ($y <= $dates['year_end']) {
            $last_year = false;
            if ($dates['year'] == $dates['year_end']) {
                $month_start = $dates['m_start'];
                $month_end = $dates['m_end'];
                $last_year = true;
            } elseif ($y == $dates['year']) {
                $month_start = $dates['m_start'];
                $month_end = 12;
            } elseif ($y == $dates['year_end']) {
                $month_start = 1;
                $month_end = $dates['m_end'];
            } else {
                $month_start = 1;
                $month_end = 12;
            }
            $i = $month_start;
            while ($i <= $month_end) {
                $d = $dates['day'];
                if ($i == $month_end) {
                    $num_of_days = $dates['day_end'];
                    if ($month_start < $month_end) {
                        $d = 1;
                    }
                } else {
                    $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y);
                }
                while ($d <= $num_of_days) {
                    $date = mktime(0, 0, 0, $i, $d, $y);
                    $end_date = mktime(23, 59, 59, $i, $d, $y);
                    $earnings = $stats->get_earnings($download_id, $date, $end_date, $include_taxes);
                    $earnings_totals += $earnings;
                    $sales = $stats->get_sales($download_id, $date, $end_date);
                    $sales_totals += $sales;
                    $temp_data['earnings'][$y][$i][$d] = $earnings;
                    $temp_data['sales'][$y][$i][$d] = $sales;
                    $d++;
                }
                $i++;
            }
            $y++;
        }
        $sales_data = array();
        $earnings_data = array();
        // When using 2 months or smaller as the custom range, show each day individually on the graph
        if ($day_by_day) {
            foreach ($temp_data['sales'] as $year => $months) {
                foreach ($months as $month => $dates) {
                    foreach ($dates as $day => $sales) {
                        $date = mktime(0, 0, 0, $month, $day, $year) * 1000;
                        $sales_data[] = array($date, $sales);
                    }
                }
            }
            foreach ($temp_data['earnings'] as $year => $months) {
                foreach ($months as $month => $dates) {
                    foreach ($dates as $day => $earnings) {
                        $date = mktime(0, 0, 0, $month, $day, $year) * 1000;
                        $earnings_data[] = array($date, $earnings);
                    }
                }
            }
            // When showing more than 2 months of results, group them by month, by the first (except for the last month, group on the last day of the month selected)
        } else {
            foreach ($temp_data['sales'] as $year => $months) {
                $month_keys = array_keys($months);
                $last_month = end($month_keys);
                foreach ($months as $month => $days) {
                    $day_keys = array_keys($days);
                    $last_day = end($day_keys);
                    $consolidated_date = $month === $last_month ? $last_day : 1;
                    $sales = array_sum($days);
                    $date = mktime(0, 0, 0, $month, $consolidated_date, $year) * 1000;
                    $sales_data[] = array($date, $sales);
                }
            }
            foreach ($temp_data['earnings'] as $year => $months) {
                $month_keys = array_keys($months);
                $last_month = end($month_keys);
                foreach ($months as $month => $days) {
                    $day_keys = array_keys($days);
                    $last_day = end($day_keys);
                    $consolidated_date = $month === $last_month ? $last_day : 1;
                    $earnings = array_sum($days);
                    $date = mktime(0, 0, 0, $month, $consolidated_date, $year) * 1000;
                    $earnings_data[] = array($date, $earnings);
                }
            }
        }
    }
    $data = array(__('Earnings', 'easy-digital-downloads') => $earnings_data, __('Sales', 'easy-digital-downloads') => $sales_data);
    ?>
	<div class="metabox-holder" style="padding-top: 0;">
		<div class="postbox">
			<h3><span><?php 
    printf(__('Earnings Over Time for %s', 'easy-digital-downloads'), get_the_title($download_id));
    ?>
</span></h3>

			<div class="inside">
				<?php 
    edd_reports_graph_controls();
    $graph = new EDD_Graph($data);
    $graph->set('x_mode', 'time');
    $graph->set('multiple_y_axes', true);
    $graph->display();
    ?>
				<p class="edd_graph_totals"><strong><?php 
    _e('Total earnings for period shown: ', 'easy-digital-downloads');
    echo edd_currency_filter(edd_format_amount($earnings_totals));
    ?>
</strong></p>
				<p class="edd_graph_totals"><strong><?php 
    _e('Total sales for period shown: ', 'easy-digital-downloads');
    echo $sales_totals;
    ?>
</strong></p>
				<p class="edd_graph_totals"><strong><?php 
    printf(__('Average monthly earnings: %s', 'easy-digital-downloads'), edd_currency_filter(edd_format_amount(edd_get_average_monthly_download_earnings($download_id))));
    ?>
				<p class="edd_graph_totals"><strong><?php 
    printf(__('Average monthly sales: %s', 'easy-digital-downloads'), number_format(edd_get_average_monthly_download_sales($download_id), 0));
    ?>
			</div>
		</div>
	</div>
	<?php 
    echo ob_get_clean();
}
 /**
  * Outputs the reporting views
  *
  * @access public
  * @since  2.4
  * @return void
  */
 public function bulk_actions($which = '')
 {
     if ('bottom' === $which) {
         return;
     }
     // These aren't really bulk actions but this outputs the markup in the right place
     edd_report_views();
     edd_reports_graph_controls();
 }
Пример #3
0
/**
 * Show Commissions Graph
 *
 * @access      public
 * @since       1.0
 * @return      void
*/
function edd_show_commissions_graph()
{
    // retrieve the queried dates
    $dates = edd_get_report_dates();
    $day_by_day = true;
    // Determine graph options
    switch ($dates['range']) {
        case 'last_year':
        case 'this_year':
        case 'last_quarter':
        case 'this_quarter':
            $day_by_day = false;
            break;
        case 'other':
            if ($dates['m_end'] - $dates['m_start'] >= 2) {
                $day_by_day = false;
            }
            break;
    }
    $user = isset($_GET['user']) ? absint($_GET['user']) : 0;
    $total = (double) 0.0;
    // Total commissions for time period shown
    ob_start();
    ?>
	<div class="tablenav top">
		<div class="alignleft actions"><?php 
    edd_report_views();
    ?>
</div>
	</div>
	<?php 
    $data = array();
    if ($dates['range'] == 'today') {
        // Hour by hour
        $hour = 1;
        $month = date('n');
        while ($hour <= 23) {
            $commissions = edd_get_commissions_by_date($dates['day'], $month, $dates['year'], $hour, $user);
            $total += $commissions;
            $date = mktime($hour, 0, 0, $month, $dates['day'], $dates['year']);
            $data[] = array($date * 1000, (int) $commissions);
            $hour++;
        }
    } elseif ($dates['range'] == 'this_week' || $dates['range'] == 'last_week') {
        //Day by day
        $day = $dates['day'];
        $day_end = $dates['day_end'];
        $month = $dates['m_start'];
        while ($day <= $day_end) {
            $commissions = edd_get_commissions_by_date($day, $month, $dates['year'], null, $user);
            $total += $commissions;
            $date = mktime(0, 0, 0, $month, $day, $dates['year']);
            $data[] = array($date * 1000, (int) $commissions);
            $day++;
        }
    } else {
        $i = $dates['m_start'];
        while ($i <= $dates['m_end']) {
            if ($day_by_day) {
                $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $dates['year']);
                $d = 1;
                while ($d <= $num_of_days) {
                    $date = mktime(0, 0, 0, $i, $d, $dates['year']);
                    $commissions = edd_get_commissions_by_date($d, $i, $dates['year'], null, $user);
                    $total += $commissions;
                    $data[] = array($date * 1000, (int) $commissions);
                    $d++;
                }
            } else {
                $date = mktime(0, 0, 0, $i, 1, $dates['year']);
                $commissions = edd_get_commissions_by_date(null, $i, $dates['year'], null, $user);
                $total += $commissions;
                $data[] = array($date * 1000, (int) $commissions);
            }
            $i++;
        }
    }
    $data = array(__('Commissions', 'eddc') => $data);
    ?>

	<div class="metabox-holder" style="padding-top: 0;">
		<div class="postbox">
			<h3><span><?php 
    _e('Commissions Paid Over Time', 'edd');
    ?>
</span></h3>

			<div class="inside">
				<?php 
    if (!empty($user)) {
        $user_data = get_userdata($user);
        ?>
				<p>
					<?php 
        printf(__('Showing commissions paid to %s', 'eddc'), $user_data->display_name);
        ?>
					&nbsp;&ndash;&nbsp;<a href="<?php 
        echo esc_url(remove_query_arg('user'));
        ?>
"><?php 
        _e('clear', 'eddc');
        ?>
</a>
				</p>
				<?php 
    }
    ?>
				<?php 
    edd_reports_graph_controls();
    $graph = new EDD_Graph($data);
    $graph->set('x_mode', 'time');
    $graph->display();
    ?>
				<p id="edd_graph_totals"><strong><?php 
    _e('Total commissions for period shown: ', 'edd');
    echo edd_currency_filter(edd_format_amount($total));
    ?>
</strong></p>
   			</div>
   		</div>
   	</div>
	<?php 
    echo ob_get_clean();
}
    /**
     * Outputs the reporting views
     *
     * @access public
     * @since 1.5
     * @return void
     */
    public function display_tablenav($which = '')
    {
        ?>
		<div class="tablenav <?php 
        echo esc_attr($which);
        ?>
">
			<div class="alignleft actions bulkactions">
				<?php 
        if ('top' === $which) {
            edd_report_views();
            edd_reports_graph_controls();
        }
        ?>
			</div>
		</div>
	<?php 
    }
Пример #5
0
/**
 * Show license upgrades
 *
 * @access      public
 * @since       3.3
 * @return      void
*/
function edd_sl_show_upgrades_graph()
{
    if (!current_user_can('view_shop_reports')) {
        wp_die(__('You do not have permission to view this data', 'edd_sl'), __('Error', 'edd_sl'), array('response' => 401));
    }
    $dates = edd_get_report_dates();
    $day_by_day = true;
    // Determine graph options
    switch ($dates['range']) {
        case 'last_year':
        case 'this_year':
        case 'last_quarter':
        case 'this_quarter':
            $day_by_day = false;
            break;
        case 'other':
            if ($dates['m_end'] - $dates['m_start'] >= 2) {
                $day_by_day = false;
            }
            break;
    }
    $total = (double) 0.0;
    // Total upgrades value for time period shown
    ob_start();
    ?>
	<div class="tablenav top">
		<div class="alignleft actions"><?php 
    edd_report_views();
    ?>
</div>
	</div>
	<?php 
    $data = array();
    if ($dates['range'] == 'today') {
        // Hour by hour
        $hour = 1;
        $month = date('n');
        while ($hour <= 23) {
            $upgrades = edd_sl_get_upgrades_by_date($dates['day'], $month, $dates['year'], $hour);
            $total += $upgrades['earnings'];
            $date = mktime($hour, 0, 0, $month, $dates['day'], $dates['year']);
            $data[] = array($date * 1000, (int) $upgrades['count']);
            $hour++;
        }
    } elseif ($dates['range'] == 'this_week' || $dates['range'] == 'last_week') {
        //Day by day
        $day = $dates['day'];
        $day_end = $dates['day_end'];
        $month = $dates['m_start'];
        while ($day <= $day_end) {
            $upgrades = edd_sl_get_upgrades_by_date($day, $month, $dates['year'], null);
            $total += $upgrades['earnings'];
            $date = mktime(0, 0, 0, $month, $day, $dates['year']);
            $data[] = array($date * 1000, (int) $upgrades['count']);
            $day++;
        }
    } else {
        $i = $dates['m_start'];
        while ($i <= $dates['m_end']) {
            if ($day_by_day) {
                $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $dates['year']);
                $d = 1;
                while ($d <= $num_of_days) {
                    $date = mktime(0, 0, 0, $i, $d, $dates['year']);
                    $upgrades = edd_sl_get_upgrades_by_date($d, $i, $dates['year'], null);
                    $total += $upgrades['earnings'];
                    $data[] = array($date * 1000, (int) $upgrades['count']);
                    $d++;
                }
            } else {
                $date = mktime(0, 0, 0, $i, 1, $dates['year']);
                $upgrades = edd_sl_get_upgrades_by_date(null, $i, $dates['year'], null);
                $total += $upgrades['earnings'];
                $data[] = array($date * 1000, (int) $upgrades['count']);
            }
            $i++;
        }
    }
    $data = array(__('License Upgrades', 'edd_sl') => $data);
    ?>

	<div class="metabox-holder" style="padding-top: 0;">
		<div class="postbox">
			<h3><span><?php 
    _e('License Upgrades', 'edd_sl');
    ?>
</span></h3>

			<div class="inside">
				<?php 
    edd_reports_graph_controls();
    $graph = new EDD_Graph($data);
    $graph->set('x_mode', 'time');
    $graph->display();
    ?>
				<p id="edd_graph_totals">
					<strong><?php 
    _e('Total earnings from upgrades period shown: ', 'edd_sl');
    echo edd_currency_filter(edd_format_amount($total));
    ?>
</strong>
				</p>
   			</div>
   		</div>
   	</div>
	<?php 
    echo ob_get_clean();
}
Пример #6
0
/**
 * Show report graphs of a specific product
 *
 * @since 1.9
 * @return void
*/
function edd_reports_graph_of_download($download_id = 0)
{
    // Retrieve the queried dates
    $dates = edd_get_report_dates();
    // Determine graph options
    switch ($dates['range']) {
        case 'today':
        case 'yesterday':
            $day_by_day = true;
            break;
        case 'last_year':
            $day_by_day = false;
            break;
        case 'this_year':
            $day_by_day = false;
            break;
        case 'last_quarter':
            $day_by_day = false;
            break;
        case 'this_quarter':
            $day_by_day = false;
            break;
        case 'other':
            if ($dates['m_end'] - $dates['m_start'] >= 2 || $dates['year_end'] > $dates['year']) {
                $day_by_day = false;
            } else {
                $day_by_day = true;
            }
            break;
        default:
            $day_by_day = true;
            break;
    }
    $earnings_totals = (double) 0.0;
    // Total earnings for time period shown
    $sales_totals = 0;
    // Total sales for time period shown
    $include_taxes = empty($_GET['exclude_taxes']) ? true : false;
    $earnings_data = array();
    $sales_data = array();
    $stats = new EDD_Payment_Stats();
    if ($dates['range'] == 'today' || $dates['range'] == 'yesterday') {
        // Hour by hour
        $month = $dates['m_start'];
        $hour = 1;
        $minute = 0;
        $second = 0;
        while ($hour <= 23) {
            if ($hour == 23) {
                $minute = $second = 59;
            }
            $date = mktime($hour, $minute, $second, $month, $dates['day'], $dates['year']);
            $date_end = mktime($hour + 1, $minute, $second, $month, $dates['day'], $dates['year']);
            $sales = $stats->get_sales($download_id, $date, $date_end);
            $sales_totals += $sales;
            $earnings = $stats->get_earnings($download_id, $date, $date_end, $include_taxes);
            $earnings_totals += $earnings;
            $sales_data[] = array($date * 1000, $sales);
            $earnings_data[] = array($date * 1000, $earnings);
            $hour++;
        }
    } elseif ($dates['range'] == 'this_week' || $dates['range'] == 'last_week') {
        //Day by day
        $day = $dates['day'];
        $day_end = $dates['day_end'];
        $month = $dates['m_start'];
        while ($day <= $day_end) {
            $date = mktime(0, 0, 0, $month, $day, $dates['year']);
            $date_end = mktime(0, 0, 0, $month, $day + 1, $dates['year']);
            $sales = $stats->get_sales($download_id, $date, $date_end);
            $sales_totals += $sales;
            $earnings = $stats->get_earnings($download_id, $date, $date_end, $include_taxes);
            $earnings_totals += $earnings;
            $sales_data[] = array($date * 1000, $sales);
            $earnings_data[] = array($date * 1000, $earnings);
            $day++;
        }
    } else {
        $y = $dates['year'];
        while ($y <= $dates['year_end']) {
            $last_year = false;
            if ($dates['year'] == $dates['year_end']) {
                $month_start = $dates['m_start'];
                $month_end = $dates['m_end'];
                $last_year = true;
            } elseif ($y == $dates['year']) {
                $month_start = $dates['m_start'];
                $month_end = 12;
            } else {
                $month_start = 1;
                $month_end = 12;
            }
            $i = $month_start;
            while ($i <= $month_end) {
                if ($day_by_day) {
                    if ($i == $month_end && $last_year) {
                        $num_of_days = $dates['day_end'];
                    } else {
                        $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y);
                    }
                    $d = $dates['day'];
                    while ($d <= $num_of_days) {
                        $date = mktime(0, 0, 0, $i, $d, $y);
                        $end_date = mktime(23, 59, 59, $i, $d, $y);
                        $sales = $stats->get_sales($download_id, $date, $end_date);
                        $sales_totals += $sales;
                        $earnings = $stats->get_earnings($download_id, $date, $end_date, $include_taxes);
                        $earnings_totals += $earnings;
                        $sales_data[] = array($date * 1000, $sales);
                        $earnings_data[] = array($date * 1000, $earnings);
                        $d++;
                    }
                } else {
                    $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y);
                    $date = mktime(0, 0, 0, $i, 1, $y);
                    $end_date = mktime(23, 59, 59, $i, $num_of_days, $y);
                    $sales = $stats->get_sales($download_id, $date, $end_date);
                    $sales_totals += $sales;
                    $earnings = $stats->get_earnings($download_id, $date, $end_date, $include_taxes);
                    $earnings_totals += $earnings;
                    $sales_data[] = array($date * 1000, $sales);
                    $earnings_data[] = array($date * 1000, $earnings);
                }
                $i++;
            }
            $y++;
        }
    }
    $data = array(__('Earnings', 'easy-digital-downloads') => $earnings_data, __('Sales', 'easy-digital-downloads') => $sales_data);
    ?>
	<div class="metabox-holder" style="padding-top: 0;">
		<div class="postbox">
			<h3><span><?php 
    printf(__('Earnings Over Time for %s', 'easy-digital-downloads'), get_the_title($download_id));
    ?>
</span></h3>

			<div class="inside">
				<?php 
    edd_reports_graph_controls();
    $graph = new EDD_Graph($data);
    $graph->set('x_mode', 'time');
    $graph->set('multiple_y_axes', true);
    $graph->display();
    ?>
				<p class="edd_graph_totals"><strong><?php 
    _e('Total earnings for period shown: ', 'easy-digital-downloads');
    echo edd_currency_filter(edd_format_amount($earnings_totals));
    ?>
</strong></p>
				<p class="edd_graph_totals"><strong><?php 
    _e('Total sales for period shown: ', 'easy-digital-downloads');
    echo $sales_totals;
    ?>
</strong></p>
				<p class="edd_graph_totals"><strong><?php 
    printf(__('Average monthly earnings: %s', 'easy-digital-downloads'), edd_currency_filter(edd_format_amount(edd_get_average_monthly_download_earnings($download_id))));
    ?>
				<p class="edd_graph_totals"><strong><?php 
    printf(__('Average monthly sales: %s', 'easy-digital-downloads'), number_format(edd_get_average_monthly_download_sales($download_id), 0));
    ?>
			</div>
		</div>
	</div>
	<?php 
    echo ob_get_clean();
}
Пример #7
0
/**
 * Show report graphs
 *
 * @access      public
 * @since       1.3
 * @return      void
*/
function edd_reports_graph()
{
    // Retrieve the queried dates
    $dates = edd_get_report_dates();
    // Determine graph options
    switch ($dates['range']) {
        case 'last_year':
            $time_format = '%b';
            $tick_size = 'month';
            $day_by_day = false;
            break;
        case 'this_year':
            $time_format = '%b';
            $tick_size = 'month';
            $day_by_day = false;
            break;
        case 'last_quarter':
            $time_format = '%b';
            $tick_size = 'month';
            $day_by_day = false;
            break;
        case 'this_quarter':
            $time_format = '%b';
            $tick_size = 'month';
            $day_by_day = false;
            break;
        case 'other':
            if ($dates['m_end'] - $dates['m_start'] >= 2) {
                $time_format = '%b';
                $tick_size = 'month';
                $day_by_day = false;
            } else {
                $time_format = '%d/%b';
                $tick_size = 'day';
                $day_by_day = true;
            }
            break;
        default:
            $time_format = '%d/%b';
            // show days by default
            $tick_size = 'day';
            // default graph interval
            $day_by_day = true;
            break;
    }
    $time_format = apply_filters('edd_graph_timeformat', $time_format);
    $tick_size = apply_filters('edd_graph_ticksize', $tick_size);
    $totals = (double) 0.0;
    // total earnings for time period shown
    ob_start();
    ?>
	<script type="text/javascript">
	   jQuery( document ).ready( function($) {
	   		$.plot(
	   			$("#edd_monthly_stats"),
	   			[{
   					data: [
	   					<?php 
    $i = $dates['m_start'];
    while ($i <= $dates['m_end']) {
        if ($day_by_day) {
            $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $dates['year']);
            $d = 1;
            while ($d <= $num_of_days) {
                $date = mktime(0, 0, 0, $i, $d, $dates['year']);
                ?>
									[<?php 
                echo $date * 1000;
                ?>
, <?php 
                echo edd_get_sales_by_date($d, $i, $dates['year']);
                ?>
],
								<?php 
                $d++;
            }
        } else {
            $date = mktime(0, 0, 0, $i, 1, $dates['year']);
            ?>
								[<?php 
            echo $date * 1000;
            ?>
, <?php 
            echo edd_get_sales_by_date(null, $i, $dates['year']);
            ?>
],
							<?php 
        }
        $i++;
    }
    ?>
,
	   				],
	   				yaxis: 2,
   					label: "<?php 
    _e('Sales', 'edd');
    ?>
",
   					id: 'sales'
   				},
   				{
   					data: [
	   					<?php 
    $i = $dates['m_start'];
    while ($i <= $dates['m_end']) {
        if ($day_by_day) {
            $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $dates['year']);
            $d = 1;
            while ($d <= $num_of_days) {
                $date = mktime(0, 0, 0, $i, $d, $dates['year']);
                $earnings = edd_get_earnings_by_date($d, $i, $dates['year']);
                $totals += $earnings;
                ?>
									[<?php 
                echo $date * 1000;
                ?>
, <?php 
                echo $earnings;
                ?>
],
								<?php 
                $d++;
            }
        } else {
            $date = mktime(0, 0, 0, $i, 1, $dates['year']);
            $earnings = edd_get_earnings_by_date(null, $i, $dates['year']);
            $totals += $earnings;
            ?>
								[<?php 
            echo $date * 1000;
            ?>
, <?php 
            echo $earnings;
            ?>
],
							<?php 
        }
        $i++;
    }
    ?>
	   				],
   					label: "<?php 
    _e('Earnings', 'edd');
    ?>
",
   					id: 'earnings'
	   			}],
	   		{
               	series: {
                   lines: { show: true },
                   points: { show: true }
            	},
            	grid: {
           			show: true,
					aboveData: false,
					color: '#ccc',
					backgroundColor: '#fff',
					borderWidth: 2,
					borderColor: '#ccc',
					clickable: false,
					hoverable: true
           		},
            	xaxis: {
	   				mode: "time",
	   				timeFormat: "<?php 
    echo $time_format;
    ?>
",
	   				minTickSize: [1, "<?php 
    echo $tick_size;
    ?>
"]
   				},
   				yaxis: [
   					{ min: 0, tickSize: 1, tickDecimals: 2 },
   					{ min: 0, tickDecimals: 0 }
   				]

            });

	   		function edd_flot_tooltip(x, y, contents) {
		        $('<div id="edd-flot-tooltip">' + contents + '</div>').css( {
		            position: 'absolute',
		            display: 'none',
		            top: y + 5,
		            left: x + 5,
		            border: '1px solid #fdd',
		            padding: '2px',
		            'background-color': '#fee',
		            opacity: 0.80
		        }).appendTo("body").fadeIn(200);
		    }

		    var previousPoint = null;
		    $("#edd_monthly_stats").bind("plothover", function (event, pos, item) {
		        $("#x").text(pos.x.toFixed(2));
		        $("#y").text(pos.y.toFixed(2));
	            if (item) {
	                if (previousPoint != item.dataIndex) {
	                    previousPoint = item.dataIndex;
	                    $("#edd-flot-tooltip").remove();
	                    var x = item.datapoint[0].toFixed(2),
	                        y = item.datapoint[1].toFixed(2);
	                    if( item.series.id == 'earnings' ) {
	                    	if( edd_vars.currency_pos == 'before' ) {
								edd_flot_tooltip( item.pageX, item.pageY, item.series.label + ' ' + edd_vars.currency_sign + y );
	                    	} else {
								edd_flot_tooltip( item.pageX, item.pageY, item.series.label + ' ' + y + edd_vars.currency_sign );
	                    	}
	                    } else {
		                    edd_flot_tooltip( item.pageX, item.pageY, item.series.label + ' ' + y.replace( '.00', '' ) );
	                    }
	                }
	            } else {
	                $("#edd-flot-tooltip").remove();
	                previousPoint = null;
	            }
		    });
	   });
    </script>

	<div class="metabox-holder" style="padding-top: 0;">
		<div class="postbox">
			<h3><span><?php 
    _e('Earnings Over Time', 'edd');
    ?>
</span></h3>
			
			<div class="inside">
				<?php 
    edd_reports_graph_controls();
    ?>
				<div id="edd_monthly_stats" style="height: 300px;"></div>
				<p id="edd_graph_totals"><strong><?php 
    _e('Total earnings for period shown: ', 'edd');
    echo edd_currency_filter(edd_format_amount($totals));
    ?>
</strong></p>
			</div>
		</div>
	</div>
	<?php 
    echo ob_get_clean();
}
Пример #8
0
/**
 * Show Commissions Graph
 *
 * @access      public
 * @since       1.0
 * @return      void
*/
function edd_show_commissions_graph()
{
    // retrieve the queried dates
    $dates = edd_get_report_dates();
    // Determine graph options
    switch ($dates['range']) {
        case 'today':
            $time_format = '%d/%b';
            $tick_size = 'hour';
            $day_by_day = true;
            break;
        case 'last_year':
            $time_format = '%b';
            $tick_size = 'month';
            $day_by_day = false;
            break;
        case 'this_year':
            $time_format = '%b';
            $tick_size = 'month';
            $day_by_day = false;
            break;
        case 'last_quarter':
            $time_format = '%b';
            $tick_size = 'month';
            $day_by_day = false;
            break;
        case 'this_quarter':
            $time_format = '%b';
            $tick_size = 'month';
            $day_by_day = false;
            break;
        case 'other':
            if ($dates['m_end'] - $dates['m_start'] >= 2) {
                $time_format = '%b';
                $tick_size = 'month';
                $day_by_day = false;
            } else {
                $time_format = '%d/%b';
                $tick_size = 'day';
                $day_by_day = true;
            }
            break;
        default:
            $time_format = '%d/%b';
            // Show days by default
            $tick_size = 'day';
            // Default graph interval
            $day_by_day = true;
            break;
    }
    $time_format = apply_filters('edd_graph_timeformat', $time_format);
    $tick_size = apply_filters('edd_graph_ticksize', $tick_size);
    $user = isset($_GET['user']) ? absint($_GET['user']) : 0;
    $totals = (double) 0.0;
    // Total commissions for time period shown
    ob_start();
    ?>
	<div class="tablenav top">
		<div class="alignleft actions"><?php 
    edd_report_views();
    ?>
</div>
	</div>
	<script type="text/javascript">
	   jQuery( document ).ready( function($) {
	   		$.plot(
	   			$("#commissions_chart_div"),
	   			[{
   					data: [
	   					<?php 
    if ($dates['range'] == 'today') {
        // Hour by hour
        $hour = 1;
        $month = date('n');
        while ($hour <= 23) {
            $commissions = edd_get_commissions_by_date($dates['day'], $month, $dates['year'], $hour, $user);
            $totals += $commissions;
            $date = mktime($hour, 0, 0, $month, $dates['day'], $dates['year']);
            ?>
								[<?php 
            echo $date * 1000;
            ?>
, <?php 
            echo $commissions;
            ?>
],
								<?php 
            $hour++;
        }
    } elseif ($dates['range'] == 'this_week' || $dates['range'] == 'last_week') {
        //Day by day
        $day = $dates['day'];
        $day_end = $dates['day_end'];
        $month = $dates['m_start'];
        while ($day <= $day_end) {
            $commissions = edd_get_commissions_by_date($day, $month, $dates['year'], null, $user);
            $totals += $commissions;
            $date = mktime(0, 0, 0, $month, $day, $dates['year']);
            ?>
								[<?php 
            echo $date * 1000;
            ?>
, <?php 
            echo $commissions;
            ?>
],
								<?php 
            $day++;
        }
    } else {
        $i = $dates['m_start'];
        while ($i <= $dates['m_end']) {
            if ($day_by_day) {
                $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $dates['year']);
                $d = 1;
                while ($d <= $num_of_days) {
                    $date = mktime(0, 0, 0, $i, $d, $dates['year']);
                    $commissions = edd_get_commissions_by_date($d, $i, $dates['year'], null, $user);
                    $totals += $commissions;
                    ?>
										[<?php 
                    echo $date * 1000;
                    ?>
, <?php 
                    echo $commissions;
                    ?>
],
									<?php 
                    $d++;
                }
            } else {
                $date = mktime(0, 0, 0, $i, 1, $dates['year']);
                $commissions = edd_get_commissions_by_date(null, $i, $dates['year'], null, $user);
                $totals += $commissions;
                ?>
									[<?php 
                echo $date * 1000;
                ?>
, <?php 
                echo $commissions;
                ?>
],
								<?php 
            }
            $i++;
        }
    }
    ?>
,
	   				],
   					label: "<?php 
    _e('Commissions', 'eddc');
    ?>
",
   					id: 'commissions'
   				}],
	   		{
               	series: {
                   lines: { show: true },
                   points: { show: true }
            	},
            	grid: {
           			show: true,
					aboveData: false,
					color: '#ccc',
					backgroundColor: '#fff',
					borderWidth: 2,
					borderColor: '#ccc',
					clickable: false,
					hoverable: true
           		},
            	xaxis: {
	   				mode: "time",
	   				timeFormat: "<?php 
    echo $time_format;
    ?>
",
	   				minTickSize: [1, "<?php 
    echo $tick_size;
    ?>
"]
   				}
            });

			function edd_flot_tooltip(x, y, contents) {
		        $('<div id="edd-flot-tooltip">' + contents + '</div>').css( {
		            position: 'absolute',
		            display: 'none',
		            top: y + 5,
		            left: x + 5,
		            border: '1px solid #fdd',
		            padding: '2px',
		            'background-color': '#fee',
		            opacity: 0.80
		        }).appendTo("body").fadeIn(200);
		    }

		    var previousPoint = null;
		    $("#commissions_chart_div").bind("plothover", function (event, pos, item) {
		        $("#x").text(pos.x.toFixed(2));
		        $("#y").text(pos.y.toFixed(2));
	            if (item) {
	                if (previousPoint != item.dataIndex) {
	                    previousPoint = item.dataIndex;
	                    $("#edd-flot-tooltip").remove();
	                    var x = item.datapoint[0].toFixed(2),
	                        y = item.datapoint[1].toFixed(2);
	                    if( item.series.id == 'commissions' ) {
	                    	if( edd_vars.currency_pos == 'before' ) {
								edd_flot_tooltip( item.pageX, item.pageY, item.series.label + ' ' + edd_vars.currency_sign + y );
	                    	} else {
								edd_flot_tooltip( item.pageX, item.pageY, item.series.label + ' ' + y + edd_vars.currency_sign );
	                    	}
	                    } else {
		                    edd_flot_tooltip( item.pageX, item.pageY, item.series.label + ' ' + y.replace( '.00', '' ) );
	                    }
	                }
	            } else {
	                $("#edd-flot-tooltip").remove();
	                previousPoint = null;
	            }
		    });
	   });
    </script>
    <div class="metabox-holder" style="padding-top: 0;">
		<div class="postbox">
			<h3><span><?php 
    _e('Commissions Paid Over Time', 'edd');
    ?>
</span></h3>

			<div class="inside">
				<?php 
    if (!empty($user)) {
        $user_data = get_userdata($user);
        ?>
				<p>
					<?php 
        printf(__('Showing commissions paid to %s', 'eddc'), $user_data->display_name);
        ?>
					&nbsp;&ndash;&nbsp;<a href="<?php 
        echo esc_url(remove_query_arg('user'));
        ?>
"><?php 
        _e('clear', 'eddc');
        ?>
</a>
				</p>
				<?php 
    }
    ?>
				<?php 
    edd_reports_graph_controls();
    ?>
   				<div id="commissions_chart_div" style="height: 300px;"></div>
   			</div>
   		</div>
   	</div>
	<p id="edd_graph_totals"><strong><?php 
    _e('Total commissions for period shown: ', 'edd');
    echo edd_currency_filter(edd_format_amount($totals));
    ?>
</strong></p>
	<?php 
    echo ob_get_clean();
}