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('
Error: ' . $e->getMessage() . '
'); } ?>
-

Customer Billing Details

- - +

EMI Details

+
+
+

Customer Name:

+

Mobile Number:

+

EMI Booking Date:

+
+
+ +

Total Amount:

+

Outstanding:

+

Tenure:

+

Frequency:

+
+ +
+
+ - + + - - + + - - - - - - - "; - } - ?> + + + + + + + + + +
#Number of EMIEMI Amount EMI DateAmountStatusPayment StatusOutstanding Action
{$i}{$emiDate}₹{$emiAmount}" . ($emiStatus == 1 ? "Paid" : "Unpaid") . " - -
+ + + + + +
- diff --git a/customers/.hta_slug/emi.php b/customers/.hta_slug/emi.php deleted file mode 100644 index 6740291..0000000 --- a/customers/.hta_slug/emi.php +++ /dev/null @@ -1,100 +0,0 @@ -setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - $customerId = $_POST['customerId']; - $totalAmount = $_POST['totalAmount']; - $tenure = min($_POST['tenure'], 18); // Limit tenure to 18 months - $firstEmiDate = $_POST['firstEmiDate']; - $emiAmount = $totalAmount / $tenure; - - // Prepare the query dynamically - $columns = ['customerId', 'totalAmount', 'tenure', 'emiAmount', 'firstEmiDate']; - $placeholders = [':customerId', ':totalAmount', ':tenure', ':emiAmount', ':firstEmiDate']; - $params = [ - ':customerId' => $customerId, - ':totalAmount' => $totalAmount, - ':tenure' => $tenure, - ':emiAmount' => $emiAmount, - ':firstEmiDate' => $firstEmiDate - ]; - - // Add EMI columns dynamically based on tenure - for ($i = 1; $i <= $tenure; $i++) { - $emiDate = date('Y-m-d', strtotime("+$i months", strtotime($firstEmiDate))); - $columns[] = "emi$i"; - $columns[] = "emi{$i}Date"; - $placeholders[] = ":emi$i"; - $placeholders[] = ":emi{$i}Date"; - $params[":emi$i"] = $emiAmount; - $params[":emi{$i}Date"] = $emiDate; - } - - // Construct SQL statement - $sql = "INSERT INTO billing (" . implode(',', $columns) . ") VALUES (" . implode(',', $placeholders) . ")"; - $stmt = $db->prepare($sql); - - // Execute the query - if ($stmt->execute($params)) { - echo '
New EMI plan for ' . htmlspecialchars($customerId) . ' saved successfully.
'; - } else { - echo '
Error executing statement: ' . $stmt->errorInfo()[2] . '
'; - } - } catch (PDOException $e) { - echo '
Error: ' . $e->getMessage() . '
'; - } -} - -// Fetch customer details -$customer = null; -if (!empty($_GET['customerId'])) { - try { - $db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass); - $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - $stmt = $db->prepare("SELECT * FROM customers WHERE customerId = :customerId"); - $stmt->bindParam(':customerId', $_GET['customerId']); - if ($stmt->execute()) { - $customer = $stmt->fetch(PDO::FETCH_ASSOC); - } - } catch (PDOException $e) { - echo '
Error: ' . $e->getMessage() . '
'; - } -} -?> - -
-

EMI Calculation

- - -

Name:

-

Mobile:

- -
Customer not found.
- - -
- - -
- - -
- -
- - -
- -
- - -
- - -
-
diff --git a/customers/.hta_slug/generate-invoice.php b/customers/.hta_slug/generate-invoice.php new file mode 100644 index 0000000..f8f4521 --- /dev/null +++ b/customers/.hta_slug/generate-invoice.php @@ -0,0 +1,149 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $totalAmount = $_POST['totalAmount']; + $tenure = $_POST['tenure']; + $firstEmiDate = $_POST['firstEmiDate']; + $totalAmount = $_POST['totalAmount']; + $frequency = $_POST['frequency']; + $bookingDate = $_POST['bookingDate']; + $paymentMode = $_POST['paymentMode']; + // EMI Calculation + $emiAmount = round($totalAmount / $tenure, 2); + $outstandingAmount = $totalAmount; + $emiDate = new DateTime($firstEmiDate); // Set initial date + + $stmt = $db->prepare("INSERT INTO emi (customerId, emiNumber, emiAmount, emiDate, totalAmount, outstanding, tenure, frequency, bookingDate, paymentMode) VALUES (:customerId, :emiNumber, :emiAmount, :emiDate, :totalAmount, :outstanding, :tenure, :frequency, bookingDate, :paymentMode)"); + + for ($i = 1; $i <= $tenure; $i++) { + $outstandingAmount -= $emiAmount; + $emiDateFormatted = $emiDate->format('Y-m-d'); + $stmt->bindParam(':customerId', $_GET['customerId']); + $stmt->bindParam(':emiNumber', $i); + $stmt->bindParam(':emiAmount', $emiAmount); + $stmt->bindParam(':emiDate', $emiDateFormatted); + $stmt->bindParam(':totalAmount', $totalAmount); + $stmt->bindParam(':outstanding', $outstandingAmount); + $stmt->bindParam(':tenure', $tenure); + $stmt->bindParam(':frequency', $frequency); + $stmt->bindParam(':bookingDate', $bookingDate); + $stmt->bindParam(':paymentMode', $paymentMode); + $stmt->execute(); + + // Move to the next month's EMI date + if($frequency === 'Weekly'){ + $emiDate->modify('+1 week'); + } elseif($frequency === 'Monthly'){ + $emiDate->modify('+1 month'); + } + } + echo '
New EMI Plan Saved Successfully!
'; + } catch (PDOException $e) { + echo '
Error: ' . $e->getMessage() . '
'; + } + } + + $customer = null; + if (!empty($_GET['customerId'])) { + try { + $db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass); + $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $stmt = $db->prepare("SELECT * FROM customers WHERE customerId = :customerId"); + $stmt->bindParam(':customerId', $_GET['customerId']); + if ($stmt->execute()) { + $customer = $stmt->fetch(PDO::FETCH_ASSOC); + } + + $stmt = $db->prepare("SELECT * FROM address WHERE customerId = :customerId"); + $stmt->bindParam(':customerId', $_GET['customerId']); + if ($stmt->execute()) { + $customerAddress = $stmt->fetch(PDO::FETCH_ASSOC); + } + + + } catch (PDOException $e) { + echo '
Error: ' . $e->getMessage() . '
'; + } + } +?> + +
+

Create Invoice

+ + +

Mobile:

+ +
Customer not found.
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+
+
+ + +
+
+ + +
+
+
+
+
+ + +
+
+ + +
+
+
+ + + + +
+
diff --git a/customers/.hta_slug/list.php b/customers/.hta_slug/list.php index 602a4f5..4603712 100644 --- a/customers/.hta_slug/list.php +++ b/customers/.hta_slug/list.php @@ -5,7 +5,7 @@

Customer List

- + @@ -33,8 +33,8 @@ \ No newline at end of file
Sl No Name Edit - Bill - Billing Info + Invoice + Installment Details