loan_history

  1. <?php
  2. /**
  3.  *
  4.  * Copyright (C) 2007,2008  Arie Nugraha (dicarve@yahoo.com)
  5.  * Modified for Excel output (C) 2010 by Wardiyono (wynerst@gmail.com)
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  */
  22. /* Loan History By Members */
  23.  
  24. // key to authenticate
  25. define(‘INDEX_AUTH’, ‘1’);
  26.  
  27. // main system configuration
  28. require ‘../../../../sysconfig.inc.php’;
  29. // IP based access limitation
  30. require LIB.’ip_based_access.inc.php’;
  31. do_checkIP(‘smc’);
  32. do_checkIP(‘smc-circulation’);
  33. // start the session
  34. require SB.’admin/default/session.inc.php’;
  35. require SB.’admin/default/session_check.inc.php’;
  36. // privileges checking
  37. $can_read = utility::havePrivilege(‘circulation’, ‘r’) || utility::havePrivilege(‘reporting’, ‘r’);
  38. $can_write = utility::havePrivilege(‘circulation’, ‘w’) || utility::havePrivilege(‘reporting’, ‘w’);
  39.  
  40. if (!$can_read) {
  41.     die(‘<div class=”errorBox”>’.__(‘You don\’t have enough privileges to access this area!’).'</div>’);
  42. }
  43.  
  44. require SIMBIO.’simbio_GUI/table/simbio_table.inc.php’;
  45. require SIMBIO.’simbio_GUI/form_maker/simbio_form_element.inc.php’;
  46. require SIMBIO.’simbio_GUI/paging/simbio_paging.inc.php’;
  47. require SIMBIO.’simbio_DB/datagrid/simbio_dbgrid.inc.php’;
  48. require MDLBS.’reporting/report_dbgrid.inc.php’;
  49.  
  50. $membershipTypes = membershipApi::getMembershipType($dbs);
  51. $page_title = ‘Loan History Report’;
  52. $reportView = false;
  53. $num_recs_show = 20;
  54. if (isset($_GET[‘reportView’])) {
  55.     $reportView = true;
  56. }
  57.  
  58. if (!$reportView) {
  59. ?>
  60.     <!– filter –>
  61.     <div class=”per_title”>
  62.         <h2><?php echo __(‘Loan History’); ?></h2>
  63.       </div>
  64.     <div class=”infoBox”>
  65.     <?php echo __(‘Report Filter’); ?>
  66.     </div>
  67.     <div class=”sub_section”>
  68.     <form method=”get” action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” target=”reportView”>
  69.     <div id=”filterForm”>
  70.         <div class=”form-group divRow”>
  71.             <label><?php echo __(‘Member ID’).’/’.__(‘Member Name’); ?></label>
  72.             <?php echo simbio_form_element::textField(‘text’, ‘id_name’, ”, ‘class=”form-control col-4″‘); ?>
  73.         </div>
  74.         <div class=”form-group divRow”>
  75.             <label><?php echo __(‘Membership Type’); ?></label>
  76.             <select name=”membershipType” class=”form-control col-3″>
  77.             <?php
  78.             foreach ($membershipTypes as $key => $membershipType) {
  79.             echo ‘<option value=”‘.$membershipType[‘member_type_name’].'”>’.$membershipType[‘member_type_name’].'</option>’;
  80.             }
  81.             ?>
  82.             </select>
  83.         </div>
  84.         <div class=”form-group divRow”>
  85.             <label><?php echo __(‘Title’); ?></label>
  86.             <?php
  87.             echo simbio_form_element::textField(‘text’, ‘title’, ”, ‘class=”form-control col-5″‘);
  88.             ?>
  89.         </div>
  90.         <div class=”form-group divRow”>
  91.             <label><?php echo __(‘Item Code’); ?></label>
  92.             <?php
  93.             echo simbio_form_element::textField(‘text’, ‘itemCode’, ”, ‘class=”form-control col-5″‘);
  94.             ?>
  95.         </div>
  96.         <div class=”form-group divRow”>
  97.             <label><?php echo __(‘Loan Date From’); ?></label>
  98.             <?php
  99.             echo simbio_form_element::dateField(‘startDate’, ‘2000-01-01’,’class=”form-control”‘);
  100.             ?>
  101.         </div>
  102.         <div class=”form-group divRow”>
  103.             <label><?php echo __(‘Loan Date Until’); ?></label>
  104.             <?php
  105.             echo simbio_form_element::dateField(‘untilDate’, date(‘Y-m-d’),’class=”form-control”‘);
  106.             ?>
  107.         </div>
  108.         <div class=”form-group divRow”>
  109.             <label><?php echo __(‘Loan Status’); ?></label>
  110.             <select name=”loanStatus” class=”form-control col-2″><option value=”ALL”><?php echo __(‘ALL’); ?></option><option value=”0″><?php echo __(‘On Loan’); ?></option><option value=”1″><?php echo __(‘Returned’); ?></option></select>
  111.         </div>
  112.         <div class=”form-group divRow”>
  113.             <label><?php echo __(‘Location’); ?></label>
  114.             <?php
  115.             $loc_q = $dbs->query(‘SELECT location_id, location_name FROM mst_location’);
  116.             $loc_options = array();
  117.             $loc_options[] = array(”, __(‘ALL’));
  118.             while ($loc_d = $loc_q->fetch_row()) {
  119.                 $loc_options[] = array($loc_d[1], $loc_d[1]);
  120.             }
  121.             echo simbio_form_element::selectList(‘location’, $loc_options,”,’class=”form-control col-3″‘);
  122.             ?>
  123.         </div>
  124.         <div class=”form-group divRow”>
  125.             <label><?php echo __(‘Collection Type’); ?></label>
  126.             <?php
  127.             $coll_type_q = $dbs->query(‘SELECT coll_type_name FROM mst_coll_type’);
  128.             $coll_type_options = array();
  129.             $coll_type_options[] = array(”, __(‘ALL’));
  130.             while ($coll_type_d = $coll_type_q->fetch_row()) {
  131.                 $coll_type_options[] = array($coll_type_d[0], $coll_type_d[0]);
  132.             }
  133.            echo simbio_form_element::selectList(‘coll_type’, $coll_type_options,”,’class=”form-control col-3″‘);
  134.             ?>
  135.         </div>  
  136.  
  137.         <div class=”form-group divRow”>
  138.             <label><?php echo __(‘Record each page’); ?></label>
  139.             <input type=”text” name=”recsEachPage” size=”3″ maxlength=”3″ class=”form-control col-1″ value=”<?php echo$num_recs_show; ?>” />
  140.             <small class=”text-muted”><?php echo __(‘Set between 20 and 200’); ?></small>
  141.         </div>
  142.     </div>
  143.     <input type=”button” class=”s-btn btn btn-default” name=”moreFilter” value=”<?php echo __(‘Show More Filter Options’); ?>” />
  144.     <input type=”submit” class=”s-btn btn btn-primary” name=”applyFilter” value=”<?php echo __(‘Apply Filter’); ?>” />
  145.     <input type=”hidden” name=”reportView” value=”true” />
  146.     </form>
  147.     </div>
  148.     <!– filter end –>
  149.     <div class=”paging-area”><div class=”pt-3 pr-3″ id=”pagingBox”></div></div>
  150.     <iframe name=”reportView” id=”reportView” src=”<?php echo $_SERVER[‘PHP_SELF’].’?reportView=true’; ?>” frameborder=”0″ style=”width: 100%; height: 500px;”></iframe>
  151. <?php
  152. } else {
  153.     ob_start();
  154.     // table spec
  155.     $table_spec = ‘loan_history’;
  156.  
  157.     // create datagrid
  158.     $reportgrid = new report_datagrid();
  159.     $reportgrid->table_attr = ‘class=”s-table table table-sm table-bordered”‘;
  160.  
  161.     $reportgrid->setSQLColumn(‘member_id AS \”.__(‘Member ID’).’\”,
  162.         ‘member_name AS \”.__(‘Member Name’).’\”,
  163.         ‘member_type_name AS \”.__(‘Membership Type’).’\”,
  164.         ‘item_code AS \”.__(‘Item Code’).’\”,
  165.         ‘title AS \”.__(‘Title’).’\”,
  166.         ‘loan_date AS \”.__(‘Loan Date’).’\”,
  167.         ‘due_date AS \”.__(‘Due Date’).’\”, ‘is_return AS \”.__(‘Loan Status’).’\”);
  168.     $reportgrid->setSQLorder(‘loan_date DESC’);
  169.  
  170.     $criteria = ‘member_id IS NOT NULL ‘;
  171.     if (isset($_GET[‘id_name’]) AND !empty($_GET[‘id_name’])) {
  172.         $id_name = utility::filterData(‘id_name’, ‘get’, truetruetrue);
  173.         $criteria .= ‘ AND (member_id LIKE \’%’.$id_name.’%\’ OR member_name LIKE \’%’.$id_name.’%\’)’;
  174.     }
  175.     if (isset($_GET[‘title’]) AND !empty($_GET[‘title’])) {
  176.         $keyword = utility::filterData(‘title’, ‘get’, truetruetrue);
  177.         $words = explode(‘ ‘, $keyword);
  178.         if (count($words) > 1) {
  179.             $concat_sql = ‘ AND (‘;
  180.             foreach ($words as $word) {
  181.                 $concat_sql .= ” (title LIKE ‘%$word%’) AND”;
  182.             }
  183.             // remove the last AND
  184.             $concat_sql = substr_replace($concat_sql, ”, -3);
  185.             $concat_sql .= ‘) ‘;
  186.             $criteria .= $concat_sql;
  187.         } else {
  188.             $criteria .= ‘ AND title LIKE \’%’.$keyword.’%\”;
  189.         }
  190.     }
  191.     if (isset($_GET[‘itemCode’]) AND !empty($_GET[‘itemCode’])) {
  192.         $item_code = utility::filterData(‘itemCode’, ‘get’, truetruetrue);
  193.         $criteria .= ‘ AND item_code=\”.$item_code.’\”;
  194.     }
  195.     // loan date
  196.     if (isset($_GET[‘startDate’]) AND isset($_GET[‘untilDate’])) {
  197.         $criteria .= ‘ AND (TO_DAYS(loan_date) BETWEEN TO_DAYS(\”.utility::filterData(‘startDate’, ‘get’, truetruetrue).’\’) AND
  198.            TO_DAYS(\”.utility::filterData(‘untilDate’, ‘get’, truetruetrue).’\’))’;
  199.     }
  200.     // loan status
  201.     if (isset($_GET[‘loanStatus’]) AND $_GET[‘loanStatus’] != ‘ALL’) {
  202.         $loanStatus = (integer)utility::filterData(‘loanStatus’, ‘get’, truetruetrue);
  203.         $criteria .= ‘ AND is_return=’.$loanStatus;
  204.     }
  205.  
  206.     if ((isset($_GET[‘membershipType’])) AND ($_GET[‘membershipType’] != ‘All’)) {
  207.         $membershipType = utility::filterData(‘membershipType’, ‘get’, truetruetrue);
  208.         $criteria .= ‘ AND member_type_name LIKE \”.$membershipType.’\”;
  209.     }else{
  210.         $criteria .= ‘ AND member_type_name LIKE \’%%\”;
  211.     }
  212.    
  213.     // item location    
  214.     if (isset($_GET[‘location’]) AND !empty($_GET[‘location’])) {
  215.         $location = utility::filterData(‘location’, ‘get’, truetruetrue);
  216.         $criteria .= ‘ AND location_name LIKE \”.$location.’\”;
  217.     }
  218.  
  219.     // collection type    
  220.     if (isset($_GET[‘coll_type’]) AND !empty($_GET[‘coll_type’])) {
  221.         $coll_type = utility::filterData(‘coll_type’, ‘get’, truetruetrue);
  222.         $criteria .= ‘ AND collection_type_name LIKE \”.$coll_type.’\”;
  223.     }
  224.    
  225.     if (isset($_GET[‘recsEachPage’])) {
  226.         $recsEachPage = (integer)utility::filterData(‘recsEachPage’, ‘get’, truetruetrue);
  227.         $num_recs_show = ($recsEachPage >= 20 && $recsEachPage <= 200)?$recsEachPage:$num_recs_show;
  228.     }
  229.     $reportgrid->setSQLCriteria($criteria);
  230.  
  231.    // callback function to show loan status
  232.     function loanStatus($obj_db, $array_data)
  233.     {
  234.         if ($array_data[7] == 0) {
  235.             return ‘<strong>’.__(‘On Loan’).'</strong>’;
  236.         } else {
  237.             return __(‘Returned’);
  238.         }
  239.     }
  240.  
  241. echo $criteria;
  242.     // modify column value
  243.     $reportgrid->modifyColumnContent(7, ‘callback{loanStatus}’);
  244.  
  245.     // show spreadsheet export button
  246.     $reportgrid->show_spreadsheet_export = true;
  247.  
  248.     // put the result into variables
  249.     echo $reportgrid->createDataGrid($dbs, $table_spec, $num_recs_show);
  250.  
  251.     echo ‘<script type=”text/javascript”>’.”\n“;
  252.     echo ‘parent.$(\’#pagingBox\’).html(\”.str_replace(array(“\n“, “\r“, “\t“), ”, $reportgrid->paging_set).’\’);’.”\n“;
  253.     echo ‘</script>’;
  254.     $xlsquery = ‘SELECT member_id AS \”.__(‘Member ID’).’\”.
  255.         ‘, member_name AS \”.__(‘Member Name’).’\”.
  256.         ‘, item_code AS \”.__(‘Item Code’).’\”.
  257.         ‘, title AS \”.__(‘Title’).’\”.
  258.         ‘, loan_date AS \”.__(‘Loan Date’).’\”.
  259.         ‘, due_date AS \”.__(‘Due Date’).’\’, is_return AS \”.__(‘Loan Status’).’\”.
  260.         ‘ FROM ‘.$table_spec.’ WHERE ‘.$criteria;
  261.  
  262.         unset($_SESSION[‘xlsdata’]);
  263.         $_SESSION[‘xlsquery’] = $xlsquery;
  264.         $_SESSION[‘tblout’] = “loan_history”;
  265.  
  266.     //echo ‘<div class=”s-export”><a href=”../xlsoutput.php” class=”s-btn btn btn-default”>’.__(‘Export to spreadsheet format’).'</a></div>’;
  267.  
  268.     $content = ob_get_clean();
  269.     // include the page template
  270.     require SB.’/admin/’.$sysconf[‘admin_template’][‘dir’].’/printed_page_tpl.php’;
  271. }
  272. ?>

RAW Paste Data