44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
|
|
$labels = array();
|
|
$data = array();
|
|
|
|
$ohc_id = $_SESSION['current_ohcttype'];
|
|
$sql_query = "SELECT ti.item_name, COUNT(si.item_id) + COUNT(t.item_id) as count
|
|
FROM stock_issue_items si
|
|
LEFT JOIN tbl_items ti ON si.item_id = ti.item_id
|
|
LEFT JOIN treatment t ON si.item_id = t.item_id
|
|
WHERE ti.ohc_type_id = ?
|
|
GROUP BY ti.item_id
|
|
ORDER BY count DESC
|
|
LIMIT 0,10";
|
|
|
|
$stmt = mysqli_prepare($conn, $sql_query);
|
|
|
|
if (!$stmt) {
|
|
error_log("Error preparing statement: " . mysqli_error($conn));
|
|
exit();
|
|
}
|
|
|
|
mysqli_stmt_bind_param($stmt, "s", $ohc_id);
|
|
mysqli_stmt_execute($stmt);
|
|
$result = mysqli_stmt_get_result($stmt);
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$name = $row['item_name'];
|
|
$count = $row['count'];
|
|
|
|
$labels[] = $name;
|
|
$data[] = $count;
|
|
}
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
$response = array(
|
|
'labels' => $labels,
|
|
'data' => $data
|
|
);
|
|
|
|
echo json_encode($response);
|