[03fe3a]: koha-reports / accessPaReport / accessPaReport.php  Maximize  Restore  History

Download this file

137 lines (110 with data), 4.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
## Copyright 2006 Kyle Hall
## This file is part of koha-tools.
## koha-tools is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
## koha-tools is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with koha-tools; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
/**
* This report generates the Access PA Tally Worksheet
* @package koha-tools
* @subpackage koha-reports
* @author Kyle Hall
* @copyright 2007
*/
require_once("../classes/MySQLConnectionFactory.class.php");
require_once("../classes/Template.class.php");
require_once("../classes/KohaStats.php");
$mySqlConnection = new MySQLConnectionFactory;
$dbh = $mySqlConnection->create();
$startDay = $_REQUEST['startDay'];
$startMonth = $_REQUEST['startMonth'];
$startYear = $_REQUEST['startYear'];
$endDay = $_REQUEST['endDay'];
$endMonth = $_REQUEST['endMonth'];
$endYear = $_REQUEST['endYear'];
$endDate = $HTTP_GET_VARS['endYear'] . '-' . $HTTP_GET_VARS['endMonth'] . '-' . $HTTP_GET_VARS['endDay'];
$year = $_REQUEST['startYear'];
$month = $_REQUEST['startMonth'];
$day = $_REQUEST['startDay'];
$library = $_REQUEST['library'];
## Compute the date we are working on
$workingDate = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
$year = substr($workingDate, 0,4);
$month = substr($workingDate, 5, 2);
$day = substr($workingDate, 8, 2);
$reportLines = array();
$totalLoansWithinCounty = 0;
$totalLoansOutsideCounty = 0;
$toalLoans = 0;
while ( $workingDate <= $endDate ) {
$reportLine = array();
$reportLine['date'] = "$month/$day/$year";
$inCountySql =
"SELECT COUNT( * ) AS checkouts
FROM statistics, borrowers
WHERE statistics.borrowernumber = borrowers.borrowernumber
AND (
statistics.type = 'issue'
OR statistics.type = 'renew'
)
AND statistics.datetime LIKE '$workingDate%'
AND borrowers.branchcode != '$library'
AND statistics.branch = '$library'
";
$outCountySql =
"SELECT COUNT( * ) AS checkouts
FROM statistics, borrowers
WHERE statistics.borrowernumber = borrowers.borrowernumber
AND (
statistics.type = 'issue'
OR statistics.type = 'renew'
)
AND statistics.datetime LIKE '$workingDate%'
AND borrowers.categorycode = 'AC'
AND statistics.branch = '$library'
";
$resultSet = mysql_query($inCountySql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
$row = mysql_fetch_array($resultSet);
$reportLine['loansWithinCounty'] = $row['checkouts'];
$resultSet = mysql_query($outCountySql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
$row = mysql_fetch_array($resultSet);
$reportLine['loansOutsideCounty'] = $row['checkouts'];
$reportLine['allLoansForLibrary'] = KohaStats::countLoansByDate( $dbh, $workingDate, $workingDate, $library, '' );
$totalAllLoansForLibrary += $reportLine['allLoansForLibrary'];
$totalLoansWithinCounty += $reportLine['loansWithinCounty'];
$totalLoansOutsideCounty += $reportLine['loansOutsideCounty'];
$totalLoans = $totalLoansWithinCounty + $totalLoansOutsideCounty;
$reportLine['totalWithinCounty'] = $totalLoansWithinCounty;
$reportLine['totalOutsideCounty'] = $totalLoansOutsideCounty;
$reportLine['totalLoans'] = $totalLoans;
$reportLines[] = $reportLine;
## Compute the next date to work on.
$workingDate = date("Y-m-d", mktime(0, 0, 0, $month, $day + 1, $year));
$year = substr($workingDate, 0,4);
$month = substr($workingDate, 5, 2);
$day = substr($workingDate, 8, 2);
}
$sql = "SELECT branchname FROM branches WHERE branchcode = '$library'";
$resultSet = mysql_query($sql);
$row = mysql_fetch_array( $resultSet );
$libraryName = $row['branchname'];
$tpl = new Template();
$tpl->set( 'libraryName', $libraryName);
$tpl->set( 'today', date('l dS \of F Y') );
$tpl->set( 'startDate', "$startMonth/$startDay/$startYear" );
$tpl->set( 'endDate', "$endMonth/$endDay/$endYear" );
$tpl->set( 'reportLines', $reportLines );
$tpl->set( 'totalLoansWithinCounty', $totalLoansWithinCounty );
$tpl->set( 'totalLoansOutsideCounty', $totalLoansOutsideCounty );
$tpl->set( 'totalLoans', $totalLoans );
$tpl->set( 'totalAllLoansForLibrary', $totalAllLoansForLibrary );
echo $tpl->fetch( 'accessPaReport.tpl' );
?>