'.__('You don\'t have enough privileges to access this area!').'');
}
require SIMBIO.'simbio_GUI/table/simbio_table.inc.php';
require SIMBIO.'simbio_GUI/form_maker/simbio_form_element.inc.php';
require SIMBIO.'simbio_GUI/paging/simbio_paging.inc.php';
require SIMBIO.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
require MDLBS.'reporting/report_dbgrid.inc.php';
$page_title = 'Loan History Report';
$reportView = false;
$num_recs_show = 20;
if (isset($_GET['reportView'])) {
$reportView = true;
}
if (!$reportView) {
?>
setSQLColumn('m.member_id AS \''.__('Member ID').'\'',
'm.member_name AS \''.__('Member Name').'\'',
'l.item_code AS \''.__('Item Code').'\'',
'b.title AS \''.__('Title').'\'',
'l.loan_date AS \''.__('Loan Date').'\'',
'l.due_date AS \''.__('Due Date').'\'', 'l.is_return AS \''.__('Loan Status').'\'');
$reportgrid->setSQLorder('l.loan_date DESC');
$criteria = 'm.member_id IS NOT NULL ';
if (isset($_GET['id_name']) AND !empty($_GET['id_name'])) {
$id_name = $dbs->escape_string($_GET['id_name']);
$criteria .= ' AND (m.member_id LIKE \'%'.$id_name.'%\' OR m.member_name LIKE \'%'.$id_name.'%\')';
}
if (isset($_GET['title']) AND !empty($_GET['title'])) {
$keyword = $dbs->escape_string(trim($_GET['title']));
$words = explode(' ', $keyword);
if (count($words) > 1) {
$concat_sql = ' AND (';
foreach ($words as $word) {
$concat_sql .= " (b.title LIKE '%$word%') AND";
}
// remove the last AND
$concat_sql = substr_replace($concat_sql, '', -3);
$concat_sql .= ') ';
$criteria .= $concat_sql;
} else {
$criteria .= ' AND b.title LIKE \'%'.$keyword.'%\'';
}
}
if (isset($_GET['itemCode']) AND !empty($_GET['itemCode'])) {
$item_code = $dbs->escape_string(trim($_GET['itemCode']));
$criteria .= ' AND i.item_code=\''.$item_code.'\'';
}
// loan date
if (isset($_GET['startDate']) AND isset($_GET['untilDate'])) {
$criteria .= ' AND (TO_DAYS(l.loan_date) BETWEEN TO_DAYS(\''.$_GET['startDate'].'\') AND
TO_DAYS(\''.$_GET['untilDate'].'\'))';
}
// loan status
if (isset($_GET['loanStatus']) AND $_GET['loanStatus'] != 'ALL') {
$loanStatus = (integer)$_GET['loanStatus'];
$criteria .= ' AND is_return='.$loanStatus;
}
if (isset($_GET['recsEachPage'])) {
$recsEachPage = (integer)$_GET['recsEachPage'];
$num_recs_show = ($recsEachPage >= 20 && $recsEachPage <= 200)?$recsEachPage:$num_recs_show;
}
$reportgrid->setSQLCriteria($criteria);
// callback function to show loan status
function loanStatus($obj_db, $array_data)
{
if ($array_data[6] == 0) {
return ''.__('On Loan').'';
} else {
return __('Returned');
}
}
// modify column value
$reportgrid->modifyColumnContent(6, 'callback{loanStatus}');
// put the result into variables
echo $reportgrid->createDataGrid($dbs, $table_spec, $num_recs_show);
echo '';
$xlsquery = 'SELECT m.member_id AS \''.__('Member ID').'\''.
', m.member_name AS \''.__('Member Name').'\''.
', l.item_code AS \''.__('Item Code').'\''.
', b.title AS \''.__('Title').'\''.
', l.loan_date AS \''.__('Loan Date').'\''.
', l.due_date AS \''.__('Due Date').'\', l.is_return AS \''.__('Loan Status').'\''.
' FROM '.$table_spec.' WHERE '.$criteria;
unset($_SESSION['xlsdata']);
$_SESSION['xlsquery'] = $xlsquery;
$_SESSION['tblout'] = "loan_history";
echo '