/** * Get the Export Data * * @access public * @since 1.0 * @return array $data The data for the CSV file */ public function get_data() { $start_year = isset($_POST['start_year']) ? absint($_POST['start_year']) : date('Y'); $end_year = isset($_POST['end_year']) ? absint($_POST['end_year']) : date('Y'); $start_month = isset($_POST['start_month']) ? absint($_POST['start_month']) : date('n'); $end_month = isset($_POST['end_month']) ? absint($_POST['end_month']) : date('n'); $data = array(); $year = $start_year; $stats = new Give_Payment_Stats(); while ($year <= $end_year) { if ($year == $start_year && $year == $end_year) { $m1 = $start_month; $m2 = $end_month; } elseif ($year == $start_year) { $m1 = $start_month; $m2 = 12; } elseif ($year == $end_year) { $m1 = 1; $m2 = $end_month; } else { $m1 = 1; $m2 = 12; } while ($m1 <= $m2) { $date1 = mktime(0, 0, 0, $m1, 1, $year); $date2 = mktime(0, 0, 0, $m1, cal_days_in_month(CAL_GREGORIAN, $m1, $year), $year); $data[] = array('date' => date_i18n('F Y', $date1), 'donations' => $stats->get_sales(0, $date1, $date2), 'earnings' => give_format_amount($stats->get_earnings(0, $date1, $date2))); $m1++; } $year++; } $data = apply_filters('give_export_get_data', $data); $data = apply_filters('give_export_get_data_' . $this->export_type, $data); return $data; }
/** * Test Get Sales by Date of Give Donation Form */ public function test_get_sales_by_date_of_give_form() { $stats = new Give_Payment_Stats(); $sales = $stats->get_sales($this->_new_form_id, 'this_month'); $this->assertEquals(2, $sales); }
/** * Retrieves estimated monthly earnings and sales * * @since 1.0 * @return array */ function give_estimated_monthly_stats() { $estimated = get_transient('give_estimated_monthly_stats'); if (false === $estimated) { $estimated = array('earnings' => 0, 'sales' => 0); $stats = new Give_Payment_Stats(); $to_date_earnings = $stats->get_earnings(0, 'this_month'); $to_date_sales = $stats->get_sales(0, 'this_month'); $current_day = date('d', current_time('timestamp')); $current_month = date('n', current_time('timestamp')); $current_year = date('Y', current_time('timestamp')); $days_in_month = cal_days_in_month(CAL_GREGORIAN, $current_month, $current_year); $estimated['earnings'] = $to_date_earnings / $current_day * $days_in_month; $estimated['sales'] = $to_date_sales / $current_day * $days_in_month; // Cache for one day set_transient('give_estimated_monthly_stats', $estimated, 86400); } return maybe_unserialize($estimated); }
/** * Sales Summary Dashboard Widget * * @descriptions: Builds and renders the statistics dashboard widget. This widget displays the current month's donations. * * @since 1.0 * @return void */ function give_dashboard_sales_widget() { if (!current_user_can(apply_filters('give_dashboard_stats_cap', 'view_give_reports'))) { return; } $stats = new Give_Payment_Stats(); ?> <div class="give-dashboard-widget"> <div class="give-dashboard-today give-clearfix"> <h3 class="give-dashboard-date-today"><?php echo date('F j, Y'); ?> </h3> <p class="give-dashboard-happy-day"><?php printf(__('Happy %1$s!', 'give'), date('l', current_time('timestamp'))); ?> </p> <?php $earnings_today = $stats->get_earnings(0, 'today', false); ?> <p class="give-dashboard-today-earnings"><?php echo give_currency_filter(give_format_amount($earnings_today)); ?> </p> <p class="give-orders-today"><?php $donations_today = $stats->get_sales(0, 'today', false, array('publish', 'revoked')); echo give_format_amount($donations_today, false); ?> <span><?php echo _x('donations today', 'Displays in WP admin dashboard widget after the day\'s total donations', 'give'); ?> </span> </p> </div> <table class="give-table-stats"> <thead style="display: none;"> <tr> <th><?php _e('This Week', 'give'); ?> </th> <th><?php _e('This Month', 'give'); ?> </th> <th><?php _e('Past 30 Days', 'give'); ?> </th> </tr> </thead> <tbody> <tr id="give-table-stats-tr-1"> <td> <p class="give-dashboard-stat-total"><?php echo give_currency_filter(give_format_amount($stats->get_earnings(0, 'this_week'))); ?> </p> <p class="give-dashboard-stat-total-label"><?php _e('this week', 'give'); ?> </p> </td> <td> <p class="give-dashboard-stat-total"><?php echo give_currency_filter(give_format_amount($stats->get_earnings(0, 'this_month'))); ?> </p> <p class="give-dashboard-stat-total-label"><?php _e('this month', 'give'); ?> </p> </td> </tr> <tr id="give-table-stats-tr-2"> <td> <p class="give-dashboard-stat-total"><?php echo give_currency_filter(give_format_amount($stats->get_earnings(0, 'last_month'))); ?> </p> <p class="give-dashboard-stat-total-label"><?php _e('last month', 'give'); ?> </p> </td> <td> <p class="give-dashboard-stat-total"><?php echo give_currency_filter(give_format_amount($stats->get_earnings(0, 'this_year', false))); ?> </p> <p class="give-dashboard-stat-total-label"><?php _e('this year', 'give'); ?> </p> </td> </tr> </tbody> </table> </div> <?php }
/** * Show report graphs of a specific product * * @since 1.0 * @return void */ function give_reports_graph_of_form($form_id = 0) { // Retrieve the queried dates $dates = give_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 $earnings_data = array(); $sales_data = array(); $stats = new Give_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($form_id, $date, $date_end); $sales_totals += $sales; $earnings = $stats->get_earnings($form_id, $date, $date_end); $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($form_id, $date, $date_end); $sales_totals += $sales; $earnings = $stats->get_earnings($form_id, $date, $date_end); $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($form_id, $date, $end_date); $sales_totals += $sales; $earnings = $stats->get_earnings($form_id, $date, $end_date); $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($form_id, $date, $end_date); $sales_totals += $sales; $earnings = $stats->get_earnings($form_id, $date, $end_date); $earnings_totals += $earnings; $sales_data[] = array($date * 1000, $sales); $earnings_data[] = array($date * 1000, $earnings); } $i++; } $y++; } } $data = array(__('Income', 'give') => $earnings_data, __('Donations', 'give') => $sales_data); ?> <h3><span><?php printf(__('Income Over Time for %s', 'give'), get_the_title($form_id)); ?> </span></h3> <div class="metabox-holder" style="padding-top: 0;"> <div class="postbox"> <div class="inside"> <?php $graph = new Give_Graph($data); $graph->set('x_mode', 'time'); $graph->set('multiple_y_axes', true); $graph->display(); ?> </div> </div> <!--/.postbox --> <table class="widefat reports-table alignleft" style="max-width:450px"> <tbody> <tr> <td class="row-title"> <label for="tablecell"><?php _e('Total income for period: ', 'give'); ?> </label></td> <td><?php echo give_currency_filter(give_format_amount($earnings_totals)); ?> </td> </tr> <tr class="alternate"> <td class="row-title"> <label for="tablecell"><?php _e('Total donations for period: ', 'give'); ?> </label> </td> <td><?php echo $sales_totals; ?> </td> </tr> <tr> <td class="row-title"> <label for="tablecell"><?php _e('Average monthly income: %s', 'give'); ?> </label> </td> <td><?php echo give_currency_filter(give_format_amount(give_get_average_monthly_form_earnings($form_id))); ?> </td> </tr> <tr class="alternate"> <td class="row-title"> <label for="tablecell"><?php _e('Average monthly donations: %s', 'give'); ?> </label> </td> <td><?php echo number_format(give_get_average_monthly_form_sales($form_id), 0); ?> </td> </tr> </tbody> </table> <?php give_reports_graph_controls(); ?> </div> <?php echo ob_get_clean(); }
/** * Build all the reports data * * @access public * @since 1.0 * @return array $reports_data All the data for donor reports */ public function reports_data() { $reports_data = array(); $gateways = give_get_payment_gateways(); $stats = new Give_Payment_Stats(); foreach ($gateways as $gateway_id => $gateway) { $complete_count = give_count_sales_by_gateway($gateway_id, 'publish'); $pending_count = give_count_sales_by_gateway($gateway_id, array('pending', 'failed')); $reports_data[] = array('ID' => $gateway_id, 'label' => $gateway['admin_label'], 'complete_sales' => give_format_amount($complete_count, false), 'pending_sales' => give_format_amount($pending_count, false), 'total_sales' => give_format_amount($complete_count + $pending_count, false), 'total_donations' => give_currency_filter(give_format_amount($stats->get_earnings(0, 0, 0, $gateway_id)))); } return $reports_data; }