Bug 20629: Pass accountline objects to template instead of hashref
authorKyle M Hall <kyle@bywatersolutions.com>
Mon, 15 Oct 2018 16:53:27 +0000 (12:53 -0400)
committerNick Clemens <nick@bywatersolutions.com>
Tue, 6 Nov 2018 16:32:41 +0000 (16:32 +0000)
Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt
members/boraccount.pl

index 57c19b8..495382e 100644 (file)
         &nbsp;[% IF ( account.itemnumber ) %]<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% account.item.biblionumber | uri %]&amp;itemnumber=[% account.itemnumber | uri %]">[% account.item.biblio.title | html %]</a>[% END %]</td>
       <td>[% IF account.itemnumber %][% Branches.GetName( account.item.homebranch ) | html %][% END %]</td>
       <td>[% account.note | html_line_break %]</td>
-      [% IF ( account.amountcredit ) %]<td class="credit" style="text-align: right;">[% ELSE %]<td class="debit" style="text-align: right;">[% END %][% account.amount | $Price %]</td>
-      [% IF ( account.amountoutstandingcredit ) %]<td class="credit" style="text-align: right;">[% ELSE %]<td class="debit" style="text-align: right;">[% END %][% account.amountoutstanding | $Price %]</td>
+      [% IF account.amount <= 0 %]<td class="credit" style="text-align: right;">[% ELSE %]<td class="debit" style="text-align: right;">[% END %][% account.amount | $Price %]</td>
+      [% IF account.amountoutstanding <= 0 %]<td class="credit" style="text-align: right;">[% ELSE %]<td class="debit" style="text-align: right;">[% END %][% account.amountoutstanding | $Price %]</td>
       <td class="actions">
-        [% IF ( account.payment ) %]
+        [% IF ( account.is_credit ) %]
           <a target="_blank" href="printfeercpt.pl?action=print&amp;accountlines_id=[% account.accountlines_id | html %]&amp;borrowernumber=[% account.borrowernumber | html %]" class="btn btn-default btn-xs"><i class="fa fa-print"></i> Print</a>
         [% ELSE %]
           <a target="_blank" href="printinvoice.pl?action=print&amp;accountlines_id=[% account.accountlines_id | html %]&amp;borrowernumber=[% account.borrowernumber | html %]" class="btn btn-default btn-xs"><i class="fa fa-print"></i> Print</a>
         [% END %]
         <a href="accountline-details.pl?accountlines_id=[% account.accountlines_id | uri %]" class="btn btn-default btn-xs"><i class="fa fa-list"></i> Details</a>
         [% IF ( reverse_col) %]
-          [% IF account.object.is_credit %]
+          [% IF account.is_credit %]
               <a href="boraccount.pl?action=void&amp;accountlines_id=[% account.accountlines_id | uri %]&amp;borrowernumber=[% account.borrowernumber | uri %]" class="btn btn-default btn-xs void"><i class="fa fa-ban"></i> Void</a>
           [% ELSE %]
             &nbsp;
index a36979a..7f94bf2 100755 (executable)
@@ -69,7 +69,7 @@ if ( $action eq 'void' ) {
 #get account details
 my $total = $patron->account->balance;
 
-my $accts = Koha::Account::Lines->search(
+my @accountlines = Koha::Account::Lines->search(
     { borrowernumber => $patron->borrowernumber },
     { order_by       => { -desc => 'accountlines_id' } }
 );
@@ -80,35 +80,6 @@ if($total <= 0){
 }
 
 my $reverse_col = 0; # Flag whether we need to show the reverse column
-my @accountlines;
-while ( my $line = $accts->next ) {
-    # FIXME We should pass the $accts iterator to the template and do this formatting part there
-    my $accountline = $line->unblessed;
-    $accountline->{object} = $line;
-    $accountline->{amount} += 0.00;
-    if ($accountline->{amount} <= 0 ) {
-        $accountline->{amountcredit} = 1;
-    }
-    $accountline->{amountoutstanding} += 0.00;
-    if ( $accountline->{amountoutstanding} <= 0 ) {
-        $accountline->{amountoutstandingcredit} = 1;
-    }
-
-    $accountline->{amount} = sprintf '%.2f', $accountline->{amount};
-    $accountline->{amountoutstanding} = sprintf '%.2f', $accountline->{amountoutstanding};
-    if ($accountline->{amount} < 0) {
-        $accountline->{payment} = 1
-          if ( $accountline->{accounttype} =~ /^Pay/ );
-
-        $reverse_col = 1;
-    }
-
-    if ( $accountline->{itemnumber} ) {
-        # Because we will not have access to the object from the template
-        $accountline->{item} = $line->item;
-    }
-    push @accountlines, $accountline;
-}
 
 if (C4::Context->preference('ExtendedPatronAttributes')) {
     my $attributes = GetBorrowerAttributes($borrowernumber);