setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $totalAmount = $_POST['totalAmount']; $tenure = $_POST['tenure']; $frequency = $_POST['frequency']; $bookingDate = $_POST['bookingDate']; $paymentMode = $_POST['paymentMode']; $salesAgent = $_POST['salesAgent']; $adminNote = $_POST['adminNote']; $invoiceId = $_POST['invoiceId']; $customerName = $_POST['customerName']; $customerAddress = $_POST['customerAddress']; $marketingAgents = $_POST['marketingAgent']; $marketingAgentList = implode(", ", $marketingAgents); $item = $_POST['item']; $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, 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); $stmt2->bindParam(':address', $customerAddress); $stmt2->bindParam(':frequency', $frequency); $stmt2->bindParam(':invoiceDate', $bookingDate); $stmt2->bindParam(':paymentMode', $paymentMode); $stmt2->bindParam(':salesAgent', $salesAgent); $stmt2->bindParam(':marketingAgent', $marketingAgentList); $stmt2->bindParam(':tenure', $tenure); $stmt2->bindParam(':item', $item); $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); $stmt2->execute(); echo '
New EMI Plan Saved Successfully!
'; echo ''; } catch (PDOException $e) { echo '
Error: ' . $e->getMessage() . '
'; } } $invoiceData = null; if (!empty($_GET['customerId'])) { try { $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->bindParam(':customerId', $_GET['customerId']); $stmt->execute(); $invoiceData = $stmt->fetch(PDO::FETCH_ASSOC); $invoiceDate = date('Y-m-d', strtotime($invoiceData['invoiceDate'])); } catch (PDOException $e) { echo '
Error: ' . $e->getMessage() . '
'; } } ?>

Create New Invoice


"One Time","3" => "3","6" => "6","9" => "9","12" => "12","0" => "Custom" ]; $selectedTenure = $invoiceData['tenure'] ?? ''; // Get selected tenure value ?>
Item Description Qty Rate Tax % Tax Amount Amount
Print Invoice