Bug 25147: (RM follow-up) Update pref references.
[srvgit] / opac / sco / sco-main.pl
index a303524..83a37ac 100755 (executable)
@@ -35,7 +35,7 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 
-use C4::Auth qw(get_template_and_user checkpw);
+use C4::Auth qw(get_template_and_user checkpw in_iprange);
 use C4::Koha;
 use C4::Circulation;
 use C4::Reserves;
@@ -59,7 +59,13 @@ unless (C4::Context->preference('WebBasedSelfCheck')) {
     exit;
 }
 
-if (C4::Context->preference('AutoSelfCheckAllowed')) 
+unless ( in_iprange(C4::Context->preference('SelfCheckAllowByIPRanges')) ) {
+    # redirect to OPAC home if self-checkout not permitted from current IP
+    print $query->redirect("/cgi-bin/koha/opac-main.pl");
+    exit;
+}
+
+if (C4::Context->preference('AutoSelfCheckAllowed'))
 {
     my $AutoSelfCheckID = C4::Context->preference('AutoSelfCheckID');
     my $AutoSelfCheckPass = C4::Context->preference('AutoSelfCheckPass');
@@ -87,10 +93,10 @@ if (C4::Context->preference('SelfCheckTimeout')) {
 }
 $template->param( SelfCheckTimeout => $selfchecktimeout );
 
-# Checks policy laid out by AllowSelfCheckReturns, defaults to 'on' if preference is undefined
+# Checks policy laid out by SCOAllowCheckin, defaults to 'on' if preference is undefined
 my $allowselfcheckreturns = 1;
-if (defined C4::Context->preference('AllowSelfCheckReturns')) {
-    $allowselfcheckreturns = C4::Context->preference('AllowSelfCheckReturns');
+if (defined C4::Context->preference('SCOAllowCheckin')) {
+    $allowselfcheckreturns = C4::Context->preference('SCOAllowCheckin');
 }
 
 my $issuerid = $loggedinuser;
@@ -234,10 +240,10 @@ elsif ( $patron && ( $op eq 'checkout' || $op eq 'renew' ) ) {
                     # Note that this should not be needed but since we do not have proper exception handling here we do it this way
                     patron_has_hold_fee => Koha::Account::Lines->search(
                         {
-                            borrowernumber => $borrower->{borrowernumber},
-                            accounttype    => 'Res',
-                            description    => 'Reserve Charge - ' . $item->biblio->title,
-                            date           => $dtf->format_date(dt_from_string)
+                            borrowernumber  => $borrower->{borrowernumber},
+                            debit_type_code => 'RESERVE',
+                            description     => $item->biblio->title,
+                            date            => $dtf->format_date(dt_from_string)
                         }
                       )->count,
                 );
@@ -278,28 +284,16 @@ if ($borrower) {
         m/priority/ and $show_priority = 1;
     }
 
-    my $total = $patron->account->balance;
-    my $accts = Koha::Account::Lines->search(
-        { borrowernumber => $borrower->{borrowernumber} },
-        { order_by       => { -desc => 'accountlines_id' } }
-    );
-
-    my @accountlines;
-    while ( my $line = $accts->next ) {
-        my $accountline = $line->unblessed;
-        $accountline->{'amount'} = sprintf( "%.2f", $accountline->{'amount'} || '0.00');
-        if ( $accountline->{'amount'} >= 0 ) {
-            $accountline->{'amountcredit'} = 1;
-        }
-        $accountline->{'amountoutstanding'} =
-        sprintf( "%.2f", $accountline->{'amountoutstanding'} || '0.00' );
-        if ( $accountline->{'amountoutstanding'} >= 0 ) {
-            $accountline->{'amountoutstandingcredit'} = 1;
-        }
-        push @accountlines, $accountline;
-    }
+    my $account = $patron->account;
+    my $total = $account->balance;
+    my $accountlines = $account->lines;
 
     my $holds = $patron->holds;
+    my $waiting_holds_count = 0;
+
+    while(my $hold = $holds->next) {
+        $waiting_holds_count++ if $hold->is_waiting;
+    }
 
     $template->param(
         validuser => 1,
@@ -311,13 +305,14 @@ if ($borrower) {
         patronid => $patronid,
         patronlogin => $patronlogin,
         patronpw => $patronpw,
+        waiting_holds_count => $waiting_holds_count,
         noitemlinks => 1 ,
         borrowernumber => $borrower->{'borrowernumber'},
         SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
         AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
-        showpriority   => $show_priority,
-        ACCOUNT_LINES => \@accountlines,
-        total => sprintf( "%.2f", $total ),
+        howpriority   => $show_priority,
+        ACCOUNT_LINES => $accountlines,
+        total => $total,
     );
 
     my $patron_messages = Koha::Patron::Messages->search(