206 lines
6.6 KiB
PHP
206 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
|
|
|
|
$isOhcSpecific = getConfigKey("IS_OHC_SPECIFIC");
|
|
error_log("IS NOTICE OHC SPECFIC-> " . $isOhcSpecific);
|
|
$AndOhcFilter = "";
|
|
$WhereOhcFilter = "";
|
|
$CommaOhcFilter = "";
|
|
// if ($isOhcSpecific == "TRUE") {
|
|
// $AndOhcFilter = "and ohc_type_id ='" . $_SESSION['current_ohcttype'] . "' ";
|
|
|
|
// $WhereOhcFilter = "where ohc_type_id = '" . $_SESSION['current_ohcttype'] . "' ";
|
|
|
|
// $CommaOhcFilter = "ohc_type_id = '" . $_SESSION['current_ohcttype'] . "' ";
|
|
// }
|
|
|
|
// Connect to mysqli database
|
|
$page = 1; // The current page
|
|
$sortname = 'sub_center'; // 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";
|
|
if ($qtype == 'item_name') {
|
|
|
|
$searchSql = " and item_id in ( select item_id from tbl_items where status='1' and item_name like '%" . trim($query) . "%')$AndOhcFilter and stock_qty>0 ";
|
|
}
|
|
else if ($qtype == 'item_code') {
|
|
|
|
$searchSql = " and item_id in ( select item_id from tbl_items where item_code like '%" . trim($query) . "%') $AndOhcFilter and stock_qty>0";
|
|
}
|
|
// else if ($qtype == 'usage_cat') {
|
|
// $searchSql = " and medicine_usage_cat_id in ( select medicine_usage_cat_id from medicine_usage_cat where medicine_usage_cat_name like '%" . trim($query) . "%') and item_id in (select item_id from items_id where status='1') $AndOhcFilter and stock_qty>0";
|
|
// }
|
|
else if ($qtype == 'expiry_date') {
|
|
$time = strtotime(trim($query));
|
|
$exp_date = date('Y-m-d', $time);
|
|
$searchSql = "and expiry_date = '" . $exp_date . "'";
|
|
} else {
|
|
$searchSql = "and upper($qtype) like upper('%" . trim($query) . "%') and stock_qty>0";
|
|
}
|
|
|
|
$ohc_id = $_SESSION['current_ohcttype'];
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
$staff_id = getFieldFromTable('emp_id','tbl_users','user_id',$user_id);
|
|
$staff_category = getFieldFromTable('staff_category','staff_master','staff_id',$staff_id);
|
|
$sub_c_id = getFieldFromTable('sub_center','staff_master','staff_id',$staff_id);
|
|
error_log($user_id."user_id ".$staff_id."staff_id ".$staff_category."staff_category".$sub_c_id."dipak mali");
|
|
|
|
|
|
|
|
// Get total count of records
|
|
$sql = "select count(*) from sub_center_stock where sub_center = '".$sub_c_id."' $searchSql ";
|
|
|
|
error_log("stock query count" . $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;
|
|
$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 * from sub_center_stock where sub_center = '".$sub_c_id."'";
|
|
error_log("Dipak mali " . $sql1);
|
|
|
|
|
|
$sql_export = $sql1;
|
|
$sql1 .= " $searchSql $sortSql $limitSql ";
|
|
|
|
|
|
error_log("stock query " . $sql1);
|
|
|
|
$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)) {
|
|
|
|
$total_available = 0;
|
|
$total_hold = 0;
|
|
$total_stock = 0;
|
|
|
|
extract($row1);
|
|
$item_id = $row1['item_id'];
|
|
$sub_center_name = getFieldFromTable('sub_center_name', 'sub_center', 'id', $sub_center);
|
|
$item_desc = getFieldFromTable('item_name', 'tbl_items', 'item_id', $item_id);
|
|
$item_code = getTableFieldValue('tbl_items', 'item_code', 'item_id', $item_id);
|
|
$unit_id = getTableFieldValue('tbl_items', 'unit_id', 'item_id', $item_id);
|
|
|
|
$item_batch_no = $row1['item_batch_no'];
|
|
$stock_qty = $row1['stock_qty'];
|
|
// $unit_name = getTableFieldValue('unit_master', 'unit_name', 'unit_id', $unit_id);
|
|
$unit_name = '';
|
|
$medicine_usage_cat_name = getTableFieldValue('medicine_usage_cat', 'medicine_usage_cat_name', 'medicine_usage_cat_id', $row1['medicine_usage_cat_id']);
|
|
|
|
$sql_details = "";
|
|
|
|
if ($qtype != '' && $qtype == 'expiry_date' && $query != '') {
|
|
$exp_date = date('Y-m-d', strtotime($query));
|
|
$sql_details = "select * from sub_center_stock where item_id='" . $row1['item_id'] . "' and expiry_date='" . $exp_date . "' $AndOhcFilter";
|
|
} else {
|
|
$sql_details = "select * from sub_center_stock where item_id='" . $row1['item_id'] . "' $AndOhcFilter";
|
|
}
|
|
error_log("Detail Query" . $sql_details);
|
|
$result_details = mysqli_query($conn, $sql_details);
|
|
$detailed_info = '';
|
|
$batch_info = '';
|
|
$expiry_info = '';
|
|
$rate='';
|
|
$batch_avl_qty = '';
|
|
|
|
|
|
|
|
//$links = $edit_link1;
|
|
$total_available += floatval($total_stock) - floatval($total_hold);
|
|
$data['rows'][] = array(
|
|
'id' => $row1['id'],
|
|
'cell' => array(
|
|
$count++,
|
|
$sub_center_name,
|
|
$item_desc,
|
|
$item_code,
|
|
|
|
// $total_stock,
|
|
$rate,
|
|
// $total_hold . " " . $unit_name,
|
|
// $total_available . " " . $unit_name,
|
|
$item_batch_no,
|
|
$stock_qty,
|
|
// $batch_avl_qty,
|
|
$expiry_info
|
|
|
|
)
|
|
);
|
|
}
|
|
$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);
|
|
?>
|