163 lines
6.6 KiB
PHP
163 lines
6.6 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);
|
|
?>
|
|
<?php
|
|
|
|
// Connect to mysqli database
|
|
$page = 1; // The current page
|
|
$sortname = 'item_code'; // 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) = upper('%".trim($query)."%')" : '';
|
|
// if ($searchSql != '') {
|
|
// if($qtype=='item_code'){
|
|
// $searchSql= " and item_code like '%".trim($query)."%') ";
|
|
// }
|
|
// if($qtype=='item_name'){
|
|
// $searchSql= " item_name like '%".trim($query)."%') ";
|
|
// }
|
|
// if($qtype=='cat'){
|
|
// $searchSql= " cat_name like '%".trim($query)."%') ";
|
|
// }
|
|
// if($qtype=='ailment_sys_name'){
|
|
// $searchSql= " ailments like '%".trim($query)."%') ";
|
|
// }
|
|
// if($qtype=='item_form'){
|
|
// $searchSql= " item_form like '%".trim($query)."%') ";
|
|
// }
|
|
// if($qtype=='medicine_usage_cat_name'){
|
|
// $searchSql= " medicine_usage_cat_name like '%".trim($query)."%') ";
|
|
// }
|
|
// }
|
|
$searchSql =($qtype != '' && $query != '') ? "where $qtype = '$query'" : '';
|
|
|
|
// Get total count of records
|
|
$ohcSql=($searchSql=='')? "where ohc_type_id ='" . $_SESSION['current_ohcttype'] . "'":" and ohc_type_id ='" . $_SESSION['current_ohcttype'] . "'";
|
|
$sql = "select count(*) from tbl_items $searchSql $ohcSql";
|
|
error_log($sql."count");
|
|
$result = mysqli_query($conn,$sql);
|
|
$row = mysqli_fetch_array($result);
|
|
error_log($row."count");
|
|
$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();
|
|
|
|
|
|
//$sql1 = "select item_stock_id,item_id,item_batch_no,expiry_date,stock_qty from item_stock ";
|
|
$sql1 = "select a.*,b.cat_name,c.form_name,d.unit_name,m.medicine_usage_cat_name,e.ailment_sys_name from tbl_items a left join tbl_categories b on b.cat_id=a.cat left join medicine_form c on c.form_id=a.item_form_id left join unit_master d on d.unit_id=a.unit_id left join ailment_system e on e.ailment_sys_id = a.ailments left join medicine_usage_cat m on m.medicine_usage_cat_id = a.medicine_usage_cat_id ";
|
|
|
|
$sql_export = $sql1;
|
|
$sql1.=" $searchSql $ohcSql $sortSql $limitSql ";
|
|
error_log($sql1."query");
|
|
$sql_export.=" $searchSql $sortSql ";
|
|
|
|
$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'];
|
|
|
|
|
|
//echo $Department_id;
|
|
$view_link="";
|
|
$edit_link="";
|
|
$delete_link="";
|
|
$links="";
|
|
if($hasReadAccess)
|
|
{
|
|
//echo "shubham";
|
|
$view_link="<a href=\"#\"class=\"grey\" onclick=\"view_item('".$item_id."','V');\"><i class=\"ace-icon fa fa-eye bigger-130\"></i></a>";
|
|
}
|
|
|
|
if($hasWriteAccess)
|
|
{
|
|
$edit_link="<a href=\"#\" class=\"blue\" onclick=\"open_item('".$item_id."','E');\"><i class=\"ace-icon fa fa-edit bigger-130\"></i></a>";
|
|
}
|
|
if($hasExecuteAccess)
|
|
{
|
|
if(!hasChildData('item_stock','item_id',$item_id) && !hasChildData('item_stock_dispensary','item_id',$item_id)){
|
|
$delete_link="<a href=\"#\" class=\"red\" onclick=\"delete_item('".$item_id."');\"><i class=\"ace-icon fa fa-trash-o bigger-130\"></i></a>";
|
|
}
|
|
}
|
|
$space=" ";
|
|
$links = $view_link.$space.$edit_link.$space.$delete_link;
|
|
|
|
|
|
|
|
$medicine_usage_cat_name=getTableFieldValue('medicine_usage_cat','medicine_usage_cat_name','medicine_usage_cat_id',$row1['medicine_usage_cat_id']);
|
|
|
|
$cat=getTableFieldValue('tbl_categories','cat_name','cat_id',$row1['cat']);
|
|
$item_form=getTableFieldValue('medicine_form','form_name','form_id',$row1['item_form_id'],'');
|
|
|
|
//$subcat=getTableFieldValue('sub_category','sub_cat_name','sub_cat_id',$row1['subcat'],'');
|
|
$unit=getTableFieldValue('unit_master','unit_name','unit_id',$row1['unit_id'],'');
|
|
|
|
/*$item_ingredients =getCommaSeperatedValuesForInClause("select ingredient_name from ingredient ","ingredient_id",$row1['active_ingredients']);*/
|
|
$item_ailment_systems = getCommaSeperatedValuesForInClause("select ailment_sys_name from ailment_system ","ailment_sys_id",$row1['ailments']);
|
|
|
|
|
|
$item_alternate_med = getCommaSeperatedValuesForInClause("select item_name from tbl_items ","item_id",$row1['item_alternate']);
|
|
$subclass = getCommaSeperatedValuesForInClause("select subclass_name from sub_classification ","subclass_id",$row1['sub_classification']);
|
|
|
|
$composition = getCommaSeperatedValuesForInClause("select composition_name from composition ","composition_id",$row1['composition']);
|
|
|
|
$indication = getCommaSeperatedValuesForInClause("select indication_name from indication ","indication_id",$row1['indication']);
|
|
|
|
$contra_indication = getCommaSeperatedValuesForInClause("select cindication_name from contra_indication ","cindication_id",$row1['contra_indication']);
|
|
|
|
$side_effect = getCommaSeperatedValuesForInClause("select sideeffect_name from side_effects ","sideeffect_id",$row1['side_effects']);
|
|
|
|
$data['rows'][] = array(
|
|
'id' => $row1['item_id'],
|
|
'cell' => array($links,$count++,$item_code,$item_name,$item_ailment_systems,$item_form,$cat,$medicine_usage_cat_name,$item_alternate_med,$row1['min_indent_level'],$row1['max_indent_level'],($status==1?'Active':'Inactive'),$is_prescription==1?'Yes':'No',$reorder_stock_level)
|
|
);
|
|
}
|
|
$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);
|
|
?>
|