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,41 +22,10 @@
$description = $_POST['description'];
$quantity = $_POST['quantity'];
$rate = $_POST['rate'];
$discount = $_POST['discount'];
$discountAmount = $_POST['discountAmount'];
// EMI Calculation
$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, 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, invoiceDate = :invoiceDate, paymentMode = :paymentMode, salesAgent = :salesAgent, marketingAgent = :marketingAgent, item = :item, description = :description, adminNote = :adminNote WHERE customerId = :customerId AND invoiceId = :invoiceId");
// Update invoice table
$stmt2 = $db->prepare("UPDATE invoice SET customerName = :customerName, address = :address, invoiceDate = :invoiceDate, paymentMode = :paymentMode, salesAgent = :salesAgent, marketingAgent = :marketingAgent, item = :item, description = :description, adminNote = :adminNote, discountAmount = :discountAmount, totalAmount = :totalAmount WHERE customerId = :customerId AND invoiceId = :invoiceId");
$stmt2->bindParam(':customerId', $_GET['customerId']);
$stmt2->bindParam(':invoiceId', $invoiceId);
$stmt2->bindParam(':customerName', $customerName);
@@ -68,8 +37,11 @@
$stmt2->bindParam(':item', $item);
$stmt2->bindParam(':description', $description);
$stmt2->bindParam(':adminNote', $adminNote);
$stmt2->bindParam(':discountAmount', $discountAmount);
$stmt2->bindParam(':totalAmount', $totalAmount);
$stmt2->execute();
echo '<div class="alert alert-success">New EMI Plan Saved Successfully!</div>';
echo '<div class="alert alert-success">Invoice Updated Successfully!</div>';
echo '<script>
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("printBtn").classList.remove("visually-hidden");
@@ -85,8 +57,9 @@
$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 = $db->prepare("SELECT * FROM invoice WHERE customerId = :customerId AND invoiceId = :invoiceId");
$stmt->bindParam(':customerId', $_GET['customerId']);
$stmt->bindParam(':invoiceId', $_GET['invoiceId']);
$stmt->execute();
$invoiceData = $stmt->fetch(PDO::FETCH_ASSOC);
$invoiceDate = date('Y-m-d', strtotime($invoiceData['invoiceDate']));
@@ -96,9 +69,8 @@
}
?>
<div class="container mt-4">
<h4>Create New Invoice</h4>
<h4>Edit Invoice</h4>
<hr>
<form method="POST">
<div class="d-flex justify-content-between gap-4">
@@ -119,10 +91,10 @@
<div class="mb-3">
<label for="frequency" class="form-label">Frequency:</label>
<select name="frequency" class="form-control" disabled>
<option value="Weekly" <?php echo ($invoiceData['frequency'] === 'Weekly') ? 'selected' : ''; ?>>Weekly</option>
<option value="Monthly" <?php echo ($invoiceData['frequency'] === 'Monthly') ? 'selected' : ''; ?>>Monthly</option>
<option value="Weekly" <?= ($invoiceData['frequency'] === 'Weekly') ? 'selected' : ''; ?>>Weekly</option>
<option value="Monthly" <?= ($invoiceData['frequency'] === 'Monthly') ? 'selected' : ''; ?>>Monthly</option>
</select>
<input type="hidden" name="frequency" value="<?php echo htmlspecialchars($invoiceData['frequency']); ?>">
<input type="hidden" name="frequency" value="<?= htmlspecialchars($invoiceData['frequency']); ?>">
</div>
<div class="d-flex w-100 gap-2">
<div class="mb-3 w-100">
@@ -134,7 +106,7 @@
<div class="w-100">
<div class="mb-3">
<label for="paymentMode" class="form-label">Payment Methods:</label>
<select name="paymentMode" class="form-control"required>
<select name="paymentMode" class="form-control" required>
<option value="">-Select-</option>
<?php
$paymentModes = ["Stripe", "Zelle", "Bank Transfer", "Cheque", "Other"];
@@ -147,15 +119,15 @@
</div>
<div class="mb-3">
<label for="salesAgent" class="form-label">Sales Agent:</label>
<select name="salesAgent" class="form-control"required>
<select name="salesAgent" class="form-control" required>
<option value="">-Select-</option>
<?php
$salesAgentOptions = ["Prabhat Mishra", "Suvojit Mishra"];
foreach ($salesAgentOptions as $salesAgentItems) {
$selected = ($invoiceData['salesAgent'] === $salesAgentItems) ? 'selected' : '';
echo "<option value=\"$salesAgentItems\" $selected>$salesAgentItems</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">
@@ -171,28 +143,22 @@
?>
</select>
</div>
<?php
$tenureOptions = [ "1" => "One Time","3" => "3","6" => "6","9" => "9","12" => "12","0" => "Custom" ];
$selectedTenure = $invoiceData['tenure'] ?? ''; // Get selected tenure value
?>
<div class="mb-3">
<label for="tenure" class="form-label">Total Cycles:</label>
<select id="tenureAuto" name="tenure" class="form-control" disabled>
<option value="">-Select-</option>
<?php
foreach ($tenureOptions as $value => $label) {
$selected = ($selectedTenure == $value) ? 'selected' : '';
echo "<option value=\"$value\" $selected>$label</option>";
}
$tenureOptions = ["1" => "One Time", "3" => "3", "6" => "6", "9" => "9", "12" => "12", "0" => "Custom"];
$selectedTenure = $invoiceData['tenure'] ?? '';
foreach ($tenureOptions as $value => $label) {
$selected = ($selectedTenure == $value) ? 'selected' : '';
echo "<option value=\"$value\" $selected>$label</option>";
}
?>
</select>
<input type="hidden" name="tenure" value="<?php echo htmlspecialchars($selectedTenure); ?>">
<input type="text" name="tenure" id="tenureCustom" class="form-control visually-hidden"
placeholder="Enter custom value" disabled onblur="restoreDropdown(this)" />
<input type="hidden" name="tenure" value="<?= htmlspecialchars($selectedTenure); ?>">
<input type="text" name="tenure" id="tenureCustom" class="form-control visually-hidden" placeholder="Enter custom value" disabled onblur="restoreDropdown(this)" />
</div>
<div class="mb-3">
<label for="adminNote" class="form-label">Admin Note:</label>
<textarea class="form-control" name="adminNote" id="adminNote" cols="30" rows="4"><?= htmlspecialchars($invoiceData['adminNote']); ?></textarea>
@@ -207,8 +173,7 @@
<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;&#36;</th>
<th class="p-2">Discount&nbsp;$</th>
<th class="p-2">Amount</th>
</tr>
</thead>
@@ -218,30 +183,16 @@
<input type="text" class="form-control w-100" name="item" id="item" value="<?= htmlspecialchars($invoiceData['item']); ?>" />
</td>
<td>
<input type="text" class="form-control w-100" name="description" id="description" value="<?= htmlspecialchars($invoiceData['description']); ?>" />
<input type="text" class="form-control w-100" name="description" id="description" value="<?= htmlspecialchars($invoiceData['description']); ?>" />
</td>
<td>
<input class="form-control w-100" name="quantity" id="quantity" value="<?= htmlspecialchars($invoiceData['qty']); ?>" readonly/>
<input class="form-control w-100" name="quantity" id="quantity" value="<?= htmlspecialchars($invoiceData['qty']); ?>" />
</td>
<td>
<input class="form-control w-100" name="rate" id="rate" value="<?= htmlspecialchars($invoiceData['rate']); ?>" readonly/>
<input class="form-control w-100" name="rate" id="rate" value="<?= htmlspecialchars($invoiceData['rate']); ?>" />
</td>
<td>
<select name="discount" id="discount" class="form-control" disabled>
<option value="0" <?php echo ($invoiceData['discount'] === "0") ? 'selected' : ''; ?>>No Discount</option>
<?php
$discountOptions = ["5", "10", "12", "18"];
foreach ($discountOptions as $discountItems) {
$selected = ($invoiceData['discount'] === $discountItems) ? 'selected' : '';
echo "<option value=\"$discountItems\" $selected> $discountItems%</option>";
}
?>
</select>
<input type="hidden" name="discount" value="<?php echo htmlspecialchars($invoiceData['discount']); ?>">
</td>
<td>
<input readonly class="form-control" name="discountAmount" id="discountAmount" value="<?= htmlspecialchars($invoiceData['discountAmount']); ?>" />
<input 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']); ?>"/>
@@ -257,72 +208,29 @@
<a href="/customers/print-invoice/?customerId=<?= $_GET['customerId'] . '&invoiceId='. $_GET['invoiceId']; ?>" id="printBtn" class="btn text-white visually-" style="background-color: #374151;">Print Invoice</a>
</div>
</div>
</form>
</div>
<script>
function changeTenureField() {
const tenureAuto = document.getElementById('tenureAuto');
const tenureCustom = document.getElementById('tenureCustom');
if (tenureAuto.value === "0") {
tenureAuto.classList.add('visually-hidden');
tenureAuto.setAttribute('disabled', 'true');
tenureAuto.removeAttribute('name');
tenureCustom.classList.remove('visually-hidden');
tenureCustom.removeAttribute('disabled');
tenureCustom.setAttribute('name', 'tenure');
tenureCustom.focus();
}
}
function restoreDropdown(input) {
const tenureAuto = document.getElementById('tenureAuto');
if (input.value.trim() === "") {
tenureAuto.classList.remove('visually-hidden');
tenureAuto.removeAttribute('disabled');
tenureAuto.setAttribute('name', 'tenure');
tenureAuto.value = ""; // Reset dropdown selection
input.classList.add('visually-hidden');
input.setAttribute('disabled', 'true');
input.removeAttribute('name');
input.value = ""; // Clear input value
} else {
tenureAuto.value = "0"; // Ensure dropdown remains on "Custom" if input has a value
}
}
document.addEventListener("DOMContentLoaded", function () {
const quantityInput = document.getElementById("quantity");
const rateInput = document.getElementById("rate");
const taxSelect = document.getElementById("discount");
const taxAmountInput = document.getElementById("discountAmount");
const discountAmountInput = document.getElementById("discountAmount");
const totalAmountInput = document.getElementById("totalAmount");
function calculateTotal() {
const quantity = parseFloat(quantityInput.value) || 0;
const rate = parseFloat(rateInput.value) || 0;
const tax = parseFloat(taxSelect.value) || 0;
const discountAmount = parseFloat(discountAmountInput.value) || 0;
let subtotal = quantity * rate;
let taxAmount = (subtotal * tax) / 100;
let grandTotal = subtotal - taxAmount;
let grandTotal = subtotal - discountAmount;
taxAmountInput.value = taxAmount.toFixed(2); // Format Tax Amount
totalAmountInput.value = grandTotal.toFixed(2); // Format Total Amount
totalAmountInput.value = grandTotal.toFixed(2);
}
// Event listeners for real-time calculation
quantityInput.addEventListener("input", calculateTotal);
rateInput.addEventListener("input", calculateTotal);
taxSelect.addEventListener("change", calculateTotal);
discountAmountInput.addEventListener("input", calculateTotal);
});
</script>
<!-- cust_67c9925ff14f4834489101 -->
<!-- CB03252 -->
</script>