/** * Grabs all of the selected date info and then redirects appropriately * * @since 1.3 * * @param $data */ function edd_parse_report_dates($data) { $dates = edd_get_report_dates(); $view = edd_get_reporting_view(); $id = isset($_GET['download-id']) ? $_GET['download-id'] : null; $exclude_taxes = isset($_GET['exclude_taxes']) ? $_GET['exclude_taxes'] : null; wp_redirect(add_query_arg($dates, admin_url('edit.php?post_type=download&page=edd-reports&view=' . esc_attr($view) . '&download-id=' . absint($id) . '&exclude_taxes=' . absint($exclude_taxes)))); edd_die(); }
/** * 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); ?> – <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(); }
/** * Build all the reports data * * @access public * @since 2.4 * @return array $reports_data All the data for customer reports */ public function reports_data() { /* * Date filtering */ $dates = edd_get_report_dates(); if (!empty($dates['year'])) { $date = new DateTime(); $date->setDate($dates['year'], $dates['m_start'], $dates['day']); $start_date = $date->format('Y-m-d'); $date->setDate($dates['year_end'], $dates['m_end'], $dates['day_end']); $end_date = $date->format('Y-m-d'); $cached_report_key = 'edd_earnings_by_category_data' . $start_date . '_' . $end_date; } else { $start_date = false; $end_date = false; $cached_report_key = 'edd_earnings_by_category_data'; } $cached_reports = get_transient($cached_report_key); if (false !== $cached_reports) { $reports_data = $cached_reports; } else { $reports_data = array(); $term_args = array('parent' => 0, 'hierarchical' => 0); $categories = get_terms('download_category', $term_args); foreach ($categories as $category_id => $category) { $category_slugs = array($category->slug); $child_args = array('parent' => $category->term_id, 'hierarchical' => 0); $child_terms = get_terms('download_category', $child_args); if (!empty($child_terms)) { foreach ($child_terms as $child_term) { $category_slugs[] = $child_term->slug; } } $download_args = array('post_type' => 'download', 'posts_per_page' => -1, 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'download_category', 'field' => 'slug', 'terms' => $category_slugs))); $downloads = get_posts($download_args); $sales = 0; $earnings = 0.0; $avg_sales = 0; $avg_earnings = 0.0; $payment_stats = new EDD_Payment_Stats(); foreach ($downloads as $download) { $current_average_sales = $current_sales = $payment_stats->get_sales($download, $start_date, $end_date); $current_average_earnings = $current_earnings = $payment_stats->get_earnings($download, $start_date, $end_date); $release_date = get_post_field('post_date', $download); $diff = abs(current_time('timestamp') - strtotime($release_date)); $months = floor($diff / (30 * 60 * 60 * 24)); // Number of months since publication if ($months > 0) { $current_average_sales = $current_sales / $months; $current_average_earnings = $current_earnings / $months; } $sales += $current_sales; $earnings += $current_earnings; $avg_sales += $current_average_sales; $avg_earnings += $current_average_earnings; } $avg_sales = round($avg_sales / count($downloads)); $avg_earnings = round($avg_earnings / count($downloads), edd_currency_decimal_filter()); $reports_data[] = array('ID' => $category->term_id, 'label' => $category->name, 'total_sales' => edd_format_amount($sales, false), 'total_sales_raw' => $sales, 'total_earnings' => edd_currency_filter(edd_format_amount($earnings)), 'total_earnings_raw' => $earnings, 'avg_sales' => edd_format_amount($avg_sales, false), 'avg_earnings' => edd_currency_filter(edd_format_amount($avg_earnings)), 'is_child' => false); if (!empty($child_terms)) { foreach ($child_terms as $child_term) { $child_args = array('post_type' => 'download', 'posts_per_page' => -1, 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'download_category', 'field' => 'slug', 'terms' => $child_term->slug))); $child_downloads = get_posts($child_args); $child_sales = 0; $child_earnings = 0.0; $child_avg_sales = 0; $child_avg_earnings = 0.0; foreach ($child_downloads as $child_download) { $current_average_sales = $current_sales = $payment_stats->get_sales($child_download, $start_date, $end_date); $current_average_earnings = $current_earnings = $payment_stats->get_earnings($child_download, $start_date, $end_date); $release_date = get_post_field('post_date', $child_download); $diff = abs(current_time('timestamp') - strtotime($release_date)); $months = floor($diff / (30 * 60 * 60 * 24)); // Number of months since publication if ($months > 0) { $current_average_sales = $current_sales / $months; $current_average_earnings = $current_earnings / $months; } $child_sales += $current_sales; $child_earnings += $current_earnings; $child_avg_sales += $current_average_sales; $child_avg_earnings += $current_average_earnings; } $child_avg_sales = round($child_avg_sales / count($child_downloads)); $child_avg_earnings = round($child_avg_earnings / count($child_downloads), edd_currency_decimal_filter()); $reports_data[] = array('ID' => $child_term->term_id, 'label' => '— ' . $child_term->name, 'total_sales' => edd_format_amount($child_sales, false), 'total_sales_raw' => $child_sales, 'total_earnings' => edd_currency_filter(edd_format_amount($child_earnings)), 'total_earnings_raw' => $child_earnings, 'avg_sales' => edd_format_amount($child_avg_sales, false), 'avg_earnings' => edd_currency_filter(edd_format_amount($child_avg_earnings)), 'is_child' => true); } } } } return $reports_data; }
/** * 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(); }
/** * Grabs all of the selected date info and then redirects appropriately * * @access public * @since 1.3 * @return void */ function edd_parse_report_dates($data) { $dates = edd_get_report_dates(); $view = isset($_GET['view']) ? $_GET['view'] : 'earnings'; wp_redirect(add_query_arg($dates, admin_url('edit.php?post_type=download&page=edd-reports&view=' . $view))); exit; }
/** * 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); ?> – <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(); }