forked from pdxlibrary/LibRooms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_fines.php
384 lines (316 loc) · 11.9 KB
/
report_fines.php
1
<?phpsession_start();require_once("config/config.inc.php");require_once("config/strings.inc.php");require_once("includes/Database.php");require_once("load.php");require_once("includes/verify_access.php");restrict_access($db,array("admin"));$format = $_GET['format'];if(isset($_GET['start_date'])) $start_date = $_GET['start_date'];else $start_date = date('m/1/Y',strtotime('now'));if(isset($_GET['end_date'])) $end_date = $_GET['end_date'];else $end_date = date('m/d/Y'); if(isset($_GET['selected_resolution_options'])) $selected_resolution_options = $_GET['selected_resolution_options'];else $selected_resolution_options = array();if(strcmp($format,'excel')){ require_once("includes/header.php"); ?><script language="JavaScript" src="js/jquery.ui.widget.js"></script><script language="JavaScript" src="js/jquery.ui.dialog.js"></script><script language="JavaScript" src="js/jquery.ui.core.js"></script><script language="JavaScript" src="js/jquery.ui.position.js"></script><link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/base/jquery-ui.css" type="text/css" media="all" /><script type="text/javascript" language="javascript" src="js/jquery.ui.datepicker.js"></script><script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script><script type="text/javascript" charset="utf-8"> jQuery(document).ready(function($) { // turn off caching for ajax calls, fixes IE caching issue jQuery.ajaxSetup({ cache: false }); $("#start_date").datepicker(); $("#end_date").datepicker(); <?php if(!isset($_GET['submitted'])) { print("select_all('reservation_fine_field');\n"); } ?> <?php if(isset($_GET['submitted'])) { print("$(\"#fine_report_form\").toggle(false);\n"); print("$(\"#show_fine_report_form\").toggle(true);\n"); } ?> $( "#reduce_dialog" ).dialog({ width: 600, height: 550, autoOpen: false, modal: true, closeText: 'hide', beforeClose: function(event, ui) { document.location.href='?<?php print($_SERVER['QUERY_STRING']); ?>'; } }); }); function show_fine_report_form() { $("#fine_report_form").toggle(true); $("#show_fine_report_form").toggle(false); } function select_all(class_name) { $("."+class_name).prop("checked",true); } function select_none(class_name) { $("."+class_name).prop("checked",false); } function resolve_fines(reservation_id) { // ajax call to resolve fine $.ajax({ type: "POST", url: "save.php", data:{table:"fines",field:"resolved",value:"1",reservation_id:reservation_id}, success: function(data){ $(".fine_row"+reservation_id).hide('slow'); } }); } function open_reduce_fine_dialog(fine_id) { $("#reduce_dialog").html("<iframe style='border: 0px;' SRC='fine_reduction.php?fine_id="+fine_id+"' width='100%' height='100%'></iframe>"); $("#reduce_dialog").dialog('open'); } function close_reduce_fine_dialog() { $("#reduce_dialog").dialog("close"); $("#reduce_dialog").html(""); }</script><link rel="stylesheet" href="css/jquery-ui.css" type="text/css" media="all" /><link rel="stylesheet" href="css/results_table.css" type="text/css" media="all" /><?php // reduce fine popup print("<div id='reduce_dialog' title='Reduce Fine'>\n</div>\n"); print("<div id='PageTitle'>Fine Report</div>\n"); print("<div class='breadcrumb'><a href='http://library.pdx.edu'>Home</a> » <a href='index.php'>Reserve a Study Room</a> » <a href='reports.php'>Reports</a> » Fine Report</div>\n"); print("<br>\n"); print("<div id='show_fine_report_form' style='display:none'><input type='button' onClick='show_fine_report_form()' value='Show Fines Report Selection Form'><br><br></div>\n"); print("<div id='fine_report_form'>\n"); print("<form>\n"); print("<h2>Date Range</h2>\n"); print("<blockquote>\n"); print("<input id='start_date' name='start_date' size='8' value='$start_date'> through <input id='end_date' name='end_date' size='8' value='$end_date'>\n"); print("</blockquote>\n"); print("<hr>\n"); print("<h2>Resolution Status</h2>\n"); print("<blockquote>\n"); foreach($fine_resolution_options as $fine_resolution_option) { if(in_array($fine_resolution_option,$selected_resolution_options)) $checked = "checked"; else $checked = ""; print("<input class='reservation_fine_field' type='checkbox' name='selected_resolution_options[]' value='$fine_resolution_option' $checked>$fine_resolution_option\n"); } print("</blockquote>\n"); print("<hr>\n"); print("<input type='submit' name='submitted' value='Create Report'> <input type='button' onClick='document.location.href=\"?\";' value='Reset Form'>\n"); print("<hr>\n"); print("</form>\n"); print("</div>\n"); if(isset($_GET['submitted'])) { print("<div style='float:right; margin-right:10px'><a href='?".$_SERVER['QUERY_STRING']."&format=excel'>Export to Excel</a></div>\n"); print("<table id='fine_report_table' width='100%' border><thead><tr><th>Date</th><th>Reservation</th><th>Patron ID</th><th>Checkout</th><th>Check-In</td><th>Description</th><th>Amount</th><th>Status</th></tr></thead>\n"); print("<tbody>\n"); $options = array(); $options['active'] = 1; if(strcmp($start_date,'')) $options['sched_start_time'] = date('Y-m-d',strtotime($start_date)); if(strcmp($end_date,'')) $options['sched_end_time'] = date('Y-m-d',strtotime("+1 day",strtotime($end_date))); $options['resolution_options'] = $_GET['selected_resolution_options']; $reservations = load_reservations_with_fines($options); // pr($reservations); foreach($reservations as $reservation) { // calculate row span $row_span = 0; foreach($reservation->fines as $fine) { $row_span++; foreach($fine->reductions as $reduction) { $row_span++; } } if($row_span > 1) $row_span++; // for the total line $user = get_user_by_id($reservation->user_id); $first = true; $total_fines = 0; foreach($reservation->fines as $fine) { $total_fines += $fine->amount; if($fine->resolved == 1) $fine_resolution = "Resolved"; else $fine_resolution = "Unresolved"; if($first) { if(in_array($fine_resolution,$selected_resolution_options)) $rows++; else { $row_span = 0; break; } print("<tr class='fine_row$reservation->id'><td rowspan='$row_span' align='center'>".date('m/d/Y',strtotime($reservation->date))."</td>"); print("<td rowspan='$row_span' align='center'><a href='reservation_details.php?reservation_id=$reservation->id'>Room ".$reservation->room->room_number."<br>(".date('g:ia',strtotime($reservation->sched_start_time))."-".date('g:ia',strtotime($reservation->sched_end_time)).")</a></td>"); print("<td rowspan='$row_span' align='center'><a href='user_details.php?user_id=$user->id'>$user->patron_id</a></td>"); if(strcmp($reservation->key_checkout_time,'')) print("<td rowspan='$row_span' align='center'>".date('m/d/Y g:ia',strtotime($reservation->key_checkout_time))."</td>"); else print("<td rowspan='$row_span' ></td>"); if(strcmp($reservation->key_checkin_time,'')) print("<td rowspan='$row_span' align='center'>".date('m/d/Y g:ia',strtotime($reservation->key_checkin_time))."</td>"); else print("<td rowspan='$row_span' ></td>"); print("<td align='center'>".$fine->description."</td>"); print("<td align='center'>".format2dollars($fine->amount)); if($fine->resolved == 0) print(" (<a href='javascript:open_reduce_fine_dialog($fine->id)'>Reduce</a>)"); print("</td>"); print("<td rowspan='$row_span' align='center'>$fine_resolution"); if($fine->resolved == 0) print("<br><a href='javascript:resolve_fines($reservation->id)'>Resolve Now</a>"); print("</td>"); print("</tr>\n"); $first = false; } else { print("<tr class='fine_row$reservation->id'>"); print("<td align='center'>".$fine->description."</td>"); print("<td align='center'>".format2dollars($fine->amount)); if($fine->resolved == 0) print(" (<a href='javascript:open_reduce_fine_dialog($fine->id)'>Reduce</a>)"); print("</td>"); print("</tr>\n"); } foreach($fine->reductions as $reduction) { $total_fines -= $reduction->amount; print("<tr class='fine_row$reservation->id'>"); print("<td align='center'>".$reduction->description."</td>"); print("<td align='center' style='color:red'>-".format2dollars($reduction->amount)."</td>"); print("</tr>\n"); } } if($row_span > 1) { print("<tr class='fine_row$reservation->id'>"); print("<td align='right'>TOTAL</td>"); print("<td align='center'>".format2dollars($total_fines)."</td>"); print("</tr>\n"); } } print("</tbody>\n"); print("</table>\n"); } require_once("includes/footer.php");}else{ header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=study_rooms_fines_report.xls"); print("<table id='fine_report_table' width='100%' border><thead><tr><th>Date</th><th>Reservation</th><th>Patron ID</th><th>Checkout Time</th><th>Check-In Time</td><th>Description</th><th>Amount</th><th>Resolved</th></tr></thead>\n"); print("<tbody>\n"); $options = array(); $options['active'] = 1; if(strcmp($start_date,'')) $options['sched_start_time'] = $start_date; if(strcmp($end_date,'')) $options['sched_end_time'] = date('Y-m-d',strtotime("+1 day",strtotime($end_date))); $options['resolution_options'] = $_GET['selected_resolution_options']; $reservations = load_reservations_with_fines($options); // pr($reservations); foreach($reservations as $reservation) { // calculate row span $row_span = 0; foreach($reservation->fines as $fine) { $row_span++; foreach($fine->reductions as $reduction) { $row_span++; } } if($row_span > 1) $row_span++; // for the total line $user = get_user_by_id($reservation->user_id); $first = true; $total_fines = 0; foreach($reservation->fines as $fine) { $total_fines += $fine->amount; if($first) { print("<tr><td rowspan='$row_span' align='center'>".date('m/d/Y',strtotime($reservation->date))."</td>"); print("<td rowspan='$row_span' align='center'>Room ".$reservation->room->room_number." (".date('g:ia',strtotime($reservation->sched_start_time))."-".date('g:ia',strtotime($reservation->sched_end_time)).")</td>"); print("<td rowspan='$row_span' align='center'>".$user->patron_id."</td>"); if(strcmp($reservation->key_checkout_time,'')) print("<td rowspan='$row_span' align='center'>".date('g:ia',strtotime($reservation->key_checkout_time))."</td>"); else print("<td rowspan='$row_span' ></td>"); if(strcmp($reservation->key_checkin_time,'')) print("<td rowspan='$row_span' align='center'>".date('g:ia',strtotime($reservation->key_checkin_time))."</td>"); else print("<td rowspan='$row_span' ></td>"); print("<td align='center'>".$fine->description."</td>"); print("<td align='center'>".format2dollars($fine->amount)."</td>"); if($fine->resolved == 1) print("<td rowspan='$row_span' align='center'>Resolved</td>"); else print("<td rowspan='$row_span' align='center'>Unresolved</td>"); print("</tr>\n"); $first = false; } else { print("<tr>"); print("<td align='center'>".$fine->description."</td>"); print("<td align='center'>".format2dollars($fine->amount)."</td>"); print("</tr>\n"); } foreach($fine->reductions as $reduction) { $total_fines -= $reduction->amount; print("<tr>"); print("<td align='center'>".$reduction->description."</td>"); print("<td align='center' style='color:red'>-".format2dollars($reduction->amount)."</td>"); print("</tr>\n"); } } if($row_span > 1) { print("<tr>"); print("<td align='right'>TOTAL</td>"); print("<td align='center'>".format2dollars($total_fines)."</td>"); print("</tr>\n"); } } print("</tbody>\n"); print("</table>\n");}?>