diff --git a/customers/.hta_slug/list.php b/customers/.hta_slug/list.php index eb82fdb..186d755 100644 --- a/customers/.hta_slug/list.php +++ b/customers/.hta_slug/list.php @@ -1,6 +1,47 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // Start Transaction + $db->beginTransaction(); + + // Delete from emi table + $stmt = $db->prepare("DELETE FROM emi WHERE customerId = :customerId AND invoiceId = :invoiceId"); + $stmt->execute(['customerId' => $customerId, 'invoiceId' => $invoiceId]); + + // Delete from invoice table + $stmt = $db->prepare("DELETE FROM invoice WHERE customerId = :customerId AND invoiceId = :invoiceId"); + $stmt->execute(['customerId' => $customerId, 'invoiceId' => $invoiceId]); + + // Delete from customers table (only if no dependent records exist) + $stmt = $db->prepare("DELETE FROM customers WHERE customerId = :customerId"); + $stmt->execute(['customerId' => $customerId]); + + // Commit Transaction + $db->commit(); + + echo '