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']; // EMI Calculation $emiAmount = round($totalAmount / $tenure, 2); $outstandingAmount = $totalAmount; $emiDate = new DateTime($firstEmiDate); // Set initial date $stmt = $db->prepare("INSERT INTO emi (customerId, emiNumber, emiAmount, emiDate, totalAmount, outstanding, tenure, frequency, bookingDate, paymentMode) VALUES (:customerId, :emiNumber, :emiAmount, :emiDate, :totalAmount, :outstanding, :tenure, :frequency, bookingDate, :paymentMode)"); 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->execute(); // Move to the next month's EMI date if($frequency === 'Weekly'){ $emiDate->modify('+1 week'); } elseif($frequency === 'Monthly'){ $emiDate->modify('+1 month'); } } echo '
Mobile: = htmlspecialchars($customer['mobile']) ?>