| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly. |
| 3 |
class ESHB_Admin_View { |
| 4 |
|
| 5 |
public static function eshb_show_payment_history_in_admin( $booking_id ) { |
| 6 |
|
| 7 |
//$booking_id = get_post_meta($order_id, '_booking_post_created', true); |
| 8 |
$eshb_booking_metaboxes = get_post_meta($booking_id, 'eshb_booking_metaboxes', true); |
| 9 |
$booking_status = !empty($eshb_booking_metaboxes['booking_status']) ? $eshb_booking_metaboxes['booking_status'] : []; |
| 10 |
$total_price = !empty($eshb_booking_metaboxes['total_price']) ? $eshb_booking_metaboxes['total_price'] : 0; |
| 11 |
$total_due = !empty($eshb_booking_metaboxes['total_due']) ? $eshb_booking_metaboxes['total_due'] : 0; |
| 12 |
$payment_ids = !empty($eshb_booking_metaboxes['payment_ids']) ? $eshb_booking_metaboxes['payment_ids'] : []; |
| 13 |
|
| 14 |
$hotel_core = new ESHB_Core(); |
| 15 |
|
| 16 |
echo '<div class="eshb-payment-history"><h3>' . esc_html__( 'Payment History', 'easy-hotel' ) . '</h3>'; |
| 17 |
echo '<table class="wp-list-table"><thead><tr>'; |
| 18 |
echo '<th>' . esc_html__( 'Date', 'easy-hotel' ) . '</th>'; |
| 19 |
echo '<th>' . esc_html__( 'Gateway', 'easy-hotel' ) . '</th>'; |
| 20 |
echo '<th>' . esc_html__( 'Note', 'easy-hotel' ) . '</th>'; |
| 21 |
echo '<th>' . esc_html__( 'Amount', 'easy-hotel' ) . '</th>'; |
| 22 |
echo '</tr></thead><tbody>'; |
| 23 |
|
| 24 |
$total_paid = 0; |
| 25 |
$total_refunded = !empty($eshb_booking_metaboxes['total_refunded']) ? $eshb_booking_metaboxes['total_refunded'] : 0; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
foreach ( $payment_ids as $payment_id ) { |
| 31 |
$eshb_payment_metaboxes = get_post_meta($payment_id, 'eshb_payment_metaboxes', true); |
| 32 |
$amt = !empty( $eshb_payment_metaboxes['amount'] ) ? (float) $eshb_payment_metaboxes['amount'] : 0; |
| 33 |
$curr = !empty( $eshb_payment_metaboxes['currency'] ) ? $eshb_payment_metaboxes['currency'] : $hotel_core->get_eshb_currency_symbol(); |
| 34 |
$date = get_the_date( '', $payment_id ); |
| 35 |
$gate = !empty( $eshb_payment_metaboxes['gateway'] ) ? $eshb_payment_metaboxes['gateway'] : ''; |
| 36 |
$note = !empty( $eshb_payment_metaboxes['note'] ) ? $eshb_payment_metaboxes['note'] : ''; |
| 37 |
$total_paid += $amt; |
| 38 |
echo '<tr>'; |
| 39 |
echo '<td>' . esc_html( $date ) . '</td>'; |
| 40 |
echo '<td>' . esc_html( $gate ) . '</td>'; |
| 41 |
echo '<td>' . esc_html( $note ) . '</td>'; |
| 42 |
echo '<td>' . wp_kses_post( $hotel_core->eshb_price($amt) ) . '</td>'; |
| 43 |
echo '</tr>'; |
| 44 |
} |
| 45 |
|
| 46 |
echo '<tr>'; |
| 47 |
echo '<td colspan="3"><strong>' . esc_html__( 'Total Paid', 'easy-hotel' ) . '</strong></td>'; |
| 48 |
|
| 49 |
|
| 50 |
if(count($payment_ids) < 1 && in_array($booking_status, ['completed', 'processing'])) { |
| 51 |
$total_paid = $total_price; |
| 52 |
} |
| 53 |
|
| 54 |
if($total_refunded > 0) { |
| 55 |
$total_paid = !empty($eshb_booking_metaboxes['total_paid']) ? $eshb_booking_metaboxes['total_paid'] : 0; |
| 56 |
} |
| 57 |
|
| 58 |
echo '<td><strong>' . wp_kses_post( $hotel_core->eshb_price($total_paid) ) . '</strong></td>'; |
| 59 |
echo '</tr>'; |
| 60 |
|
| 61 |
|
| 62 |
if($total_paid < $total_price) { |
| 63 |
$total_due = $total_price - $total_paid; |
| 64 |
echo '<tr>'; |
| 65 |
echo '<td colspan="3"><strong>' . esc_html__( 'Total Due', 'easy-hotel' ) . '</strong></td>'; |
| 66 |
echo '<td><strong>' . wp_kses_post( $hotel_core->eshb_price($total_due) ) . '</strong></td>'; |
| 67 |
echo '</tr>'; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
echo '</tbody></table>'; |
| 72 |
if($booking_status !== 'cancelled' && $total_paid < $total_price){ |
| 73 |
$add_new_post_url = admin_url( 'post-new.php?post_type=eshb_payment&booking=' . $booking_id ); |
| 74 |
$add_new_post_url_with_amount = admin_url( 'post-new.php?post_type=eshb_payment&booking=' . $booking_id . '&amount=' . $total_due); |
| 75 |
echo '<br> |
| 76 |
<a href="'. esc_url( $add_new_post_url ) .'" target="_blank" class="button button-primary">' . esc_html__( 'Add payment', 'easy-hotel' ) . '</a> |
| 77 |
<a href="'. esc_url( $add_new_post_url_with_amount ) .'" target="_blank" class="button button-primary">' . esc_html__( 'Add Due payment', 'easy-hotel' ) . '</a> |
| 78 |
</div>'; |
| 79 |
} |
| 80 |
|
| 81 |
} |
| 82 |
} |