From 11187345d5b93a4e6db875a02e5ec3611e976c32 Mon Sep 17 00:00:00 2001 From: Suvodip Date: Sat, 1 Mar 2025 18:55:53 +0530 Subject: [PATCH] s22 --- .hta_slug/_nav.php | 2 +- customers/.hta_slug/billing-details.php | 5 +- customers/.hta_slug/generate-invoice.php | 279 ++++++++++++++++++----- customers/.hta_slug/list.php | 71 +++++- customers/.hta_slug/new.php | 2 +- customers/.hta_slug/print-invoice.php | 130 ++++++++++- 6 files changed, 411 insertions(+), 78 deletions(-) diff --git a/.hta_slug/_nav.php b/.hta_slug/_nav.php index b002639..adbf370 100644 --- a/.hta_slug/_nav.php +++ b/.hta_slug/_nav.php @@ -7,7 +7,7 @@
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']; + $salesAgent = $_POST['salesAgent']; + $adminNote = $_POST['adminNote']; + $invoiceId = $_POST['invoiceId']; + $customerName = $_POST['customerName']; + $customerAddress = $_POST['customerAddress']; + $marketingAgent = $_POST['marketingAgent']; + $item = $_POST['item']; + $description = $_POST['description']; + $quantity = $_POST['quantity']; + $rate = $_POST['rate']; + $tax = $_POST['tax']; + $taxAmount = $_POST['taxAmount']; + + + // EMI Calculation - $emiAmount = round($totalAmount / $tenure, 2); - $outstandingAmount = $totalAmount; - $emiDate = new DateTime($firstEmiDate); // Set initial date + $emiAmount = round($totalAmount / $tenure, 2); + $outstandingAmount = $totalAmount; + $emiDate = new DateTime($bookingDate); // Set initial date - $stmt = $db->prepare("INSERT INTO emi (customerId, emiNumber, emiAmount, emiDate, totalAmount, outstanding, tenure, frequency, bookingDate, paymentMode, salesAgent) VALUES (:customerId, :emiNumber, :emiAmount, :emiDate, :totalAmount, :outstanding, :tenure, :frequency, bookingDate, :paymentMode, :salesAgent)"); - - 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->bindParam(':salesAgent', $salesAgent); - $stmt->execute(); - - // Move to the next month's EMI date - if($frequency === 'Weekly'){ - $emiDate->modify('+1 week'); - } elseif($frequency === 'Monthly'){ - $emiDate->modify('+1 month'); - } + $stmt = $db->prepare("INSERT INTO emi (customerId, emiNumber, emiAmount, emiDate, totalAmount, outstanding, tenure, frequency, bookingDate, invoiceId) VALUES (:customerId, :emiNumber, :emiAmount, :emiDate, :totalAmount, :outstanding, :tenure, :frequency, :bookingDate, :invoiceId)"); + 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(':invoiceId', $invoiceId); + $stmt->execute(); + // Move to the next EMI date + if (trim(strtolower($frequency)) === 'weekly') { + $emiDate->modify('+1 week'); + } elseif (trim(strtolower($frequency)) === 'monthly') { + $emiDate->modify('+1 month'); } + } + + // Insert into invoice table + $stmt2 = $db->prepare("INSERT INTO invoice (customerId, invoiceId, customerName, address, frequency, invoiceDate, paymentMode, salesAgent, marketingAgent, tenure, item, description, qty, rate, tax, totalAmount, adminNote, taxAmount) VALUES (:customerId, :invoiceId, :customerName, :address, :frequency, :invoiceDate, :paymentMode, :salesAgent, :marketingAgent, :tenure, :item, :description, :qty, :rate, :tax, :totalAmount, :adminNote, :taxAmount)"); + $stmt2->bindParam(':customerId', $_GET['customerId']); + $stmt2->bindParam(':invoiceId', $invoiceId); + $stmt2->bindParam(':customerName', $customerName); + $stmt2->bindParam(':address', $customerAddress); + $stmt2->bindParam(':frequency', $frequency); + $stmt2->bindParam(':invoiceDate', $bookingDate); + $stmt2->bindParam(':paymentMode', $paymentMode); + $stmt2->bindParam(':salesAgent', $salesAgent); + $stmt2->bindParam(':marketingAgent', $marketingAgent); + $stmt2->bindParam(':tenure', $tenure); + $stmt2->bindParam(':item', $item); + $stmt2->bindParam(':description', $description); + $stmt2->bindParam(':qty', $quantity); + $stmt2->bindParam(':rate', $rate); + $stmt2->bindParam(':tax', $tax); + $stmt2->bindParam(':totalAmount', $totalAmount); + $stmt2->bindParam(':adminNote', $adminNote); + $stmt2->bindParam(':taxAmount', $taxAmount); + $stmt2->execute(); + echo '
New EMI Plan Saved Successfully!
'; + echo ''; } catch (PDOException $e) { echo '
Error: ' . $e->getMessage() . '
'; } } - $customer = null; if (!empty($_GET['customerId'])) { try { @@ -67,6 +104,13 @@ $customerAddress = $stmt->fetch(PDO::FETCH_ASSOC); } + $stmt = $db->query("SELECT id FROM invoice ORDER BY id DESC LIMIT 1"); + $lastInvoice = $stmt->fetch(PDO::FETCH_ASSOC); + $invoiceId = "ASDQ-" . ($lastInvoice ? ($lastInvoice['id'] + 1) : '1'); + + $stmt = $db->query("SELECT invoiceId FROM invoice ORDER BY id DESC LIMIT 1"); + $lastInvoicePrint = $stmt->fetch(PDO::FETCH_ASSOC); + // $invoiceIdPrint = "ASDQ-" . ($lastInvoice ? ($lastInvoice['id'] + 1) : '1'); } catch (PDOException $e) { echo '
Error: ' . $e->getMessage() . '
'; @@ -74,29 +118,24 @@ } ?> +
-

Create Invoice

- - -

Mobile:

- -
Customer not found.
- - +

Create New Invoice

+
- - + +
- - + +
- - + +
@@ -110,11 +149,7 @@
- -
-
- - +
@@ -126,14 +161,7 @@ - -
-
- -
@@ -145,17 +173,146 @@
- - + + + +
+
+ + + +
+
+ +
- +
+ + + + + + + + + + + + + + + + + + + + + + + +
ItemDescriptionQtyRateTax % Tax AmountAmount
+ + + + + + + + + + + + + +
+
+
+
+ + + Print Invoice +
+
+
+ \ No newline at end of file diff --git a/customers/.hta_slug/list.php b/customers/.hta_slug/list.php index 4603712..b4e0862 100644 --- a/customers/.hta_slug/list.php +++ b/customers/.hta_slug/list.php @@ -11,39 +11,86 @@ Name Mobile Email + Invoice Id + Invoice Date + Amount Action setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // Fetch customer data $stmt = $db->prepare("SELECT * FROM customers ORDER BY regDate DESC"); $stmt->execute(); $content = $stmt->fetchAll(PDO::FETCH_ASSOC); - $customerSerial = 1; // Moved outside loop + // 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) { ?> - - - - - - - Edit - Invoice - Installment Details - - + + + + + + + + + + + + + Edit + Create Invoice + EMI Details + Print + + + + + + + + No invoice available + + Edit + Create Invoice + EMI Details + + + Error: ' . $e->getMessage() . ''; } ?> + + diff --git a/customers/.hta_slug/new.php b/customers/.hta_slug/new.php index a0f4609..4965541 100644 --- a/customers/.hta_slug/new.php +++ b/customers/.hta_slug/new.php @@ -48,4 +48,4 @@ - \ No newline at end of file + diff --git a/customers/.hta_slug/print-invoice.php b/customers/.hta_slug/print-invoice.php index 162eb43..c50dbe8 100644 --- a/customers/.hta_slug/print-invoice.php +++ b/customers/.hta_slug/print-invoice.php @@ -1,4 +1,132 @@ \ No newline at end of file +$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 AND invoiceId = :invoiceId"); +$stmt->bindParam(':customerId', $_GET['customerId']); +$stmt->bindParam(':invoiceId', $_GET['invoiceId']); +$stmt->execute(); +$invoiceInfo = $stmt->fetch(PDO::FETCH_ASSOC); + +$emiPlans = []; +if ($invoiceInfo['tenure'] > 1) { + $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); +} +?> + +
+
+

Invoice


+
+
+
Invoice ID:
+
Customer:
+

Address:

+
+
+
Invoice Date:
+
Payment Mode:
+

Agent:

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
ItemDescriptionQtyRateTax(%)TaxTotal
%
+ + + 1): ?> +

EMI Payment Plan

+ + + + + + + + + + + + + + + + + + + + + +
EMI No.EMI DateEMI AmountOutstandingStatus
+ Paid' : 'Pending' ?> +
+ + +

Admin Note:

+ + + +
+
+ +