<?php
error_reporting(0);
ini_set('display_errors', 0);

session_start();
include "../../../root.class.php";
$db = new db_safeguard();

if (empty($_POST['jobcard_no'])) {
    echo '0';
    exit;
}

$jobcard_no = $_POST['jobcard_no'];

$res = $db->query("notes", "SELECT * FROM notes WHERE jobcard_id = '{$jobcard_no}' AND reason NOT LIKE '%BIT%' ORDER BY record_id DESC");

if ($res->num_rows === 0) {
    echo '0';
    exit;
}

$rows = [];
while ($row = $res->fetch_assoc()) {
    $rows[] = [
        'reason'    => $row['reason'],
        'note'      => $row['note'],
        'image'     => $row['image'],
        'date_time' => $row['date_time']
    ];
}

echo json_encode($rows);
?>