ohctech_p8/fetch_near_expiring_medicine.php

41 lines
1.3 KiB
PHP
Raw Normal View History

2024-10-16 19:18:52 +05:30
<?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));
2024-11-02 18:03:13 +05:30
die();
2024-10-16 19:18:52 +05:30
}
$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);