Bug 22588: (follow-up) Simplify getting accounts even more
[koha-ffzg.git] / opac / sco / sco-main.pl
index 458e52e..bbaaf70 100755 (executable)
@@ -158,11 +158,12 @@ elsif ( $patron && ( $op eq 'checkout' || $op eq 'renew' ) ) {
     if (scalar keys %$impossible) {
 
         my $issue_error = (keys %$impossible)[0]; # FIXME This is wrong, we assume only one error and keys are not ordered
+        my $title = ( $item ) ? $item->biblio->title : '';
 
         $template->param(
             impossible                => $issue_error,
             "circ_error_$issue_error" => 1,
-            title                     => $item->biblio->title, # FIXME Need to be backport! GetItem did not return the biblio's title
+            title                     => $title,
             hide_main                 => 1,
         );
         if ($issue_error eq 'DEBT') {
@@ -235,7 +236,7 @@ elsif ( $patron && ( $op eq 'checkout' || $op eq 'renew' ) ) {
                         {
                             borrowernumber => $borrower->{borrowernumber},
                             accounttype    => 'Res',
-                            description    => 'Reserve Charge - ' . $item->biblio->title,
+                            description    => $item->biblio->title,
                             date           => $dtf->format_date(dt_from_string)
                         }
                       )->count,
@@ -277,27 +278,9 @@ if ($borrower) {
         m/priority/ and $show_priority = 1;
     }
 
-    my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
-    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;
 
@@ -315,9 +298,9 @@ if ($borrower) {
         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(