<?php
require_once 'db_connect.php';
$invoice_id = isset($_GET['invoice_id']) ? intval($_GET['invoice_id']) : 0;
try {
    $stmt = $conn->prepare("SELECT id, installment_number, amount, due_date, status, paid_date FROM installments WHERE invoice_id = :invoice_id ORDER BY installment_number ASC");
    $stmt->execute([':invoice_id' => $invoice_id]);
    $installments = $stmt->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode(['status' => 'success', 'installments' => $installments]);
} catch (PDOException $e) {
    echo json_encode(['status' => 'error', 'message' => 'Failed to fetch installments']);
}
?>