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

151 lines
5.2 KiB
PHP

<?php
include ('includes/config/config.php');
include ('includes/auth/auth.php');
include ('includes/functions.php');
include ('access.php');
include ('log_entry.php')?>
<?php
// Connect to mysqli database
$page = 1; // The current page
$sortname = 'item_id'; // Sort column
$sortorder = 'asc'; // Sort order
$qtype = ''; // Search column
$query = ''; // Search string
// Get posted data
if (isset($_REQUEST['page'])) {
$page = mysqli_real_escape_string($conn,$_REQUEST['page']);
}
if (isset($_REQUEST['sortname'])) {
$sortname = mysqli_real_escape_string($conn,$_REQUEST['sortname']);
}
if (isset($_REQUEST['sortorder'])) {
$sortorder = mysqli_real_escape_string($conn,$_REQUEST['sortorder']);
}
if (isset($_REQUEST['qtype'])) {
$qtype = mysqli_real_escape_string($conn,$_REQUEST['qtype']);
}
if (isset($_REQUEST['query'])) {
$query = mysqli_real_escape_string($conn,$_REQUEST['query']);
}
if (isset($_REQUEST['rp'])) {
$rp = mysqli_real_escape_string($conn,$_REQUEST['rp']);
}
// Setup sort and search SQL using posted data
$hasReadAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'R');
$hasWriteAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'W');
$hasExecuteAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'E');
$sortSql = "order by $sortname $sortorder";
$searchSql = ($qtype != '' && $query != '') ? " and upper($qtype) like upper('%" . trim($query) . "%')" : '';
// Get total count of records
// $sql = "select count(a.item_id) from item_stock_dispensary a inner join tbl_items b on a.item_id=b.item_id where a.ohc_location_id='".$_SESSION['current_ohcttype']."' $searchSql $sortSql ";
$sql = "SELECT count(*) from tbl_items i left join (select item_id, stock_qty from item_stock_dispensary isd where ohc_location_id='" . $_SESSION['current_ohcttype'] . "') d on i.item_id=d.item_id where status='1' and (stock_qty>0 or (is_group_item='P' or is_packaging_item='P')) $searchSql ";
// echo $sql;
error_log("query2: " . $sql);
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result);
$total = $row[0];
if (! isSet($rp)) {
$rp = 10;
}
// Setup paging SQL
// $rp=1;
$pageStart = ($page - 1) * $rp;
error_log("pageStart: " . $pageStart);
$limitSql = "limit $pageStart, $rp";
error_log("limitSql: " . $limitSql);
// Return JSON data
$data = array();
$data['page'] = $page;
$data['total'] = $total;
error_log("total: " . $total);
$data['rows'] = array();
// $sql1 = "select item_stock_id,item_id,item_batch_no,expiry_date,stock_qty from item_stock ";
// $sql1 = "select a.*,b.item_name,b.unit_id from item_stock_dispensary a inner join tbl_items b on a.item_id=b.item_id where a.ohc_location_id='".$_SESSION['current_ohcttype']."'";
$sql1 = "SELECT i.item_id, i.reorder_dispensary_level, i.min_dispensary_level ,item_name, unit_id, ifnull(d.stock_qty,0) as stock_qty from tbl_items i left join (select item_id, stock_qty from item_stock_dispensary isd where ohc_location_id='" . $_SESSION['current_ohcttype'] . "') d on i.item_id=d.item_id where status='1' and (stock_qty>0 or (is_group_item='P' or is_packaging_item='P')) ";
// echo $sql1;
error_log("query21: " . $sql1);
$sql_export = $sql1;
$sql1 .= " $searchSql $sortSql $limitSql ";
$sql_export .= " $searchSql $sortSql ";
error_log("query1: " . $sql1);
$results = mysqli_query($conn,$sql1);
$count = ($page - 1) * $rp + 1;
// echo $sql1;
// echo $access_level;
while ($row1 = mysqli_fetch_assoc($results)) {
extract($row1);
$item_id = $row1['item_id'];
$item_name= getItemWithFormName($row1['item_id']);
$reorder_stock_level=$row1['reorder_dispensary_level'];
$minqyt = $row1['min_dispensary_level'];
$edit_link1="";
//$delete_link="";
$view_link1="";
if($hasWriteAccess || $hasExecuteAccess )
{
$edit_link1="<a href=\"#\" class=\"blue\" onclick=\"open_item('".$item_id."','E');\"><i class=\"ace-icon fa fa-pencil bigger-130\"></i></a>";
}
if($hasReadAccess||$hasWriteAccess || $hasExecuteAccess )
{
$view_link1="<a href=\"#\"class=\"green\" onclick=\"open_item('".$item_id."','V');\"><i class=\"ace-icon fa fa-search-plus bigger-130\"></i></a>";
}
$space = "&nbsp;&nbsp;";
$links = $view_link1.$space.$edit_link1;
// $item_id=$row1['item_id'];
// $item_desc = getTableFieldValue('tbl_items','item_name','item_id',$item_id);
// $unit_id=getTableFieldValue('tbl_items','unit_id','item_id',$item_id);
$unit_name = getTableFieldValue('unit_master', 'unit_name', 'unit_id', $unit_id);
$data['rows'][] = array(
'id' => $row1['item_id'],
'cell' => array(
$count ++,
$item_name,
$stock_qty. " " . $unit_name,
$reorder_stock_level,
$minqyt,
$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);
?>