<?php
require("php_con.php");

if(isset($_POST["customer_id"])) {
    $customer_id = mysqli_real_escape_string($connation, $_POST["customer_id"]);
    $query = "SELECT ip.plan_id, ip.product_name, ip.remaining_balance
              FROM installment_plans ip
              WHERE ip.cs_id = $customer_id AND ip.status = 'active'";
    
    $result = mysqli_query($connation, $query);
    
    if(mysqli_num_rows($result) > 0) {
        while($row = mysqli_fetch_assoc($result)) {
            echo "<option value='".$row['plan_id']."'>".$row['product_name']." (Remaining: ".$row['remaining_balance'].")</option>";
        }
    } else {
        echo "<option value=''>No active plans found</option>";
    }
}
?>