use Modern::Perl;
use C4::Accounts;
+use C4::Biblio qw( GetMarcFromKohaField );
use C4::Circulation qw( CheckIfIssuedToPatron GetAgeRestriction GetBranchItemRule );
use C4::Context;
use C4::Items qw( CartToShelf get_hostitemnumbers_of );
use C4::Members::Messaging;
use C4::Members;
use Koha::Account::Lines;
+use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
use Koha::Biblios;
use Koha::Calendar;
use Koha::CirculationRules;
$found = 'W';
}
}
-
- if ( C4::Context->preference('AllowHoldDateInFuture') ) {
-
- # Make room in reserves for this before those of a later reserve date
- $priority = _ShiftPriorityByDateAndPriority( $biblionumber, $resdate, $priority );
+ if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
+ # Make room in reserves for this if passed a priority
+ $priority = _ShiftPriority( $biblionumber, $priority );
}
my $waitingdate;
}
Koha::Plugins->call('after_hold_create', $hold);
+ Koha::Plugins->call(
+ 'after_hold_action',
+ {
+ action => 'place',
+ payload => { hold => $hold->get_from_storage }
+ }
+ );
+
+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
+ {
+ biblio_ids => [ $biblionumber ]
+ }
+ ) if C4::Context->preference('RealTimeHoldsQueue');
return $reserve_id;
}
return { status =>'alreadypossession' };
}
+ if ( $params->{itemtype} ) {
+
+ # biblio-level, item type-contrained
+ my $patron = Koha::Patrons->find($borrowernumber);
+ my $reservesallowed = Koha::CirculationRules->get_effective_rule(
+ {
+ itemtype => $params->{itemtype},
+ categorycode => $patron->categorycode,
+ branchcode => $pickup_branchcode,
+ rule_name => 'reservesallowed',
+ }
+ )->rule_value;
+
+ $reservesallowed = ( $reservesallowed eq '' ) ? undef : $reservesallowed;
+
+ my $count = $patron->holds->search(
+ {
+ '-or' => [
+ { 'me.itemtype' => $params->{itemtype} },
+ { 'item.itype' => $params->{itemtype} }
+ ]
+ },
+ {
+ join => ['item']
+ }
+ )->count;
+
+ return { status => '' }
+ if defined $reservesallowed and $reservesallowed < $count + 1;
+ }
+
my $items;
#get items linked via host records
my @hostitemnumbers = get_hostitemnumbers_of($biblionumber);
# we retrieve borrowers and items informations #
# item->{itype} will come for biblioitems if necessery
- my $biblio = $item->biblio;
my $borrower = $patron->unblessed;
# If an item is damaged and we don't allow holds on damaged items, we can stop right here
if ( $item->damaged
&& !C4::Context->preference('AllowHoldsOnDamagedItems') );
- # Check for the age restriction
- my ( $ageRestriction, $daysToAgeRestriction ) =
- C4::Circulation::GetAgeRestriction( $biblio->biblioitem->agerestriction, $borrower );
- return { status => 'ageRestricted' } if $daysToAgeRestriction && $daysToAgeRestriction > 0;
+ if( GetMarcFromKohaField('biblioitems.agerestriction') ){
+ my $biblio = $item->biblio;
+ # Check for the age restriction
+ my ( $ageRestriction, $daysToAgeRestriction ) =
+ C4::Circulation::GetAgeRestriction( $biblio->biblioitem->agerestriction, $borrower );
+ return { status => 'ageRestricted' } if $daysToAgeRestriction && $daysToAgeRestriction > 0;
+ }
# Check that the patron doesn't have an item level hold on this item already
return { status =>'itemAlreadyOnHold' }
# Check that patron have not checked out this biblio (if AllowHoldsOnPatronsPossessions set)
if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions')
- && C4::Circulation::CheckIfIssuedToPatron( $patron->borrowernumber, $biblio->biblionumber ) ) {
+ && C4::Circulation::CheckIfIssuedToPatron( $patron->borrowernumber, $item->biblionumber ) ) {
return { status =>'alreadypossession' };
}
# check if a recall exists on this item from this borrower
return { status => 'recall' }
- if $patron->recalls->filter_by_current->search({ itemnumber => $item->itemnumber })->count;
+ if $patron->recalls->filter_by_current->search({ item_id => $item->itemnumber })->count;
my $controlbranch = C4::Context->preference('ReservesControlBranch');
# If using item-level itypes, fall back to the record
# level itemtype if the hold has no associated item
- $querycount .=
- C4::Context->preference('item-level_itypes')
- ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
- : " AND biblioitems.itemtype = ?"
- if defined $ruleitemtype;
+ if ( defined $ruleitemtype ) {
+ if ( C4::Context->preference('item-level_itypes') ) {
+ $querycount .= q{
+ AND ( COALESCE( items.itype, biblioitems.itemtype ) = ?
+ OR reserves.itemtype = ? )
+ };
+ }
+ else {
+ $querycount .= q{
+ AND ( biblioitems.itemtype = ?
+ OR reserves.itemtype = ? )
+ };
+ }
+ }
my $sthcount = $dbh->prepare($querycount);
if ( defined $ruleitemtype ) {
- $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype );
+ $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype, $ruleitemtype );
}
else {
$sthcount->execute( $patron->borrowernumber, $reserves_control_branch );
_FixPriority({ reserve_id => $reserve_id, rank => $last_priority });
}
+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
+ {
+ biblio_ids => [ $hold->biblionumber ]
+ }
+ ) if C4::Context->preference('RealTimeHoldsQueue');
# FIXME Should return the new priority
}
}
-=head2 _ShiftPriorityByDateAndPriority
+=head2 _ShiftPriority
- $new_priority = _ShiftPriorityByDateAndPriority( $biblionumber, $reservedate, $priority );
+ $new_priority = _ShiftPriority( $biblionumber, $priority );
This increments the priority of all reserves after the one
with either the lowest date after C<$reservedate>
=cut
-sub _ShiftPriorityByDateAndPriority {
- my ( $biblio, $resdate, $new_priority ) = @_;
+sub _ShiftPriority {
+ my ( $biblio, $new_priority ) = @_;
my $dbh = C4::Context->dbh;
- my $query = "SELECT priority FROM reserves WHERE biblionumber = ? AND ( reservedate > ? OR priority > ? ) ORDER BY priority ASC LIMIT 1";
+ my $query = "SELECT priority FROM reserves WHERE biblionumber = ? AND priority > ? ORDER BY priority ASC LIMIT 1";
my $sth = $dbh->prepare( $query );
- $sth->execute( $biblio, $resdate, $new_priority );
+ $sth->execute( $biblio, $new_priority );
my $min_priority = $sth->fetchrow;
# if no such matches are found, $new_priority remains as original value
$new_priority = $min_priority if ( $min_priority );
_FixPriority( { biblionumber => $hold->biblionumber } );
+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
+ {
+ biblio_ids => [ $hold->biblionumber ]
+ }
+ ) if C4::Context->preference('RealTimeHoldsQueue');
+
+
return $hold;
}
the parameter value.
After calculation of this priority, it is recommended to call
-_ShiftPriorityByDateAndPriority. Note that this is currently done in
+_ShiftPriority. Note that this is currently done in
AddReserves.
=cut