From ce1dace3fbdd2546b2562b8a11ba7567f125794c Mon Sep 17 00:00:00 2001 From: Suvodip Date: Tue, 4 Mar 2025 20:24:41 +0530 Subject: [PATCH] s44 --- .hta_slug/_home.php | 6 +- .hta_slug/_nav.php | 9 +++ .hta_slug/login.php | 54 +++++++++++++++ .hta_slug/logout.php | 13 ++++ customers/.hta_slug/new.php | 61 ++++++++++++----- customers/index.php | 31 +++++---- index.php | 1 + my-account/.hta_slug/_404.php | 0 my-account/.hta_slug/_home.php | 94 ++++++++++++++++++++++++++ my-account/.hta_slug/emi-details.php | 99 ++++++++++++++++++++++++++++ my-account/.hta_slug/stat.php | 60 +++++++++++++++++ my-account/.htaccess | 8 +++ my-account/index.php | 19 ++++++ my-account/sample-page.php | 1 + 14 files changed, 426 insertions(+), 30 deletions(-) create mode 100644 .hta_slug/login.php create mode 100644 .hta_slug/logout.php create mode 100644 my-account/.hta_slug/_404.php create mode 100644 my-account/.hta_slug/_home.php create mode 100644 my-account/.hta_slug/emi-details.php create mode 100644 my-account/.hta_slug/stat.php create mode 100644 my-account/.htaccess create mode 100644 my-account/index.php create mode 100644 my-account/sample-page.php diff --git a/.hta_slug/_home.php b/.hta_slug/_home.php index 7fa87fb..a9f36c3 100644 --- a/.hta_slug/_home.php +++ b/.hta_slug/_home.php @@ -1,3 +1,7 @@
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam mollitia quidem sint dolores nostrum, similique nulla consequuntur. Animi neque labore praesentium ratione a? Facere, quasi ea reprehenderit eum tempora voluptatum. -
\ No newline at end of file + + \ No newline at end of file diff --git a/.hta_slug/_nav.php b/.hta_slug/_nav.php index 22da05c..fd6367a 100644 --- a/.hta_slug/_nav.php +++ b/.hta_slug/_nav.php @@ -21,6 +21,15 @@ + diff --git a/.hta_slug/login.php b/.hta_slug/login.php new file mode 100644 index 0000000..dc314b8 --- /dev/null +++ b/.hta_slug/login.php @@ -0,0 +1,54 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $stmt = $db->prepare("SELECT * FROM users WHERE email = :email AND password = :password"); + $stmt->bindParam(':email', $_POST['email'], PDO::PARAM_STR); + $stmt->bindParam(':password', $userPassword, PDO::PARAM_STR); + $stmt->execute(); + + $user = $stmt->fetch(PDO::FETCH_ASSOC); // Fetch a single record + + if ($user) { + $_SESSION['userName'] = $user['name']; + $_SESSION['userEmail'] = $user['email']; + $_SESSION['userType'] = $user['type']; + $_SESSION['isLogedin'] = true; + $_SESSION['customerId'] = $user['customerId']; + var_dump($_SESSION); + echo "Login successful! Welcome, " . htmlspecialchars($user['email']); + // var_dump($_SESSION); + } else { + echo "Invalid email or password."; + } + } catch (PDOException $e) { + echo "Error: " . $e->getMessage(); + } + } +?> + +
+
+

Login

+
+
+ + +
+
+ + +
+
+ + +
+ +
+

Forgot password?

+
+
diff --git a/.hta_slug/logout.php b/.hta_slug/logout.php new file mode 100644 index 0000000..1966a3e --- /dev/null +++ b/.hta_slug/logout.php @@ -0,0 +1,13 @@ + diff --git a/customers/.hta_slug/new.php b/customers/.hta_slug/new.php index 4965541..4a06b8f 100644 --- a/customers/.hta_slug/new.php +++ b/customers/.hta_slug/new.php @@ -6,28 +6,41 @@

Customer Registration

- setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - 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']); + $stmt = $db->prepare("INSERT INTO customers (name, mobile, email, customerId) VALUES (:name, :mobile, :email, :customerId)"); + $stmt->bindParam(':name', $_POST['name']); + $stmt->bindParam(':mobile', $_POST['mobile']); + $stmt->bindParam(':email', $_POST['email']); + $stmt->bindParam(':customerId', $customerId); - if ($stmt->execute()) { - echo '
New Customer ' . htmlspecialchars($_POST['name']) . ' created successfully.
'; - } else { - echo '
Error executing statement: ' . $stmt->errorInfo()[2] . '
'; - } - } catch (PDOException $e) { - echo '
Error: ' . $e->getMessage() . '
'; + $stmt2 = $db->prepare("INSERT INTO users (name, mobile, email, type, password, customerId) VALUES (:name, :mobile, :email, :type, :password, :customerId)"); + $stmt2->bindParam(':name', $_POST['name']); + $stmt2->bindParam(':mobile', $_POST['mobile']); + $stmt2->bindParam(':email', $_POST['email']); + $stmt2->bindParam(':type', $_POST['type']); + $stmt2->bindParam(':password', $userPassword); + $stmt2->bindParam(':customerId', $customerId); + + if ($stmt->execute()) { + $stmt2->execute(); + echo '
New Customer ' . htmlspecialchars($_POST['name']) . ' created successfully.
'; + } else { + echo '
Error inserting into customers table: ' . $stmt->errorInfo()[2] . '
'; } + } catch (PDOException $e) { + echo '
Error: ' . $e->getMessage() . '
'; } + } ?> +
@@ -42,6 +55,20 @@
+ +
+ + +
+ +
+ + +
diff --git a/customers/index.php b/customers/index.php index b39e111..fb1a445 100644 --- a/customers/index.php +++ b/customers/index.php @@ -1,18 +1,25 @@ +
+

Customer List

+
+ + + + + + + + + + + + + + + setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // Fetch customer data + $stmt = $db->prepare("SELECT * FROM customers WHERE customerId = :customerId ORDER BY regDate DESC"); + $stmt->bindParam(':customerId', $_SESSION['customerId']); + $stmt->execute(); + $content = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // Fetch invoice data + $stmt2 = $db->prepare("SELECT * FROM invoice"); + $stmt2->execute(); + $invoiceContent = $stmt2->fetchAll(PDO::FETCH_ASSOC); + + // Loop through each customer + $customerSerial = 1; + foreach ($content as $customer) { + // Find all invoices for the current customer + $matchingInvoices = array_filter($invoiceContent, function ($invoice) use ($customer) { + return $invoice['customerId'] === $customer['customerId']; + }); + + // If there are matching invoices, loop through them + if (!empty($matchingInvoices)) { + foreach ($matchingInvoices as $invoice) { + ?> + + + + + + + + + + + + + + + + + + + + + + + '; + } + ?> + + + +
Sl NoNameMobileEmailInvoice IdInvoice DateAmountAction
+ EMI Details + Print +
No invoice available + EMI Details +
Error: ' . $e->getMessage() . '
+
+
diff --git a/my-account/.hta_slug/emi-details.php b/my-account/.hta_slug/emi-details.php new file mode 100644 index 0000000..8cb9a31 --- /dev/null +++ b/my-account/.hta_slug/emi-details.php @@ -0,0 +1,99 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + 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; + } + + // Fetch EMI data + $stmt = $db->prepare("SELECT * FROM emi WHERE customerId = :customerId AND invoiceId = :invoiceId ORDER BY emiDate ASC"); + $stmt->bindParam(':customerId', $_GET['customerId']); + $stmt->bindParam(':invoiceId', $_GET['invoiceId']); + $stmt->execute(); + $emiPlans = $stmt->fetchAll(PDO::FETCH_ASSOC); + // var_dump($emiPlans); + + $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() . '
'); +} +?> +
+

EMI Details

+
+
+

Customer Name:

+

Mobile Number:

+

EMI Booking Date:

+

EMI Booking Date:

+
+
+ +

Total Amount:

+

Outstanding:

+

Tenure:

+

Frequency:

+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
Number of EMIEMI AmountEMI DatePayment StatusOutstanding
+ + + +
+
\ No newline at end of file diff --git a/my-account/.hta_slug/stat.php b/my-account/.hta_slug/stat.php new file mode 100644 index 0000000..63d9956 --- /dev/null +++ b/my-account/.hta_slug/stat.php @@ -0,0 +1,60 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $currentMonth = date('Y-m'); + $stmt = $db->prepare(" SELECT e.customerId, c.name, e.emiAmount, e.emiDate, e.payStatus, e.outstanding FROM emi e JOIN customers c ON e.customerId = c.customerId WHERE DATE_FORMAT(e.emiDate, '%Y-%m') = :currentMonth ORDER BY e.emiDate ASC"); + $stmt->bindParam(':currentMonth', $currentMonth); + $stmt->execute(); + $emiPlans = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // Calculate total demand amount + $totalDemand = array_sum(array_column($emiPlans, 'emiAmount')); +} catch (PDOException $e) { + die("Database error: " . $e->getMessage()); +} +?> +
+

Pending EMIs for

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Customer NameEMI AmountEMI DatePay StatusOutstanding
+ + Pending + + Paid + +
No pending EMIs this month
+ +
+

Total Demand EMI Amount: ₹

+
+ +
diff --git a/my-account/.htaccess b/my-account/.htaccess new file mode 100644 index 0000000..ffcc268 --- /dev/null +++ b/my-account/.htaccess @@ -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 diff --git a/my-account/index.php b/my-account/index.php new file mode 100644 index 0000000..4e02cb1 --- /dev/null +++ b/my-account/index.php @@ -0,0 +1,19 @@ +