From 881c48d5bb3eaa40ff6df054a04a97becf2442e1 Mon Sep 17 00:00:00 2001 From: Suvodip Date: Fri, 7 Mar 2025 16:49:09 +0530 Subject: [PATCH] s11 --- .hta_slug/_nav.php | 2 +- admin/.hta_slug/stat.php | 137 ++++++--- admin/index.php | 3 +- customers/.hta_slug/additional-payment.php | 86 ++++++ customers/.hta_slug/billing-details.php | 290 ++++++++++++------ customers/.hta_slug/edit-invoice.php | 325 +++++++++++++++++++++ customers/.hta_slug/generate-invoice.php | 6 +- customers/.hta_slug/list.php | 38 ++- customers/.hta_slug/new.php | 78 +++-- customers/.hta_slug/print-invoice.php | 8 +- info.txt | 1 + my-account/.hta_slug/emi-details.php | 4 +- my-account/.hta_slug/print-invoice.php | 11 +- 13 files changed, 800 insertions(+), 189 deletions(-) create mode 100644 customers/.hta_slug/additional-payment.php create mode 100644 customers/.hta_slug/edit-invoice.php create mode 100644 info.txt diff --git a/.hta_slug/_nav.php b/.hta_slug/_nav.php index e47e7cc..e1f194d 100644 --- a/.hta_slug/_nav.php +++ b/.hta_slug/_nav.php @@ -20,7 +20,7 @@ Customer List '; diff --git a/admin/.hta_slug/stat.php b/admin/.hta_slug/stat.php index 63d9956..c739963 100644 --- a/admin/.hta_slug/stat.php +++ b/admin/.hta_slug/stat.php @@ -4,9 +4,36 @@ require('../.hta_config/conf.php'); try { $db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass); $db->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); + + // Ensure the URL parameters work with or without trailing slash + $uri = $_SERVER['REQUEST_URI']; + parse_str(parse_url($uri, PHP_URL_QUERY), $queryParams); + + // Default values: current month + $currentYear = date('Y'); + $currentMonth = date('m'); + $currentMonthStart = date('Y-m-01'); + $currentMonthEnd = date('Y-m-t'); + + // Extract query parameters + $startDate = isset($queryParams['start_date']) ? $queryParams['start_date'] : $currentMonthStart; + $endDate = isset($queryParams['end_date']) ? $queryParams['end_date'] : $currentMonthEnd; + $selectedMonth = isset($queryParams['month']) ? $queryParams['month'] : "$currentYear-$currentMonth"; + + // If month is selected, override date range + if (isset($queryParams['month']) && preg_match('/^\d{4}-\d{2}$/', $selectedMonth)) { + $startDate = date('Y-m-01', strtotime($selectedMonth)); + $endDate = date('Y-m-t', strtotime($selectedMonth)); + } + + // Validate date format + if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $startDate) || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $endDate)) { + die("Invalid date format. Please use YYYY-MM-DD."); + } + + $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 e.emiDate BETWEEN :startDate AND :endDate ORDER BY e.emiDate ASC"); + $stmt->bindParam(':startDate', $startDate); + $stmt->bindParam(':endDate', $endDate); $stmt->execute(); $emiPlans = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -16,45 +43,73 @@ try { die("Database error: " . $e->getMessage()); } ?> -
-

Pending EMIs for

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

Total Demand EMI Amount: ₹

+ +
+

Pending EMIs ()

+ + +
+
+ + +
+
+ OR +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Customer NameEMI AmountEMI DatePay StatusOutstanding
$ + + Pending + + Paid + + $
No pending EMIs in this period
+ +
+

Total Demand EMI Amount: $

+
diff --git a/admin/index.php b/admin/index.php index b39e111..7d5cf99 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,4 +1,5 @@ + +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + if($_SERVER['REQUEST_METHOD'] === 'POST'){ + + try{ + $stmt3 = $db->prepare("INSERT INTO emi (customerId, invoiceId, adPaymentAmount, adPaymentDate, adPaymentSource, adPaymentTran, adPaymentRemarks, payStatus) VALUES (:customerId, :invoiceId, :adPaymentAmount, :adPaymentDate, :adPaymentSource, :adPaymentTran, :adPaymentRemarks, 1)"); + $stmt3->bindParam(':customerId', $_GET['customerId']); + $stmt3->bindParam(':invoiceId', $_GET['invoiceId']); + $stmt3->bindParam(':adPaymentAmount', $_POST['adPaymentAmount']); + $stmt3->bindParam(':adPaymentDate', $_POST['adPaymentDate']); + $stmt3->bindParam(':adPaymentSource', $_POST['adPaymentSource']); + $stmt3->bindParam(':adPaymentTran', $_POST['adPaymentTran']); + $stmt3->bindParam(':adPaymentRemarks', $_POST['adPaymentRemarks']); + if($stmt3->execute()){ + echo '
Additional Payment ' . htmlspecialchars($_POST['adPaymentAmount']) . ' Paid Successfully.
'; + }else{ + echo '
Additional Payment ' . htmlspecialchars($_POST['adPaymentAmount']) . ' Payment Faild.
'; + } + } catch(PDOException $e){ + echo '
Error: ' . $e->getMessage() . '
'; + } + + } + try { + $stmt = $db->prepare("SELECT * FROM invoice WHERE customerId = :customerId"); + $stmt->bindParam(':customerId', $_GET['customerId']); + $stmt->execute(); + $invoiceData = $stmt->fetch(PDO::FETCH_ASSOC); + + $stmt2 = $db->prepare("SELECT * FROM emi WHERE customerId = :customerId"); + $stmt2->bindParam(':customerId', $_GET['customerId']); + $stmt2->execute(); + $emiData = $stmt2->fetch(PDO::FETCH_ASSOC); + + // var_dump($emiData); + } catch (PDOException $e) { + echo '
Error: ' . $e->getMessage() . '
'; + } +?> + +
+
+
+
+
+

Additional Payment

+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+ \ No newline at end of file diff --git a/customers/.hta_slug/billing-details.php b/customers/.hta_slug/billing-details.php index fb48388..1176940 100644 --- a/customers/.hta_slug/billing-details.php +++ b/customers/.hta_slug/billing-details.php @@ -1,108 +1,226 @@ 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()]); + + if($_SERVER['REQUEST_METHOD'] === 'POST'){ + try{ + $stmt3 = $db->prepare("INSERT INTO emi (customerId, invoiceId, adPaymentAmount, adPaymentDate, adPaymentSource, adPaymentTran, adPaymentRemarks, payStatus) VALUES (:customerId, :invoiceId, :adPaymentAmount, :adPaymentDate, :adPaymentSource, :adPaymentTran, :adPaymentRemarks, 1)"); + $stmt3->bindParam(':customerId', $_GET['customerId']); + $stmt3->bindParam(':invoiceId', $_GET['invoiceId']); + $stmt3->bindParam(':adPaymentAmount', $_POST['adPaymentAmount']); + $stmt3->bindParam(':adPaymentDate', $_POST['adPaymentDate']); + $stmt3->bindParam(':adPaymentSource', $_POST['adPaymentSource']); + $stmt3->bindParam(':adPaymentTran', $_POST['adPaymentTran']); + $stmt3->bindParam(':adPaymentRemarks', $_POST['adPaymentRemarks']); + if($stmt3->execute()){ + echo '
Additional Payment ' . htmlspecialchars($_POST['adPaymentAmount']) . ' Paid Successfully.
'; + }else{ + echo '
Additional Payment ' . htmlspecialchars($_POST['adPaymentAmount']) . ' Payment Faild.
'; + } + } catch(PDOException $e){ + echo '
Error: ' . $e->getMessage() . '
'; + } } + try { + $stmt = $db->prepare("SELECT * FROM invoice WHERE customerId = :customerId"); + $stmt->bindParam(':customerId', $_GET['customerId']); + $stmt->execute(); + $invoiceData = $stmt->fetch(PDO::FETCH_ASSOC); - exit; - } + $stmt2 = $db->prepare("SELECT * FROM emi WHERE customerId = :customerId"); + $stmt2->bindParam(':customerId', $_GET['customerId']); + $stmt2->execute(); + $emiData = $stmt2->fetch(PDO::FETCH_ASSOC); - // 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); + // var_dump($emiData); + } catch (PDOException $e) { + echo '
Error: ' . $e->getMessage() . '
'; + } + + 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()]); + } + } + try { + // 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() . '
'); -} + $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() . '
'); + } + + $currentOutstanding = 0; + $totalAmount = 0; + $bookingDate = null; + $currentOutstanding = 0; + $totalAmount = 0; + $bookingDate = null; + $tenure = null; + $frequency = null; + + foreach ($emiPlans as $emi) { + $totalAmount = $emi['totalAmount']; + if ($bookingDate === null && !empty($emi['bookingDate'])) { + $bookingDate = $emi['bookingDate']; + } + if ($emi['payStatus'] == 0) { + $currentOutstanding += $emi['emiAmount']; + } + if ($tenure === null && isset($emi['tenure'])) { + $tenure = $emi['tenure']; + } + if ($frequency === null && isset($emi['frequency'])) { + $frequency = $emi['frequency']; + } + } + $currentOutstanding = round($currentOutstanding); + $tenure = $tenure !== null ? $tenure : 0; + $frequency = $frequency !== null ? $frequency : 0; ?>
-

EMI Details

+

EMI Details

Customer Name:

Mobile Number:

-

EMI Booking Date:

-

EMI Booking Date:

+

EMI Booking Date:

+

Invoice Id:

- -

Total Amount:

-

Outstanding:

-

Tenure:

-

Frequency:

+

Total Amount: $

+

Outstanding: $

+

Tenure:

+

Frequency:

+
-
- - - - - - - - - - - - - - - - - - - - +
+
+
Number of EMIEMI AmountEMI DatePayment StatusOutstandingAction
- - - - - -
+ + + + + + + + - - -
Number of EMIEMI AmountEMI DatePayment StatusOutstandingAction
+ + + + + + $ + + + + + + + $ + + + + + + + + +

Additional Payment Details

+ + + + + + + + + + + + + + + + + + + +
AmountPayment DateTransaction IdPayment Status
$ + + + +
+ + + +
+
'; + } catch (PDOException $e) { + echo '
Error: ' . $e->getMessage() . '
'; + } + } + $invoiceData = 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 invoice WHERE customerId = :customerId"); + $stmt->bindParam(':customerId', $_GET['customerId']); + $stmt->execute(); + $invoiceData = $stmt->fetch(PDO::FETCH_ASSOC); + $invoiceDate = date('Y-m-d', strtotime($invoiceData['invoiceDate'])); + } catch (PDOException $e) { + echo '
Error: ' . $e->getMessage() . '
'; + } + } +?> + + +
+

Create New Invoice

+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+
+
+ + +
+
+
+
+
+ + +
+
+ + +
+
+ + +
+ "One Time","3" => "3","6" => "6","9" => "9","12" => "12","0" => "Custom" ]; + $selectedTenure = $invoiceData['tenure'] ?? ''; // Get selected tenure value + ?> + +
+ + + +
+ +
+ + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
ItemDescriptionQtyRateTax % Tax AmountAmount
+ + + + + + + + + + + + + +
+
+
+
+ + + Print Invoice +
+
+ +
+
+ \ No newline at end of file diff --git a/customers/.hta_slug/generate-invoice.php b/customers/.hta_slug/generate-invoice.php index a6bdda4..b9abbf8 100644 --- a/customers/.hta_slug/generate-invoice.php +++ b/customers/.hta_slug/generate-invoice.php @@ -105,9 +105,9 @@ $customerAddress = $stmt->fetch(PDO::FETCH_ASSOC); } - $stmt = $db->query("SELECT id FROM invoice ORDER BY id DESC LIMIT 1"); + $stmt = $db->query("SELECT id FROM invoice WHERE DATE(invoiceDate) = CURDATE() ORDER BY id DESC LIMIT 1"); $lastInvoice = $stmt->fetch(PDO::FETCH_ASSOC); - $invoiceId = "ASDQ-" . ($lastInvoice ? ($lastInvoice['id'] + 1) : '1'); + $invoiceId = "CB" . date('my') . ($lastInvoice ? ($lastInvoice['id'] + 1) : '1'); $stmt = $db->query("SELECT invoiceId FROM invoice ORDER BY id DESC LIMIT 1"); $lastInvoicePrint = $stmt->fetch(PDO::FETCH_ASSOC); @@ -136,7 +136,7 @@
- +
diff --git a/customers/.hta_slug/list.php b/customers/.hta_slug/list.php index b4e0862..7da7637 100644 --- a/customers/.hta_slug/list.php +++ b/customers/.hta_slug/list.php @@ -5,15 +5,16 @@

Customer List

- + - - - - - + + + + + + @@ -48,20 +49,22 @@ ?> - - - + + + - + Customer Registration
- setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $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); + $stmt = $db->prepare("INSERT INTO customers (name, mobile, email, customerId, company, address, sallery) VALUES (:name, :mobile, :email, :customerId, :company, :address, :sallery)"); + $stmt->bindParam(':name', $_POST['name']); + $stmt->bindParam(':mobile', $_POST['mobile']); + $stmt->bindParam(':email', $_POST['email']); + $stmt->bindParam(':company', $_POST['jobCompany']); + $stmt->bindParam(':address', $_POST['billingAddress']); + $stmt->bindParam(':sallery', $_POST['sallery']); + $stmt->bindParam(':customerId', $customerId); - $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); + $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] . '
'; + 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() . '
'; } - } catch (PDOException $e) { - echo '
Error: ' . $e->getMessage() . '
'; } - } ?>
- +
- +
@@ -56,6 +59,21 @@
+
+ + +
+ +
+ + +
+ +
+ + +
+
- - + +
Sl No NameMobileEmailInvoice IdInvoice DateAmountPayment Start DatePayment End DateNumber of InstallmentsMonthly Payment DateMonthly Payment AmountTotoal Amount Action
$ $ - Edit - Create Invoice - EMI Details - Print + + New Invoice + Edit Invoice + + + Payment
No invoice available - Edit + + Create Invoice - EMI Details + + Additional Payment +
%$$
@@ -79,8 +79,8 @@ if ($invoiceInfo['tenure'] > 1) { - ₹ - ₹ + $ + $ Paid' : 'Pending' ?> diff --git a/info.txt b/info.txt new file mode 100644 index 0000000..92187d0 --- /dev/null +++ b/info.txt @@ -0,0 +1 @@ +http://localhost:2056/customers/billing-details/?customerId=cust_67c9925ff14f4834489101&invoiceId=CB03251 ? Additional Amount. \ No newline at end of file diff --git a/my-account/.hta_slug/emi-details.php b/my-account/.hta_slug/emi-details.php index 8cb9a31..763c5a1 100644 --- a/my-account/.hta_slug/emi-details.php +++ b/my-account/.hta_slug/emi-details.php @@ -84,14 +84,14 @@ try { - ₹ + $ - ₹ + $ diff --git a/my-account/.hta_slug/print-invoice.php b/my-account/.hta_slug/print-invoice.php index c50dbe8..504d2d6 100644 --- a/my-account/.hta_slug/print-invoice.php +++ b/my-account/.hta_slug/print-invoice.php @@ -55,12 +55,13 @@ if ($invoiceInfo['tenure'] > 1) { % - ₹ - ₹ + $ + $ - + 1): ?>

EMI Payment Plan

@@ -79,8 +80,8 @@ if ($invoiceInfo['tenure'] > 1) { - ₹ - ₹ + $ + $ Paid' : 'Pending' ?>