<?php
include $_SERVER['DOCUMENT_ROOT'] . '/classes/autoload.php';

$invoice_id = (int) ($_POST['invoice_id'] ?? 0);
if ($invoice_id <= 0) {
    echo '';
    exit;
}

$res = $db->query("invoice_list", "SELECT il.*, s.code, s.name, s.unit_of_measure, s.retail FROM invoice_list il JOIN stock s ON s.record_id = il.stock_id WHERE il.invoice_id = $invoice_id");

while ($row = $res->fetch_assoc()) {
    echo $row['code'] . '~' . $row['name'] . '~' . $row['unit_of_measure'] . '~' . $row['retail'] . "\n";
}