138 lines
4.5 KiB
PHP
138 lines
4.5 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);
|
|
|
|
|
|
// 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
|
|
$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 != '') ? "where upper($qtype) like upper('%$query%')" : '';
|
|
if ($searchSql != '') {
|
|
|
|
if ($qtype == 'procurement_date') {
|
|
|
|
$searchSql = " and date_format(date(procurement_date),'%Y-%m-%d')=str_to_date('$query','%d-%m-%Y') ";
|
|
//echo $searchSql;
|
|
}
|
|
}
|
|
// Get total count of records
|
|
$searchSql=preg_replace('/and/', 'where', $searchSql, 1);
|
|
$sql = "select count(*) from tbl_items where item_id in (select group_id from group_items group by group_id)";
|
|
//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();
|
|
$sql1 = "select item_name,item_id,item_code from tbl_items where item_id in (select group_id from group_items group by group_id) ";
|
|
//echo $sql1;
|
|
$results = mysqli_query($conn,$sql1);
|
|
//echo $results;
|
|
//echo mysqli_error($conn$results);
|
|
$count=($page-1)*$rp+1;
|
|
//echo $sql_ailment;
|
|
//echo $access_level;
|
|
|
|
while ($row1= mysqli_fetch_assoc($results)) {
|
|
|
|
|
|
$id1=$row1['item_id'];
|
|
//echo $Department_id;
|
|
$view_link="";
|
|
$edit_link="";
|
|
$delete_link="";
|
|
$links="";
|
|
if($hasReadAccess)
|
|
{
|
|
//echo "shubham";
|
|
//$view_link="<a href=\"#\"class=\"green\" onclick=\"open_group_items('".$id."','V');\"><i class=\"ace-icon fa fa-search-plus bigger-130\"></i></a>";
|
|
}
|
|
|
|
//echo $hasWriteAccess;
|
|
if($hasWriteAccess)
|
|
{
|
|
$edit_link="<a href=\"#\" class=\"blue\" onclick=\"open_group_items('".$id1."','E');\"><i class=\"ace-icon fa fa-edit bigger-130\"></i></a>";
|
|
}
|
|
if($hasExecuteAccess)
|
|
{
|
|
$delete_link="<a href=\"#\" class=\"red\" onclick=\"delete_group_items('".$id1."','E');\"><i class=\"ace-icon fa fa-trash-o bigger-130\"></i></a>";
|
|
}
|
|
$item_desc="";
|
|
$item_qty="";
|
|
|
|
//$item_rate="";
|
|
|
|
$sql_group_items=" select * from group_items where group_id=$id1";
|
|
$results_group_items= mysqli_query($conn,$sql_group_items);
|
|
$item_desc="";
|
|
while ($row_group_items= mysqli_fetch_assoc($results_group_items)) {
|
|
$item_desc = $item_desc.' <p> '.getTableFieldValue('tbl_items','item_name','item_id',$row_group_items['item_id']).'</p>';
|
|
|
|
$item_unit_id =getTableFieldValue(' tbl_items','unit_id','item_id',$row_group_items['item_id']);
|
|
$item_unit =getTableFieldValue(' unit_master','unit_name','unit_id',$item_unit_id);
|
|
$item_qty=$item_qty.' <p> '.$row_group_items['qty'].' '.$item_unit.'</p>';
|
|
$item_type=$row_group_items['item_type'];
|
|
$cost = $row_group_items['cost'];
|
|
}
|
|
/*$item_desc = $item_desc.' <p> '.getTableFieldValue('tbl_items','item_name','item_id',$row1['item_id']).'</p>';
|
|
$item_unit_id=getTableFieldValue('tbl_items','unit_id','item_id',$row1['item_id']);
|
|
$item_unit =getTableFieldValue(' unit_master','unit_name','unit_id',$item_unit_id);
|
|
$item_qty=$item_qty.' <p> '.$row1['qty'].' '.$item_unit.'</p>';*/
|
|
|
|
// echo $item_expiry_date;
|
|
|
|
|
|
|
|
$space=" ";
|
|
$links = $assign_link.$space.$view_link.$space.$edit_link;
|
|
|
|
|
|
$data['rows'][] = array(
|
|
'id' => $row1['id'],
|
|
'cell' => array($count++,$row1['item_name'],$item_type==1?'Grouping Item':'Packaging Item',$item_desc,$item_qty,$cost,$edit_link)
|
|
);
|
|
}
|
|
|
|
echo json_encode($data);
|