From 7bf5252c36ec238a36218a4024ddede2298a4686 Mon Sep 17 00:00:00 2001 From: Lyon3 Team Date: Tue, 17 Dec 2013 18:39:13 +0100 Subject: [PATCH 1/2] Bug 11481 HoldOnlyWhenAllItemsOnLoan new syspref This syspref sets the following behavior about reserves : Placing hold on a document is possible only when all items that can be reserved according to the issuing rules are on loan. It's disabled by default. --- C4/Reserves.pm | 31 +++++++++++++++++-- installer/data/mysql/sysprefs.sql | 4 +- installer/data/mysql/updatedatabase.pl | 7 ++++ .../en/modules/admin/preferences/circulation.pref | 8 +++++ .../prog/en/modules/reserve/request.tt | 6 +++- opac/opac-detail.pl | 8 ++++- reserve/request.pl | 9 ++++-- 7 files changed, 62 insertions(+), 11 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index de25488..add671f 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -431,8 +431,15 @@ sub CanBookBeReserved{ push (@$items,@hostitems); } - foreach my $item (@$items){ - return 1 if CanItemBeReserved($borrowernumber, $item); + unless (C4::Context->preference('HoldOnlyWhenAllItemsOnLoan')) { + foreach my $item (@$items){ + return 1 if CanItemBeReserved($borrowernumber, $item); + } + }else { + foreach my $item (@$items){ + return undef if !defined(CanItemBeReserved($borrowernumber, $item)); + } + return 1; } return 0; } @@ -535,9 +542,25 @@ sub CanItemBeReserved{ return 0; } } + my $holdonly = C4::Context->preference('HoldOnlyWhenAllItemsOnLoan'); + if ( !$holdonly ){ + return 1; + } else { + my $querystatus ="SELECT found FROM reserves WHERE itemnumber = ?"; + my $sth=$dbh->prepare($querystatus); + $sth->execute($itemnumber); + my ($status) = $sth->fetchrow_array(); - return 1; -} + if ($item->{'onloan'} or $status eq 'W' or $status eq 'T') { + return 1; + } elsif ( !($item->{'notforloan'} and $item->{'withdrawn'} and $item->{'itemlost'} and $item->{'damaged'}) ) { + return 0; + } else { + return undef; + } + } + + } #-------------------------------------------------------------------------------- =head2 GetReserveCount diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 0de3ac7..79f9b09 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -424,5 +424,5 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'), ('yuipath','local','local|http://yui.yahooapis.com/2.5.1/build','Insert the path to YUI libraries, choose local if you use koha offline','Choice'), ('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'), -('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo') -; +('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'), +('HoldOnlyWhenAllItemsOnLoan','0', 'Placing hold on a document is possible only when all items that can be reserved according to the issuing rules are on loan', NULL, 'YesNo') diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index d0255a4..6e7168b 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7885,6 +7885,13 @@ if(CheckVersion($DBversion)) { SetVersion($DBversion); } +$DBversion = "3.15.00.XXX"; +if (CheckVersion($DBversion) ) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('HoldOnlyWhenAllItemsOnLoan','0', 'Placing hold on a document is possible only when all items that can be reserved according to the issuing rules are on loan', NULL, 'YesNo')"); + print "Upgrade to $DBversion done (Add system preference HoldOnlyWhenAllItemsOnLoan)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($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 2c5469b..e0d41f5 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 @@ -371,6 +371,14 @@ Circulation: no: "Don't allow" - hold requests to be placed on items that are not checked out. - + - To be able to place hold on a document + - pref: HoldOnlyWhenAllItemsOnLoan + default: 0 + choices: + yes: "it is necessary" + no: "it is not necessary" + - that all the items potentially holdable are on loan + - - pref: AllowHoldDateInFuture choices: yes: Allow diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index 9e46732..e3127c2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -243,7 +243,11 @@ function checkMultiHold() {
  • [% borrowerfirstname %] [% borrowersurname %] already has a hold on this item
  • [% END %] [% IF ( none_available ) %] -
  • No copies are available to be placed on hold
  • + [% IF ( not_all_holdable_onloan ) %] +
  • All reservable items of the record must be on loan
  • + [% ELSE %] +
  • No copies are available to be placed on hold
  • + [% END %] [% END %] [% IF ( alreadypossession ) %]
  • [% borrowerfirstname %] [% borrowersurname %] is already in possesion of one item
  • diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 77de12f..0b6439e 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -403,7 +403,13 @@ if ($session->param('busc')) { $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); -$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); +if ( C4::Context->preference("HoldOnlyWhenAllItemsOnLoan") ) { + $template->param( 'ItemsIssued' => CanBookBeReserved($borrowernumber,$biblionumber) ); +} else { + $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); +} + + diff --git a/reserve/request.pl b/reserve/request.pl index a735b0c..7d8abc0 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -180,14 +180,16 @@ if ($multihold) { my $itemdata_enumchron = 0; my @biblioloop = (); +my $not_all_holdable_onloan; foreach my $biblionumber (@biblionumbers) { my %biblioloopiter = (); my $dat = GetBiblioData($biblionumber); - - unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) { + my $canbookbereserved = CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber); + unless ( $canbookbereserved ) { $maxreserves = 1; + $not_all_holdable_onloan = 1 if !defined($canbookbereserved); } my $alreadypossession; @@ -413,7 +415,7 @@ foreach my $biblionumber (@biblionumbers) { ) { $item->{available} = 1; - $num_available++; + $num_available++ unless $not_all_holdable_onloan; } elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) { @@ -442,6 +444,7 @@ foreach my $biblionumber (@biblionumbers) { if ( $num_override == scalar( @{ $biblioitem->{itemloop} } ) ) { # That is, if all items require an override $template->param( override_required => 1 ); } elsif ( $num_available == 0 ) { + $template->param( not_all_holdable_onloan => $not_all_holdable_onloan ); $template->param( none_available => 1 ); $biblioloopiter{warn} = 1; $biblioloopiter{none_avail} = 1; -- 1.7.2.5