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