=cut
-use strict;
-use warnings;
-use C4::Branch;
+use Modern::Perl;
+
use CGI qw ( -utf8 );
use List::MoreUtils qw/uniq/;
use Date::Calc qw/Date_to_Days/;
use C4::Members;
use C4::Search; # enabled_staff_search_views
use Koha::DateUtils;
-use Koha::Borrower::Debarments qw(IsDebarred);
use Koha::Holds;
+use Koha::Libraries;
+use Koha::Patrons;
my $dbh = C4::Context->dbh;
my $input = new CGI;
$template->param(multi_hold => $multihold);
my $showallitems = $input->param('showallitems');
-# get Branches and Itemtypes
-my $branches = GetBranches();
my $itemtypes = GetItemTypes();
-my $userbranch = '';
-if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
- $userbranch = C4::Context->userenv->{'branch'};
-}
-
-
# Select borrowers infos
my $findborrower = $input->param('findborrower');
$findborrower = '' unless defined $findborrower;
my $warnings;
my $messages;
my $exceeded_maxreserves;
+my $exceeded_holds_per_record;
my $date = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
my $action = $input->param('action');
if ($multihold) {
@biblionumbers = split '/', $biblionumbers;
} else {
- push @biblionumbers, $input->param('biblionumber');
+ push @biblionumbers, $input->multi_param('biblionumber');
}
$diffbranch = 1;
}
+ my $is_debarred = Koha::Patrons->find( $borrowerinfo->{borrowernumber} )->is_debarred;
$template->param(
borrowernumber => $borrowerinfo->{'borrowernumber'},
borrowersurname => $borrowerinfo->{'surname'},
diffbranch => $diffbranch,
messages => $messages,
warnings => $warnings,
- restricted => IsDebarred($borrowerinfo->{'borrowernumber'}),
+ restricted => $is_debarred,
amount_outstanding => GetMemberAccountRecords($borrowerinfo->{borrowernumber}),
);
}
# FIXME launch another time GetMember perhaps until
my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
+my $logged_in_patron = Koha::Patrons->find( $borrowernumber );
+
my $itemdata_enumchron = 0;
my @biblioloop = ();
foreach my $biblionumber (@biblionumbers) {
+ next unless $biblionumber =~ m|^\d+$|;
my %biblioloopiter = ();
elsif ( $canReserve eq 'tooManyReserves' ) {
$exceeded_maxreserves = 1;
}
+ elsif ( $canReserve eq 'tooManyHoldsForThisRecord' ) {
+ $exceeded_holds_per_record = 1;
+ $biblioloopiter{$canReserve} = 1;
+ }
elsif ( $canReserve eq 'ageRestricted' ) {
$template->param( $canReserve => 1 );
$biblioloopiter{$canReserve} = 1;
$biblioloopiter{$canReserve} = 1;
}
- my $alreadypossession;
- if (not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowerinfo->{borrowernumber},$biblionumber)) {
- $alreadypossession = 1;
+ my $force_hold_level;
+ if ( $borrowerinfo->{borrowernumber} ) {
+ # For multiple holds per record, if a patron has previously placed a hold,
+ # the patron can only place more holds of the same type. That is, if the
+ # patron placed a record level hold, all the holds the patron places must
+ # be record level. If the patron placed an item level hold, all holds
+ # the patron places must be item level
+ my $holds = Koha::Holds->search(
+ {
+ borrowernumber => $borrowerinfo->{borrowernumber},
+ biblionumber => $biblionumber,
+ found => undef,
+ }
+ );
+ $force_hold_level = $holds->forced_hold_level();
+ $biblioloopiter{force_hold_level} = $force_hold_level;
+ $template->param( force_hold_level => $force_hold_level );
+
+ # For a librarian to be able to place multiple record holds for a patron for a record,
+ # we must find out what the maximum number of holds they can place for the patron is
+ my $max_holds_for_record = GetMaxPatronHoldsForRecord( $borrowerinfo->{borrowernumber}, $biblionumber );
+ my $remaining_holds_for_record = $max_holds_for_record - $holds->count();
+ $biblioloopiter{remaining_holds_for_record} = $max_holds_for_record;
+ $template->param( max_holds_for_record => $max_holds_for_record );
+ $template->param( remaining_holds_for_record => $remaining_holds_for_record );
}
- # get existing reserves .....
- my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
- my $count = scalar( @$reserves );
- my $totalcount = $count;
- my $holds_count = 0;
- my $alreadyreserved = 0;
-
- foreach my $res (@$reserves) {
- if ( defined $res->{found} ) { # found can be 'W' or 'T'
- $count--;
- }
-
- if ( defined $borrowerinfo && defined($borrowerinfo->{borrowernumber}) && ($borrowerinfo->{borrowernumber} eq $res->{borrowernumber}) ) {
- $holds_count++;
- }
+ # Check to see if patron is allowed to place holds on records where the
+ # patron already has an item from that record checked out
+ my $alreadypossession;
+ if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions')
+ && CheckIfIssuedToPatron( $borrowerinfo->{borrowernumber}, $biblionumber ) )
+ {
+ $template->param( alreadypossession => $alreadypossession, );
}
- if ( $holds_count ) {
- $alreadyreserved = 1;
- $biblioloopiter{warn} = 1;
- $biblioloopiter{alreadyres} = 1;
- }
- $template->param(
- alreadyreserved => $alreadyreserved,
- alreadypossession => $alreadypossession,
- );
+ my $count = Koha::Holds->search( { biblionumber => $biblionumber } )->count();
+ my $totalcount = $count;
# FIXME think @optionloop, is maybe obsolete, or must be switchable by a systeme preference fixed rank or not
# make priorities options
my @bibitemloop;
+ my @available_itemtypes;
foreach my $biblioitemnumber (@biblioitemnumbers) {
my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
my $num_available = 0;
my $num_override = 0;
my $hiddencount = 0;
+ $biblioitem->{force_hold_level} = $force_hold_level;
+
if ( $biblioitem->{biblioitemnumber} ne $biblionumber ) {
$biblioitem->{hostitemsflag} = 1;
}
foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } ) {
my $item = $iteminfos_of->{$itemnumber};
+ $item->{force_hold_level} = $force_hold_level;
+
unless (C4::Context->preference('item-level_itypes')) {
$item->{itype} = $biblioitem->{itemtype};
}
$item->{itypename} = $itemtypes->{ $item->{itype} }{description};
$item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
- $item->{homebranchname} = $branches->{ $item->{homebranch} }{branchname};
+ $item->{homebranch} = $item->{homebranch};
# if the holdingbranch is different than the homebranch, we show the
# holdingbranch of the document too
if ( $item->{homebranch} ne $item->{holdingbranch} ) {
- $item->{holdingbranchname} =
- $branches->{ $item->{holdingbranch} }{branchname};
+ $item->{holdingbranch} = $item->{holdingbranch};
}
if($item->{biblionumber} ne $biblionumber){
$item->{ReservedForBorrowernumber} = $reservedfor;
$item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
$item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
- $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
+ $item->{ExpectedAtLibrary} = $expectedAt;
$item->{waitingdate} = $wait;
}
: $item->{itemlost} == 2 ? "(long overdue)"
: "";
$item->{backgroundcolor} = 'other';
- if (GetHideLostItemsPreference($borrowernumber) && !$showallitems) {
+ if ($logged_in_patron->category->hidelostitems && !$showallitems) {
$item->{hide} = 1;
$hiddencount++;
}
if ( defined $transfertwhen && $transfertwhen ne '' ) {
$item->{transfertwhen} = output_pref({ dt => dt_from_string( $transfertwhen ), dateonly => 1 });
- $item->{transfertfrom} =
- $branches->{$transfertfrom}{branchname};
- $item->{transfertto} = $branches->{$transfertto}{branchname};
+ $item->{transfertfrom} = $transfertfrom;
+ $item->{transfertto} = $transfertto;
$item->{nocancel} = 1;
}
$item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
+ my $can_item_be_reserved = CanItemBeReserved( $borrowerinfo->{borrowernumber}, $itemnumber );
+ $item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' );
+
+ $item->{item_level_holds} = OPACItemHoldsAllowed( $item, $borrowerinfo );
+
if (
!$item->{cantreserve}
&& !$exceeded_maxreserves
&& IsAvailableForItemLevelRequest($item, $borrowerinfo)
- && CanItemBeReserved(
- $borrowerinfo->{borrowernumber}, $itemnumber
- ) eq 'OK'
+ && $can_item_be_reserved eq 'OK'
)
{
$item->{available} = 1;
$num_available++;
+
+ push( @available_itemtypes, $item->{itype} );
}
elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
# If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
push @bibitemloop, $biblioitem;
}
+ @available_itemtypes = uniq( @available_itemtypes );
+ $template->param( available_itemtypes => \@available_itemtypes );
+
# existingreserves building
my @reserveloop;
my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } );
}
if ( $res->is_found() ) {
- $reserve{'wait'} = 1;
$reserve{'holdingbranch'} = $res->item()->holdingbranch();
$reserve{'biblionumber'} = $res->item()->biblionumber();
$reserve{'barcodenumber'} = $res->item()->barcode();
$reserve{'suspend'} = $res->suspend();
$reserve{'suspend_until'} = $res->suspend_until();
$reserve{'reserve_id'} = $res->reserve_id();
-
- if ( C4::Context->preference('IndependentBranches') && $flags->{'superlibrarian'} != 1 ) {
- $reserve{'branchloop'} = [ GetBranchDetail( $res->branchcode() ) ];
- }
- else {
- $reserve{'branchloop'} = GetBranchesLoop( $res->branchcode() );
- }
+ $reserve{itemtype} = $res->itemtype();
+ $reserve{branchcode} = $res->branchcode();
push( @reserveloop, \%reserve );
}
my $time = time();
$template->param(
- branchloop => GetBranchesLoop($userbranch),
time => $time,
fixedRank => $fixedRank,
);
C4::Search::enabled_staff_search_views,
);
if (defined $borrowerinfo && exists $borrowerinfo->{'branchcode'}) {
- $template->param(
- borrower_branchname => $branches->{$borrowerinfo->{'branchcode'}}->{'branchname'},
- borrower_branchcode => $borrowerinfo->{'branchcode'},
- );
+ $template->param( borrower_branchcode => $borrowerinfo->{'branchcode'},);
}
$biblioloopiter{biblionumber} = $biblionumber;
$template->param( biblioloop => \@biblioloop );
$template->param( biblionumbers => $biblionumbers );
$template->param( exceeded_maxreserves => $exceeded_maxreserves );
+$template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
if ($multihold) {
$template->param( multi_hold => 1 );