[Koha-patches] [PATCH] Add extra information to overdues report

Jesse Weaver pianohacker at gmail.com
Thu Jul 8 21:50:59 CEST 2010


This allows staff to see the call number and, optionally, the number of days an
item is overdue.

This work sponsored by John C. Fremont Library District, Florence, CO, USA.
---
 circ/overdue.pl                                    |   55 +++++++++++++++-----
 installer/data/mysql/en/mandatory/sysprefs.sql     |    1 +
 installer/data/mysql/updatedatabase.pl             |    7 +++
 .../en/modules/admin/preferences/circulation.pref  |    6 ++
 .../prog/en/modules/circ/overdue.tmpl              |   27 ++++++----
 5 files changed, 73 insertions(+), 23 deletions(-)

diff --git a/circ/overdue.pl b/circ/overdue.pl
index cad8e6d..579b1c7 100755
--- a/circ/overdue.pl
+++ b/circ/overdue.pl
@@ -26,8 +26,9 @@ use CGI qw(-oldstyle_urls);
 use C4::Auth;
 use C4::Branch;
 use C4::Debug;
+use C4::Calendar qw();
 use C4::Dates qw/format_date/;
-use Date::Calc qw/Today/;
+use Date::Calc qw( Today Delta_Days );
 use Text::CSV_XS;
 
 my $input = new CGI;
@@ -233,6 +234,7 @@ if ($noreport) {
         borrowers.email,
         issues.itemnumber,
         items.barcode,
+        items.itemcallnumber,
         biblio.title,
         biblio.author,
         borrowers.borrowernumber,
@@ -270,6 +272,8 @@ if ($noreport) {
     $sth->execute();
 
     my @overduedata;
+    my $prevbor = -1;
+    my $prevrow;
     while (my $data = $sth->fetchrow_hashref) {
 
         # most of the overdue report data is linked to the database schema, i.e. things like borrowernumber and phone
@@ -284,22 +288,34 @@ if ($noreport) {
             push @patron_attr_value_loop, { value => join(', ', sort { lc $a cmp lc $b } @displayvalues) };
         }
 
-        push @overduedata, {
-            duedate                => format_date($data->{date_due}),
-            borrowernumber         => $data->{borrowernumber},
-            barcode                => $data->{barcode},
-            itemnum                => $data->{itemnumber},
-            name                   => $data->{borrower},
-            phone                  => $data->{phone},
-            email                  => $data->{email},
-            biblionumber           => $data->{biblionumber},
-            title                  => $data->{title},
-            author                 => $data->{author},
-            branchcode             => $data->{branchcode},
+        my $row = {
+            rowspan        => 1,
+            duedate        => format_date($data->{date_due}),
+            difference     => C4::Context->preference( 'ShowDifferenceOnOverdueReport' ) ? GetDaysOverdue( $data->{'branchcode'}, $data->{'date_due'} ) : 0,
+            borrowernumber => $data->{borrowernumber},
+            barcode        => $data->{barcode},
+            itemnum        => $data->{itemnumber},
+            biblionumber   => $data->{biblionumber},
+            title          => $data->{title},
+            author         => $data->{author},
+            itemcallnumber => $data->{itemcallnumber},
+            branchcode     => $data->{branchcode},
             itemcallnumber         => $data->{itemcallnumber},
             replacementprice       => $data->{replacementprice},
             patron_attr_value_loop => \@patron_attr_value_loop,
         };
+
+        if ( $prevbor eq $data->{'borrowernumber'} && $op ne 'csv' ) {
+            $prevrow->{'rowspan'}++;
+        } else {
+            $row->{'email'} = $data->{'email'};
+            $row->{'phone'} = $data->{'phone'} || ' ';
+            $row->{'name'} = $data->{'borrower'};
+            $prevrow = $row;
+            $prevbor = $row->{'borrowernumber'};
+        }
+
+        push ( @overduedata, $row );
     }
 
     my ($attrorder) = $order =~ /patron_attr_(.*)$/; 
@@ -379,3 +395,16 @@ sub build_csv {
 
     return join("\n", @lines) . "\n";
 }
+
+our %calendars;
+
+sub GetDaysOverdue {
+    my ( $branchcode, $date_due ) = @_;
+
+    if ( C4::Context->preference( 'useDaysMode' ) eq 'Calendar' && $branchcode ) {
+        my $calendar = defined( $calendars{$branchcode} ) ? $calendars{$branchcode} : ( $calendars{$branchcode} = C4::Calendar->new( branchcode => $branchcode ) );
+        return $calendars{$branchcode}->daysBetween( C4::Dates->new( $date_due, 'iso' ), C4::Dates->new() );
+    } else {
+        return Delta_Days( split( "-", $date_due ), Today() );
+    }
+}
diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql
index 8bfed37..19c8b58 100644
--- a/installer/data/mysql/en/mandatory/sysprefs.sql
+++ b/installer/data/mysql/en/mandatory/sysprefs.sql
@@ -286,3 +286,4 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ILS-DI:Authorized_IPs','','.','Restricts usage of ILS-DI to some IPs','Free');
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OverduesBlockCirc','noblock','When checking out an item should overdues block checkout, generate a confirmation dialogue, or allow checkout','noblock|confirmation|block','Choice');
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('DisplayMultiPlaceHold','1','Display the ability to place multiple holds or not','','YesNo');
+INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('ShowDifferenceOnOverdueReport','0','Show the number of days overdue for each item on the overdues report','','YesNo');
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 68e7cbc..a032f0f 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -3687,6 +3687,13 @@ if (C4::Context->preference('Version') < TransformToNum($DBversion)){
     SetVersion ($DBversion);
 }
 
+$DBversion = '';
+if (C4::Context->preference('Version') < TransformToNum($DBversion)){
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('ShowDifferenceOnOverdueReport','0','Show the number of days overdue for each item on the overdues report','','YesNo')");
+    print "Upgrade to $DBversion done (adding syspref ShowDifferenceOnOverdueReport)\n";
+    SetVersion ($DBversion);
+}
+
 
 =item DropAllForeignKeys($table)
 
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
index ab92915..5793c87 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
@@ -60,6 +60,12 @@ Circulation:
                   yes: Require
                   no: "Don't require"
             - staff to choose which checkouts to show before running the overdues report.
+        -
+            - pref: ShowDifferenceOnOverdueReport
+              choices:
+                  yes: Show
+                  no: "Don't show"
+            - the number of days that each item is overdue on the overdues report.
         -            
             - pref: DisplayClearScreenButton
               choices:
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tmpl
index 5ac278b..ca9ff94 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tmpl
@@ -106,24 +106,31 @@
 <thead><tr>
     <th>Due Date</th>
     <th>Patron</th>
-    <th>Library</th>
     <th>Title</th>
-    <th>Barcode</th>
     <th>Call number</th>
+    <th>Barcode</th>
 </tr></thead>
 
 <tbody><!-- TMPL_LOOP NAME="overdueloop" -->
     <tr>
-        <td><!-- TMPL_VAR NAME="duedate" --></td>
-        <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!-- TMPL_VAR name="borrowernumber"-->"><!-- TMPL_VAR NAME="name" --></a>
-        <!-- TMPL_IF NAME="email" -->[<a href="mailto:<!-- TMPL_VAR NAME="email" -->?subject=Overdue: <!-- TMPL_VAR NAME="title" ESCAPE="html" -->">email</a>]<!-- /TMPL_IF -->
-        (<!--TMPL_IF NAME="phone" --><!-- TMPL_VAR NAME="phone" --><!-- TMPL_ELSIF NAME="mobile" --><!-- TMPL_VAR NAME="mobile" --><!-- TMPL_ELSIF NAME="phonepro" --><!-- TMPL_VAR NAME="phonepro" --><!-- /TMPL_IF -->)</td>
-        <td><!-- TMPL_VAR name="branchcode" --></td>
-        <td><!-- TMPL_INCLUDE NAME="biblio-default-view.inc" --><!-- TMPL_VAR NAME="title" ESCAPE="html" -->  <!-- TMPL_VAR NAME="subtitle" --></a> <!-- TMPL_IF NAME="author" -->, by <!-- TMPL_VAR NAME="author" --><!-- /TMPL_IF -->
+        <td><!-- TMPL_VAR NAME="duedate" --> <!-- TMPL_IF NAME="difference" -->(<!-- TMPL_VAR NAME="difference" --><!-- TMPL_IF NAME="__first__" --> days ago<!-- /TMPL_IF -->)<!-- /TMPL_IF --></td>
+        <!-- TMPL_IF NAME="name" -->
+        <td rowspan="<!-- TMPL_VAR rowspan -->">
+        <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!-- TMPL_VAR name="borrowernumber"-->"><!-- TMPL_VAR NAME="name" --></a>
+        <!-- TMPL_IF NAME="email" -->[<a href="mailto:<!-- TMPL_VAR NAME="email" -->?subject=Overdue: <!-- TMPL_VAR NAME="title" -->">email</a>]<!-- /TMPL_IF -->
+        (<!--TMPL_IF NAME="phone" --><!-- TMPL_VAR NAME="phone" --><!-- TMPL_ELSIF NAME="mobile" --><!-- TMPL_VAR NAME="mobile" --><!-- TMPL_ELSIF NAME="phonepro" --><!-- TMPL_VAR NAME="phonepro" --><!-- /TMPL_IF -->)
+        </td>
+        <!-- /TMPL_IF -->
+        <td><!-- TMPL_IF name="BiblioDefaultViewmarc" -->
+<a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="title" ESCAPE="html" --></a>
+<!-- TMPL_ELSIF NAME="BiblioDefaultViewisbd" -->
+<a href="/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="title" ESCAPE="html" --></a>
+<!-- TMPL_ELSE -->
+<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="title" ESCAPE="html" -->  <!-- TMPL_VAR NAME="subtitle" --></a><!-- /TMPL_IF --> <!-- TMPL_IF NAME="author" -->, by <!-- TMPL_VAR NAME="author" --><!-- /TMPL_IF -->
         </td>
-		<td><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnum" -->#item<!-- TMPL_VAR NAME="itemnum" -->"><!-- TMPL_VAR name="barcode" --></a></td>
 		<td><!-- TMPL_VAR name="itemcallnumber" --></td>
-        </tr>
+        <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnum" -->#item<!-- TMPL_VAR NAME="itemnum" -->"><!-- TMPL_VAR name="barcode" --></a></td>
+    </tr>
 <!-- /TMPL_LOOP --></tbody>
 </table>
 
-- 
1.7.0.4



More information about the Koha-patches mailing list