| Server IP : 65.1.209.187 / Your IP : 216.73.216.144 Web Server : nginx/1.24.0 System : Linux ip-172-31-5-206 6.14.0-1015-aws #15~24.04.1-Ubuntu SMP Tue Sep 23 22:44:48 UTC 2025 x86_64 User : ( 1001) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/ttc_wordpress/wp-content/themes/ttc/ |
Upload File : |
<?php
/*
Template Name: Payment History
*/
// Redirect if user is not logged in
if (!is_user_logged_in()) {
wp_redirect(wp_login_url(get_permalink()));
exit;
}
// Check if user has appropriate permissions
$current_user = wp_get_current_user();
$user_can_view = in_array('ttc-website-member', $current_user->roles) || current_user_can('administrator');
if (!$user_can_view) {
wp_redirect(home_url());
exit;
}
// Get the current user's ID
$user_id = get_current_user_id();
// Get the member post associated with this user
$member_id = 0;
$args = array(
'post_type' => 'member',
'posts_per_page' => 1,
'meta_query' => array(
array(
'key' => 'member_user_id',
'value' => $user_id,
'compare' => '='
)
)
);
$member_query = new WP_Query($args);
if ($member_query->have_posts()) {
$member_query->the_post();
$member_id = get_the_ID();
}
wp_reset_postdata();
// If no member post found, redirect to home
if (!$member_id) {
wp_redirect(home_url());
exit;
}
// Pagination setup
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$per_page = 5; // Number of payments per page
// Get payment history for this member with pagination
global $wpdb;
$payment_history_table = $wpdb->prefix . 'payment_history';
$payment_dues_table = $wpdb->prefix . 'payment_dues';
// Count total payments for pagination
$total_payments = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(*) FROM $payment_history_table ph
LEFT JOIN $payment_dues_table pd ON ph.payment_due_id = pd.id
WHERE ph.member_id = %d",
$member_id
)
);
// Calculate the offset for the query
$offset = ($paged - 1) * $per_page;
// Get the payments for the current page
$payment_history = $wpdb->get_results(
$wpdb->prepare(
"SELECT ph.*, pd.title, pd.original_amount
FROM $payment_history_table ph
LEFT JOIN $payment_dues_table pd ON ph.payment_due_id = pd.id
WHERE ph.member_id = %d
ORDER BY ph.payment_date DESC
LIMIT %d OFFSET %d",
$member_id,
$per_page,
$offset
)
);
// Calculate the total number of pages
$total_pages = ceil($total_payments / $per_page);
get_header();
if (have_posts()) : the_post();
?>
<div class="py-20">
<div class="container px-4 sm:px-8 lg:grid lg:grid-cols-12 lg:gap-4">
<div class="lg:col-span-3 mt-6 lg:mt-0">
<?php
// Include the member menu template part
get_template_part('parts/member-menu');
?>
</div>
<div class="lg:col-span-9">
<div class="mb-6">
<h2 class="text-2xl font-bold"><?php the_title(); ?></h2>
<p class="text-gray-600">View your payment history and download receipts.</p>
</div>
<!-- Payment History Table -->
<div class="relative p-6 bg-white">
<?php if (!empty($payment_history)): ?>
<div class="grid gap-6">
<?php foreach ($payment_history as $payment): ?>
<div class="bg-white rounded-xl border border-gray-200 shadow-sm hover:shadow-md transition-shadow duration-200">
<div class="p-6">
<div class="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-4">
<!-- Left Section -->
<div class="flex-1">
<h3 class="text-xl font-semibold text-gray-800 mb-2">
<?php echo esc_html($payment->title ? $payment->title : 'Payment #' . $payment->id); ?>
</h3>
<div class="grid grid-cols-2 lg:grid-cols-3 gap-4 text-sm">
<div class="flex flex-col">
<span class="text-gray-500">Amount Paid</span>
<span class="text-lg font-medium text-gray-800">₹<?php echo esc_html(number_format($payment->amount, 2)); ?></span>
</div>
<div class="flex flex-col">
<span class="text-gray-500">Payment Date</span>
<span class="text-lg font-medium text-gray-800"><?php echo esc_html(date('d M Y', strtotime($payment->payment_date))); ?></span>
</div>
<div class="flex flex-col">
<span class="text-gray-500">Payment Type</span>
<span class="inline-flex items-center px-2.5 py-1 text-xs font-medium bg-green-100 text-green-800">
<?php echo esc_html(ucfirst($payment->payment_type)); ?>
</span>
</div>
</div>
</div>
<!-- Right Section -->
<div class="flex flex-col lg:flex-row items-start lg:items-center gap-4">
<!-- Receipt Download -->
<div class="flex-shrink-0">
<?php if (!empty($payment->receipt_file)): ?>
<a href="<?php echo esc_url($payment->receipt_file); ?>"
target="_blank"
class="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium text-gray-700 bg-gray-50 border border-gray-300 rounded-lg hover:bg-gray-100 transition-colors duration-200"
download>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
Download Receipt
</a>
<?php else: ?>
<span class="inline-flex items-center px-4 py-2 text-sm text-gray-500 bg-gray-50 border border-gray-200 rounded-lg">
No receipt
</span>
<?php endif; ?>
</div>
<!-- Invoice Download -->
<div class="flex-shrink-0">
<?php if (!empty($payment->invoice_file)): ?>
<a href="<?php echo esc_url($payment->invoice_file); ?>"
target="_blank"
class="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium text-gray-700 bg-gray-50 border border-gray-300 rounded-lg hover:bg-gray-100 transition-colors duration-200"
download>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
Download Invoice
</a>
<?php else: ?>
<span class="inline-flex items-center px-4 py-2 text-sm text-gray-500 bg-gray-50 border border-gray-200 rounded-lg">
No invoice
</span>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<!-- Pagination -->
<?php if ($total_pages > 1): ?>
<div class="lg:col-span-12"></div>
<nav aria-label="Page navigation">
<ul class="flex items-center gap-2 h-8 text-sm justify-center my-4">
<?php if ($paged > 1) : ?>
<li>
<a href="<?php echo add_query_arg('paged', $paged - 1); ?>"
class="flex items-center justify-center px-3 h-8 ms-0 leading-tight bg-white border border-e-0 border-gray-300 rounded-s-lg hover:bg-gray-100 text-lg hover:text-gray-700 text-white dark:hover:bg-gray-700 dark:hover:text-white rounded green-bg">
<span class="sr-only">Previous</span>
<svg class="w-2.5 h-2.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 1 1 5l4 4"/>
</svg>
</a>
</li>
<?php endif; ?>
<?php
// First page
if ($paged > 1 + 1) : ?>
<li>
<a href="<?php echo add_query_arg('paged', 1); ?>"
class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 light-bg border border-gray-300 text-base font-medium hover:bg-gray-100 hover:text-gray-700 rounded">
1
</a>
</li>
<?php if ($paged > 1 + 2) : ?>
<li class="flex items-center justify-center px-3 h-8">...</li>
<?php endif;
endif;
// Pages around current
$range = 1; // How many pages to show on each side of current page
for ($i = max(1, $paged - $range); $i <= min($total_pages, $paged + $range); $i++) :
$is_current = $paged == $i;
?>
<li>
<a href="<?php echo add_query_arg('paged', $i); ?>"
class="flex items-center justify-center px-3 h-8 leading-tight <?php echo $is_current ? 'green-bg text-white' : 'text-gray-500 light-bg'; ?> border border-gray-300 text-base font-medium hover:bg-gray-100 hover:text-gray-700 rounded">
<?php echo $i; ?>
</a>
</li>
<?php endfor;
// Last page
if ($paged < $total_pages - $range) :
if ($paged < $total_pages - $range - 1) : ?>
<li class="flex items-center justify-center px-3 h-8">...</li>
<?php endif; ?>
<li>
<a href="<?php echo add_query_arg('paged', $total_pages); ?>"
class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 light-bg border border-gray-300 text-base font-medium hover:bg-gray-100 hover:text-gray-700 rounded">
<?php echo $total_pages; ?>
</a>
</li>
<?php endif; ?>
<?php if ($paged < $total_pages) : ?>
<li>
<a href="<?php echo add_query_arg('paged', $paged + 1); ?>"
class="flex items-center justify-center px-3 h-8 ms-0 leading-tight bg-white border border-e-0 border-gray-300 rounded-s-lg hover:bg-gray-100 text-lg hover:text-gray-700 text-white dark:hover:bg-gray-700 dark:hover:text-white rounded green-bg">
<span class="sr-only">Next</span>
<svg class="w-2.5 h-2.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 9 4-4-4-4"/>
</svg>
</a>
</li>
<?php endif; ?>
</ul>
</nav>
<?php endif; ?>
<?php else: ?>
<div class="text-center py-10">
<p class="text-lg text-gray-600">You don't have any payment history yet.</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php
endif;
get_footer();
?>