160 lines
6.9 KiB
PHP
160 lines
6.9 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) like upper('%" . trim($query) . "%')" : '';
|
|
if ($searchSql != '') {
|
|
if ($qtype == 'item_code') {
|
|
$searchSql = " and item_code = '" . trim($query) . "' ";
|
|
}
|
|
if ($qtype == 'item_desc') {
|
|
$searchSql = " and item_name = '" . trim($query) . "' ";
|
|
}
|
|
// if($qtype=='cat'){
|
|
// $searchSql= " and cat_name like '%".trim($query)."%') ";
|
|
// }
|
|
// if($qtype=='ailment_sys_id'){
|
|
// $searchSql= " and ailments like '%".trim($query)."%') ";
|
|
// }
|
|
// if($qtype=='status'){
|
|
// $searchSql= " and status like '%".trim($query)."%') ";
|
|
// }
|
|
// if($qtype=='is_prescription'){
|
|
// $searchSql= " and is_prescription like '%".trim($query)."%') ";
|
|
// }
|
|
// if($qtype=='item_form'){
|
|
// $searchSql= " and item_form like '%".trim($query)."%') ";
|
|
// }
|
|
}
|
|
|
|
// Get total count of records
|
|
$sql = "select count(*) from tbl_items where (ohc_type_id ='" . $_SESSION['current_ohcttype'] . "' OR ohc_type_id='0' ) $searchSql";
|
|
error_log($sql . "count");
|
|
$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;
|
|
$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 where ( a.ohc_type_id ='" . $_SESSION['current_ohcttype'] . "' OR a.ohc_type_id='0') ";
|
|
|
|
$sql_export = $sql1;
|
|
$sql1 .= " $searchSql $sortSql $limitSql ";
|
|
|
|
$sql_export .= " $searchSql $sortSql ";
|
|
|
|
$results = mysqli_query($conn, $sql1);
|
|
$count = ($page - 1) * $rp + 1;
|
|
error_log("sql for item " . $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=\"open_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']);
|
|
|
|
$subclass = getCommaSeperatedValuesForInClause("select subclass_name from sub_classification ", "subclass_id", $row1['sub_classification']);
|
|
|
|
$alternate = get_alternate_medicine_data($row1['item_id']);
|
|
$composition = get_med_salt_details($row1['item_id']);
|
|
|
|
$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, $composition, $alternate, $row1['min_indent_level'], $row1['max_indent_level'], ($status == 1 ? 'Active' : 'Inactive'), $is_prescription == 1 ? 'Yes' : 'No', $row1['reorder_store_level'], $subclass, $indication, $contra_indication, $side_effect, $row1['interaction'], $row1['item_precaution'])
|
|
);
|
|
}
|
|
$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);
|
|
?>
|