Lines 37-48
use Koha::Calendar;
Link Here
|
37 |
use Koha::CirculationRules; |
37 |
use Koha::CirculationRules; |
38 |
use Koha::Database; |
38 |
use Koha::Database; |
39 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
39 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
40 |
use Koha::Hold; |
|
|
41 |
use Koha::Holds; |
40 |
use Koha::Holds; |
42 |
use Koha::ItemTypes; |
41 |
use Koha::ItemTypes; |
43 |
use Koha::Items; |
42 |
use Koha::Items; |
44 |
use Koha::Libraries; |
43 |
use Koha::Libraries; |
45 |
use Koha::Old::Hold; |
|
|
46 |
use Koha::Patrons; |
44 |
use Koha::Patrons; |
47 |
use Koha::Plugins; |
45 |
use Koha::Plugins; |
48 |
|
46 |
|
Lines 190-196
sub AddReserve {
Link Here
|
190 |
my $notes = $params->{notes}; |
188 |
my $notes = $params->{notes}; |
191 |
my $title = $params->{title}; |
189 |
my $title = $params->{title}; |
192 |
my $checkitem = $params->{itemnumber}; |
190 |
my $checkitem = $params->{itemnumber}; |
193 |
my $found = $params->{found}; |
191 |
my $found = $params->{found} // 'placed'; |
194 |
my $itemtype = $params->{itemtype}; |
192 |
my $itemtype = $params->{itemtype}; |
195 |
my $non_priority = $params->{non_priority}; |
193 |
my $non_priority = $params->{non_priority}; |
196 |
|
194 |
|
Lines 221-227
sub AddReserve {
Link Here
|
221 |
&& !$item->current_holds->count ) |
219 |
&& !$item->current_holds->count ) |
222 |
{ |
220 |
{ |
223 |
$priority = 0; |
221 |
$priority = 0; |
224 |
$found = 'W'; |
222 |
$found = 'waiting'; |
225 |
} |
223 |
} |
226 |
} |
224 |
} |
227 |
|
225 |
|
Lines 234-240
sub AddReserve {
Link Here
|
234 |
my $waitingdate; |
232 |
my $waitingdate; |
235 |
|
233 |
|
236 |
# If the reserv had the waiting status, we had the value of the resdate |
234 |
# If the reserv had the waiting status, we had the value of the resdate |
237 |
if ( $found && $found eq 'W' ) { |
235 |
if ( $found and $found eq 'waiting' ) { |
238 |
$waitingdate = $resdate; |
236 |
$waitingdate = $resdate; |
239 |
} |
237 |
} |
240 |
|
238 |
|
Lines 244-265
sub AddReserve {
Link Here
|
244 |
# updates take place here |
242 |
# updates take place here |
245 |
my $hold = Koha::Hold->new( |
243 |
my $hold = Koha::Hold->new( |
246 |
{ |
244 |
{ |
247 |
borrowernumber => $borrowernumber, |
245 |
patron_id => $borrowernumber, |
248 |
biblionumber => $biblionumber, |
246 |
biblio_id => $biblionumber, |
249 |
reservedate => $resdate, |
247 |
created_date => $resdate, |
250 |
branchcode => $branch, |
248 |
pickup_library_id => $branch, |
251 |
priority => $priority, |
249 |
priority => $priority, |
252 |
reservenotes => $notes, |
250 |
notes => $notes, |
253 |
itemnumber => $checkitem, |
251 |
item_id => $checkitem, |
254 |
found => $found, |
252 |
waiting_date => $waitingdate, |
255 |
waitingdate => $waitingdate, |
253 |
expiration_date => $expdate, |
256 |
expirationdate => $expdate, |
254 |
item_type => $itemtype, |
257 |
itemtype => $itemtype, |
255 |
item_level => $checkitem ? 1 : 0, |
258 |
item_level_hold => $checkitem ? 1 : 0, |
|
|
259 |
non_priority => $non_priority ? 1 : 0, |
256 |
non_priority => $non_priority ? 1 : 0, |
260 |
} |
257 |
} |
261 |
)->store(); |
258 |
)->store(); |
262 |
$hold->set_waiting() if $found && $found eq 'W'; |
259 |
$hold->set_waiting() if $found eq 'waiting'; |
263 |
|
260 |
|
264 |
logaction( 'HOLDS', 'CREATE', $hold->id, Dumper($hold->unblessed) ) |
261 |
logaction( 'HOLDS', 'CREATE', $hold->id, Dumper($hold->unblessed) ) |
265 |
if C4::Context->preference('HoldsLog'); |
262 |
if C4::Context->preference('HoldsLog'); |
Lines 398-404
sub CanItemBeReserved {
Link Here
|
398 |
|
395 |
|
399 |
# Check that the patron doesn't have an item level hold on this item already |
396 |
# Check that the patron doesn't have an item level hold on this item already |
400 |
return { status =>'itemAlreadyOnHold' } |
397 |
return { status =>'itemAlreadyOnHold' } |
401 |
if ( !$params->{ignore_hold_counts} && Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count() ); |
398 |
if ( !$params->{ignore_hold_counts} && Koha::Holds->search( { patron_id => $borrowernumber, item_id => $itemnumber, completed => 0 } )->count() ); |
402 |
|
399 |
|
403 |
# Check that patron have not checked out this biblio (if AllowHoldsOnPatronsPossessions set) |
400 |
# Check that patron have not checked out this biblio (if AllowHoldsOnPatronsPossessions set) |
404 |
if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions') |
401 |
if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions') |
Lines 410-424
sub CanItemBeReserved {
Link Here
|
410 |
|
407 |
|
411 |
my $querycount = q{ |
408 |
my $querycount = q{ |
412 |
SELECT count(*) AS count |
409 |
SELECT count(*) AS count |
413 |
FROM reserves |
410 |
FROM holds |
414 |
LEFT JOIN items USING (itemnumber) |
411 |
LEFT JOIN items ON (holds.item_id=items.itemnumber) |
415 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
412 |
LEFT JOIN biblioitems ON (holds.biblio_id=biblioitems.biblionumber) |
416 |
LEFT JOIN borrowers USING (borrowernumber) |
413 |
LEFT JOIN borrowers ON (holds.patron_id=borrowers.borrowernumber) |
417 |
WHERE borrowernumber = ? |
414 |
WHERE completed = 0 and borrowernumber = ? |
418 |
}; |
415 |
}; |
419 |
|
416 |
|
420 |
my $branchcode = ""; |
417 |
my $branchcode = ""; |
421 |
my $branchfield = "reserves.branchcode"; |
418 |
my $branchfield = "holds.pickup_library_id"; |
422 |
|
419 |
|
423 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
420 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
424 |
$branchfield = "items.homebranch"; |
421 |
$branchfield = "items.homebranch"; |
Lines 455-464
sub CanItemBeReserved {
Link Here
|
455 |
my $holds_per_day = $rights->{holds_per_day}; |
452 |
my $holds_per_day = $rights->{holds_per_day}; |
456 |
|
453 |
|
457 |
my $search_params = { |
454 |
my $search_params = { |
458 |
borrowernumber => $borrowernumber, |
455 |
patron_id => $borrowernumber, |
459 |
biblionumber => $item->biblionumber, |
456 |
biblio_id => $item->biblionumber, |
|
|
457 |
completed => 0, |
460 |
}; |
458 |
}; |
461 |
$search_params->{found} = undef if $params->{ignore_found_holds}; |
459 |
$search_params->{status} = 'placed' if $params->{ignore_found_holds}; |
462 |
|
460 |
|
463 |
my $holds = Koha::Holds->search($search_params); |
461 |
my $holds = Koha::Holds->search($search_params); |
464 |
if ( defined $holds_per_record && $holds_per_record ne '' ){ |
462 |
if ( defined $holds_per_record && $holds_per_record ne '' ){ |
Lines 471-478
sub CanItemBeReserved {
Link Here
|
471 |
} |
469 |
} |
472 |
|
470 |
|
473 |
my $today_holds = Koha::Holds->search({ |
471 |
my $today_holds = Koha::Holds->search({ |
474 |
borrowernumber => $borrowernumber, |
472 |
patron_id => $borrowernumber, |
475 |
reservedate => dt_from_string->date |
473 |
created_date => dt_from_string->date, |
|
|
474 |
completed => 0 |
476 |
}); |
475 |
}); |
477 |
|
476 |
|
478 |
if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne '' |
477 |
if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne '' |
Lines 528-534
sub CanItemBeReserved {
Link Here
|
528 |
if (!$params->{ignore_hold_counts} && $rule && defined( $rule->rule_value ) && $rule->rule_value ne '' ) { |
527 |
if (!$params->{ignore_hold_counts} && $rule && defined( $rule->rule_value ) && $rule->rule_value ne '' ) { |
529 |
my $total_holds_count = Koha::Holds->search( |
528 |
my $total_holds_count = Koha::Holds->search( |
530 |
{ |
529 |
{ |
531 |
borrowernumber => $borrower->{borrowernumber} |
530 |
patron_id => $borrower->{borrowernumber}, |
|
|
531 |
completed => 0 |
532 |
} |
532 |
} |
533 |
)->count(); |
533 |
)->count(); |
534 |
|
534 |
|
Lines 606-615
sub CanReserveBeCanceledFromOpac {
Link Here
|
606 |
my ($reserve_id, $borrowernumber) = @_; |
606 |
my ($reserve_id, $borrowernumber) = @_; |
607 |
|
607 |
|
608 |
return unless $reserve_id and $borrowernumber; |
608 |
return unless $reserve_id and $borrowernumber; |
609 |
my $reserve = Koha::Holds->find($reserve_id) or return; |
609 |
my $hold = Koha::Holds->find($reserve_id); |
|
|
610 |
return unless $hold; |
610 |
|
611 |
|
611 |
return 0 unless $reserve->borrowernumber == $borrowernumber; |
612 |
return 0 unless $hold->patron_id == $borrowernumber; |
612 |
return $reserve->is_cancelable_from_opac; |
613 |
return $hold->is_cancelable_from_opac; |
613 |
} |
614 |
} |
614 |
|
615 |
|
615 |
=head2 GetOtherReserves |
616 |
=head2 GetOtherReserves |
Lines 627-645
sub GetOtherReserves {
Link Here
|
627 |
my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber); |
628 |
my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber); |
628 |
if ($checkreserves) { |
629 |
if ($checkreserves) { |
629 |
my $item = Koha::Items->find($itemnumber); |
630 |
my $item = Koha::Items->find($itemnumber); |
630 |
if ( $item->holdingbranch ne $checkreserves->{'branchcode'} ) { |
631 |
if ( $item->holdingbranch ne $checkreserves->{pickup_library_id} ) { |
631 |
$messages->{'transfert'} = $checkreserves->{'branchcode'}; |
632 |
$messages->{'transfert'} = $checkreserves->{pickup_library_id}; |
632 |
#minus priorities of others reservs |
633 |
#minus priorities of others reservs |
633 |
ModReserveMinusPriority( |
634 |
ModReserveMinusPriority( |
634 |
$itemnumber, |
635 |
$itemnumber, |
635 |
$checkreserves->{'reserve_id'}, |
636 |
$checkreserves->{id}, |
636 |
); |
637 |
); |
637 |
|
638 |
|
638 |
#launch the subroutine dotransfer |
639 |
#launch the subroutine dotransfer |
639 |
C4::Items::ModItemTransfer( |
640 |
C4::Items::ModItemTransfer( |
640 |
$itemnumber, |
641 |
$itemnumber, |
641 |
$item->holdingbranch, |
642 |
$item->holdingbranch, |
642 |
$checkreserves->{'branchcode'}, |
643 |
$checkreserves->{pickup_library_id}, |
643 |
'Reserve' |
644 |
'Reserve' |
644 |
), |
645 |
), |
645 |
; |
646 |
; |
Lines 650-658
sub GetOtherReserves {
Link Here
|
650 |
$messages->{'waiting'} = 1; |
651 |
$messages->{'waiting'} = 1; |
651 |
ModReserveMinusPriority( |
652 |
ModReserveMinusPriority( |
652 |
$itemnumber, |
653 |
$itemnumber, |
653 |
$checkreserves->{'reserve_id'}, |
654 |
$checkreserves->{id}, |
654 |
); |
655 |
); |
655 |
ModReserveStatus($itemnumber,'W'); |
656 |
ModReserveStatus($itemnumber,'waiting'); |
656 |
} |
657 |
} |
657 |
|
658 |
|
658 |
$nextreservinfo = $checkreserves; |
659 |
$nextreservinfo = $checkreserves; |
Lines 743-767
If several reserves exist, the reserve with the lower priority is given.
Link Here
|
743 |
## multiple reserves for that bib can have the itemnumber set |
744 |
## multiple reserves for that bib can have the itemnumber set |
744 |
## the sub is only used once in the codebase. |
745 |
## the sub is only used once in the codebase. |
745 |
sub GetReserveStatus { |
746 |
sub GetReserveStatus { |
746 |
my ($itemnumber) = @_; |
747 |
my ($item_id) = @_; |
747 |
|
748 |
|
748 |
my $dbh = C4::Context->dbh; |
749 |
my $holds_rs = Koha::Holds->search({ item_id => $item_id, completed => 0 }, { order_by => 'priority' }); |
749 |
|
750 |
|
750 |
my ($sth, $found, $priority); |
751 |
if ( $holds_rs->count > 0 ) { |
751 |
if ( $itemnumber ) { |
752 |
# They are sorted by priority, pick the first one |
752 |
$sth = $dbh->prepare("SELECT found, priority FROM reserves WHERE itemnumber = ? order by priority LIMIT 1"); |
753 |
my $hold = $holds_rs->next; |
753 |
$sth->execute($itemnumber); |
|
|
754 |
($found, $priority) = $sth->fetchrow_array; |
755 |
} |
756 |
|
754 |
|
757 |
if(defined $found) { |
755 |
return 'Waiting' if $hold->is_waiting and $hold->priority == 0; |
758 |
return 'Waiting' if $found eq 'W' and $priority == 0; |
756 |
return 'Processing' if $hold->is_in_processing; |
759 |
return 'Processing' if $found eq 'P'; |
757 |
return 'Finished' if $hold->status eq 'fulfilled'; |
760 |
return 'Finished' if $found eq 'F'; |
758 |
return 'Reserved' if $hold->priority > 0; |
761 |
} |
759 |
} |
762 |
|
760 |
|
763 |
return 'Reserved' if defined $priority && $priority > 0; |
|
|
764 |
|
765 |
return ''; # empty string here will remove need for checking undef, or less log lines |
761 |
return ''; # empty string here will remove need for checking undef, or less log lines |
766 |
} |
762 |
} |
767 |
|
763 |
|
Lines 800-806
sub CheckReserves {
Link Here
|
800 |
my $sth; |
796 |
my $sth; |
801 |
my $select; |
797 |
my $select; |
802 |
if (C4::Context->preference('item-level_itypes')){ |
798 |
if (C4::Context->preference('item-level_itypes')){ |
803 |
$select = " |
799 |
$select = " |
804 |
SELECT items.biblionumber, |
800 |
SELECT items.biblionumber, |
805 |
items.biblioitemnumber, |
801 |
items.biblioitemnumber, |
806 |
itemtypes.notforloan, |
802 |
itemtypes.notforloan, |
Lines 815-821
sub CheckReserves {
Link Here
|
815 |
"; |
811 |
"; |
816 |
} |
812 |
} |
817 |
else { |
813 |
else { |
818 |
$select = " |
814 |
$select = " |
819 |
SELECT items.biblionumber, |
815 |
SELECT items.biblionumber, |
820 |
items.biblioitemnumber, |
816 |
items.biblioitemnumber, |
821 |
itemtypes.notforloan, |
817 |
itemtypes.notforloan, |
Lines 868-878
sub CheckReserves {
Link Here
|
868 |
|
864 |
|
869 |
my $priority = 10000000; |
865 |
my $priority = 10000000; |
870 |
foreach my $res (@reserves) { |
866 |
foreach my $res (@reserves) { |
871 |
if ($res->{'found'} && $res->{'found'} eq 'W') { |
867 |
if ($res->{status} eq 'waiting') { |
872 |
return ( "Waiting", $res, \@reserves ); # Found it, it is waiting |
868 |
return ( "Waiting", $res, \@reserves ); # Found it, it is waiting |
873 |
} elsif ($res->{'found'} && $res->{'found'} eq 'P') { |
869 |
} elsif ($res->{status} eq 'processing') { |
874 |
return ( "Processing", $res, \@reserves ); # Found determinated hold, e. g. the transferred one |
870 |
return ( "Processing", $res, \@reserves ); # Found determinated hold, e. g. the transferred one |
875 |
} elsif ($res->{'found'} && $res->{'found'} eq 'T') { |
871 |
} elsif ($res->{status} eq 'in_transit') { |
876 |
return ( "Transferred", $res, \@reserves ); # Found determinated hold, e. g. the transferred one |
872 |
return ( "Transferred", $res, \@reserves ); # Found determinated hold, e. g. the transferred one |
877 |
} else { |
873 |
} else { |
878 |
my $patron; |
874 |
my $patron; |
Lines 880-886
sub CheckReserves {
Link Here
|
880 |
my $local_hold_match; |
876 |
my $local_hold_match; |
881 |
|
877 |
|
882 |
if ($LocalHoldsPriority) { |
878 |
if ($LocalHoldsPriority) { |
883 |
$patron = Koha::Patrons->find( $res->{borrowernumber} ); |
879 |
$patron = Koha::Patrons->find( $res->{patron_id} ); |
884 |
$item = Koha::Items->find($itemnumber); |
880 |
$item = Koha::Items->find($itemnumber); |
885 |
|
881 |
|
886 |
unless ($item->exclude_from_local_holds_priority || $patron->category->exclude_from_local_holds_priority) { |
882 |
unless ($item->exclude_from_local_holds_priority || $patron->category->exclude_from_local_holds_priority) { |
Lines 888-894
sub CheckReserves {
Link Here
|
888 |
$item->$LocalHoldsPriorityItemControl; |
884 |
$item->$LocalHoldsPriorityItemControl; |
889 |
my $local_holds_priority_patron_branchcode = |
885 |
my $local_holds_priority_patron_branchcode = |
890 |
( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' ) |
886 |
( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' ) |
891 |
? $res->{branchcode} |
887 |
? $res->{pickup_library_id} |
892 |
: ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' ) |
888 |
: ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' ) |
893 |
? $patron->branchcode |
889 |
? $patron->branchcode |
894 |
: undef; |
890 |
: undef; |
Lines 899-908
sub CheckReserves {
Link Here
|
899 |
} |
895 |
} |
900 |
|
896 |
|
901 |
# See if this item is more important than what we've got so far |
897 |
# See if this item is more important than what we've got so far |
902 |
if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) { |
898 |
if ( ( $res->{priority} && $res->{priority} < $priority ) || $local_hold_match ) { |
903 |
$item ||= Koha::Items->find($itemnumber); |
899 |
$item ||= Koha::Items->find($itemnumber); |
904 |
next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype; |
900 |
next if $res->{item_type} && $res->{item_type} ne $item->effective_itemtype; |
905 |
$patron ||= Koha::Patrons->find( $res->{borrowernumber} ); |
901 |
$patron ||= Koha::Patrons->find( $res->{patron_id} ); |
906 |
my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed ); |
902 |
my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed ); |
907 |
my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype); |
903 |
my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype); |
908 |
next if ($branchitemrule->{'holdallowed'} eq 'not_allowed'); |
904 |
next if ($branchitemrule->{'holdallowed'} eq 'not_allowed'); |
Lines 910-919
sub CheckReserves {
Link Here
|
910 |
my $library = Koha::Libraries->find({branchcode=>$item->homebranch}); |
906 |
my $library = Koha::Libraries->find({branchcode=>$item->homebranch}); |
911 |
next if (($branchitemrule->{'holdallowed'} eq 'from_local_hold_group') && (!$library->validate_hold_sibling({branchcode => $patron->branchcode}) )); |
907 |
next if (($branchitemrule->{'holdallowed'} eq 'from_local_hold_group') && (!$library->validate_hold_sibling({branchcode => $patron->branchcode}) )); |
912 |
my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy}; |
908 |
my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy}; |
913 |
next if ( ($hold_fulfillment_policy eq 'holdgroup') && (!$library->validate_hold_sibling({branchcode => $res->{branchcode}})) ); |
909 |
next if ( ($hold_fulfillment_policy eq 'holdgroup') && (!$library->validate_hold_sibling({branchcode => $res->{pickup_library_id}})) ); |
914 |
next if ( ($hold_fulfillment_policy eq 'homebranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) ); |
910 |
next if ( ($hold_fulfillment_policy eq 'homebranch') && ($res->{pickup_library_id} ne $item->$hold_fulfillment_policy) ); |
915 |
next if ( ($hold_fulfillment_policy eq 'holdingbranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) ); |
911 |
next if ( ($hold_fulfillment_policy eq 'holdingbranch') && ($res->{pickup_library_id} ne $item->$hold_fulfillment_policy) ); |
916 |
next unless $item->can_be_transferred( { to => Koha::Libraries->find( $res->{branchcode} ) } ); |
912 |
next unless $item->can_be_transferred( { to => Koha::Libraries->find( $res->{pickup_library_id} ) } ); |
917 |
$priority = $res->{'priority'}; |
913 |
$priority = $res->{'priority'}; |
918 |
$highest = $res; |
914 |
$highest = $res; |
919 |
last if $local_hold_match; |
915 |
last if $local_hold_match; |
Lines 947-966
sub CancelExpiredReserves {
Link Here
|
947 |
my $expireWaiting = C4::Context->preference('ExpireReservesMaxPickUpDelay'); |
943 |
my $expireWaiting = C4::Context->preference('ExpireReservesMaxPickUpDelay'); |
948 |
|
944 |
|
949 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
945 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
950 |
my $params = { expirationdate => { '<', $dtf->format_date($today) } }; |
946 |
my $params = { expiration_date => { '<', $dtf->format_date($today) } }; |
951 |
$params->{found} = [ { '!=', 'W' }, undef ] unless $expireWaiting; |
947 |
$params->{status} = [ { '!=', 'waiting' }, undef ] unless $expireWaiting; |
952 |
|
948 |
|
953 |
# FIXME To move to Koha::Holds->search_expired (?) |
949 |
# FIXME To move to Koha::Holds->search_expired (?) |
954 |
my $holds = Koha::Holds->search( $params ); |
950 |
my $holds = Koha::Holds->search( $params ); |
955 |
|
951 |
|
956 |
while ( my $hold = $holds->next ) { |
952 |
while ( my $hold = $holds->next ) { |
957 |
my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode ); |
953 |
my $calendar = Koha::Calendar->new( branchcode => $hold->pickup_library_id ); |
958 |
|
954 |
|
959 |
next if !$cancel_on_holidays && $calendar->is_holiday( $today ); |
955 |
next if !$cancel_on_holidays && $calendar->is_holiday( $today ); |
960 |
|
956 |
|
961 |
my $cancel_params = {}; |
957 |
my $cancel_params = {}; |
962 |
$cancel_params->{cancellation_reason} = $cancellation_reason if defined($cancellation_reason); |
958 |
$cancel_params->{cancellation_reason} = $cancellation_reason if defined($cancellation_reason); |
963 |
if ( defined($hold->found) && $hold->found eq 'W' ) { |
959 |
if ( $hold->is_waiting ) { |
964 |
$cancel_params->{charge_cancel_fee} = 1; |
960 |
$cancel_params->{charge_cancel_fee} = 1; |
965 |
} |
961 |
} |
966 |
$hold->cancel( $cancel_params ); |
962 |
$hold->cancel( $cancel_params ); |
Lines 971-984
sub CancelExpiredReserves {
Link Here
|
971 |
|
967 |
|
972 |
AutoUnsuspendReserves(); |
968 |
AutoUnsuspendReserves(); |
973 |
|
969 |
|
974 |
Unsuspends all suspended reserves with a suspend_until date from before today. |
970 |
Unsuspends all suspended reserves with a suspended_until date from before today. |
975 |
|
971 |
|
976 |
=cut |
972 |
=cut |
977 |
|
973 |
|
978 |
sub AutoUnsuspendReserves { |
974 |
sub AutoUnsuspendReserves { |
979 |
my $today = dt_from_string(); |
975 |
my $today = dt_from_string(); |
980 |
|
976 |
|
981 |
my @holds = Koha::Holds->search( { suspend_until => { '<=' => $today->ymd() } } ); |
977 |
my @holds = Koha::Holds->search( { suspended_until_date => { '<=' => $today->ymd() } } ); |
982 |
|
978 |
|
983 |
map { $_->resume() } @holds; |
979 |
map { $_->resume() } @holds; |
984 |
} |
980 |
} |
Lines 1038-1047
sub ModReserve {
Link Here
|
1038 |
|
1034 |
|
1039 |
my $hold; |
1035 |
my $hold; |
1040 |
unless ( $reserve_id ) { |
1036 |
unless ( $reserve_id ) { |
1041 |
my $holds = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber, itemnumber => $itemnumber }); |
1037 |
my $holds = Koha::Holds->search({ biblio_id => $biblionumber, patron_id => $borrowernumber, item_id => $itemnumber }); |
1042 |
return unless $holds->count; # FIXME Should raise an exception |
1038 |
return unless $holds->count; # FIXME Should raise an exception |
1043 |
$hold = $holds->next; |
1039 |
$hold = $holds->next; |
1044 |
$reserve_id = $hold->reserve_id; |
1040 |
$reserve_id = $hold->id; |
1045 |
} |
1041 |
} |
1046 |
|
1042 |
|
1047 |
$hold ||= Koha::Holds->find($reserve_id); |
1043 |
$hold ||= Koha::Holds->find($reserve_id); |
Lines 1050-1070
sub ModReserve {
Link Here
|
1050 |
$hold->cancel({ cancellation_reason => $cancellation_reason }); |
1046 |
$hold->cancel({ cancellation_reason => $cancellation_reason }); |
1051 |
} |
1047 |
} |
1052 |
elsif ($rank =~ /^\d+/ and $rank > 0) { |
1048 |
elsif ($rank =~ /^\d+/ and $rank > 0) { |
1053 |
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) ) |
1049 |
logaction( 'HOLDS', 'MODIFY', $hold->id, Dumper($hold->unblessed) ) |
1054 |
if C4::Context->preference('HoldsLog'); |
1050 |
if C4::Context->preference('HoldsLog'); |
1055 |
|
1051 |
|
1056 |
my $properties = { |
1052 |
my $properties = { |
1057 |
priority => $rank, |
1053 |
priority => $rank, |
1058 |
branchcode => $branchcode, |
1054 |
pickup_library_id => $branchcode, |
1059 |
itemnumber => $itemnumber, |
1055 |
item_id => $itemnumber, |
1060 |
found => undef, |
1056 |
status => 'placed', |
1061 |
waitingdate => undef |
1057 |
waiting_date => undef |
1062 |
}; |
1058 |
}; |
1063 |
if (exists $params->{reservedate}) { |
1059 |
if (exists $params->{reservedate}) { |
1064 |
$properties->{reservedate} = $params->{reservedate} || undef; |
1060 |
$properties->{created_date} = $params->{reservedate} || undef; |
1065 |
} |
1061 |
} |
1066 |
if (exists $params->{expirationdate}) { |
1062 |
if (exists $params->{expirationdate}) { |
1067 |
$properties->{expirationdate} = $params->{expirationdate} || undef; |
1063 |
$properties->{expiration_date} = $params->{expirationdate} || undef; |
1068 |
} |
1064 |
} |
1069 |
|
1065 |
|
1070 |
$hold->set($properties)->store(); |
1066 |
$hold->set($properties)->store(); |
Lines 1076-1082
sub ModReserve {
Link Here
|
1076 |
} else { |
1072 |
} else { |
1077 |
# If the hold is suspended leave the hold suspended, but convert it to an indefinite hold. |
1073 |
# If the hold is suspended leave the hold suspended, but convert it to an indefinite hold. |
1078 |
# If the hold is not suspended, this does nothing. |
1074 |
# If the hold is not suspended, this does nothing. |
1079 |
$hold->set( { suspend_until => undef } )->store(); |
1075 |
$hold->set( { suspended_until_date => undef } )->store(); |
1080 |
} |
1076 |
} |
1081 |
} |
1077 |
} |
1082 |
|
1078 |
|
Lines 1098-1134
whose keys are fields from the reserves table in the Koha database.
Link Here
|
1098 |
|
1094 |
|
1099 |
sub ModReserveFill { |
1095 |
sub ModReserveFill { |
1100 |
my ($res) = @_; |
1096 |
my ($res) = @_; |
1101 |
my $reserve_id = $res->{'reserve_id'}; |
1097 |
my $reserve_id = $res->{'id'}; |
1102 |
|
1098 |
|
1103 |
my $hold = Koha::Holds->find($reserve_id); |
1099 |
my $hold = Koha::Holds->find($reserve_id); |
1104 |
# get the priority on this record.... |
1100 |
# get the priority on this record.... |
1105 |
my $priority = $hold->priority; |
1101 |
my $priority = $hold->priority; |
1106 |
|
1102 |
|
1107 |
# update the hold statuses, no need to store it though, we will be deleting it anyway |
1103 |
# update the hold statuses, no need to store it though, we will be deleting it anyway |
|
|
1104 |
# FIXME: Add Koha::Hold->set_filled and add the correct log |
1108 |
$hold->set( |
1105 |
$hold->set( |
1109 |
{ |
1106 |
{ |
1110 |
found => 'F', |
1107 |
status => 'fulfilled', |
1111 |
priority => 0, |
1108 |
priority => 0, |
|
|
1109 |
completed => 1, |
1110 |
completed_date => \'NOW()' |
1112 |
} |
1111 |
} |
1113 |
); |
1112 |
); |
1114 |
|
1113 |
|
1115 |
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) ) |
1114 |
logaction( 'HOLDS', 'MODIFY', $hold->id, Dumper($hold->unblessed) ) |
1116 |
if C4::Context->preference('HoldsLog'); |
1115 |
if C4::Context->preference('HoldsLog'); |
1117 |
|
1116 |
|
1118 |
# FIXME Must call Koha::Hold->cancel ? => No, should call ->filled and add the correct log |
1117 |
$hold->store(); |
1119 |
Koha::Old::Hold->new( $hold->unblessed() )->store(); |
|
|
1120 |
|
1121 |
$hold->delete(); |
1122 |
|
1118 |
|
1123 |
if ( C4::Context->preference('HoldFeeMode') eq 'any_time_is_collected' ) { |
1119 |
if ( C4::Context->preference('HoldFeeMode') eq 'any_time_is_collected' ) { |
1124 |
my $reserve_fee = GetReserveFee( $hold->borrowernumber, $hold->biblionumber ); |
1120 |
my $reserve_fee = GetReserveFee( $hold->patron_id, $hold->biblio_id ); |
1125 |
ChargeReserveFee( $hold->borrowernumber, $reserve_fee, $hold->biblio->title ); |
1121 |
ChargeReserveFee( $hold->patron_id, $reserve_fee, $hold->biblio->title ); |
1126 |
} |
1122 |
} |
1127 |
|
1123 |
|
1128 |
# now fix the priority on the others (if the priority wasn't |
1124 |
# now fix the priority on the others (if the priority wasn't |
1129 |
# already sorted!).... |
1125 |
# already sorted!).... |
1130 |
unless ( $priority == 0 ) { |
1126 |
unless ( $priority == 0 ) { |
1131 |
_FixPriority( { reserve_id => $reserve_id, biblionumber => $hold->biblionumber } ); |
1127 |
_FixPriority( { reserve_id => $reserve_id, biblionumber => $hold->biblio_id } ); |
1132 |
} |
1128 |
} |
1133 |
} |
1129 |
} |
1134 |
|
1130 |
|
Lines 1150-1156
sub ModReserveStatus {
Link Here
|
1150 |
my ($itemnumber, $newstatus) = @_; |
1146 |
my ($itemnumber, $newstatus) = @_; |
1151 |
my $dbh = C4::Context->dbh; |
1147 |
my $dbh = C4::Context->dbh; |
1152 |
|
1148 |
|
1153 |
my $query = "UPDATE reserves SET found = ?, waitingdate = NOW() WHERE itemnumber = ? AND found IS NULL AND priority = 0"; |
1149 |
my $query = "UPDATE holds SET status = ?, waiting_date = NOW() WHERE item_id = ? AND status='placed' AND priority = 0"; |
1154 |
my $sth_set = $dbh->prepare($query); |
1150 |
my $sth_set = $dbh->prepare($query); |
1155 |
$sth_set->execute( $newstatus, $itemnumber ); |
1151 |
$sth_set->execute( $newstatus, $itemnumber ); |
1156 |
|
1152 |
|
Lines 1196-1210
sub ModReserveAffect {
Link Here
|
1196 |
# Find hold by id if we have it |
1192 |
# Find hold by id if we have it |
1197 |
$hold = Koha::Holds->find( $reserve_id ) if $reserve_id; |
1193 |
$hold = Koha::Holds->find( $reserve_id ) if $reserve_id; |
1198 |
# Find item level hold for this item if there is one |
1194 |
# Find item level hold for this item if there is one |
1199 |
$hold ||= Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->next(); |
1195 |
$hold ||= Koha::Holds->search( { patron_id => $borrowernumber, item_id => $itemnumber } )->next(); |
1200 |
# Find record level hold if there is no item level hold |
1196 |
# Find record level hold if there is no item level hold |
1201 |
$hold ||= Koha::Holds->search( { borrowernumber => $borrowernumber, biblionumber => $biblionumber } )->next(); |
1197 |
$hold ||= Koha::Holds->search( { patron_id => $borrowernumber, biblio_id => $biblionumber } )->next(); |
1202 |
|
1198 |
|
1203 |
return unless $hold; |
1199 |
return unless $hold; |
1204 |
|
1200 |
|
1205 |
my $already_on_shelf = $hold->found && $hold->found eq 'W'; |
1201 |
my $already_on_shelf = $hold->status eq 'waiting'; |
1206 |
|
1202 |
|
1207 |
$hold->itemnumber($itemnumber); |
1203 |
$hold->item_id($itemnumber); |
1208 |
|
1204 |
|
1209 |
if ($transferToDo) { |
1205 |
if ($transferToDo) { |
1210 |
$hold->set_transfer(); |
1206 |
$hold->set_transfer(); |
Lines 1214-1220
sub ModReserveAffect {
Link Here
|
1214 |
$hold->set_processing(); |
1210 |
$hold->set_processing(); |
1215 |
} else { |
1211 |
} else { |
1216 |
$hold->set_waiting($desk_id); |
1212 |
$hold->set_waiting($desk_id); |
1217 |
_koha_notify_reserve( $hold->reserve_id ) unless $already_on_shelf; |
1213 |
_koha_notify_reserve( $hold->id ) unless $already_on_shelf; |
1218 |
# Complete transfer if one exists |
1214 |
# Complete transfer if one exists |
1219 |
my $transfer = $hold->item->get_transfer; |
1215 |
my $transfer = $hold->item->get_transfer; |
1220 |
$transfer->receive if $transfer; |
1216 |
$transfer->receive if $transfer; |
Lines 1238-1246
sub ModReserveAffect {
Link Here
|
1238 |
AND q.holdingbranch = t.source_branchcode |
1234 |
AND q.holdingbranch = t.source_branchcode |
1239 |
WHERE t.reserve_id = ? |
1235 |
WHERE t.reserve_id = ? |
1240 |
}); |
1236 |
}); |
1241 |
$std->execute($hold->reserve_id); |
1237 |
$std->execute($hold->id); |
1242 |
|
1238 |
|
1243 |
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->get_from_storage->unblessed) ) |
1239 |
logaction( 'HOLDS', 'MODIFY', $hold->id, Dumper($hold->get_from_storage->unblessed) ) |
1244 |
if C4::Context->preference('HoldsLog'); |
1240 |
if C4::Context->preference('HoldsLog'); |
1245 |
|
1241 |
|
1246 |
return; |
1242 |
return; |
Lines 1257-1271
function to cancel reserv,check other reserves, and transfer document if it's ne
Link Here
|
1257 |
sub ModReserveCancelAll { |
1253 |
sub ModReserveCancelAll { |
1258 |
my $messages; |
1254 |
my $messages; |
1259 |
my $nextreservinfo; |
1255 |
my $nextreservinfo; |
1260 |
my ( $itemnumber, $borrowernumber, $cancellation_reason ) = @_; |
1256 |
my ( $item_id, $patron_id, $cancellation_reason ) = @_; |
1261 |
|
1257 |
|
1262 |
#step 1 : cancel the reservation |
1258 |
#step 1 : cancel the reservation |
1263 |
my $holds = Koha::Holds->search({ itemnumber => $itemnumber, borrowernumber => $borrowernumber }); |
1259 |
my $holds = Koha::Holds->search({ item_id => $item_id, patron_id => $patron_id }); |
1264 |
return unless $holds->count; |
1260 |
return unless $holds->count; |
1265 |
$holds->next->cancel({ cancellation_reason => $cancellation_reason }); |
1261 |
$holds->next->cancel({ cancellation_reason => $cancellation_reason }); |
1266 |
|
1262 |
|
1267 |
#step 2 launch the subroutine of the others reserves |
1263 |
#step 2 launch the subroutine of the others reserves |
1268 |
( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber); |
1264 |
( $messages, $nextreservinfo ) = GetOtherReserves($item_id); |
1269 |
|
1265 |
|
1270 |
return ( $messages, $nextreservinfo->{borrowernumber} ); |
1266 |
return ( $messages, $nextreservinfo->{borrowernumber} ); |
1271 |
} |
1267 |
} |
Lines 1279-1295
Reduce the values of queued list
Link Here
|
1279 |
=cut |
1275 |
=cut |
1280 |
|
1276 |
|
1281 |
sub ModReserveMinusPriority { |
1277 |
sub ModReserveMinusPriority { |
1282 |
my ( $itemnumber, $reserve_id ) = @_; |
1278 |
my ( $item_id, $reserve_id ) = @_; |
1283 |
|
1279 |
|
1284 |
#first step update the value of the first person on reserv |
1280 |
#first step update the value of the first person on reserv |
1285 |
my $dbh = C4::Context->dbh; |
1281 |
my $dbh = C4::Context->dbh; |
1286 |
my $query = " |
1282 |
my $query = " |
1287 |
UPDATE reserves |
1283 |
UPDATE holds |
1288 |
SET priority = 0 , itemnumber = ? |
1284 |
SET priority = 0 , item_id = ? |
1289 |
WHERE reserve_id = ? |
1285 |
WHERE id = ? |
1290 |
"; |
1286 |
"; |
1291 |
my $sth_upd = $dbh->prepare($query); |
1287 |
my $sth_upd = $dbh->prepare($query); |
1292 |
$sth_upd->execute( $itemnumber, $reserve_id ); |
1288 |
$sth_upd->execute( $item_id, $reserve_id ); |
1293 |
# second step update all others reserves |
1289 |
# second step update all others reserves |
1294 |
_FixPriority({ reserve_id => $reserve_id, rank => '0' }); |
1290 |
_FixPriority({ reserve_id => $reserve_id, rank => '0' }); |
1295 |
} |
1291 |
} |
Lines 1433-1440
sub AlterPriority {
Link Here
|
1433 |
my $hold = Koha::Holds->find( $reserve_id ); |
1429 |
my $hold = Koha::Holds->find( $reserve_id ); |
1434 |
return unless $hold; |
1430 |
return unless $hold; |
1435 |
|
1431 |
|
1436 |
if ( $hold->cancellationdate ) { |
1432 |
if ( $hold->completed_date and $hold->status eq 'cancelled' ) { |
1437 |
warn "I cannot alter the priority for reserve_id $reserve_id, the reserve has been cancelled (" . $hold->cancellationdate . ')'; |
1433 |
warn "I cannot alter the priority for reserve_id $reserve_id, the reserve has been cancelled (" . $hold->completed_date . ')'; |
1438 |
return; |
1434 |
return; |
1439 |
} |
1435 |
} |
1440 |
|
1436 |
|
Lines 1466-1472
sub ToggleLowestPriority {
Link Here
|
1466 |
|
1462 |
|
1467 |
my $dbh = C4::Context->dbh; |
1463 |
my $dbh = C4::Context->dbh; |
1468 |
|
1464 |
|
1469 |
my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?"); |
1465 |
my $sth = $dbh->prepare( "UPDATE holds SET lowest_priority = NOT lowest_priority WHERE id = ?"); |
1470 |
$sth->execute( $reserve_id ); |
1466 |
$sth->execute( $reserve_id ); |
1471 |
|
1467 |
|
1472 |
_FixPriority({ reserve_id => $reserve_id, rank => '999999' }); |
1468 |
_FixPriority({ reserve_id => $reserve_id, rank => '999999' }); |
Lines 1526-1534
sub SuspendAll {
Link Here
|
1526 |
return unless ( $borrowernumber || $biblionumber ); |
1522 |
return unless ( $borrowernumber || $biblionumber ); |
1527 |
|
1523 |
|
1528 |
my $params; |
1524 |
my $params; |
1529 |
$params->{found} = undef; |
1525 |
$params->{status} = 'placed'; |
1530 |
$params->{borrowernumber} = $borrowernumber if $borrowernumber; |
1526 |
$params->{patron_id} = $borrowernumber if $borrowernumber; |
1531 |
$params->{biblionumber} = $biblionumber if $biblionumber; |
1527 |
$params->{biblio_id} = $biblionumber if $biblionumber; |
1532 |
|
1528 |
|
1533 |
my @holds = Koha::Holds->search($params); |
1529 |
my @holds = Koha::Holds->search($params); |
1534 |
|
1530 |
|
Lines 1588-1602
sub _FixPriority {
Link Here
|
1588 |
my $hold; |
1584 |
my $hold; |
1589 |
if ( $reserve_id ) { |
1585 |
if ( $reserve_id ) { |
1590 |
$hold = Koha::Holds->find( $reserve_id ); |
1586 |
$hold = Koha::Holds->find( $reserve_id ); |
1591 |
if (!defined $hold){ |
|
|
1592 |
# may have already been checked out and hold fulfilled |
1593 |
$hold = Koha::Old::Holds->find( $reserve_id ); |
1594 |
} |
1595 |
return unless $hold; |
1587 |
return unless $hold; |
1596 |
} |
1588 |
} |
1597 |
|
1589 |
|
1598 |
unless ( $biblionumber ) { # FIXME This is a very weird API |
1590 |
unless ( $biblionumber ) { # FIXME This is a very weird API |
1599 |
$biblionumber = $hold->biblionumber; |
1591 |
$biblionumber = $hold->biblio_id; |
1600 |
} |
1592 |
} |
1601 |
|
1593 |
|
1602 |
if ( $rank eq "del" ) { # FIXME will crash if called without $hold |
1594 |
if ( $rank eq "del" ) { # FIXME will crash if called without $hold |
Lines 1606-1615
sub _FixPriority {
Link Here
|
1606 |
|
1598 |
|
1607 |
# make sure priority for waiting or in-transit items is 0 |
1599 |
# make sure priority for waiting or in-transit items is 0 |
1608 |
my $query = " |
1600 |
my $query = " |
1609 |
UPDATE reserves |
1601 |
UPDATE holds |
1610 |
SET priority = 0 |
1602 |
SET priority = 0 |
1611 |
WHERE reserve_id = ? |
1603 |
WHERE id = ? |
1612 |
AND found IN ('W', 'T', 'P') |
1604 |
AND status IN ('waiting', 'in_transit', 'processing') |
1613 |
"; |
1605 |
"; |
1614 |
my $sth = $dbh->prepare($query); |
1606 |
my $sth = $dbh->prepare($query); |
1615 |
$sth->execute( $reserve_id ); |
1607 |
$sth->execute( $reserve_id ); |
Lines 1618-1627
sub _FixPriority {
Link Here
|
1618 |
|
1610 |
|
1619 |
# get whats left |
1611 |
# get whats left |
1620 |
my $query = " |
1612 |
my $query = " |
1621 |
SELECT reserve_id, borrowernumber, reservedate |
1613 |
SELECT id |
1622 |
FROM reserves |
1614 |
FROM holds |
1623 |
WHERE biblionumber = ? |
1615 |
WHERE biblio_id = ? |
1624 |
AND ((found <> 'W' AND found <> 'T' AND found <> 'P') OR found IS NULL) |
1616 |
AND completed = 0 |
|
|
1617 |
AND status = 'placed' |
1625 |
ORDER BY priority ASC |
1618 |
ORDER BY priority ASC |
1626 |
"; |
1619 |
"; |
1627 |
my $sth = $dbh->prepare($query); |
1620 |
my $sth = $dbh->prepare($query); |
Lines 1635-1641
sub _FixPriority {
Link Here
|
1635 |
my $i; |
1628 |
my $i; |
1636 |
my $key = -1; # to allow for 0 to be a valid result |
1629 |
my $key = -1; # to allow for 0 to be a valid result |
1637 |
for ( $i = 0 ; $i < @priority ; $i++ ) { |
1630 |
for ( $i = 0 ; $i < @priority ; $i++ ) { |
1638 |
if ( $reserve_id && $reserve_id == $priority[$i]->{'reserve_id'} ) { |
1631 |
if ( $reserve_id && $reserve_id == $priority[$i]->{'id'} ) { |
1639 |
$key = $i; # save the index |
1632 |
$key = $i; # save the index |
1640 |
last; |
1633 |
last; |
1641 |
} |
1634 |
} |
Lines 1651-1675
sub _FixPriority {
Link Here
|
1651 |
|
1644 |
|
1652 |
# now fix the priority on those that are left.... |
1645 |
# now fix the priority on those that are left.... |
1653 |
$query = " |
1646 |
$query = " |
1654 |
UPDATE reserves |
1647 |
UPDATE holds |
1655 |
SET priority = ? |
1648 |
SET priority = ? |
1656 |
WHERE reserve_id = ? |
1649 |
WHERE id = ? |
1657 |
"; |
1650 |
"; |
1658 |
$sth = $dbh->prepare($query); |
1651 |
$sth = $dbh->prepare($query); |
1659 |
for ( my $j = 0 ; $j < @priority ; $j++ ) { |
1652 |
for ( my $j = 0 ; $j < @priority ; $j++ ) { |
1660 |
$sth->execute( |
1653 |
$sth->execute( |
1661 |
$j + 1, |
1654 |
$j + 1, |
1662 |
$priority[$j]->{'reserve_id'} |
1655 |
$priority[$j]->{'id'} |
1663 |
); |
1656 |
); |
1664 |
} |
1657 |
} |
1665 |
|
1658 |
|
1666 |
$sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" ); |
1659 |
$sth = $dbh->prepare( "SELECT id FROM holds WHERE lowest_priority = 1 ORDER BY priority" ); |
1667 |
$sth->execute(); |
1660 |
$sth->execute(); |
1668 |
|
1661 |
|
1669 |
unless ( $ignoreSetLowestRank ) { |
1662 |
unless ( $ignoreSetLowestRank ) { |
1670 |
while ( my $res = $sth->fetchrow_hashref() ) { |
1663 |
while ( my $res = $sth->fetchrow_hashref() ) { |
1671 |
_FixPriority({ |
1664 |
_FixPriority({ |
1672 |
reserve_id => $res->{'reserve_id'}, |
1665 |
reserve_id => $res->{'id'}, |
1673 |
rank => '999999', |
1666 |
rank => '999999', |
1674 |
ignoreSetLowestRank => 1 |
1667 |
ignoreSetLowestRank => 1 |
1675 |
}); |
1668 |
}); |
Lines 1706-1734
sub _Findgroupreserve {
Link Here
|
1706 |
# TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var. |
1699 |
# TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var. |
1707 |
# check for exact targeted match |
1700 |
# check for exact targeted match |
1708 |
my $item_level_target_query = qq{ |
1701 |
my $item_level_target_query = qq{ |
1709 |
SELECT reserves.biblionumber AS biblionumber, |
1702 |
SELECT holds.biblio_id AS biblio_id, |
1710 |
reserves.borrowernumber AS borrowernumber, |
1703 |
holds.patron_id AS patron_id, |
1711 |
reserves.reservedate AS reservedate, |
1704 |
holds.created_date AS created_date, |
1712 |
reserves.branchcode AS branchcode, |
1705 |
holds.pickup_library_id AS pickup_library_id, |
1713 |
reserves.cancellationdate AS cancellationdate, |
1706 |
holds.completed_date AS completed_date, |
1714 |
reserves.found AS found, |
1707 |
holds.status AS status, |
1715 |
reserves.reservenotes AS reservenotes, |
1708 |
holds.notes AS notes, |
1716 |
reserves.priority AS priority, |
1709 |
holds.priority AS priority, |
1717 |
reserves.timestamp AS timestamp, |
1710 |
holds.timestamp AS timestamp, |
1718 |
biblioitems.biblioitemnumber AS biblioitemnumber, |
1711 |
biblioitems.biblioitemnumber AS biblioitemnumber, |
1719 |
reserves.itemnumber AS itemnumber, |
1712 |
holds.item_id AS item_id, |
1720 |
reserves.reserve_id AS reserve_id, |
1713 |
holds.id AS id, |
1721 |
reserves.itemtype AS itemtype, |
1714 |
holds.item_type AS item_type, |
1722 |
reserves.non_priority AS non_priority |
1715 |
holds.non_priority AS non_priority |
1723 |
FROM reserves |
1716 |
FROM holds |
1724 |
JOIN biblioitems USING (biblionumber) |
1717 |
JOIN biblioitems ON (holds.biblio_id=biblioitems.biblionumber) |
1725 |
JOIN hold_fill_targets USING (reserve_id) |
1718 |
JOIN hold_fill_targets ON (holds.id=hold_fill_targets.reserve_id) |
1726 |
WHERE found IS NULL |
1719 |
WHERE status='placed' |
1727 |
AND priority > 0 |
1720 |
AND priority > 0 |
1728 |
AND item_level_request = 1 |
1721 |
AND completed = 0 |
1729 |
AND hold_fill_targets.itemnumber = ? |
1722 |
AND item_level = 1 |
1730 |
AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1723 |
AND item_id = ? |
1731 |
AND suspend = 0 |
1724 |
AND created_date <= DATE_ADD(NOW(),INTERVAL ? DAY) |
|
|
1725 |
AND suspended = 0 |
1732 |
ORDER BY priority |
1726 |
ORDER BY priority |
1733 |
}; |
1727 |
}; |
1734 |
my $sth = $dbh->prepare($item_level_target_query); |
1728 |
my $sth = $dbh->prepare($item_level_target_query); |
Lines 1736-1770
sub _Findgroupreserve {
Link Here
|
1736 |
my @results; |
1730 |
my @results; |
1737 |
if ( my $data = $sth->fetchrow_hashref ) { |
1731 |
if ( my $data = $sth->fetchrow_hashref ) { |
1738 |
push( @results, $data ) |
1732 |
push( @results, $data ) |
1739 |
unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ; |
1733 |
unless any{ $data->{patron_id} eq $_ } @$ignore_borrowers ; |
1740 |
} |
1734 |
} |
1741 |
return @results if @results; |
1735 |
return @results if @results; |
1742 |
|
1736 |
|
1743 |
# check for title-level targeted match |
1737 |
# check for title-level targeted match |
1744 |
my $title_level_target_query = qq{ |
1738 |
my $title_level_target_query = qq{ |
1745 |
SELECT reserves.biblionumber AS biblionumber, |
1739 |
SELECT holds.biblio_id AS biblio_id, |
1746 |
reserves.borrowernumber AS borrowernumber, |
1740 |
holds.patron_id AS patron_id, |
1747 |
reserves.reservedate AS reservedate, |
1741 |
holds.created_date AS created_date, |
1748 |
reserves.branchcode AS branchcode, |
1742 |
holds.pickup_library_id AS pickup_library_id, |
1749 |
reserves.cancellationdate AS cancellationdate, |
1743 |
holds.completed_date AS completed_date, |
1750 |
reserves.found AS found, |
1744 |
holds.status AS status, |
1751 |
reserves.reservenotes AS reservenotes, |
1745 |
holds.notes AS notes, |
1752 |
reserves.priority AS priority, |
1746 |
holds.priority AS priority, |
1753 |
reserves.timestamp AS timestamp, |
1747 |
holds.timestamp AS timestamp, |
1754 |
biblioitems.biblioitemnumber AS biblioitemnumber, |
1748 |
biblioitems.biblioitemnumber AS biblioitemnumber, |
1755 |
reserves.itemnumber AS itemnumber, |
1749 |
holds.item_id AS item_id, |
1756 |
reserves.reserve_id AS reserve_id, |
1750 |
holds.id AS id, |
1757 |
reserves.itemtype AS itemtype, |
1751 |
holds.item_type AS item_type, |
1758 |
reserves.non_priority AS non_priority |
1752 |
holds.non_priority AS non_priority |
1759 |
FROM reserves |
1753 |
FROM holds |
1760 |
JOIN biblioitems USING (biblionumber) |
1754 |
JOIN biblioitems ON (holds.biblio_id=biblioitems.biblionumber) |
1761 |
JOIN hold_fill_targets USING (reserve_id) |
1755 |
JOIN hold_fill_targets ON (holds.id=hold_fill_targets.reserve_id) |
1762 |
WHERE found IS NULL |
1756 |
WHERE status='placed' |
1763 |
AND priority > 0 |
1757 |
AND priority > 0 |
1764 |
AND item_level_request = 0 |
1758 |
AND completed = 0 |
|
|
1759 |
AND item_level = 0 |
1765 |
AND hold_fill_targets.itemnumber = ? |
1760 |
AND hold_fill_targets.itemnumber = ? |
1766 |
AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1761 |
AND created_date <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1767 |
AND suspend = 0 |
1762 |
AND suspended = 0 |
1768 |
ORDER BY priority |
1763 |
ORDER BY priority |
1769 |
}; |
1764 |
}; |
1770 |
$sth = $dbh->prepare($title_level_target_query); |
1765 |
$sth = $dbh->prepare($title_level_target_query); |
Lines 1772-1801
sub _Findgroupreserve {
Link Here
|
1772 |
@results = (); |
1767 |
@results = (); |
1773 |
if ( my $data = $sth->fetchrow_hashref ) { |
1768 |
if ( my $data = $sth->fetchrow_hashref ) { |
1774 |
push( @results, $data ) |
1769 |
push( @results, $data ) |
1775 |
unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ; |
1770 |
unless any{ $data->{patron_id} eq $_ } @$ignore_borrowers ; |
1776 |
} |
1771 |
} |
1777 |
return @results if @results; |
1772 |
return @results if @results; |
1778 |
|
1773 |
|
1779 |
my $query = qq{ |
1774 |
my $query = qq{ |
1780 |
SELECT reserves.biblionumber AS biblionumber, |
1775 |
SELECT holds.biblio_id AS biblio_id, |
1781 |
reserves.borrowernumber AS borrowernumber, |
1776 |
holds.patron_id AS patron_id, |
1782 |
reserves.reservedate AS reservedate, |
1777 |
holds.created_date AS created_date, |
1783 |
reserves.waitingdate AS waitingdate, |
1778 |
holds.waiting_date AS waiting_date, |
1784 |
reserves.branchcode AS branchcode, |
1779 |
holds.pickup_library_id AS pickup_library_id, |
1785 |
reserves.cancellationdate AS cancellationdate, |
1780 |
holds.completed_date AS completed_date, |
1786 |
reserves.found AS found, |
1781 |
holds.status AS status, |
1787 |
reserves.reservenotes AS reservenotes, |
1782 |
holds.notes AS notes, |
1788 |
reserves.priority AS priority, |
1783 |
holds.priority AS priority, |
1789 |
reserves.timestamp AS timestamp, |
1784 |
holds.timestamp AS timestamp, |
1790 |
reserves.itemnumber AS itemnumber, |
1785 |
holds.item_id AS item_id, |
1791 |
reserves.reserve_id AS reserve_id, |
1786 |
holds.id AS id, |
1792 |
reserves.itemtype AS itemtype, |
1787 |
holds.item_type AS item_type, |
1793 |
reserves.non_priority AS non_priority |
1788 |
holds.non_priority AS non_priority |
1794 |
FROM reserves |
1789 |
FROM holds |
1795 |
WHERE reserves.biblionumber = ? |
1790 |
WHERE holds.biblio_id = ? |
1796 |
AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?) |
1791 |
AND (holds.item_id IS NULL OR holds.item_id = ?) |
1797 |
AND reserves.reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1792 |
AND holds.created_date <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1798 |
AND suspend = 0 |
1793 |
AND suspended = 0 |
|
|
1794 |
AND completed = 0 |
1799 |
ORDER BY priority |
1795 |
ORDER BY priority |
1800 |
}; |
1796 |
}; |
1801 |
$sth = $dbh->prepare($query); |
1797 |
$sth = $dbh->prepare($query); |
Lines 1803-1809
sub _Findgroupreserve {
Link Here
|
1803 |
@results = (); |
1799 |
@results = (); |
1804 |
while ( my $data = $sth->fetchrow_hashref ) { |
1800 |
while ( my $data = $sth->fetchrow_hashref ) { |
1805 |
push( @results, $data ) |
1801 |
push( @results, $data ) |
1806 |
unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ; |
1802 |
unless any{ $data->{patron_id} eq $_ } @$ignore_borrowers ; |
1807 |
} |
1803 |
} |
1808 |
return @results; |
1804 |
return @results; |
1809 |
} |
1805 |
} |
Lines 1839-1845
The following tables are availalbe witin the notice:
Link Here
|
1839 |
sub _koha_notify_reserve { |
1835 |
sub _koha_notify_reserve { |
1840 |
my $reserve_id = shift; |
1836 |
my $reserve_id = shift; |
1841 |
my $hold = Koha::Holds->find($reserve_id); |
1837 |
my $hold = Koha::Holds->find($reserve_id); |
1842 |
my $borrowernumber = $hold->borrowernumber; |
1838 |
my $borrowernumber = $hold->patron_id; |
1843 |
|
1839 |
|
1844 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
1840 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
1845 |
|
1841 |
|
Lines 1851-1871
sub _koha_notify_reserve {
Link Here
|
1851 |
message_name => 'Hold_Filled' |
1847 |
message_name => 'Hold_Filled' |
1852 |
} ); |
1848 |
} ); |
1853 |
|
1849 |
|
1854 |
my $library = Koha::Libraries->find( $hold->branchcode ); |
1850 |
my $library = Koha::Libraries->find( $hold->pickup_library_id ); |
1855 |
my $admin_email_address = $library->from_email_address; |
1851 |
my $admin_email_address = $library->from_email_address; |
1856 |
$library = $library->unblessed; |
1852 |
$library = $library->unblessed; |
1857 |
|
1853 |
|
1858 |
my %letter_params = ( |
1854 |
my %letter_params = ( |
1859 |
module => 'reserves', |
1855 |
module => 'reserves', |
1860 |
branchcode => $hold->branchcode, |
1856 |
branchcode => $hold->pickup_library_id, |
1861 |
lang => $patron->lang, |
1857 |
lang => $patron->lang, |
1862 |
tables => { |
1858 |
tables => { |
1863 |
'branches' => $library, |
1859 |
'branches' => $library, |
1864 |
'borrowers' => $patron->unblessed, |
1860 |
'borrowers' => $patron->unblessed, |
1865 |
'biblio' => $hold->biblionumber, |
1861 |
'biblio' => $hold->biblio_id, |
1866 |
'biblioitems' => $hold->biblionumber, |
1862 |
'biblioitems' => $hold->biblio_id, |
1867 |
'reserves' => $hold->unblessed, |
1863 |
'holds' => $hold->unblessed, |
1868 |
'items' => $hold->itemnumber, |
1864 |
'items' => $hold->item_id, |
1869 |
}, |
1865 |
}, |
1870 |
); |
1866 |
); |
1871 |
|
1867 |
|
Lines 1929-1935
sub _ShiftPriorityByDateAndPriority {
Link Here
|
1929 |
my ( $biblio, $resdate, $new_priority ) = @_; |
1925 |
my ( $biblio, $resdate, $new_priority ) = @_; |
1930 |
|
1926 |
|
1931 |
my $dbh = C4::Context->dbh; |
1927 |
my $dbh = C4::Context->dbh; |
1932 |
my $query = "SELECT priority FROM reserves WHERE biblionumber = ? AND ( reservedate > ? OR priority > ? ) ORDER BY priority ASC LIMIT 1"; |
1928 |
my $query = "SELECT priority FROM holds WHERE biblio_id = ? AND ( created_date > ? OR priority > ? ) AND completed = 0 ORDER BY priority ASC LIMIT 1"; |
1933 |
my $sth = $dbh->prepare( $query ); |
1929 |
my $sth = $dbh->prepare( $query ); |
1934 |
$sth->execute( $biblio, $resdate, $new_priority ); |
1930 |
$sth->execute( $biblio, $resdate, $new_priority ); |
1935 |
my $min_priority = $sth->fetchrow; |
1931 |
my $min_priority = $sth->fetchrow; |
Lines 1937-1956
sub _ShiftPriorityByDateAndPriority {
Link Here
|
1937 |
$new_priority = $min_priority if ( $min_priority ); |
1933 |
$new_priority = $min_priority if ( $min_priority ); |
1938 |
|
1934 |
|
1939 |
# Shift the priority up by one; works in conjunction with the next SQL statement |
1935 |
# Shift the priority up by one; works in conjunction with the next SQL statement |
1940 |
$query = "UPDATE reserves |
1936 |
$query = "UPDATE holds |
1941 |
SET priority = priority+1 |
1937 |
SET priority = priority+1 |
1942 |
WHERE biblionumber = ? |
1938 |
WHERE biblio_id = ? |
1943 |
AND borrowernumber = ? |
1939 |
AND patron_id = ? |
1944 |
AND reservedate = ? |
1940 |
AND created_date = ? |
1945 |
AND found IS NULL"; |
1941 |
AND status = 'placed'"; |
1946 |
my $sth_update = $dbh->prepare( $query ); |
1942 |
my $sth_update = $dbh->prepare( $query ); |
1947 |
|
1943 |
|
1948 |
# Select all reserves for the biblio with priority greater than $new_priority, and order greatest to least |
1944 |
# Select all reserves for the biblio with priority greater than $new_priority, and order greatest to least |
1949 |
$query = "SELECT borrowernumber, reservedate FROM reserves WHERE priority >= ? AND biblionumber = ? ORDER BY priority DESC"; |
1945 |
$query = "SELECT patron_id, created_date FROM holds WHERE priority >= ? AND biblio_id = ? ORDER BY priority DESC"; |
1950 |
$sth = $dbh->prepare( $query ); |
1946 |
$sth = $dbh->prepare( $query ); |
1951 |
$sth->execute( $new_priority, $biblio ); |
1947 |
$sth->execute( $new_priority, $biblio ); |
1952 |
while ( my $row = $sth->fetchrow_hashref ) { |
1948 |
while ( my $row = $sth->fetchrow_hashref ) { |
1953 |
$sth_update->execute( $biblio, $row->{borrowernumber}, $row->{reservedate} ); |
1949 |
$sth_update->execute( $biblio, $row->{patron_id}, $row->{created_date} ); |
1954 |
} |
1950 |
} |
1955 |
|
1951 |
|
1956 |
return $new_priority; # so the caller knows what priority they wind up receiving |
1952 |
return $new_priority; # so the caller knows what priority they wind up receiving |
Lines 1974-1982
sub MoveReserve {
Link Here
|
1974 |
my ( $restype, $res, undef ) = CheckReserves( $itemnumber, undef, $lookahead ); |
1970 |
my ( $restype, $res, undef ) = CheckReserves( $itemnumber, undef, $lookahead ); |
1975 |
return unless $res; |
1971 |
return unless $res; |
1976 |
|
1972 |
|
1977 |
my $biblionumber = $res->{biblionumber}; |
1973 |
my $biblionumber = $res->{biblio_id}; |
1978 |
|
1974 |
|
1979 |
if ($res->{borrowernumber} == $borrowernumber) { |
1975 |
if ($res->{patron_id} == $borrowernumber) { |
1980 |
ModReserveFill($res); |
1976 |
ModReserveFill($res); |
1981 |
} |
1977 |
} |
1982 |
else { |
1978 |
else { |
Lines 1985-1992
sub MoveReserve {
Link Here
|
1985 |
# Find this item in the reserves |
1981 |
# Find this item in the reserves |
1986 |
|
1982 |
|
1987 |
my $borr_res = Koha::Holds->search({ |
1983 |
my $borr_res = Koha::Holds->search({ |
1988 |
borrowernumber => $borrowernumber, |
1984 |
patron_id => $borrowernumber, |
1989 |
biblionumber => $biblionumber, |
1985 |
biblio_id => $biblionumber, |
1990 |
},{ |
1986 |
},{ |
1991 |
order_by => 'priority' |
1987 |
order_by => 'priority' |
1992 |
})->next(); |
1988 |
})->next(); |
Lines 2000-2006
sub MoveReserve {
Link Here
|
2000 |
RevertWaitingStatus({ itemnumber => $itemnumber }); |
1996 |
RevertWaitingStatus({ itemnumber => $itemnumber }); |
2001 |
} |
1997 |
} |
2002 |
elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item |
1998 |
elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item |
2003 |
my $hold = Koha::Holds->find( $res->{reserve_id} ); |
1999 |
my $hold = Koha::Holds->find( $res->{id} ); |
2004 |
$hold->cancel; |
2000 |
$hold->cancel; |
2005 |
} |
2001 |
} |
2006 |
} |
2002 |
} |
Lines 2017-2049
This shifts the holds from C<$from_biblio> to C<$to_biblio> and reorders them by
Link Here
|
2017 |
sub MergeHolds { |
2013 |
sub MergeHolds { |
2018 |
my ( $dbh, $to_biblio, $from_biblio ) = @_; |
2014 |
my ( $dbh, $to_biblio, $from_biblio ) = @_; |
2019 |
my $sth = $dbh->prepare( |
2015 |
my $sth = $dbh->prepare( |
2020 |
"SELECT count(*) as reserve_count FROM reserves WHERE biblionumber = ?" |
2016 |
"SELECT count(*) as reserve_count FROM holds WHERE biblio_id = ? AND completed = 0" |
2021 |
); |
2017 |
); |
2022 |
$sth->execute($from_biblio); |
2018 |
$sth->execute($from_biblio); |
2023 |
if ( my $data = $sth->fetchrow_hashref() ) { |
2019 |
if ( my $data = $sth->fetchrow_hashref() ) { |
2024 |
|
2020 |
|
2025 |
# holds exist on old record, if not we don't need to do anything |
2021 |
# holds exist on old record, if not we don't need to do anything |
2026 |
$sth = $dbh->prepare( |
2022 |
$sth = $dbh->prepare( |
2027 |
"UPDATE reserves SET biblionumber = ? WHERE biblionumber = ?"); |
2023 |
"UPDATE holds SET biblio_id = ? WHERE biblio_id = ?"); |
2028 |
$sth->execute( $to_biblio, $from_biblio ); |
2024 |
$sth->execute( $to_biblio, $from_biblio ); |
2029 |
|
2025 |
|
2030 |
# Reorder by date |
2026 |
# Reorder by date |
2031 |
# don't reorder those already waiting |
2027 |
# don't reorder those already waiting |
2032 |
|
2028 |
|
2033 |
$sth = $dbh->prepare( |
2029 |
$sth = $dbh->prepare( |
2034 |
"SELECT * FROM reserves WHERE biblionumber = ? AND (found NOT IN ('W', 'T', 'P') OR found is NULL) ORDER BY reservedate ASC" |
2030 |
"SELECT id FROM holds WHERE biblio_id = ? AND status = 'placed' AND completed = 0 ORDER BY created_date ASC" |
2035 |
); |
2031 |
); |
2036 |
my $upd_sth = $dbh->prepare( |
2032 |
my $upd_sth = $dbh->prepare( |
2037 |
"UPDATE reserves SET priority = ? WHERE biblionumber = ? AND borrowernumber = ? |
2033 |
"UPDATE holds SET priority = ? WHERE id = ? " |
2038 |
AND reservedate = ? AND (itemnumber = ? or itemnumber is NULL) " |
|
|
2039 |
); |
2034 |
); |
2040 |
$sth->execute( $to_biblio ); |
2035 |
$sth->execute( $to_biblio ); |
2041 |
my $priority = 1; |
2036 |
my $priority = 1; |
2042 |
while ( my $reserve = $sth->fetchrow_hashref() ) { |
2037 |
while ( my $reserve = $sth->fetchrow_hashref() ) { |
2043 |
$upd_sth->execute( |
2038 |
$upd_sth->execute( |
2044 |
$priority, $to_biblio, |
2039 |
$priority, |
2045 |
$reserve->{'borrowernumber'}, $reserve->{'reservedate'}, |
2040 |
$reserve->{'id'} |
2046 |
$reserve->{'itemnumber'} |
|
|
2047 |
); |
2041 |
); |
2048 |
$priority++; |
2042 |
$priority++; |
2049 |
} |
2043 |
} |
Lines 2066-2101
sub MergeHolds {
Link Here
|
2066 |
|
2060 |
|
2067 |
sub RevertWaitingStatus { |
2061 |
sub RevertWaitingStatus { |
2068 |
my ( $params ) = @_; |
2062 |
my ( $params ) = @_; |
2069 |
my $itemnumber = $params->{'itemnumber'}; |
2063 |
my $item_id = $params->{'itemnumber'}; |
2070 |
|
2064 |
|
2071 |
return unless ( $itemnumber ); |
2065 |
return unless ( $item_id ); |
2072 |
|
|
|
2073 |
my $dbh = C4::Context->dbh; |
2074 |
|
2066 |
|
2075 |
## Get the waiting reserve we want to revert |
2067 |
## Get the waiting reserve we want to revert |
2076 |
my $hold = Koha::Holds->search( |
2068 |
my $hold = Koha::Holds->search( |
2077 |
{ |
2069 |
{ |
2078 |
itemnumber => $itemnumber, |
2070 |
item_id => $item_id, |
2079 |
found => { not => undef }, |
2071 |
status => 'waiting', |
2080 |
} |
2072 |
} |
2081 |
)->next; |
2073 |
)->next; |
2082 |
|
2074 |
|
2083 |
## Increment the priority of all other non-waiting |
2075 |
## Increment the priority of all other non-waiting |
2084 |
## reserves for this bib record |
2076 |
## reserves for this bib record |
2085 |
my $holds = Koha::Holds->search({ biblionumber => $hold->biblionumber, priority => { '>' => 0 } }) |
2077 |
my $holds = Koha::Holds->search({ biblio_id => $hold->biblio_id, priority => { '>' => 0 } }) |
2086 |
->update({ priority => \'priority + 1' }, { no_triggers => 1 }); |
2078 |
->update({ priority => \'priority + 1' }, { no_triggers => 1 }); |
2087 |
|
2079 |
|
2088 |
## Fix up the currently waiting reserve |
2080 |
## Fix up the currently waiting reserve |
2089 |
$hold->set( |
2081 |
$hold->set( |
2090 |
{ |
2082 |
{ |
2091 |
priority => 1, |
2083 |
priority => 1, |
2092 |
found => undef, |
2084 |
status => 'placed', |
2093 |
waitingdate => undef, |
2085 |
waiting_date => undef, |
2094 |
itemnumber => $hold->item_level_hold ? $hold->itemnumber : undef, |
2086 |
item_id => $hold->item_level ? $hold->item_id : undef, |
2095 |
} |
2087 |
} |
2096 |
)->store(); |
2088 |
)->store(); |
2097 |
|
2089 |
|
2098 |
_FixPriority( { biblionumber => $hold->biblionumber } ); |
2090 |
_FixPriority( { biblionumber => $hold->biblio_id } ); |
2099 |
|
2091 |
|
2100 |
return $hold; |
2092 |
return $hold; |
2101 |
} |
2093 |
} |
Lines 2128-2154
available within the slip:
Link Here
|
2128 |
|
2120 |
|
2129 |
sub ReserveSlip { |
2121 |
sub ReserveSlip { |
2130 |
my ($args) = @_; |
2122 |
my ($args) = @_; |
2131 |
my $branchcode = $args->{branchcode}; |
2123 |
my $branchcode = $args->{branchcode}; |
2132 |
my $reserve_id = $args->{reserve_id}; |
2124 |
my $reserve_id = $args->{reserve_id}; |
2133 |
|
2125 |
|
2134 |
my $hold = Koha::Holds->find($reserve_id); |
2126 |
my $hold = Koha::Holds->find($reserve_id); |
2135 |
return unless $hold; |
2127 |
return unless $hold; |
2136 |
|
2128 |
|
2137 |
my $patron = $hold->borrower; |
2129 |
my $patron = $hold->patron; |
2138 |
my $reserve = $hold->unblessed; |
|
|
2139 |
|
2130 |
|
2140 |
return C4::Letters::GetPreparedLetter ( |
2131 |
return C4::Letters::GetPreparedLetter( |
2141 |
module => 'circulation', |
2132 |
module => 'circulation', |
2142 |
letter_code => 'HOLD_SLIP', |
2133 |
letter_code => 'HOLD_SLIP', |
2143 |
branchcode => $branchcode, |
2134 |
branchcode => $branchcode, |
2144 |
lang => $patron->lang, |
2135 |
lang => $patron->lang, |
2145 |
tables => { |
2136 |
tables => { |
2146 |
'reserves' => $reserve, |
2137 |
'holds' => $hold->unblessed, |
2147 |
'branches' => $reserve->{branchcode}, |
2138 |
'branches' => $hold->pickup_library_id, |
2148 |
'borrowers' => $reserve->{borrowernumber}, |
2139 |
'borrowers' => $hold->patron_id, |
2149 |
'biblio' => $reserve->{biblionumber}, |
2140 |
'biblio' => $hold->biblio_id, |
2150 |
'biblioitems' => $reserve->{biblionumber}, |
2141 |
'biblioitems' => $hold->biblio_id, |
2151 |
'items' => $reserve->{itemnumber}, |
2142 |
'items' => $hold->item_id, |
2152 |
}, |
2143 |
}, |
2153 |
); |
2144 |
); |
2154 |
} |
2145 |
} |
Lines 2202-2218
sub CalculatePriority {
Link Here
|
2202 |
my ( $biblionumber, $resdate ) = @_; |
2193 |
my ( $biblionumber, $resdate ) = @_; |
2203 |
|
2194 |
|
2204 |
my $sql = q{ |
2195 |
my $sql = q{ |
2205 |
SELECT COUNT(*) FROM reserves |
2196 |
SELECT COUNT(*) FROM holds |
2206 |
WHERE biblionumber = ? |
2197 |
WHERE biblio_id = ? |
2207 |
AND priority > 0 |
2198 |
AND priority > 0 |
2208 |
AND (found IS NULL OR found = '') |
2199 |
AND status='placed' |
2209 |
}; |
2200 |
}; |
2210 |
#skip found==W or found==T or found==P (waiting, transit or processing holds) |
2201 |
#skip status==waiting or status==in_transit or status==processing |
2211 |
if( $resdate ) { |
2202 |
if( $resdate ) { |
2212 |
$sql.= ' AND ( reservedate <= ? )'; |
2203 |
$sql.= ' AND ( created_date <= ? )'; |
2213 |
} |
2204 |
} |
2214 |
else { |
2205 |
else { |
2215 |
$sql.= ' AND ( reservedate < NOW() )'; |
2206 |
$sql.= ' AND ( created_date < NOW() )'; |
2216 |
} |
2207 |
} |
2217 |
my $dbh = C4::Context->dbh(); |
2208 |
my $dbh = C4::Context->dbh(); |
2218 |
my @row = $dbh->selectrow_array( |
2209 |
my @row = $dbh->selectrow_array( |
Lines 2226-2251
sub CalculatePriority {
Link Here
|
2226 |
|
2217 |
|
2227 |
=head2 IsItemOnHoldAndFound |
2218 |
=head2 IsItemOnHoldAndFound |
2228 |
|
2219 |
|
2229 |
my $bool = IsItemFoundHold( $itemnumber ); |
2220 |
my $bool = IsItemFoundHold( $item_id ); |
2230 |
|
2221 |
|
2231 |
Returns true if the item is currently on hold |
2222 |
Returns true if the item is currently on hold |
2232 |
and that hold has a non-null found status ( W, T, etc. ) |
2223 |
and that hold has a status of in_transit, processing |
|
|
2224 |
or waiting. |
2233 |
|
2225 |
|
2234 |
=cut |
2226 |
=cut |
2235 |
|
2227 |
|
2236 |
sub IsItemOnHoldAndFound { |
2228 |
sub IsItemOnHoldAndFound { |
2237 |
my ($itemnumber) = @_; |
2229 |
my ($item_id) = @_; |
2238 |
|
|
|
2239 |
my $rs = Koha::Database->new()->schema()->resultset('Reserve'); |
2240 |
|
2230 |
|
2241 |
my $found = $rs->count( |
2231 |
return Koha::Holds->search( |
2242 |
{ |
2232 |
{ |
2243 |
itemnumber => $itemnumber, |
2233 |
item_id => $item_id, |
2244 |
found => { '!=' => undef } |
2234 |
status => [ 'in_transit', 'processing', 'waiting' ], |
|
|
2235 |
completed => 0 |
2245 |
} |
2236 |
} |
2246 |
); |
2237 |
)->count; |
2247 |
|
|
|
2248 |
return $found; |
2249 |
} |
2238 |
} |
2250 |
|
2239 |
|
2251 |
=head2 GetMaxPatronHoldsForRecord |
2240 |
=head2 GetMaxPatronHoldsForRecord |