Lines 41-46
use Koha::Database;
Link Here
|
41 |
use Koha::Hold; |
41 |
use Koha::Hold; |
42 |
use Koha::Holds; |
42 |
use Koha::Holds; |
43 |
use Koha::Libraries; |
43 |
use Koha::Libraries; |
|
|
44 |
use Koha::Patrons; |
44 |
|
45 |
|
45 |
use List::MoreUtils qw( firstidx any ); |
46 |
use List::MoreUtils qw( firstidx any ); |
46 |
use Carp; |
47 |
use Carp; |
Lines 141-146
BEGIN {
Link Here
|
141 |
&GetReservesControlBranch |
142 |
&GetReservesControlBranch |
142 |
|
143 |
|
143 |
IsItemOnHoldAndFound |
144 |
IsItemOnHoldAndFound |
|
|
145 |
|
146 |
GetMaxPatronHoldsForRecord |
144 |
); |
147 |
); |
145 |
@EXPORT_OK = qw( MergeHolds ); |
148 |
@EXPORT_OK = qw( MergeHolds ); |
146 |
} |
149 |
} |
Lines 168-179
sub AddReserve {
Link Here
|
168 |
$title, $checkitem, $found |
171 |
$title, $checkitem, $found |
169 |
) = @_; |
172 |
) = @_; |
170 |
|
173 |
|
171 |
if ( Koha::Holds->search( { borrowernumber => $borrowernumber, biblionumber => $biblionumber } )->count() > 0 ) { |
174 |
my $dbh = C4::Context->dbh; |
172 |
carp("AddReserve: borrower $borrowernumber already has a hold for biblionumber $biblionumber"); |
|
|
173 |
return; |
174 |
} |
175 |
|
176 |
my $dbh = C4::Context->dbh; |
177 |
|
175 |
|
178 |
$resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' }) |
176 |
$resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' }) |
179 |
or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' }); |
177 |
or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' }); |
Lines 453-459
sub CanItemBeReserved {
Link Here
|
453 |
|
451 |
|
454 |
my $dbh = C4::Context->dbh; |
452 |
my $dbh = C4::Context->dbh; |
455 |
my $ruleitemtype; # itemtype of the matching issuing rule |
453 |
my $ruleitemtype; # itemtype of the matching issuing rule |
456 |
my $allowedreserves = 0; |
454 |
my $allowedreserves = 0; # Total number of holds allowed across all records |
|
|
455 |
my $holds_per_record = 1; # Total number of holds allowed for this one given record |
457 |
|
456 |
|
458 |
# we retrieve borrowers and items informations # |
457 |
# we retrieve borrowers and items informations # |
459 |
# item->{itype} will come for biblioitems if necessery |
458 |
# item->{itype} will come for biblioitems if necessery |
Lines 466-491
sub CanItemBeReserved {
Link Here
|
466 |
if ( $item->{damaged} |
465 |
if ( $item->{damaged} |
467 |
&& !C4::Context->preference('AllowHoldsOnDamagedItems') ); |
466 |
&& !C4::Context->preference('AllowHoldsOnDamagedItems') ); |
468 |
|
467 |
|
469 |
#Check for the age restriction |
468 |
# Check for the age restriction |
470 |
my ( $ageRestriction, $daysToAgeRestriction ) = |
469 |
my ( $ageRestriction, $daysToAgeRestriction ) = |
471 |
C4::Circulation::GetAgeRestriction( $biblioData->{agerestriction}, $borrower ); |
470 |
C4::Circulation::GetAgeRestriction( $biblioData->{agerestriction}, $borrower ); |
472 |
return 'ageRestricted' if $daysToAgeRestriction && $daysToAgeRestriction > 0; |
471 |
return 'ageRestricted' if $daysToAgeRestriction && $daysToAgeRestriction > 0; |
473 |
|
472 |
|
474 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
473 |
# Check that the patron doesn't have an item level hold on this item already |
|
|
474 |
return 'itemAlreadyOnHold' |
475 |
if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count(); |
475 |
|
476 |
|
476 |
# we retrieve user rights on this itemtype and branchcode |
477 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
477 |
my $sth = $dbh->prepare( |
|
|
478 |
q{ |
479 |
SELECT categorycode, itemtype, branchcode, reservesallowed |
480 |
FROM issuingrules |
481 |
WHERE (categorycode in (?,'*') ) |
482 |
AND (itemtype IN (?,'*')) |
483 |
AND (branchcode IN (?,'*')) |
484 |
ORDER BY categorycode DESC, |
485 |
itemtype DESC, |
486 |
branchcode DESC |
487 |
} |
488 |
); |
489 |
|
478 |
|
490 |
my $querycount = q{ |
479 |
my $querycount = q{ |
491 |
SELECT count(*) AS count |
480 |
SELECT count(*) AS count |
Lines 509-523
sub CanItemBeReserved {
Link Here
|
509 |
} |
498 |
} |
510 |
|
499 |
|
511 |
# we retrieve rights |
500 |
# we retrieve rights |
512 |
$sth->execute( $borrower->{'categorycode'}, $item->{'itype'}, $branchcode ); |
501 |
if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->{'itype'}, $branchcode ) ) { |
513 |
if ( my $rights = $sth->fetchrow_hashref() ) { |
502 |
$ruleitemtype = $rights->{itemtype}; |
514 |
$ruleitemtype = $rights->{itemtype}; |
503 |
$allowedreserves = $rights->{reservesallowed}; |
515 |
$allowedreserves = $rights->{reservesallowed}; |
504 |
$holds_per_record = $rights->{holds_per_record}; |
516 |
} |
505 |
} |
517 |
else { |
506 |
else { |
518 |
$ruleitemtype = '*'; |
507 |
$ruleitemtype = '*'; |
519 |
} |
508 |
} |
520 |
|
509 |
|
|
|
510 |
my $item = Koha::Items->find( $itemnumber ); |
511 |
my $holds = Koha::Holds->search( |
512 |
{ |
513 |
borrowernumber => $borrowernumber, |
514 |
biblionumber => $item->biblionumber, |
515 |
found => undef, # Found holds don't count against a patron's holds limit |
516 |
} |
517 |
); |
518 |
if ( $holds->count() >= $holds_per_record ) { |
519 |
return "tooManyHoldsForThisRecord"; |
520 |
} |
521 |
|
521 |
# we retrieve count |
522 |
# we retrieve count |
522 |
|
523 |
|
523 |
$querycount .= "AND $branchfield = ?"; |
524 |
$querycount .= "AND $branchfield = ?"; |
Lines 747-754
sub GetReservesToBranch {
Link Here
|
747 |
my $dbh = C4::Context->dbh; |
748 |
my $dbh = C4::Context->dbh; |
748 |
my $sth = $dbh->prepare( |
749 |
my $sth = $dbh->prepare( |
749 |
"SELECT reserve_id,borrowernumber,reservedate,itemnumber,timestamp |
750 |
"SELECT reserve_id,borrowernumber,reservedate,itemnumber,timestamp |
750 |
FROM reserves |
751 |
FROM reserves |
751 |
WHERE priority='0' |
752 |
WHERE priority='0' |
752 |
AND branchcode=?" |
753 |
AND branchcode=?" |
753 |
); |
754 |
); |
754 |
$sth->execute( $frombranch ); |
755 |
$sth->execute( $frombranch ); |
Lines 773-779
sub GetReservesForBranch {
Link Here
|
773 |
|
774 |
|
774 |
my $query = " |
775 |
my $query = " |
775 |
SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate |
776 |
SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate |
776 |
FROM reserves |
777 |
FROM reserves |
777 |
WHERE priority='0' |
778 |
WHERE priority='0' |
778 |
AND found='W' |
779 |
AND found='W' |
779 |
"; |
780 |
"; |
Lines 1395-1401
sub ModReserveMinusPriority {
Link Here
|
1395 |
my $dbh = C4::Context->dbh; |
1396 |
my $dbh = C4::Context->dbh; |
1396 |
my $query = " |
1397 |
my $query = " |
1397 |
UPDATE reserves |
1398 |
UPDATE reserves |
1398 |
SET priority = 0 , itemnumber = ? |
1399 |
SET priority = 0 , itemnumber = ? |
1399 |
WHERE reserve_id = ? |
1400 |
WHERE reserve_id = ? |
1400 |
"; |
1401 |
"; |
1401 |
my $sth_upd = $dbh->prepare($query); |
1402 |
my $sth_upd = $dbh->prepare($query); |
Lines 1610-1616
sub ToggleLowestPriority {
Link Here
|
1610 |
|
1611 |
|
1611 |
my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?"); |
1612 |
my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?"); |
1612 |
$sth->execute( $reserve_id ); |
1613 |
$sth->execute( $reserve_id ); |
1613 |
|
1614 |
|
1614 |
_FixPriority({ reserve_id => $reserve_id, rank => '999999' }); |
1615 |
_FixPriority({ reserve_id => $reserve_id, rank => '999999' }); |
1615 |
} |
1616 |
} |
1616 |
|
1617 |
|
Lines 1794-1800
sub _FixPriority {
Link Here
|
1794 |
$priority[$j]->{'reserve_id'} |
1795 |
$priority[$j]->{'reserve_id'} |
1795 |
); |
1796 |
); |
1796 |
} |
1797 |
} |
1797 |
|
1798 |
|
1798 |
$sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" ); |
1799 |
$sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" ); |
1799 |
$sth->execute(); |
1800 |
$sth->execute(); |
1800 |
|
1801 |
|
Lines 2029-2035
sub _koha_notify_reserve {
Link Here
|
2029 |
if (! $notification_sent) { |
2030 |
if (! $notification_sent) { |
2030 |
&$send_notification('print', 'HOLD'); |
2031 |
&$send_notification('print', 'HOLD'); |
2031 |
} |
2032 |
} |
2032 |
|
2033 |
|
2033 |
} |
2034 |
} |
2034 |
|
2035 |
|
2035 |
=head2 _ShiftPriorityByDateAndPriority |
2036 |
=head2 _ShiftPriorityByDateAndPriority |
Lines 2458-2463
sub IsItemOnHoldAndFound {
Link Here
|
2458 |
return $found; |
2459 |
return $found; |
2459 |
} |
2460 |
} |
2460 |
|
2461 |
|
|
|
2462 |
=head2 GetMaxPatronHoldsForRecord |
2463 |
|
2464 |
my $holds_per_record = ReservesControlBranch( $borrowernumber, $biblionumber ); |
2465 |
|
2466 |
For multiple holds on a given record for a given patron, the max |
2467 |
number of record level holds that a patron can be placed is the highest |
2468 |
value of the holds_per_record rule for each item if the record for that |
2469 |
patron. This subroutine finds and returns the highest holds_per_record |
2470 |
rule value for a given patron id and record id. |
2471 |
|
2472 |
=cut |
2473 |
|
2474 |
sub GetMaxPatronHoldsForRecord { |
2475 |
my ( $borrowernumber, $biblionumber ) = @_; |
2476 |
|
2477 |
my $patron = Koha::Patrons->find($borrowernumber); |
2478 |
my @items = Koha::Items->search( { biblionumber => $biblionumber } ); |
2479 |
|
2480 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
2481 |
|
2482 |
my $categorycode = $patron->categorycode; |
2483 |
my $branchcode; |
2484 |
$branchcode = $patron->branchcode if ( $controlbranch eq "PatronLibrary" ); |
2485 |
|
2486 |
my $max = 0; |
2487 |
foreach my $item (@items) { |
2488 |
my $itemtype = $item->effective_itemtype(); |
2489 |
|
2490 |
$branchcode = $item->homebranch if ( $controlbranch eq "ItemHomeLibrary" ); |
2491 |
|
2492 |
my $rule = GetHoldRule( $categorycode, $itemtype, $branchcode ); |
2493 |
my $holds_per_record = $rule ? $rule->{holds_per_record} : 0; |
2494 |
$max = $holds_per_record if $holds_per_record > $max; |
2495 |
} |
2496 |
|
2497 |
return $max; |
2498 |
} |
2499 |
|
2500 |
=head2 GetHoldRule |
2501 |
|
2502 |
my $rule = GetHoldRule( $categorycode, $itemtype, $branchcode ); |
2503 |
|
2504 |
Returns the matching hold related issuingrule fields for a given |
2505 |
patron category, itemtype, and library. |
2506 |
|
2507 |
=cut |
2508 |
|
2509 |
sub GetHoldRule { |
2510 |
my ( $categorycode, $itemtype, $branchcode ) = @_; |
2511 |
|
2512 |
my $dbh = C4::Context->dbh; |
2513 |
|
2514 |
my $sth = $dbh->prepare( |
2515 |
q{ |
2516 |
SELECT categorycode, itemtype, branchcode, reservesallowed, holds_per_record |
2517 |
FROM issuingrules |
2518 |
WHERE (categorycode in (?,'*') ) |
2519 |
AND (itemtype IN (?,'*')) |
2520 |
AND (branchcode IN (?,'*')) |
2521 |
ORDER BY categorycode DESC, |
2522 |
itemtype DESC, |
2523 |
branchcode DESC |
2524 |
} |
2525 |
); |
2526 |
|
2527 |
$sth->execute( $categorycode, $itemtype, $branchcode ); |
2528 |
|
2529 |
return $sth->fetchrow_hashref(); |
2530 |
} |
2531 |
|
2461 |
=head1 AUTHOR |
2532 |
=head1 AUTHOR |
2462 |
|
2533 |
|
2463 |
Koha Development Team <http://koha-community.org/> |
2534 |
Koha Development Team <http://koha-community.org/> |