<?php

include "../../classes/autoload.php";

$invoice_id = $_POST['invoice_id'];

$res = $db->query("invoice_list", "SELECT * FROM invoice_list WHERE invoice_id = '$invoice_id'");

$subtotal = 0;
while ($row = $res->fetch_assoc()) {
    $price = floatval(preg_replace('/[^0-9\.\-]/', '', $row['price']));
    $qty   = floatval($row['qty']);
    $subtotal += $price * $qty;
}

echo json_encode([
    'subtotal' => 'R ' . number_format($subtotal, 2, '.', ',')
]);