Lines 198-203
$template->param(
Link Here
|
198 |
multi_hold => $multi_hold, |
198 |
multi_hold => $multi_hold, |
199 |
); |
199 |
); |
200 |
|
200 |
|
|
|
201 |
# If we are coming from the search result and only 1 is selected |
202 |
$biblionumber ||= $biblionumbers[0] unless $multi_hold; |
203 |
|
201 |
# If we have the borrowernumber because we've performed an action, then we |
204 |
# If we have the borrowernumber because we've performed an action, then we |
202 |
# don't want to try to place another reserve. |
205 |
# don't want to try to place another reserve. |
203 |
if ($borrowernumber_hold && !$action) { |
206 |
if ($borrowernumber_hold && !$action) { |
Lines 293-696
$template->param(
Link Here
|
293 |
messageclub => $messageclub |
296 |
messageclub => $messageclub |
294 |
); |
297 |
); |
295 |
|
298 |
|
296 |
# FIXME launch another time GetMember perhaps until (Joubu: Why?) |
|
|
297 |
my $patron = Koha::Patrons->find( $borrowernumber_hold ); |
298 |
|
299 |
if ( $patron && $multi_hold ) { |
300 |
my @multi_pickup_locations = |
301 |
Koha::Biblios->search( { biblionumber => \@biblionumbers } ) |
302 |
->pickup_locations( { patron => $patron } ); |
303 |
$template->param( multi_pickup_locations => \@multi_pickup_locations ); |
304 |
} |
305 |
|
299 |
|
306 |
my $logged_in_patron = Koha::Patrons->find( $borrowernumber ); |
300 |
if ( $club_hold or $borrowernumber_hold ) { |
|
|
301 |
# FIXME launch another time GetMember perhaps until (Joubu: Why?) |
302 |
my $patron = Koha::Patrons->find( $borrowernumber_hold ); |
307 |
|
303 |
|
308 |
my $wants_check; |
304 |
if ( $patron && $multi_hold ) { |
309 |
if ($patron) { |
305 |
my @multi_pickup_locations = |
310 |
$wants_check = $patron->wants_check_for_previous_checkout; |
306 |
Koha::Biblios->search( { biblionumber => \@biblionumbers } ) |
311 |
} |
307 |
->pickup_locations( { patron => $patron } ); |
312 |
my $itemdata_enumchron = 0; |
308 |
$template->param( multi_pickup_locations => \@multi_pickup_locations ); |
313 |
my $itemdata_ccode = 0; |
309 |
} |
314 |
my @biblioloop = (); |
|
|
315 |
my $no_reserves_allowed = 0; |
316 |
foreach my $biblionumber (@biblionumbers) { |
317 |
next unless $biblionumber =~ m|^\d+$|; |
318 |
|
310 |
|
319 |
my %biblioloopiter = (); |
311 |
my $logged_in_patron = Koha::Patrons->find( $borrowernumber ); |
320 |
|
312 |
|
321 |
my $biblio = Koha::Biblios->find( $biblionumber ); |
313 |
my $wants_check; |
322 |
unless ($biblio) { |
314 |
if ($patron) { |
323 |
$biblioloopiter{noitems} = 1; |
315 |
$wants_check = $patron->wants_check_for_previous_checkout; |
324 |
$template->param('nobiblio' => 1); |
|
|
325 |
last; |
326 |
} |
316 |
} |
|
|
317 |
my $itemdata_enumchron = 0; |
318 |
my $itemdata_ccode = 0; |
319 |
my @biblioloop = (); |
320 |
my $no_reserves_allowed = 0; |
321 |
foreach my $biblionumber (@biblionumbers) { |
322 |
next unless $biblionumber =~ m|^\d+$|; |
323 |
|
324 |
my %biblioloopiter = (); |
325 |
|
326 |
my $biblio = Koha::Biblios->find( $biblionumber ); |
327 |
unless ($biblio) { |
328 |
$biblioloopiter{noitems} = 1; |
329 |
$template->param('nobiblio' => 1); |
330 |
last; |
331 |
} |
327 |
|
332 |
|
328 |
if ( $patron ) { |
333 |
if ( $patron ) { |
329 |
{ # CanBookBeReserved |
334 |
{ # CanBookBeReserved |
330 |
my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber ); |
335 |
my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber ); |
331 |
if ( $canReserve->{status} eq 'OK' ) { |
336 |
if ( $canReserve->{status} eq 'OK' ) { |
332 |
|
337 |
|
333 |
#All is OK and we can continue |
338 |
#All is OK and we can continue |
334 |
} |
339 |
} |
335 |
elsif ( $canReserve->{status} eq 'noReservesAllowed' || $canReserve->{status} eq 'notReservable' ) { |
340 |
elsif ( $canReserve->{status} eq 'noReservesAllowed' || $canReserve->{status} eq 'notReservable' ) { |
336 |
$no_reserves_allowed = 1; |
341 |
$no_reserves_allowed = 1; |
337 |
} |
342 |
} |
338 |
elsif ( $canReserve->{status} eq 'tooManyReserves' ) { |
343 |
elsif ( $canReserve->{status} eq 'tooManyReserves' ) { |
339 |
$exceeded_maxreserves = 1; |
344 |
$exceeded_maxreserves = 1; |
340 |
$template->param( maxreserves => $canReserve->{limit} ); |
345 |
$template->param( maxreserves => $canReserve->{limit} ); |
341 |
} |
346 |
} |
342 |
elsif ( $canReserve->{status} eq 'tooManyHoldsForThisRecord' ) { |
347 |
elsif ( $canReserve->{status} eq 'tooManyHoldsForThisRecord' ) { |
343 |
$exceeded_holds_per_record = 1; |
348 |
$exceeded_holds_per_record = 1; |
344 |
$biblioloopiter{ $canReserve->{status} } = 1; |
349 |
$biblioloopiter{ $canReserve->{status} } = 1; |
345 |
} |
350 |
} |
346 |
elsif ( $canReserve->{status} eq 'ageRestricted' ) { |
351 |
elsif ( $canReserve->{status} eq 'ageRestricted' ) { |
347 |
$template->param( $canReserve->{status} => 1 ); |
352 |
$template->param( $canReserve->{status} => 1 ); |
348 |
$biblioloopiter{ $canReserve->{status} } = 1; |
353 |
$biblioloopiter{ $canReserve->{status} } = 1; |
349 |
} |
354 |
} |
350 |
elsif ( $canReserve->{status} eq 'alreadypossession' ) { |
355 |
elsif ( $canReserve->{status} eq 'alreadypossession' ) { |
351 |
$template->param( $canReserve->{status} => 1); |
356 |
$template->param( $canReserve->{status} => 1); |
352 |
$biblioloopiter{ $canReserve->{status} } = 1; |
357 |
$biblioloopiter{ $canReserve->{status} } = 1; |
353 |
} |
358 |
} |
354 |
else { |
359 |
else { |
355 |
$biblioloopiter{ $canReserve->{status} } = 1; |
360 |
$biblioloopiter{ $canReserve->{status} } = 1; |
|
|
361 |
} |
356 |
} |
362 |
} |
357 |
} |
|
|
358 |
|
363 |
|
359 |
# For multiple holds per record, if a patron has previously placed a hold, |
364 |
# For multiple holds per record, if a patron has previously placed a hold, |
360 |
# the patron can only place more holds of the same type. That is, if the |
365 |
# the patron can only place more holds of the same type. That is, if the |
361 |
# patron placed a record level hold, all the holds the patron places must |
366 |
# patron placed a record level hold, all the holds the patron places must |
362 |
# be record level. If the patron placed an item level hold, all holds |
367 |
# be record level. If the patron placed an item level hold, all holds |
363 |
# the patron places must be item level |
368 |
# the patron places must be item level |
364 |
my $holds = Koha::Holds->search( |
369 |
my $holds = Koha::Holds->search( |
365 |
{ |
370 |
{ |
366 |
borrowernumber => $patron->borrowernumber, |
371 |
borrowernumber => $patron->borrowernumber, |
367 |
biblionumber => $biblionumber, |
372 |
biblionumber => $biblionumber, |
368 |
found => undef, |
373 |
found => undef, |
369 |
} |
374 |
} |
370 |
); |
375 |
); |
371 |
$template->param( force_hold_level => $holds->forced_hold_level() ); |
376 |
$template->param( force_hold_level => $holds->forced_hold_level() ); |
372 |
|
377 |
|
373 |
# For a librarian to be able to place multiple record holds for a patron for a record, |
378 |
# For a librarian to be able to place multiple record holds for a patron for a record, |
374 |
# we must find out what the maximum number of holds they can place for the patron is |
379 |
# we must find out what the maximum number of holds they can place for the patron is |
375 |
my $max_holds_for_record = GetMaxPatronHoldsForRecord( $patron->borrowernumber, $biblionumber ); |
380 |
my $max_holds_for_record = GetMaxPatronHoldsForRecord( $patron->borrowernumber, $biblionumber ); |
376 |
my $remaining_holds_for_record = $max_holds_for_record - $holds->count(); |
381 |
my $remaining_holds_for_record = $max_holds_for_record - $holds->count(); |
377 |
$biblioloopiter{remaining_holds_for_record} = $max_holds_for_record; |
382 |
$biblioloopiter{remaining_holds_for_record} = $max_holds_for_record; |
378 |
$template->param( max_holds_for_record => $max_holds_for_record ); |
383 |
$template->param( max_holds_for_record => $max_holds_for_record ); |
379 |
$template->param( remaining_holds_for_record => $remaining_holds_for_record ); |
384 |
$template->param( remaining_holds_for_record => $remaining_holds_for_record ); |
380 |
} |
385 |
} |
381 |
|
386 |
|
382 |
# adding a fixed value for priority options |
387 |
# adding a fixed value for priority options |
383 |
my $fixedRank = $biblio->holds->count + 1; |
388 |
my $fixedRank = $biblio->holds->count + 1; |
384 |
|
389 |
|
385 |
my @items = $biblio->items->as_list; |
390 |
my @items = $biblio->items->as_list; |
386 |
|
391 |
|
387 |
my @host_items = $biblio->host_items->as_list; |
392 |
my @host_items = $biblio->host_items->as_list; |
388 |
if (@host_items) { |
393 |
if (@host_items) { |
389 |
push @items, @host_items; |
394 |
push @items, @host_items; |
390 |
} |
395 |
} |
391 |
|
396 |
|
392 |
unless ( @items ) { |
397 |
unless ( @items ) { |
393 |
# FIXME Then why do we continue? |
398 |
# FIXME Then why do we continue? |
394 |
$template->param('noitems' => 1) unless ( $multi_hold ); |
399 |
$template->param('noitems' => 1) unless ( $multi_hold ); |
395 |
$biblioloopiter{noitems} = 1; |
400 |
$biblioloopiter{noitems} = 1; |
396 |
} |
401 |
} |
397 |
|
402 |
|
398 |
my @available_itemtypes; |
403 |
my @available_itemtypes; |
399 |
my $num_available = 0; |
404 |
my $num_available = 0; |
400 |
my $num_override = 0; |
405 |
my $num_override = 0; |
401 |
my $hiddencount = 0; |
406 |
my $hiddencount = 0; |
402 |
my $num_alreadyheld = 0; |
407 |
my $num_alreadyheld = 0; |
403 |
|
408 |
|
404 |
# iterating through all items first to check if any of them available |
409 |
# iterating through all items first to check if any of them available |
405 |
# to pass this value further inside down to IsAvailableForItemLevelRequest to |
410 |
# to pass this value further inside down to IsAvailableForItemLevelRequest to |
406 |
# it's complicated logic to analyse. |
411 |
# it's complicated logic to analyse. |
407 |
# (before this loop was inside that sub loop so it was O(n^2) ) |
412 |
# (before this loop was inside that sub loop so it was O(n^2) ) |
408 |
my $items_any_available; |
413 |
my $items_any_available; |
409 |
$items_any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio->biblionumber, patron => $patron }) |
414 |
$items_any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio->biblionumber, patron => $patron }) |
410 |
if $patron; |
415 |
if $patron; |
411 |
|
416 |
|
412 |
for my $item_object ( @items ) { |
417 |
for my $item_object ( @items ) { |
413 |
my $do_check; |
418 |
my $do_check; |
414 |
my $item = $item_object->unblessed; |
419 |
my $item = $item_object->unblessed; |
415 |
if ( $patron ) { |
420 |
if ( $patron ) { |
416 |
$do_check = $patron->do_check_for_previous_checkout($item) if $wants_check; |
421 |
$do_check = $patron->do_check_for_previous_checkout($item) if $wants_check; |
417 |
if ( $do_check && $wants_check ) { |
422 |
if ( $do_check && $wants_check ) { |
418 |
$item->{checked_previously} = $do_check; |
423 |
$item->{checked_previously} = $do_check; |
419 |
if ( $multi_hold ) { |
424 |
if ( $multi_hold ) { |
420 |
$biblioloopiter{checked_previously} = $do_check; |
425 |
$biblioloopiter{checked_previously} = $do_check; |
421 |
} else { |
426 |
} else { |
422 |
$template->param( checked_previously => $do_check ); |
427 |
$template->param( checked_previously => $do_check ); |
|
|
428 |
} |
423 |
} |
429 |
} |
424 |
} |
430 |
} |
425 |
} |
|
|
426 |
|
431 |
|
427 |
$item->{itemtype} = $itemtypes->{ $item_object->effective_itemtype }; |
432 |
$item->{itemtype} = $itemtypes->{ $item_object->effective_itemtype }; |
428 |
|
433 |
|
429 |
if($item->{biblionumber} ne $biblio->biblionumber){ |
434 |
if($item->{biblionumber} ne $biblio->biblionumber){ |
430 |
$item->{hosttitle} = Koha::Biblios->find( $item->{biblionumber} )->title; |
435 |
$item->{hosttitle} = Koha::Biblios->find( $item->{biblionumber} )->title; |
431 |
} |
436 |
} |
432 |
|
437 |
|
433 |
# if the item is currently on loan, we display its return date and |
438 |
# if the item is currently on loan, we display its return date and |
434 |
# change the background color |
439 |
# change the background color |
435 |
my $issue = $item_object->checkout; |
440 |
my $issue = $item_object->checkout; |
436 |
if ( $issue ) { # FIXME must be moved to the template |
441 |
if ( $issue ) { # FIXME must be moved to the template |
437 |
$item->{date_due} = $issue->date_due; |
442 |
$item->{date_due} = $issue->date_due; |
438 |
$item->{backgroundcolor} = 'onloan'; |
443 |
$item->{backgroundcolor} = 'onloan'; |
439 |
} |
444 |
} |
440 |
|
445 |
|
441 |
# checking reserve |
446 |
# checking reserve |
442 |
my $holds = $item_object->current_holds; |
447 |
my $holds = $item_object->current_holds; |
443 |
if ( my $first_hold = $holds->next ) { |
448 |
if ( my $first_hold = $holds->next ) { |
444 |
my $p = Koha::Patrons->find( $first_hold->borrowernumber ); |
449 |
my $p = Koha::Patrons->find( $first_hold->borrowernumber ); |
445 |
|
450 |
|
446 |
$item->{backgroundcolor} = 'reserved'; |
451 |
$item->{backgroundcolor} = 'reserved'; |
447 |
$item->{reservedate} = output_pref({ dt => dt_from_string( $first_hold->reservedate ), dateonly => 1 }); # FIXME Should be formatted in the template |
452 |
$item->{reservedate} = output_pref({ dt => dt_from_string( $first_hold->reservedate ), dateonly => 1 }); # FIXME Should be formatted in the template |
448 |
$item->{ReservedFor} = $p; |
453 |
$item->{ReservedFor} = $p; |
449 |
$item->{ExpectedAtLibrary} = $first_hold->branchcode; |
454 |
$item->{ExpectedAtLibrary} = $first_hold->branchcode; |
450 |
$item->{waitingdate} = $first_hold->waitingdate; |
455 |
$item->{waitingdate} = $first_hold->waitingdate; |
451 |
} |
456 |
} |
452 |
|
457 |
|
453 |
# Management of the notforloan document |
458 |
# Management of the notforloan document |
454 |
if ( $item->{notforloan} ) { |
459 |
if ( $item->{notforloan} ) { |
455 |
$item->{backgroundcolor} = 'other'; |
460 |
$item->{backgroundcolor} = 'other'; |
456 |
} |
461 |
} |
457 |
|
462 |
|
458 |
# Management of lost or long overdue items |
463 |
# Management of lost or long overdue items |
459 |
if ( $item->{itemlost} ) { |
464 |
if ( $item->{itemlost} ) { |
460 |
$item->{backgroundcolor} = 'other'; |
465 |
$item->{backgroundcolor} = 'other'; |
461 |
if ($logged_in_patron->category->hidelostitems && !$showallitems) { |
466 |
if ($logged_in_patron->category->hidelostitems && !$showallitems) { |
462 |
$item->{hide} = 1; |
467 |
$item->{hide} = 1; |
463 |
$hiddencount++; |
468 |
$hiddencount++; |
|
|
469 |
} |
464 |
} |
470 |
} |
465 |
} |
|
|
466 |
|
471 |
|
467 |
# Check the transit status |
472 |
# Check the transit status |
468 |
my ( $transfertwhen, $transfertfrom, $transfertto ) = |
473 |
my ( $transfertwhen, $transfertfrom, $transfertto ) = |
469 |
GetTransfers($item_object->itemnumber); # FIXME replace with get_transfer |
474 |
GetTransfers($item_object->itemnumber); # FIXME replace with get_transfer |
470 |
|
475 |
|
471 |
if ( defined $transfertwhen && $transfertwhen ne '' ) { |
476 |
if ( defined $transfertwhen && $transfertwhen ne '' ) { |
472 |
$item->{transfertwhen} = output_pref({ dt => dt_from_string( $transfertwhen ), dateonly => 1 }); |
477 |
$item->{transfertwhen} = output_pref({ dt => dt_from_string( $transfertwhen ), dateonly => 1 }); |
473 |
$item->{transfertfrom} = $transfertfrom; |
478 |
$item->{transfertfrom} = $transfertfrom; |
474 |
$item->{transfertto} = $transfertto; |
479 |
$item->{transfertto} = $transfertto; |
475 |
$item->{nocancel} = 1; |
480 |
$item->{nocancel} = 1; |
476 |
} |
481 |
} |
477 |
|
482 |
|
478 |
# If there is no loan, return and transfer, we show a checkbox. |
483 |
# If there is no loan, return and transfer, we show a checkbox. |
479 |
$item->{notforloan} ||= 0; |
484 |
$item->{notforloan} ||= 0; |
480 |
|
485 |
|
481 |
# if independent branches is on we need to check if the person can reserve |
486 |
# if independent branches is on we need to check if the person can reserve |
482 |
# for branches they arent logged in to |
487 |
# for branches they arent logged in to |
483 |
if ( C4::Context->preference("IndependentBranches") ) { |
488 |
if ( C4::Context->preference("IndependentBranches") ) { |
484 |
if (! C4::Context->preference("canreservefromotherbranches")){ |
489 |
if (! C4::Context->preference("canreservefromotherbranches")){ |
485 |
# can't reserve items so need to check if item homebranch and userenv branch match if not we can't reserve |
490 |
# can't reserve items so need to check if item homebranch and userenv branch match if not we can't reserve |
486 |
my $userenv = C4::Context->userenv; |
491 |
my $userenv = C4::Context->userenv; |
487 |
unless ( C4::Context->IsSuperLibrarian ) { |
492 |
unless ( C4::Context->IsSuperLibrarian ) { |
488 |
$item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} ); |
493 |
$item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} ); |
|
|
494 |
} |
489 |
} |
495 |
} |
490 |
} |
496 |
} |
491 |
} |
|
|
492 |
|
493 |
if ( $patron ) { |
494 |
my $patron_unblessed = $patron->unblessed; |
495 |
my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed); |
496 |
|
497 |
|
497 |
my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} ); |
498 |
if ( $patron ) { |
|
|
499 |
my $patron_unblessed = $patron->unblessed; |
500 |
my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed); |
498 |
|
501 |
|
499 |
$item->{'holdallowed'} = $branchitemrule->{'holdallowed'}; |
502 |
my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} ); |
500 |
|
503 |
|
501 |
my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $item_object->itemnumber )->{status}; |
504 |
$item->{'holdallowed'} = $branchitemrule->{'holdallowed'}; |
502 |
$item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' ); |
|
|
503 |
|
505 |
|
504 |
$item->{item_level_holds} = Koha::CirculationRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } ); |
506 |
my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $item_object->itemnumber )->{status}; |
|
|
507 |
$item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' ); |
505 |
|
508 |
|
506 |
if ( |
509 |
$item->{item_level_holds} = Koha::CirculationRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } ); |
507 |
!$item->{cantreserve} |
|
|
508 |
&& !$exceeded_maxreserves |
509 |
&& $can_item_be_reserved eq 'OK' |
510 |
# items_any_available defined outside of the current loop, |
511 |
# so we avoiding loop inside IsAvailableForItemLevelRequest: |
512 |
&& IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available) |
513 |
) |
514 |
{ |
515 |
# Send the pickup locations count to the UI, the pickup locations will be pulled using the API |
516 |
my $pickup_locations = $item_object->pickup_locations({ patron => $patron }); |
517 |
$item->{pickup_locations_count} = $pickup_locations->count; |
518 |
if ( $item->{pickup_locations_count} > 0 ) { |
519 |
$num_available++; |
520 |
$item->{available} = 1; |
521 |
# pass the holding branch for use as default |
522 |
my $default_pickup_location = $pickup_locations->search({ branchcode => $item->{holdingbranch} })->next; |
523 |
$item->{default_pickup_location} = $default_pickup_location; |
524 |
} |
525 |
else { |
526 |
$item->{available} = 0; |
527 |
$item->{not_holdable} = "no_valid_pickup_location"; |
528 |
} |
529 |
|
510 |
|
530 |
push( @available_itemtypes, $item->{itype} ); |
511 |
if ( |
531 |
} |
512 |
!$item->{cantreserve} |
532 |
elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) { |
513 |
&& !$exceeded_maxreserves |
533 |
# If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules |
514 |
&& $can_item_be_reserved eq 'OK' |
534 |
# with the exception of itemAlreadyOnHold because, you know, the item is already on hold |
515 |
# items_any_available defined outside of the current loop, |
535 |
if ( $can_item_be_reserved ne 'itemAlreadyOnHold' ) { |
516 |
# so we avoiding loop inside IsAvailableForItemLevelRequest: |
|
|
517 |
&& IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available) |
518 |
) |
519 |
{ |
536 |
# Send the pickup locations count to the UI, the pickup locations will be pulled using the API |
520 |
# Send the pickup locations count to the UI, the pickup locations will be pulled using the API |
537 |
my @pickup_locations = $item_object->pickup_locations({ patron => $patron })->as_list; |
521 |
my $pickup_locations = $item_object->pickup_locations({ patron => $patron }); |
538 |
$item->{pickup_locations_count} = scalar @pickup_locations; |
522 |
$item->{pickup_locations_count} = $pickup_locations->count; |
539 |
|
523 |
if ( $item->{pickup_locations_count} > 0 ) { |
540 |
if ( @pickup_locations ) { |
|
|
541 |
$num_available++; |
524 |
$num_available++; |
542 |
$item->{available} = 1; |
525 |
$item->{available} = 1; |
543 |
|
526 |
# pass the holding branch for use as default |
544 |
my $default_pickup_location; |
527 |
my $default_pickup_location = $pickup_locations->search({ branchcode => $item->{holdingbranch} })->next; |
545 |
|
|
|
546 |
# Default to logged-in, if valid |
547 |
if ( C4::Context->userenv->{branch} ) { |
548 |
($default_pickup_location) = grep { $_->branchcode eq C4::Context->userenv->{branch} } @pickup_locations; |
549 |
} |
550 |
|
551 |
$item->{default_pickup_location} = $default_pickup_location; |
528 |
$item->{default_pickup_location} = $default_pickup_location; |
552 |
} |
529 |
} |
553 |
else { |
530 |
else { |
554 |
$item->{available} = 0; |
531 |
$item->{available} = 0; |
555 |
$item->{not_holdable} = "no_valid_pickup_location"; |
532 |
$item->{not_holdable} = "no_valid_pickup_location"; |
556 |
} |
533 |
} |
557 |
} else { $num_alreadyheld++ } |
|
|
558 |
|
534 |
|
559 |
push( @available_itemtypes, $item->{itype} ); |
535 |
push( @available_itemtypes, $item->{itype} ); |
560 |
} |
536 |
} |
|
|
537 |
elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) { |
538 |
# If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules |
539 |
# with the exception of itemAlreadyOnHold because, you know, the item is already on hold |
540 |
if ( $can_item_be_reserved ne 'itemAlreadyOnHold' ) { |
541 |
# Send the pickup locations count to the UI, the pickup locations will be pulled using the API |
542 |
my @pickup_locations = $item_object->pickup_locations({ patron => $patron })->as_list; |
543 |
$item->{pickup_locations_count} = scalar @pickup_locations; |
544 |
|
545 |
if ( @pickup_locations ) { |
546 |
$num_available++; |
547 |
$item->{available} = 1; |
548 |
|
549 |
my $default_pickup_location; |
550 |
|
551 |
# Default to logged-in, if valid |
552 |
if ( C4::Context->userenv->{branch} ) { |
553 |
($default_pickup_location) = grep { $_->branchcode eq C4::Context->userenv->{branch} } @pickup_locations; |
554 |
} |
555 |
|
556 |
$item->{default_pickup_location} = $default_pickup_location; |
557 |
} |
558 |
else { |
559 |
$item->{available} = 0; |
560 |
$item->{not_holdable} = "no_valid_pickup_location"; |
561 |
} |
562 |
} else { $num_alreadyheld++ } |
563 |
|
564 |
push( @available_itemtypes, $item->{itype} ); |
565 |
} |
561 |
|
566 |
|
562 |
# If none of the conditions hold true, then neither override nor available is set and the item cannot be checked |
567 |
# If none of the conditions hold true, then neither override nor available is set and the item cannot be checked |
563 |
|
568 |
|
564 |
# Show serial enumeration when needed |
569 |
# Show serial enumeration when needed |
565 |
if ($item->{enumchron}) { |
570 |
if ($item->{enumchron}) { |
566 |
$itemdata_enumchron = 1; |
571 |
$itemdata_enumchron = 1; |
567 |
} |
572 |
} |
568 |
# Show collection when needed |
573 |
# Show collection when needed |
569 |
if ($item->{ccode}) { |
574 |
if ($item->{ccode}) { |
570 |
$itemdata_ccode = 1; |
575 |
$itemdata_ccode = 1; |
|
|
576 |
} |
571 |
} |
577 |
} |
572 |
} |
|
|
573 |
|
578 |
|
574 |
push @{ $biblioloopiter{itemloop} }, $item; |
579 |
push @{ $biblioloopiter{itemloop} }, $item; |
575 |
} |
580 |
} |
576 |
|
581 |
|
577 |
$biblioloopiter{biblioitem} = $biblio->biblioitem; |
582 |
$biblioloopiter{biblioitem} = $biblio->biblioitem; |
578 |
|
583 |
|
579 |
# While we can't override an alreay held item, we should be able to override the others |
584 |
# While we can't override an alreay held item, we should be able to override the others |
580 |
# Unless all items are already held |
585 |
# Unless all items are already held |
581 |
if ( $num_override > 0 && ($num_override + $num_alreadyheld) == scalar( @{ $biblioloopiter{itemloop} } ) ) { |
586 |
if ( $num_override > 0 && ($num_override + $num_alreadyheld) == scalar( @{ $biblioloopiter{itemloop} } ) ) { |
582 |
# That is, if all items require an override |
587 |
# That is, if all items require an override |
583 |
$template->param( override_required => 1 ); |
588 |
$template->param( override_required => 1 ); |
584 |
} elsif ( $num_available == 0 ) { |
589 |
} elsif ( $num_available == 0 ) { |
585 |
$template->param( none_available => 1 ); |
590 |
$template->param( none_available => 1 ); |
586 |
$biblioloopiter{warn} = 1; |
591 |
$biblioloopiter{warn} = 1; |
587 |
$biblioloopiter{none_avail} = 1; |
592 |
$biblioloopiter{none_avail} = 1; |
588 |
} |
|
|
589 |
$template->param( hiddencount => $hiddencount); |
590 |
|
591 |
@available_itemtypes = uniq( @available_itemtypes ); |
592 |
$template->param( available_itemtypes => \@available_itemtypes ); |
593 |
|
594 |
# existingreserves building |
595 |
my @reserveloop; |
596 |
my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } ); |
597 |
foreach my $res ( |
598 |
sort { |
599 |
my $a_found = $a->found() || ''; |
600 |
my $b_found = $a->found() || ''; |
601 |
$a_found cmp $b_found; |
602 |
} @reserves |
603 |
) |
604 |
{ |
605 |
my %reserve; |
606 |
if ( $res->is_found() ) { |
607 |
$reserve{'holdingbranch'} = $res->item()->holdingbranch(); |
608 |
$reserve{'biblionumber'} = $res->item()->biblionumber(); |
609 |
$reserve{'barcodenumber'} = $res->item()->barcode(); |
610 |
$reserve{'wbrcode'} = $res->branchcode(); |
611 |
$reserve{'itemnumber'} = $res->itemnumber(); |
612 |
$reserve{'wbrname'} = $res->branch()->branchname(); |
613 |
$reserve{'atdestination'} = $res->is_at_destination(); |
614 |
$reserve{'desk_name'} = ( $res->desk() ) ? $res->desk()->desk_name() : '' ; |
615 |
$reserve{'found'} = $res->is_found(); |
616 |
$reserve{'inprocessing'} = $res->is_in_processing(); |
617 |
$reserve{'intransit'} = $res->is_in_transit(); |
618 |
} |
593 |
} |
619 |
elsif ( $res->priority() > 0 ) { |
594 |
$template->param( hiddencount => $hiddencount); |
620 |
if ( my $item = $res->item() ) { |
595 |
|
621 |
$reserve{'itemnumber'} = $item->id(); |
596 |
@available_itemtypes = uniq( @available_itemtypes ); |
622 |
$reserve{'barcodenumber'} = $item->barcode(); |
597 |
$template->param( available_itemtypes => \@available_itemtypes ); |
623 |
$reserve{'item_level_hold'} = 1; |
598 |
|
|
|
599 |
# existingreserves building |
600 |
my @reserveloop; |
601 |
my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } ); |
602 |
foreach my $res ( |
603 |
sort { |
604 |
my $a_found = $a->found() || ''; |
605 |
my $b_found = $a->found() || ''; |
606 |
$a_found cmp $b_found; |
607 |
} @reserves |
608 |
) |
609 |
{ |
610 |
my %reserve; |
611 |
if ( $res->is_found() ) { |
612 |
$reserve{'holdingbranch'} = $res->item()->holdingbranch(); |
613 |
$reserve{'biblionumber'} = $res->item()->biblionumber(); |
614 |
$reserve{'barcodenumber'} = $res->item()->barcode(); |
615 |
$reserve{'wbrcode'} = $res->branchcode(); |
616 |
$reserve{'itemnumber'} = $res->itemnumber(); |
617 |
$reserve{'wbrname'} = $res->branch()->branchname(); |
618 |
$reserve{'atdestination'} = $res->is_at_destination(); |
619 |
$reserve{'desk_name'} = ( $res->desk() ) ? $res->desk()->desk_name() : '' ; |
620 |
$reserve{'found'} = $res->is_found(); |
621 |
$reserve{'inprocessing'} = $res->is_in_processing(); |
622 |
$reserve{'intransit'} = $res->is_in_transit(); |
623 |
} |
624 |
elsif ( $res->priority() > 0 ) { |
625 |
if ( my $item = $res->item() ) { |
626 |
$reserve{'itemnumber'} = $item->id(); |
627 |
$reserve{'barcodenumber'} = $item->barcode(); |
628 |
$reserve{'item_level_hold'} = 1; |
629 |
} |
624 |
} |
630 |
} |
|
|
631 |
|
632 |
$reserve{'expirationdate'} = $res->expirationdate; |
633 |
$reserve{'date'} = $res->reservedate; |
634 |
$reserve{'borrowernumber'} = $res->borrowernumber(); |
635 |
$reserve{'biblionumber'} = $res->biblionumber(); |
636 |
$reserve{'patron'} = $res->borrower; |
637 |
$reserve{'notes'} = $res->reservenotes(); |
638 |
$reserve{'waiting_date'} = $res->waitingdate(); |
639 |
$reserve{'ccode'} = $res->item() ? $res->item()->ccode() : undef; |
640 |
$reserve{'barcode'} = $res->item() ? $res->item()->barcode() : undef; |
641 |
$reserve{'priority'} = $res->priority(); |
642 |
$reserve{'lowestPriority'} = $res->lowestPriority(); |
643 |
$reserve{'suspend'} = $res->suspend(); |
644 |
$reserve{'suspend_until'} = $res->suspend_until(); |
645 |
$reserve{'reserve_id'} = $res->reserve_id(); |
646 |
$reserve{itemtype} = $res->itemtype(); |
647 |
$reserve{branchcode} = $res->branchcode(); |
648 |
$reserve{non_priority} = $res->non_priority(); |
649 |
$reserve{object} = $res; |
650 |
|
651 |
push( @reserveloop, \%reserve ); |
625 |
} |
652 |
} |
626 |
|
653 |
|
627 |
$reserve{'expirationdate'} = $res->expirationdate; |
654 |
# get the time for the form name... |
628 |
$reserve{'date'} = $res->reservedate; |
655 |
my $time = time(); |
629 |
$reserve{'borrowernumber'} = $res->borrowernumber(); |
|
|
630 |
$reserve{'biblionumber'} = $res->biblionumber(); |
631 |
$reserve{'patron'} = $res->borrower; |
632 |
$reserve{'notes'} = $res->reservenotes(); |
633 |
$reserve{'waiting_date'} = $res->waitingdate(); |
634 |
$reserve{'ccode'} = $res->item() ? $res->item()->ccode() : undef; |
635 |
$reserve{'barcode'} = $res->item() ? $res->item()->barcode() : undef; |
636 |
$reserve{'priority'} = $res->priority(); |
637 |
$reserve{'lowestPriority'} = $res->lowestPriority(); |
638 |
$reserve{'suspend'} = $res->suspend(); |
639 |
$reserve{'suspend_until'} = $res->suspend_until(); |
640 |
$reserve{'reserve_id'} = $res->reserve_id(); |
641 |
$reserve{itemtype} = $res->itemtype(); |
642 |
$reserve{branchcode} = $res->branchcode(); |
643 |
$reserve{non_priority} = $res->non_priority(); |
644 |
$reserve{object} = $res; |
645 |
|
646 |
push( @reserveloop, \%reserve ); |
647 |
} |
648 |
|
656 |
|
649 |
# get the time for the form name... |
657 |
$template->param( |
650 |
my $time = time(); |
658 |
time => $time, |
|
|
659 |
fixedRank => $fixedRank, |
660 |
); |
651 |
|
661 |
|
652 |
$template->param( |
662 |
# display infos |
653 |
time => $time, |
663 |
$template->param( |
654 |
fixedRank => $fixedRank, |
664 |
itemdata_enumchron => $itemdata_enumchron, |
655 |
); |
665 |
itemdata_ccode => $itemdata_ccode, |
|
|
666 |
date => $date, |
667 |
biblionumber => $biblionumber, |
668 |
findborrower => $findborrower, |
669 |
biblio => $biblio, |
670 |
holdsview => 1, |
671 |
C4::Search::enabled_staff_search_views, |
672 |
); |
673 |
|
674 |
$biblioloopiter{biblionumber} = $biblionumber; |
675 |
$biblioloopiter{title} = $biblio->title; |
676 |
$biblioloopiter{rank} = $fixedRank; |
677 |
$biblioloopiter{reserveloop} = \@reserveloop; |
678 |
|
679 |
if (@reserveloop) { |
680 |
$template->param( reserveloop => \@reserveloop ); |
681 |
} |
656 |
|
682 |
|
657 |
# display infos |
683 |
if ( $patron ) { |
658 |
$template->param( |
684 |
# Add the valid pickup locations |
659 |
itemdata_enumchron => $itemdata_enumchron, |
685 |
my @pickup_locations = $biblio->pickup_locations({ patron => $patron }); |
660 |
itemdata_ccode => $itemdata_ccode, |
686 |
$biblioloopiter{pickup_locations} = \@pickup_locations; |
661 |
date => $date, |
687 |
$biblioloopiter{pickup_locations_codes} = [ map { $_->branchcode } @pickup_locations ]; |
662 |
biblionumber => $biblionumber, |
688 |
} |
663 |
findborrower => $findborrower, |
|
|
664 |
biblio => $biblio, |
665 |
holdsview => 1, |
666 |
C4::Search::enabled_staff_search_views, |
667 |
); |
668 |
|
669 |
$biblioloopiter{biblionumber} = $biblionumber; |
670 |
$biblioloopiter{title} = $biblio->title; |
671 |
$biblioloopiter{rank} = $fixedRank; |
672 |
$biblioloopiter{reserveloop} = \@reserveloop; |
673 |
|
674 |
if (@reserveloop) { |
675 |
$template->param( reserveloop => \@reserveloop ); |
676 |
} |
677 |
|
689 |
|
678 |
if ( $patron ) { |
690 |
push @biblioloop, \%biblioloopiter; |
679 |
# Add the valid pickup locations |
|
|
680 |
my @pickup_locations = $biblio->pickup_locations({ patron => $patron }); |
681 |
$biblioloopiter{pickup_locations} = \@pickup_locations; |
682 |
$biblioloopiter{pickup_locations_codes} = [ map { $_->branchcode } @pickup_locations ]; |
683 |
} |
691 |
} |
684 |
|
692 |
$template->param( biblioloop => \@biblioloop ); |
685 |
push @biblioloop, \%biblioloopiter; |
693 |
$template->param( no_reserves_allowed => $no_reserves_allowed ); |
|
|
694 |
$template->param( exceeded_maxreserves => $exceeded_maxreserves ); |
695 |
$template->param( exceeded_holds_per_record => $exceeded_holds_per_record ); |
696 |
$template->param( subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber)); |
697 |
} elsif ( ! $multi_hold ) { |
698 |
my $biblio = Koha::Biblios->find( $biblionumber ); |
699 |
$template->param( biblio => $biblio ); |
686 |
} |
700 |
} |
687 |
|
701 |
|
688 |
$template->param( biblioloop => \@biblioloop ); |
702 |
if ( $multi_hold ) { |
689 |
$template->param( no_reserves_allowed => $no_reserves_allowed ); |
703 |
$template->param( biblionumbers => join('/', @biblionumbers) ); |
690 |
$template->param( biblionumbers => join('/', @biblionumbers) ); |
704 |
} else { |
691 |
$template->param( exceeded_maxreserves => $exceeded_maxreserves ); |
705 |
$template->param( biblionumber => $biblionumber || $biblionumbers[0] ); |
692 |
$template->param( exceeded_holds_per_record => $exceeded_holds_per_record ); |
706 |
} |
693 |
$template->param( subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber)); |
|
|
694 |
|
707 |
|
695 |
# pass the userenv branch if no pickup location selected |
708 |
# pass the userenv branch if no pickup location selected |
696 |
$template->param( pickup => $pickup || C4::Context->userenv->{branch} ); |
709 |
$template->param( pickup => $pickup || C4::Context->userenv->{branch} ); |
697 |
- |
|
|