chart-body.php
6 years ago
earning-report-top-menu.php
6 years ago
report-date_range.php
6 years ago
report-last_month.php
6 years ago
report-last_week.php
6 years ago
report-last_year.php
6 years ago
report-this_month.php
6 years ago
report-this_week.php
6 years ago
report-this_year.php
6 years ago
report.php
6 years ago
statement.php
6 years ago
statements.php
6 years ago
report-date_range.php
122 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Template for displaying instructors earnings |
| 4 | * |
| 5 | * @since v.1.1.2 |
| 6 | * |
| 7 | * @author Themeum |
| 8 | * @url https://themeum.com |
| 9 | * |
| 10 | * @package TutorLMS/Templates |
| 11 | * @version 1.4.3 |
| 12 | */ |
| 13 | |
| 14 | global $wpdb; |
| 15 | |
| 16 | $user_id = get_current_user_id(); |
| 17 | |
| 18 | /** |
| 19 | * Getting the This Week |
| 20 | */ |
| 21 | |
| 22 | $start_date = sanitize_text_field(tutor_utils()->avalue_dot('date_range_from', $_GET)); |
| 23 | $end_date = sanitize_text_field(tutor_utils()->avalue_dot('date_range_to', $_GET)); |
| 24 | |
| 25 | $earning_sum = tutor_utils()->get_earning_sum($user_id, compact('start_date', 'end_date')); |
| 26 | if ( ! $earning_sum){ |
| 27 | echo '<p>'.__('No Earning info available', 'tutor' ).'</p>'; |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | $complete_status = tutor_utils()->get_earnings_completed_statuses(); |
| 32 | $statuses = $complete_status; |
| 33 | $complete_status = "'".implode("','", $complete_status)."'"; |
| 34 | |
| 35 | /** |
| 36 | * Format Date Name |
| 37 | */ |
| 38 | $begin = new DateTime($start_date); |
| 39 | $end = new DateTime($end_date.' + 1 day'); |
| 40 | $interval = DateInterval::createFromDateString('1 day'); |
| 41 | $period = new DatePeriod($begin, $interval, $end); |
| 42 | |
| 43 | $datesPeriod = array(); |
| 44 | foreach ($period as $dt) { |
| 45 | $datesPeriod[$dt->format("Y-m-d")] = 0; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Query This Month |
| 50 | */ |
| 51 | |
| 52 | $salesQuery = $wpdb->get_results( " |
| 53 | SELECT SUM(instructor_amount) as total_earning, |
| 54 | DATE(created_at) as date_format |
| 55 | from {$wpdb->prefix}tutor_earnings |
| 56 | WHERE user_id = {$user_id} AND order_status IN({$complete_status}) |
| 57 | AND (created_at BETWEEN '{$start_date}' AND '{$end_date}') |
| 58 | GROUP BY date_format |
| 59 | ORDER BY created_at ASC ;"); |
| 60 | |
| 61 | $total_earning = wp_list_pluck($salesQuery, 'total_earning'); |
| 62 | $queried_date = wp_list_pluck($salesQuery, 'date_format'); |
| 63 | $dateWiseSales = array_combine($queried_date, $total_earning); |
| 64 | |
| 65 | $chartData = array_merge($datesPeriod, $dateWiseSales); |
| 66 | foreach ($chartData as $key => $salesCount){ |
| 67 | unset($chartData[$key]); |
| 68 | $formatDate = date('d M', strtotime($key)); |
| 69 | $chartData[$formatDate] = $salesCount; |
| 70 | } |
| 71 | |
| 72 | $statements = tutor_utils()->get_earning_statements($user_id, compact('start_date', 'end_date', 'statuses')); |
| 73 | |
| 74 | ?> |
| 75 | |
| 76 | <div class="tutor-dashboard-info-cards"> |
| 77 | <div class="tutor-dashboard-info-card" title="<?php _e('All time', 'tutor'); ?>"> |
| 78 | <p> |
| 79 | <span> <?php _e('My Earning', 'tutor'); ?> </span> |
| 80 | <span class="tutor-dashboard-info-val"><?php echo tutor_utils()->tutor_price($earning_sum->instructor_amount); ?></span> |
| 81 | </p> |
| 82 | </div> |
| 83 | <div class="tutor-dashboard-info-card" title="<?php _e('Based on course price', 'tutor'); ?>"> |
| 84 | <p> |
| 85 | <span> <?php _e('All time sales', 'tutor'); ?> </span> |
| 86 | <span class="tutor-dashboard-info-val"><?php echo tutor_utils()->tutor_price($earning_sum->course_price_total); ?></span> |
| 87 | </p> |
| 88 | </div> |
| 89 | <div class="tutor-dashboard-info-card"> |
| 90 | <p> |
| 91 | <span> <?php _e('Deducted Commissions', 'tutor'); ?> </span> |
| 92 | <span class="tutor-dashboard-info-val"><?php echo tutor_utils()->tutor_price($earning_sum->admin_amount); ?></span> |
| 93 | </p> |
| 94 | </div> |
| 95 | |
| 96 | |
| 97 | <?php if ($earning_sum->deduct_fees_amount > 0){ ?> |
| 98 | <div class="tutor-dashboard-info-card" title="<?php _e('Deducted Fees', 'tutor'); ?>"> |
| 99 | <p> |
| 100 | <span> <?php _e('Deducted Fees', 'tutor'); ?> </span> |
| 101 | <span class="tutor-dashboard-info-val"><?php echo tutor_utils()->tutor_price($earning_sum->deduct_fees_amount); ?></span> |
| 102 | </p> |
| 103 | </div> |
| 104 | <?php } ?> |
| 105 | </div> |
| 106 | |
| 107 | |
| 108 | <div class="tutor-dashboard-item-group"> |
| 109 | <h4><?php echo sprintf(__("Showing Result from %s to %s", 'tutor'), $begin->format('d F, Y'), $end->format('d F, Y')); ?></h4> |
| 110 | <?php |
| 111 | tutor_load_template('dashboard.earning.chart-body', compact('chartData', 'statements')); |
| 112 | ?> |
| 113 | </div> |
| 114 | |
| 115 | <div class="tutor-dashboard-item-group"> |
| 116 | <h4><?php _e('Sales statements for this period', 'tutor') ?></h4> |
| 117 | <?php tutor_load_template('dashboard.earning.statement', compact('chartData', 'statements')); ?> |
| 118 | </div> |
| 119 | |
| 120 | |
| 121 | |
| 122 |