billing
5 days ago
reviews
5 days ago
settings
5 days ago
withdrawal
5 days ago
billing.php
5 days ago
profile.php
5 days ago
reviews.php
5 days ago
settings.php
5 days ago
withdrawals.php
5 days ago
withdrawals.php
274 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Withdrawals Template for Account |
| 4 | * |
| 5 | * @package Tutor\Templates |
| 6 | * @subpackage Dashboard |
| 7 | * @author Themeum <support@themeum.com> |
| 8 | * @link https://themeum.com |
| 9 | * @since 4.0.0 |
| 10 | */ |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | use Tutor\Components\Badge; |
| 15 | use TUTOR\Input; |
| 16 | use Tutor\Components\Button; |
| 17 | use Tutor\Components\EmptyState; |
| 18 | use Tutor\Components\Pagination; |
| 19 | use Tutor\Components\Constants\Size; |
| 20 | use Tutor\Components\Constants\Variant; |
| 21 | use Tutor\Components\Modal; |
| 22 | use Tutor\Components\Tooltip; |
| 23 | use TUTOR\Dashboard; |
| 24 | use Tutor\Components\Constants\Color; |
| 25 | use Tutor\Components\SvgIcon; |
| 26 | use Tutor\Helpers\ComponentHelper; |
| 27 | use Tutor\Helpers\QueryHelper; |
| 28 | use TUTOR\Icon; |
| 29 | use Tutor\Models\WithdrawModel; |
| 30 | |
| 31 | $item_per_page = tutor_utils()->get_option( 'pagination_per_page', 20 ); |
| 32 | $current_page = max( 1, Input::get( 'current_page', 0, Input::TYPE_INT ) ); |
| 33 | $offset = ( $current_page - 1 ) * $item_per_page; |
| 34 | |
| 35 | $selected_filter = Input::get( 'data', '' ); |
| 36 | $order_filter = Input::get( 'order', 'DESC' ); |
| 37 | $start_date = Input::get( 'start_date' ); |
| 38 | $end_date = Input::get( 'end_date' ); |
| 39 | $user_id = get_current_user_id(); |
| 40 | |
| 41 | $filters = array( |
| 42 | 'status' => array_keys( WithdrawModel::get_withdrawal_status_list() ), |
| 43 | 'order' => QueryHelper::get_valid_sort_order( $order_filter ), |
| 44 | ); |
| 45 | |
| 46 | if ( ! empty( $selected_filter ) && 'all' !== $selected_filter ) { |
| 47 | $filters['status'] = $selected_filter; |
| 48 | } |
| 49 | |
| 50 | if ( ! empty( $start_date ) && ! empty( $end_date ) ) { |
| 51 | $filters['start_date'] = $start_date; |
| 52 | $filters['end_date'] = $end_date; |
| 53 | } |
| 54 | |
| 55 | $withdral_history = WithdrawModel::get_withdrawals_history( $user_id, $filters, $offset, $item_per_page ); |
| 56 | $min_withdraw = (float) tutor_utils()->get_option( 'min_withdraw_amount' ); |
| 57 | $formatted_min_withdraw_amount = tutor_utils()->tutor_price( $min_withdraw ); |
| 58 | |
| 59 | $saved_account = WithdrawModel::get_user_withdraw_method(); |
| 60 | $withdraw_method_name = tutor_utils()->avalue_dot( 'withdraw_method_name', $saved_account ); |
| 61 | |
| 62 | $history_count = $withdral_history->count; |
| 63 | $method_icons = WithdrawModel::get_method_icons(); |
| 64 | $status_message = array( |
| 65 | WithdrawModel::STATUS_REJECTED => __( 'Please contact the site administrator for more information.', 'tutor' ), |
| 66 | WithdrawModel::STATUS_PENDING => __( 'Withdrawal request is pending approval, please hold tight.', 'tutor' ), |
| 67 | ); |
| 68 | |
| 69 | $currency_config = tutor_utils()->get_monetization_currency_config(); |
| 70 | $currency_symbol = $currency_config['symbol'] ?? ''; |
| 71 | |
| 72 | $summary_data = WithdrawModel::get_withdraw_summary( $user_id ); |
| 73 | $available_for_withdraw = $summary_data->available_for_withdraw - $summary_data->total_pending; |
| 74 | $is_balance_sufficient = $available_for_withdraw >= $min_withdraw; |
| 75 | $available_for_withdraw_formatted = tutor_utils()->tutor_price( $available_for_withdraw ); |
| 76 | $current_balance_formated = tutor_utils()->tutor_price( $summary_data->current_balance ); |
| 77 | ?> |
| 78 | |
| 79 | <?php require_once tutor_get_template( 'account-header' ); ?> |
| 80 | |
| 81 | <div role="main" class="tutor-user-withdrawals tutor-py-9 tutor-sm-py-6" x-data="tutorWithdrawals()"> |
| 82 | <div class="tutor-account-container"> |
| 83 | <div class="tutor-card tutor-card-rounded-2xl"> |
| 84 | <div class="tutor-withdrawal-available-header tutor-flex tutor-items-center tutor-justify-between"> |
| 85 | <div class="tutor-flex tutor-flex-column tutor-gap-2"> |
| 86 | <h3 class="tutor-h3"><?php echo wp_kses( $available_for_withdraw_formatted, tutor_price_allowed_html() ); ?></h3> |
| 87 | <div class="tutor-small tutor-text-secondary"><?php esc_html_e( 'Available for Withdrawal', 'tutor' ); ?></div> |
| 88 | </div> |
| 89 | <div> |
| 90 | <?php |
| 91 | if ( $is_balance_sufficient && $withdraw_method_name ) { |
| 92 | $form_id = 'withdrawal-request-form'; |
| 93 | $modal_id = 'withdrawal-request-modal'; |
| 94 | $modal_template_path = tutor_get_template( 'dashboard.account.withdrawal.withdrawal-request-modal' ); |
| 95 | |
| 96 | Button::make() |
| 97 | ->label( __( 'Request Withdrawal', 'tutor' ) ) |
| 98 | ->attr( '@click', "TutorCore.form.reset('{$form_id}'); TutorCore.modal.showModal('{$modal_id}')" ) |
| 99 | ->variant( Variant::PRIMARY ) |
| 100 | ->size( Size::X_SMALL ) |
| 101 | ->render(); |
| 102 | |
| 103 | Modal::make() |
| 104 | ->id( $modal_id ) |
| 105 | ->title( __( 'Withdrawal Request', 'tutor' ) ) |
| 106 | ->template( |
| 107 | $modal_template_path, |
| 108 | array( |
| 109 | 'form_id' => $form_id, |
| 110 | 'modal_id' => $modal_id, |
| 111 | 'available_balance' => $available_for_withdraw, |
| 112 | 'min_withdrawal' => $min_withdraw, |
| 113 | 'withdraw_method_name' => $withdraw_method_name, |
| 114 | 'currency_symbol' => $currency_symbol, |
| 115 | ) |
| 116 | ) |
| 117 | ->render(); |
| 118 | } |
| 119 | ?> |
| 120 | </div> |
| 121 | </div> |
| 122 | |
| 123 | <div class="tutor-withdrawal-status"> |
| 124 | <div class="tutor-withdrawal-status-item"> |
| 125 | <div class="tutor-withdrawal-status-item-label"><?php esc_html_e( 'Net Income', 'tutor' ); ?></div> |
| 126 | <div class="tutor-withdrawal-status-item-value"><?php echo wp_kses( tutor_utils()->tutor_price( $summary_data->total_income ), tutor_price_allowed_html() ); ?></div> |
| 127 | </div> |
| 128 | <div class="tutor-withdrawal-status-item"> |
| 129 | <div class="tutor-withdrawal-status-item-label tutor-flex tutor-items-center tutor-gap-1"> |
| 130 | <?php esc_html_e( 'Pending Withdrawals', 'tutor' ); ?> |
| 131 | |
| 132 | </div> |
| 133 | <div class="tutor-withdrawal-status-item-value tutor-withdrawal-status-item-value--pending tutor-flex tutor-items-center tutor-gap-3"> |
| 134 | <?php echo wp_kses( tutor_utils()->tutor_price( $summary_data->total_pending ), tutor_price_allowed_html() ); ?> |
| 135 | <?php |
| 136 | Tooltip::make() |
| 137 | ->content( __( 'Total amount requested but not yet processed.', 'tutor' ) ) |
| 138 | ->placement( 'top' ) |
| 139 | ->arrow( 'center' ) |
| 140 | ->trigger_element( SvgIcon::make()->name( Icon::INFO_OCTAGON )->size( 16 )->color( Color::SECONDARY )->get() ) |
| 141 | ->render(); |
| 142 | ?> |
| 143 | </div> |
| 144 | </div> |
| 145 | <div class="tutor-withdrawal-status-item"> |
| 146 | <div class="tutor-withdrawal-status-item-label"><?php esc_html_e( 'Withdrawal Total', 'tutor' ); ?></div> |
| 147 | <div class="tutor-withdrawal-status-item-value"><?php echo wp_kses( tutor_utils()->tutor_price( $summary_data->total_withdraw ), tutor_price_allowed_html() ); ?></div> |
| 148 | </div> |
| 149 | </div> |
| 150 | </div> |
| 151 | |
| 152 | <div class="tutor-mt-4 tutor-flex tutor-items-start tutor-gap-3"> |
| 153 | <div class="tutor-flex tutor-flex-shrink-0 tutor-mt-1"> |
| 154 | <?php |
| 155 | SvgIcon::make() |
| 156 | ->name( Icon::INFO_OCTAGON ) |
| 157 | ->size( 16 ) |
| 158 | ->color( Color::SECONDARY ) |
| 159 | ->render(); |
| 160 | ?> |
| 161 | </div> |
| 162 | <div class="tutor-tiny"> |
| 163 | <?php |
| 164 | $withdrawal_pref_link = Dashboard::get_account_page_url( 'settings?tab=withdraw' ); |
| 165 | |
| 166 | $pref_link_text = sprintf( |
| 167 | /* translators: %s: Withdraw preference settings link. */ |
| 168 | __( 'You can update your %s.', 'tutor' ), |
| 169 | '<a href="' . esc_url( $withdrawal_pref_link ) . '" class="tutor-text-brand">' . esc_html__( 'Withdraw Preference', 'tutor' ) . '</a>' |
| 170 | ); |
| 171 | |
| 172 | echo wp_kses_post( |
| 173 | sprintf( |
| 174 | /* translators: 1: Preferred withdraw method, 2: Withdraw preference settings sentence with link. */ |
| 175 | __( 'The preferred payment method is selected as %1$s. %2$s', 'tutor' ), |
| 176 | esc_html( $withdraw_method_name ), |
| 177 | $pref_link_text |
| 178 | ) |
| 179 | ); |
| 180 | ?> |
| 181 | </div> |
| 182 | </div> |
| 183 | |
| 184 | <div class="tutor-withdrawal-history-heading"> |
| 185 | <?php esc_html_e( 'Withdrawal History', 'tutor' ); ?> |
| 186 | </div> |
| 187 | |
| 188 | <div class="tutor-card tutor-p-none"> |
| 189 | <?php require_once tutor_get_template( 'dashboard.account.withdrawal.withdrawal-history-filters' ); ?> |
| 190 | <div class="tutor-flex tutor-flex-column"> |
| 191 | <?php if ( tutor_utils()->count( $withdral_history->results ) > 0 ) : ?> |
| 192 | <?php |
| 193 | foreach ( $withdral_history->results as $withdrawal ) : |
| 194 | $method_data = maybe_unserialize( $withdrawal->method_data ); |
| 195 | $method_key = $method_data['withdraw_method_key'] ?? ''; |
| 196 | $method_icon = $method_icons[ $method_key ] ?? ''; |
| 197 | $method_title = ''; |
| 198 | ?> |
| 199 | <div class="tutor-billing-card"> |
| 200 | <div class="tutor-billing-card-left"> |
| 201 | <div class="tutor-flex tutor-gap-5"> |
| 202 | <div> |
| 203 | <?php |
| 204 | Badge::make() |
| 205 | ->attr( 'class', 'tutor-py-2' ) |
| 206 | ->icon( $method_icon, 20, 20 ) |
| 207 | ->label( $method_data['withdraw_method_name'] ?? '' ) |
| 208 | ->render(); |
| 209 | ?> |
| 210 | </div> |
| 211 | <div class="tutor-text-tiny tutor-text-secondary tutor-flex tutor-items-center"> |
| 212 | <?php |
| 213 | switch ( $method_key ) { |
| 214 | case WithdrawModel::METHOD_BANK_TRANSFER_WITHDRAW: |
| 215 | $method_title = tutor_utils()->asterisks_center_text( $method_data['account_number']['value'] ?? '', 4 ); |
| 216 | break; |
| 217 | case WithdrawModel::METHOD_PAYPAL_WITHDRAW: |
| 218 | $method_title = tutor_utils()->asterisks_email( $method_data['paypal_email']['value'] ?? '' ); |
| 219 | break; |
| 220 | } |
| 221 | echo esc_html( $method_title ); |
| 222 | ?> |
| 223 | </div> |
| 224 | </div> |
| 225 | <div class="tutor-text-tiny tutor-text-secondary"> |
| 226 | <?php echo esc_html( tutor_i18n_get_formated_date( $withdrawal->created_at ) ); ?> |
| 227 | </div> |
| 228 | </div> |
| 229 | |
| 230 | <div class="tutor-billing-card-right"> |
| 231 | <div class="tutor-billing-card-amount"> |
| 232 | <?php echo wp_kses( tutor_utils()->tutor_price( $withdrawal->amount ), tutor_price_allowed_html() ); ?> |
| 233 | |
| 234 | <div class="tutor-flex tutor-items-center tutor-gap-5 tutor-mt-4"> |
| 235 | <?php |
| 236 | ComponentHelper::render_status_badge( $withdrawal->status ); |
| 237 | if ( in_array( $withdrawal->status, array( WithdrawModel::STATUS_PENDING, WithdrawModel::STATUS_REJECTED ), true ) ) { |
| 238 | $tooltip_content = $status_message[ $withdrawal->status ]; |
| 239 | if ( WithdrawModel::STATUS_REJECTED === $withdrawal->status && is_array( $method_data ) && isset( $method_data['rejects'] ) ) { |
| 240 | $tooltip_content = $method_data['rejects']['reject_comment'] ? $method_data['rejects']['reject_comment'] : $method_data['rejects']['reject_type']; |
| 241 | } |
| 242 | Tooltip::make() |
| 243 | ->content( $tooltip_content ) |
| 244 | ->placement( 'top' ) |
| 245 | ->arrow( 'center' ) |
| 246 | ->trigger_element( SvgIcon::make()->name( Icon::INFO_OCTAGON )->color( Color::SECONDARY )->get() ) |
| 247 | ->render(); |
| 248 | } |
| 249 | ?> |
| 250 | </div> |
| 251 | </div> |
| 252 | </div> |
| 253 | </div> |
| 254 | <?php endforeach; ?> |
| 255 | <?php else : ?> |
| 256 | <?php |
| 257 | EmptyState::make() |
| 258 | ->title( __( 'No withdrawal records found', 'tutor' ) ) |
| 259 | ->render(); |
| 260 | ?> |
| 261 | <?php endif; ?> |
| 262 | </div> |
| 263 | </div> |
| 264 | <?php |
| 265 | Pagination::make() |
| 266 | ->current( $current_page ) |
| 267 | ->total( $history_count ) |
| 268 | ->limit( $item_per_page ) |
| 269 | ->attr( 'class', 'tutor-mt-6' ) |
| 270 | ->render(); |
| 271 | ?> |
| 272 | </div> |
| 273 | </div> |
| 274 |