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="";
}
if($hasReadAccess||$hasWriteAccess || $hasExecuteAccess )
{
$view_link1="";
}
$space = " ";
$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(
'',
"",
"",
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
''
)
);
echo json_encode($data);
?>