Beispiel #1
0
 public function output_data($data, $query_mode, $api_object)
 {
     if ('commissions' != $query_mode) {
         return $data;
     }
     $user_id = $api_object->get_user();
     $data['unpaid'] = array();
     $data['paid'] = array();
     $unpaid = eddc_get_unpaid_commissions(array('user_id' => $user_id, 'number' => 30, 'paged' => $api_object->get_paged()));
     if (!empty($unpaid)) {
         foreach ($unpaid as $commission) {
             $commission_meta = get_post_meta($commission->ID, '_edd_commission_info', true);
             $data['unpaid'][] = array('amount' => edd_sanitize_amount($commission_meta['amount']), 'rate' => $commission_meta['rate'], 'currency' => $commission_meta['currency'], 'item' => get_the_title(get_post_meta($commission->ID, '_download_id', true)), 'date' => $commission->post_date);
         }
     }
     $paid = eddc_get_paid_commissions(array('user_id' => $user_id, 'number' => 30, 'paged' => $api_object->get_paged()));
     if (!empty($paid)) {
         foreach ($paid as $commission) {
             $commission_meta = get_post_meta($commission->ID, '_edd_commission_info', true);
             $data['paid'][] = array('amount' => edd_sanitize_amount($commission_meta['amount']), 'rate' => $commission_meta['rate'], 'currency' => $commission_meta['currency'], 'item' => get_the_title(get_post_meta($commission->ID, '_download_id', true)), 'date' => $commission->post_date);
         }
     }
     $data['totals'] = array('unpaid' => eddc_get_unpaid_totals($user_id), 'paid' => eddc_get_paid_totals($user_id));
     return $data;
 }
 private function get_users()
 {
     $commissions = eddc_get_unpaid_commissions(array('number' => -1));
     if (empty($commissions)) {
         return false;
     }
     $due_amounts = array();
     foreach ($commissions as $commission) {
         $commission_meta = get_post_meta($commission->ID, '_edd_commission_info', true);
         $user_id = $commission_meta['user_id'];
         $user = get_userdata($user_id);
         $custom_paypal = get_user_meta($user_id, 'eddc_user_paypal', true);
         $email = is_email($custom_paypal) ? $custom_paypal : $user->user_email;
         $due_amounts[$user_id][] = $commission_meta['amount'];
         eddc_set_commission_status($commission->ID, 'paid');
     }
     foreach ($due_amounts as $vendor_id => $totals_due) {
         $due_amounts[$vendor_id] = array_sum($totals_due);
     }
     foreach ($due_amounts as $vendor_id => $total_due) {
         $commission_due = $total_due;
         $custom_paypal = get_user_meta($vendor_id, 'eddc_user_paypal', true);
         $user = get_userdata($vendor_id);
         $paypal_email = is_email($custom_paypal) ? $custom_paypal : $user->user_email;
         // Skip vendors that haven't filled a paypal address
         // Or that don't have an outstanding balance
         if (empty($paypal_email) || empty($commission_due)) {
             continue;
         }
         // Who knows if it exists more than once. Let's not take a risk
         // Therefore, we add the total due to perhaps a previously existing one
         $vendors = array();
         $vendors[$paypal_email] = array('user_id' => $user_id, 'total_due' => !empty($vendors[$paypal_email][$vendor_id]['total_due']) ? $vendors[$paypal_email][$vendor_id]['total_due'] + $commission_due : $commission_due);
     }
     return $vendors;
 }
Beispiel #3
0
/**
 * Commissions Summary Dashboard Widget
 *
 * @access      private
 * @since       1.6
*/
function eddc_dashboard_commissions_widget()
{
    global $user_ID;
    $unpaid_paged = isset($_GET['eddcup']) ? absint($_GET['eddcup']) : 1;
    $paid_paged = isset($_GET['eddcp']) ? absint($_GET['eddcp']) : 1;
    $unpaid_commissions = eddc_get_unpaid_commissions(array('user_id' => $user_ID, 'number' => 20, 'paged' => $unpaid_paged));
    $paid_commissions = eddc_get_paid_commissions(array('user_id' => $user_ID, 'number' => 20, 'paged' => $paid_paged));
    $total_unpaid = eddc_count_user_commissions($user_ID, 'unpaid');
    $total_paid = eddc_count_user_commissions($user_ID, 'paid');
    $unpaid_offset = 20 * ($unpaid_paged - 1);
    $unpaid_total_pages = ceil($total_unpaid / 20);
    $paid_offset = 20 * ($paid_paged - 1);
    $paid_total_pages = ceil($total_paid / 20);
    $stats = '';
    if (!empty($unpaid_commissions) || !empty($paid_commissions)) {
        // only show tables if user has commission data
        ob_start();
        ?>
			<div id="edd_user_commissions" class="edd_dashboard_widget">
				<style>#edd_user_commissions_unpaid { margin-top: 30px; }#edd_user_commissions_unpaid_total,#edd_user_commissions_paid_total { padding-bottom: 20px; } .edd_user_commissions { width: 100%; margin: 0 0 20px; }.edd_user_commissions th, .edd_user_commissions td { text-align:left; padding: 4px 4px 4px 0; }</style>
				<!-- unpaid -->
				<div id="edd_user_commissions_unpaid" class="table">
					<p class="edd_user_commissions_header sub"><?php 
        _e('Unpaid Commissions', 'eddc');
        ?>
</p>
					<table id="edd_user_unpaid_commissions_table" class="edd_user_commissions">
						<thead>
							<tr class="edd_user_commission_row">
								<th class="edd_commission_item"><?php 
        _e('Item', 'eddc');
        ?>
</th>
								<th class="edd_commission_amount"><?php 
        _e('Amount', 'eddc');
        ?>
</th>
								<th class="edd_commission_rate"><?php 
        _e('Rate', 'eddc');
        ?>
</th>
								<th class="edd_commission_date"><?php 
        _e('Date', 'eddc');
        ?>
</th>
							</tr>
						</thead>
						<tbody>
						<?php 
        $total = (double) 0;
        ?>
						<?php 
        if (!empty($unpaid_commissions)) {
            ?>
							<?php 
            foreach ($unpaid_commissions as $commission) {
                ?>
								<tr class="edd_user_commission_row">
									<?php 
                $item_name = get_the_title(get_post_meta($commission->ID, '_download_id', true));
                $commission_info = get_post_meta($commission->ID, '_edd_commission_info', true);
                $amount = $commission_info['amount'];
                $rate = $commission_info['rate'];
                $total += $amount;
                ?>
									<td class="edd_commission_item"><?php 
                echo esc_html($item_name);
                ?>
</td>
									<td class="edd_commission_amount"><?php 
                echo edd_currency_filter($amount);
                ?>
</td>
									<td class="edd_commission_rate"><?php 
                echo $rate . '%';
                ?>
</td>
									<td class="edd_commission_date"><?php 
                echo date_i18n(get_option('date_format'), strtotime($commission->post_date));
                ?>
</td>
								</tr>
							<?php 
            }
            ?>
						<?php 
        } else {
            ?>
							<tr class="edd_user_commission_row edd_row_empty">
								<td colspan="4"><?php 
            _e('No unpaid commissions', 'eddc');
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
						</tbody>
					</table>

					<div id="edd_user_commissions_unpaid_total"><?php 
        _e('Total unpaid:', 'eddc');
        ?>
&nbsp;<?php 
        echo edd_currency_filter(eddc_get_unpaid_totals($user_ID));
        ?>
</div>

					<div id="edd_commissions_unpaid_pagination" class="navigation" style="padding: 0 0 15px;">
					<?php 
        $big = 999999;
        echo paginate_links(array('base' => admin_url() . '%_%#edd_user_commissions_unpaid', 'format' => '?eddcup=%#%', 'current' => max(1, $unpaid_paged), 'total' => $unpaid_total_pages));
        ?>
					</div>

				</div><!--end #edd_user_commissions_unpaid-->

				<!-- paid -->
				<div id="edd_user_commissions_paid" class="table">
					<p class="edd_user_commissions_header sub"><?php 
        _e('Paid Commissions', 'eddc');
        ?>
</p>
					<table id="edd_user_paid_commissions_table" class="edd_user_commissions">
						<thead>
							<tr class="edd_user_commission_row">
								<th class="edd_commission_item"><?php 
        _e('Item', 'eddc');
        ?>
</th>
								<th class="edd_commission_amount"><?php 
        _e('Amount', 'eddc');
        ?>
</th>
								<th class="edd_commission_rate"><?php 
        _e('Rate', 'eddc');
        ?>
</th>
								<th class="edd_commission_date"><?php 
        _e('Date', 'eddc');
        ?>
</th>
							</tr>
						</thead>
						<tbody>
						<?php 
        $total = (double) 0;
        ?>
						<?php 
        if (!empty($paid_commissions)) {
            ?>
							<?php 
            foreach ($paid_commissions as $commission) {
                ?>
								<tr class="edd_user_commission_row">
									<?php 
                $item_name = get_the_title(get_post_meta($commission->ID, '_download_id', true));
                $commission_info = get_post_meta($commission->ID, '_edd_commission_info', true);
                $amount = $commission_info['amount'];
                $rate = $commission_info['rate'];
                $total += $amount;
                ?>
									<td class="edd_commission_item"><?php 
                echo esc_html($item_name);
                ?>
</td>
									<td class="edd_commission_amount"><?php 
                echo edd_currency_filter($amount);
                ?>
</td>
									<td class="edd_commission_rate"><?php 
                echo $rate . '%';
                ?>
</td>
									<td class="edd_commission_date"><?php 
                echo date_i18n(get_option('date_format'), strtotime($commission->post_date));
                ?>
</td>
								</tr>
							<?php 
            }
            ?>
						<?php 
        } else {
            ?>
							<tr class="edd_user_commission_row edd_row_empty">
								<td colspan="4"><?php 
            _e('No paid commissions', 'eddc');
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
						</tbody>
					</table>

					<div id="edd_user_commissions_paid_total"><?php 
        _e('Total paid:', 'eddc');
        ?>
&nbsp;<?php 
        echo edd_currency_filter(eddc_get_paid_totals($user_ID));
        ?>
</div>

					<div id="edd_commissions_paid_pagination" class="navigation" style="padding: 0 0 15px;">
					<?php 
        $big = 999999;
        echo paginate_links(array('base' => admin_url() . '%_%#edd_user_commissions_paid', 'format' => '?eddcup=%#%', 'current' => max(1, $paid_paged), 'total' => $paid_total_pages));
        ?>
					</div>

					<div id"edd_commissions_export">
						<p><strong><?php 
        _e('Export Paid Commissions', 'eddc');
        ?>
</strong></p>
						<form method="post" action="<?php 
        echo admin_url('index.php');
        ?>
">
							<?php 
        echo EDD()->html->month_dropdown();
        ?>
							<?php 
        echo EDD()->html->year_dropdown();
        ?>
							<input type="hidden" name="edd_action" value="generate_commission_export"/>
							<input type="submit" class="button-secondary" value="<?php 
        _e('Download CSV', 'eddc');
        ?>
"/>
						</form>
					</div>
				</div><!--end #edd_user_commissions_unpaid-->
			</div><!--end #edd_user_commissions-->
		<?php 
        $stats = ob_get_clean();
    }
    echo $stats;
}
 /**
  * Return the calculated completion percentage
  *
  * @since 3.2
  * @return int
  */
 public function get_percentage_complete()
 {
     $from = explode('/', $this->start);
     $to = explode('/', $this->end);
     $args = array('number' => -1, 'query_args' => array('date_query' => array('after' => array('year' => $from[2], 'month' => $from[0], 'day' => $from[1]), 'before' => array('year' => $to[2], 'month' => $to[0], 'day' => $to[1]), 'inclusive' => true)));
     $commissions = eddc_get_unpaid_commissions($args);
     $total = count($commissions);
     $percentage = 100;
     if ($total > 0) {
         $percentage = 25 * $this->step / $total * 100;
     }
     if ($percentage > 100) {
         $percentage = 100;
     }
     return $percentage;
 }
 public function get_commission_status_counts()
 {
     if (!is_null($this->term_counts)) {
         return $this->term_counts;
     }
     $term_counts = array('paid' => 0, 'unpaid' => 0, 'revoked' => 0, 'all' => 0);
     $user = $this->get_filtered_user();
     if (!empty($user)) {
         $args = array('number' => -1, 'user_id' => $this->get_filtered_user());
         $paid = eddc_get_paid_commissions($args);
         $unpaid = eddc_get_unpaid_commissions($args);
         $revoked = eddc_get_revoked_commissions($args);
         $term_counts = array('paid' => !empty($paid) ? count($paid) : 0, 'unpaid' => !empty($unpaid) ? count($unpaid) : 0, 'revoked' => !empty($revoked) ? count($revoked) : 0);
         $term_counts['all'] = $term_counts['paid'] + $term_counts['unpaid'] + $term_counts['revoked'];
     } else {
         $found_terms = get_terms('edd_commission_status');
         $total_term_count = 0;
         foreach ($found_terms as $term) {
             if (array_key_exists($term->slug, $term_counts)) {
                 $term_counts[$term->slug] = $term->count;
                 $total_term_count += $term->count;
             }
         }
         $term_counts['all'] = $total_term_count;
     }
     $this->term_counts = $term_counts;
     return $this->term_counts;
 }
function eddc_generate_payout_file($data)
{
    if (wp_verify_nonce($data['eddc-payout-nonce'], 'eddc-payout-nonce')) {
        $from = !empty($data['from']) ? sanitize_text_field($data['from']) : date('m/d/Y', strtotime('-1 month'));
        $to = !empty($data['to']) ? sanitize_text_field($data['to']) : date('m/d/Y');
        $from = explode('/', $from);
        $to = explode('/', $to);
        $args = array('number' => -1, 'query_args' => array('date_query' => array('after' => array('year' => $from[2], 'month' => $from[0], 'day' => $from[1]), 'before' => array('year' => $to[2], 'month' => $to[0], 'day' => $to[1]), 'inclusive' => true)));
        $commissions = eddc_get_unpaid_commissions($args);
        if ($commissions) {
            header('Content-Type: text/csv; charset=utf-8');
            header('Content-Disposition: attachment; filename=edd-commission-payout-' . date('m-d-Y') . '.csv');
            header("Pragma: no-cache");
            header("Expires: 0");
            $payouts = array();
            foreach ($commissions as $commission) {
                $commission_meta = get_post_meta($commission->ID, '_edd_commission_info', true);
                $user_id = $commission_meta['user_id'];
                $user = get_userdata($user_id);
                $custom_paypal = get_user_meta($user_id, 'eddc_user_paypal', true);
                $email = is_email($custom_paypal) ? $custom_paypal : $user->user_email;
                if (array_key_exists($email, $payouts)) {
                    $payouts[$email]['amount'] += $commission_meta['amount'];
                } else {
                    $payouts[$email] = array('amount' => $commission_meta['amount'], 'currency' => $commission_meta['currency']);
                }
                eddc_set_commission_status($commission->ID, 'paid');
            }
            if ($payouts) {
                foreach ($payouts as $key => $payout) {
                    echo $key . ",";
                    echo edd_sanitize_amount(number_format($payout['amount'], 2)) . ",";
                    echo $payout['currency'];
                    echo "\r\n";
                }
            }
        } else {
            wp_die(__('No commissions to be paid', 'eddc'), __('Error'));
        }
        die;
    }
}
function eddc_user_commissions()
{
    global $user_ID;
    if (!is_user_logged_in()) {
        return;
    }
    $unpaid_paged = isset($_GET['eddcup']) ? absint($_GET['eddcup']) : 1;
    $paid_paged = isset($_GET['eddcp']) ? absint($_GET['eddcp']) : 1;
    $unpaid_commissions = eddc_get_unpaid_commissions(array('user_id' => $user_ID, 'number' => 20, 'paged' => $unpaid_paged));
    $paid_commissions = eddc_get_paid_commissions(array('user_id' => $user_ID, 'number' => 20, 'paged' => $paid_paged));
    $total_unpaid = eddc_count_user_commissions($user_ID, 'unpaid');
    $total_paid = eddc_count_user_commissions($user_ID, 'paid');
    $unpaid_offset = 20 * ($unpaid_paged - 1);
    $unpaid_total_pages = ceil($total_unpaid / 20);
    $paid_offset = 20 * ($paid_paged - 1);
    $paid_total_pages = ceil($total_paid / 20);
    $stats = '';
    if (eddc_user_has_commissions()) {
        // only show tables if user has commission data
        ob_start();
        ?>
			<div id="edd_user_commissions">

				<!-- unpaid -->
				<div id="edd_user_commissions_unpaid">
					<h3 class="edd_user_commissions_header"><?php 
        _e('Unpaid Commissions', 'eddc');
        ?>
</h3>
					<table id="edd_user_unpaid_commissions_table" class="edd_user_commissions">
						<thead>
							<tr class="edd_user_commission_row">
								<?php 
        do_action('eddc_user_commissions_unpaid_head_row_begin');
        ?>
								<th class="edd_commission_item"><?php 
        _e('Item', 'eddc');
        ?>
</th>
								<th class="edd_commission_amount"><?php 
        _e('Amount', 'eddc');
        ?>
</th>
								<th class="edd_commission_rate"><?php 
        _e('Rate', 'eddc');
        ?>
</th>
								<th class="edd_commission_date"><?php 
        _e('Date', 'eddc');
        ?>
</th>
								<?php 
        do_action('eddc_user_commissions_unpaid_head_row_end');
        ?>
							</tr>
						</thead>
						<tbody>
						<?php 
        $total = (double) 0;
        ?>
						<?php 
        if (!empty($unpaid_commissions)) {
            ?>
							<?php 
            foreach ($unpaid_commissions as $commission) {
                ?>
								<tr class="edd_user_commission_row">
									<?php 
                do_action('eddc_user_commissions_unpaid_row_begin', $commission);
                $item_name = get_the_title(get_post_meta($commission->ID, '_download_id', true));
                $commission_info = get_post_meta($commission->ID, '_edd_commission_info', true);
                $amount = $commission_info['amount'];
                $rate = $commission_info['rate'];
                ?>
									<td class="edd_commission_item"><?php 
                echo esc_html($item_name);
                ?>
</td>
									<td class="edd_commission_amount"><?php 
                echo edd_currency_filter(edd_format_amount($amount));
                ?>
</td>
									<td class="edd_commission_rate"><?php 
                echo $rate . '%';
                ?>
</td>
									<td class="edd_commission_date"><?php 
                echo date_i18n(get_option('date_format'), strtotime($commission->post_date));
                ?>
</td>
									<?php 
                do_action('eddc_user_commissions_unpaid_row_end', $commission);
                ?>
								</tr>
							<?php 
            }
            ?>
						<?php 
        } else {
            ?>
							<tr class="edd_user_commission_row edd_row_empty">
								<td colspan="4"><?php 
            _e('No unpaid commissions', 'eddc');
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
						</tbody>
					</table>
					<div id="edd_user_commissions_unpaid_total"><?php 
        _e('Total unpaid:', 'eddc');
        ?>
&nbsp;<?php 
        echo edd_currency_filter(edd_format_amount(eddc_get_unpaid_totals($user_ID)));
        ?>
</div>

					<div id="edd_commissions_unpaid_pagination" class="navigation">
					<?php 
        $big = 999999;
        echo paginate_links(array('base' => remove_query_arg('eddcup', edd_get_current_page_url()) . '%_%#edd_user_commissions_unpaid', 'format' => '?eddcup=%#%', 'current' => max(1, $unpaid_paged), 'total' => $unpaid_total_pages));
        ?>
					</div>

				</div><!--end #edd_user_commissions_unpaid-->

				<!-- paid -->
				<div id="edd_user_commissions_paid">
					<h3 class="edd_user_commissions_header"><?php 
        _e('Paid Commissions', 'eddc');
        ?>
</h3>
					<table id="edd_user_paid_commissions_table" class="edd_user_commissions">
						<thead>
							<tr class="edd_user_commission_row">
								<?php 
        do_action('eddc_user_commissions_paid_head_row_begin');
        ?>
								<th class="edd_commission_item"><?php 
        _e('Item', 'eddc');
        ?>
</th>
								<th class="edd_commission_amount"><?php 
        _e('Amount', 'eddc');
        ?>
</th>
								<th class="edd_commission_rate"><?php 
        _e('Rate', 'eddc');
        ?>
</th>
								<th class="edd_commission_date"><?php 
        _e('Date', 'eddc');
        ?>
</th>
								<?php 
        do_action('eddc_user_commissions_paid_head_row_end');
        ?>
							</tr>
						</thead>
						<tbody>
						<?php 
        $total = (double) 0;
        ?>
						<?php 
        if (!empty($paid_commissions)) {
            ?>
							<?php 
            foreach ($paid_commissions as $commission) {
                ?>
								<tr class="edd_user_commission_row">
									<?php 
                do_action('eddc_user_commissions_paid_row_begin', $commission);
                $item_name = get_the_title(get_post_meta($commission->ID, '_download_id', true));
                $commission_info = get_post_meta($commission->ID, '_edd_commission_info', true);
                $amount = $commission_info['amount'];
                $rate = $commission_info['rate'];
                ?>
									<td class="edd_commission_item"><?php 
                echo esc_html($item_name);
                ?>
</td>
									<td class="edd_commission_amount"><?php 
                echo edd_currency_filter($amount);
                ?>
</td>
									<td class="edd_commission_rate"><?php 
                echo $rate . '%';
                ?>
</td>
									<td class="edd_commission_date"><?php 
                echo date_i18n(get_option('date_format'), strtotime($commission->post_date));
                ?>
</td>
									<?php 
                do_action('eddc_user_commissions_paid_row_end', $commission);
                ?>
								</tr>
							<?php 
            }
            ?>
						<?php 
        } else {
            ?>
							<tr class="edd_user_commission_row edd_row_empty">
								<td colspan="4"><?php 
            _e('No paid commissions', 'eddc');
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
						</tbody>
					</table>
					<div id="edd_user_commissions_paid_total"><?php 
        _e('Total paid:', 'eddc');
        ?>
&nbsp;<?php 
        echo edd_currency_filter(edd_format_amount(eddc_get_paid_totals($user_ID)));
        ?>
</div>

					<div id="edd_commissions_paid_pagination" class="navigation">
					<?php 
        $big = 999999;
        echo paginate_links(array('base' => remove_query_arg('eddcp', edd_get_current_page_url()) . '%_%#edd_user_commissions_paid', 'format' => '?eddcp=%#%', 'current' => max(1, $paid_paged), 'total' => $paid_total_pages));
        ?>
					</div>

					<div id="edd_commissions_export">
						<p><strong><?php 
        _e('Export Paid Commissions', 'eddc');
        ?>
</strong></p>
						<form method="post" action="<?php 
        echo home_url();
        ?>
">
							<?php 
        echo EDD()->html->month_dropdown();
        ?>
							<?php 
        echo EDD()->html->year_dropdown();
        ?>
							<input type="hidden" name="edd_action" value="generate_commission_export"/>
							<input type="submit" class="edd-submit button" value="<?php 
        _e('Download CSV', 'eddc');
        ?>
"/>
						</form><br/>
					</div>

				</div><!--end #edd_user_commissions_paid-->

			</div><!--end #edd_user_commissions-->
		<?php 
        $stats = apply_filters('edd_user_commissions_display', ob_get_clean());
    }
    return $stats;
}
/**
 * Given a user id, provide a detailed list of commissions
 *
 * @param  integer $user_id Given a user id, get their commissions details
 * @return string           HTML markup for the commissions details
 */
function eddc_user_commissions($user_id = 0)
{
    $user_id = empty($user_id) ? get_current_user_id() : $user_id;
    // If still empty, exit
    if (empty($user_id)) {
        return;
    }
    $per_page = 20;
    $unpaid_paged = isset($_GET['eddcup']) ? absint($_GET['eddcup']) : 1;
    $paid_paged = isset($_GET['eddcp']) ? absint($_GET['eddcp']) : 1;
    $revoked_paged = isset($_GET['eddcrp']) ? absint($_GET['eddcrp']) : 1;
    $unpaid_commissions = eddc_get_unpaid_commissions(array('user_id' => $user_id, 'number' => $per_page, 'paged' => $unpaid_paged));
    $paid_commissions = eddc_get_paid_commissions(array('user_id' => $user_id, 'number' => $per_page, 'paged' => $paid_paged));
    $revoked_commissions = eddc_get_revoked_commissions(array('user_id' => $user_id, 'number' => $per_page, 'paged' => $paid_paged));
    $total_unpaid = eddc_count_user_commissions($user_id, 'unpaid');
    $total_paid = eddc_count_user_commissions($user_id, 'paid');
    $total_revoked = eddc_count_user_commissions($user_id, 'revoked');
    $unpaid_offset = $per_page * ($unpaid_paged - 1);
    $unpaid_total_pages = ceil($total_unpaid / $per_page);
    $paid_offset = $per_page * ($paid_paged - 1);
    $paid_total_pages = ceil($total_paid / $per_page);
    $revoked_offset = $per_page * ($revoked_paged - 1);
    $revoked_total_pages = ceil($total_revoked / $per_page);
    $page_prefix = false !== strpos(edd_get_current_page_url(), '?') ? '&' : '?';
    $stats = '';
    if (eddc_user_has_commissions($user_id)) {
        // only show tables if user has commission data
        ob_start();
        ?>
			<div id="edd_user_commissions">

				<!-- unpaid -->
				<div id="edd_user_commissions_unpaid">
					<h3 class="edd_user_commissions_header"><?php 
        _e('Unpaid Commissions', 'eddc');
        ?>
</h3>
					<table id="edd_user_unpaid_commissions_table" class="edd_user_commissions">
						<thead>
							<tr class="edd_user_commission_row">
								<?php 
        do_action('eddc_user_commissions_unpaid_head_row_begin');
        ?>
								<th class="edd_commission_item"><?php 
        _e('Item', 'eddc');
        ?>
</th>
								<th class="edd_commission_amount"><?php 
        _e('Amount', 'eddc');
        ?>
</th>
								<th class="edd_commission_rate"><?php 
        _e('Rate', 'eddc');
        ?>
</th>
								<th class="edd_commission_date"><?php 
        _e('Date', 'eddc');
        ?>
</th>
								<?php 
        do_action('eddc_user_commissions_unpaid_head_row_end');
        ?>
							</tr>
						</thead>
						<tbody>
						<?php 
        $total = (double) 0;
        ?>
						<?php 
        if (!empty($unpaid_commissions)) {
            ?>
							<?php 
            foreach ($unpaid_commissions as $commission) {
                ?>
								<tr class="edd_user_commission_row">
									<?php 
                do_action('eddc_user_commissions_unpaid_row_begin', $commission);
                $item_name = get_the_title(get_post_meta($commission->ID, '_download_id', true));
                $commission_info = get_post_meta($commission->ID, '_edd_commission_info', true);
                $amount = $commission_info['amount'];
                $rate = $commission_info['rate'];
                ?>
									<td class="edd_commission_item"><?php 
                echo esc_html($item_name);
                ?>
</td>
									<td class="edd_commission_amount">
										<?php 
                echo edd_currency_filter(edd_format_amount(edd_sanitize_amount($amount)));
                ?>
										<?php 
                if (eddc_commission_is_renewal($commission->ID)) {
                    ?>
											&nbsp;&olarr;
										<?php 
                }
                ?>
									</td>
									<td class="edd_commission_rate"><?php 
                echo $rate . '%';
                ?>
</td>
									<td class="edd_commission_date"><?php 
                echo date_i18n(get_option('date_format'), strtotime($commission->post_date));
                ?>
</td>
									<?php 
                do_action('eddc_user_commissions_unpaid_row_end', $commission);
                ?>
								</tr>
							<?php 
            }
            ?>
						<?php 
        } else {
            ?>
							<tr class="edd_user_commission_row edd_row_empty">
								<td colspan="4"><?php 
            _e('No unpaid commissions', 'eddc');
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
						</tbody>
					</table>
					<div id="edd_user_commissions_unpaid_total"><?php 
        _e('Total unpaid:', 'eddc');
        ?>
&nbsp;<?php 
        echo edd_currency_filter(edd_format_amount(eddc_get_unpaid_totals($user_id)));
        ?>
</div>

					<div id="edd_commissions_unpaid_pagination" class="navigation">
					<?php 
        $big = 999999;
        $search_for = array($big, '#038;');
        $replace_with = array('%#%', '&');
        echo paginate_links(array('base' => remove_query_arg('eddcup', str_replace($search_for, $replace_with, edd_get_current_page_url())) . '%_%', 'format' => $page_prefix . 'eddcup=%#%', 'current' => max(1, $unpaid_paged), 'total' => $unpaid_total_pages));
        ?>
					</div>

				</div><!--end #edd_user_commissions_unpaid-->

				<!-- paid -->
				<div id="edd_user_commissions_paid">
					<h3 class="edd_user_commissions_header"><?php 
        _e('Paid Commissions', 'eddc');
        ?>
</h3>
					<table id="edd_user_paid_commissions_table" class="edd_user_commissions">
						<thead>
							<tr class="edd_user_commission_row">
								<?php 
        do_action('eddc_user_commissions_paid_head_row_begin');
        ?>
								<th class="edd_commission_item"><?php 
        _e('Item', 'eddc');
        ?>
</th>
								<th class="edd_commission_amount"><?php 
        _e('Amount', 'eddc');
        ?>
</th>
								<th class="edd_commission_rate"><?php 
        _e('Rate', 'eddc');
        ?>
</th>
								<th class="edd_commission_date"><?php 
        _e('Date', 'eddc');
        ?>
</th>
								<?php 
        do_action('eddc_user_commissions_paid_head_row_end');
        ?>
							</tr>
						</thead>
						<tbody>
						<?php 
        $total = (double) 0;
        ?>
						<?php 
        if (!empty($paid_commissions)) {
            ?>
							<?php 
            foreach ($paid_commissions as $commission) {
                ?>
								<tr class="edd_user_commission_row">
									<?php 
                do_action('eddc_user_commissions_paid_row_begin', $commission);
                $item_name = get_the_title(get_post_meta($commission->ID, '_download_id', true));
                $commission_info = get_post_meta($commission->ID, '_edd_commission_info', true);
                $amount = $commission_info['amount'];
                $rate = $commission_info['rate'];
                ?>
									<td class="edd_commission_item"><?php 
                echo esc_html($item_name);
                ?>
</td>
									<td class="edd_commission_amount">
										<?php 
                echo edd_currency_filter(edd_format_amount(edd_sanitize_amount($amount)));
                ?>
										<?php 
                if (eddc_commission_is_renewal($commission->ID)) {
                    ?>
											&nbsp;&olarr;
										<?php 
                }
                ?>
									</td>
									<td class="edd_commission_rate"><?php 
                echo $rate . '%';
                ?>
</td>
									<td class="edd_commission_date"><?php 
                echo date_i18n(get_option('date_format'), strtotime($commission->post_date));
                ?>
</td>
									<?php 
                do_action('eddc_user_commissions_paid_row_end', $commission);
                ?>
								</tr>
							<?php 
            }
            ?>
						<?php 
        } else {
            ?>
							<tr class="edd_user_commission_row edd_row_empty">
								<td colspan="4"><?php 
            _e('No paid commissions', 'eddc');
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
						</tbody>
					</table>
					<div id="edd_user_commissions_paid_total"><?php 
        _e('Total paid:', 'eddc');
        ?>
&nbsp;<?php 
        echo edd_currency_filter(edd_format_amount(eddc_get_paid_totals($user_id)));
        ?>
</div>

					<div id="edd_commissions_paid_pagination" class="navigation">
					<?php 
        $big = 999999;
        $search_for = array($big, '#038;');
        $replace_with = array('%#%', '&');
        echo paginate_links(array('base' => remove_query_arg('eddcp', str_replace($search_for, $replace_with, edd_get_current_page_url())) . '%_%', 'format' => $page_prefix . 'eddcp=%#%', 'current' => max(1, $paid_paged), 'total' => $paid_total_pages));
        ?>
					</div>

				</div><!--end #edd_user_commissions_paid-->

				<!-- revoked -->
				<div id="edd_user_commissions_revoked">
					<h3 class="edd_user_commissions_header"><?php 
        _e('Revoked Commissions', 'eddc');
        ?>
</h3>
					<table id="edd_user_revoked_commissions_table" class="edd_user_commissions">
						<thead>
							<tr class="edd_user_commission_row">
								<?php 
        do_action('eddc_user_commissions_revoked_head_row_begin');
        ?>
								<th class="edd_commission_item"><?php 
        _e('Item', 'eddc');
        ?>
</th>
								<th class="edd_commission_amount"><?php 
        _e('Amount', 'eddc');
        ?>
</th>
								<th class="edd_commission_rate"><?php 
        _e('Rate', 'eddc');
        ?>
</th>
								<th class="edd_commission_date"><?php 
        _e('Date', 'eddc');
        ?>
</th>
								<?php 
        do_action('eddc_user_commissions_revoked_head_row_end');
        ?>
							</tr>
						</thead>
						<tbody>
						<?php 
        $total = (double) 0;
        ?>
						<?php 
        if (!empty($revoked_commissions)) {
            ?>
							<?php 
            foreach ($revoked_commissions as $commission) {
                ?>
								<tr class="edd_user_commission_row">
									<?php 
                do_action('eddc_user_commissions_revoked_row_begin', $commission);
                $item_name = get_the_title(get_post_meta($commission->ID, '_download_id', true));
                $commission_info = get_post_meta($commission->ID, '_edd_commission_info', true);
                $amount = $commission_info['amount'];
                $rate = $commission_info['rate'];
                ?>
									<td class="edd_commission_item"><?php 
                echo esc_html($item_name);
                ?>
</td>
									<td class="edd_commission_amount">
										<?php 
                echo edd_currency_filter(edd_format_amount(edd_sanitize_amount($amount)));
                ?>
										<?php 
                if (eddc_commission_is_renewal($commission->ID)) {
                    ?>
											&nbsp;&olarr;
										<?php 
                }
                ?>
									</td>
									<td class="edd_commission_rate"><?php 
                echo $rate . '%';
                ?>
</td>
									<td class="edd_commission_date"><?php 
                echo date_i18n(get_option('date_format'), strtotime($commission->post_date));
                ?>
</td>
									<?php 
                do_action('eddc_user_commissions_revoked_row_end', $commission);
                ?>
								</tr>
							<?php 
            }
            ?>
						<?php 
        } else {
            ?>
							<tr class="edd_user_commission_row edd_row_empty">
								<td colspan="4"><?php 
            _e('No revoked commissions', 'eddc');
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
						</tbody>
					</table>
					<div id="edd_user_commissions_revoked_total"><?php 
        _e('Total revoked:', 'eddc');
        ?>
&nbsp;<?php 
        echo edd_currency_filter(edd_format_amount(eddc_get_revoked_totals($user_id)));
        ?>
</div>

					<div id="edd_commissions_revoked_pagination" class="navigation">
					<?php 
        $big = 999999;
        $search_for = array($big, '#038;');
        $replace_with = array('%#%', '&');
        echo paginate_links(array('base' => remove_query_arg('eddcrp', str_replace($search_for, $replace_with, edd_get_current_page_url())) . '%_%', 'format' => $page_prefix . 'eddcrp=%#%', 'current' => max(1, $revoked_paged), 'total' => $revoked_total_pages));
        ?>
					</div>

				</div><!--end #edd_user_commissions_revoked-->

				<?php 
        if (!empty($total_paid)) {
            ?>
				<div id="edd_commissions_export">
					<?php 
            $args = array('user_id' => $user_id, 'number' => 1, 'orderby' => 'date', 'order' => 'ASC');
            $first_commission = eddc_get_paid_commissions($args);
            $first_year = date('Y', strtotime($first_commission[0]->post_date));
            $years_back = date('Y', current_time('timestamp')) - $first_year;
            $url = is_admin() ? admin_url('index.php') : home_url();
            ?>
					<h3><?php 
            _e('Export Paid Commissions', 'eddc');
            ?>
</h3>
					<form method="post" action="<?php 
            echo $url;
            ?>
">
						<?php 
            echo EDD()->html->month_dropdown();
            ?>
						<?php 
            echo EDD()->html->year_dropdown('year', 0, $years_back, 0);
            ?>
						<input type="hidden" name="user_id" value="<?php 
            echo $user_id;
            ?>
"/>
						<input type="hidden" name="edd_action" value="generate_commission_export"/>
						<input type="submit" class="edd-submit button" value="<?php 
            _e('Download CSV', 'eddc');
            ?>
"/>
					</form>
				</div>
				<?php 
        }
        ?>


			</div><!--end #edd_user_commissions-->
		<?php 
        $stats = apply_filters('edd_user_commissions_display', ob_get_clean());
    }
    return $stats;
}
/**
 * Display the commissions area for the customer view
 *
 * @since  3.2
 * @param  object $customer The Customer being displayed
 * @return void
 */
function eddc_customer_commissions_view($customer)
{
    ?>
	<div class="edd-item-notes-header">
		<?php 
    echo get_avatar($customer->email, 30);
    ?>
 <span><?php 
    echo $customer->name;
    ?>
</span>
	</div>

	<div id="edd-item-stats-wrapper" class="customer-section">
		<ul>
			<li>
				<span class="dashicons dashicons-chart-area"></span>
				<?php 
    echo edd_currency_filter(edd_format_amount(eddc_get_paid_totals($customer->user_id)));
    ?>
 <?php 
    _e('Paid Commissions', 'eddc');
    ?>
				<?php 
    $paid_sales = eddc_count_user_commissions($customer->user_id, 'paid');
    ?>
				<?php 
    if (!empty($paid_sales)) {
        ?>
				<br />
				<a title="<?php 
        _e('View All Paid Commissions', 'edd');
        ?>
" href="<?php 
        echo admin_url('edit.php?post_type=download&page=edd-commissions&view=paid&user='******'via %d sale', 'via %d sales', $paid_sales, 'eddc'), $paid_sales);
        ?>
				</a>
				<?php 
    }
    ?>
			</li>
			<li>
				<span class="dashicons dashicons-chart-area"></span>
				<?php 
    echo edd_currency_filter(edd_format_amount(eddc_get_unpaid_totals($customer->user_id)));
    ?>
 <?php 
    _e('Unpaid Commissions', 'eddc');
    ?>
				<?php 
    $unpaid_sales = eddc_count_user_commissions($customer->user_id, 'unpaid');
    ?>
				<?php 
    if (!empty($unpaid_sales)) {
        ?>
				<br />
				<a title="<?php 
        _e('View All Unpaid Commissions', 'edd');
        ?>
" href="<?php 
        echo admin_url('edit.php?post_type=download&page=edd-commissions&view=unpaid&user='******'via %d sale', 'via %d sales', $unpaid_sales, 'eddc'), $unpaid_sales);
        ?>
				</a>
				<?php 
    }
    ?>
			</li>
		</ul>
	</div>

	<?php 
    $downloads = eddc_get_download_ids_of_user($customer->user_id);
    ?>
	<?php 
    if (false !== $downloads) {
        ?>
	<div id="edd-item-tables-wrapper" class="customer-section">
		<h3><?php 
        printf(__('Commissioned %s', 'eddc'), edd_get_label_plural());
        ?>
</h3>

		<table class="wp-list-table widefat striped downloads">
			<thead>
				<tr>
					<th><?php 
        echo edd_get_label_singular();
        ?>
</th>
					<th><?php 
        _e('Rate', 'eddc');
        ?>
</th>
					<th width="120px"><?php 
        _e('Actions', 'eddc');
        ?>
</th>
				</tr>
			</thead>
			<tbody>
				<?php 
        if (!empty($downloads)) {
            ?>
					<?php 
            foreach ($downloads as $download) {
                ?>
						<?php 
                $download = new EDD_Download($download);
                ?>
						<?php 
                $commission_type = eddc_get_commission_type($download->ID);
                ?>
						<?php 
                $commission_rate = eddc_get_recipient_rate($download->ID, $customer->user_id);
                ?>
						<tr>
							<td><?php 
                echo $download->post_title;
                ?>
</td>
							<td>
								<?php 
                if ($commission_type === 'percentage') {
                    ?>
									<?php 
                    echo $commission_rate;
                    ?>
%
								<?php 
                } else {
                    ?>
									<?php 
                    echo edd_currency_filter(edd_format_amount($commission_rate));
                    ?>
								<?php 
                }
                ?>

							</td>
							<td>
								<a title="<?php 
                echo esc_attr(sprintf(__('View %s', 'edd'), $download->post_title));
                ?>
" href="<?php 
                echo esc_url(admin_url('post.php?action=edit&post=' . $download->ID));
                ?>
">
									<?php 
                printf(__('View %s', 'eddc'), edd_get_label_singular());
                ?>
								</a>
							</td>
						</tr>
					<?php 
            }
            ?>
				<?php 
        } else {
            ?>
					<tr><td colspan="2"><?php 
            printf(__('No %s Found', 'eddc'), edd_get_label_plural());
            ?>
</td></tr>
				<?php 
        }
        ?>
			</tbody>
		</table>

	</div>
	<?php 
    }
    ?>

	<div id="edd-item-tables-wrapper" class="customer-section">

		<h3><?php 
    _e('Recent Unpaid Commissions', 'edd');
    ?>
</h3>
		<?php 
    $args = array('user_id' => $customer->user_id, 'number' => 10);
    $commissions = eddc_get_unpaid_commissions($args);
    ?>
		<table class="wp-list-table widefat striped payments">
			<thead>
				<tr>
					<th><?php 
    _e('ID', 'edd');
    ?>
</th>
					<th><?php 
    _e('Item', 'edd');
    ?>
</th>
					<th><?php 
    _e('Amount', 'edd');
    ?>
</th>
				</tr>
			</thead>
			<tbody>
				<?php 
    if (!empty($commissions)) {
        ?>
					<?php 
        foreach ($commissions as $commission) {
            ?>
						<?php 
            $commission_meta = get_post_meta($commission->ID, '_edd_commission_info', true);
            ?>
						<tr>
							<td><?php 
            echo $commission->ID;
            ?>
</td>
							<td><?php 
            echo get_the_title(get_post_meta($commission->ID, '_download_id', true));
            ?>
</td>
							<td><?php 
            echo edd_currency_filter(edd_sanitize_amount($commission_meta['amount']));
            ?>
</td>
						</tr>
					<?php 
        }
        ?>
				<?php 
    } else {
        ?>
					<tr><td colspan="5"><?php 
        _e('No unpaid commissions', 'edd');
        ?>
</td></tr>
				<?php 
    }
    ?>
			</tbody>
		</table>

	</div>

	<?php 
}