127 lines
4.4 KiB
PHP
127 lines
4.4 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/auth/auth.php');
|
|
include('includes/functions.php');
|
|
include('log_entry.php');
|
|
include('access.php');
|
|
|
|
error_reporting(E_ERROR | E_PARSE);
|
|
|
|
// Connect to mysqli database
|
|
// Check if connection is successful
|
|
if (!$conn) {
|
|
error_log('Database connection failed.');
|
|
exit('Database connection failed.');
|
|
}
|
|
|
|
$page = isset($_POST['page']) ? intval($_POST['page']) : 1; // Current page
|
|
$sortname = isset($_POST['sortname']) ? $_POST['sortname'] : 'fee_collection_id'; // Sort column
|
|
$sortorder = isset($_POST['sortorder']) ? $_POST['sortorder'] : 'asc'; // Sort order
|
|
$qtype = isset($_POST['qtype']) ? $_POST['qtype'] : ''; // Search column
|
|
$query = isset($_POST['query']) ? $_POST['query'] : ''; // Search string
|
|
$rp = isset($_POST['rp']) ? intval($_POST['rp']) : 100; // Records per page
|
|
|
|
// Ensure valid column names and order
|
|
$allowed_sort_columns = ['fee_collection_id', 'batch_id', 'beneficiary_id', 'fee_schedule_id', 'fee_amount', 'collection_date', 'collection_status', 'payment_mode', 'payment_remarks'];
|
|
$allowed_sort_orders = ['asc', 'desc'];
|
|
|
|
if (!in_array($sortname, $allowed_sort_columns)) {
|
|
$sortname = 'fee_collection_id'; // Default column
|
|
}
|
|
|
|
if (!in_array($sortorder, $allowed_sort_orders)) {
|
|
$sortorder = 'asc'; // Default order
|
|
}
|
|
|
|
// Access control
|
|
$hasReadAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'R');
|
|
$hasWriteAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'W');
|
|
$hasExecuteAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'E');
|
|
|
|
// Search SQL
|
|
$searchSql = ($qtype != '' && $query != '') ? "WHERE UPPER($qtype) LIKE UPPER(?)" : '';
|
|
|
|
// Get total count of records
|
|
$total_sql = "SELECT COUNT(*) FROM fee_collection $searchSql";
|
|
$stmt = $conn->prepare($total_sql);
|
|
if ($searchSql) {
|
|
$search_query = "%$query%";
|
|
$stmt->bind_param('s', $search_query);
|
|
}
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$row = $result->fetch_array();
|
|
$total = $row[0];
|
|
|
|
// Setup paging
|
|
$pageStart = ($page - 1) * $rp;
|
|
$limitSql = "LIMIT ?, ?";
|
|
|
|
// Prepare SQL query with sorting and paging
|
|
$sql_fee_collection = "SELECT * FROM fee_collection $searchSql ORDER BY $sortname $sortorder $limitSql";
|
|
$stmt = $conn->prepare($sql_fee_collection);
|
|
if ($searchSql) {
|
|
$stmt->bind_param('sii', $search_query, $pageStart, $rp);
|
|
} else {
|
|
$stmt->bind_param('ii', $pageStart, $rp);
|
|
}
|
|
$stmt->execute();
|
|
$result_fee_collection = $stmt->get_result();
|
|
|
|
$data = array();
|
|
$data['page'] = $page;
|
|
$data['total'] = $total;
|
|
$data['rows'] = array();
|
|
$count = ($page - 1) * $rp + 1;
|
|
|
|
while ($row_fee_collection = $result_fee_collection->fetch_assoc()) {
|
|
$fee_collection_id = $row_fee_collection['fee_collection_id'];
|
|
$links = '';
|
|
$batch_name = getFieldFromTable('batch_name', 'training_batch_master', 'batch_id', $row_fee_collection['batch_name']);
|
|
$beneficiary_name = getFieldFromTable('patient_name', 'patient_master', 'id', $row_fee_collection['beneficiary_name']);
|
|
$fee_schedule = getFieldFromTable('schedule_name', 'batch_fee_schedule', 'fee_schedule_id', $row_fee_collection['fee_schedule_id']);
|
|
$collection_date = date_format(date_create($row_fee_collection['collection_date']),"d-m-Y");
|
|
|
|
|
|
|
|
$links = "";
|
|
if ($hasReadAccess) {
|
|
|
|
$links .= "<a href=\"#\"class=\"grey\" onclick=\"open_section('" . $fee_collection_id . "','V');\"><i class=\"ace-icon fa fa-eye bigger-130\"></i></a>";
|
|
}
|
|
if ($hasWriteAccess) {
|
|
$links .= "  <a href=\"#\" class=\"blue\" onclick=\"open_section('" . $fee_collection_id . "','E');\"><i class=\"ace-icon fa fa-edit bigger-130\"></i></a>";
|
|
}
|
|
if ($hasExecuteAccess) {
|
|
$links .= " <a href=\"#\" class=\"red\" onclick=\"delete_section('" . $fee_collection_id . "');\"><i class=\"ace-icon fa fa-trash-o bigger-130\"></i></a>";
|
|
}
|
|
|
|
if ($hasExecuteAccess) {
|
|
$links .= "<a target=\"_blank\" href=\"fees_receipt_pdf.php?id=" . $fee_collection_id . "\"class=\"red\" title=\"Fees Receipt\" ><i class=\"ace-icon fa fa-file-pdf-o\" style=\"font-size: 15px;\"></i></a>";
|
|
}
|
|
|
|
|
|
$data['rows'][] = array(
|
|
'fee_collection_id' => $row_fee_collection['fee_collection_id'],
|
|
'cell' => array(
|
|
$links,
|
|
$count++,
|
|
$batch_name,
|
|
$beneficiary_name,
|
|
$fee_schedule,
|
|
$row_fee_collection['fee_amount'],
|
|
$collection_date,
|
|
$row_fee_collection['payment_mode'],
|
|
$row_fee_collection['remarks'],
|
|
)
|
|
);
|
|
}
|
|
|
|
// Output JSON data
|
|
header('Content-Type: application/json');
|
|
echo json_encode($data);
|
|
|
|
// Close the statement and connection
|
|
$stmt->close();
|
|
$conn->close();
|