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