41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
![]() |
<?php
|
||
|
include('includes/config/config.php');
|
||
|
|
||
|
$data = array();
|
||
|
|
||
|
$sql_expiry_items = "SELECT i.item_name, itm_stk.item_batch_no, itm_stk.expiry_date, itm_stk.stock_qty
|
||
|
FROM tbl_items i
|
||
|
JOIN item_stock itm_stk ON i.item_id = itm_stk.item_id
|
||
|
WHERE itm_stk.stock_qty > 0
|
||
|
AND itm_stk.ohc_type_id = ?
|
||
|
AND itm_stk.item_stock_id NOT IN (SELECT item_stock_id FROM cleanup_item_stock)
|
||
|
AND DATE(expiry_date) <= (CURDATE() + INTERVAL ? DAY)";
|
||
|
|
||
|
$stmt = mysqli_prepare($conn, $sql_expiry_items);
|
||
|
|
||
|
if (!$stmt) {
|
||
|
error_log("Error preparing statement: " . mysqli_error($conn));
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
$ohc_id = $_SESSION['current_ohcttype'];
|
||
|
$expiryAlertAdvance = getConfigKey("ITEM_EXPIRY_ALERT_DAYS");
|
||
|
if ($expiryAlertAdvance == null) {
|
||
|
$expiryAlertAdvance = 90;
|
||
|
}
|
||
|
|
||
|
mysqli_stmt_bind_param($stmt, "ss", $ohc_id, $expiryAlertAdvance);
|
||
|
mysqli_stmt_execute($stmt);
|
||
|
$result = mysqli_stmt_get_result($stmt);
|
||
|
|
||
|
if ($result) {
|
||
|
while ($row = mysqli_fetch_assoc($result)) {
|
||
|
$data[] = $row; // Append each row to the data array
|
||
|
}
|
||
|
} else {
|
||
|
error_log("Error executing statement: " . mysqli_error($conn));
|
||
|
}
|
||
|
|
||
|
// error_log('near expiring');
|
||
|
echo json_encode($data);
|