koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha C4/Stats.pm koha-tmpl/intranet-tmpl/npl/en... [dev_week]


From: Chris Cormack
Subject: [Koha-cvs] koha C4/Stats.pm koha-tmpl/intranet-tmpl/npl/en... [dev_week]
Date: Sat, 04 Aug 2007 19:26:27 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         dev_week
Changes by:     Chris Cormack <rangi>   07/08/04 19:26:27

Modified files:
        C4             : Stats.pm 
        koha-tmpl/intranet-tmpl/npl/en/catalogue: moredetail.tmpl 
Added files:
        .              : issues_stats.pl 
        koha-tmpl/intranet-tmpl/npl/en/catalogue: issues_stats.tmpl 

Log message:
        Changing circulation stats

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Stats.pm?cvsroot=koha&only_with_tag=dev_week&r1=1.18.6.1&r2=1.18.6.2
http://cvs.savannah.gnu.org/viewcvs/koha/issues_stats.pl?cvsroot=koha&only_with_tag=dev_week&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/npl/en/catalogue/moredetail.tmpl?cvsroot=koha&only_with_tag=dev_week&r1=1.3.2.3.2.10&r2=1.3.2.3.2.11
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/npl/en/catalogue/issues_stats.tmpl?cvsroot=koha&only_with_tag=dev_week&rev=1.1.2.1

Patches:
Index: C4/Stats.pm
===================================================================
RCS file: /sources/koha/koha/C4/Stats.pm,v
retrieving revision 1.18.6.1
retrieving revision 1.18.6.2
diff -u -b -r1.18.6.1 -r1.18.6.2
--- C4/Stats.pm 11 Jul 2006 13:56:17 -0000      1.18.6.1
+++ C4/Stats.pm 4 Aug 2007 19:26:26 -0000       1.18.6.2
@@ -1,6 +1,6 @@
 package C4::Stats;
 
-# $Id: Stats.pm,v 1.18.6.1 2006/07/11 13:56:17 kados Exp $
+# $Id: Stats.pm,v 1.18.6.2 2007/08/04 19:26:26 rangi Exp $
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -49,7 +49,9 @@
 
 @ISA = qw(Exporter);
 @EXPORT = qw(&UpdateStats &statsreport &TotalOwing
-&TotalPaid &getcharges &Getpaidbranch &unfilledreserves);
+  &TotalPaid &getcharges &Getpaidbranch &unfilledreserves &getcredits
+  &getrefunds &checkReserveByTypeOnly &inhousereturns &issuesbyyear
+  &issues_count &renews_count &returns_count &borrowers_count &reserves_count 
&expired_reserves);
 
 =item UpdateStats
 
@@ -69,126 +71,475 @@
 C<$env-E<gt>{usercode}> specifies the value of the C<usercode> field.
 
 =cut
+
 #'
 sub UpdateStats {
+
        #module to insert stats data into stats table
-       my 
($env,$branch,$type,$amount,$other,$itemnum,$itemtype,$borrowernumber)address@hidden;
+    my (
+        $env,      $branch,         $type,
+        $amount,   $other,          $itemnum,
+        $itemtype, $borrowernumber, $accountno
+      )
+      = @_;
        my $dbh = C4::Context->dbh;
-       if ($branch eq ''){
-               $branch=$env->{'branchcode'};
+    if ( $branch eq '' ) {
+        $branch = $env->{'branchcode'};
        }
+
+    warn
+"MASON: updatedates(): 
$env,$branch,$type,$amount,$other,$itemnum,$itemtype,$borrowernumber,$accountno";
+
        my $user = $env->{'usercode'};
        print $borrowernumber;
+
        # FIXME - Use $dbh->do() instead
-       my $sth=$dbh->prepare("Insert into statistics 
(datetime,branch,type,usercode,value,
-                                       
other,itemnumber,itemtype,borrowernumber) values (now(),?,?,?,?,?,?,?,?)");
-       
$sth->execute($branch,$type,$user,$amount,$other,$itemnum,$itemtype,$borrowernumber);
+    my $sth = $dbh->prepare(
+        "Insert into statistics (datetime,branch,type,usercode,value,
+                                        
other,itemnumber,itemtype,borrowernumber,proccode) values 
(now(),?,?,?,?,?,?,?,?,?)"
+    );
+    $sth->execute(
+        $branch,   $type,           $user,
+        $amount,   $other,          $itemnum,
+        $itemtype, $borrowernumber, $accountno
+    );
        $sth->finish;
 }
 
 # Otherwise, it'd need a POD.
 sub TotalPaid {
-       my ($time,$time2)address@hidden;
-       $time2=$time unless $time2;
+    my ( $date, $date2 ) = @_;
        my $dbh = C4::Context->dbh;
-       my $query="Select * from accountlines,borrowers where (accounttype = 
'Pay' or accounttype ='W' or accounttype='C')
-                                       and accountlines.borrowernumber = 
borrowers.borrowernumber";
-       my @bind = ();
-       if ($time eq 'today'){
-               $query .= " and date = now()";
-       } else {
-               $query.=" and date>=? and date<=?";
-               @bind = ($time,$time2);
-       }
-       #  my $query="Select * from statistics,borrowers
-       #  where statistics.borrowernumber= borrowers.borrowernumber
-       #  and (statistics.type='payment' or statistics.type='writeoff') ";
-       #  if ($time eq 'today'){
-       #    $query=$query." and datetime = now()";
-       #  } else {
-       #    $query.=" and datetime > '$time'";
-       #  }
-       $query.=" order by timestamp";
-         warn $query;
-       my $sth=$dbh->prepare($query);
-       $sth->execute(@bind);
+
+    warn "TotalPaid $date, $date2";
+    my $query = "Select * from statistics,borrowers
+                                 where statistics.borrowernumber= 
borrowers.borrowernumber
+                                       and (statistics.type='payment' or 
statistics.type='writeoff')
+                                               and  date_FORMAT(datetime, 
'%Y-%m-%d' ) >= ?
+                               and  date_FORMAT(datetime, '%Y-%m-%d' ) < ? 
+                                               order by datetime";
+
+    #          warn $query;
+    my $sth = $dbh->prepare($query);
+    $sth->execute( $date, $date2 );
        my @results;
-       while (my $data=$sth->fetchrow_hashref){
-               push @results,$data;
+    my $i = 0;
+    while ( my $data = $sth->fetchrow_hashref ) {
+        $results[$i] = $data;
+        $i++;
        }
        $sth->finish;
-       #  print $query;
-       return(@results);
+    warn $query;
+    return (@results);
 }
 
 # Otherwise, it needs a POD.
-sub getcharges{
-       my($borrowerno,$timestamp)address@hidden;
+sub getcharges {
+    my ( $borrowerno, $timestamp, $accountno ) = @_;
+
+#        warn "MASON: getcharges(): \$borrowerno,\$timestamp,\$accountno= 
$borrowerno,$timestamp,$accountno";
        my $dbh = C4::Context->dbh;
-       my $timestamp2=$timestamp-1;
-       my $query="";
-       my $sth=$dbh->prepare("Select * from accountlines where borrowernumber=?
+    my $timestamp2 = $timestamp - 1;
+    my $query      = "";
+    my $sth;
+
+    # getcharges is now taking accountno. as an argument
+    if ($accountno) {
+        $sth = $dbh->prepare(
+            "Select * from accountlines where borrowernumber=?
+              and accountno = ?"
+        );
+        $sth->execute( $borrowerno, $accountno );
+
+        # this bit left in for old 2 arg usage of getcharges
+    }
+    else {
+        $sth = $dbh->prepare(
+            "Select * from accountlines where borrowernumber=?
        and timestamp = ? and accounttype <> 'Pay' and
-       accounttype <> 'W'");
+              accounttype <> 'W'"
+        );
+        $sth->execute( $borrowerno, $timestamp );
+    }
+
        #  print $query,"<br>";
-       $sth->execute($borrowerno,$timestamp);
-       my $i=0;
+    my $i = 0;
        my @results;
-       while (my $data=$sth->fetchrow_hashref){
+    while ( my $data = $sth->fetchrow_hashref ) {
+
        #    if ($data->{'timestamp'} == $timestamp){
-               $results[$i]=$data;
+        $results[$i] = $data;
                $i++;
+
        #    }
        }
-       return(@results);
+
+    #        warn "MASON: getcharges(): results = @results";
+    return (@results);
+}
+
+# Otherwise, it needs a POD.
+sub getcredits {
+    my ( $date, $date2 ) = @_;
+    my $dbh = C4::Context->dbh;
+
+    #takes date converts to timestamps
+    my $padding = "000000";
+    ( my $a, my $b, my $c ) = unpack( "A4 x1 A2 x1 A2", $date );
+    ( my $x, my $y, my $z ) = unpack( "A4 x1 A2 x1 A2", $date2 );
+    my $timestamp  = $a . $b . $c . $padding;
+    my $timestamp2 = $x . $y . $z . $padding;
+
+    my $sth = $dbh->prepare(
+        "Select * from accountlines,borrowers 
+where (((accounttype = 'LR')  or (accounttype <> 'Pay'))
+and amount < 0  and accountlines.borrowernumber = borrowers.borrowernumber
+and timestamp >=?  and timestamp < ?)"
+    );
+    $sth->execute( $timestamp, $timestamp2 );
+
+    my $i = 0;
+    my @results;
+    while ( my $data = $sth->fetchrow_hashref ) {
+        ( my $hr, my $min ) = unpack( "x8 A2 A2", $data->{'timestamp'} );
+        $data->{'date'} = "$data->{'date'} $hr:$min";
+        $results[$i] = $data;
+        $i++;
+    }
+    return (@results);
 }
 
 # Otherwise, this needs a POD.
-sub Getpaidbranch{
-       my($date,$borrno)address@hidden;
+sub Getpaidbranch {
+    my ( $date, $borrno ) = @_;
        my $dbh = C4::Context->dbh;
-       my $sth=$dbh->prepare("select * from statistics where type='payment' 
and datetime >? and  borrowernumber=?");
-       $sth->execute($date,$borrno);
+    my $sth =
+      $dbh->prepare(
+"select * from statistics where type='payment' and datetime >? and  
borrowernumber=?"
+      );
+    $sth->execute( $date, $borrno );
+
        #  print $query;
-       my $data=$sth->fetchrow_hashref;
+    my $data = $sth->fetchrow_hashref;
        $sth->finish;
-       return($data->{'branch'});
+    return ( $data->{'branch'} );
 }
 
 # FIXME - This is only used in reservereport.pl and reservereport.xls,
 # neither of which is used.
 # Otherwise, it needs a POD.
+
+# unfilledreserves now take a branchcode arg (eg: BL, TPE. MTN) and sorting by 
borrower, date and title.
+# this is used to display outstanding holds per branch re; bug #3427
 sub unfilledreserves {
+
+    my ( $branch, $sort ) = @_;
+    my ( @bind, @results, $i );
        my $dbh = C4::Context->dbh;
-       my $sth=$dbh->prepare("select *,biblio.title from 
reserves,reserveconstraints,biblio,borrowers,biblioitems where found <> 'F' and 
cancellationdate
-                                                               is NULL and 
biblio.biblionumber=reserves.biblionumber and
-                                                               
reserves.constrainttype='o'
-                                                               and 
(reserves.biblionumber=reserveconstraints.biblionumber
-                                                               and 
reserves.borrowernumber=reserveconstraints.borrowernumber)
-                                                               and
+
+    # allowing 'ALL' to be passed as an arg too.
+    if ( $branch eq 'ALL' ) {
+        $branch = '';
+    }
+
+    my $query =
+      "select reserves.*,reserveconstraints.*,borrowers.borrowernumber,
+                       borrowers.surname,      
borrowers.firstname,biblio.title, biblioitems.*
+                       from 
reserves,reserveconstraints,biblio,borrowers,biblioitems
+                       where (found <> 'F' or found is NULL) and
+                       cancellationdate is NULL and 
biblio.biblionumber=reserves.biblionumber and
+            (reserves.constrainttype='o' or reserves.constrainttype='a') and
+                       (reserves.biblionumber=reserveconstraints.biblionumber 
and
+            reserves.borrowernumber=reserveconstraints.borrowernumber) and
                                                                
reserves.borrowernumber=borrowers.borrowernumber and
-                                                               
biblioitems.biblioitemnumber=reserveconstraints.biblioitemnumber order by
-                                                               
biblio.title,reserves.reservedate");
-       $sth->execute;
-       my $i=0;
-       my @results;
-       while (my $data=$sth->fetchrow_hashref){
-               $results[$i]=$data;
+            biblioitems.biblioitemnumber=reserveconstraints.biblioitemnumber";
+    if ( $branch ne '' ) {
+        $query .= " and reserves.branchcode = ?";
+    }
+
+    $query .=
+" group by reserves.borrowernumber,reserves.biblionumber,reserves.itemnumber";
+
+    if ( $sort eq 'name' ) {
+        $query .= " order by borrowers.surname, biblio.title";
+    }
+    elsif ( $sort eq 'title' ) {
+        $query .= " order by biblio.title,  reserves.reservedate desc";
+    }
+    elsif ( $sort eq 'date' || sort eq '' ) {    # sort by date as default.
+        $query .=
+" order by reserves.reservedate desc, borrowers.surname, biblio.title";
+    }
+
+    my $sth = $dbh->prepare($query);
+    if ( $branch ne '' ) {
+        push( @bind, $branch );
+    }
+    $sth->execute(@bind);
+    warn "$query $branch";
+
+    #  my @results
+    while ( my $data = $sth->fetchrow_hashref ) {
+        $results[$i] = $data;
                $i++;
        }
+
        $sth->finish;
-       $sth=$dbh->prepare("select *,biblio.title from 
reserves,biblio,borrowers where found <> 'F' and cancellationdate
-               is NULL and biblio.biblionumber=reserves.biblionumber and 
reserves.constrainttype='a' and
-               reserves.borrowernumber=borrowers.borrowernumber
-               order by
-               biblio.title,reserves.reservedate");
-       $sth->execute;
-       while (my $data=$sth->fetchrow_hashref){
-               $results[$i]=$data;
+    return ( $i, address@hidden );
+}
+
+sub getrefunds {
+    my ( $date, $date2 ) = @_;
+    my $dbh = C4::Context->dbh;
+
+    my $sth = $dbh->prepare(
+        "Select *,
+                               date_FORMAT(timestamp, '%Y-%m-%d %H:%i' ) as 
datetime
+                               from accountlines,borrowers 
+                               where (accounttype = 'REF'
+                and accountlines.borrowernumber = borrowers.borrowernumber
+                and date  >=?  and date  <?)"
+    );
+
+    $sth->execute( $date, $date2 );
+
+    my $i = 0;
+    my @results;
+    while ( my $data = $sth->fetchrow_hashref ) {
+        $results[$i] = $data;
+        $i++;
+    }
+    return (@results);
+}
+
+sub checkReserveByTypeOnly {
+    my ( $biblio, $biblioitem ) = @_;
+    my $query = "SELECT * FROM items
+                       WHERE biblionumber = ?
+                       AND biblioitemnumber = ?";
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->prepare($query);
+    $sth->execute( $biblio, $biblioitem );
+    my $i;
+    my @results;
+
+    while ( my $data = $sth->fetchrow_hashref ) {
+        my $isth = $dbh->prepare(
+            "SELECT issues.*,borrowers.cardnumber
+                                    FROM issues,borrowers
+                                    WHERE itemnumber = ? AND returndate is null
+                                    AND 
issues.borrowernumber=borrowers.borrowernumber"
+        );
+        $isth->execute( $data->{'itemnumber'} );
+        if ( my $idata = $isth->fetchrow_hashref ) {
+            $data->{borrowernumber} = $idata->{borrowernumber};
+            $data->{cardnumber}     = $idata->{cardnumber};
+            $data->{datedue}        = $idata->{'date_due'};
+        }
+        $results[$i] = $data;
                $i++;
        }
        $sth->finish;
-       return($i,address@hidden);
+    return ( $i, address@hidden );
+}
+
+=item inhousereturns                                                           
                                                
+                                                                               
                                                  
+($count, @returns) = &inhousereturns($startdate,$enddate,$branch);             
                                              
+                                                                               
                                                
+Looks up the items that have been returned inhouse.                            
                                                
+This sub is used if you want to know about reading habits.                     
                                                
+So if items that have been found in the library in an incorrect location       
                                                
+like at a reading table or by the photocopier, they can be scanned as 
returned.                                                
+                                                                               
                                                  
+Then this sub can get info for a report by checking to see if the returns in a 
time period                                     
+have a borrowernumber or not - those without a borrowernumber are inhouse 
returns.                                             
+                                                                               
                                                  
+Returns count and array of inhouse returns                                     
                                                
+                                                                               
                                                  
+=cut                                                                           
                                                
+
+sub inhousereturns {
+    my ( $startdate, $enddate, $branch ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth;
+    my $query =
+"SELECT * FROM statistics                                                      
                                
+                   WHERE type = 'return'                                       
                                                  
+                   AND datetime > ?                                            
                                                  
+                   AND datetime < ?                                            
                                                  
+                   AND borrowernumber IS NULL";
+    if ( $branch ne '' ) { # if branch is indicated then limit results to 
branch
+        $query .= " AND branch = ?";
+        $sth = $dbh->prepare($query);
+        $sth->execute( $startdate, $enddate, $branch );
+    }
+    else {
+        $sth = $dbh->prepare($query);
+        $sth->execute( $startdate, $enddate );
+    }
+    warn "inhouse query $query";
+    my $count = 0;
+    my @results;
+    while ( my $data = $sth->fetchrow_hashref ) {
+        $results[$count] = $data;
+#        $results[$count]->{'branch'} = getbranchname( $data->{'branch'} );
+        my $sth2 =
+          $dbh->prepare("SELECT biblionumber FROM items WHERE itemnumber = ?");
+        $sth2->execute( $data->{'itemnumber'} );
+        while ( my $data2 = $sth2->fetchrow_hashref ) {
+            my $biblionumber = $data2->{'biblionumber'};
+            my $sth3         =
+              $dbh->prepare("SELECT * FROM biblio WHERE biblionumber = ?");
+            $sth3->execute($biblionumber);
+            while ( my $data3 = $sth3->fetchrow_hashref ) {
+                $results[$count]->{'biblionumber'} = $data3->{'biblionumber'};
+                $results[$count]->{'title'}        = $data3->{'title'};
+                $results[$count]->{'author'}       = $data3->{'author'};
+            }
+        }
+        $count++;
+    }
+    $sth->finish;
+    return ( $count, @results );
+}
+
+sub issuesbyyear {
+    my ($itemnumber,$year) = @_;
+    my $dbh=C4::Context->dbh();
+    my $query;
+    if ($year) {
+               $query = "SELECT count(*) as totalcount,branch FROM statistics 
WHERE itemnumber=? AND datetime >= ? AND datetime <= ? AND type = ? GROUP BY 
branch";
+    }
+    else {
+               $query = "SELECT count(*) as totalcount,branch FROM statistics 
WHERE itemnumber=? AND type = ? GROUP BY branch"; 
+    }
+    my $sth=$dbh->prepare($query);
+    my $startdate;
+    my $enddate;
+    if ($year){
+               $startdate="$year-01-01";
+               $enddate="$year-12-31";
+               $sth->execute($itemnumber,$startdate,$enddate,'issue');
+    }
+    else {
+               $sth->execute($itemnumber,'issue');
+    }
+    my %issues;
+    while (my $data = $sth->fetchrow_hashref()){
+               $issues{$data->{'branch'}}=$data->{'totalcount'};
+    }
+    $sth->finish();
+    if ($year){
+               $query = "SELECT * FROM statistics WHERE itemnumber=? AND 
datetime >= ? AND datetime <= ? AND (type = ? OR type = ?) order by datetime";
+               $sth=$dbh->prepare($query);
+       }
+    else {
+               $query = "SELECT * FROM statistics WHERE itemnumber=? AND (type 
= ? OR type = ?) order by datetime";
+               $sth=$dbh->prepare($query);
+    }
+    if ($year){
+               $sth->execute($itemnumber,$startdate,$enddate,'issue','renew');
+    }
+    else {
+               $sth->execute($itemnumber,'issue','renew');
+       }
+    my %renews;
+    my $branch;
+    while (my $data = $sth->fetchrow_hashref()){
+               if ($data->{'type'} eq 'issue'){
+                       if (!$branch || $branch ne $data->{'branch'}){
+                               $branch=$data->{'branch'};
+                       }
+               }
+               else {
+                       $renews{$branch}++;
+               }
+    }
+    return(\%issues,\%renews);
+}
+
+=item issues_count
+                                                                               
                                                  
+$count = &issues_count($startdate,$enddate,$branch);                           
                                
+                                                                               
                                                
+Returns a count of issues for a given period of time, and a give branch
+                                                                               
                                                  
+=cut                                                                           
                                                
+sub issues_count {
+       my ($startdate,$enddate,$branch) = @_;
+    my $count = get_count($startdate,$enddate,$branch,'issue');
+       return $count;
+}
+
+sub renews_count {
+       my ($startdate,$enddate,$branch) = @_;
+    my $count = get_count($startdate,$enddate,$branch,'renew');
+       return $count;
+}
+
+sub returns_count {
+       my ($startdate,$enddate,$branch) = @_;
+    my $count = get_count($startdate,$enddate,$branch,'return');
+       return $count;
+}
+
+sub borrowers_count {
+       my ($startdate,$enddate,$branch) = @_;
+    my $dbh = C4::Context->dbh();
+       my $query = "SELECT count(*) as total FROM borrowers WHERE dateenrolled 
<=? AND dateenrolled >=? AND branchcode=?";
+       my $sth = $dbh->prepare($query);
+       $sth->execute($enddate,$startdate,$branch);
+       my $data = $sth->fetchrow_hashref();
+       $sth->finish();
+       return ($data->{'total'});
+}
+
+sub reserves_count {
+       my ($startdate,$enddate,$branch) = @_;
+    my $dbh = C4::Context->dbh();
+       my $query = "SELECT count(*) as total FROM reserves WHERE reservedate 
<=? AND reservedate >=? AND branchcode=?";
+       my $sth = $dbh->prepare($query);
+       $sth->execute($enddate,$startdate,$branch);
+       my $data = $sth->fetchrow_hashref();
+       $sth->finish();
+       return ($data->{'total'});
+}      
+
+sub expired_reserves {
+    my ($startdate,$enddate,$branch) = @_;
+    my $dbh=C4::Context->dbh();
+    my $query = "SELECT * FROM statistics LEFT JOIN reserves ON 
statistics.datetime=reserves.timestamp WHERE type=? AND datetime >= ? AND 
datetime < ?
+    AND statistics.borrowernumber=reserves.borrowernumber AND 
statistics.itemnumber=reserves.itemnumber";
+    if ($branch){
+       $query.= " AND reserves.branchcode=?";
+    }
+    my $sth=$dbh->prepare($query);
+    if ($branch){
+       $sth->execute('expirereserve',$startdate,$enddate,$branch);
+    }
+    else {
+       $sth->execute('expirereserve',$startdate,$enddate);
+    }
+    my @results;
+    while (my $data=$sth->fetchrow_hashref()){
+       push @results,$data;
+    }
+    return (address@hidden);
+}
+
+
+
+# internal sub
+sub get_count {
+       my ($startdate,$enddate,$branch,$type) = @_;
+       my $dbh = C4::Context->dbh();
+       my $query = "SELECT count(*) as total FROM statistics WHERE datetime <= 
? AND datetime >= ? AND branch = ? AND type = ?";
+       my $sth = $dbh->prepare($query);
+       $sth->execute($enddate,$startdate,$branch,$type);
+       my $data = $sth->fetchrow_hashref();
+       $sth->finish();
+       return($data->{'total'});
 }
 
 1;
@@ -201,3 +552,5 @@
 Koha Developement team <address@hidden>
 
 =cut
+
+

Index: koha-tmpl/intranet-tmpl/npl/en/catalogue/moredetail.tmpl
===================================================================
RCS file: 
/sources/koha/koha/koha-tmpl/intranet-tmpl/npl/en/catalogue/Attic/moredetail.tmpl,v
retrieving revision 1.3.2.3.2.10
retrieving revision 1.3.2.3.2.11
diff -u -b -r1.3.2.3.2.10 -r1.3.2.3.2.11
--- koha-tmpl/intranet-tmpl/npl/en/catalogue/moredetail.tmpl    18 Jun 2007 
22:06:58 -0000      1.3.2.3.2.10
+++ koha-tmpl/intranet-tmpl/npl/en/catalogue/moredetail.tmpl    4 Aug 2007 
19:26:27 -0000       1.3.2.3.2.11
@@ -99,7 +99,8 @@
 <!-- TMPL_IF NAME="wthdrawn" --><input type="hidden" name="wthdrawn" value="0" 
/><!-- TMPL_ELSE --><input type="hidden" name="wthdrawn" value="1" /><!-- 
/TMPL_IF -->
 <input type="submit" name="submit" class="submit" value="<!-- TMPL_IF 
NAME="wthdrawn" -->Restore<!-- TMPL_ELSE -->Make Withdrawn<!-- /TMPL_IF -->" 
/></form></td></tr>
 
-<tr><th>Total Issues:</th><td><!-- TMPL_VAR NAME="issues" --> (<a 
href="/cgi-bin/koha/bookcount.pl?&amp;bib=<!-- TMPL_VAR NAME="biblionumber" 
-->&amp;bi=<!-- TMPL_VAR NAME="biblioitemnumber" -->&amp;itm=<!-- TMPL_VAR 
NAME="itemnumber" -->">View Circulation History</a>)</td></tr>
+<tr><th>Total Issues:</th><td><!-- TMPL_VAR NAME="issues" --> (<a 
href="/cgi-bin/koha/issues_stats.pl?bib=<!-- TMPL_VAR NAME="biblionumber" 
-->&amp;bi=<!-- TMPL_VAR NAME="biblioitemnumber" -->&amp;item=<!-- TMPL_VAR 
NAME="itemnumber" -->">View Circulation History</a>)</td></tr>
+
 <tr><th>Group Number:</th><td> <!-- TMPL_VAR NAME="biblioitemnumber" --> 
</td></tr>
 <tr><th>Biblio number:</th><td> <!-- TMPL_VAR NAME="biblionumber" --> 
</td></tr>
 </table></div>

Index: issues_stats.pl
===================================================================
RCS file: issues_stats.pl
diff -N issues_stats.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ issues_stats.pl     4 Aug 2007 19:26:27 -0000       1.1.2.1
@@ -0,0 +1,129 @@
+#!/usr/bin/perl
+
+# $Id: issues_stats.pl,v 1.1.2.1 2007/08/04 19:26:27 rangi Exp $
+
+# Copyright 2000-2002 Katipo Communications
+# Copyright 2007 Liblime
+#
+# This file is part of Koha.
+#
+# Koha 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 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; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+use CGI;
+use C4::Context;
+use C4::Search;
+use C4::Output;
+use C4::Koha;
+use C4::Auth;
+use HTML::Template;
+use C4::Stats;
+use C4::Date;
+
+# get all the data ....
+my %env;
+my $main='#cccc99';
+my $secondary='#ffffcc';
+
+my $input = new CGI;
+my $item = $input->param('item');
+my $bi = $input->param('bi');
+my $bib = $input->param('bib');
+my $year = $input->param('year');
+
+#if (!$year){
+#    $year='2007';
+#}
+my $branches = getbranches('IS');
+
+my ($issues,$renews)=issuesbyyear($item,$year);
+
+my $barcode = get_barcode($item);
+
+my $total_issues=0;
+my $total_renews=0;
+
+ 
+# make the page ...
+my @branchloop;                                                                
                                                                              
+                                                                               
                                                                              
+foreach my $branchcode (keys %$branches) {                                     
                                                                              
+    my %linebranch;                                                            
                                                                          
+    $linebranch{issues} = $issues->{$branchcode};
+    $linebranch{renews} = $renews->{$branchcode};
+       $total_issues+= $issues->{$branchcode};
+       $total_renews+= $renews->{$branchcode}; 
+    my $date = lastseenat($item, $branchcode);                                 
                                                                               
+    $linebranch{seen} = format_date($date);                                    
                                                                                
+    $linebranch{branchname}=$branches->{$branchcode}->{'branchname'};          
                                                                          
+    push(@branchloop,\%linebranch);                                            
                                                                          
+}  
+
+
+my ($template, $loggedinuser, $cookie)
+      = get_template_and_user({template_name => "catalogue/issues_stats.tmpl",
+                                        query => $input,
+                                        type => "intranet",
+                                        authnotrequired => 0,
+                                        flagsrequired => {borrowers => 1},
+                                        debug => 1,
+                                        });
+
+$template->param(branchloop =>address@hidden,
+    item => $item,
+    bib => $bib,
+    biblioitemnumber => $bi,
+       TOTAL_ISSUES => $total_issues,
+       TOTAL_RENEWS => $total_renews,
+       barcode => $barcode,
+year => $year);                                                                
                                                 
+
+print "Content-Type: text/html\n\n", $template->output;
+
+
+sub lastseenat {                                                               
                                                                              
+          my ($itm, $brc)address@hidden;                                       
                                                                                
             
+          my $dbh = C4::Context->dbh;                                          
                                                                                
  
+          my $sth=$dbh->prepare("Select max(timestamp) from issues where 
itemnumber=? and branchcode = ?");                                              
        
+          $sth->execute($itm,$brc);                                            
                                                                                
  
+          my ($date1)=$sth->fetchrow_array;                                    
                                                                                
  
+          $sth->finish;                                                        
                                                                                
  
+          $sth=$dbh->prepare("Select max(datearrived) from branchtransfers 
where itemnumber=? and tobranch = ?");                                          
      
+          $sth->execute($itm,$brc);                                            
                                                                                
  
+          my ($date2)=$sth->fetchrow_array;                                    
                                                                                
  
+          $sth->finish;                                                        
                                                                                
  
+          #FIXME: MJR thinks unsafe                                            
                                                                                
  
+          $date2 =~ s/-//g;                                                    
                                                                                
  
+          $date2 =~ s/://g;                                                    
                                                                                
  
+          $date2 =~ s/ //g;                                                    
                                                                                
  
+          my $date;                                                            
                                                                                
  
+          if ($date1 < $date2) {                                               
                                                                                
  
+                       $date = $date2;                                         
                                                                                
           
+                   } else {                                                    
                                                                                
           
+                                 $date = $date1;                               
                                                                                
                     
+                             }                                                 
                                                                                
                     
+          return($date);                                                       
                                                                                
  
+    }
+
+sub get_barcode {
+       my ($itemnumber) address@hidden;
+       my $dbh = C4::Context->dbh();
+       my $sth = $dbh->prepare("SELECT barcode FROM items WHERE itemnumber = 
?");
+       $sth->execute($itemnumber);
+       my $data= $sth->fetchrow_hashref();
+       $sth->finish();
+       return ($data->{'barcode'});
+       }
+               
+               

Index: koha-tmpl/intranet-tmpl/npl/en/catalogue/issues_stats.tmpl
===================================================================
RCS file: koha-tmpl/intranet-tmpl/npl/en/catalogue/issues_stats.tmpl
diff -N koha-tmpl/intranet-tmpl/npl/en/catalogue/issues_stats.tmpl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ koha-tmpl/intranet-tmpl/npl/en/catalogue/issues_stats.tmpl  4 Aug 2007 
19:26:27 -0000       1.1.2.1
@@ -0,0 +1,52 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->Koha -- Circulation Statistics 
for <!-- TMPL_VAR Name="title" --><!-- TMPL_INCLUDE NAME="doc-head-close.inc" 
-->
+<!-- TMPL_INCLUDE NAME="masthead.inc" -->
+<!-- TMPL_INCLUDE NAME="intranet-nav.inc" -->
+
+<div id="main">
+<h1>
+<!-- TMPL_VAR Name="title" --> <!-- TMPL_IF NAME="author" -->(<!-- TMPL_VAR 
Name="author" -->)<!-- /TMPL_IF --></a></h1>
+<h2>Barcode <!-- TMPL_VAR Name="barcode" --></h2>
+<h2>Year <!-- TMPL_VAR NAME="year" --></h2>
+
+<form method=get action="/cgi-bin/koha/issues_stats.pl">
+<input type="hidden" name="item" value="<!-- TMPL_VAR NAME="item" -->">
+<select name="year">
+<option value="">All</option>
+<option value="2007">2007</option>
+<option value="2006">2006</option>
+
+</select>
+<input type="submit" value="Submit">
+
+</form>
+<div class="tabitem"><form action="/cgi-bin/koha/detail.pl" 
method="get"><input type="hidden" name="bib" value="<!-- TMPL_VAR Name="bib" 
-->"><input type="hidden" name="type" value="intra"><input type="submit" 
class="submit" value="Brief Display"></form> <form 
action="/cgi-bin/koha/moredetail.pl" method="get"><input type="hidden" 
name="type" value="<!-- TMPL_VAR NAME="type" -->"><input type="hidden" 
name="item" value="<!-- TMPL_VAR NAME="item" -->"><input type="hidden" 
name="bib" value="<!-- TMPL_VAR NAME="bib" -->"><input type="hidden" name="bi" 
value="<!-- TMPL_VAR NAME="biblioitemnumber" -->"> <input type="submit" 
class="submit" value="Item Details"></form><!-- TMPL_IF NAME="norequests" 
--><!-- TMPL_ELSE --> <form action="request.pl" method="get"><input 
type="hidden" value="<!-- TMPL_VAR name="bib" -->" name="bib"> <input 
type="submit" value="Place Reserve" class="submit"></form><!-- /TMPL_IF 
--></div>
+<div class="data">
+</div>
+<div class="table">
+               <table>
+                       <tr>
+                               <th> Branch</th>
+                               <th> No. of Issues</th>
+                               <th> No. of Renews</th>
+                               <th> Last Seen </th>
+                       </tr>
+                       <!-- TMPL_LOOP Name="branchloop" -->
+                               <tr>
+                                       <td class="data"><!-- TMPL_VAR 
Name="branchname" --> </td>
+                                       <td class="data"><!-- TMPL_VAR 
Name="issues" --> </td>
+                                       <td class="data"><!-- TMPL_VAR 
Name="renews" --> </td>
+                                       <td class="data"><!-- TMPL_VAR 
Name="seen" --> </td>
+                               </tr>
+                       <!-- /TMPL_LOOP -->
+                       <tr>
+                       <td> Total </td>
+                       <td><!-- TMPL_VAR NAME="TOTAL_ISSUES" --></td>
+                       <td><!-- TMPL_VAR NAME="TOTAL_RENEWS" --></td>
+                       <td></td>
+                       </tr>
+               </table></div>
+               </td>
+       </tr>
+</table></div>
+
+<!-- TMPL_INCLUDE Name="intranet-bottom.inc" -->




reply via email to

[Prev in Thread] Current Thread [Next in Thread]