ESH/pending_expiry_list_script.php
2024-10-23 18:28:06 +05:30

150 lines
5.4 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;
}
// Get total count of records
$sql = "select count(*) from item_stock where ohc_type_id='".$_SESSION['current_ohcttype']."' and stock_qty>0 and item_stock_id not in (select item_stock_id from cleanup_item_stock) 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 where ohc_type_id='".$_SESSION['current_ohcttype']."' and stock_qty>0 and item_stock_id not in (select item_stock_id from cleanup_item_stock) 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 = "";
/*
* if($access_level=='R' ||$access_level=='W' || $access_level=='E' )
* {
* //echo "shubham";
* $view_link="<a href=\"#\"class=\"green\" onclick=\"open_procurement('".$id."','V');\"><i class=\"ace-icon fa fa-search-plus bigger-130\"></i></a>";
* }
*
* if($access_level=='W' || $access_level=='E' )
* {
* $edit_link="<a href=\"#\" class=\"blue\" onclick=\"open_procurement('".$id."','E');\"><i class=\"ace-icon fa fa-pencil bigger-130\"></i></a>";
* }
* if($access_level=='E' )
* {
* $delete_link="<a href=\"#\" class=\"blue\" onclick=\"delete_procurement('".$id."');\"><i class=\"ace-icon fa fa-trash-o bigger-130\"></i></a>";
* }
*/
while ( $row_pending_expiry = mysqli_fetch_assoc ( $results_pending_expiry ) ) {
$id = $row_pending_expiry ['item_stock_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(qty) from procurement_items where item_id=" . $item_id . " and batch='" . $item_batch . "' and ohc_type_id='".$_SESSION['current_ohcttype']."' ";
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 = "&nbsp;&nbsp;&nbsp;";
$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 );
?>