[r568]: kohaReports / trunk / usageByItemType-PreviousYear / usageByItemType.php Maximize Restore History

Download this file

usageByItemType.php    99 lines (75 with data), 2.8 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
<?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 reports generates a count of borrowers by borrower type.
* @package koha-tools
* @subpackage koha-reports
* @author Kyle Hall
* @copyright 2006
*/
require_once("../classes/KohaStats.php");
require_once("../classes/Template.class.php");
require_once("../classes/MySQLConnectionFactory.class.php");
$mysqli = MySQLConnectionFactory::createi();
$mysql = MySQLConnectionFactory::create();
$library = mysqli_escape_string( $mysqli, $_REQUEST['library'] );
//Get an array of item types
$itemtypes = array();
$query = "SELECT itemtype, description FROM itemtypes";
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
$itemtypes[] = $row;
}
/* free result set */
$result->close();
}
$currentYear = date("Y") - 1;
$currentMonth = 12;
$stats = array();
$totals = array();
$months = array();
for ( $i = 11; $i >= 0; $i-- ) {
$month = $currentMonth - $i;
$year = $currentYear;
if ( $month <= 0 ) {
$month += 12;
$year--;
}
$startDay = "01";
$timestamp = mktime( 0, 0, 0, $month, $startDay, $year );
$lastDay = date( "t", $timestamp );
$months[] = date( "M", $timestamp );
$startDate = "$year-$month-$startDay";
$endDate = "$year-$month-$lastDay";
foreach ( $itemtypes as $itemtype ) {
$usage = KohaStats::countLoansByDate( $mysql, $startDate, $endDate, $library, $itemtype['itemtype'] );
$stats[ date( "M", $timestamp ) ][ $itemtype['itemtype'] ] = $usage;
$totals['month'][ date( "M", $timestamp ) ] += $usage;
$totals['itemtype'][ $itemtype['itemtype'] ] += $usage;
}
}
foreach ( $itemtypes as $i ) {
$stats[ 'Totals' ][ $i['itemtype'] ] = $totals['itemtype'][ $i['itemtype'] ];
}
foreach ( $months as $m ) {
$stats[ $m ][ 'Totals' ] = $totals['month'][ $m ];
$stats[ 'Totals' ][ 'Totals' ] += $totals['month'][ $m ];
}
$tpl = new Template();
$tpl->set( 'itemtypes', $itemtypes );
$tpl->set( 'stats', $stats );
echo $tpl->fetch('usageByItemType.tpl');
?>