📁 File Manager
Editing:
/home/wvl7mof7402e/public_html/remindyourdata.live/admin/clientpaymentedit.php
<?php session_start(); include "dbconnect.php"; // Database Connection // Check if ID is provided in the URL if (isset($_GET['id'])) { $payment_id = $_GET['id']; // Prepare SQL statement to avoid SQL injection $stmt = $con->prepare("SELECT cp.id, cp.applicant_id, cp.total_payment, cp.paid_amount, cp.pending_amount, cp.payment_date, cp.payment_message, cp.installment_number, cp.installment_due_date, ja.name, ja.passport_no, ja.position, ja.job_country, ja.reference FROM clientspayment cp JOIN job_applicants ja ON cp.applicant_id = ja.id WHERE cp.id = ?"); $stmt->bind_param("i", $payment_id); // "i" is for integer $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { $payment = $result->fetch_assoc(); } else { echo "<script>alert('No payment record found!'); window.location.href = 'clientpaymentlist.php';</script>"; exit; } } else { echo "<script>alert('No payment record found!'); window.location.href = 'clientpaymentlist.php';</script>"; exit; } // Handle form submission for updating the payment record if ($_SERVER["REQUEST_METHOD"] == "POST") { $total_payment = $_POST['total_payment']; $paid_amount = $_POST['paid_amount']; $payment_date = $_POST['payment_date']; $payment_message = $_POST['payment_message']; $installments = $_POST['installments']; // Number of installments // Calculate pending amount $pending_amount = $total_payment - $paid_amount; // Update payment record in the database $stmt_update = $con->prepare("UPDATE clientspayment SET total_payment = ?, paid_amount = ?, pending_amount = ?, payment_date = ?, payment_message = ?, installment_number = ? WHERE id = ?"); $stmt_update->bind_param("dddssii", $total_payment, $paid_amount, $pending_amount, $payment_date, $payment_message, $installments, $payment_id); if ($stmt_update->execute()) { // Update installment due dates in a separate table or handle appropriately // For now, assuming installment_due_date is a single date, store the first installment due date // If multiple installment due dates needed, the database schema should support it properly. // You can adapt below if your DB supports multiple due dates per installment: /* for ($i = 1; $i <= $installments; $i++) { $due_date = $_POST['installment_due_date_' . $i]; // Run update/insert query accordingly } */ echo "<script>alert('Payment Record Updated Successfully'); window.location.href = 'clientpaymentlist.php';</script>"; exit; } else { $error = $con->error; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Edit Payment Record</title> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> <!-- Bootstrap Icons --> <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" /> <style> body { min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #fff; padding: 20px 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } .card { background: rgba(255, 255, 255, 0.95); color: #222; border-radius: 12px; box-shadow: 0 8px 25px rgba(0,0,0,0.3); } h3 { color: #764ba2; font-weight: 700; margin-bottom: 1.5rem; text-align: center; } .form-control:focus { border-color: #764ba2; box-shadow: 0 0 6px #764ba2; } label { font-weight: 600; } .input-group-text { background-color: #764ba2; border-color: #764ba2; color: #fff; } .btn-primary { background-color: #764ba2; border-color: #764ba2; font-weight: 600; transition: background-color 0.3s ease; } .btn-primary:hover { background-color: #5a3576; border-color: #5a3576; } .form-group + .form-group { margin-top: 1rem; } @media (max-width: 575.98px) { body { padding: 10px 10px; } } </style> </head> <body> <div class="container"> <div class="d-flex justify-content-end mb-3"> <a href="logout.php" class="btn btn-danger"> <i class="bi bi-box-arrow-right"></i> Logout </a> </div> <div class="card p-4 mx-auto" style="max-width: 700px;"> <h3><i class="bi bi-pencil-square"></i> Edit Payment Record</h3> <?php if (isset($error)) : ?> <div class="alert alert-danger"><?= htmlspecialchars($error) ?></div> <?php endif; ?> <form method="POST" novalidate> <!-- Applicant Info (Read-only) --> <div class="mb-3"> <label for="applicant_name" class="form-label"><i class="bi bi-person-fill"></i> Applicant Name</label> <input type="text" id="applicant_name" class="form-control" value="<?= htmlspecialchars($payment['name']) ?>" disabled> </div> <div class="mb-3"> <label for="passport_no" class="form-label"><i class="bi bi-credit-card-2-front-fill"></i> Passport Number</label> <input type="text" id="passport_no" class="form-control" value="<?= htmlspecialchars($payment['passport_no']) ?>" disabled> </div> <div class="mb-3"> <label for="position" class="form-label"><i class="bi bi-briefcase-fill"></i> Position</label> <input type="text" id="position" class="form-control" value="<?= htmlspecialchars($payment['position']) ?>" disabled> </div> <div class="mb-3"> <label for="job_country" class="form-label"><i class="bi bi-geo-alt-fill"></i> Job Country</label> <input type="text" id="job_country" class="form-control" value="<?= htmlspecialchars($payment['job_country']) ?>" disabled> </div> <div class="mb-3"> <label for="reference" class="form-label"><i class="bi bi-people-fill"></i> Reference (Agent)</label> <input type="text" id="reference" class="form-control" value="<?= htmlspecialchars($payment['reference']) ?>" disabled> </div> <!-- Editable Fields with icons --> <div class="mb-3"> <label for="payment_date" class="form-label"><i class="bi bi-calendar-check-fill"></i> Payment Date</label> <div class="input-group"> <span class="input-group-text"><i class="bi bi-calendar-event"></i></span> <input type="date" name="payment_date" id="payment_date" class="form-control" value="<?= htmlspecialchars($payment['payment_date']) ?>" required> </div> </div> <div class="mb-3"> <label for="total_payment" class="form-label"><i class="bi bi-cash-stack"></i> Total Payment</label> <div class="input-group"> <span class="input-group-text"><i class="bi bi-currency-dollar"></i></span> <input type="number" name="total_payment" id="total_payment" step="0.01" min="0" class="form-control" value="<?= htmlspecialchars($payment['total_payment']) ?>" required> </div> </div> <div class="mb-3"> <label for="paid_amount" class="form-label"><i class="bi bi-wallet2"></i> Paid Amount</label> <div class="input-group"> <span class="input-group-text"><i class="bi bi-currency-dollar"></i></span> <input type="number" name="paid_amount" id="paid_amount" step="0.01" min="0" class="form-control" value="<?= htmlspecialchars($payment['paid_amount']) ?>" required> </div> </div> <div class="mb-3"> <label for="payment_message" class="form-label"><i class="bi bi-chat-left-text-fill"></i> Payment Message</label> <textarea name="payment_message" id="payment_message" rows="3" class="form-control" required><?= htmlspecialchars($payment['payment_message']) ?></textarea> </div> <div class="mb-3"> <label for="installments" class="form-label"><i class="bi bi-list-ol"></i> Number of Installments</label> <select name="installments" id="installments" class="form-select" required> <?php for ($i = 1; $i <= 4; $i++) : ?> <option value="<?= $i ?>" <?= ($payment['installment_number'] == $i) ? 'selected' : '' ?>><?= $i ?></option> <?php endfor; ?> </select> </div> <!-- Dynamic Installment Due Dates --> <div id="installments_due_dates"></div> <div class="d-grid mt-4"> <button type="submit" class="btn btn-primary"><i class="bi bi-check-circle-fill"></i> Update Payment Record</button> </div> </form> </div> </div> <!-- Bootstrap Bundle JS --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script> // Pass PHP installment due date for JavaScript use const existingDueDate = "<?= htmlspecialchars($payment['installment_due_date']) ?>"; // Function to dynamically create installment due date fields function createInstallmentDueDates(number) { const container = document.getElementById('installments_due_dates'); container.innerHTML = ''; // Clear previous fields for (let i = 1; i <= number; i++) { // For now, set the first installment's due date to existingDueDate, others blank const dueDateValue = (i === 1 && existingDueDate) ? existingDueDate : ''; const div = document.createElement('div'); div.classList.add('mb-3'); div.innerHTML = ` <label for="installment_due_date_${i}" class="form-label"><i class="bi bi-clock-history"></i> Installment ${i} Due Date</label> <div class="input-group"> <span class="input-group-text"><i class="bi bi-calendar"></i></span> <input type="date" name="installment_due_date_${i}" id="installment_due_date_${i}" class="form-control" value="${dueDateValue}" required> </div> `; container.appendChild(div); } } // Initial population of installment due dates on page load const installmentsSelect = document.getElementById('installments'); createInstallmentDueDates(parseInt(installmentsSelect.value)); installmentsSelect.addEventListener('change', function() { createInstallmentDueDates(parseInt(this.value)); }); </script> </body> </html>
Save
Cancel