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