iKhokha integration completerer...
This commit is contained in:
@@ -517,7 +517,7 @@ function getUserMemberStatus($user_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Step 3: Check membership fees table for valid payment status and membership_end_date
|
// Step 3: Check membership fees table for valid payment status and membership_end_date
|
||||||
$queryFees = "SELECT payment_status, membership_end_date FROM membership_fees WHERE user_id = ?";
|
$queryFees = "SELECT payment_status, membership_end_date, renewal_period_end FROM membership_fees WHERE user_id = ?";
|
||||||
$stmtFees = $conn->prepare($queryFees);
|
$stmtFees = $conn->prepare($queryFees);
|
||||||
if (!$stmtFees) {
|
if (!$stmtFees) {
|
||||||
error_log("Failed to prepare fees query: " . $conn->error);
|
error_log("Failed to prepare fees query: " . $conn->error);
|
||||||
@@ -540,6 +540,7 @@ function getUserMemberStatus($user_id)
|
|||||||
$fees = $resultFees->fetch_assoc();
|
$fees = $resultFees->fetch_assoc();
|
||||||
$payment_status = $fees['payment_status'];
|
$payment_status = $fees['payment_status'];
|
||||||
$membership_end_date = $fees['membership_end_date'];
|
$membership_end_date = $fees['membership_end_date'];
|
||||||
|
$renewal_period_end = $fees['renewal_period_end'];
|
||||||
|
|
||||||
// Validate payment status and membership_end_date
|
// Validate payment status and membership_end_date
|
||||||
$current_date = new DateTime();
|
$current_date = new DateTime();
|
||||||
@@ -548,6 +549,12 @@ function getUserMemberStatus($user_id)
|
|||||||
if ($payment_status === "PAID" && $current_date <= $membership_end_date_obj) {
|
if ($payment_status === "PAID" && $current_date <= $membership_end_date_obj) {
|
||||||
$conn->close();
|
$conn->close();
|
||||||
return true; // Direct membership is active
|
return true; // Direct membership is active
|
||||||
|
}elseif ($payment_status === "PENDING RENEWAL") {
|
||||||
|
$renewal_period_end_obj = DateTime::createFromFormat('Y-m-d', $renewal_period_end);
|
||||||
|
if ($current_date <= $renewal_period_end_obj) {
|
||||||
|
$conn->close();
|
||||||
|
return true; // Direct membership is in renewal period
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Direct membership is not active, check if user is linked to another active membership
|
// Direct membership is not active, check if user is linked to another active membership
|
||||||
error_log("Direct membership not active for user_id: $user_id - checking linked memberships");
|
error_log("Direct membership not active for user_id: $user_id - checking linked memberships");
|
||||||
@@ -3409,3 +3416,38 @@ function getPaymentLinkByPaymentId($payment_id)
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the membership_end_date for a given user_id from membership_fees.
|
||||||
|
* Returns the date string (Y-m-d) or null if not found.
|
||||||
|
*
|
||||||
|
* @param int $user_id
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
function getMembershipEndDate($user_id)
|
||||||
|
{
|
||||||
|
$conn = openDatabaseConnection();
|
||||||
|
if ($conn === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $conn->prepare("SELECT membership_end_date FROM membership_fees WHERE user_id = ? LIMIT 1");
|
||||||
|
if (!$stmt) {
|
||||||
|
$conn->close();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt->bind_param('i', $user_id);
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt->bind_result($membership_end_date);
|
||||||
|
$found = $stmt->fetch();
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
|
||||||
|
if ($found) {
|
||||||
|
return $membership_end_date;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,8 +188,8 @@ if (empty($application['id_number'])) {
|
|||||||
|
|
||||||
<td><?php echo htmlspecialchars($membership['payment_amount']); ?></td>
|
<td><?php echo htmlspecialchars($membership['payment_amount']); ?></td>
|
||||||
<td><?php echo htmlspecialchars($membership['payment_id']); ?></td>
|
<td><?php echo htmlspecialchars($membership['payment_id']); ?></td>
|
||||||
<?php if ($membership['payment_status'] == "AWAITING PAYMENT") { ?>
|
<?php if ($membership['payment_status'] == "AWAITING PAYMENT" || $membership['payment_status'] == "PENDING RENEWAL") { ?>
|
||||||
<td><a href='<?= $payment_link; ?>' class='theme-btn style-two style-three' style='padding: 0px 14px;'><span data-hover='PAY NOW'>PAY NOW</span></a></td>
|
<td><a href='<?= $payment_link; ?>' class='theme-btn style-two style-three' style='padding: 0px 14px;'><span data-hover='PAY NOW'>PENDING RENEWAL</span></a></td>
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
<td><?php echo htmlspecialchars($membership['payment_status']); ?></td>
|
<td><?php echo htmlspecialchars($membership['payment_status']); ?></td>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
@@ -206,17 +206,27 @@ if (empty($application['id_number'])) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// Check if membership has expired
|
// Show renew button when current date is within 3 months of membership end
|
||||||
$membership_end_date = $membership ? $membership['membership_end_date'] : null;
|
$membership_end_date = $membership ? $membership['membership_end_date'] : null;
|
||||||
$today = date('Y-m-d');
|
$today = date('Y-m-d');
|
||||||
|
|
||||||
if ($membership_end_date && strtotime($today) > strtotime($membership_end_date)) {
|
if ($membership_end_date) {
|
||||||
|
try {
|
||||||
|
$end = new DateTime($membership_end_date);
|
||||||
|
$threeMonthsBefore = (clone $end)->modify('-3 months')->format('Y-m-d');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Fallback using strtotime if DateTime parsing fails
|
||||||
|
$threeMonthsBefore = date('Y-m-d', strtotime($membership_end_date . ' -3 months'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strtotime($today) >= strtotime($threeMonthsBefore)) {
|
||||||
echo '
|
echo '
|
||||||
<a href="renew_membership" class="theme-btn style-two bgc-secondary" style="width:100%; margin-top: 20px; background-color: #63ab45; padding: 10px 20px; color: white; text-decoration: none; border-radius: 25px;">
|
<a href="renew_membership" class="theme-btn style-two bgc-secondary" style="width:100%; margin-top: 20px; background-color: #63ab45; padding: 10px 20px; color: white; text-decoration: none; border-radius: 25px;">
|
||||||
<span data-hover="Renew Membership">Renew Membership</span>
|
<span data-hover="Renew Membership">Renew Membership</span>
|
||||||
<i class="fal fa-arrow-right"></i>
|
<i class="fal fa-arrow-right"></i>
|
||||||
</a>';
|
</a>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,22 +3,27 @@ $headerStyle = 'light';
|
|||||||
$rootPath = dirname(dirname(dirname(__DIR__)));
|
$rootPath = dirname(dirname(dirname(__DIR__)));
|
||||||
include_once($rootPath . '/header.php');
|
include_once($rootPath . '/header.php');
|
||||||
|
|
||||||
$user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : null;
|
$is_logged_in = isset($_SESSION['user_id']);
|
||||||
|
if (isset($_SESSION['user_id'])) {
|
||||||
|
$user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : null;
|
||||||
|
} else {
|
||||||
|
header('Location: login.php');
|
||||||
|
exit(); // Stop further script execution
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$payment_id = uniqid();
|
$payment_id = uniqid();
|
||||||
$payment_amount = getPriceByDescription('membership_fees');
|
$payment_amount = getPriceByDescription('membership_fees');
|
||||||
$payment_date = date('Y-m-d');
|
$payment_date = date('Y-m-d');
|
||||||
|
$renewal_period_end = getMembershipEndDate($user_id);
|
||||||
// Hardcode membership start date to 2026-03-01 per request
|
// Hardcode membership start date to 2026-03-01 per request
|
||||||
$membership_start_date = '2026-03-01';
|
$renewed_membership_start_date = '2026-03-01';
|
||||||
|
|
||||||
// Set membership_end_date to the last day of February in the following year
|
// Set membership_end_date to the last day of February in the following year
|
||||||
$nextYear = intval(date('Y')) + 1;
|
$renewed_membership_end_date = '2027-02-28';
|
||||||
$dt = new DateTime($nextYear . '-02-28');
|
|
||||||
$membership_end_date = $dt->format('Y-m-t');
|
|
||||||
|
|
||||||
$stmt = $conn->prepare("UPDATE membership_fees SET payment_amount = ?, payment_date = ?, membership_start_date = ?, membership_end_date = ?, payment_status = 'AWAITING PAYMENT', payment_id = ? WHERE user_id = ?");
|
$stmt = $conn->prepare("UPDATE membership_fees SET payment_amount = ?, payment_date = ?, membership_start_date = ?, membership_end_date = ?, renewal_period_end = ?, payment_status = 'PENDING RENEWAL', payment_id = ? WHERE user_id = ?");
|
||||||
$stmt->bind_param("dssssi", $payment_amount, $payment_date, $membership_start_date, $membership_end_date, $payment_id, $user_id);
|
$stmt->bind_param("dsssssi", $payment_amount, $payment_date, $renewed_membership_start_date, $renewed_membership_end_date, $renewal_period_end, $payment_id, $user_id);
|
||||||
|
|
||||||
if ($stmt->execute()) {
|
if ($stmt->execute()) {
|
||||||
// Commit the transaction
|
// Commit the transaction
|
||||||
|
|||||||
Reference in New Issue
Block a user