/** * Retrieve sale stats * * @access public * @since 1.0 * * @param $form_id INT The download product to retrieve stats for. If false, gets stats for all forms * @param $start_date string|bool The starting date for which we'd like to filter our sale stats. If false, we'll use the default start date of `this_month` * @param $end_date string|bool The end date for which we'd like to filter our sale stats. If false, we'll use the default end date of `this_month` * @param $status string|array The sale status(es) to count. Only valid when retrieving global stats * * @return float|int */ public function get_sales($form_id = 0, $start_date = false, $end_date = false, $status = 'publish') { $this->setup_dates($start_date, $end_date); // Make sure start date is valid if (is_wp_error($this->start_date)) { return $this->start_date; } // Make sure end date is valid if (is_wp_error($this->end_date)) { return $this->end_date; } if (empty($form_id)) { // Global sale stats add_filter('give_count_payments_where', array($this, 'count_where')); if (is_array($status)) { $count = 0; foreach ($status as $payment_status) { $count += give_count_payments()->{$payment_status}; } } else { $count = give_count_payments()->{$status}; } remove_filter('give_count_payments_where', array($this, 'count_where')); } else { // Product specific stats global $give_logs; add_filter('posts_where', array($this, 'payments_where')); $count = $give_logs->get_log_count($form_id, 'sale'); remove_filter('posts_where', array($this, 'payments_where')); } return $count; }
/** * Return the calculated completion percentage. * * @since 1.5 * @return int */ public function get_percentage_complete() { $status = $this->status; $args = array('start-date' => date('n/d/Y', strtotime($this->start)), 'end-date' => date('n/d/Y', strtotime($this->end))); if ('any' == $status) { $total = array_sum((array) give_count_payments($args)); } else { $total = give_count_payments($args)->{$status}; } $percentage = 100; if ($total > 0) { $percentage = 30 * $this->step / $total * 100; } if ($percentage > 100) { $percentage = 100; } return $percentage; }
/** * Retrieve the payment counts * * @access public * @since 1.0 * @return void */ public function get_payment_counts() { global $wp_query; $args = array(); if (isset($_GET['user'])) { $args['user'] = urldecode($_GET['user']); } elseif (isset($_GET['s'])) { $args['s'] = urldecode($_GET['s']); } if (!empty($_GET['start-date'])) { $args['start-date'] = urldecode($_GET['start-date']); } if (!empty($_GET['end-date'])) { $args['end-date'] = urldecode($_GET['end-date']); } $payment_count = give_count_payments($args); $this->complete_count = $payment_count->publish; $this->pending_count = $payment_count->pending; $this->refunded_count = $payment_count->refunded; $this->failed_count = $payment_count->failed; $this->revoked_count = $payment_count->revoked; $this->abandoned_count = $payment_count->abandoned; foreach ($payment_count as $count) { $this->total_count += $count; } }
/** * Retrieve the payment counts * * @access public * @since 1.0 * @return void */ public function get_payment_counts() { $args = array(); if (isset($_GET['user'])) { $args['user'] = urldecode($_GET['user']); } elseif (isset($_GET['s'])) { $is_user = strpos($_GET['s'], strtolower('user:'******'user'] = absint(trim(str_replace('user:'******'', strtolower($_GET['s'])))); unset($args['s']); } else { $args['s'] = sanitize_text_field($_GET['s']); } } if (!empty($_GET['start-date'])) { $args['start-date'] = urldecode($_GET['start-date']); } if (!empty($_GET['end-date'])) { $args['end-date'] = urldecode($_GET['end-date']); } $payment_count = give_count_payments($args); $this->complete_count = $payment_count->publish; $this->pending_count = $payment_count->pending; $this->refunded_count = $payment_count->refunded; $this->failed_count = $payment_count->failed; $this->revoked_count = $payment_count->revoked; $this->cancelled_count = $payment_count->cancelled; $this->abandoned_count = $payment_count->abandoned; foreach ($payment_count as $count) { $this->total_count += $count; } }
/** * Get Total Donations. * * @since 1.0 * * @return int $count Total sales. */ function give_get_total_sales() { $payments = give_count_payments(); return $payments->publish; }
/** * Return the calculated completion percentage * * @since 1.5 * @return int */ public function get_percentage_complete() { $total = $this->get_stored_data('give_recount_income_total'); if (false === $total) { $args = apply_filters('give_recount_income_total_args', array()); $counts = give_count_payments($args); $total = absint($counts->publish); $total = apply_filters('give_recount_store_income_total', $total); $this->store_data('give_recount_income_total', $total); } $percentage = 100; if ($total > 0) { $percentage = $this->per_step * $this->step / $total * 100; } if ($percentage > 100) { $percentage = 100; } return $percentage; }
/** * Give Preview Email Header. * * Displays a header bar with the ability to change transactions to preview actual data within the preview. Will not display if * * @since 1.6 * */ function give_get_preview_email_header() { //Payment receipt switcher $payment_count = give_count_payments()->publish; $payment_id = (int) isset($_GET['preview_id']) ? $_GET['preview_id'] : ''; if ($payment_count <= 0) { return false; } //Get payments. $payments = new Give_Payments_Query(array('number' => 100)); $payments = $payments->get_payments(); $options = array(); //Provide nice human readable options. if ($payments) { $options[0] = esc_html__('- Select a transaction -', 'give'); foreach ($payments as $payment) { $options[$payment->ID] = esc_html('#' . $payment->ID . ' - ' . $payment->email . ' - ' . $payment->form_title); } } else { $options[0] = esc_html__('No Transactions Found', 'give'); } //Start constructing HTML output. $transaction_header = '<div style="margin:0;padding:10px 0;width:100%;background-color:#FFF;border-bottom:1px solid #eee; text-align:center;">'; //Inline JS function for switching transactions. $transaction_header .= '<script> function change_preview(){ var transactions = document.getElementById("give_preview_email_payment_id"); var selected_trans = transactions.options[transactions.selectedIndex]; console.log(selected_trans); if (selected_trans){ var url_string = "' . get_bloginfo('url') . '?give_action=preview_email&preview_id=" + selected_trans.value; window.location = url_string; } } </script>'; $transaction_header .= '<label for="give_preview_email_payment_id" style="font-size:12px;color:#333;margin:0 4px 0 0;">' . esc_html__('Preview email with a transaction:', 'give') . '</label>'; //The select field with 100 latest transactions $transaction_header .= Give()->html->select(array('name' => 'preview_email_payment_id', 'selected' => $payment_id, 'id' => 'give_preview_email_payment_id', 'class' => 'give-preview-email-payment-id', 'options' => $options, 'chosen' => false, 'select_atts' => 'onchange="change_preview()">', 'show_option_all' => false, 'show_option_none' => false)); //Closing tag $transaction_header .= '</div>'; return apply_filters('give_preview_email_receipt_header', $transaction_header); }