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

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 -->