📁 File Manager
Editing:
/home/wvl7mof7402e/www/domain/domain-charges.php
<?php declare(strict_types=1); session_start(); require_once 'db.php'; /* |-------------------------------------------------------------------------- | CAPAPP - DOMAIN CHARGES |-------------------------------------------------------------------------- | File: domain-charges.php | Database: db.php | | Existing table: | domain_charges | | Expected fields: | id | domain_id | charge_type | total_amount | paid_amount | payment_status |-------------------------------------------------------------------------- */ /* ========================================================= LOGIN CHECK ========================================================= */ if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit; } /* ========================================================= HELPER ========================================================= */ function e($value): string { return htmlspecialchars( (string)$value, ENT_QUOTES, 'UTF-8' ); } /* ========================================================= BASIC DB CHECK ========================================================= */ if (!isset($conn) || !($conn instanceof mysqli)) { die("Database connection failed."); } /* ========================================================= DOMAIN ID ========================================================= */ $domain_id = 0; if (isset($_POST['domain_id'])) { $domain_id = (int)$_POST['domain_id']; } elseif (isset($_GET['domain_id'])) { $domain_id = (int)$_GET['domain_id']; } /* ========================================================= PAGINATION ========================================================= */ $limit = 10; $page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1; $start = ($page - 1) * $limit; /* ========================================================= FORM VALUES ========================================================= */ $charge_type = $_POST['charge_type'] ?? 'Design'; $total_amount = $_POST['total_amount'] ?? ''; $paid_amount = $_POST['paid_amount'] ?? ''; $errorMessage = ''; $successMessage = ''; /* ========================================================= SAVE CHARGE ========================================================= */ if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save']) ) { $domain_id = (int)($_POST['domain_id'] ?? 0); $charge_type = trim( (string)($_POST['charge_type'] ?? '') ); $total_amount = (float)( $_POST['total_amount'] ?? 0 ); $paid_amount = (float)( $_POST['paid_amount'] ?? 0 ); /* VALIDATE */ if ($domain_id <= 0) { $errorMessage = "Please select a domain."; } elseif ($charge_type === '') { $errorMessage = "Please select charge type."; } elseif ($total_amount <= 0) { $errorMessage = "Total amount must be greater than 0."; } elseif ($paid_amount < 0) { $errorMessage = "Paid amount cannot be negative."; } elseif ($paid_amount > $total_amount) { $errorMessage = "Paid amount cannot be greater than total amount."; } else { /* CHECK DOMAIN */ $checkDomain = mysqli_prepare( $conn, "SELECT id FROM domains WHERE id = ? LIMIT 1" ); if (!$checkDomain) { $errorMessage = "Database error while checking domain."; } else { mysqli_stmt_bind_param( $checkDomain, "i", $domain_id ); mysqli_stmt_execute( $checkDomain ); mysqli_stmt_store_result( $checkDomain ); $domainExists = mysqli_stmt_num_rows( $checkDomain ) > 0; mysqli_stmt_close( $checkDomain ); if (!$domainExists) { $errorMessage = "Selected domain does not exist."; } else { /* PAYMENT STATUS */ if ($paid_amount >= $total_amount) { $status = 'Paid'; } elseif ($paid_amount > 0) { $status = 'Partial'; } else { $status = 'Partial'; } /* INSERT */ $stmt = mysqli_prepare( $conn, "INSERT INTO domain_charges ( domain_id, charge_type, total_amount, paid_amount, payment_status ) VALUES (?, ?, ?, ?, ?)" ); if (!$stmt) { $errorMessage = "Unable to prepare charge query."; } else { mysqli_stmt_bind_param( $stmt, "isdds", $domain_id, $charge_type, $total_amount, $paid_amount, $status ); if ( mysqli_stmt_execute($stmt) ) { mysqli_stmt_close($stmt); header( "Location: domain-charges.php?domain_id=" . $domain_id . "&saved=1" ); exit; } else { $errorMessage = "Charge could not be saved: " . mysqli_stmt_error($stmt); mysqli_stmt_close($stmt); } } } } } } /* ========================================================= SUCCESS MESSAGE ========================================================= */ if ( isset($_GET['saved']) && $_GET['saved'] === '1' ) { $successMessage = "Domain charge added successfully."; } /* ========================================================= DOMAIN LIST ========================================================= */ $domains = mysqli_query( $conn, "SELECT id, domain_name FROM domains ORDER BY domain_name ASC" ); if (!$domains) { die( "Unable to load domains: " . e(mysqli_error($conn)) ); } /* ========================================================= SELECTED DOMAIN NAME ========================================================= */ $domainName = ''; if ($domain_id > 0) { $stmt = mysqli_prepare( $conn, "SELECT domain_name FROM domains WHERE id = ? LIMIT 1" ); if ($stmt) { mysqli_stmt_bind_param( $stmt, "i", $domain_id ); mysqli_stmt_execute($stmt); mysqli_stmt_bind_result( $stmt, $selectedDomainName ); if (mysqli_stmt_fetch($stmt)) { $domainName = $selectedDomainName; } mysqli_stmt_close($stmt); } } /* ========================================================= SUMMARY ========================================================= */ $totalAmt = 0; $totalPaid = 0; $pending = 0; if ($domain_id > 0) { $summaryStmt = mysqli_prepare( $conn, "SELECT COALESCE(SUM(total_amount), 0), COALESCE(SUM(paid_amount), 0) FROM domain_charges WHERE domain_id = ?" ); if ($summaryStmt) { mysqli_stmt_bind_param( $summaryStmt, "i", $domain_id ); mysqli_stmt_execute( $summaryStmt ); mysqli_stmt_bind_result( $summaryStmt, $totalAmt, $totalPaid ); mysqli_stmt_fetch( $summaryStmt ); mysqli_stmt_close( $summaryStmt ); } } $totalAmt = (float)$totalAmt; $totalPaid = (float)$totalPaid; $pending = max( 0, $totalAmt - $totalPaid ); /* ========================================================= TOTAL RECORDS ========================================================= */ $count = 0; if ($domain_id > 0) { $countStmt = mysqli_prepare( $conn, "SELECT COUNT(*) FROM domain_charges WHERE domain_id = ?" ); if ($countStmt) { mysqli_stmt_bind_param( $countStmt, "i", $domain_id ); mysqli_stmt_execute( $countStmt ); mysqli_stmt_bind_result( $countStmt, $count ); mysqli_stmt_fetch( $countStmt ); mysqli_stmt_close( $countStmt ); } } $count = (int)$count; $totalPages = max( 1, (int)ceil($count / $limit) ); if ($page > $totalPages) { $page = $totalPages; $start = ($page - 1) * $limit; } /* ========================================================= CHARGE DATA ========================================================= */ $charges = []; if ($domain_id > 0) { $dataStmt = mysqli_prepare( $conn, "SELECT dc.id, dc.charge_type, dc.total_amount, dc.paid_amount, dc.payment_status, d.domain_name FROM domain_charges dc INNER JOIN domains d ON d.id = dc.domain_id WHERE dc.domain_id = ? ORDER BY dc.id DESC LIMIT ?, ?" ); if ($dataStmt) { mysqli_stmt_bind_param( $dataStmt, "iii", $domain_id, $start, $limit ); mysqli_stmt_execute( $dataStmt ); mysqli_stmt_bind_result( $dataStmt, $chargeId, $chargeTypeDb, $totalDb, $paidDb, $statusDb, $domainNameDb ); while ( mysqli_stmt_fetch($dataStmt) ) { $charges[] = [ 'id' => $chargeId, 'charge_type' => $chargeTypeDb, 'total_amount' => $totalDb, 'paid_amount' => $paidDb, 'payment_status' => $statusDb, 'domain_name' => $domainNameDb ]; } mysqli_stmt_close($dataStmt); } } /* ========================================================= ADMIN NAME ========================================================= */ $adminName = $_SESSION['user_name'] ?? 'Admin'; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0" > <title> CAPAPP | Domain Charges </title> <!-- Bootstrap --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" > <!-- Bootstrap Icons --> <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet" > <style> /* ========================================================= ROOT ========================================================= */ :root{ --primary:#2563eb; --primary-dark:#1d4ed8; --sidebar:#0f172a; --sidebar2:#172554; --bg:#f1f5f9; --text:#0f172a; --muted:#64748b; --success:#16a34a; --warning:#f59e0b; --danger:#dc2626; --white:#fff; --shadow: 0 15px 40px rgba(15,23,42,.07); } /* ========================================================= GLOBAL ========================================================= */ *{ margin:0; padding:0; box-sizing:border-box; } html{ scroll-behavior:smooth; } body{ background: linear-gradient( 135deg, #eef4ff, #f8fafc ); color:var(--text); font-family: "Segoe UI", Arial, sans-serif; min-height:100vh; } /* ========================================================= SIDEBAR ========================================================= */ .sidebar{ width:270px; position:fixed; left:0; top:0; bottom:0; padding:22px 16px; background: linear-gradient( 180deg, #0f172a, #172554 ); z-index:1000; overflow-y:auto; box-shadow: 10px 0 35px rgba(15,23,42,.12); transition:.3s ease; } /* LOGO */ .logo-box{ text-align:center; padding: 8px 10px 25px; } .logo-icon{ width:58px; height:58px; margin:auto; display:flex; align-items:center; justify-content:center; border-radius:18px; background: linear-gradient( 135deg, #2563eb, #7c3aed ); color:#fff; font-size:28px; box-shadow: 0 12px 30px rgba(37,99,235,.35); } .logo-box h2{ color:#fff; font-size:26px; font-weight:900; margin-top:12px; } .logo-box p{ color:#94a3b8; font-size:12px; } /* MENU */ .menu-title{ color:#64748b; font-size:10px; font-weight:800; letter-spacing:1.2px; text-transform:uppercase; padding: 13px 13px 7px; } .menu a{ display:flex; align-items:center; gap:13px; padding:13px 14px; margin-bottom:6px; border-radius:13px; color:#cbd5e1; text-decoration:none; font-size:14px; font-weight:600; transition:.25s; position:relative; } .menu a i{ width:23px; text-align:center; font-size:19px; } .menu a:hover{ color:#fff; background: rgba(37,99,235,.28); transform: translateX(4px); } .menu a.active{ color:#fff; background: linear-gradient( 135deg, #2563eb, #1d4ed8 ); box-shadow: 0 8px 20px rgba(37,99,235,.25); } .menu a.active::before{ content:""; position:absolute; left:0; top:50%; transform: translateY(-50%); width:4px; height:24px; background:#fff; border-radius: 0 5px 5px 0; } /* ========================================================= MAIN ========================================================= */ .main{ margin-left:270px; padding:25px; min-height:100vh; } /* ========================================================= TOPBAR ========================================================= */ .topbar{ background: rgba(255,255,255,.94); border: 1px solid #e2e8f0; border-radius:20px; padding:16px 20px; display:flex; justify-content:space-between; align-items:center; gap:15px; box-shadow:var(--shadow); margin-bottom:25px; } .title-area{ display:flex; align-items:center; gap:13px; } .mobile-toggle{ display:none; width:42px; height:42px; align-items:center; justify-content:center; border-radius:12px; background:#eff6ff; color:var(--primary); font-size:23px; cursor:pointer; } .topbar h3{ margin:0; font-size:21px; font-weight:850; } .topbar-sub{ color:var(--muted); font-size:11px; margin-top:3px; } .admin-box{ display:flex; align-items:center; gap:10px; } .admin-icon{ width:44px; height:44px; display:flex; align-items:center; justify-content:center; border-radius:14px; background: linear-gradient( 135deg, #2563eb, #7c3aed ); color:#fff; font-size:19px; } .admin-name{ font-size:13px; font-weight:800; } .admin-role{ font-size:10px; color:var(--muted); } /* ========================================================= SUMMARY ========================================================= */ .summary-card{ background:#fff; border-radius:19px; padding:20px; position:relative; overflow:hidden; box-shadow:var(--shadow); border: 1px solid #e5e7eb; transition:.25s; } .summary-card:hover{ transform: translateY(-4px); } .summary-icon{ width:45px; height:45px; border-radius:13px; display:flex; align-items:center; justify-content:center; font-size:20px; margin-bottom:14px; } .summary-label{ font-size:12px; color:var(--muted); font-weight:600; } .summary-value{ font-size:27px; font-weight:900; margin-top:2px; } .summary-total .summary-icon{ background:#dbeafe; color:#2563eb; } .summary-paid .summary-icon{ background:#dcfce7; color:#16a34a; } .summary-pending .summary-icon{ background:#fee2e2; color:#dc2626; } /* ========================================================= MAIN CARDS ========================================================= */ .panel{ background:#fff; border-radius:20px; padding:22px; margin-top:22px; border: 1px solid #e5e7eb; box-shadow:var(--shadow); } .panel-header{ display:flex; justify-content:space-between; align-items:center; gap:15px; margin-bottom:20px; } .panel-title{ display:flex; align-items:center; gap:12px; } .panel-title-icon{ width:44px; height:44px; border-radius:13px; display:flex; align-items:center; justify-content:center; background:#eff6ff; color:#2563eb; font-size:20px; } .panel-title h4{ margin:0; font-size:18px; font-weight:850; } .panel-title p{ margin:3px 0 0; font-size:11px; color:var(--muted); } /* ========================================================= FORM ========================================================= */ .form-label{ font-size:12px; font-weight:750; color:#334155; margin-bottom:7px; } .form-control, .form-select{ min-height:46px; border: 1px solid #dbe3ee; border-radius:12px; font-size:13px; box-shadow:none !important; } .form-control:focus, .form-select:focus{ border-color:#60a5fa; box-shadow: 0 0 0 4px rgba(37,99,235,.08) !important; } .input-icon{ position:relative; } .input-icon i{ position:absolute; left:14px; top:50%; transform: translateY(-50%); color:#64748b; z-index:2; } .input-icon input{ padding-left:42px; } /* ADD BUTTON */ .add-btn{ min-height:46px; border:0; border-radius:12px; width:100%; background: linear-gradient( 135deg, #2563eb, #1d4ed8 ); color:#fff; font-size:13px; font-weight:750; box-shadow: 0 8px 20px rgba(37,99,235,.20); transition:.2s; } .add-btn:hover{ transform: translateY(-2px); box-shadow: 0 12px 25px rgba(37,99,235,.30); color:#fff; } /* ========================================================= LIVE BALANCE ========================================================= */ .live-balance{ display:flex; align-items:center; justify-content:space-between; gap:10px; padding:12px 15px; margin-top:15px; background:#f8fafc; border: 1px solid #e2e8f0; border-radius:13px; } .live-balance span{ color:#64748b; font-size:12px; } .live-balance strong{ color:#dc2626; font-size:16px; } /* ========================================================= TABLE ========================================================= */ .table-wrap{ overflow-x:auto; } .modern-table{ width:100%; min-width:700px; border-collapse:separate; border-spacing:0; } .modern-table thead th{ background:#f8fafc; color:#64748b; font-size:11px; font-weight:800; text-transform:uppercase; letter-spacing:.4px; padding:14px; border-bottom: 1px solid #e5e7eb; } .modern-table tbody td{ padding:15px 14px; border-bottom: 1px solid #eef2f7; font-size:13px; color:#334155; } .modern-table tbody tr{ transition:.2s; } .modern-table tbody tr:hover{ background:#f8fbff; } .charge-type{ display:flex; align-items:center; gap:10px; font-weight:750; } .charge-icon{ width:35px; height:35px; display:flex; align-items:center; justify-content:center; border-radius:10px; background:#eff6ff; color:#2563eb; } .amount{ font-weight:750; } .balance{ font-weight:850; color:#dc2626; } /* STATUS */ .status-badge{ display:inline-flex; align-items:center; gap:5px; padding:6px 10px; border-radius:30px; font-size:10px; font-weight:800; } .status-paid{ color:#166534; background:#dcfce7; } .status-partial{ color:#92400e; background:#fef3c7; } /* ========================================================= EMPTY ========================================================= */ .empty-state{ padding:55px 20px; text-align:center; background:#f8fafc; border-radius:17px; border: 1px dashed #cbd5e1; } .empty-icon{ width:65px; height:65px; margin:auto; display:flex; align-items:center; justify-content:center; border-radius:18px; background:#eff6ff; color:#2563eb; font-size:28px; } .empty-state h5{ margin-top:15px; font-weight:850; } .empty-state p{ color:#64748b; font-size:12px; } /* ========================================================= PAGINATION ========================================================= */ .pagination-wrap{ display:flex; align-items:center; justify-content:space-between; gap:10px; margin-top:20px; flex-wrap:wrap; } .page-info{ font-size:11px; color:#64748b; } .pagination{ margin:0; gap:5px; } .page-link{ border:0; min-width:36px; height:36px; display:flex; align-items:center; justify-content:center; border-radius:10px !important; font-size:12px; color:#475569; background:#f1f5f9; } .page-link:hover{ color:#fff; background:#2563eb; } .page-item.active .page-link{ color:#fff; background:#2563eb; box-shadow: 0 5px 15px rgba(37,99,235,.25); } .page-item.disabled .page-link{ opacity:.45; } /* ========================================================= ALERT ========================================================= */ .modern-alert{ border:0; border-radius:14px; font-size:13px; box-shadow: 0 8px 20px rgba(15,23,42,.06); } /* ========================================================= FOOTER ========================================================= */ .footer{ text-align:center; padding:25px 10px; color:#64748b; font-size:11px; } /* ========================================================= OVERLAY ========================================================= */ .sidebar-overlay{ display:none; position:fixed; inset:0; background: rgba(15,23,42,.55); z-index:999; backdrop-filter:blur(3px); } /* ========================================================= RESPONSIVE ========================================================= */ @media(max-width:991px){ .sidebar{ left:-290px; } .sidebar.active{ left:0; } .sidebar-overlay.active{ display:block; } .main{ margin-left:0; padding:14px; } .mobile-toggle{ display:flex; } .topbar{ border-radius:16px; padding:14px; } .topbar h3{ font-size:18px; } } @media(max-width:767px){ .admin-box{ display:none; } .panel{ padding:16px; border-radius:17px; } .summary-card{ padding:17px; } .summary-value{ font-size:24px; } .panel-header{ align-items:flex-start; } .pagination-wrap{ flex-direction:column; align-items:center; } } @media(max-width:480px){ .main{ padding:10px; } .topbar{ margin-bottom:15px; } .topbar h3{ font-size:16px; } .panel-title h4{ font-size:16px; } .panel-title p{ display:none; } } </style> </head> <body> <!-- ========================================================= SIDEBAR OVERLAY ========================================================= --> <div class="sidebar-overlay" id="sidebarOverlay" onclick="closeSidebar()" ></div> <!-- ========================================================= SIDEBAR ========================================================= --> <aside class="sidebar" id="sidebar" > <div class="logo-box"> <div class="logo-icon"> <i class="bi bi-globe2"></i> </div> <h2>CAPAPP</h2> <p> Domain Management Panel </p> </div> <div class="menu"> <div class="menu-title"> Main Menu </div> <a href="dashboard.php"> <i class="bi bi-speedometer2"></i> <span> Dashboard </span> </a> <a href="index.php"> <i class="bi bi-globe2"></i> <span> All Domains </span> </a> <a href="add-domain.php"> <i class="bi bi-plus-circle"></i> <span> Add Domain </span> </a> <div class="menu-title"> Finance </div> <a href="domain-charges.php" class="active" > <i class="bi bi-cash-stack"></i> <span> Domain Charges </span> </a> <a href="add-payment.php"> <i class="bi bi-wallet2"></i> <span> Receive Payment </span> </a> <a href="domain-ledger.php"> <i class="bi bi-receipt"></i> <span> Balance Sheet </span> </a> <a href="bill.php"> <i class="bi bi-file-earmark-text"></i> <span> Generate Invoice </span> </a> <div class="menu-title"> Management </div> <a href="expired-domains.php"> <i class="bi bi-exclamation-octagon"></i> <span> Expired Domains </span> </a> <a href="logout.php"> <i class="bi bi-box-arrow-right"></i> <span> Logout </span> </a> </div> </aside> <!-- ========================================================= MAIN ========================================================= --> <main class="main"> <!-- TOPBAR --> <div class="topbar"> <div class="title-area"> <div class="mobile-toggle" onclick="toggleSidebar()" > <i class="bi bi-list"></i> </div> <div> <h3> Domain Charges </h3> <div class="topbar-sub"> Manage domain, hosting, renewal & service charges </div> </div> </div> <div class="admin-box"> <div class="admin-icon"> <i class="bi bi-person-fill"></i> </div> <div> <div class="admin-name"> <?= e($adminName) ?> </div> <div class="admin-role"> CAPAPP Administrator </div> </div> </div> </div> <!-- ===================================================== ALERTS ====================================================== --> <?php if ($successMessage): ?> <div class="alert alert-success modern-alert" > <i class="bi bi-check-circle-fill"></i> <?= e($successMessage) ?> </div> <?php endif; ?> <?php if ($errorMessage): ?> <div class="alert alert-danger modern-alert" > <i class="bi bi-exclamation-triangle-fill"></i> <?= e($errorMessage) ?> </div> <?php endif; ?> <!-- ===================================================== SUMMARY ====================================================== --> <div class="row g-3 mt-1"> <!-- TOTAL --> <div class="col-lg-4 col-md-4"> <div class="summary-card summary-total"> <div class="summary-icon"> <i class="bi bi-cash-stack"></i> </div> <div class="summary-label"> Total Charges </div> <div class="summary-value"> ₹<?= number_format( $totalAmt, 2 ) ?> </div> </div> </div> <!-- PAID --> <div class="col-lg-4 col-md-4"> <div class="summary-card summary-paid"> <div class="summary-icon"> <i class="bi bi-check2-circle"></i> </div> <div class="summary-label"> Total Paid </div> <div class="summary-value"> ₹<?= number_format( $totalPaid, 2 ) ?> </div> </div> </div> <!-- PENDING --> <div class="col-lg-4 col-md-4"> <div class="summary-card summary-pending"> <div class="summary-icon"> <i class="bi bi-hourglass-split"></i> </div> <div class="summary-label"> Pending Balance </div> <div class="summary-value"> ₹<?= number_format( $pending, 2 ) ?> </div> </div> </div> </div> <!-- ===================================================== ADD CHARGE ====================================================== --> <section class="panel"> <div class="panel-header"> <div class="panel-title"> <div class="panel-title-icon"> <i class="bi bi-plus-circle-fill"></i> </div> <div> <h4> Add Domain Charge </h4> <p> Add a new charge or payment against a domain </p> </div> </div> </div> <form method="POST" id="chargeForm" > <div class="row g-3"> <!-- DOMAIN --> <div class="col-lg-3 col-md-6"> <label class="form-label"> Select Domain </label> <select name="domain_id" class="form-select" required onchange="changeDomain(this)" > <option value=""> Select Domain </option> <?php while ( $d = mysqli_fetch_assoc($domains) ): ?> <option value="<?= (int)$d['id'] ?>" <?= ( (int)$d['id'] === $domain_id ) ? 'selected' : '' ?> > <?= e( $d['domain_name'] ) ?> </option> <?php endwhile; ?> </select> </div> <!-- CHARGE TYPE --> <div class="col-lg-3 col-md-6"> <label class="form-label"> Charge Type </label> <select name="charge_type" class="form-select" required > <?php $types = [ 'Design', 'Domain', 'Hosting', 'Renewal', 'SSL', 'Email', 'Maintenance', 'Other' ]; ?> <?php foreach ( $types as $type ): ?> <option value="<?= e($type) ?>" <?= ( $charge_type === $type ) ? 'selected' : '' ?> > <?= e($type) ?> </option> <?php endforeach; ?> </select> </div> <!-- TOTAL --> <div class="col-lg-2 col-md-6"> <label class="form-label"> Total Amount </label> <div class="input-icon"> <i class="bi bi-currency-rupee"></i> <input type="number" name="total_amount" id="totalAmount" class="form-control" placeholder="0.00" min="0" step="0.01" value="<?= e( $total_amount ) ?>" required > </div> </div> <!-- PAID --> <div class="col-lg-2 col-md-6"> <label class="form-label"> Paid Amount </label> <div class="input-icon"> <i class="bi bi-currency-rupee"></i> <input type="number" name="paid_amount" id="paidAmount" class="form-control" placeholder="0.00" min="0" step="0.01" value="<?= e( $paid_amount ) ?>" required > </div> </div> <!-- BUTTON --> <div class="col-lg-2 col-md-12 d-flex align-items-end"> <button type="submit" name="save" class="add-btn" > <i class="bi bi-plus-lg"></i> Add Charge </button> </div> </div> <!-- LIVE BALANCE --> <div class="live-balance"> <span> <i class="bi bi-info-circle"></i> Current entry balance </span> <strong id="liveBalance"> ₹0.00 </strong> </div> </form> </section> <!-- ===================================================== CHARGES LIST ====================================================== --> <section class="panel"> <div class="panel-header"> <div class="panel-title"> <div class="panel-title-icon"> <i class="bi bi-list-check"></i> </div> <div> <h4> Charge History </h4> <p> <?php if ($domain_id > 0): ?> <?= e( $domainName ) ?> <?php else: ?> Select a domain to view charge history <?php endif; ?> </p> </div> </div> <?php if ($domain_id > 0): ?> <span class="badge text-bg-light"> <?= $count ?> Records </span> <?php endif; ?> </div> <?php if ($domain_id <= 0): ?> <div class="empty-state"> <div class="empty-icon"> <i class="bi bi-globe2"></i> </div> <h5> Select a Domain </h5> <p> Select a domain above to view its charges and payment history. </p> </div> <?php elseif (count($charges) === 0): ?> <div class="empty-state"> <div class="empty-icon"> <i class="bi bi-receipt"></i> </div> <h5> No Charges Found </h5> <p> No charge has been added for this domain yet. </p> </div> <?php else: ?> <div class="table-wrap"> <table class="modern-table"> <thead> <tr> <th> # </th> <th> Charge Type </th> <th> Total </th> <th> Paid </th> <th> Balance </th> <th> Status </th> </tr> </thead> <tbody> <?php foreach ( $charges as $index => $r ): ?> <?php $rowTotal = (float)$r[ 'total_amount' ]; $rowPaid = (float)$r[ 'paid_amount' ]; $rowBalance = max( 0, $rowTotal - $rowPaid ); $rowStatus = $r[ 'payment_status' ]; ?> <tr> <td> <span class="text-muted" > <?= ( $start + $index + 1 ) ?> </span> </td> <td> <div class="charge-type"> <div class="charge-icon"> <?php $icon = 'bi-receipt'; if ( $r[ 'charge_type' ] === 'Domain' ) { $icon = 'bi-globe2'; } elseif ( $r[ 'charge_type' ] === 'Hosting' ) { $icon = 'bi-server'; } elseif ( $r[ 'charge_type' ] === 'Renewal' ) { $icon = 'bi-arrow-repeat'; } elseif ( $r[ 'charge_type' ] === 'Design' ) { $icon = 'bi-palette'; } elseif ( $r[ 'charge_type' ] === 'Email' ) { $icon = 'bi-envelope'; } elseif ( $r[ 'charge_type' ] === 'SSL' ) { $icon = 'bi-shield-check'; } ?> <i class="bi <?= e( $icon ) ?>"></i> </div> <?= e( $r[ 'charge_type' ] ) ?> </div> </td> <td> <span class="amount"> ₹<?= number_format( $rowTotal, 2 ) ?> </span> </td> <td> <span class="amount text-success"> ₹<?= number_format( $rowPaid, 2 ) ?> </span> </td> <td> <span class="balance"> ₹<?= number_format( $rowBalance, 2 ) ?> </span> </td> <td> <?php if ( strtolower( (string)$rowStatus ) === 'paid' ): ?> <span class="status-badge status-paid" > <i class="bi bi-check-circle-fill"></i> Paid </span> <?php else: ?> <span class="status-badge status-partial" > <i class="bi bi-clock-fill"></i> Partial </span> <?php endif; ?> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <!-- PAGINATION --> <?php if ($totalPages > 1): ?> <div class="pagination-wrap"> <div class="page-info"> Showing <?= $start + 1 ?> - <?= min( $start + $limit, $count ) ?> of <?= $count ?> records </div> <nav> <ul class="pagination"> <!-- PREVIOUS --> <li class="page-item <?= ( $page <= 1 ) ? 'disabled' : '' ?>" > <?php if ($page > 1): ?> <a class="page-link" href="?domain_id=<?= $domain_id ?>&page=<?= $page - 1 ?>" > <i class="bi bi-chevron-left"></i> </a> <?php else: ?> <span class="page-link"> <i class="bi bi-chevron-left"></i> </span> <?php endif; ?> </li> <!-- PAGE NUMBERS --> <?php $pageStart = max( 1, $page - 2 ); $pageEnd = min( $totalPages, $page + 2 ); ?> <?php if ( $pageStart > 1 ): ?> <li class="page-item"> <a class="page-link" href="?domain_id=<?= $domain_id ?>&page=1" > 1 </a> </li> <?php if ( $pageStart > 2 ): ?> <li class="page-item disabled"> <span class="page-link"> ... </span> </li> <?php endif; ?> <?php endif; ?> <?php for ( $i = $pageStart; $i <= $pageEnd; $i++ ): ?> <li class="page-item <?= ( $i === $page ) ? 'active' : '' ?>" > <a class="page-link" href="?domain_id=<?= $domain_id ?>&page=<?= $i ?>" > <?= $i ?> </a> </li> <?php endfor; ?> <?php if ( $pageEnd < $totalPages ): ?> <?php if ( $pageEnd < $totalPages - 1 ): ?> <li class="page-item disabled"> <span class="page-link"> ... </span> </li> <?php endif; ?> <li class="page-item"> <a class="page-link" href="?domain_id=<?= $domain_id ?>&page=<?= $totalPages ?>" > <?= $totalPages ?> </a> </li> <?php endif; ?> <!-- NEXT --> <li class="page-item <?= ( $page >= $totalPages ) ? 'disabled' : '' ?>" > <?php if ( $page < $totalPages ): ?> <a class="page-link" href="?domain_id=<?= $domain_id ?>&page=<?= $page + 1 ?>" > <i class="bi bi-chevron-right"></i> </a> <?php else: ?> <span class="page-link"> <i class="bi bi-chevron-right"></i> </span> <?php endif; ?> </li> </ul> </nav> </div> <?php endif; ?> <?php endif; ?> </section> <!-- FOOTER --> <div class="footer"> © <?= date('Y') ?> CAPAPP IT SOLUTION PRIVATE LIMITED • Domain Management System </div> </main> <script> /* ========================================================= SIDEBAR ========================================================= */ function toggleSidebar(){ const sidebar = document.getElementById( 'sidebar' ); const overlay = document.getElementById( 'sidebarOverlay' ); sidebar.classList.toggle( 'active' ); overlay.classList.toggle( 'active' ); } function closeSidebar(){ const sidebar = document.getElementById( 'sidebar' ); const overlay = document.getElementById( 'sidebarOverlay' ); sidebar.classList.remove( 'active' ); overlay.classList.remove( 'active' ); } /* ========================================================= DOMAIN CHANGE ========================================================= */ function changeDomain(select){ const domainId = select.value; if(!domainId){ window.location.href = 'domain-charges.php'; return; } window.location.href = 'domain-charges.php?domain_id=' + encodeURIComponent( domainId ); } /* ========================================================= LIVE BALANCE ========================================================= */ function updateBalance(){ const total = parseFloat( document.getElementById( 'totalAmount' ).value ) || 0; const paid = parseFloat( document.getElementById( 'paidAmount' ).value ) || 0; const balance = Math.max( 0, total - paid ); document.getElementById( 'liveBalance' ).textContent = '₹' + balance.toLocaleString( 'en-IN', { minimumFractionDigits:2, maximumFractionDigits:2 } ); } /* ========================================================= AMOUNT EVENTS ========================================================= */ document .getElementById('totalAmount') .addEventListener( 'input', updateBalance ); document .getElementById('paidAmount') .addEventListener( 'input', updateBalance ); updateBalance(); /* ========================================================= FORM VALIDATION ========================================================= */ document .getElementById('chargeForm') .addEventListener( 'submit', function(event){ const total = parseFloat( document.getElementById( 'totalAmount' ).value ) || 0; const paid = parseFloat( document.getElementById( 'paidAmount' ).value ) || 0; if(total <= 0){ event.preventDefault(); alert( 'Please enter a valid total amount.' ); return; } if(paid < 0){ event.preventDefault(); alert( 'Paid amount cannot be negative.' ); return; } if(paid > total){ event.preventDefault(); alert( 'Paid amount cannot be greater than total amount.' ); return; } } ); /* ========================================================= CLOSE MOBILE SIDEBAR AFTER CLICK ========================================================= */ document .querySelectorAll('.sidebar a') .forEach( function(link){ link.addEventListener( 'click', function(){ if( window.innerWidth <= 991 ){ closeSidebar(); } } ); } ); </script> </body> </html>
Save
Cancel