diff --git a/customers/.hta_slug/billing-details.php b/customers/.hta_slug/billing-details.php index e9d6e9d..af86d64 100644 --- a/customers/.hta_slug/billing-details.php +++ b/customers/.hta_slug/billing-details.php @@ -1,106 +1,130 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -} catch (PDOException $e) { - die("Database connection failed: " . $e->getMessage()); -} -// Handle Payment Status Update -if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["emiId"]) && isset($_POST["status"])) { - $emiId = $_POST["emiId"]; - $status = $_POST["status"]; - - try { - $stmt = $db->prepare("UPDATE billing SET emi".$emiId."Status = :status WHERE customerId = :customerId"); - $stmt->bindParam(':status', $status, PDO::PARAM_INT); - $stmt->bindParam(':customerId', $_POST["customerId"]); - $stmt->execute(); - echo json_encode(["success" => true, "message" => "Payment status updated"]); - } catch (PDOException $e) { - echo json_encode(["success" => false, "message" => "Error updating payment status"]); + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['emiId'], $_POST['payStatus'])) { + header('Content-Type: application/json'); + ob_end_clean(); // Clears any accidental HTML output + + try { + $stmt = $db->prepare("UPDATE emi SET payStatus = :payStatus WHERE customerId = :customerId AND id = :emiId"); + $stmt->bindParam(':customerId', $_GET['customerId']); + $stmt->bindParam(':payStatus', $_POST['payStatus'], PDO::PARAM_INT); + $stmt->bindParam(':emiId', $_POST['emiId'], PDO::PARAM_INT); + $stmt->execute(); + + echo json_encode(['status' => 'success']); + } catch (PDOException $e) { + echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); + } + + exit; } - exit; -} + + // Fetch EMI data + $stmt = $db->prepare("SELECT * FROM emi WHERE customerId = :customerId ORDER BY emiDate ASC"); + $stmt->bindParam(':customerId', $_GET['customerId']); + $stmt->execute(); + $emiPlans = $stmt->fetchAll(PDO::FETCH_ASSOC); + // var_dump($emiPlans); -// Fetch Customer Billing Data -if (!isset($_GET['customerId'])) { - die("Invalid request: Customer ID is required."); -} - -$customerId = $_GET['customerId']; -$stmt = $db->prepare("SELECT * FROM billing WHERE customerId = :customerId"); -$stmt->bindParam(':customerId', $customerId); -$stmt->execute(); -$billingData = $stmt->fetch(PDO::FETCH_ASSOC); - -if (!$billingData) { - die("No billing data found for this customer."); + $stmt = $db->prepare("SELECT * FROM customers WHERE customerId = :customerId"); + $stmt->bindParam(':customerId', $_GET['customerId']); + $stmt->execute(); + $customer = $stmt->fetch(PDO::FETCH_ASSOC); + // var_dump($customer); + +} catch (PDOException $e) { + die('
# | +Number of EMI | +EMI Amount | EMI Date | -Amount | -Status | +Payment Status | +Outstanding | Action | {$i} | -{$emiDate} | -₹{$emiAmount} | -" . ($emiStatus == 1 ? "Paid" : "Unpaid") . " | -- - | - "; - } - ?> + +
---|---|---|---|---|---|---|---|---|
= $emi['emiNumber']; ?> | +₹= number_format($emi['emiAmount'], 2); ?> | += date('d-m-Y', strtotime($emi['emiDate'])); ?> | ++ + = $emi['payStatus'] == 0 ? 'Unpaid' : 'Paid'; ?> + + | +₹= number_format($emi['outstanding'], 2); ?> | ++ + | +
Name: = htmlspecialchars($customer['name']) ?>
-Mobile: = htmlspecialchars($customer['mobile']) ?>
- -Mobile: = htmlspecialchars($customer['mobile']) ?>
+ +Sl No | Name | @@ -33,8 +33,8 @@Edit - Bill - Billing Info + Invoice + Installment Details |
---|