138 lines
5.1 KiB
PHP
138 lines
5.1 KiB
PHP
![]() |
<?php
|
||
|
include ('includes/config/config.php');
|
||
|
include ('includes/auth/auth.php');
|
||
|
include ('includes/functions.php');
|
||
|
include ('access.php');
|
||
|
error_reporting(E_ERROR | E_PARSE);
|
||
|
include 'log_entry.php';
|
||
|
?>
|
||
|
<?php
|
||
|
|
||
|
// Connect to mysqli database
|
||
|
$page = 1; // The current page
|
||
|
$sortname = 'id'; // Sort column
|
||
|
$sortorder = 'asc'; // Sort order
|
||
|
$qtype = ''; // Search column
|
||
|
$query = ''; // Search string
|
||
|
// Get posted data
|
||
|
if (isset($_POST['page'])) {
|
||
|
$page = mysqli_real_escape_string($conn, $_POST['page']);
|
||
|
}
|
||
|
if (isset($_POST['sortname'])) {
|
||
|
$sortname = mysqli_real_escape_string($conn, $_POST['sortname']);
|
||
|
}
|
||
|
if (isset($_POST['sortorder'])) {
|
||
|
$sortorder = mysqli_real_escape_string($conn, $_POST['sortorder']);
|
||
|
}
|
||
|
if (isset($_POST['qtype'])) {
|
||
|
$qtype = mysqli_real_escape_string($conn, $_POST['qtype']);
|
||
|
}
|
||
|
if (isset($_POST['query'])) {
|
||
|
$query = mysqli_real_escape_string($conn, $_POST['query']);
|
||
|
}
|
||
|
if (isset($_POST['rp'])) {
|
||
|
$rp = mysqli_real_escape_string($conn, $_POST['rp']);
|
||
|
}
|
||
|
// Setup sort and search SQL using posted data
|
||
|
$sortSql = "order by $sortname $sortorder";
|
||
|
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
|
||
|
|
||
|
if ($searchSql != '') {
|
||
|
// ECHO RAM;
|
||
|
if ($qtype == 'expiry') {
|
||
|
|
||
|
$searchSql = " and date_format(date(expiry),'%Y-%m-%d')=str_to_date('$query','%d/%m/%Y') ";
|
||
|
} else if ($qtype == 'expiry_date_between') {
|
||
|
$dates = explode("-", $query);
|
||
|
|
||
|
// $qtype=" due_date between ";
|
||
|
$searchSql = " and expiry_date_between between str_to_date('" . trim($dates[0]) . "','%d/%m/%Y') and str_to_date('" . trim($dates[1]) . "','%d/%m/%Y') ";
|
||
|
}
|
||
|
}
|
||
|
$expiryAlertAdvance = getConfigKey("ITEM_EXPIRY_ALERT_DAYS");
|
||
|
if ($expiryAlertAdvance == null) {
|
||
|
$expiryAlertAdvance = 90;
|
||
|
}
|
||
|
|
||
|
$ohc_loc = getFieldFromTable('ohc_type_id', 'ohc_type', 'ohc_code', 'OHCAMB');
|
||
|
|
||
|
|
||
|
// Get total count of records
|
||
|
$sql = "select count(*) from item_stock_miscellaneous where issue_to_ohc_id='" . $ohc_loc . "' and stock_qty>0 and id not in (select item_stock_id from cleanup_item_stock) and expiry_date != '0000-00-00' and DATE(expiry_date)<= (CURDATE() + INTERVAL $expiryAlertAdvance DAY ) $searchSql ";
|
||
|
error_log("COUNTING QUERY::" . $sql);
|
||
|
// echo $sql;
|
||
|
$result = mysqli_query($conn, $sql);
|
||
|
// echo $result;
|
||
|
$row = mysqli_fetch_array($result);
|
||
|
$total = $row[0];
|
||
|
if (!isset($rp)) {
|
||
|
$rp = 10;
|
||
|
}
|
||
|
// Setup paging SQL
|
||
|
// $rp=1;
|
||
|
$pageStart = ($page - 1) * $rp;
|
||
|
$limitSql = "limit $pageStart, $rp";
|
||
|
// Return JSON data
|
||
|
$data = array();
|
||
|
$data['page'] = $page;
|
||
|
$data['total'] = $total;
|
||
|
$data['rows'] = array();
|
||
|
$count = 1;
|
||
|
|
||
|
$sql_pending_expiry = "select * from item_stock_miscellaneous where issue_to_ohc_id='" . $ohc_loc . "' and stock_qty>0 and id not in (select item_stock_id from cleanup_item_stock) and expiry_date != '0000-00-00' and DATE(expiry_date)<= (CURDATE() + INTERVAL $expiryAlertAdvance DAY )";
|
||
|
error_log("PENDING EXPIRY QUERY::" . $sql_pending_expiry);
|
||
|
$sql_export = $sql_pending_expiry;
|
||
|
|
||
|
$sql_pending_expiry .= " $searchSql $sortSql $limitSql ";
|
||
|
$sql_export .= " $searchSql $sortSql ";
|
||
|
|
||
|
$results_pending_expiry = mysqli_query($conn, $sql_pending_expiry);
|
||
|
|
||
|
$view_link = "";
|
||
|
$edit_link = "";
|
||
|
$delete_link = "";
|
||
|
$links = "";
|
||
|
|
||
|
while ($row_pending_expiry = mysqli_fetch_assoc($results_pending_expiry)) {
|
||
|
|
||
|
$id = $row_pending_expiry['id'];
|
||
|
$item_id = $row_pending_expiry['item_id'];
|
||
|
$item_desc = getItemWithFormName($row_pending_expiry['item_id']);
|
||
|
$item_qty = $row_pending_expiry['stock_qty'];
|
||
|
$item_batch = $row_pending_expiry['item_batch_no'];
|
||
|
$procurement_qty_query = "select sum(a.issue_qty) from stock_issue_items a left join stock_issue b on a.stock_issue_id=b.stock_issue_id where a.item_id=" . $item_id . " and a.item_batch_no='" . $item_batch . "' and b.ohc_location_id='" . $ohc_loc . "' ";
|
||
|
|
||
|
error_log("CONSUMPTION QUERY::" . $procurement_qty_query);
|
||
|
|
||
|
$results_qty_query = mysqli_query($conn, $procurement_qty_query);
|
||
|
|
||
|
$row_procurement_qty = mysqli_fetch_row($results_qty_query);
|
||
|
$procurement_qty = $row_procurement_qty[0];
|
||
|
$item_expiry_date = date_format(date_create($row_pending_expiry['expiry_date']), "M-Y ");
|
||
|
if ($access_level == 'W' || $access_level == 'E') {
|
||
|
$edit_link = "<a href=\"#\" class=\"grey\" onclick=\"open_pending_expiry('" . $id . "' ,'E');\"><i class=\"glyphicon glyphicon-eye-open\"></i></a>";
|
||
|
}
|
||
|
|
||
|
$space = " ";
|
||
|
$links = $space . $edit_link;
|
||
|
|
||
|
$data['rows'][] = array(
|
||
|
'id' => $row1['id'],
|
||
|
'cell' => array(
|
||
|
$count++,
|
||
|
$item_desc,
|
||
|
$procurement_qty,
|
||
|
$procurement_qty - $item_qty,
|
||
|
$item_qty,
|
||
|
$item_batch,
|
||
|
$item_expiry_date,
|
||
|
$links
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
$data['rows'][] = array(
|
||
|
'id' => $row['filterkey'],
|
||
|
'cell' => array('', "<input type=hidden name='filterkey' id='filterkey' value=\"" . base64_encode($sql_export) . "\">", "<input type=hidden name=paramlist id=paramlist value=\"" . base64_encode($paramlist) . "\">", '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')
|
||
|
);
|
||
|
echo json_encode($data);
|
||
|
?>
|