|
Lines 41-46
use Koha::Calendar;
Link Here
|
| 41 |
use Koha::Database; |
41 |
use Koha::Database; |
| 42 |
use Koha::Hold; |
42 |
use Koha::Hold; |
| 43 |
use Koha::Holds; |
43 |
use Koha::Holds; |
|
|
44 |
use Koha::Borrowers; |
| 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 1390-1396
sub ModReserveMinusPriority {
Link Here
|
| 1390 |
my $dbh = C4::Context->dbh; |
1391 |
my $dbh = C4::Context->dbh; |
| 1391 |
my $query = " |
1392 |
my $query = " |
| 1392 |
UPDATE reserves |
1393 |
UPDATE reserves |
| 1393 |
SET priority = 0 , itemnumber = ? |
1394 |
SET priority = 0 , itemnumber = ? |
| 1394 |
WHERE reserve_id = ? |
1395 |
WHERE reserve_id = ? |
| 1395 |
"; |
1396 |
"; |
| 1396 |
my $sth_upd = $dbh->prepare($query); |
1397 |
my $sth_upd = $dbh->prepare($query); |
|
Lines 1605-1611
sub ToggleLowestPriority {
Link Here
|
| 1605 |
|
1606 |
|
| 1606 |
my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?"); |
1607 |
my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?"); |
| 1607 |
$sth->execute( $reserve_id ); |
1608 |
$sth->execute( $reserve_id ); |
| 1608 |
|
1609 |
|
| 1609 |
_FixPriority({ reserve_id => $reserve_id, rank => '999999' }); |
1610 |
_FixPriority({ reserve_id => $reserve_id, rank => '999999' }); |
| 1610 |
} |
1611 |
} |
| 1611 |
|
1612 |
|
|
Lines 1815-1821
sub _FixPriority {
Link Here
|
| 1815 |
$priority[$j]->{'reserve_id'} |
1816 |
$priority[$j]->{'reserve_id'} |
| 1816 |
); |
1817 |
); |
| 1817 |
} |
1818 |
} |
| 1818 |
|
1819 |
|
| 1819 |
$sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" ); |
1820 |
$sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" ); |
| 1820 |
$sth->execute(); |
1821 |
$sth->execute(); |
| 1821 |
|
1822 |
|
|
Lines 2050-2056
sub _koha_notify_reserve {
Link Here
|
| 2050 |
if (! $notification_sent) { |
2051 |
if (! $notification_sent) { |
| 2051 |
&$send_notification('print', 'HOLD'); |
2052 |
&$send_notification('print', 'HOLD'); |
| 2052 |
} |
2053 |
} |
| 2053 |
|
2054 |
|
| 2054 |
} |
2055 |
} |
| 2055 |
|
2056 |
|
| 2056 |
=head2 _ShiftPriorityByDateAndPriority |
2057 |
=head2 _ShiftPriorityByDateAndPriority |
|
Lines 2479-2484
sub IsItemOnHoldAndFound {
Link Here
|
| 2479 |
return $found; |
2480 |
return $found; |
| 2480 |
} |
2481 |
} |
| 2481 |
|
2482 |
|
|
|
2483 |
=head2 GetMaxPatronHoldsForRecord |
| 2484 |
|
| 2485 |
my $holds_per_record = ReservesControlBranch( $borrowernumber, $biblionumber ); |
| 2486 |
|
| 2487 |
For multiple holds on a given record for a given patron, the max |
| 2488 |
number of record level holds that a patron can be placed is the highest |
| 2489 |
value of the holds_per_record rule for each item if the record for that |
| 2490 |
patron. This subroutine finds and returns the highest holds_per_record |
| 2491 |
rule value for a given patron id and record id. |
| 2492 |
|
| 2493 |
=cut |
| 2494 |
|
| 2495 |
sub GetMaxPatronHoldsForRecord { |
| 2496 |
my ( $borrowernumber, $biblionumber ) = @_; |
| 2497 |
|
| 2498 |
my $patron = Koha::Borrowers->find($borrowernumber); |
| 2499 |
my @items = Koha::Items->search( { biblionumber => $biblionumber } ); |
| 2500 |
|
| 2501 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
| 2502 |
|
| 2503 |
my $categorycode = $patron->categorycode; |
| 2504 |
my $branchcode; |
| 2505 |
$branchcode = $patron->branchcode if ( $controlbranch eq "PatronLibrary" ); |
| 2506 |
|
| 2507 |
my $max = 0; |
| 2508 |
foreach my $item (@items) { |
| 2509 |
my $itemtype = $item->effective_itemtype(); |
| 2510 |
|
| 2511 |
$branchcode = $item->homebranch if ( $controlbranch eq "ItemHomeLibrary" ); |
| 2512 |
|
| 2513 |
my $rule = GetHoldRule( $categorycode, $itemtype, $branchcode ); |
| 2514 |
my $holds_per_record = $rule ? $rule->{holds_per_record} : 0; |
| 2515 |
$max = $holds_per_record if $holds_per_record > $max; |
| 2516 |
} |
| 2517 |
|
| 2518 |
return $max; |
| 2519 |
} |
| 2520 |
|
| 2521 |
=head2 GetHoldRule |
| 2522 |
|
| 2523 |
my $rule = GetHoldRule( $categorycode, $itemtype, $branchcode ); |
| 2524 |
|
| 2525 |
Returns the matching hold related issuingrule fields for a given |
| 2526 |
patron category, itemtype, and library. |
| 2527 |
|
| 2528 |
=cut |
| 2529 |
|
| 2530 |
sub GetHoldRule { |
| 2531 |
my ( $categorycode, $itemtype, $branchcode ) = @_; |
| 2532 |
|
| 2533 |
my $dbh = C4::Context->dbh; |
| 2534 |
|
| 2535 |
my $sth = $dbh->prepare( |
| 2536 |
q{ |
| 2537 |
SELECT categorycode, itemtype, branchcode, reservesallowed, holds_per_record |
| 2538 |
FROM issuingrules |
| 2539 |
WHERE (categorycode in (?,'*') ) |
| 2540 |
AND (itemtype IN (?,'*')) |
| 2541 |
AND (branchcode IN (?,'*')) |
| 2542 |
ORDER BY categorycode DESC, |
| 2543 |
itemtype DESC, |
| 2544 |
branchcode DESC |
| 2545 |
} |
| 2546 |
); |
| 2547 |
|
| 2548 |
$sth->execute( $categorycode, $itemtype, $branchcode ); |
| 2549 |
|
| 2550 |
return $sth->fetchrow_hashref(); |
| 2551 |
} |
| 2552 |
|
| 2482 |
=head1 AUTHOR |
2553 |
=head1 AUTHOR |
| 2483 |
|
2554 |
|
| 2484 |
Koha Development Team <http://koha-community.org/> |
2555 |
Koha Development Team <http://koha-community.org/> |