--- a
+++ b/kohaReports/trunk/usageByItemType-PreviousYear/usageByItemType.php
@@ -0,0 +1,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');
+
+?>