|
Lines 351-543
if (@$barcodes && $op eq 'cud-checkout') {
Link Here
|
| 351 |
} |
351 |
} |
| 352 |
}; |
352 |
}; |
| 353 |
|
353 |
|
| 354 |
my $blocker = $invalidduedate ? 1 : 0; |
354 |
my $blocker = $invalidduedate ? 1 : 0; |
| 355 |
|
355 |
|
| 356 |
$template_params->{alert} = $alerts; |
356 |
$template_params->{alert} = $alerts; |
| 357 |
$template_params->{messages} = $messages; |
357 |
$template_params->{messages} = $messages; |
| 358 |
|
358 |
|
| 359 |
my $item = Koha::Items->find({ barcode => $barcode }); |
359 |
my $item = Koha::Items->find({ barcode => $barcode }); |
| 360 |
|
360 |
|
| 361 |
my $biblio; |
361 |
my $biblio; |
| 362 |
if ( $item ) { |
362 |
if ( $item ) { |
| 363 |
$biblio = $item->biblio; |
363 |
$biblio = $item->biblio; |
| 364 |
} |
364 |
} |
| 365 |
|
365 |
|
| 366 |
if ( $issuingimpossible->{'STATS'} ) { |
366 |
if ( $issuingimpossible->{'STATS'} ) { |
| 367 |
my ( $stats_return, $stats_messages, $stats_iteminformation, $stats_borrower ) = |
367 |
my ( $stats_return, $stats_messages, $stats_iteminformation, $stats_borrower ) = |
| 368 |
AddReturn( $item->barcode, C4::Context->userenv->{'branch'}, undef, undef, 1 ); |
368 |
AddReturn( $item->barcode, C4::Context->userenv->{'branch'}, undef, undef, 1 ); |
| 369 |
|
369 |
|
| 370 |
$template->param( |
370 |
$template->param( |
| 371 |
STATS => 1, |
371 |
STATS => 1, |
| 372 |
CHECKEDIN => $stats_return, |
372 |
CHECKEDIN => $stats_return, |
| 373 |
MESSAGES => $stats_messages, |
373 |
MESSAGES => $stats_messages, |
| 374 |
ITEM => $stats_iteminformation, |
374 |
ITEM => $stats_iteminformation, |
| 375 |
BORROWER => $stats_borrower, |
375 |
BORROWER => $stats_borrower, |
| 376 |
); |
376 |
); |
| 377 |
|
377 |
|
| 378 |
#increment items.localuse |
378 |
#increment items.localuse |
| 379 |
my $localuse_count = $item->localuse; |
379 |
my $localuse_count = $item->localuse; |
| 380 |
$localuse_count++; |
380 |
$localuse_count++; |
| 381 |
$item->localuse($localuse_count)->store; |
381 |
$item->localuse($localuse_count)->store; |
| 382 |
} |
382 |
} |
| 383 |
|
383 |
|
| 384 |
# Fix for bug 7494: optional checkout-time fallback search for a book |
384 |
# Fix for bug 7494: optional checkout-time fallback search for a book |
| 385 |
|
385 |
|
| 386 |
if ( $issuingimpossible->{'UNKNOWN_BARCODE'} |
386 |
if ( $issuingimpossible->{'UNKNOWN_BARCODE'} |
| 387 |
&& C4::Context->preference("itemBarcodeFallbackSearch") |
387 |
&& C4::Context->preference("itemBarcodeFallbackSearch") |
| 388 |
&& not $batch |
388 |
&& not $batch |
| 389 |
) |
389 |
) |
| 390 |
{ |
390 |
{ |
| 391 |
$template_params->{FALLBACK} = 1; |
391 |
$template_params->{FALLBACK} = 1; |
| 392 |
|
392 |
|
| 393 |
my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); |
393 |
my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); |
| 394 |
my $query = "kw=" . $barcode; |
394 |
my $query = "kw=" . $barcode; |
| 395 |
my ( $searcherror, $results, $total_hits ) = $searcher->simple_search_compat($query, 0, 10); |
395 |
my ( $searcherror, $results, $total_hits ) = $searcher->simple_search_compat($query, 0, 10); |
| 396 |
|
396 |
|
| 397 |
# if multiple hits, offer options to librarian |
397 |
# if multiple hits, offer options to librarian |
| 398 |
if ( $total_hits > 0 ) { |
398 |
if ( $total_hits > 0 ) { |
| 399 |
my @barcodes; |
399 |
my @barcodes; |
| 400 |
foreach my $hit ( @{$results} ) { |
400 |
foreach my $hit ( @{$results} ) { |
| 401 |
my $chosen = # Maybe easier to retrieve the itemnumber from $hit? |
401 |
my $chosen = # Maybe easier to retrieve the itemnumber from $hit? |
| 402 |
TransformMarcToKoha({ record => C4::Search::new_record_from_zebra('biblioserver',$hit) }); |
402 |
TransformMarcToKoha({ record => C4::Search::new_record_from_zebra('biblioserver',$hit) }); |
| 403 |
|
403 |
|
| 404 |
# offer all barcodes individually |
404 |
# offer all barcodes individually |
| 405 |
if ( $chosen->{barcode} ) { |
405 |
if ( $chosen->{barcode} ) { |
| 406 |
push @barcodes, sort split(/\s*\|\s*/, $chosen->{barcode}); |
406 |
push @barcodes, sort split(/\s*\|\s*/, $chosen->{barcode}); |
|
|
407 |
} |
| 407 |
} |
408 |
} |
|
|
409 |
my $items = Koha::Items->search({ barcode => {-in => \@barcodes}}); |
| 410 |
$template_params->{options} = $items; |
| 408 |
} |
411 |
} |
| 409 |
my $items = Koha::Items->search({ barcode => {-in => \@barcodes}}); |
|
|
| 410 |
$template_params->{options} = $items; |
| 411 |
} |
412 |
} |
| 412 |
} |
|
|
| 413 |
|
413 |
|
| 414 |
# Only some errors will block when performing forced onsite checkout, |
414 |
# Only some errors will block when performing forced onsite checkout, |
| 415 |
# for other cases all errors will block |
415 |
# for other cases all errors will block |
| 416 |
my @blocking_error_codes = |
416 |
my @blocking_error_codes = |
| 417 |
( $onsite_checkout and C4::Context->preference("OnSiteCheckoutsForce") ) |
417 |
( $onsite_checkout and C4::Context->preference("OnSiteCheckoutsForce") ) |
| 418 |
? qw( UNKNOWN_BARCODE NO_OPEN_DAYS ) |
418 |
? qw( UNKNOWN_BARCODE NO_OPEN_DAYS ) |
| 419 |
: ( keys %$issuingimpossible ); |
419 |
: ( keys %$issuingimpossible ); |
| 420 |
|
420 |
|
| 421 |
if ( $issuingimpossible->{BOOKED_TO_ANOTHER} ) { |
421 |
if ( $issuingimpossible->{BOOKED_TO_ANOTHER} ) { |
| 422 |
$template_params->{BOOKED_TO_ANOTHER} = $issuingimpossible->{BOOKED_TO_ANOTHER}; |
422 |
$template_params->{BOOKED_TO_ANOTHER} = $issuingimpossible->{BOOKED_TO_ANOTHER}; |
| 423 |
$template_params->{IMPOSSIBLE} = 1; |
423 |
$template_params->{IMPOSSIBLE} = 1; |
| 424 |
$blocker = 1; |
424 |
$blocker = 1; |
| 425 |
} |
425 |
} |
| 426 |
|
426 |
|
| 427 |
foreach my $code ( @blocking_error_codes ) { |
427 |
foreach my $code ( @blocking_error_codes ) { |
| 428 |
if ($issuingimpossible->{$code}) { |
428 |
if ($issuingimpossible->{$code}) { |
| 429 |
$template_params->{$code} = $issuingimpossible->{$code}; |
429 |
$template_params->{$code} = $issuingimpossible->{$code}; |
| 430 |
|
430 |
|
| 431 |
$template_params->{IMPOSSIBLE} = 1; |
431 |
$template_params->{IMPOSSIBLE} = 1; |
| 432 |
$blocker = 1; |
432 |
$blocker = 1; |
|
|
433 |
} |
| 433 |
} |
434 |
} |
| 434 |
} |
|
|
| 435 |
|
435 |
|
| 436 |
delete $needsconfirmation->{'DEBT'} if ($debt_confirmed); |
436 |
delete $needsconfirmation->{'DEBT'} if ($debt_confirmed); |
| 437 |
|
437 |
|
| 438 |
if ( $item && C4::Context->preference('ClaimReturnedLostValue') ) { |
438 |
if ( $item && C4::Context->preference('ClaimReturnedLostValue') ) { |
| 439 |
my $autoClaimReturnCheckout = C4::Context->preference('AutoClaimReturnStatusOnCheckout'); |
439 |
my $autoClaimReturnCheckout = C4::Context->preference('AutoClaimReturnStatusOnCheckout'); |
| 440 |
|
440 |
|
| 441 |
my $claims = Koha::Checkouts::ReturnClaims->search( |
441 |
my $claims = Koha::Checkouts::ReturnClaims->search( |
| 442 |
{ |
442 |
{ |
| 443 |
itemnumber => $item->id, |
443 |
itemnumber => $item->id, |
|
|
444 |
resolution => undef, |
| 445 |
} |
| 446 |
); |
| 447 |
if ( $claims->count ) { |
| 448 |
if ($autoClaimReturnCheckout) { |
| 449 |
my $claim = $claims->next; |
| 450 |
|
| 451 |
my $patron_id = $logged_in_user->borrowernumber; |
| 452 |
my $resolution = $autoClaimReturnCheckout; |
| 453 |
|
| 454 |
$claim->resolve( |
| 455 |
{ |
| 456 |
resolution => $resolution, |
| 457 |
resolved_by => $patron_id, |
| 458 |
} |
| 459 |
); |
| 460 |
$template_params->{CLAIM_RESOLUTION} = $claim; |
| 461 |
} |
| 444 |
} |
462 |
} |
| 445 |
); |
463 |
} |
| 446 |
if ( $claims->count ) { |
|
|
| 447 |
if ($autoClaimReturnCheckout) { |
| 448 |
my $claim = $claims->next; |
| 449 |
|
| 450 |
my $patron_id = $logged_in_user->borrowernumber; |
| 451 |
my $resolution = $autoClaimReturnCheckout; |
| 452 |
|
464 |
|
| 453 |
$claim->resolve( |
465 |
if( $item and ( !$blocker or $force_allow_issue ) ){ |
| 454 |
{ |
466 |
my $confirm_required = 0; |
| 455 |
resolution => $resolution, |
467 |
unless($issueconfirmed){ |
| 456 |
resolved_by => $patron_id, |
468 |
# Get the item title for more information |
|
|
469 |
my $materials = $item->materials; |
| 470 |
my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $biblio->frameworkcode, kohafield => 'items.materials', authorised_value => $materials }); |
| 471 |
$materials = $descriptions->{lib} // $materials; |
| 472 |
$template_params->{ADDITIONAL_MATERIALS} = $materials; |
| 473 |
$template_params->{itemhomebranch} = $item->homebranch; |
| 474 |
|
| 475 |
# pass needsconfirmation to template if issuing is possible and user hasn't yet confirmed. |
| 476 |
foreach my $needsconfirmation_key ( keys %$needsconfirmation ) { |
| 477 |
$template_params->{$needsconfirmation_key} = $needsconfirmation->{$needsconfirmation_key}; |
| 478 |
$template_params->{getTitleMessageIteminfo} = $biblio->title; |
| 479 |
$template_params->{getBarcodeMessageIteminfo} = $item->barcode; |
| 480 |
$template_params->{NEEDSCONFIRMATION} = 1; |
| 481 |
$confirm_required = 1; |
| 482 |
if ( $needsconfirmation_key eq 'BOOKED_TO_ANOTHER' ) { |
| 483 |
my $reduceddue = |
| 484 |
dt_from_string( $$needsconfirmation{$needsconfirmation_key}->start_date )->subtract( days => 1 ); |
| 485 |
$template_params->{reduceddue} = $reduceddue; |
| 457 |
} |
486 |
} |
| 458 |
); |
487 |
} |
| 459 |
$template_params->{CLAIM_RESOLUTION} = $claim; |
|
|
| 460 |
} |
488 |
} |
| 461 |
} |
489 |
unless ($confirm_required) { |
| 462 |
} |
490 |
my $switch_onsite_checkout = exists $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}; |
|
|
491 |
if ( C4::Context->preference('UseRecalls') && !$recall_id ) { |
| 492 |
my $recall = Koha::Recalls->find( |
| 493 |
{ |
| 494 |
biblio_id => $item->biblionumber, |
| 495 |
item_id => [ undef, $item->itemnumber ], |
| 496 |
status => [ 'requested', 'waiting' ], |
| 497 |
completed => 0, |
| 498 |
patron_id => $patron->borrowernumber, |
| 499 |
} |
| 500 |
); |
| 501 |
$recall_id = ( $recall and $recall->id ) ? $recall->id : undef; |
| 502 |
} |
| 463 |
|
503 |
|
| 464 |
if( $item and ( !$blocker or $force_allow_issue ) ){ |
504 |
# If booked (alerts or confirmation) update datedue to end of booking |
| 465 |
my $confirm_required = 0; |
505 |
if ( my $booked = $needsconfirmation->{BOOKED_EARLY} // $alerts->{BOOKED} ) { |
| 466 |
unless($issueconfirmed){ |
506 |
$datedue = $booked->end_date; |
| 467 |
# Get the item title for more information |
|
|
| 468 |
my $materials = $item->materials; |
| 469 |
my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $biblio->frameworkcode, kohafield => 'items.materials', authorised_value => $materials }); |
| 470 |
$materials = $descriptions->{lib} // $materials; |
| 471 |
$template_params->{ADDITIONAL_MATERIALS} = $materials; |
| 472 |
$template_params->{itemhomebranch} = $item->homebranch; |
| 473 |
|
| 474 |
# pass needsconfirmation to template if issuing is possible and user hasn't yet confirmed. |
| 475 |
foreach my $needsconfirmation_key ( keys %$needsconfirmation ) { |
| 476 |
$template_params->{$needsconfirmation_key} = $needsconfirmation->{$needsconfirmation_key}; |
| 477 |
$template_params->{getTitleMessageIteminfo} = $biblio->title; |
| 478 |
$template_params->{getBarcodeMessageIteminfo} = $item->barcode; |
| 479 |
$template_params->{NEEDSCONFIRMATION} = 1; |
| 480 |
$confirm_required = 1; |
| 481 |
if ( $needsconfirmation_key eq 'BOOKED_TO_ANOTHER' ) { |
| 482 |
my $reduceddue = |
| 483 |
dt_from_string( $$needsconfirmation{$needsconfirmation_key}->start_date )->subtract( days => 1 ); |
| 484 |
$template_params->{reduceddue} = $reduceddue; |
| 485 |
} |
507 |
} |
| 486 |
} |
508 |
my $issue = AddIssue( |
| 487 |
} |
509 |
$patron, $barcode, $datedue, |
| 488 |
unless ($confirm_required) { |
510 |
$cancelreserve, |
| 489 |
my $switch_onsite_checkout = exists $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}; |
511 |
undef, undef, |
| 490 |
if ( C4::Context->preference('UseRecalls') && !$recall_id ) { |
|
|
| 491 |
my $recall = Koha::Recalls->find( |
| 492 |
{ |
512 |
{ |
| 493 |
biblio_id => $item->biblionumber, |
513 |
onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), |
| 494 |
item_id => [ undef, $item->itemnumber ], |
514 |
switch_onsite_checkout => $switch_onsite_checkout, cancel_recall => $cancel_recall, |
| 495 |
status => [ 'requested', 'waiting' ], |
515 |
recall_id => $recall_id, |
| 496 |
completed => 0, |
|
|
| 497 |
patron_id => $patron->borrowernumber, |
| 498 |
} |
516 |
} |
| 499 |
); |
517 |
); |
| 500 |
$recall_id = ( $recall and $recall->id ) ? $recall->id : undef; |
518 |
$template_params->{issue} = $issue; |
|
|
519 |
$session->clear('auto_renew'); |
| 520 |
$inprocess = 1; |
| 501 |
} |
521 |
} |
|
|
522 |
} |
| 502 |
|
523 |
|
| 503 |
# If booked (alerts or confirmation) update datedue to end of booking |
524 |
if ($needsconfirmation->{RESERVE_WAITING} or $needsconfirmation->{RESERVED} or $needsconfirmation->{TRANSFERRED} or $needsconfirmation->{PROCESSING}){ |
| 504 |
if ( my $booked = $needsconfirmation->{BOOKED_EARLY} // $alerts->{BOOKED} ) { |
525 |
$template->param( |
| 505 |
$datedue = $booked->end_date; |
526 |
reserveborrowernumber => $needsconfirmation->{'resborrowernumber'}, |
| 506 |
} |
527 |
reserve_id => $needsconfirmation->{reserve_id}, |
| 507 |
my $issue = AddIssue( |
|
|
| 508 |
$patron, $barcode, $datedue, |
| 509 |
$cancelreserve, |
| 510 |
undef, undef, |
| 511 |
{ |
| 512 |
onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), |
| 513 |
switch_onsite_checkout => $switch_onsite_checkout, cancel_recall => $cancel_recall, |
| 514 |
recall_id => $recall_id, |
| 515 |
} |
| 516 |
); |
528 |
); |
| 517 |
$template_params->{issue} = $issue; |
|
|
| 518 |
$session->clear('auto_renew'); |
| 519 |
$inprocess = 1; |
| 520 |
} |
529 |
} |
| 521 |
} |
|
|
| 522 |
|
| 523 |
if ($needsconfirmation->{RESERVE_WAITING} or $needsconfirmation->{RESERVED} or $needsconfirmation->{TRANSFERRED} or $needsconfirmation->{PROCESSING}){ |
| 524 |
$template->param( |
| 525 |
reserveborrowernumber => $needsconfirmation->{'resborrowernumber'}, |
| 526 |
reserve_id => $needsconfirmation->{reserve_id}, |
| 527 |
); |
| 528 |
} |
| 529 |
|
530 |
|
| 530 |
|
531 |
|
| 531 |
# FIXME If the issue is confirmed, we launch another time checkouts->count, now display the issue count after issue |
532 |
# FIXME If the issue is confirmed, we launch another time checkouts->count, now display the issue count after issue |
| 532 |
$patron = Koha::Patrons->find( $borrowernumber ); |
533 |
$patron = Koha::Patrons->find( $borrowernumber ); |
| 533 |
$template_params->{issuecount} = $patron->checkouts->count; |
534 |
$template_params->{issuecount} = $patron->checkouts->count; |
| 534 |
|
535 |
|
| 535 |
if ( $item ) { |
536 |
if ( $item ) { |
| 536 |
$template_params->{item} = $item; |
537 |
$template_params->{item} = $item; |
| 537 |
$template_params->{biblio} = $biblio; |
538 |
$template_params->{biblio} = $biblio; |
| 538 |
$template_params->{itembiblionumber} = $biblio->biblionumber; |
539 |
$template_params->{itembiblionumber} = $biblio->biblionumber; |
| 539 |
} |
540 |
} |
| 540 |
push @$checkout_infos, $template_params; |
541 |
push @$checkout_infos, $template_params; |
| 541 |
} |
542 |
} |
| 542 |
unless ( $batch ) { |
543 |
unless ( $batch ) { |
| 543 |
$template->param( %{$checkout_infos->[0]} ); |
544 |
$template->param( %{$checkout_infos->[0]} ); |
| 544 |
- |
|
|