/**
  * Get the Export Data
  *
  * @access public
  * @since 2.5
  * @global object $wpdb Used to query the database using the WordPress
  *   Database API
  * @return array $data The data for the CSV file
  */
 public function get_data()
 {
     $args = array('number' => $this->per_step, 'offset' => $this->per_step * ($this->step - 1), 'orderby' => 'id', 'order' => 'DESC');
     $customers = EDD()->customers->get_customers($args);
     if ($customers) {
         $allowed_payment_status = apply_filters('edd_recount_customer_payment_statuses', edd_get_payment_status_keys());
         foreach ($customers as $customer) {
             $attached_payment_ids = explode(',', $customer->payment_ids);
             $attached_args = array('post__in' => $attached_payment_ids, 'number' => -1, 'status' => $allowed_payment_status);
             $attached_payments = edd_get_payments($attached_args);
             $unattached_args = array('post__not_in' => $attached_payment_ids, 'number' => -1, 'status' => $allowed_payment_status, 'meta_query' => array(array('key' => '_edd_payment_user_email', 'value' => $customer->email, 'compare' => '=')));
             $unattached_payments = edd_get_payments($unattached_args);
             $payments = array_merge($attached_payments, $unattached_payments);
             $purchase_value = 0.0;
             $purchase_count = 0;
             $payment_ids = array();
             if ($payments) {
                 foreach ($payments as $payment) {
                     $should_process_payment = 'publish' == $payment->post_status || 'revoked' == $payment->post_status ? true : false;
                     $should_process_payment = apply_filters('edd_customer_recount_should_process_payment', $should_process_payment, $payment);
                     if (true === $should_process_payment) {
                         if (apply_filters('edd_customer_recount_sholud_increase_value', true, $payment)) {
                             $purchase_value += edd_get_payment_amount($payment->ID);
                         }
                         if (apply_filters('edd_customer_recount_sholud_increase_count', true, $payment)) {
                             $purchase_count++;
                         }
                     }
                     $payment_ids[] = $payment->ID;
                 }
             }
             $payment_ids = implode(',', $payment_ids);
             $customer_update_data = array('purchase_count' => $purchase_count, 'purchase_value' => $purchase_value, 'payment_ids' => $payment_ids);
             $customer_instance = new EDD_Customer($customer->id);
             $customer_instance->update($customer_update_data);
         }
         return true;
     }
     return false;
 }
 /**
  * Retrieve all the data for all the payments
  *
  * @access public
  * @since 1.4
  * @return array $payment_data Array of all the data for the payments
  */
 public function payments_data()
 {
     $per_page = $this->per_page;
     $orderby = isset($_GET['orderby']) ? urldecode($_GET['orderby']) : 'ID';
     $order = isset($_GET['order']) ? $_GET['order'] : 'DESC';
     $user = isset($_GET['user']) ? $_GET['user'] : null;
     $customer = isset($_GET['customer']) ? $_GET['customer'] : null;
     $status = isset($_GET['status']) ? $_GET['status'] : edd_get_payment_status_keys();
     $meta_key = isset($_GET['meta_key']) ? $_GET['meta_key'] : null;
     $year = isset($_GET['year']) ? $_GET['year'] : null;
     $month = isset($_GET['m']) ? $_GET['m'] : null;
     $day = isset($_GET['day']) ? $_GET['day'] : null;
     $search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : null;
     $start_date = isset($_GET['start-date']) ? sanitize_text_field($_GET['start-date']) : null;
     $end_date = isset($_GET['end-date']) ? sanitize_text_field($_GET['end-date']) : $start_date;
     if (!empty($search)) {
         $status = 'any';
         // Force all payment statuses when searching
     }
     $args = array('output' => 'payments', 'number' => $per_page, 'page' => isset($_GET['paged']) ? $_GET['paged'] : null, 'orderby' => $orderby, 'order' => $order, 'user' => $user, 'customer' => $customer, 'status' => $status, 'meta_key' => $meta_key, 'year' => $year, 'month' => $month, 'day' => $day, 's' => $search, 'start_date' => $start_date, 'end_date' => $end_date);
     if (is_string($search) && false !== strpos($search, 'txn:')) {
         $args['search_in_notes'] = true;
         $args['s'] = trim(str_replace('txn:', '', $args['s']));
     }
     $p_query = new EDD_Payments_Query($args);
     return $p_query->get_payments();
 }
 /**
  * Zero out the data on step one
  *
  * @access public
  * @since 2.5
  * @return void
  */
 public function pre_fetch()
 {
     if ($this->step === 1) {
         $allowed_payment_status = apply_filters('edd_recount_customer_payment_statuses', edd_get_payment_status_keys());
         // Before we start, let's zero out the customer's data
         $customer = new EDD_Customer($this->customer_id);
         $customer->update(array('purchase_value' => edd_format_amount(0), 'purchase_count' => 0));
         $attached_payment_ids = explode(',', $customer->payment_ids);
         $attached_args = array('post__in' => $attached_payment_ids, 'number' => -1, 'status' => $allowed_post_status);
         $attached_payments = edd_get_payments($attached_args);
         $unattached_args = array('post__not_in' => $attached_payment_ids, 'number' => -1, 'status' => $allowed_post_status, 'meta_query' => array(array('key' => '_edd_payment_user_email', 'value' => $customer->email)));
         $unattached_payments = edd_get_payments($unattached_args);
         $payments = array_merge($attached_payments, $unattached_payments);
         $this->store_data('edd_recount_customer_payments_' . $customer->id, $payments);
     }
 }
 /**
  * Default query arguments.
  *
  * Not all of these are valid arguments that can be passed to WP_Query. The ones that are not, are modified before
  * the query is run to convert them to the proper syntax.
  *
  * @access public
  * @since 1.8
  * @param $args array The array of arguments that can be passed in and used for setting up this payment query.
  */
 public function __construct($args = array())
 {
     $defaults = array('output' => 'payments', 'post_type' => array('edd_payment'), 'start_date' => false, 'end_date' => false, 'number' => 20, 'page' => null, 'orderby' => 'ID', 'order' => 'DESC', 'user' => null, 'status' => edd_get_payment_status_keys(), 'meta_key' => null, 'year' => null, 'month' => null, 'day' => null, 's' => null, 'search_in_notes' => false, 'children' => false, 'fields' => null, 'download' => null);
     $this->args = wp_parse_args($args, $defaults);
     $this->init();
 }