Lines 29-34
use C4::Members;
Link Here
|
29 |
use C4::Items; |
29 |
use C4::Items; |
30 |
use C4::Circulation; |
30 |
use C4::Circulation; |
31 |
use C4::Accounts; |
31 |
use C4::Accounts; |
|
|
32 |
use C4::Circulation qw(CanBookBeIssued); |
32 |
|
33 |
|
33 |
# for _koha_notify_reserve |
34 |
# for _koha_notify_reserve |
34 |
use C4::Members::Messaging; |
35 |
use C4::Members::Messaging; |
Lines 41-46
use Koha::Calendar;
Link Here
|
41 |
use Koha::Database; |
42 |
use Koha::Database; |
42 |
use Koha::Hold; |
43 |
use Koha::Hold; |
43 |
use Koha::Holds; |
44 |
use Koha::Holds; |
|
|
45 |
use Koha::Items; |
44 |
|
46 |
|
45 |
use List::MoreUtils qw( firstidx any ); |
47 |
use List::MoreUtils qw( firstidx any ); |
46 |
use Carp; |
48 |
use Carp; |
Lines 421-439
See CanItemBeReserved() for possible return values.
Link Here
|
421 |
|
423 |
|
422 |
=cut |
424 |
=cut |
423 |
|
425 |
|
424 |
sub CanBookBeReserved{ |
426 |
sub CanBookBeReserved { |
425 |
my ($borrowernumber, $biblionumber) = @_; |
427 |
my ( $borrowernumber, $biblionumber ) = @_; |
426 |
|
428 |
|
427 |
my $items = GetItemnumbersForBiblio($biblionumber); |
429 |
my $items = GetItemnumbersForBiblio($biblionumber); |
|
|
430 |
|
428 |
#get items linked via host records |
431 |
#get items linked via host records |
429 |
my @hostitems = get_hostitemnumbers_of($biblionumber); |
432 |
my @hostitems = get_hostitemnumbers_of($biblionumber); |
430 |
if (@hostitems){ |
433 |
if (@hostitems) { |
431 |
push (@$items,@hostitems); |
434 |
push( @$items, @hostitems ); |
432 |
} |
435 |
} |
433 |
|
436 |
|
434 |
my $canReserve; |
437 |
my $canReserve; |
435 |
foreach my $item (@$items) { |
438 |
foreach my $itemnumber (@$items) { |
436 |
$canReserve = CanItemBeReserved( $borrowernumber, $item ); |
439 |
$canReserve = CanItemBeReserved( $borrowernumber, $itemnumber ); |
437 |
return 'OK' if $canReserve eq 'OK'; |
440 |
return 'OK' if $canReserve eq 'OK'; |
438 |
} |
441 |
} |
439 |
return $canReserve; |
442 |
return $canReserve; |
Lines 459-465
sub CanItemBeReserved{
Link Here
|
459 |
my $dbh = C4::Context->dbh; |
462 |
my $dbh = C4::Context->dbh; |
460 |
my $ruleitemtype; # itemtype of the matching issuing rule |
463 |
my $ruleitemtype; # itemtype of the matching issuing rule |
461 |
my $allowedreserves = 0; |
464 |
my $allowedreserves = 0; |
462 |
|
465 |
|
463 |
# we retrieve borrowers and items informations # |
466 |
# we retrieve borrowers and items informations # |
464 |
# item->{itype} will come for biblioitems if necessery |
467 |
# item->{itype} will come for biblioitems if necessery |
465 |
my $item = GetItem($itemnumber); |
468 |
my $item = GetItem($itemnumber); |
Lines 476-482
sub CanItemBeReserved{
Link Here
|
476 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
479 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
477 |
|
480 |
|
478 |
# we retrieve user rights on this itemtype and branchcode |
481 |
# we retrieve user rights on this itemtype and branchcode |
479 |
my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed |
482 |
my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed, allow_hold_if_items_available |
480 |
FROM issuingrules |
483 |
FROM issuingrules |
481 |
WHERE (categorycode in (?,'*') ) |
484 |
WHERE (categorycode in (?,'*') ) |
482 |
AND (itemtype IN (?,'*')) |
485 |
AND (itemtype IN (?,'*')) |
Lines 495-502
sub CanItemBeReserved{
Link Here
|
495 |
LEFT JOIN borrowers USING (borrowernumber) |
498 |
LEFT JOIN borrowers USING (borrowernumber) |
496 |
WHERE borrowernumber = ? |
499 |
WHERE borrowernumber = ? |
497 |
"; |
500 |
"; |
498 |
|
501 |
|
499 |
|
502 |
|
500 |
my $branchcode = ""; |
503 |
my $branchcode = ""; |
501 |
my $branchfield = "reserves.branchcode"; |
504 |
my $branchfield = "reserves.branchcode"; |
502 |
|
505 |
|
Lines 507-526
sub CanItemBeReserved{
Link Here
|
507 |
$branchfield = "borrowers.branchcode"; |
510 |
$branchfield = "borrowers.branchcode"; |
508 |
$branchcode = $borrower->{branchcode}; |
511 |
$branchcode = $borrower->{branchcode}; |
509 |
} |
512 |
} |
510 |
|
513 |
|
511 |
# we retrieve rights |
514 |
my $allow_hold_if_items_available; |
|
|
515 |
|
516 |
# we retrieve rights |
512 |
$sth->execute($borrower->{'categorycode'}, $item->{'itype'}, $branchcode); |
517 |
$sth->execute($borrower->{'categorycode'}, $item->{'itype'}, $branchcode); |
513 |
if(my $rights = $sth->fetchrow_hashref()){ |
518 |
if ( my $rights = $sth->fetchrow_hashref() ) { |
514 |
$ruleitemtype = $rights->{itemtype}; |
519 |
$ruleitemtype = $rights->{itemtype}; |
515 |
$allowedreserves = $rights->{reservesallowed}; |
520 |
$allowedreserves = $rights->{reservesallowed}; |
516 |
}else{ |
521 |
$allow_hold_if_items_available = $rights->{allow_hold_if_items_available}; |
|
|
522 |
} |
523 |
else { |
517 |
$ruleitemtype = '*'; |
524 |
$ruleitemtype = '*'; |
518 |
} |
525 |
} |
519 |
|
526 |
|
520 |
# we retrieve count |
527 |
# we retrieve count |
521 |
|
528 |
|
522 |
$querycount .= "AND $branchfield = ?"; |
529 |
$querycount .= "AND $branchfield = ?"; |
523 |
|
530 |
|
524 |
# If using item-level itypes, fall back to the record |
531 |
# If using item-level itypes, fall back to the record |
525 |
# level itemtype if the hold has no associated item |
532 |
# level itemtype if the hold has no associated item |
526 |
$querycount .= |
533 |
$querycount .= |
Lines 530-536
sub CanItemBeReserved{
Link Here
|
530 |
if ( $ruleitemtype ne "*" ); |
537 |
if ( $ruleitemtype ne "*" ); |
531 |
|
538 |
|
532 |
my $sthcount = $dbh->prepare($querycount); |
539 |
my $sthcount = $dbh->prepare($querycount); |
533 |
|
540 |
|
534 |
if($ruleitemtype eq "*"){ |
541 |
if($ruleitemtype eq "*"){ |
535 |
$sthcount->execute($borrowernumber, $branchcode); |
542 |
$sthcount->execute($borrowernumber, $branchcode); |
536 |
}else{ |
543 |
}else{ |
Lines 572-577
sub CanItemBeReserved{
Link Here
|
572 |
} |
579 |
} |
573 |
} |
580 |
} |
574 |
|
581 |
|
|
|
582 |
unless ( $allow_hold_if_items_available ) { |
583 |
my $item = Koha::Items->find($itemnumber); |
584 |
my @items = Koha::Items->search({ biblionumber => $item->biblionumber }); |
585 |
foreach $item (@items) { |
586 |
my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( |
587 |
$borrower, $item->barcode, my $duedate, |
588 |
my $inprocess, |
589 |
my $ignore_reserves = 1 |
590 |
); |
591 |
|
592 |
return 'itemsAvailable' unless ( keys %$issuingimpossible || keys %$needsconfirmation ); |
593 |
} |
594 |
} |
595 |
|
575 |
return 'OK'; |
596 |
return 'OK'; |
576 |
} |
597 |
} |
577 |
|
598 |
|
Lines 744-751
sub GetReservesToBranch {
Link Here
|
744 |
my $dbh = C4::Context->dbh; |
765 |
my $dbh = C4::Context->dbh; |
745 |
my $sth = $dbh->prepare( |
766 |
my $sth = $dbh->prepare( |
746 |
"SELECT reserve_id,borrowernumber,reservedate,itemnumber,timestamp |
767 |
"SELECT reserve_id,borrowernumber,reservedate,itemnumber,timestamp |
747 |
FROM reserves |
768 |
FROM reserves |
748 |
WHERE priority='0' |
769 |
WHERE priority='0' |
749 |
AND branchcode=?" |
770 |
AND branchcode=?" |
750 |
); |
771 |
); |
751 |
$sth->execute( $frombranch ); |
772 |
$sth->execute( $frombranch ); |
Lines 770-776
sub GetReservesForBranch {
Link Here
|
770 |
|
791 |
|
771 |
my $query = " |
792 |
my $query = " |
772 |
SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate |
793 |
SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate |
773 |
FROM reserves |
794 |
FROM reserves |
774 |
WHERE priority='0' |
795 |
WHERE priority='0' |
775 |
AND found='W' |
796 |
AND found='W' |
776 |
"; |
797 |
"; |
Lines 1389-1395
sub ModReserveMinusPriority {
Link Here
|
1389 |
my $dbh = C4::Context->dbh; |
1410 |
my $dbh = C4::Context->dbh; |
1390 |
my $query = " |
1411 |
my $query = " |
1391 |
UPDATE reserves |
1412 |
UPDATE reserves |
1392 |
SET priority = 0 , itemnumber = ? |
1413 |
SET priority = 0 , itemnumber = ? |
1393 |
WHERE reserve_id = ? |
1414 |
WHERE reserve_id = ? |
1394 |
"; |
1415 |
"; |
1395 |
my $sth_upd = $dbh->prepare($query); |
1416 |
my $sth_upd = $dbh->prepare($query); |
Lines 1604-1610
sub ToggleLowestPriority {
Link Here
|
1604 |
|
1625 |
|
1605 |
my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?"); |
1626 |
my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?"); |
1606 |
$sth->execute( $reserve_id ); |
1627 |
$sth->execute( $reserve_id ); |
1607 |
|
1628 |
|
1608 |
_FixPriority({ reserve_id => $reserve_id, rank => '999999' }); |
1629 |
_FixPriority({ reserve_id => $reserve_id, rank => '999999' }); |
1609 |
} |
1630 |
} |
1610 |
|
1631 |
|
Lines 1814-1820
sub _FixPriority {
Link Here
|
1814 |
$priority[$j]->{'reserve_id'} |
1835 |
$priority[$j]->{'reserve_id'} |
1815 |
); |
1836 |
); |
1816 |
} |
1837 |
} |
1817 |
|
1838 |
|
1818 |
$sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" ); |
1839 |
$sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" ); |
1819 |
$sth->execute(); |
1840 |
$sth->execute(); |
1820 |
|
1841 |
|
Lines 2052-2058
sub _koha_notify_reserve {
Link Here
|
2052 |
if (! $notification_sent) { |
2073 |
if (! $notification_sent) { |
2053 |
&$send_notification('print', 'HOLD'); |
2074 |
&$send_notification('print', 'HOLD'); |
2054 |
} |
2075 |
} |
2055 |
|
2076 |
|
2056 |
} |
2077 |
} |
2057 |
|
2078 |
|
2058 |
=head2 _ShiftPriorityByDateAndPriority |
2079 |
=head2 _ShiftPriorityByDateAndPriority |