From d128f7b591754a94fb005c9a567ab2d3e065434e Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 5 Nov 2012 14:35:23 -0500 Subject: [PATCH] Bug 9011 - Add the ability to store the last patron to return an item Currently if the AnonymousPatron system preference is in use, all patron data is anonymized. Some libraries would like to be able to see the last patron who returned out an item ( in case of damage ) but still keep all other patrons anonymized. * Add the field items.last_borrower, foreign key to borrowers.borrowernumber * Add new system preference StoreLastBorrower * If StoreLastBorrower is enabled, upon checkin have Koha set this new field to the patron who last returned this item. * If this new field has a value, link to the patron from the item details page. Test plan: 1) Apply patch 2) Run updatedatabase.pl 3) Enable StoreLastBorrower 4) Issue an item to a patron and return said item 5) Issue the same item to a second patron, do not return it. 6) View moredetail.pl for the given bib, find the given item. There should be a new field in the history list 'Last returned by' with a link to the given borrowernumber. Optionally, you can also verify this works even if patron issuing history has been set to anonymize issues upon return. Signed-off-by: Owen Leonard Signed-off-by: Jonathan Druart --- C4/Circulation.pm | 4 ++ Koha/Template/Plugin/KohaBorrowers.pm | 44 ++++++++++++++++++++ catalogue/moredetail.pl | 1 + installer/data/mysql/kohastructure.sql | 4 ++ installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 13 ++++++ .../prog/en/modules/admin/preferences/opac.pref | 7 +++ .../prog/en/modules/catalogue/moredetail.tt | 2 + .../opac-tmpl/prog/en/modules/opac-privacy.tt | 2 + opac/opac-privacy.pl | 1 + 10 files changed, 79 insertions(+), 0 deletions(-) create mode 100644 Koha/Template/Plugin/KohaBorrowers.pm diff --git a/C4/Circulation.pm b/C4/Circulation.pm index d2f5516..e1c0939 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2004,6 +2004,10 @@ sub MarkIssueReturned { WHERE borrowernumber = ? AND itemnumber = ?"); $sth_del->execute($borrowernumber, $itemnumber); + + if ( C4::Context->preference('StoreLastBorrower') ) { + $dbh->do("UPDATE items SET last_returned_by = ? WHERE itemnumber = ?", undef, ( $borrowernumber, $itemnumber ) ); + } } =head2 _debar_user_on_return diff --git a/Koha/Template/Plugin/KohaBorrowers.pm b/Koha/Template/Plugin/KohaBorrowers.pm new file mode 100644 index 0000000..c575607 --- /dev/null +++ b/Koha/Template/Plugin/KohaBorrowers.pm @@ -0,0 +1,44 @@ +package Koha::Template::Plugin::KohaBorrowers; + +# Copyright ByWater Solutions 2013 + +# 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., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Template::Plugin; +use base qw( Template::Plugin ); + +use C4::Context; + +=pod + +This plugin contains TT helper functions related to borrowers + +=cut + +sub BorrowernumberToCardnumber { + my ( $self, $borrowernumber ) = @_; + + my $sql = "SELECT cardnumber FROM borrowers WHERE borrowernumber = ?"; + my $sth = C4::Context->dbh->prepare( $sql ); + $sth->execute( $borrowernumber ); + my ( $cardnumber ) = $sth->fetchrow_array(); + + return $cardnumber; +} + +1; diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index a925285..0850a0d 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -212,6 +212,7 @@ $template->param( z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)), subtitle => $subtitle, hidepatronname => $hidepatronname, + StoreLastBorrower => C4::Context->preference('StoreLastBorrower'), ); $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items ); $template->{'VARS'}->{'searchid'} = $query->param('searchid'); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index a6a779e..e48f388 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -863,6 +863,7 @@ CREATE TABLE `deleteditems` ( `replacementpricedate` date default NULL, -- the date the price is effective from (MARC21 952$w) `datelastborrowed` date default NULL, -- the date the item was last checked out `datelastseen` date default NULL, -- the date the item was last see (usually the last time the barcode was scanned or inventory was done) + `last_returned_by` int(11) DEFAULT NULL, -- the last borrower to return an item `stack` tinyint(1) default NULL, `notforloan` tinyint(1) NOT NULL default 0, -- authorized value defining why this item is not for loan (MARC21 952$7) `damaged` tinyint(1) NOT NULL default 0, -- authorized value defining this item as damaged (MARC21 952$4) @@ -900,6 +901,7 @@ CREATE TABLE `deleteditems` ( KEY `delhomebranch` (`homebranch`), KEY `delholdingbranch` (`holdingbranch`), KEY `itype_idx` (`itype`) + KEY `del_last_returned_by` (`last_returned_by`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- @@ -1156,6 +1158,7 @@ CREATE TABLE `items` ( -- holdings/item information `replacementpricedate` date default NULL, -- the date the price is effective from (MARC21 952$w) `datelastborrowed` date default NULL, -- the date the item was last checked out/issued `datelastseen` date default NULL, -- the date the item was last see (usually the last time the barcode was scanned or inventory was done) + `last_returned_by` int(11) DEFAULT NULL, -- the last borrower to return an item `stack` tinyint(1) default NULL, `notforloan` tinyint(1) NOT NULL default 0, -- authorized value defining why this item is not for loan (MARC21 952$7) `damaged` tinyint(1) NOT NULL default 0, -- authorized value defining this item as damaged (MARC21 952$4) @@ -1195,6 +1198,7 @@ CREATE TABLE `items` ( -- holdings/item information KEY `items_location` (`location`), KEY `items_ccode` (`ccode`), KEY `itype_idx` (`itype`), + KEY `last_returned_by` (`last_returned_by`), CONSTRAINT `items_ibfk_1` FOREIGN KEY (`biblioitemnumber`) REFERENCES `biblioitems` (`biblioitemnumber`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `items_ibfk_2` FOREIGN KEY (`homebranch`) REFERENCES `branches` (`branchcode`) ON UPDATE CASCADE, CONSTRAINT `items_ibfk_3` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON UPDATE CASCADE diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 71513ce..9648450 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -351,6 +351,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('staffClientBaseURL','',NULL,'Specify the base URL of the staff client','free'), ('StaffSerialIssueDisplayCount','3','','Number of serial issues to display per subscription in the Staff client','Integer'), ('StaticHoldsQueueWeight','0',NULL,'Specify a list of library location codes separated by commas -- the list of codes will be traversed and weighted with first values given higher weight for holds fulfillment -- alternatively, if RandomizeHoldsQueueWeight is set, the list will be randomly selective','Integer'), +('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo'), ('SubfieldsToUseWhenPrefill','','','Define a list of subfields to use when prefilling items (separated by space)','Free'), ('SubscriptionDuplicateDroppedInput','','','List of fields which must not be rewritten when a subscription is duplicated (Separated by pipe |)','Free'), ('SubscriptionHistory','simplified','simplified|full','Define the display preference for serials issue history in OPAC','Choice'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 3d2ca44..7976604 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7595,6 +7595,19 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.13.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE items ADD last_returned_by INT( 11 ) NULL DEFAULT NULL AFTER datelastseen"); + $dbh->do("ALTER TABLE items ADD INDEX ( last_returned_by )"); + + $dbh->do("ALTER TABLE deleteditems ADD last_returned_by INT( 11 ) NULL DEFAULT NULL AFTER datelastseen"); + $dbh->do("ALTER TABLE deleteditems ADD INDEX ( last_returned_by )"); + + $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo')"); + + print "Upgrade to $DBversion done ( Add syspref StoreLastBorrower )\n"; + SetVersion ($DBversion); +} =head1 FUNCTIONS diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index a75c7ef..6f9991e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -551,6 +551,13 @@ OPAC: track: "Track" no: "Don't track" - links that patrons click on + - + - pref: StoreLastBorrower + default: 0 + choices: + yes: Store + no: "Don't store" + - the last patron to return an item. This setting is independent of opacreadinghistory/AnonymousPatron. Shelf Browser: - diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt index 40798eb..24e0698 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt @@ -1,3 +1,4 @@ +[% USE KohaBorrowers %] [% INCLUDE 'doc-head-open.inc' %] Koha › Catalog › Item details for [% title %] [% FOREACH subtitl IN subtitle %] [% subtitl.subfield %][% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -212,6 +213,7 @@
  • Last seen:[% IF ( ITEM_DAT.datelastseen ) %][% ITEM_DAT.datelastseen | $KohaDates %] [%END %] 
  • Last borrowed:[% IF (ITEM_DAT.datelastborrowed ) %][% ITEM_DAT.datelastborrowed | $KohaDates %][% END %] 
  • + [% IF ( StoreLastBorrower && ITEM_DAT.last_returned_by ) %]
  • Last returned by: [% KohaBorrowers.BorrowernumberToCardnumber( ITEM_DAT.last_returned_by ) %] 
  • [% END %] [% IF ( ITEM_DAT.card0 ) %]
  • Last borrower: [% ITEM_DAT.card0 %] 
  • [% END %] [% IF ( ITEM_DAT.card1 ) %]
  • Previous borrower: [% ITEM_DAT.card1 %] 
  • [% END %] [% IF ( ITEM_DAT.card2 ) %]
  • Previous borrower: [% ITEM_DAT.card2 %] 
  • [% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-privacy.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-privacy.tt index 1106973..5e7c716 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-privacy.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-privacy.tt @@ -62,6 +62,8 @@ [% END %] + + [% IF StoreLastBorrower %]

    Please note, the last person to return an item is tracked for the management of items returned damaged.

    [% END %] diff --git a/opac/opac-privacy.pl b/opac/opac-privacy.pl index 22fe694..5905447 100755 --- a/opac/opac-privacy.pl +++ b/opac/opac-privacy.pl @@ -68,6 +68,7 @@ $template->param( 'Ask_data' => '1', 'firstname' => $borr->{'firstname'}, 'surname' => $borr->{'surname'}, 'privacyview' => 1, + 'StoreLastBorrower' => C4::Context->preference('StoreLastBorrower'), ); output_html_with_http_headers $query, $cookie, $template->output; -- 1.7.2.5