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 |
|
46 |
|
49 |
use Carp; |
47 |
use Carp; |
Lines 170-176
The following tables are available witin the HOLDPLACED message:
Link Here
|
170 |
reserves |
168 |
reserves |
171 |
|
169 |
|
172 |
=cut |
170 |
=cut |
173 |
|
171 |
use Carp::Always; |
174 |
sub AddReserve { |
172 |
sub AddReserve { |
175 |
my ($params) = @_; |
173 |
my ($params) = @_; |
176 |
my $branch = $params->{branchcode}; |
174 |
my $branch = $params->{branchcode}; |
Lines 212-218
sub AddReserve {
Link Here
|
212 |
&& !$item->current_holds->count ) |
210 |
&& !$item->current_holds->count ) |
213 |
{ |
211 |
{ |
214 |
$priority = 0; |
212 |
$priority = 0; |
215 |
$found = 'W'; |
213 |
$found = 'waiting'; |
216 |
} |
214 |
} |
217 |
} |
215 |
} |
218 |
|
216 |
|
Lines 225-231
sub AddReserve {
Link Here
|
225 |
my $waitingdate; |
223 |
my $waitingdate; |
226 |
|
224 |
|
227 |
# If the reserv had the waiting status, we had the value of the resdate |
225 |
# If the reserv had the waiting status, we had the value of the resdate |
228 |
if ( $found && $found eq 'W' ) { |
226 |
if ( $found && $found eq 'waiting' ) { |
229 |
$waitingdate = $resdate; |
227 |
$waitingdate = $resdate; |
230 |
} |
228 |
} |
231 |
|
229 |
|
Lines 235-255
sub AddReserve {
Link Here
|
235 |
# updates take place here |
233 |
# updates take place here |
236 |
my $hold = Koha::Hold->new( |
234 |
my $hold = Koha::Hold->new( |
237 |
{ |
235 |
{ |
238 |
borrowernumber => $borrowernumber, |
236 |
patron_id => $borrowernumber, |
239 |
biblionumber => $biblionumber, |
237 |
biblio_id => $biblionumber, |
240 |
reservedate => $resdate, |
238 |
placing_date => $resdate, |
241 |
branchcode => $branch, |
239 |
pickup_library_id => $branch, |
242 |
priority => $priority, |
240 |
priority => $priority, |
243 |
reservenotes => $notes, |
241 |
notes => $notes, |
244 |
itemnumber => $checkitem, |
242 |
item_id => $checkitem, |
245 |
found => $found, |
243 |
status => $found, |
246 |
waitingdate => $waitingdate, |
244 |
waiting_date => $waitingdate, |
247 |
expirationdate => $expdate, |
245 |
expiration_date => $expdate, |
248 |
itemtype => $itemtype, |
246 |
item_type => $itemtype, |
249 |
item_level_hold => $checkitem ? 1 : 0, |
247 |
item_level => $checkitem ? 1 : 0, |
250 |
} |
248 |
} |
251 |
)->store(); |
249 |
)->store(); |
252 |
$hold->set_waiting() if $found && $found eq 'W'; |
250 |
$hold->set_waiting() if $found && $found eq 'waiting'; |
253 |
|
251 |
|
254 |
logaction( 'HOLDS', 'CREATE', $hold->id, Dumper($hold->unblessed) ) |
252 |
logaction( 'HOLDS', 'CREATE', $hold->id, Dumper($hold->unblessed) ) |
255 |
if C4::Context->preference('HoldsLog'); |
253 |
if C4::Context->preference('HoldsLog'); |
Lines 373-393
sub CanItemBeReserved {
Link Here
|
373 |
|
371 |
|
374 |
# Check that the patron doesn't have an item level hold on this item already |
372 |
# Check that the patron doesn't have an item level hold on this item already |
375 |
return { status =>'itemAlreadyOnHold' } |
373 |
return { status =>'itemAlreadyOnHold' } |
376 |
if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count(); |
374 |
if Koha::Holds->search( { patron_id => $borrowernumber, item_id => $itemnumber, completed=>0 } )->count(); |
377 |
|
375 |
|
378 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
376 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
379 |
|
377 |
|
380 |
my $querycount = q{ |
378 |
my $querycount = q{ |
381 |
SELECT count(*) AS count |
379 |
SELECT count(*) AS count |
382 |
FROM reserves |
380 |
FROM holds |
383 |
LEFT JOIN items USING (itemnumber) |
381 |
LEFT JOIN items ON (holds.item_id=items.itemnumber) |
384 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
382 |
LEFT JOIN biblioitems ON (holds.biblio_id=biblioitems.biblionumber) |
385 |
LEFT JOIN borrowers USING (borrowernumber) |
383 |
LEFT JOIN borrowers ON (holds.patron_id=borrowers.borrowernumber) |
386 |
WHERE borrowernumber = ? |
384 |
WHERE completed = 0 and borrowernumber = ? |
387 |
}; |
385 |
}; |
388 |
|
386 |
|
389 |
my $branchcode = ""; |
387 |
my $branchcode = ""; |
390 |
my $branchfield = "reserves.branchcode"; |
388 |
my $branchfield = "holds.pickup_library_id"; |
391 |
|
389 |
|
392 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
390 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
393 |
$branchfield = "items.homebranch"; |
391 |
$branchfield = "items.homebranch"; |
Lines 411-418
sub CanItemBeReserved {
Link Here
|
411 |
|
409 |
|
412 |
my $holds = Koha::Holds->search( |
410 |
my $holds = Koha::Holds->search( |
413 |
{ |
411 |
{ |
414 |
borrowernumber => $borrowernumber, |
412 |
patron_id => $borrowernumber, |
415 |
biblionumber => $item->biblionumber, |
413 |
biblio_id => $item->biblionumber, |
416 |
} |
414 |
} |
417 |
); |
415 |
); |
418 |
if ( defined $holds_per_record && $holds_per_record ne '' |
416 |
if ( defined $holds_per_record && $holds_per_record ne '' |
Lines 421-428
sub CanItemBeReserved {
Link Here
|
421 |
} |
419 |
} |
422 |
|
420 |
|
423 |
my $today_holds = Koha::Holds->search({ |
421 |
my $today_holds = Koha::Holds->search({ |
424 |
borrowernumber => $borrowernumber, |
422 |
patron_id => $borrowernumber, |
425 |
reservedate => dt_from_string->date |
423 |
placing_date => dt_from_string->date |
426 |
}); |
424 |
}); |
427 |
|
425 |
|
428 |
if ( defined $holds_per_day && $holds_per_day ne '' |
426 |
if ( defined $holds_per_day && $holds_per_day ne '' |
Lines 474-480
sub CanItemBeReserved {
Link Here
|
474 |
if ( $rule && defined( $rule->rule_value ) && $rule->rule_value ne '' ) { |
472 |
if ( $rule && defined( $rule->rule_value ) && $rule->rule_value ne '' ) { |
475 |
my $total_holds_count = Koha::Holds->search( |
473 |
my $total_holds_count = Koha::Holds->search( |
476 |
{ |
474 |
{ |
477 |
borrowernumber => $borrower->{borrowernumber} |
475 |
patron_id => $borrower->{borrowernumber} |
478 |
} |
476 |
} |
479 |
)->count(); |
477 |
)->count(); |
480 |
|
478 |
|
Lines 554-561
sub CanReserveBeCanceledFromOpac {
Link Here
|
554 |
return unless $reserve_id and $borrowernumber; |
552 |
return unless $reserve_id and $borrowernumber; |
555 |
my $reserve = Koha::Holds->find($reserve_id); |
553 |
my $reserve = Koha::Holds->find($reserve_id); |
556 |
|
554 |
|
557 |
return 0 unless $reserve->borrowernumber == $borrowernumber; |
555 |
return 0 if $reserve->completed; |
558 |
return 0 if ( $reserve->found eq 'W' ) or ( $reserve->found eq 'T' ); |
556 |
return 0 unless $reserve->patron_id == $borrowernumber; |
|
|
557 |
return 0 if ( $reserve->status eq 'waiting' ) or ( $reserve->status eq 'in_transit' ); |
559 |
|
558 |
|
560 |
return 1; |
559 |
return 1; |
561 |
|
560 |
|
Lines 576-594
sub GetOtherReserves {
Link Here
|
576 |
my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber); |
575 |
my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber); |
577 |
if ($checkreserves) { |
576 |
if ($checkreserves) { |
578 |
my $item = Koha::Items->find($itemnumber); |
577 |
my $item = Koha::Items->find($itemnumber); |
579 |
if ( $item->holdingbranch ne $checkreserves->{'branchcode'} ) { |
578 |
if ( $item->holdingbranch ne $checkreserves->{pickup_library_id} ) { |
580 |
$messages->{'transfert'} = $checkreserves->{'branchcode'}; |
579 |
$messages->{'transfert'} = $checkreserves->{pickup_library_id}; |
581 |
#minus priorities of others reservs |
580 |
#minus priorities of others reservs |
582 |
ModReserveMinusPriority( |
581 |
ModReserveMinusPriority( |
583 |
$itemnumber, |
582 |
$itemnumber, |
584 |
$checkreserves->{'reserve_id'}, |
583 |
$checkreserves->{id}, |
585 |
); |
584 |
); |
586 |
|
585 |
|
587 |
#launch the subroutine dotransfer |
586 |
#launch the subroutine dotransfer |
588 |
C4::Items::ModItemTransfer( |
587 |
C4::Items::ModItemTransfer( |
589 |
$itemnumber, |
588 |
$itemnumber, |
590 |
$item->holdingbranch, |
589 |
$item->holdingbranch, |
591 |
$checkreserves->{'branchcode'}, |
590 |
$checkreserves->{pickup_library_id}, |
592 |
'Reserve' |
591 |
'Reserve' |
593 |
), |
592 |
), |
594 |
; |
593 |
; |
Lines 599-610
sub GetOtherReserves {
Link Here
|
599 |
$messages->{'waiting'} = 1; |
598 |
$messages->{'waiting'} = 1; |
600 |
ModReserveMinusPriority( |
599 |
ModReserveMinusPriority( |
601 |
$itemnumber, |
600 |
$itemnumber, |
602 |
$checkreserves->{'reserve_id'}, |
601 |
$checkreserves->{id}, |
603 |
); |
602 |
); |
604 |
ModReserveStatus($itemnumber,'W'); |
603 |
ModReserveStatus($itemnumber,'waiting'); |
605 |
} |
604 |
} |
606 |
|
605 |
|
607 |
$nextreservinfo = $checkreserves->{'borrowernumber'}; |
606 |
$nextreservinfo = $checkreserves->{patron_id}; |
608 |
} |
607 |
} |
609 |
|
608 |
|
610 |
return ( $messages, $nextreservinfo ); |
609 |
return ( $messages, $nextreservinfo ); |
Lines 696-713
sub GetReserveStatus {
Link Here
|
696 |
|
695 |
|
697 |
my $dbh = C4::Context->dbh; |
696 |
my $dbh = C4::Context->dbh; |
698 |
|
697 |
|
699 |
my ($sth, $found, $priority); |
698 |
my ($sth, $status, $priority); |
700 |
if ( $itemnumber ) { |
699 |
if ( $itemnumber ) { |
701 |
$sth = $dbh->prepare("SELECT found, priority FROM reserves WHERE itemnumber = ? order by priority LIMIT 1"); |
700 |
$sth = $dbh->prepare(q{ |
|
|
701 |
SELECT status, priority FROM holds WHERE item_id = ? AND completed = 0 order by priority LIMIT 1 |
702 |
}); |
702 |
$sth->execute($itemnumber); |
703 |
$sth->execute($itemnumber); |
703 |
($found, $priority) = $sth->fetchrow_array; |
704 |
my $h = Koha::Holds->search({item_id => $itemnumber}); |
704 |
} |
705 |
($status, $priority) = $sth->fetchrow_array; |
705 |
|
|
|
706 |
if(defined $found) { |
707 |
return 'Waiting' if $found eq 'W' and $priority == 0; |
708 |
return 'Finished' if $found eq 'F'; |
709 |
} |
706 |
} |
710 |
|
707 |
|
|
|
708 |
return 'Waiting' if defined $status and $status eq 'waiting' and $priority == 0; |
709 |
return 'Finished' if defined $status and $status eq 'fulfilled'; |
711 |
return 'Reserved' if defined $priority && $priority > 0; |
710 |
return 'Reserved' if defined $priority && $priority > 0; |
712 |
|
711 |
|
713 |
return ''; # empty string here will remove need for checking undef, or less log lines |
712 |
return ''; # empty string here will remove need for checking undef, or less log lines |
Lines 748-754
sub CheckReserves {
Link Here
|
748 |
my $sth; |
747 |
my $sth; |
749 |
my $select; |
748 |
my $select; |
750 |
if (C4::Context->preference('item-level_itypes')){ |
749 |
if (C4::Context->preference('item-level_itypes')){ |
751 |
$select = " |
750 |
$select = " |
752 |
SELECT items.biblionumber, |
751 |
SELECT items.biblionumber, |
753 |
items.biblioitemnumber, |
752 |
items.biblioitemnumber, |
754 |
itemtypes.notforloan, |
753 |
itemtypes.notforloan, |
Lines 763-769
sub CheckReserves {
Link Here
|
763 |
"; |
762 |
"; |
764 |
} |
763 |
} |
765 |
else { |
764 |
else { |
766 |
$select = " |
765 |
$select = " |
767 |
SELECT items.biblionumber, |
766 |
SELECT items.biblionumber, |
768 |
items.biblioitemnumber, |
767 |
items.biblioitemnumber, |
769 |
itemtypes.notforloan, |
768 |
itemtypes.notforloan, |
Lines 810-817
sub CheckReserves {
Link Here
|
810 |
|
809 |
|
811 |
my $priority = 10000000; |
810 |
my $priority = 10000000; |
812 |
foreach my $res (@reserves) { |
811 |
foreach my $res (@reserves) { |
813 |
if ( $res->{'itemnumber'} && $res->{'itemnumber'} == $itemnumber && $res->{'priority'} == 0) { |
812 |
if ( $res->{item_id} && $res->{item_id} == $itemnumber && $res->{priority} == 0) { |
814 |
if ($res->{'found'} eq 'W') { |
813 |
if ($res->{status} eq 'waiting') { |
815 |
return ( "Waiting", $res, \@reserves ); # Found it, it is waiting |
814 |
return ( "Waiting", $res, \@reserves ); # Found it, it is waiting |
816 |
} else { |
815 |
} else { |
817 |
return ( "Reserved", $res, \@reserves ); # Found determinated hold, e. g. the tranferred one |
816 |
return ( "Reserved", $res, \@reserves ); # Found determinated hold, e. g. the tranferred one |
Lines 822-835
sub CheckReserves {
Link Here
|
822 |
my $local_hold_match; |
821 |
my $local_hold_match; |
823 |
|
822 |
|
824 |
if ($LocalHoldsPriority) { |
823 |
if ($LocalHoldsPriority) { |
825 |
$patron = Koha::Patrons->find( $res->{borrowernumber} ); |
824 |
$patron = Koha::Patrons->find( $res->{patron_id} ); |
826 |
$item = Koha::Items->find($itemnumber); |
825 |
$item = Koha::Items->find($itemnumber); |
827 |
|
826 |
|
828 |
my $local_holds_priority_item_branchcode = |
827 |
my $local_holds_priority_item_branchcode = |
829 |
$item->$LocalHoldsPriorityItemControl; |
828 |
$item->$LocalHoldsPriorityItemControl; |
830 |
my $local_holds_priority_patron_branchcode = |
829 |
my $local_holds_priority_patron_branchcode = |
831 |
( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' ) |
830 |
( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' ) |
832 |
? $res->{branchcode} |
831 |
? $res->{pickup_library_id} |
833 |
: ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' ) |
832 |
: ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' ) |
834 |
? $patron->branchcode |
833 |
? $patron->branchcode |
835 |
: undef; |
834 |
: undef; |
Lines 839-848
sub CheckReserves {
Link Here
|
839 |
} |
838 |
} |
840 |
|
839 |
|
841 |
# See if this item is more important than what we've got so far |
840 |
# See if this item is more important than what we've got so far |
842 |
if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) { |
841 |
if ( ( $res->{priority} && $res->{priority} < $priority ) || $local_hold_match ) { |
843 |
$item ||= Koha::Items->find($itemnumber); |
842 |
$item ||= Koha::Items->find($itemnumber); |
844 |
next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype; |
843 |
next if $res->{item_type} && $res->{item_type} ne $item->effective_itemtype; |
845 |
$patron ||= Koha::Patrons->find( $res->{borrowernumber} ); |
844 |
$patron ||= Koha::Patrons->find( $res->{patron_id} ); |
846 |
my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed ); |
845 |
my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed ); |
847 |
my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype); |
846 |
my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype); |
848 |
next if ($branchitemrule->{'holdallowed'} == 0); |
847 |
next if ($branchitemrule->{'holdallowed'} == 0); |
Lines 850-859
sub CheckReserves {
Link Here
|
850 |
my $library = Koha::Libraries->find({branchcode=>$item->homebranch}); |
849 |
my $library = Koha::Libraries->find({branchcode=>$item->homebranch}); |
851 |
next if (($branchitemrule->{'holdallowed'} == 3) && (!$library->validate_hold_sibling({branchcode => $patron->branchcode}) )); |
850 |
next if (($branchitemrule->{'holdallowed'} == 3) && (!$library->validate_hold_sibling({branchcode => $patron->branchcode}) )); |
852 |
my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy}; |
851 |
my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy}; |
853 |
next if ( ($hold_fulfillment_policy eq 'holdgroup') && (!$library->validate_hold_sibling({branchcode => $res->{branchcode}})) ); |
852 |
next if ( ($hold_fulfillment_policy eq 'holdgroup') && (!$library->validate_hold_sibling({branchcode => $res->{pickup_library_id}})) ); |
854 |
next if ( ($hold_fulfillment_policy eq 'homebranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) ); |
853 |
next if ( ($hold_fulfillment_policy eq 'homebranch') && ($res->{pickup_library_id} ne $item->$hold_fulfillment_policy) ); |
855 |
next if ( ($hold_fulfillment_policy eq 'holdingbranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) ); |
854 |
next if ( ($hold_fulfillment_policy eq 'holdingbranch') && ($res->{pickup_library_id} ne $item->$hold_fulfillment_policy) ); |
856 |
next unless $item->can_be_transferred( { to => Koha::Libraries->find( $res->{branchcode} ) } ); |
855 |
next unless $item->can_be_transferred( { to => Koha::Libraries->find( $res->{pickup_library_id} ) } ); |
857 |
$priority = $res->{'priority'}; |
856 |
$priority = $res->{'priority'}; |
858 |
$highest = $res; |
857 |
$highest = $res; |
859 |
last if $local_hold_match; |
858 |
last if $local_hold_match; |
Lines 886-904
sub CancelExpiredReserves {
Link Here
|
886 |
my $expireWaiting = C4::Context->preference('ExpireReservesMaxPickUpDelay'); |
885 |
my $expireWaiting = C4::Context->preference('ExpireReservesMaxPickUpDelay'); |
887 |
|
886 |
|
888 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
887 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
889 |
my $params = { expirationdate => { '<', $dtf->format_date($today) } }; |
888 |
my $params = { expiration_date => { '<', $dtf->format_date($today) } }; |
890 |
$params->{found} = [ { '!=', 'W' }, undef ] unless $expireWaiting; |
889 |
$params->{status} = [ { '!=', 'waiting' }, undef ] unless $expireWaiting; |
891 |
|
890 |
|
892 |
# FIXME To move to Koha::Holds->search_expired (?) |
891 |
# FIXME To move to Koha::Holds->search_expired (?) |
893 |
my $holds = Koha::Holds->search( $params ); |
892 |
my $holds = Koha::Holds->search( $params ); |
894 |
|
893 |
|
895 |
while ( my $hold = $holds->next ) { |
894 |
while ( my $hold = $holds->next ) { |
896 |
my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode ); |
895 |
my $calendar = Koha::Calendar->new( branchcode => $hold->pickup_library_id ); |
897 |
|
896 |
|
898 |
next if !$cancel_on_holidays && $calendar->is_holiday( $today ); |
897 |
next if !$cancel_on_holidays && $calendar->is_holiday( $today ); |
899 |
|
898 |
|
900 |
my $cancel_params = {}; |
899 |
my $cancel_params = {}; |
901 |
if ( $hold->found eq 'W' ) { |
900 |
if ( $hold->status eq 'waiting' ) { |
902 |
$cancel_params->{charge_cancel_fee} = 1; |
901 |
$cancel_params->{charge_cancel_fee} = 1; |
903 |
} |
902 |
} |
904 |
$hold->cancel( $cancel_params ); |
903 |
$hold->cancel( $cancel_params ); |
Lines 909-922
sub CancelExpiredReserves {
Link Here
|
909 |
|
908 |
|
910 |
AutoUnsuspendReserves(); |
909 |
AutoUnsuspendReserves(); |
911 |
|
910 |
|
912 |
Unsuspends all suspended reserves with a suspend_until date from before today. |
911 |
Unsuspends all suspended reserves with a suspended_until date from before today. |
913 |
|
912 |
|
914 |
=cut |
913 |
=cut |
915 |
|
914 |
|
916 |
sub AutoUnsuspendReserves { |
915 |
sub AutoUnsuspendReserves { |
917 |
my $today = dt_from_string(); |
916 |
my $today = dt_from_string(); |
918 |
|
917 |
|
919 |
my @holds = Koha::Holds->search( { suspend_until => { '<=' => $today->ymd() } } ); |
918 |
my @holds = Koha::Holds->search( { suspended_until_date => { '<=' => $today->ymd() } } ); |
920 |
|
919 |
|
921 |
map { $_->resume() } @holds; |
920 |
map { $_->resume() } @holds; |
922 |
} |
921 |
} |
Lines 975-984
sub ModReserve {
Link Here
|
975 |
|
974 |
|
976 |
my $hold; |
975 |
my $hold; |
977 |
unless ( $reserve_id ) { |
976 |
unless ( $reserve_id ) { |
978 |
my $holds = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber, itemnumber => $itemnumber }); |
977 |
my $holds = Koha::Holds->search({ biblio_id => $biblionumber, patron_id => $borrowernumber, item_id => $itemnumber }); |
979 |
return unless $holds->count; # FIXME Should raise an exception |
978 |
return unless $holds->count; # FIXME Should raise an exception |
980 |
$hold = $holds->next; |
979 |
$hold = $holds->next; |
981 |
$reserve_id = $hold->reserve_id; |
980 |
$reserve_id = $hold->id; |
982 |
} |
981 |
} |
983 |
|
982 |
|
984 |
$hold ||= Koha::Holds->find($reserve_id); |
983 |
$hold ||= Koha::Holds->find($reserve_id); |
Lines 987-1007
sub ModReserve {
Link Here
|
987 |
$hold->cancel; |
986 |
$hold->cancel; |
988 |
} |
987 |
} |
989 |
elsif ($rank =~ /^\d+/ and $rank > 0) { |
988 |
elsif ($rank =~ /^\d+/ and $rank > 0) { |
990 |
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) ) |
989 |
logaction( 'HOLDS', 'MODIFY', $hold->id, Dumper($hold->unblessed) ) |
991 |
if C4::Context->preference('HoldsLog'); |
990 |
if C4::Context->preference('HoldsLog'); |
992 |
|
991 |
|
993 |
my $properties = { |
992 |
my $properties = { |
994 |
priority => $rank, |
993 |
priority => $rank, |
995 |
branchcode => $branchcode, |
994 |
pickup_library_id => $branchcode, |
996 |
itemnumber => $itemnumber, |
995 |
item_id => $itemnumber, |
997 |
found => undef, |
996 |
status => 'placed', |
998 |
waitingdate => undef |
997 |
waiting_date => undef |
999 |
}; |
998 |
}; |
1000 |
if (exists $params->{reservedate}) { |
999 |
if (exists $params->{reservedate}) { |
1001 |
$properties->{reservedate} = $params->{reservedate} || undef; |
1000 |
$properties->{placing_date} = $params->{reservedate} || undef; |
1002 |
} |
1001 |
} |
1003 |
if (exists $params->{expirationdate}) { |
1002 |
if (exists $params->{expirationdate}) { |
1004 |
$properties->{expirationdate} = $params->{expirationdate} || undef; |
1003 |
$properties->{expiration_date} = $params->{expirationdate} || undef; |
1005 |
} |
1004 |
} |
1006 |
|
1005 |
|
1007 |
$hold->set($properties)->store(); |
1006 |
$hold->set($properties)->store(); |
Lines 1013-1019
sub ModReserve {
Link Here
|
1013 |
} else { |
1012 |
} else { |
1014 |
# If the hold is suspended leave the hold suspended, but convert it to an indefinite hold. |
1013 |
# If the hold is suspended leave the hold suspended, but convert it to an indefinite hold. |
1015 |
# If the hold is not suspended, this does nothing. |
1014 |
# If the hold is not suspended, this does nothing. |
1016 |
$hold->set( { suspend_until => undef } )->store(); |
1015 |
$hold->set( { suspended_until_date => undef } )->store(); |
1017 |
} |
1016 |
} |
1018 |
} |
1017 |
} |
1019 |
|
1018 |
|
Lines 1035-1071
whose keys are fields from the reserves table in the Koha database.
Link Here
|
1035 |
|
1034 |
|
1036 |
sub ModReserveFill { |
1035 |
sub ModReserveFill { |
1037 |
my ($res) = @_; |
1036 |
my ($res) = @_; |
1038 |
my $reserve_id = $res->{'reserve_id'}; |
1037 |
my $reserve_id = $res->{'id'}; |
1039 |
|
1038 |
|
1040 |
my $hold = Koha::Holds->find($reserve_id); |
1039 |
my $hold = Koha::Holds->find($reserve_id); |
1041 |
# get the priority on this record.... |
1040 |
# get the priority on this record.... |
1042 |
my $priority = $hold->priority; |
1041 |
my $priority = $hold->priority; |
1043 |
|
1042 |
|
1044 |
# update the hold statuses, no need to store it though, we will be deleting it anyway |
1043 |
# update the hold statuses, no need to store it though, we will be deleting it anyway |
|
|
1044 |
# FIXME: Add Koha::Hold->set_filled and add the correct log |
1045 |
$hold->set( |
1045 |
$hold->set( |
1046 |
{ |
1046 |
{ |
1047 |
found => 'F', |
1047 |
status => 'fulfilled', |
1048 |
priority => 0, |
1048 |
priority => 0, |
|
|
1049 |
completed => 1, |
1050 |
completion_date => \'NOW()' |
1049 |
} |
1051 |
} |
1050 |
); |
1052 |
); |
1051 |
|
1053 |
|
1052 |
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) ) |
1054 |
logaction( 'HOLDS', 'MODIFY', $hold->id, Dumper($hold->unblessed) ) |
1053 |
if C4::Context->preference('HoldsLog'); |
1055 |
if C4::Context->preference('HoldsLog'); |
1054 |
|
1056 |
|
1055 |
# FIXME Must call Koha::Hold->cancel ? => No, should call ->filled and add the correct log |
1057 |
$hold->store(); |
1056 |
Koha::Old::Hold->new( $hold->unblessed() )->store(); |
|
|
1057 |
|
1058 |
$hold->delete(); |
1059 |
|
1058 |
|
1060 |
if ( C4::Context->preference('HoldFeeMode') eq 'any_time_is_collected' ) { |
1059 |
if ( C4::Context->preference('HoldFeeMode') eq 'any_time_is_collected' ) { |
1061 |
my $reserve_fee = GetReserveFee( $hold->borrowernumber, $hold->biblionumber ); |
1060 |
my $reserve_fee = GetReserveFee( $hold->patron_id, $hold->biblio_id ); |
1062 |
ChargeReserveFee( $hold->borrowernumber, $reserve_fee, $hold->biblio->title ); |
1061 |
ChargeReserveFee( $hold->patron_id, $reserve_fee, $hold->biblio->title ); |
1063 |
} |
1062 |
} |
1064 |
|
1063 |
|
1065 |
# now fix the priority on the others (if the priority wasn't |
1064 |
# now fix the priority on the others (if the priority wasn't |
1066 |
# already sorted!).... |
1065 |
# already sorted!).... |
1067 |
unless ( $priority == 0 ) { |
1066 |
unless ( $priority == 0 ) { |
1068 |
_FixPriority( { reserve_id => $reserve_id, biblionumber => $hold->biblionumber } ); |
1067 |
_FixPriority( { reserve_id => $reserve_id, biblionumber => $hold->biblio_id } ); |
1069 |
} |
1068 |
} |
1070 |
} |
1069 |
} |
1071 |
|
1070 |
|
Lines 1087-1093
sub ModReserveStatus {
Link Here
|
1087 |
my ($itemnumber, $newstatus) = @_; |
1086 |
my ($itemnumber, $newstatus) = @_; |
1088 |
my $dbh = C4::Context->dbh; |
1087 |
my $dbh = C4::Context->dbh; |
1089 |
|
1088 |
|
1090 |
my $query = "UPDATE reserves SET found = ?, waitingdate = NOW() WHERE itemnumber = ? AND found IS NULL AND priority = 0"; |
1089 |
my $query = "UPDATE holds SET status = ?, waiting_date = NOW() WHERE item_id = ? AND status='placed' AND priority = 0"; |
1091 |
my $sth_set = $dbh->prepare($query); |
1090 |
my $sth_set = $dbh->prepare($query); |
1092 |
$sth_set->execute( $newstatus, $itemnumber ); |
1091 |
$sth_set->execute( $newstatus, $itemnumber ); |
1093 |
|
1092 |
|
Lines 1131-1149
sub ModReserveAffect {
Link Here
|
1131 |
# Find hold by id if we have it |
1130 |
# Find hold by id if we have it |
1132 |
$hold = Koha::Holds->find( $reserve_id ) if $reserve_id; |
1131 |
$hold = Koha::Holds->find( $reserve_id ) if $reserve_id; |
1133 |
# Find item level hold for this item if there is one |
1132 |
# Find item level hold for this item if there is one |
1134 |
$hold ||= Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->next(); |
1133 |
$hold ||= Koha::Holds->search( { patron_id => $borrowernumber, item_id => $itemnumber } )->next(); |
1135 |
# Find record level hold if there is no item level hold |
1134 |
# Find record level hold if there is no item level hold |
1136 |
$hold ||= Koha::Holds->search( { borrowernumber => $borrowernumber, biblionumber => $biblionumber } )->next(); |
1135 |
$hold ||= Koha::Holds->search( { patron_id => $borrowernumber, biblio_id => $biblionumber } )->next(); |
1137 |
|
1136 |
|
1138 |
return unless $hold; |
1137 |
return unless $hold; |
1139 |
|
1138 |
|
1140 |
my $already_on_shelf = $hold->found && $hold->found eq 'W'; |
1139 |
my $already_on_shelf = $hold->status eq 'waiting'; |
1141 |
|
1140 |
|
1142 |
$hold->itemnumber($itemnumber); |
1141 |
$hold->item_id($itemnumber); |
1143 |
$hold->set_waiting($transferToDo); |
1142 |
$hold->set_waiting($transferToDo); |
1144 |
|
1143 |
|
1145 |
if( !$transferToDo ){ |
1144 |
if( !$transferToDo ){ |
1146 |
_koha_notify_reserve( $hold->reserve_id ) unless $already_on_shelf; |
1145 |
_koha_notify_reserve( $hold->id ) unless $already_on_shelf; |
1147 |
my $transfers = Koha::Item::Transfers->search({ |
1146 |
my $transfers = Koha::Item::Transfers->search({ |
1148 |
itemnumber => $itemnumber, |
1147 |
itemnumber => $itemnumber, |
1149 |
datearrived => undef |
1148 |
datearrived => undef |
Lines 1161-1167
sub ModReserveAffect {
Link Here
|
1161 |
CartToShelf( $itemnumber ); |
1160 |
CartToShelf( $itemnumber ); |
1162 |
} |
1161 |
} |
1163 |
|
1162 |
|
1164 |
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) ) |
1163 |
logaction( 'HOLDS', 'MODIFY', $hold->id, Dumper($hold->unblessed) ) |
1165 |
if C4::Context->preference('HoldsLog'); |
1164 |
if C4::Context->preference('HoldsLog'); |
1166 |
|
1165 |
|
1167 |
return; |
1166 |
return; |
Lines 1178-1192
function to cancel reserv,check other reserves, and transfer document if it's ne
Link Here
|
1178 |
sub ModReserveCancelAll { |
1177 |
sub ModReserveCancelAll { |
1179 |
my $messages; |
1178 |
my $messages; |
1180 |
my $nextreservinfo; |
1179 |
my $nextreservinfo; |
1181 |
my ( $itemnumber, $borrowernumber ) = @_; |
1180 |
my ( $item_id, $patron_id ) = @_; |
1182 |
|
1181 |
|
1183 |
#step 1 : cancel the reservation |
1182 |
#step 1 : cancel the reservation |
1184 |
my $holds = Koha::Holds->search({ itemnumber => $itemnumber, borrowernumber => $borrowernumber }); |
1183 |
my $holds = Koha::Holds->search({ item_id => $item_id, patron_id => $patron_id }); |
1185 |
return unless $holds->count; |
1184 |
return unless $holds->count; |
1186 |
$holds->next->cancel; |
1185 |
$holds->next->cancel; |
1187 |
|
1186 |
|
1188 |
#step 2 launch the subroutine of the others reserves |
1187 |
#step 2 launch the subroutine of the others reserves |
1189 |
( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber); |
1188 |
( $messages, $nextreservinfo ) = GetOtherReserves($item_id); |
1190 |
|
1189 |
|
1191 |
return ( $messages, $nextreservinfo ); |
1190 |
return ( $messages, $nextreservinfo ); |
1192 |
} |
1191 |
} |
Lines 1200-1216
Reduce the values of queued list
Link Here
|
1200 |
=cut |
1199 |
=cut |
1201 |
|
1200 |
|
1202 |
sub ModReserveMinusPriority { |
1201 |
sub ModReserveMinusPriority { |
1203 |
my ( $itemnumber, $reserve_id ) = @_; |
1202 |
my ( $item_id, $reserve_id ) = @_; |
1204 |
|
1203 |
|
1205 |
#first step update the value of the first person on reserv |
1204 |
#first step update the value of the first person on reserv |
1206 |
my $dbh = C4::Context->dbh; |
1205 |
my $dbh = C4::Context->dbh; |
1207 |
my $query = " |
1206 |
my $query = " |
1208 |
UPDATE reserves |
1207 |
UPDATE holds |
1209 |
SET priority = 0 , itemnumber = ? |
1208 |
SET priority = 0 , item_id = ? |
1210 |
WHERE reserve_id = ? |
1209 |
WHERE id = ? |
1211 |
"; |
1210 |
"; |
1212 |
my $sth_upd = $dbh->prepare($query); |
1211 |
my $sth_upd = $dbh->prepare($query); |
1213 |
$sth_upd->execute( $itemnumber, $reserve_id ); |
1212 |
$sth_upd->execute( $item_id, $reserve_id ); |
1214 |
# second step update all others reserves |
1213 |
# second step update all others reserves |
1215 |
_FixPriority({ reserve_id => $reserve_id, rank => '0' }); |
1214 |
_FixPriority({ reserve_id => $reserve_id, rank => '0' }); |
1216 |
} |
1215 |
} |
Lines 1348-1355
sub AlterPriority {
Link Here
|
1348 |
my $hold = Koha::Holds->find( $reserve_id ); |
1347 |
my $hold = Koha::Holds->find( $reserve_id ); |
1349 |
return unless $hold; |
1348 |
return unless $hold; |
1350 |
|
1349 |
|
1351 |
if ( $hold->cancellationdate ) { |
1350 |
if ( $hold->completion_date and $hold->status eq 'cancelled' ) { |
1352 |
warn "I cannot alter the priority for reserve_id $reserve_id, the reserve has been cancelled (" . $hold->cancellationdate . ')'; |
1351 |
warn "I cannot alter the priority for reserve_id $reserve_id, the reserve has been cancelled (" . $hold->completion_date . ')'; |
1353 |
return; |
1352 |
return; |
1354 |
} |
1353 |
} |
1355 |
|
1354 |
|
Lines 1381-1387
sub ToggleLowestPriority {
Link Here
|
1381 |
|
1380 |
|
1382 |
my $dbh = C4::Context->dbh; |
1381 |
my $dbh = C4::Context->dbh; |
1383 |
|
1382 |
|
1384 |
my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?"); |
1383 |
my $sth = $dbh->prepare( "UPDATE holds SET lowest_priority = NOT lowest_priority WHERE id = ?"); |
1385 |
$sth->execute( $reserve_id ); |
1384 |
$sth->execute( $reserve_id ); |
1386 |
|
1385 |
|
1387 |
_FixPriority({ reserve_id => $reserve_id, rank => '999999' }); |
1386 |
_FixPriority({ reserve_id => $reserve_id, rank => '999999' }); |
Lines 1441-1449
sub SuspendAll {
Link Here
|
1441 |
return unless ( $borrowernumber || $biblionumber ); |
1440 |
return unless ( $borrowernumber || $biblionumber ); |
1442 |
|
1441 |
|
1443 |
my $params; |
1442 |
my $params; |
1444 |
$params->{found} = undef; |
1443 |
$params->{status} = 'placed'; |
1445 |
$params->{borrowernumber} = $borrowernumber if $borrowernumber; |
1444 |
$params->{patron_id} = $borrowernumber if $borrowernumber; |
1446 |
$params->{biblionumber} = $biblionumber if $biblionumber; |
1445 |
$params->{biblio_id} = $biblionumber if $biblionumber; |
1447 |
|
1446 |
|
1448 |
my @holds = Koha::Holds->search($params); |
1447 |
my @holds = Koha::Holds->search($params); |
1449 |
|
1448 |
|
Lines 1503-1517
sub _FixPriority {
Link Here
|
1503 |
my $hold; |
1502 |
my $hold; |
1504 |
if ( $reserve_id ) { |
1503 |
if ( $reserve_id ) { |
1505 |
$hold = Koha::Holds->find( $reserve_id ); |
1504 |
$hold = Koha::Holds->find( $reserve_id ); |
1506 |
if (!defined $hold){ |
|
|
1507 |
# may have already been checked out and hold fulfilled |
1508 |
$hold = Koha::Old::Holds->find( $reserve_id ); |
1509 |
} |
1510 |
return unless $hold; |
1505 |
return unless $hold; |
1511 |
} |
1506 |
} |
1512 |
|
1507 |
|
1513 |
unless ( $biblionumber ) { # FIXME This is a very weird API |
1508 |
unless ( $biblionumber ) { # FIXME This is a very weird API |
1514 |
$biblionumber = $hold->biblionumber; |
1509 |
$biblionumber = $hold->biblio_id; |
1515 |
} |
1510 |
} |
1516 |
|
1511 |
|
1517 |
if ( $rank eq "del" ) { # FIXME will crash if called without $hold |
1512 |
if ( $rank eq "del" ) { # FIXME will crash if called without $hold |
Lines 1521-1530
sub _FixPriority {
Link Here
|
1521 |
|
1516 |
|
1522 |
# make sure priority for waiting or in-transit items is 0 |
1517 |
# make sure priority for waiting or in-transit items is 0 |
1523 |
my $query = " |
1518 |
my $query = " |
1524 |
UPDATE reserves |
1519 |
UPDATE holds |
1525 |
SET priority = 0 |
1520 |
SET priority = 0 |
1526 |
WHERE reserve_id = ? |
1521 |
WHERE id = ? |
1527 |
AND found IN ('W', 'T') |
1522 |
AND status IN ('waiting', 'in_transit') |
1528 |
"; |
1523 |
"; |
1529 |
my $sth = $dbh->prepare($query); |
1524 |
my $sth = $dbh->prepare($query); |
1530 |
$sth->execute( $reserve_id ); |
1525 |
$sth->execute( $reserve_id ); |
Lines 1533-1542
sub _FixPriority {
Link Here
|
1533 |
|
1528 |
|
1534 |
# get whats left |
1529 |
# get whats left |
1535 |
my $query = " |
1530 |
my $query = " |
1536 |
SELECT reserve_id, borrowernumber, reservedate |
1531 |
SELECT id |
1537 |
FROM reserves |
1532 |
FROM holds |
1538 |
WHERE biblionumber = ? |
1533 |
WHERE biblio_id = ? |
1539 |
AND ((found <> 'W' AND found <> 'T') OR found IS NULL) |
1534 |
AND completed = 0 |
|
|
1535 |
AND status = 'placed' |
1540 |
ORDER BY priority ASC |
1536 |
ORDER BY priority ASC |
1541 |
"; |
1537 |
"; |
1542 |
my $sth = $dbh->prepare($query); |
1538 |
my $sth = $dbh->prepare($query); |
Lines 1550-1556
sub _FixPriority {
Link Here
|
1550 |
my $i; |
1546 |
my $i; |
1551 |
my $key = -1; # to allow for 0 to be a valid result |
1547 |
my $key = -1; # to allow for 0 to be a valid result |
1552 |
for ( $i = 0 ; $i < @priority ; $i++ ) { |
1548 |
for ( $i = 0 ; $i < @priority ; $i++ ) { |
1553 |
if ( $reserve_id && $reserve_id == $priority[$i]->{'reserve_id'} ) { |
1549 |
if ( $reserve_id && $reserve_id == $priority[$i]->{'id'} ) { |
1554 |
$key = $i; # save the index |
1550 |
$key = $i; # save the index |
1555 |
last; |
1551 |
last; |
1556 |
} |
1552 |
} |
Lines 1566-1590
sub _FixPriority {
Link Here
|
1566 |
|
1562 |
|
1567 |
# now fix the priority on those that are left.... |
1563 |
# now fix the priority on those that are left.... |
1568 |
$query = " |
1564 |
$query = " |
1569 |
UPDATE reserves |
1565 |
UPDATE holds |
1570 |
SET priority = ? |
1566 |
SET priority = ? |
1571 |
WHERE reserve_id = ? |
1567 |
WHERE id = ? |
1572 |
"; |
1568 |
"; |
1573 |
$sth = $dbh->prepare($query); |
1569 |
$sth = $dbh->prepare($query); |
1574 |
for ( my $j = 0 ; $j < @priority ; $j++ ) { |
1570 |
for ( my $j = 0 ; $j < @priority ; $j++ ) { |
1575 |
$sth->execute( |
1571 |
$sth->execute( |
1576 |
$j + 1, |
1572 |
$j + 1, |
1577 |
$priority[$j]->{'reserve_id'} |
1573 |
$priority[$j]->{'id'} |
1578 |
); |
1574 |
); |
1579 |
} |
1575 |
} |
1580 |
|
1576 |
|
1581 |
$sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" ); |
1577 |
$sth = $dbh->prepare( "SELECT id FROM holds WHERE lowest_priority = 1 ORDER BY priority" ); |
1582 |
$sth->execute(); |
1578 |
$sth->execute(); |
1583 |
|
1579 |
|
1584 |
unless ( $ignoreSetLowestRank ) { |
1580 |
unless ( $ignoreSetLowestRank ) { |
1585 |
while ( my $res = $sth->fetchrow_hashref() ) { |
1581 |
while ( my $res = $sth->fetchrow_hashref() ) { |
1586 |
_FixPriority({ |
1582 |
_FixPriority({ |
1587 |
reserve_id => $res->{'reserve_id'}, |
1583 |
reserve_id => $res->{'id'}, |
1588 |
rank => '999999', |
1584 |
rank => '999999', |
1589 |
ignoreSetLowestRank => 1 |
1585 |
ignoreSetLowestRank => 1 |
1590 |
}); |
1586 |
}); |
Lines 1621-1648
sub _Findgroupreserve {
Link Here
|
1621 |
# TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var. |
1617 |
# TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var. |
1622 |
# check for exact targeted match |
1618 |
# check for exact targeted match |
1623 |
my $item_level_target_query = qq{ |
1619 |
my $item_level_target_query = qq{ |
1624 |
SELECT reserves.biblionumber AS biblionumber, |
1620 |
SELECT holds.biblio_id AS biblio_id, |
1625 |
reserves.borrowernumber AS borrowernumber, |
1621 |
holds.patron_id AS patron_id, |
1626 |
reserves.reservedate AS reservedate, |
1622 |
holds.placing_date AS placing_date, |
1627 |
reserves.branchcode AS branchcode, |
1623 |
holds.pickup_library_id AS pickup_library_id, |
1628 |
reserves.cancellationdate AS cancellationdate, |
1624 |
holds.completion_date AS completion_date, |
1629 |
reserves.found AS found, |
1625 |
holds.status AS status, |
1630 |
reserves.reservenotes AS reservenotes, |
1626 |
holds.notes AS notes, |
1631 |
reserves.priority AS priority, |
1627 |
holds.priority AS priority, |
1632 |
reserves.timestamp AS timestamp, |
1628 |
holds.timestamp AS timestamp, |
1633 |
biblioitems.biblioitemnumber AS biblioitemnumber, |
1629 |
biblioitems.biblioitemnumber AS biblioitemnumber, |
1634 |
reserves.itemnumber AS itemnumber, |
1630 |
holds.item_id AS item_id, |
1635 |
reserves.reserve_id AS reserve_id, |
1631 |
holds.id AS id, |
1636 |
reserves.itemtype AS itemtype |
1632 |
holds.item_type AS item_type |
1637 |
FROM reserves |
1633 |
FROM holds |
1638 |
JOIN biblioitems USING (biblionumber) |
1634 |
JOIN biblioitems ON (holds.biblio_id=biblioitems.biblionumber) |
1639 |
JOIN hold_fill_targets USING (biblionumber, borrowernumber, itemnumber) |
1635 |
JOIN hold_fill_targets ON ( |
1640 |
WHERE found IS NULL |
1636 |
holds.biblio_id=hold_fill_targets.biblionumber |
|
|
1637 |
AND holds.patron_id=hold_fill_targets.borrowernumber |
1638 |
AND holds.item_id=hold_fill_targets.itemnumber) |
1639 |
WHERE status='placed' |
1641 |
AND priority > 0 |
1640 |
AND priority > 0 |
1642 |
AND item_level_request = 1 |
1641 |
AND completed = 0 |
1643 |
AND itemnumber = ? |
1642 |
AND item_level = 1 |
1644 |
AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1643 |
AND item_id = ? |
1645 |
AND suspend = 0 |
1644 |
AND placing_date <= DATE_ADD(NOW(),INTERVAL ? DAY) |
|
|
1645 |
AND suspended = 0 |
1646 |
ORDER BY priority |
1646 |
ORDER BY priority |
1647 |
}; |
1647 |
}; |
1648 |
my $sth = $dbh->prepare($item_level_target_query); |
1648 |
my $sth = $dbh->prepare($item_level_target_query); |
Lines 1650-1683
sub _Findgroupreserve {
Link Here
|
1650 |
my @results; |
1650 |
my @results; |
1651 |
if ( my $data = $sth->fetchrow_hashref ) { |
1651 |
if ( my $data = $sth->fetchrow_hashref ) { |
1652 |
push( @results, $data ) |
1652 |
push( @results, $data ) |
1653 |
unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ; |
1653 |
unless any{ $data->{patron_id} eq $_ } @$ignore_borrowers ; |
1654 |
} |
1654 |
} |
1655 |
return @results if @results; |
1655 |
return @results if @results; |
1656 |
|
1656 |
|
1657 |
# check for title-level targeted match |
1657 |
# check for title-level targeted match |
1658 |
my $title_level_target_query = qq{ |
1658 |
my $title_level_target_query = qq{ |
1659 |
SELECT reserves.biblionumber AS biblionumber, |
1659 |
SELECT holds.biblio_id AS biblio_id, |
1660 |
reserves.borrowernumber AS borrowernumber, |
1660 |
holds.patron_id AS patron_id, |
1661 |
reserves.reservedate AS reservedate, |
1661 |
holds.placing_date AS placing_date, |
1662 |
reserves.branchcode AS branchcode, |
1662 |
holds.pickup_library_id AS pickup_library_id, |
1663 |
reserves.cancellationdate AS cancellationdate, |
1663 |
holds.completion_date AS completion_date, |
1664 |
reserves.found AS found, |
1664 |
holds.status AS status, |
1665 |
reserves.reservenotes AS reservenotes, |
1665 |
holds.notes AS notes, |
1666 |
reserves.priority AS priority, |
1666 |
holds.priority AS priority, |
1667 |
reserves.timestamp AS timestamp, |
1667 |
holds.timestamp AS timestamp, |
1668 |
biblioitems.biblioitemnumber AS biblioitemnumber, |
1668 |
biblioitems.biblioitemnumber AS biblioitemnumber, |
1669 |
reserves.itemnumber AS itemnumber, |
1669 |
holds.item_id AS item_id, |
1670 |
reserves.reserve_id AS reserve_id, |
1670 |
holds.id AS id, |
1671 |
reserves.itemtype AS itemtype |
1671 |
holds.item_type AS item_type |
1672 |
FROM reserves |
1672 |
FROM holds |
1673 |
JOIN biblioitems USING (biblionumber) |
1673 |
JOIN biblioitems ON (holds.biblio_id=biblioitems.biblionumber) |
1674 |
JOIN hold_fill_targets USING (biblionumber, borrowernumber) |
1674 |
JOIN hold_fill_targets ON ( |
1675 |
WHERE found IS NULL |
1675 |
holds.biblio_id=hold_fill_targets.biblionumber |
|
|
1676 |
AND holds.patron_id=hold_fill_targets.borrowernumber) |
1677 |
WHERE status='placed' |
1676 |
AND priority > 0 |
1678 |
AND priority > 0 |
1677 |
AND item_level_request = 0 |
1679 |
AND completed = 0 |
|
|
1680 |
AND item_level = 0 |
1678 |
AND hold_fill_targets.itemnumber = ? |
1681 |
AND hold_fill_targets.itemnumber = ? |
1679 |
AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1682 |
AND placing_date <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1680 |
AND suspend = 0 |
1683 |
AND suspended = 0 |
1681 |
ORDER BY priority |
1684 |
ORDER BY priority |
1682 |
}; |
1685 |
}; |
1683 |
$sth = $dbh->prepare($title_level_target_query); |
1686 |
$sth = $dbh->prepare($title_level_target_query); |
Lines 1685-1713
sub _Findgroupreserve {
Link Here
|
1685 |
@results = (); |
1688 |
@results = (); |
1686 |
if ( my $data = $sth->fetchrow_hashref ) { |
1689 |
if ( my $data = $sth->fetchrow_hashref ) { |
1687 |
push( @results, $data ) |
1690 |
push( @results, $data ) |
1688 |
unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ; |
1691 |
unless any{ $data->{patron_id} eq $_ } @$ignore_borrowers ; |
1689 |
} |
1692 |
} |
1690 |
return @results if @results; |
1693 |
return @results if @results; |
1691 |
|
1694 |
|
1692 |
my $query = qq{ |
1695 |
my $query = qq{ |
1693 |
SELECT reserves.biblionumber AS biblionumber, |
1696 |
SELECT holds.biblio_id AS biblio_id, |
1694 |
reserves.borrowernumber AS borrowernumber, |
1697 |
holds.patron_id AS patron_id, |
1695 |
reserves.reservedate AS reservedate, |
1698 |
holds.placing_date AS placing_date, |
1696 |
reserves.waitingdate AS waitingdate, |
1699 |
holds.waiting_date AS waiting_date, |
1697 |
reserves.branchcode AS branchcode, |
1700 |
holds.pickup_library_id AS pickup_library_id, |
1698 |
reserves.cancellationdate AS cancellationdate, |
1701 |
holds.completion_date AS completion_date, |
1699 |
reserves.found AS found, |
1702 |
holds.status AS status, |
1700 |
reserves.reservenotes AS reservenotes, |
1703 |
holds.notes AS notes, |
1701 |
reserves.priority AS priority, |
1704 |
holds.priority AS priority, |
1702 |
reserves.timestamp AS timestamp, |
1705 |
holds.timestamp AS timestamp, |
1703 |
reserves.itemnumber AS itemnumber, |
1706 |
holds.item_id AS item_id, |
1704 |
reserves.reserve_id AS reserve_id, |
1707 |
holds.id AS id, |
1705 |
reserves.itemtype AS itemtype |
1708 |
holds.item_type AS item_type |
1706 |
FROM reserves |
1709 |
FROM holds |
1707 |
WHERE reserves.biblionumber = ? |
1710 |
WHERE holds.biblio_id = ? |
1708 |
AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?) |
1711 |
AND (holds.item_id IS NULL OR holds.item_id = ?) |
1709 |
AND reserves.reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1712 |
AND holds.placing_date <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1710 |
AND suspend = 0 |
1713 |
AND suspended = 0 |
|
|
1714 |
AND completed = 0 |
1711 |
ORDER BY priority |
1715 |
ORDER BY priority |
1712 |
}; |
1716 |
}; |
1713 |
$sth = $dbh->prepare($query); |
1717 |
$sth = $dbh->prepare($query); |
Lines 1715-1721
sub _Findgroupreserve {
Link Here
|
1715 |
@results = (); |
1719 |
@results = (); |
1716 |
while ( my $data = $sth->fetchrow_hashref ) { |
1720 |
while ( my $data = $sth->fetchrow_hashref ) { |
1717 |
push( @results, $data ) |
1721 |
push( @results, $data ) |
1718 |
unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ; |
1722 |
unless any{ $data->{patron_id} eq $_ } @$ignore_borrowers ; |
1719 |
} |
1723 |
} |
1720 |
return @results; |
1724 |
return @results; |
1721 |
} |
1725 |
} |
Lines 1751-1757
The following tables are availalbe witin the notice:
Link Here
|
1751 |
sub _koha_notify_reserve { |
1755 |
sub _koha_notify_reserve { |
1752 |
my $reserve_id = shift; |
1756 |
my $reserve_id = shift; |
1753 |
my $hold = Koha::Holds->find($reserve_id); |
1757 |
my $hold = Koha::Holds->find($reserve_id); |
1754 |
my $borrowernumber = $hold->borrowernumber; |
1758 |
my $borrowernumber = $hold->patron_id; |
1755 |
|
1759 |
|
1756 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
1760 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
1757 |
|
1761 |
|
Lines 1763-1783
sub _koha_notify_reserve {
Link Here
|
1763 |
message_name => 'Hold_Filled' |
1767 |
message_name => 'Hold_Filled' |
1764 |
} ); |
1768 |
} ); |
1765 |
|
1769 |
|
1766 |
my $library = Koha::Libraries->find( $hold->branchcode )->unblessed; |
1770 |
my $library = Koha::Libraries->find( $hold->pickup_library_id )->unblessed; |
1767 |
|
1771 |
|
1768 |
my $admin_email_address = $library->{branchemail} || C4::Context->preference('KohaAdminEmailAddress'); |
1772 |
my $admin_email_address = $library->{branchemail} || C4::Context->preference('KohaAdminEmailAddress'); |
1769 |
|
1773 |
|
1770 |
my %letter_params = ( |
1774 |
my %letter_params = ( |
1771 |
module => 'reserves', |
1775 |
module => 'reserves', |
1772 |
branchcode => $hold->branchcode, |
1776 |
branchcode => $hold->pickup_library_id, |
1773 |
lang => $patron->lang, |
1777 |
lang => $patron->lang, |
1774 |
tables => { |
1778 |
tables => { |
1775 |
'branches' => $library, |
1779 |
'branches' => $library, |
1776 |
'borrowers' => $patron->unblessed, |
1780 |
'borrowers' => $patron->unblessed, |
1777 |
'biblio' => $hold->biblionumber, |
1781 |
'biblio' => $hold->biblio_id, |
1778 |
'biblioitems' => $hold->biblionumber, |
1782 |
'biblioitems' => $hold->biblio_id, |
1779 |
'reserves' => $hold->unblessed, |
1783 |
'reserves' => $hold->unblessed, |
1780 |
'items' => $hold->itemnumber, |
1784 |
'items' => $hold->item_id, |
1781 |
}, |
1785 |
}, |
1782 |
); |
1786 |
); |
1783 |
|
1787 |
|
Lines 1840-1846
sub _ShiftPriorityByDateAndPriority {
Link Here
|
1840 |
my ( $biblio, $resdate, $new_priority ) = @_; |
1844 |
my ( $biblio, $resdate, $new_priority ) = @_; |
1841 |
|
1845 |
|
1842 |
my $dbh = C4::Context->dbh; |
1846 |
my $dbh = C4::Context->dbh; |
1843 |
my $query = "SELECT priority FROM reserves WHERE biblionumber = ? AND ( reservedate > ? OR priority > ? ) ORDER BY priority ASC LIMIT 1"; |
1847 |
my $query = "SELECT priority FROM holds WHERE biblio_id = ? AND ( placing_date > ? OR priority > ? ) AND completed = 0 ORDER BY priority ASC LIMIT 1"; |
1844 |
my $sth = $dbh->prepare( $query ); |
1848 |
my $sth = $dbh->prepare( $query ); |
1845 |
$sth->execute( $biblio, $resdate, $new_priority ); |
1849 |
$sth->execute( $biblio, $resdate, $new_priority ); |
1846 |
my $min_priority = $sth->fetchrow; |
1850 |
my $min_priority = $sth->fetchrow; |
Lines 1848-1867
sub _ShiftPriorityByDateAndPriority {
Link Here
|
1848 |
$new_priority = $min_priority if ( $min_priority ); |
1852 |
$new_priority = $min_priority if ( $min_priority ); |
1849 |
|
1853 |
|
1850 |
# Shift the priority up by one; works in conjunction with the next SQL statement |
1854 |
# Shift the priority up by one; works in conjunction with the next SQL statement |
1851 |
$query = "UPDATE reserves |
1855 |
$query = "UPDATE holds |
1852 |
SET priority = priority+1 |
1856 |
SET priority = priority+1 |
1853 |
WHERE biblionumber = ? |
1857 |
WHERE biblio_id = ? |
1854 |
AND borrowernumber = ? |
1858 |
AND patron_id = ? |
1855 |
AND reservedate = ? |
1859 |
AND placing_date = ? |
1856 |
AND found IS NULL"; |
1860 |
AND status = 'placed'"; |
1857 |
my $sth_update = $dbh->prepare( $query ); |
1861 |
my $sth_update = $dbh->prepare( $query ); |
1858 |
|
1862 |
|
1859 |
# Select all reserves for the biblio with priority greater than $new_priority, and order greatest to least |
1863 |
# Select all reserves for the biblio with priority greater than $new_priority, and order greatest to least |
1860 |
$query = "SELECT borrowernumber, reservedate FROM reserves WHERE priority >= ? AND biblionumber = ? ORDER BY priority DESC"; |
1864 |
$query = "SELECT patron_id, placing_date FROM holds WHERE priority >= ? AND biblio_id = ? ORDER BY priority DESC"; |
1861 |
$sth = $dbh->prepare( $query ); |
1865 |
$sth = $dbh->prepare( $query ); |
1862 |
$sth->execute( $new_priority, $biblio ); |
1866 |
$sth->execute( $new_priority, $biblio ); |
1863 |
while ( my $row = $sth->fetchrow_hashref ) { |
1867 |
while ( my $row = $sth->fetchrow_hashref ) { |
1864 |
$sth_update->execute( $biblio, $row->{borrowernumber}, $row->{reservedate} ); |
1868 |
$sth_update->execute( $biblio, $row->{patron_id}, $row->{placing_date} ); |
1865 |
} |
1869 |
} |
1866 |
|
1870 |
|
1867 |
return $new_priority; # so the caller knows what priority they wind up receiving |
1871 |
return $new_priority; # so the caller knows what priority they wind up receiving |
Lines 1885-1893
sub MoveReserve {
Link Here
|
1885 |
my ( $restype, $res, undef ) = CheckReserves( $itemnumber, undef, $lookahead ); |
1889 |
my ( $restype, $res, undef ) = CheckReserves( $itemnumber, undef, $lookahead ); |
1886 |
return unless $res; |
1890 |
return unless $res; |
1887 |
|
1891 |
|
1888 |
my $biblionumber = $res->{biblionumber}; |
1892 |
my $biblionumber = $res->{biblio_id}; |
1889 |
|
1893 |
|
1890 |
if ($res->{borrowernumber} == $borrowernumber) { |
1894 |
if ($res->{patron_id} == $borrowernumber) { |
1891 |
ModReserveFill($res); |
1895 |
ModReserveFill($res); |
1892 |
} |
1896 |
} |
1893 |
else { |
1897 |
else { |
Lines 1896-1903
sub MoveReserve {
Link Here
|
1896 |
# Find this item in the reserves |
1900 |
# Find this item in the reserves |
1897 |
|
1901 |
|
1898 |
my $borr_res = Koha::Holds->search({ |
1902 |
my $borr_res = Koha::Holds->search({ |
1899 |
borrowernumber => $borrowernumber, |
1903 |
patron_id => $borrowernumber, |
1900 |
biblionumber => $biblionumber, |
1904 |
biblio_id => $biblionumber, |
1901 |
},{ |
1905 |
},{ |
1902 |
order_by => 'priority' |
1906 |
order_by => 'priority' |
1903 |
})->next(); |
1907 |
})->next(); |
Lines 1911-1917
sub MoveReserve {
Link Here
|
1911 |
RevertWaitingStatus({ itemnumber => $itemnumber }); |
1915 |
RevertWaitingStatus({ itemnumber => $itemnumber }); |
1912 |
} |
1916 |
} |
1913 |
elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item |
1917 |
elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item |
1914 |
my $hold = Koha::Holds->find( $res->{reserve_id} ); |
1918 |
my $hold = Koha::Holds->find( $res->{id} ); |
1915 |
$hold->cancel; |
1919 |
$hold->cancel; |
1916 |
} |
1920 |
} |
1917 |
} |
1921 |
} |
Lines 1928-1960
This shifts the holds from C<$from_biblio> to C<$to_biblio> and reorders them by
Link Here
|
1928 |
sub MergeHolds { |
1932 |
sub MergeHolds { |
1929 |
my ( $dbh, $to_biblio, $from_biblio ) = @_; |
1933 |
my ( $dbh, $to_biblio, $from_biblio ) = @_; |
1930 |
my $sth = $dbh->prepare( |
1934 |
my $sth = $dbh->prepare( |
1931 |
"SELECT count(*) as reserve_count FROM reserves WHERE biblionumber = ?" |
1935 |
"SELECT count(*) as reserve_count FROM holds WHERE biblio_id = ? AND completed = 0" |
1932 |
); |
1936 |
); |
1933 |
$sth->execute($from_biblio); |
1937 |
$sth->execute($from_biblio); |
1934 |
if ( my $data = $sth->fetchrow_hashref() ) { |
1938 |
if ( my $data = $sth->fetchrow_hashref() ) { |
1935 |
|
1939 |
|
1936 |
# holds exist on old record, if not we don't need to do anything |
1940 |
# holds exist on old record, if not we don't need to do anything |
1937 |
$sth = $dbh->prepare( |
1941 |
$sth = $dbh->prepare( |
1938 |
"UPDATE reserves SET biblionumber = ? WHERE biblionumber = ?"); |
1942 |
"UPDATE holds SET biblio_id = ? WHERE biblio_id = ?"); |
1939 |
$sth->execute( $to_biblio, $from_biblio ); |
1943 |
$sth->execute( $to_biblio, $from_biblio ); |
1940 |
|
1944 |
|
1941 |
# Reorder by date |
1945 |
# Reorder by date |
1942 |
# don't reorder those already waiting |
1946 |
# don't reorder those already waiting |
1943 |
|
1947 |
|
1944 |
$sth = $dbh->prepare( |
1948 |
$sth = $dbh->prepare( |
1945 |
"SELECT * FROM reserves WHERE biblionumber = ? AND (found <> ? AND found <> ? OR found is NULL) ORDER BY reservedate ASC" |
1949 |
"SELECT id FROM holds WHERE biblio_id = ? AND status = 'placed' AND completed = 0 ORDER BY placing_date ASC" |
1946 |
); |
1950 |
); |
1947 |
my $upd_sth = $dbh->prepare( |
1951 |
my $upd_sth = $dbh->prepare( |
1948 |
"UPDATE reserves SET priority = ? WHERE biblionumber = ? AND borrowernumber = ? |
1952 |
"UPDATE holds SET priority = ? WHERE id = ? " |
1949 |
AND reservedate = ? AND (itemnumber = ? or itemnumber is NULL) " |
|
|
1950 |
); |
1953 |
); |
1951 |
$sth->execute( $to_biblio, 'W', 'T' ); |
1954 |
$sth->execute( $to_biblio ); |
1952 |
my $priority = 1; |
1955 |
my $priority = 1; |
1953 |
while ( my $reserve = $sth->fetchrow_hashref() ) { |
1956 |
while ( my $reserve = $sth->fetchrow_hashref() ) { |
1954 |
$upd_sth->execute( |
1957 |
$upd_sth->execute( |
1955 |
$priority, $to_biblio, |
1958 |
$priority, |
1956 |
$reserve->{'borrowernumber'}, $reserve->{'reservedate'}, |
1959 |
$reserve->{'id'} |
1957 |
$reserve->{'itemnumber'} |
|
|
1958 |
); |
1960 |
); |
1959 |
$priority++; |
1961 |
$priority++; |
1960 |
} |
1962 |
} |
Lines 1985-2024
sub RevertWaitingStatus {
Link Here
|
1985 |
|
1987 |
|
1986 |
## Get the waiting reserve we want to revert |
1988 |
## Get the waiting reserve we want to revert |
1987 |
my $query = " |
1989 |
my $query = " |
1988 |
SELECT * FROM reserves |
1990 |
SELECT * FROM holds |
1989 |
WHERE itemnumber = ? |
1991 |
WHERE item_id = ? |
1990 |
AND found IS NOT NULL |
1992 |
AND status <> 'placed' AND completed = 0 |
1991 |
"; |
1993 |
"; |
1992 |
my $sth = $dbh->prepare( $query ); |
1994 |
my $sth = $dbh->prepare( $query ); |
1993 |
$sth->execute( $itemnumber ); |
1995 |
$sth->execute( $itemnumber ); |
1994 |
my $reserve = $sth->fetchrow_hashref(); |
1996 |
my $reserve = $sth->fetchrow_hashref(); |
1995 |
|
1997 |
|
1996 |
my $hold = Koha::Holds->find( $reserve->{reserve_id} ); # TODO Remove the next raw SQL statements and use this instead |
1998 |
my $hold = Koha::Holds->find( $reserve->{id} ); # TODO Remove the next raw SQL statements and use this instead |
1997 |
|
1999 |
|
1998 |
## Increment the priority of all other non-waiting |
2000 |
## Increment the priority of all other non-waiting |
1999 |
## reserves for this bib record |
2001 |
## reserves for this bib record |
2000 |
$query = " |
2002 |
$query = " |
2001 |
UPDATE reserves |
2003 |
UPDATE holds |
2002 |
SET |
2004 |
SET |
2003 |
priority = priority + 1 |
2005 |
priority = priority + 1 |
2004 |
WHERE |
2006 |
WHERE |
2005 |
biblionumber = ? |
2007 |
biblio_id = ? |
2006 |
AND |
2008 |
AND |
2007 |
priority > 0 |
2009 |
priority > 0 |
2008 |
"; |
2010 |
"; |
2009 |
$sth = $dbh->prepare( $query ); |
2011 |
$sth = $dbh->prepare( $query ); |
2010 |
$sth->execute( $reserve->{'biblionumber'} ); |
2012 |
$sth->execute( $reserve->{'biblio_id'} ); |
2011 |
|
2013 |
|
2012 |
$hold->set( |
2014 |
$hold->set( |
2013 |
{ |
2015 |
{ |
2014 |
priority => 1, |
2016 |
priority => 1, |
2015 |
found => undef, |
2017 |
status => 'placed', |
2016 |
waitingdate => undef, |
2018 |
waiting_date => undef, |
2017 |
itemnumber => $hold->item_level_hold ? $hold->itemnumber : undef, |
2019 |
item_id => $hold->item_level ? $hold->item_id : undef, |
2018 |
} |
2020 |
} |
2019 |
)->store(); |
2021 |
)->store(); |
2020 |
|
2022 |
|
2021 |
_FixPriority( { biblionumber => $reserve->{biblionumber} } ); |
2023 |
_FixPriority( { biblionumber => $reserve->{biblio_id} } ); |
2022 |
|
2024 |
|
2023 |
return $hold; |
2025 |
return $hold; |
2024 |
} |
2026 |
} |
Lines 2066-2082
sub ReserveSlip {
Link Here
|
2066 |
|
2068 |
|
2067 |
$hold = Koha::Holds->search( |
2069 |
$hold = Koha::Holds->search( |
2068 |
{ |
2070 |
{ |
2069 |
biblionumber => $biblionumber, |
2071 |
biblio_id => $biblionumber, |
2070 |
borrowernumber => $borrowernumber, |
2072 |
patron_id => $borrowernumber, |
2071 |
itemnumber => $itemnumber |
2073 |
item_id => $itemnumber, |
|
|
2074 |
completed => 0 |
2072 |
} |
2075 |
} |
2073 |
)->next; |
2076 |
)->next; |
2074 |
} |
2077 |
} |
2075 |
else { |
2078 |
else { |
2076 |
$hold = Koha::Holds->search( |
2079 |
$hold = Koha::Holds->search( |
2077 |
{ |
2080 |
{ |
2078 |
biblionumber => $biblionumber, |
2081 |
biblio_id => $biblionumber, |
2079 |
borrowernumber => $borrowernumber |
2082 |
patron_id => $borrowernumber, |
|
|
2083 |
completed => 0 |
2080 |
} |
2084 |
} |
2081 |
)->next; |
2085 |
)->next; |
2082 |
} |
2086 |
} |
Lines 2091-2101
sub ReserveSlip {
Link Here
|
2091 |
lang => $patron->lang, |
2095 |
lang => $patron->lang, |
2092 |
tables => { |
2096 |
tables => { |
2093 |
'reserves' => $reserve, |
2097 |
'reserves' => $reserve, |
2094 |
'branches' => $reserve->{branchcode}, |
2098 |
'branches' => $reserve->{pickup_library_id}, |
2095 |
'borrowers' => $reserve->{borrowernumber}, |
2099 |
'borrowers' => $reserve->{patron_id}, |
2096 |
'biblio' => $reserve->{biblionumber}, |
2100 |
'biblio' => $reserve->{biblio_id}, |
2097 |
'biblioitems' => $reserve->{biblionumber}, |
2101 |
'biblioitems' => $reserve->{biblio_id}, |
2098 |
'items' => $reserve->{itemnumber}, |
2102 |
'items' => $reserve->{item_id}, |
2099 |
}, |
2103 |
}, |
2100 |
); |
2104 |
); |
2101 |
} |
2105 |
} |
Lines 2149-2165
sub CalculatePriority {
Link Here
|
2149 |
my ( $biblionumber, $resdate ) = @_; |
2153 |
my ( $biblionumber, $resdate ) = @_; |
2150 |
|
2154 |
|
2151 |
my $sql = q{ |
2155 |
my $sql = q{ |
2152 |
SELECT COUNT(*) FROM reserves |
2156 |
SELECT COUNT(*) FROM holds |
2153 |
WHERE biblionumber = ? |
2157 |
WHERE biblio_id = ? |
2154 |
AND priority > 0 |
2158 |
AND priority > 0 |
2155 |
AND (found IS NULL OR found = '') |
2159 |
AND status='placed' |
2156 |
}; |
2160 |
}; |
2157 |
#skip found==W or found==T (waiting or transit holds) |
2161 |
#skip status==W or status==T (waiting or transit holds) |
2158 |
if( $resdate ) { |
2162 |
if( $resdate ) { |
2159 |
$sql.= ' AND ( reservedate <= ? )'; |
2163 |
$sql.= ' AND ( placing_date <= ? )'; |
2160 |
} |
2164 |
} |
2161 |
else { |
2165 |
else { |
2162 |
$sql.= ' AND ( reservedate < NOW() )'; |
2166 |
$sql.= ' AND ( placing_date < NOW() )'; |
2163 |
} |
2167 |
} |
2164 |
my $dbh = C4::Context->dbh(); |
2168 |
my $dbh = C4::Context->dbh(); |
2165 |
my @row = $dbh->selectrow_array( |
2169 |
my @row = $dbh->selectrow_array( |
Lines 2176-2194
sub CalculatePriority {
Link Here
|
2176 |
my $bool = IsItemFoundHold( $itemnumber ); |
2180 |
my $bool = IsItemFoundHold( $itemnumber ); |
2177 |
|
2181 |
|
2178 |
Returns true if the item is currently on hold |
2182 |
Returns true if the item is currently on hold |
2179 |
and that hold has a non-null found status ( W, T, etc. ) |
2183 |
and that hold has a status of waiting or in_transit |
2180 |
|
2184 |
|
2181 |
=cut |
2185 |
=cut |
2182 |
|
2186 |
|
2183 |
sub IsItemOnHoldAndFound { |
2187 |
sub IsItemOnHoldAndFound { |
2184 |
my ($itemnumber) = @_; |
2188 |
my ($itemnumber) = @_; |
2185 |
|
2189 |
|
2186 |
my $rs = Koha::Database->new()->schema()->resultset('Reserve'); |
2190 |
my $rs = Koha::Database->new()->schema()->resultset('Hold'); |
2187 |
|
2191 |
|
2188 |
my $found = $rs->count( |
2192 |
my $found = $rs->count( |
2189 |
{ |
2193 |
{ |
2190 |
itemnumber => $itemnumber, |
2194 |
item_id => $itemnumber, |
2191 |
found => { '!=' => undef } |
2195 |
status => { '-in' => ['waiting', 'in_transit'] } |
2192 |
} |
2196 |
} |
2193 |
); |
2197 |
); |
2194 |
|
2198 |
|