Bug 25701: Remove sort on removed field
[koha-ffzg.git] / circ / circulation.pl
index 8fcb9bb..5ec80c8 100755 (executable)
@@ -30,9 +30,8 @@ use DateTime;
 use DateTime::Duration;
 use Scalar::Util qw( looks_like_number );
 use C4::Output;
-use C4::Print;
 use C4::Auth qw/:DEFAULT get_session haspermission/;
-use C4::Koha;   # GetPrinter
+use C4::Koha;
 use C4::Circulation;
 use C4::Utils::DataTables::Members;
 use C4::Members;
@@ -73,13 +72,6 @@ my $override_high_holds_tmp = $query->param('override_high_holds_tmp');
 
 my $sessionID = $query->cookie("CGISESSID") ;
 my $session = get_session($sessionID);
-if (!C4::Context->userenv){
-    if ($session->param('branch') eq 'NO_LIBRARY_SET'){
-        # no branch set we can't issue
-        print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
-        exit;
-    }
-}
 
 my $barcodes = [];
 my $barcode =  $query->param('barcode');
@@ -126,7 +118,7 @@ if ( $batch && C4::Context->preference('BatchCheckouts') ) {
     $template_name = q|circ/circulation_batch_checkouts.tt|;
     my @batch_category_codes = split '\|', C4::Context->preference('BatchCheckoutsValidCategories');
     my $categorycode = $patron->categorycode;
-    if ( $categorycode && grep {/^$categorycode$/} @batch_category_codes ) {
+    if ( $categorycode && grep { $_ eq $categorycode } @batch_category_codes ) {
         $batch_allowed = 1;
     } else {
         $barcodes = [];
@@ -142,15 +134,18 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
         flagsrequired   => { circulate => 'circulate_remaining_permissions' },
     }
 );
-my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
+my $logged_in_user = Koha::Patrons->find( $loggedinuser );
 
 my $force_allow_issue = $query->param('forceallow') || 0;
 if (!C4::Auth::haspermission( C4::Context->userenv->{id} , { circulate => 'force_checkout' } )) {
     $force_allow_issue = 0;
 }
-
 my $onsite_checkout = $query->param('onsite_checkout');
 
+if (C4::Context->preference("OnSiteCheckoutAutoCheck") && $onsite_checkout eq "on") {
+    $template->param(onsite_checkout => $onsite_checkout);
+}
+
 my @failedrenews = $query->multi_param('failedrenew');    # expected to be itemnumbers
 our %renew_failed = ();
 for (@failedrenews) { $renew_failed{$_} = 1; }
@@ -175,7 +170,7 @@ for my $barcode ( @$barcodes ) {
 
 my $stickyduedate  = $query->param('stickyduedate') || $session->param('stickyduedate');
 my $duedatespec    = $query->param('duedatespec')   || $session->param('stickyduedate');
-$duedatespec = eval { output_pref( { dt => dt_from_string( $duedatespec ), dateformat => 'iso', timeformat => '24hr' }); }
+$duedatespec = eval { output_pref( { dt => dt_from_string( $duedatespec ), dateformat => 'iso' }); }
     if ( $duedatespec );
 my $restoreduedatespec  = $query->param('restoreduedatespec') || $duedatespec || $session->param('stickyduedate');
 if ( $restoreduedatespec && $restoreduedatespec eq "highholds_empty" ) {
@@ -183,7 +178,6 @@ if ( $restoreduedatespec && $restoreduedatespec eq "highholds_empty" ) {
 }
 my $issueconfirmed = $query->param('issueconfirmed');
 my $cancelreserve  = $query->param('cancelreserve');
-my $print          = $query->param('print') || q{};
 my $debt_confirmed = $query->param('debt_confirmed') || 0; # Don't show the debt error dialog twice
 my $charges        = $query->param('charges') || q{};
 
@@ -201,6 +195,8 @@ else {
     $session->clear('auto_renew');
 }
 
+$template->param( auto_renew => $session->param('auto_renew') );
+
 my ($datedue,$invalidduedate);
 
 my $duedatespec_allow = C4::Context->preference('SpecifyDueDate');
@@ -217,11 +213,6 @@ if( $onsite_checkout && !$duedatespec_allow ) {
     }
 }
 
-# check and see if we should print
-if ( @$barcodes == 0 && $print eq 'maybe' ) {
-    $print = 'yes';
-}
-
 my $inprocess = (@$barcodes == 0) ? '' : $query->param('inprocess');
 if ( @$barcodes == 0 && $charges eq 'yes' ) {
     $template->param(
@@ -230,16 +221,6 @@ if ( @$barcodes == 0 && $charges eq 'yes' ) {
     );
 }
 
-if ( $print eq 'yes' && $borrowernumber ne '' ) {
-    if ( C4::Context->boolean_preference('printcirculationslips') ) {
-        my $letter = IssueSlip($branch, $borrowernumber, "QUICK");
-        NetworkPrint($letter->{content});
-    }
-    $query->param( 'borrowernumber', '' );
-    $borrowernumber = '';
-    undef $patron;
-}
-
 #
 # STEP 2 : FIND BORROWER
 # if there is a list of find borrowers....
@@ -320,6 +301,13 @@ if ($patron) {
         }
     }
 
+    # Calculate and display patron's age
+    if ( !$patron->is_valid_age ) {
+        $template->param( age_limitations => 1 );
+        $template->param( age_low => $patron->category->dateofbirthrequired );
+        $template->param( age_high => $patron->category->upperagelimit );
+    }
+
 }
 
 #
@@ -330,8 +318,10 @@ if (@$barcodes) {
   my $checkout_infos;
   for my $barcode ( @$barcodes ) {
 
-    my $template_params = { barcode => $barcode };
-    $template_params->{onsite_checkout} = $onsite_checkout;
+    my $template_params = {
+        barcode         => $barcode,
+        onsite_checkout => $onsite_checkout,
+    };
 
     # always check for blockers on issuing
     my ( $error, $question, $alerts, $messages ) = CanBookBeIssued(
@@ -415,7 +405,6 @@ if (@$barcodes) {
                 $template_params->{getTitleMessageIteminfo} = $biblio->title;
                 $template_params->{getBarcodeMessageIteminfo} = $item->barcode;
                 $template_params->{NEEDSCONFIRMATION} = 1;
-                $template_params->{auto_renew} = $session->param('auto_renew');
                 $confirm_required = 1;
             }
         }
@@ -430,7 +419,8 @@ if (@$barcodes) {
 
     if ($question->{RESERVE_WAITING} or $question->{RESERVED}){
         $template->param(
-            reserveborrowernumber => $question->{'resborrowernumber'}
+            reserveborrowernumber => $question->{'resborrowernumber'},
+            reserve_id => $question->{reserve_id},
         );
     }
 
@@ -503,7 +493,7 @@ if ( $patron ) {
     $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
     if ( defined $no_issues_charge_guarantees ) {
         my $guarantees_non_issues_charges = 0;
-        my $guarantees = $patron->guarantees;
+        my $guarantees = $patron->guarantee_relationships->guarantees;
         while ( my $g = $guarantees->next ) {
             $guarantees_non_issues_charges += $g->account->non_issues_charges;
         }
@@ -558,14 +548,12 @@ my $view = $batch
     : 'circview';
 
 my @relatives;
-if ( $borrowernumber ) {
-    if ( $patron ) {
-        if ( my $guarantor = $patron->guarantor ) {
-            push @relatives, $guarantor->borrowernumber;
-            push @relatives, $_->borrowernumber for $patron->siblings;
-        } else {
-            push @relatives, $_->borrowernumber for $patron->guarantees;
-        }
+if ( $patron ) {
+    if ( my @guarantors = $patron->guarantor_relationships()->guarantors() ) {
+        push( @relatives, $_->id ) for @guarantors;
+        push( @relatives, $_->id ) for $patron->siblings();
+    } else {
+        push( @relatives, $_->id ) for $patron->guarantee_relationships()->guarantees();
     }
 }
 my $relatives_issues_count =
@@ -626,13 +614,14 @@ my $has_modifications = Koha::Patron::Modifications->search( { borrowernumber =>
 $template->param(
     debt_confirmed            => $debt_confirmed,
     SpecifyDueDate            => $duedatespec_allow,
-    CircAutocompl             => C4::Context->preference("CircAutocompl"),
+    PatronAutoComplete      => C4::Context->preference("PatronAutoComplete"),
     debarments                => scalar GetDebarments({ borrowernumber => $borrowernumber }),
     todaysdate                => output_pref( { dt => dt_from_string()->set(hour => 23)->set(minute => 59), dateformat => 'sql' } ),
     has_modifications         => $has_modifications,
     override_high_holds       => $override_high_holds,
     nopermission              => scalar $query->param('nopermission'),
     autoswitched              => $autoswitched,
+    logged_in_user            => $logged_in_user,
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;