Suvodip 2025-03-08 17:01:20 +05:30
parent e97d30ce72
commit b813a79fe8
7 changed files with 229 additions and 126 deletions

View File

@ -24,7 +24,6 @@
} catch(PDOException $e){
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
}
}
try {
$stmt = $db->prepare("SELECT * FROM invoice WHERE customerId = :customerId");

View File

@ -3,32 +3,85 @@
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->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 '<div class="alert alert-success">Additional Payment <strong>' . htmlspecialchars($_POST['adPaymentAmount']) . '</strong> Paid Successfully.</div>';
}else{
echo '<div class="alert alert-danger">Additional Payment <strong>' . htmlspecialchars($_POST['adPaymentAmount']) . '</strong> Payment Faild.</div>';
}
} catch(PDOException $e){
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$stmt = $db->prepare("SELECT * FROM invoice WHERE customerId = :customerId");
// Get customer EMI details
$customerId = $_GET['customerId'];
$invoiceId = $_GET['invoiceId'];
$adPaymentAmount = floatval($_POST['adPaymentAmount']);
$adPaymentDate = $_POST['adPaymentDate'];
$adPaymentSource = $_POST['adPaymentSource'];
$adPaymentTran = $_POST['adPaymentTran'];
$adPaymentRemarks = $_POST['adPaymentRemarks'];
// Fetch EMIs of the customer (Assuming we have emiNumber in ascending order)
$stmt = $db->prepare("SELECT * FROM emi WHERE customerId = :customerId AND invoiceId = :invoiceId ORDER BY emiNumber DESC");
$stmt->bindParam(':customerId', $customerId);
$stmt->bindParam(':invoiceId', $invoiceId);
$stmt->execute();
$emiRecords = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!$emiRecords) {
echo '<div class="alert alert-danger">No EMI records found.</div>';
exit;
}
$remainingAmount = $adPaymentAmount;
foreach ($emiRecords as $index => &$emi) {
if ($remainingAmount <= 0) break;
$emiId = $emi['id'];
$emiAmount = floatval($emi['emiAmount']);
if ($remainingAmount >= $emiAmount) {
// If additional amount is greater or equal to EMI, pay it off
$payAmount = $emiAmount;
$remainingAmount -= $emiAmount;
$newEmiAmount = 0; // EMI is fully paid
} else {
// If additional amount is less than EMI, reduce this EMI
$payAmount = $remainingAmount;
$newEmiAmount = $emiAmount - $remainingAmount;
$remainingAmount = 0; // No more amount left to deduct
}
// Update EMI record with reduced amount
$updateStmt = $db->prepare("UPDATE emi SET emiAmount = :newEmiAmount, payStatus = CASE WHEN emiAmount = 0 THEN 1 ELSE 0 END WHERE id = :emiId");
$updateStmt->bindParam(':newEmiAmount', $newEmiAmount);
$updateStmt->bindParam(':emiId', $emiId);
$updateStmt->execute();
}
// Insert additional payment record
$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', $customerId);
$stmt3->bindParam(':invoiceId', $invoiceId);
$stmt3->bindParam(':adPaymentAmount', $adPaymentAmount);
$stmt3->bindParam(':adPaymentDate', $adPaymentDate);
$stmt3->bindParam(':adPaymentSource', $adPaymentSource);
$stmt3->bindParam(':adPaymentTran', $adPaymentTran);
$stmt3->bindParam(':adPaymentRemarks', $adPaymentRemarks);
if ($stmt3->execute()) {
echo '<div class="alert alert-success">Additional Payment <strong>' . htmlspecialchars($_POST['adPaymentAmount']) . '</strong> applied successfully.</div>';
} else {
echo '<div class="alert alert-danger">Failed to record the additional payment.</div>';
}
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
}
}
try {
$stmt = $db->prepare("SELECT * FROM invoice WHERE customerId = :customerId AND invoiceId = :invoiceId");
$stmt->bindParam(':invoiceId', $_GET['invoiceId']);
$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();
@ -48,11 +101,16 @@
$stmt->bindParam(':payStatus', $_POST['payStatus'], PDO::PARAM_INT);
$stmt->bindParam(':emiId', $_POST['emiId'], PDO::PARAM_INT);
$stmt->execute();
// Ensure no previous output before JSON
echo json_encode(['status' => 'success']);
exit; // Terminate script after sending JSON
} catch (PDOException $e) {
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
exit;
}
}
try {
// Fetch EMI data
$stmt = $db->prepare("SELECT * FROM emi WHERE customerId = :customerId AND invoiceId = :invoiceId ORDER BY emiDate ASC");
@ -113,7 +171,7 @@
<p>Total Amount: <strong>$<?php echo $totalAmount; ?></strong></p>
<p>Outstanding: <strong>$<?php echo $currentOutstanding; ?></strong></p>
<p>Tenure: <strong><?php echo $tenure; ?></strong></p>
<p>Frequency: <strong><?php echo $frequency; ?></strong></p>
<p>Frequency: <strong><?php echo $invoiceData['frequency'] ?></strong></p>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#myModal">Additional Payment</button>
</div>
</div>
@ -126,7 +184,6 @@
<th>EMI Amount</th>
<th>EMI Date</th>
<th>Payment Status</th>
<th>Outstanding</th>
<th>Action</th>
</tr>
</thead>
@ -141,7 +198,6 @@
<?= $emi['payStatus'] == 0 ? 'Unpaid' : 'Paid'; ?>
</span>
</td>
<td>$<?= number_format($emi['outstanding'], 2); ?></td>
<td>
<select class="form-select paymentStatus" data-emi-id="<?= $emi['id']; ?>">
<option value="1" <?= $emi['payStatus'] == 1 ? 'selected' : ''; ?>>Paid</option>
@ -153,7 +209,7 @@
</tbody>
</table>
<?php
if($emiPlans[0]['adPaymentAmount'] !== null) { ?>
if($emiPlans[0]['adPaymentAmount'] > 0 ) { ?>
<h3 class="mb-3">Additional Payment Details</h3>
<table class="table table-striped table-bordered">
<thead class="bg-primary text-white text-center">
@ -161,20 +217,16 @@
<th>Amount</th>
<th>Payment Date</th>
<th>Transaction Id</th>
<th>Payment Status</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<?php foreach ($emiPlans as $emi) { if($emi['emiAmount'] === null) { ?>
<?php foreach ($emiPlans as $emi) { if($emi['adPaymentAmount'] !== null && $emi['emiAmount'] == 0) { ?>
<tr id="row-<?= $emi['id']; ?>">
<td>$<?= $emi['adPaymentAmount']; ?></td>
<td><?= $emi['adPaymentDate']; ?></td>
<td><?= $emi['adPaymentTran']; ?></td>
<td>
<span id="status-<?= $emi['id']; ?>" class="badge <?= $emi['payStatus'] == 0 ? 'bg-danger' : 'bg-success'; ?>">
<?= $emi['payStatus'] == 0 ? 'Unpaid' : 'Paid'; ?>
</span>
</td>
<td><?= $emi['adPaymentRemarks']; ?></td>
</tr>
<?php } }?>
</tbody>
@ -192,7 +244,7 @@
<form method="POST" class="">
<div class="form-group">
<label for="adPaymentAmount">Payment Amount:</label>
<input type="text" id="adPaymentAmount" name="adPaymentAmount" class="form-control" value="<?= $emiData['emiAmount']; ?>" required>
<input oninput="addAutoAddRemarks();" type="text" id="adPaymentAmount" name="adPaymentAmount" class="form-control" value="<?= htmlspecialchars($emiData['emiAmount']); ?>" required>
</div>
<div class="form-group">
<label for="adPaymentDate">Payment Date:</label>
@ -223,12 +275,12 @@
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll(".paymentStatus").forEach(select => {
select.addEventListener("change", function() {
select.addEventListener("change", function () {
let emiId = this.getAttribute("data-emi-id");
let newStatus = this.value;
fetch(window.location.href, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
@ -236,14 +288,30 @@
})
.then(response => response.json())
.then(data => {
console.log(data); // Debugging output
if (data.status === "success") {
let statusBadge = document.getElementById("status-" + emiId);
statusBadge.textContent = newStatus == 1 ? "Paid" : "Unpaid";
statusBadge.className = "badge " + (newStatus == 1 ? "bg-success" : "bg-danger");
if (statusBadge) {
statusBadge.textContent = newStatus == 1 ? "Paid" : "Unpaid";
statusBadge.className = "badge " + (newStatus == 1 ? "bg-success" : "bg-danger");
}
} else {
alert("Error updating status: " + data.message);
}
})
.catch(error => console.error("Error:", error));
});
});
});
</script>
function addAutoAddRemarks() {
const emiAmount = <?= json_encode($emiData['emiAmount']); ?>;
const addPayAmount = parseFloat(document.getElementById('adPaymentAmount').value) || 0;
const extraAmount = addPayAmount - emiAmount;
document.getElementById('adPaymentRemarks').value =
`EMI Amount: ${emiAmount}. Extra ${extraAmount > 0 ? extraAmount.toFixed(2) : "0.00"} Settled in last EMI `;
}
</script>

View File

@ -22,8 +22,8 @@
$description = $_POST['description'];
$quantity = $_POST['quantity'];
$rate = $_POST['rate'];
$tax = $_POST['tax'];
$taxAmount = $_POST['taxAmount'];
$discount = $_POST['discount'];
$discountAmount = $_POST['discountAmount'];
@ -32,31 +32,31 @@
$outstandingAmount = $totalAmount;
$emiDate = new DateTime($bookingDate); // Set initial date
$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');
}
}
// $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("UPDATE invoice SET customerName = :customerName, address = :address, frequency = :frequency, invoiceDate = :invoiceDate, paymentMode = :paymentMode, salesAgent = :salesAgent, marketingAgent = :marketingAgent, tenure = :tenure, item = :item, description = :description, qty = :qty, rate = :rate, tax = :tax, totalAmount = :totalAmount, adminNote = :adminNote, taxAmount = :taxAmount WHERE customerId = :customerId AND invoiceId = :invoiceId");
$stmt2 = $db->prepare("UPDATE invoice SET customerName = :customerName, address = :address, frequency = :frequency, invoiceDate = :invoiceDate, paymentMode = :paymentMode, salesAgent = :salesAgent, marketingAgent = :marketingAgent, tenure = :tenure, item = :item, description = :description, qty = :qty, rate = :rate, discount = :discount, totalAmount = :totalAmount, adminNote = :adminNote, discount = :discount WHERE customerId = :customerId AND invoiceId = :invoiceId");
$stmt2->bindParam(':customerId', $_GET['customerId']);
$stmt2->bindParam(':invoiceId', $invoiceId);
$stmt2->bindParam(':customerName', $customerName);
@ -71,13 +71,11 @@
$stmt2->bindParam(':description', $description);
$stmt2->bindParam(':qty', $quantity);
$stmt2->bindParam(':rate', $rate);
$stmt2->bindParam(':tax', $tax);
$stmt2->bindParam(':discount', $discount);
$stmt2->bindParam(':totalAmount', $totalAmount);
$stmt2->bindParam(':adminNote', $adminNote);
$stmt2->bindParam(':taxAmount', $taxAmount);
$stmt2->bindParam(':discountAmount', $discountAmount);
$stmt2->execute();
echo '<div class="alert alert-success">New EMI Plan Saved Successfully!</div>';
echo '<script>
document.addEventListener("DOMContentLoaded", function() {
@ -142,11 +140,11 @@
</div>
<div class="w-100">
<div class="mb-3">
<label for="paymentMode" class="form-label">Payment Mode:</label>
<label for="paymentMode" class="form-label">Payment Methods:</label>
<select name="paymentMode" class="form-control"required>
<option value="">-Select-</option>
<?php
$paymentModes = ["UPI", "Credit Card", "Debit Card", "Cash"];
$paymentModes = ["Stripe", "Zelle", "Bank Transfer", "Cheque", "Other"];
foreach ($paymentModes as $mode) {
$selected = ($invoiceData['paymentMode'] === $mode) ? 'selected' : '';
echo "<option value=\"$mode\" $selected>$mode</option>";
@ -158,8 +156,13 @@
<label for="salesAgent" class="form-label">Sales Agent:</label>
<select name="salesAgent" class="form-control"required>
<option value="">-Select-</option>
<option value="Prabhat Mishra">Prabhat Mishra</option>
<option value="Suvojit Mishra">Suvojit Mishra</option>
<?php
$salesAgentOptions = ["Prabhat Mishra", "Suvojit Mishra"];
foreach ($salesAgentOptions as $salesAgentItems) {
$selected = ($invoiceData['salesAgent'] === $salesAgentItems) ? 'selected' : '';
echo "<option value=\"$salesAgentItems\" $selected>$salesAgentItems</option>";
}
?>
</select>
</div>
<div class="mb-3">
@ -229,19 +232,19 @@
<input class="form-control w-100" name="rate" id="rate" value="<?= htmlspecialchars($invoiceData['rate']); ?>"/>
</td>
<td>
<select name="tax" id="tax" class="form-control">
<option value="0">No Tax</option>
<select name="discount" id="discount" class="form-control">
<option value="0">No Discount</option>
<?php
$taxOptions = ["5", "10", "12", "18"];
foreach ($taxOptions as $tax) {
$selected = ($invoiceData['tax'] === $tax) ? 'selected' : '';
echo "<option value=\"$tax\" $selected> $tax%</option>";
$discountOptions = ["5", "10", "12", "18"];
foreach ($discountOptions as $discountItems) {
$selected = ($invoiceData['discount'] === $discountItems) ? 'selected' : '';
echo "<option value=\"$discountItems\" $selected> $discountItems%</option>";
}
?>
</select>
</td>
<td>
<input readonly class="form-control" name="taxAmount" id="taxAmount" value="<?= htmlspecialchars($invoiceData['taxAmount']); ?>" />
<input readonly class="form-control" name="discountAmount" id="discountAmount" value="<?= htmlspecialchars($invoiceData['discountAmount']); ?>" />
</td>
<td>
<input readonly class="form-control" name="totalAmount" id="totalAmount" value="<?= htmlspecialchars($invoiceData['totalAmount']); ?>"/>
@ -254,7 +257,7 @@
<div>
<button class="btn btn-secondary">Discard</button>
<button type="submit" class="btn btn-primary">Save</button>
<a href="/customers/print-invoice/?customerId=<?= $_GET['customerId'] . '&invoiceId='. $lastInvoicePrint['invoiceId']; ?>" id="printBtn" class="btn btn-primary visually-">Print Invoice</a>
<a href="/customers/print-invoice/?customerId=<?= $_GET['customerId'] . '&invoiceId='. $_GET['invoiceId']; ?>" id="printBtn" class="btn btn-primary visually-">Print Invoice</a>
</div>
</div>
@ -298,8 +301,8 @@
document.addEventListener("DOMContentLoaded", function () {
const quantityInput = document.getElementById("quantity");
const rateInput = document.getElementById("rate");
const taxSelect = document.getElementById("tax");
const taxAmountInput = document.getElementById("taxAmount");
const taxSelect = document.getElementById("discount");
const taxAmountInput = document.getElementById("discountAmount");
const totalAmountInput = document.getElementById("totalAmount");
function calculateTotal() {
@ -309,7 +312,7 @@
let subtotal = quantity * rate;
let taxAmount = (subtotal * tax) / 100;
let grandTotal = subtotal + taxAmount;
let grandTotal = subtotal - taxAmount;
taxAmountInput.value = taxAmount.toFixed(2); // Format Tax Amount
totalAmountInput.value = grandTotal.toFixed(2); // Format Total Amount
@ -322,4 +325,7 @@
});
</script>
</script>
<!-- cust_67c9925ff14f4834489101 -->
<!-- CB03252 -->

View File

@ -22,10 +22,8 @@
$description = $_POST['description'];
$quantity = $_POST['quantity'];
$rate = $_POST['rate'];
$tax = $_POST['tax'];
$taxAmount = $_POST['taxAmount'];
$discount = $_POST['discount'];
$discountAmount = $_POST['discountAmount'];
// EMI Calculation
$emiAmount = round($totalAmount / $tenure, 2);
@ -56,7 +54,7 @@
}
// 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 = $db->prepare("INSERT INTO invoice (customerId, invoiceId, customerName, address, frequency, invoiceDate, paymentMode, salesAgent, marketingAgent, tenure, item, description, qty, rate, discount, totalAmount, adminNote, discountAmount) VALUES (:customerId, :invoiceId, :customerName, :address, :frequency, :invoiceDate, :paymentMode, :salesAgent, :marketingAgent, :tenure, :item, :description, :qty, :rate, :discount, :totalAmount, :adminNote, :discountAmount)");
$stmt2->bindParam(':customerId', $_GET['customerId']);
$stmt2->bindParam(':invoiceId', $invoiceId);
$stmt2->bindParam(':customerName', $customerName);
@ -71,10 +69,10 @@
$stmt2->bindParam(':description', $description);
$stmt2->bindParam(':qty', $quantity);
$stmt2->bindParam(':rate', $rate);
$stmt2->bindParam(':tax', $tax);
$stmt2->bindParam(':discount', $discount);
$stmt2->bindParam(':totalAmount', $totalAmount);
$stmt2->bindParam(':adminNote', $adminNote);
$stmt2->bindParam(':taxAmount', $taxAmount);
$stmt2->bindParam(':discountAmount', $discountAmount);
$stmt2->execute();
echo '<div class="alert alert-success">New EMI Plan Saved Successfully!</div>';
@ -156,13 +154,14 @@
</div>
<div class="w-100">
<div class="mb-3">
<label for="paymentMode" class="form-label">Payment Mode:</label>
<label for="paymentMode" class="form-label">Payment Methods:</label>
<select name="paymentMode" class="form-control"required>
<option value="">-Select-</option>
<option value="UPI">UPI</option>
<option value="Credit Card">Credit Card</option>
<option value="Debit Card">Debit Card</option>
<option value="Cash">Cash</option>
<option value="Stripe">Stripe</option>
<option value="Zelle">Zelle</option>
<option value="Bank Transfer">Bank Transfer</option>
<option value="Cheque">Cheque</option>
<option value="Other">Other</option>
</select>
</div>
<div class="mb-3">
@ -213,8 +212,8 @@
<th class="p-2">Description</th>
<th class="p-2">Qty</th>
<th class="p-2">Rate</th>
<th class="p-2">Tax % </th>
<th class="p-2">Tax Amount</th>
<th class="p-2">Discount % </th>
<th class="p-2">Discount Amount</th>
<th class="p-2">Amount</th>
</tr>
</thead>
@ -233,8 +232,8 @@
<input class="form-control w-100" name="rate" id="rate" />
</td>
<td>
<select name="tax" id="tax" class="form-control">
<option value="0">No Tax</option>
<select name="discount" id="discount" class="form-control">
<option value="0">No Discount</option>
<option value="5">5 %</option>
<option value="10">10 %</option>
<option value="12">12 %</option>
@ -242,7 +241,7 @@
</select>
</td>
<td>
<input readonly class="form-control" name="taxAmount" id="taxAmount" />
<input readonly class="form-control" name="discountAmount" id="discountAmount" />
</td>
<td>
<input readonly class="form-control" name="totalAmount" id="totalAmount" />
@ -297,8 +296,8 @@
document.addEventListener("DOMContentLoaded", function () {
const quantityInput = document.getElementById("quantity");
const rateInput = document.getElementById("rate");
const taxSelect = document.getElementById("tax");
const taxAmountInput = document.getElementById("taxAmount");
const taxSelect = document.getElementById("discount");
const taxAmountInput = document.getElementById("discountAmount");
const totalAmountInput = document.getElementById("totalAmount");
function calculateTotal() {
@ -308,7 +307,7 @@
let subtotal = quantity * rate;
let taxAmount = (subtotal * tax) / 100;
let grandTotal = subtotal + taxAmount;
let grandTotal = subtotal - taxAmount;
taxAmountInput.value = taxAmount.toFixed(2); // Format Tax Amount
totalAmountInput.value = grandTotal.toFixed(2); // Format Total Amount

View File

@ -4,7 +4,7 @@
<div class="container-xxl mt-4">
<h3 class="mb-3 ">Customer List</h3><hr>
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover w-100" style="font-size: 12px;">
<table class="table table-bordered table-striped table-hover w-100" style="font-size: 13px;">
<thead class="bg-primary text-white text-center" >
<tr>
<th>Sl No</th>
@ -15,7 +15,7 @@
<th>Monthly Payment Date</th>
<th>Monthly Payment Amount</th>
<th>Total Amount</th>
<th>Action</th>
<th>Invoice</th>
</tr>
</thead>
<tbody>
@ -84,9 +84,9 @@
<td>$<?php echo isset($emi['totalAmount']) ? htmlspecialchars($emi['totalAmount']) : '0.00'; ?></td>
<td class="d-flex gap-1">
<a href="/customers/generate-invoice/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm" style="font-size: 13px;">New Invoice</a>
<a href="/customers/edit-invoice/?customerId=<?php echo $customer['customerId'].'&invoiceId='.$invoice['invoiceId']; ?>" class="btn btn-primary btn-sm" style="font-size: 13px;">Edit Invoice</a>
<a href="/customers/additional-payment/?customerId=<?php echo $customer['customerId'].'&invoiceId='.$invoice['invoiceId']; ?>" class="btn btn-primary btn-sm" style="font-size: 13px;">Payment</a>
<a href="/customers/generate-invoice/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm" style="font-size: 13px;">New</a>
<a href="/customers/edit-invoice/?customerId=<?php echo $customer['customerId'].'&invoiceId='.$invoice['invoiceId']; ?>" class="btn btn-primary btn-sm" style="font-size: 13px;">Edit</a>
<a href="/customers/print-invoice/?customerId=<?php echo $customer['customerId'].'&invoiceId='.$invoice['invoiceId']; ?>" class="btn btn-primary btn-sm" style="font-size: 13px;">Print</a>
</td>
</tr>
<?php
@ -99,7 +99,7 @@
<td><?php echo htmlspecialchars($customer['name']); ?></td>
<td colspan="6" class="text-center">No EMI or Invoice Data</td>
<td>
<a href="/customers/generate-invoice/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Create Invoice</a>
<a href="/customers/generate-invoice/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">New</a>
</td>
</tr>
<?php

View File

@ -43,8 +43,8 @@ if ($invoiceInfo['tenure'] > 1) {
<th>Description</th>
<th>Qty</th>
<th>Rate</th>
<th>Tax(%)</th>
<th>Tax</th>
<th>Discount(%)</th>
<th>Discount</th>
<th>Total</th>
</tr>
</thead>
@ -54,8 +54,8 @@ if ($invoiceInfo['tenure'] > 1) {
<td><?= $invoiceInfo['description'] ?></td>
<td><?= $invoiceInfo['qty'] ?></td>
<td><?= $invoiceInfo['rate'] ?></td>
<td><?= $invoiceInfo['tax'] ?>%</td>
<td>$<?= $invoiceInfo['taxAmount'] ?></td>
<td><?= $invoiceInfo['discount'] ?>%</td>
<td>$<?= $invoiceInfo['discountAmount'] ?></td>
<td>$<?= number_format($invoiceInfo['totalAmount'], 2) ?></td>
</tr>
</tbody>
@ -63,7 +63,7 @@ if ($invoiceInfo['tenure'] > 1) {
<!-- EMI Table (if tenure > 1) -->
<?php if ($invoiceInfo['tenure'] > 1): ?>
<h4 class="mt-4 text-blue">EMI Payment Plan</h4>
<h5 class="mt-4 text-blue">EMI Payment Plan</h5>
<table class="table table-striped">
<thead>
<tr>
@ -75,7 +75,7 @@ if ($invoiceInfo['tenure'] > 1) {
</tr>
</thead>
<tbody>
<?php foreach ($emiPlans as $emi): ?>
<?php foreach ($emiPlans as $emi): if($emi['emiAmount'] !== null) {?>
<tr>
<td><?= $emi['emiNumber'] ?></td>
<td><?= $emi['emiDate'] ?></td>
@ -85,18 +85,49 @@ if ($invoiceInfo['tenure'] > 1) {
<?= ($emi['payStatus'] == 1) ? '<span class="badge bg-success">Paid</span>' : '<span class="badge bg-danger">Pending</span>' ?>
</td>
</tr>
<?php endforeach; ?>
<?php } endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<h5 class="mt-4 text-blue">Additional Payment Details:</h5>
<table class="table table-striped " style="font-size: 12px;">
<thead class="">
<tr>
<th>Payment Amount</th>
<th>Payment Date</th>
<th>Payment Source</th>
<th>Transaction ID</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<?php
foreach ($emiPlans as $emiAdditional) {
if (!is_null($emiAdditional['adPaymentAmount']) && $emiAdditional['adPaymentAmount'] > 0) {
?>
<tr>
<td><?= number_format($emiAdditional['adPaymentAmount'], 2) ?></td>
<td><?= !empty($emiAdditional['adPaymentDate']) ? $emiAdditional['adPaymentDate'] : '-' ?></td>
<td><?= !empty($emiAdditional['adPaymentSource']) ? $emiAdditional['adPaymentSource'] : '-' ?></td>
<td><?= !empty($emiAdditional['adPaymentTran']) ? $emiAdditional['adPaymentTran'] : '-' ?></td>
<td><?= !empty($emiAdditional['adPaymentRemarks']) ? $emiAdditional['adPaymentRemarks'] : '-' ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<p class="text-muted mt-3"><strong>Admin Note:</strong> <?= $invoiceInfo['adminNote'] ?></p>
<!-- Print Button -->
<p style="font-size: 12px;"><strong>Invoice Generate Date: </strong><span id="invoiceGenDate"></span></p>
<button onclick="window.print()" class="btn btn-primary btn-print w-100">Print Invoice</button>
</div>
</div>
<script>
document.getElementById('invoiceGenDate').textContent = new Date().toLocaleDateString('en-GB');
</script>
<style>
body {
background-color: #f8f9fa;

View File

@ -43,8 +43,8 @@ if ($invoiceInfo['tenure'] > 1) {
<th>Description</th>
<th>Qty</th>
<th>Rate</th>
<th>Tax(%)</th>
<th>Tax</th>
<th>Discount(%)</th>
<th>Discount</th>
<th>Total</th>
</tr>
</thead>
@ -54,8 +54,8 @@ if ($invoiceInfo['tenure'] > 1) {
<td><?= $invoiceInfo['description'] ?></td>
<td><?= $invoiceInfo['qty'] ?></td>
<td><?= $invoiceInfo['rate'] ?></td>
<td><?= $invoiceInfo['tax'] ?>%</td>
<td>$<?= $invoiceInfo['taxAmount'] ?></td>
<td><?= $invoiceInfo['discount'] ?>%</td>
<td>$<?= $invoiceInfo['discountAmount'] ?></td>
<td>$<?= number_format($invoiceInfo['totalAmount'], 2) ?></td>
</tr>
</tbody>