Exemplo n.º 1
0
/**
 * Renders the Restrict > Payments page
 *
 * @since  1.0
 * @return void
*/
function rcp_payments_page()
{
    global $rcp_options;
    $current_page = admin_url('/admin.php?page=rcp-payments');
    ?>

	<div class="wrap">

		<?php 
    if (isset($_GET['view']) && 'new-payment' == $_GET['view']) {
        include 'new-payment.php';
    } elseif (isset($_GET['view']) && 'edit-payment' == $_GET['view']) {
        include 'edit-payment.php';
    } else {
        ?>
		<h2>
			<?php 
        _e('Payments', 'rcp');
        ?>
			<a href="<?php 
        echo admin_url('/admin.php?page=rcp-payments&view=new-payment');
        ?>
" class="add-new-h2">
				<?php 
        _e('Create Payment', 'rcp');
        ?>
			</a>
		</h2>

		<?php 
        do_action('rcp_payments_page_top');
        $rcp_payments = new RCP_Payments();
        $page = isset($_GET['p']) ? $_GET['p'] : 1;
        $per_page = 20;
        $search = !empty($_GET['s']) ? urldecode($_GET['s']) : '';
        $user = get_current_user_id();
        $screen = get_current_screen();
        $screen_option = $screen->get_option('per_page', 'option');
        $per_page = get_user_meta($user, $screen_option, true);
        if (empty($per_page) || $per_page < 1) {
            $per_page = $screen->get_option('per_page', 'default');
        }
        $total_pages = 1;
        $offset = $per_page * ($page - 1);
        $user_id = isset($_GET['user_id']) ? $_GET['user_id'] : 0;
        $payments = $rcp_payments->get_payments(array('offset' => $offset, 'number' => $per_page, 'user_id' => $user_id, 's' => $search));
        $payment_count = $rcp_payments->count(array('user_id' => $user_id));
        $total_pages = ceil($payment_count / $per_page);
        ?>
		<form id="rcp-member-search" method="get" action="<?php 
        menu_page_url('rcp-payments');
        ?>
">
			<label class="screen-reader-text" for="rcp-member-search-input"><?php 
        _e('Search Payments', 'rcp');
        ?>
</label>
			<input type="search" id="rcp-member-search-input" name="s" value="<?php 
        echo esc_attr($search);
        ?>
"/>
			<input type="hidden" name="page" value="rcp-payments"/>
			<input type="submit" name="" id="rcp-member-search-submit" class="button" value="<?php 
        _e('Search Payments', 'rcp');
        ?>
"/>
		</form>
		<p class="total"><strong><?php 
        _e('Total Earnings', 'rcp');
        ?>
: <?php 
        echo rcp_currency_filter(number_format_i18n($rcp_payments->get_earnings(), 2));
        ?>
</strong></p>
		<?php 
        if (!empty($user_id)) {
            ?>
		<p><a href="<?php 
            echo admin_url('admin.php?page=rcp-payments');
            ?>
" class="button-secondary" title="<?php 
            _e('View all payments', 'rcp');
            ?>
"><?php 
            _e('Reset User Filter', 'rcp');
            ?>
</a></p>
		<?php 
        }
        ?>
		<table class="wp-list-table widefat fixed posts rcp-payments">
			<thead>
				<tr>
					<th style="width: 40px;"><?php 
        _e('ID', 'rcp');
        ?>
</th>
					<th style="width: 90px;"><?php 
        _e('User', 'rcp');
        ?>
</th>
					<th style="width: 150px;"><?php 
        _e('Subscription', 'rcp');
        ?>
</th>
					<th><?php 
        _e('Date', 'rcp');
        ?>
</th>
					<th style="width: 90px;"><?php 
        _e('Amount', 'rcp');
        ?>
</th>
					<th><?php 
        _e('Type', 'rcp');
        ?>
</th>
					<th><?php 
        _e('Transaction ID', 'rcp');
        ?>
</th>
					<th><?php 
        _e('Status', 'rcp');
        ?>
</th>
					<?php 
        do_action('rcp_payments_page_table_header');
        ?>
					<?php 
        if (current_user_can('rcp_manage_payments')) {
            ?>
						<th><?php 
            _e('Actions', 'rcp');
            ?>
</th>
					<?php 
        }
        ?>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<th style="width: 40px;"><?php 
        _e('ID', 'rcp');
        ?>
</th>
					<th><?php 
        _e('User', 'rcp');
        ?>
</th>
					<th><?php 
        _e('Subscription', 'rcp');
        ?>
</th>
					<th><?php 
        _e('Date', 'rcp');
        ?>
</th>
					<th><?php 
        _e('Amount', 'rcp');
        ?>
</th>
					<th><?php 
        _e('Type', 'rcp');
        ?>
</th>
					<th><?php 
        _e('Transaction ID', 'rcp');
        ?>
</th>
					<th><?php 
        _e('Status', 'rcp');
        ?>
</th>
					<?php 
        do_action('rcp_payments_page_table_footer');
        ?>
					<?php 
        if (current_user_can('rcp_manage_payments')) {
            ?>
						<th><?php 
            _e('Actions', 'rcp');
            ?>
</th>
					<?php 
        }
        ?>
				</tr>
			</tfoot>
			<tbody>
				<?php 
        if ($payments) {
            $i = 0;
            $total_earnings = 0;
            foreach ($payments as $payment) {
                $user = get_userdata($payment->user_id);
                ?>
							<tr class="rcp_payment <?php 
                if (rcp_is_odd($i)) {
                    echo 'alternate';
                }
                ?>
">
								<td><?php 
                echo absint($payment->id);
                ?>
</td>
								<td>
									<a href="<?php 
                echo esc_url(add_query_arg('user_id', $payment->user_id, menu_page_url('rcp-payments', false)));
                ?>
" title="<?php 
                _e('View payments by this user', 'rcp');
                ?>
">
										<?php 
                echo isset($user->display_name) ? esc_html($user->display_name) : '';
                ?>
									</a>
								</td>
								<td><?php 
                echo esc_html($payment->subscription);
                ?>
</td>
								<td><?php 
                echo esc_html($payment->date);
                ?>
</td>
								<td><?php 
                echo rcp_currency_filter($payment->amount);
                ?>
</td>
								<td><?php 
                echo esc_html($payment->payment_type);
                ?>
</td>
								<td><?php 
                echo $payment->transaction_id;
                ?>
</td>
								<td><?php 
                echo rcp_get_payment_status_label($payment);
                ?>
</td>
								<?php 
                do_action('rcp_payments_page_table_column', $payment->id);
                ?>
								<?php 
                if (current_user_can('rcp_manage_payments')) {
                    ?>
									<td>
										<a href="<?php 
                    echo rcp_get_pdf_download_url($payment->id);
                    ?>
" class="rcp-payment-invoice"><?php 
                    _e('Download Invoice', 'rcp');
                    ?>
</a>
										<span>&nbsp;|&nbsp;</span>
										<a href="<?php 
                    echo esc_url(add_query_arg(array('payment_id' => $payment->id, 'view' => 'edit-payment'), admin_url('admin.php?page=rcp-payments')));
                    ?>
" class="rcp-edit-payment"><?php 
                    _e('Edit', 'rcp');
                    ?>
</a>
										<span>&nbsp;|&nbsp;</span>
										<a href="<?php 
                    echo wp_nonce_url(add_query_arg(array('payment_id' => $payment->id, 'rcp-action' => 'delete_payment'), admin_url('admin.php?page=rcp-payments')), 'rcp_delete_payment_nonce');
                    ?>
" class="rcp-delete-payment"><?php 
                    _e('Delete', 'rcp');
                    ?>
</a>
									</td>
								<?php 
                }
                ?>
							</tr>
						<?php 
                $i++;
                $total_earnings = $total_earnings + $payment->amount;
            }
        } else {
            ?>
					<tr><td colspan="8"><?php 
            _e('No payments recorded yet', 'rcp');
            ?>
</td></tr>
				<?php 
        }
        ?>
			</table>
			<?php 
        if ($total_pages > 1) {
            ?>
				<div class="tablenav">
					<div class="tablenav-pages alignright">
						<?php 
            $base = 'admin.php?' . remove_query_arg('p', $_SERVER['QUERY_STRING']) . '%_%';
            echo paginate_links(array('base' => $base, 'format' => '&p=%#%', 'prev_text' => __('&laquo; Previous'), 'next_text' => __('Next &raquo;'), 'total' => $total_pages, 'current' => $page, 'end_size' => 1, 'mid_size' => 5));
            ?>
				    </div>
				</div><!--end .tablenav-->
			<?php 
        }
        ?>
			<?php 
        do_action('rcp_payments_page_bottom');
        ?>
		<?php 
    }
    ?>
	</div><!--end wrap-->
	<?php 
}
Exemplo n.º 2
0
/**
 * Displays the earnings graph.
 *
 * @access  public
 * @since   1.8
*/
function rcp_earnings_graph()
{
    global $rcp_options, $wpdb;
    // Retrieve the queried dates
    $dates = rcp_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('rcp_graph_timeformat', $time_format);
    $tick_size = apply_filters('rcp_graph_ticksize', $tick_size);
    $earnings = (double) 0.0;
    // Total earnings for time period shown
    $subscription = isset($_GET['subscription']) ? absint($_GET['subscription']) : false;
    $payments_db = new RCP_Payments();
    $args = array('subscription' => rcp_get_subscription_name($subscription), 'date' => array());
    ob_start();
    ?>
	<script type="text/javascript">
	   jQuery( document ).ready( function($) {
	   		$.plot(
	   			$("#rcp_earnings_graph"),
	   			[{
   					data: [
	   					<?php 
    if ($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) {
            $args = array('date' => array('day' => $day, 'month' => $month, 'year' => $dates['year']), 'fields' => 'amount');
            $args['date'] = array('day' => $day, 'month' => $month, 'year' => $dates['year']);
            $payments = $payments_db->get_earnings($args);
            $earnings += $payments;
            $date = mktime(0, 0, 0, $month, $day, $dates['year']);
            ?>
								[<?php 
            echo $date * 1000;
            ?>
, <?php 
            echo $payments;
            ?>
],
								<?php 
            $day++;
        }
    } else {
        $y = $dates['year'];
        while ($y <= $dates['year_end']) {
            if ($dates['year'] == $dates['year_end']) {
                $month_start = $dates['m_start'];
                $month_end = $dates['m_end'];
            } 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) {
                    $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y);
                    $d = 1;
                    while ($d <= $num_of_days) {
                        $args['date'] = array('day' => $d, 'month' => $i, 'year' => $y);
                        $payments = $payments_db->get_earnings($args);
                        $earnings += $payments;
                        $date = mktime(0, 0, 0, $i, $d, $y);
                        ?>
											[<?php 
                        echo $date * 1000;
                        ?>
, <?php 
                        echo $payments;
                        ?>
],
										<?php 
                        $d++;
                    }
                } else {
                    $args['date'] = array('day' => null, 'month' => $i, 'year' => $y);
                    $payments = $payments_db->get_earnings($args);
                    $earnings += $payments;
                    $date = mktime(0, 0, 0, $i, 1, $y);
                    ?>
										[<?php 
                    echo $date * 1000;
                    ?>
, <?php 
                    echo $payments;
                    ?>
],
									<?php 
                }
                $i++;
            }
            $y++;
        }
    }
    ?>
,
	   				],
	   				yaxis: 2,
   					label: "<?php 
    _e('Earnings', 'rcp');
    ?>
",
   					id: 'sales'
   				}],
	   		{
               	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;
    ?>
"]
   				},
   				yaxis: {
   					min: 0,
   					minTickSize: 1,
   					tickDecimals: 0
   				}

            });

			function rcp_flot_tooltip(x, y, contents) {
		        $('<div id="rcp-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;
		    $("#rcp_earnings_graph").bind("plothover", function (event, pos, item) {
	            if (item) {
	                if (previousPoint != item.dataIndex) {
	                    previousPoint = item.dataIndex;
	                    $("#rcp-flot-tooltip").remove();
	                    var x = item.datapoint[0].toFixed(2),
                        y = item.datapoint[1].toFixed(2);
                    	if( rcp_vars.currency_pos == 'before' ) {
							rcp_flot_tooltip( item.pageX, item.pageY, item.series.label + ' ' + rcp_vars.currency_sign + y );
                    	} else {
							rcp_flot_tooltip( item.pageX, item.pageY, item.series.label + ' ' + y + rcp_vars.currency_sign );
                    	}
	                }
	            } else {
	                $("#rcp-flot-tooltip").remove();
	                previousPoint = null;
	            }
		    });
	   });
    </script>
	<h2><?php 
    _e('Earnings Report', 'rcp');
    ?>
</h2>
	<div class="metabox-holder" style="padding-top: 0;">
		<div class="postbox">
			<div class="inside">
				<?php 
    rcp_reports_graph_controls();
    ?>
				<div id="rcp_earnings_graph" style="height: 300px;"></div>
				<p class="rcp_graph_totals"><strong><?php 
    _e('Total earnings for period shown: ', 'rcp');
    echo rcp_currency_filter(number_format_i18n($earnings, 2));
    ?>
</strong></p>
			</div>
		</div>
	</div>
	<?php 
    echo ob_get_clean();
}