first commit

This commit is contained in:
Suvodip
2025-02-28 17:08:43 +05:30
commit e56d4f72ab
27 changed files with 598 additions and 0 deletions

View File

View File

@@ -0,0 +1 @@
sample route home

View File

@@ -0,0 +1,106 @@
<?php
require('../.hta_config/conf.php');
// Enable error reporting (for debugging)
error_reporting(E_ALL);
ini_set('display_errors', 1);
try {
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->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"]);
}
exit;
}
// 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.");
}
?>
<div class="container mt-4">
<h2 class="mb-3 text-center">Customer Billing Details</h2>
<table class="table table-bordered table-striped">
<thead class="thead-dark">
<tr>
<th>#</th>
<th>EMI Date</th>
<th>Amount</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
for ($i = 1; $i <= 12; $i++) {
$emiAmount = $billingData["emi$i"];
$emiDate = $billingData["emi{$i}Date"];
$emiStatus = $billingData["emi{$i}Status"];
if (!$emiAmount || !$emiDate) continue;
echo "<tr>
<td>{$i}</td>
<td>{$emiDate}</td>
<td>₹{$emiAmount}</td>
<td id='status-$i'>" . ($emiStatus == 1 ? "<span class='badge bg-success'>Paid</span>" : "<span class='badge bg-danger'>Unpaid</span>") . "</td>
<td>
<button class='btn btn-sm " . ($emiStatus == 1 ? "btn-secondary disabled" : "btn-primary") . "' onclick='updatePaymentStatus($i)' id='btn-$i'>Mark as Paid</button>
</td>
</tr>";
}
?>
</tbody>
</table>
</div>
<script>
function updatePaymentStatus(emiId) {
let customerId = "<?php echo $customerId; ?>";
let formData = new FormData();
formData.append("emiId", emiId);
formData.append("status", 1); // Set status to "1" (Paid)
formData.append("customerId", customerId);
fetch("billing-details.php", {
method: "POST",
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById("status-" + emiId).innerHTML = "<span class='badge badge-success'>Paid</span>";
document.getElementById("btn-" + emiId).classList.replace("btn-primary", "btn-secondary");
document.getElementById("btn-" + emiId).classList.add("disabled");
} else {
alert("Failed to update payment status!");
}
})
.catch(error => console.error("Error:", error));
}
</script>

View File

@@ -0,0 +1,109 @@
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card shadow-lg">
<div class="card-header bg-primary text-white text-center">
<h4>Edit Customer Details</h4>
</div>
<div class="card-body">
<?php
require('../.hta_config/conf.php');
try {
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Update customer details
$stmt = $db->prepare("UPDATE customers SET name = :name, mobile = :mobile, email = :email WHERE customerId = :customerId");
$stmt->bindParam(':name', $_POST['name']);
$stmt->bindParam(':mobile', $_POST['mobile']);
$stmt->bindParam(':email', $_POST['email']);
$stmt = $db->prepare("SELECT COUNT(*) FROM address WHERE customerId = :customerId");
$stmt->bindParam(':customerId', $_POST['customerId']);
$stmt->execute();
$addressExists = $stmt->fetchColumn();
if ($addressExists) {
$stmt = $db->prepare("UPDATE address SET city = :city, district = :district, state = :state, pinCode = :pin WHERE customerId = :customerId");
} else {
$stmt = $db->prepare("INSERT INTO address (customerId, city, district, state, pinCode) VALUES (:customerId, :city, :district, :state, :pin)");
}
$stmt->bindParam(':city', $_POST['city']);
$stmt->bindParam(':district', $_POST['district']);
$stmt->bindParam(':state', $_POST['state']);
$stmt->bindParam(':pin', $_POST['pinCode']);
$stmt->bindParam(':customerId', $_POST['customerId']);
if ($stmt->execute()) {
echo '<div class="alert alert-success">Customer details updated successfully.</div>';
} else {
echo '<div class="alert alert-danger">Error updating customer.</div>';
}
}
// Fetch customer data
$stmt = $db->prepare("SELECT * FROM customers WHERE customerId = :customerId");
$stmt->bindParam(':customerId', $_GET['customerId']);
$stmt->execute();
$customer = $stmt->fetch(PDO::FETCH_ASSOC);
$stmtAddress = $db->prepare("SELECT * FROM address WHERE customerId = :customerId");
$stmtAddress->bindParam(':customerId', $_GET['customerId']);
$stmtAddress->execute();
$customerAddress = $stmtAddress->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
}
?>
<?php if ($customer): ?>
<form method="POST">
<input type="hidden" name="customerId" value="<?php echo htmlspecialchars($customer['customerId']); ?>">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" name="name" class="form-control" value="<?php echo htmlspecialchars($customer['name']); ?>" required>
</div>
<div class="form-group">
<label for="mobile">Mobile:</label>
<input type="text" id="mobile" name="mobile" class="form-control" value="<?php echo htmlspecialchars($customer['mobile']); ?>" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" class="form-control" value="<?php echo htmlspecialchars($customer['email']); ?>" required>
</div>
<div class="form-group">
<label for="city">City:</label>
<input type="text" id="city" name="city" class="form-control" value="<?php echo htmlspecialchars($customerAddress['city'] ?? ''); ?>" required>
</div>
<div class="form-group">
<label for="district">District:</label>
<input type="text" id="district" name="district" class="form-control" value="<?php echo htmlspecialchars($customerAddress['district'] ?? ''); ?>" required>
</div>
<div class="form-group">
<label for="state">State:</label>
<input type="text" id="state" name="state" class="form-control" value="<?php echo htmlspecialchars($customerAddress['state'] ?? ''); ?>" required>
</div>
<div class="form-group">
<label for="pinCode">Pin Code:</label>
<input type="text" id="pinCode" name="pinCode" class="form-control" value="<?php echo htmlspecialchars($customerAddress['pinCode'] ?? ''); ?>" required>
</div>
<button type="submit" class="btn btn-success btn-block mt-2">Update Customer</button>
</form>
<?php else: ?>
<div class="alert alert-danger text-center">Customer not found!</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>

100
customers/.hta_slug/emi.php Normal file
View File

@@ -0,0 +1,100 @@
<?php
require('../.hta_config/conf.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->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 '<div class="alert alert-success">New EMI plan for <strong>' . htmlspecialchars($customerId) . '</strong> saved successfully.</div>';
} else {
echo '<div class="alert alert-danger">Error executing statement: ' . $stmt->errorInfo()[2] . '</div>';
}
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
}
}
// 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 '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
}
}
?>
<div class="container mt-4">
<h2>EMI Calculation</h2>
<?php if (!empty($customer)): ?>
<p><strong>Name:</strong> <?= htmlspecialchars($customer['name']) ?></p>
<p><strong>Mobile:</strong> <?= htmlspecialchars($customer['mobile']) ?></p>
<?php else: ?>
<div class="alert alert-warning">Customer not found.</div>
<?php endif; ?>
<form method="POST">
<input type="hidden" name="customerId" value="<?= htmlspecialchars($_GET['customerId'] ?? '') ?>">
<div class="mb-3">
<label for="totalAmount" class="form-label">Total Amount:</label>
<input type="number" class="form-control" id="totalAmount" name="totalAmount" required>
</div>
<div class="mb-3">
<label for="tenure" class="form-label">Tenure (Months):</label>
<input type="number" class="form-control" id="tenure" name="tenure" min="1" max="18" required>
</div>
<div class="mb-3">
<label for="firstEmiDate" class="form-label">First EMI Date:</label>
<input type="date" class="form-control" id="firstEmiDate" name="firstEmiDate" required>
</div>
<button type="submit" class="btn btn-primary">Save EMI</button>
</form>
</div>

View File

@@ -0,0 +1,49 @@
<?php
require('../.hta_config/conf.php');
?>
<div class="container mt-4">
<h2 class="mb-3 text-center">Customer List</h2>
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover">
<thead class="thead-dark">
<tr>
<th>Sl No</th>
<th>Name</th>
<th>Mobile</th>
<th>Email</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
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 ORDER BY regDate DESC");
$stmt->execute();
$content = $stmt->fetchAll(PDO::FETCH_ASSOC);
$customerSerial = 1; // Moved outside loop
foreach ($content as $customer) {
?>
<tr>
<td><?php echo $customerSerial++; ?></td>
<td><?php echo htmlspecialchars($customer['name']); ?></td>
<td><?php echo htmlspecialchars($customer['mobile']); ?></td>
<td><?php echo htmlspecialchars($customer['email']); ?></td>
<td>
<a href="/customers/edit/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Edit</a>
<a href="/customers/emi/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Bill</a>
<a href="/customers/billing-details/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Billing Info</a>
</td>
</tr>
<?php
}
} catch (PDOException $e) {
echo '<tr><td colspan="5" class="text-danger text-center">Error: ' . $e->getMessage() . '</td></tr>';
}
?>
</tbody>
</table>
</div>
</div>

View File

@@ -0,0 +1,51 @@
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card shadow-lg">
<div class="card-header bg-primary text-white text-center">
<h4>Customer Registration</h4>
</div>
<div class="card-body">
<?php
require('../.hta_config/conf.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("INSERT INTO customers (name, mobile, email) VALUES (:name, :mobile, :email)");
$stmt->bindParam(':name', $_POST['name']);
$stmt->bindParam(':mobile', $_POST['mobile']);
$stmt->bindParam(':email', $_POST['email']);
if ($stmt->execute()) {
echo '<div class="alert alert-success">New Customer <strong>' . htmlspecialchars($_POST['name']) . '</strong> created successfully.</div>';
} else {
echo '<div class="alert alert-danger">Error executing statement: ' . $stmt->errorInfo()[2] . '</div>';
}
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
}
}
?>
<form method="POST">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" name="name" class="form-control" required>
</div>
<div class="form-group">
<label for="mobile">Mobile:</label>
<input type="text" id="mobile" name="mobile" class="form-control" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" class="form-control" required>
</div>
<button type="submit" class="btn btn-success btn-block mt-2">Save Customer</button>
</form>
</div>
</div>
</div>
</div>
</div>

8
customers/.htaccess Normal file
View File

@@ -0,0 +1,8 @@
RewriteEngine On
#RewriteCond %{HTTPS} !=on
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php

18
customers/index.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
require('../.hta_slug/_header.php');
require('../.hta_slug/_nav.php');
require_once('../.hta_config/var.php');
$url = explode('/', $_SERVER['REQUEST_URI']);
if (strpos($url[1], "?") !== false) {
$url2 = explode('?', $url[1]);
$slug=$url2[0];
} else $slug=$url[2];
require_once('../.hta_slug/_header.php');
if($slug=="") require_once('.hta_slug/_home.php');
elseif(file_exists(".hta_slug/".$slug.".php")) include ".hta_slug/".$slug.".php";
else require_once('.hta_slug/_404.php');
require_once('../.hta_slug/_footer.php');

View File

@@ -0,0 +1 @@
sample-page