chnage some feaures

This commit is contained in:
Suvodip
2025-04-02 19:46:00 +05:30
parent 43f6f2ce21
commit 1ceb71c146
8 changed files with 109 additions and 234 deletions

View File

@@ -22,7 +22,6 @@
$description = $_POST['description'];
$quantity = $_POST['quantity'];
$rate = $_POST['rate'];
$discount = $_POST['discount'];
$discountAmount = $_POST['discountAmount'];
// EMI Calculation
@@ -54,7 +53,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, discount, totalAmount, adminNote, discountAmount) VALUES (:customerId, :invoiceId, :customerName, :address, :frequency, :invoiceDate, :paymentMode, :salesAgent, :marketingAgent, :tenure, :item, :description, :qty, :rate, :discount, :totalAmount, :adminNote, :discountAmount)");
$stmt2 = $db->prepare("INSERT INTO invoice (customerId, invoiceId, customerName, address, frequency, invoiceDate, paymentMode, salesAgent, marketingAgent, tenure, item, description, qty, rate, totalAmount, adminNote, discountAmount) VALUES (:customerId, :invoiceId, :customerName, :address, :frequency, :invoiceDate, :paymentMode, :salesAgent, :marketingAgent, :tenure, :item, :description, :qty, :rate, :totalAmount, :adminNote, :discountAmount)");
$stmt2->bindParam(':customerId', $_GET['customerId']);
$stmt2->bindParam(':invoiceId', $invoiceId);
$stmt2->bindParam(':customerName', $customerName);
@@ -69,7 +68,6 @@
$stmt2->bindParam(':description', $description);
$stmt2->bindParam(':qty', $quantity);
$stmt2->bindParam(':rate', $rate);
$stmt2->bindParam(':discount', $discount);
$stmt2->bindParam(':totalAmount', $totalAmount);
$stmt2->bindParam(':adminNote', $adminNote);
$stmt2->bindParam(':discountAmount', $discountAmount);
@@ -111,7 +109,6 @@
$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 '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
@@ -214,7 +211,6 @@
<th class="p-2">Description</th>
<th class="p-2">Qty</th>
<th class="p-2">Rate</th>
<th class="p-2">Discount&nbsp;% </th>
<th class="p-2">Discount&nbsp;$</th>
<th class="p-2">Amount</th>
</tr>
@@ -234,18 +230,7 @@
<input class="form-control w-100" name="rate" id="rate" />
</td>
<td>
<select onchange="changeDiscountField();" id="discountAuto" name="discount" class="form-control" required>
<option value="">-Select-</option>
<option value="5">5%</option>
<option value="10">10%</option>
<option value="12">12%</option>
<option value="18">18%</option>
<option value="0">Custom</option>
</select>
<input type="text" name="discount" id="discountCustom" class="form-control visually-hidden" placeholder="Enter custom discount" disabled onblur="restoreDiscounDropdown(this)" />
</td>
<td>
<input readonly class="form-control" name="discountAmount" id="discountAmount" />
<input class="form-control" name="discountAmount" id="discountAmount" />
</td>
<td>
<input readonly class="form-control" name="totalAmount" id="totalAmount" />
@@ -269,8 +254,6 @@
const formattedDate = today.toISOString().split('T')[0];
document.getElementById('bookingDate').value = formattedDate;
function changeTenureField() {
const tenureAuto = document.getElementById('tenureAuto');
const tenureCustom = document.getElementById('tenureCustom');
@@ -299,75 +282,27 @@
tenureAuto.value = "";
}
}
document.addEventListener("DOMContentLoaded", function () {
const quantityInput = document.getElementById("quantity");
const rateInput = document.getElementById("rate");
const discountSelect = document.getElementById("discountAuto");
const discountInput = document.getElementById("discountCustom");
const discountAmountInput = document.getElementById("discountAmount");
const totalAmountInput = document.getElementById("totalAmount");
function getDiscountValue() {
// Use the visible element's value (dropdown or input)
if (!discountSelect.disabled) {
return parseFloat(discountSelect.value) || 0;
} else {
return parseFloat(discountInput.value) || 0;
}
}
function calculateTotal() {
const quantity = parseFloat(quantityInput.value) || 0;
const rate = parseFloat(rateInput.value) || 0;
const discount = getDiscountValue();
const discountAmount = parseFloat(discountAmountInput.value) || 0;
let subtotal = quantity * rate;
let discountAmount = (subtotal * discount) / 100;
let grandTotal = subtotal - discountAmount;
discountAmountInput.value = discountAmount.toFixed(2);
totalAmountInput.value = grandTotal.toFixed(2);
}
// Event listeners for real-time calculation
quantityInput.addEventListener("input", calculateTotal);
rateInput.addEventListener("input", calculateTotal);
discountSelect.addEventListener("change", calculateTotal);
discountInput.addEventListener("input", calculateTotal);
discountAmountInput.addEventListener("input", calculateTotal);
});
function changeDiscountField() {
const discountAuto = document.getElementById('discountAuto');
const discountCustom = document.getElementById('discountCustom');
if (discountAuto.value === "0") { // "Custom" option selected
discountAuto.classList.add('visually-hidden');
discountAuto.removeAttribute('name');
discountAuto.setAttribute('disabled', 'true');
discountCustom.classList.remove('visually-hidden');
discountCustom.setAttribute('name', 'discount');
discountCustom.removeAttribute('disabled');
discountCustom.focus();
}
}
function restoreDiscounDropdown(input) {
const discountAuto = document.getElementById('discountAuto');
if (input.value.trim() === "") { // If input is empty, restore the dropdown
discountAuto.classList.remove('visually-hidden');
discountAuto.removeAttribute('disabled');
discountAuto.setAttribute('name', 'discount');
discountAuto.value = "";
input.classList.add('visually-hidden');
input.removeAttribute('name');
input.setAttribute('disabled', 'true');
}
}
</script>