Add coupon discount display to my_servers and admin_invoices pages

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-10-29 11:02:40 +00:00
parent 0a2ec94cf8
commit 54c5efe0a8
2 changed files with 42 additions and 5 deletions

View file

@ -21,10 +21,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
// Fetch all orders
$orders = mysqli_query($db, "SELECT o.*, u.user_name
// Fetch all orders with coupon information
$orders = mysqli_query($db, "SELECT o.*, u.user_name, c.code AS coupon_code, c.discount_percent AS coupon_discount
FROM ogp_billing_orders o
LEFT JOIN ogp_users u ON o.user_id = u.user_id
LEFT JOIN ogp_billing_coupons c ON o.coupon_id = c.coupon_id
ORDER BY o.order_id DESC");
function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }
@ -88,7 +89,20 @@ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }
<td><?php echo h($row['home_id'] ?? 'N/A'); ?></td>
<td><?php echo h($row['home_name']); ?></td>
<td><?php echo h($row['ip']); ?></td>
<td>$<?php echo number_format($row['price'], 2); ?></td>
<td>
<?php
$price = floatval($row['price']);
$discount = floatval($row['discount_amount'] ?? 0);
if ($discount > 0 && !empty($row['coupon_code'])) {
echo '<span style="text-decoration: line-through; color: #999;">$' . number_format($price + $discount, 2) . '</span><br>';
echo '<strong>$' . number_format($price, 2) . '</strong>';
echo '<br><small style="color: #28a745;">(' . h($row['coupon_code']) . ' -' . number_format($row['coupon_discount'], 0) . '%)</small>';
} else {
echo '$' . number_format($price, 2);
}
?>
</td>
<td><?php echo h($row['invoice_duration']); ?></td>
<td>
<span class="status-badge status-<?php echo h($row['status']); ?>">

View file

@ -43,12 +43,18 @@ $query = "SELECT
-- use end_date as the expiration marker (set when order is paid/created)
o.end_date AS expiration_date,
bs.service_name,
bs.price_monthly
bs.price_monthly,
o.price,
o.discount_amount,
o.coupon_id,
bc.code AS coupon_code,
bc.discount_percent AS coupon_discount_percent
FROM ogp_home h
LEFT JOIN ogp_remote_servers rs ON h.remote_server_id = rs.remote_server_id
LEFT JOIN ogp_game_configs gc ON h.home_cfg_id = gc.home_cfg_id
LEFT JOIN ogp_billing_orders o ON h.user_id = o.user_id
LEFT JOIN ogp_billing_services bs ON o.service_id = bs.service_id
LEFT JOIN ogp_billing_coupons bc ON o.coupon_id = bc.coupon_id
WHERE h.user_id = $user_id
ORDER BY h.home_id DESC";
@ -91,7 +97,24 @@ $result = mysqli_query($db, $query);
<td><?php echo htmlspecialchars($server['remote_server_name'] ?? 'Unknown'); ?></td>
<td class="<?php echo $status_class; ?>"><?php echo $status_text; ?></td>
<td><?php echo $server['expiration_date'] ? date('M d, Y', strtotime($server['expiration_date'])) : 'N/A'; ?></td>
<td><?php echo $server['price_monthly'] ? '$' . number_format($server['price_monthly'], 2) : 'N/A'; ?></td>
<td>
<?php
$price = $server['price'] ?? $server['price_monthly'];
$discount = floatval($server['discount_amount'] ?? 0);
if ($price) {
if ($discount > 0 && $server['coupon_code']) {
echo '<span style="text-decoration: line-through; color: #999;">$' . number_format($price + $discount, 2) . '</span><br>';
echo '<strong>$' . number_format($price, 2) . '</strong>';
echo '<br><small style="color: #28a745;">(' . htmlspecialchars($server['coupon_code']) . ' -' . number_format($server['coupon_discount_percent'], 0) . '%)</small>';
} else {
echo '$' . number_format($price, 2);
}
} else {
echo 'N/A';
}
?>
</td>
<td>
<?php if ($server['order_id']): ?>
<a href="renew_server.php?order_id=<?php echo urlencode($server['order_id']); ?>" class="gsw-btn">Renew</a>