Bug 23051: (follow-up) Add renewal feedback and move code to subroutines and test
[koha-ffzg.git] / members / printinvoice.pl
index a75b0a6..38950e3 100755 (executable)
@@ -49,19 +49,14 @@ my $borrowernumber  = $input->param('borrowernumber');
 my $action          = $input->param('action') || '';
 my $accountlines_id = $input->param('accountlines_id');
 
-my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
+my $logged_in_user = Koha::Patrons->find( $loggedinuser );
 my $patron         = Koha::Patrons->find( $borrowernumber );
 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
 
-if ( $patron->is_child ) {
-    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
-    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-    $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
-}
-
 #get account details
 my $total = $patron->account->balance;
-my $accountline = Koha::Account::Lines->find($accountlines_id)->unblessed;
+my $accountline_object = Koha::Account::Lines->find($accountlines_id);
+my $accountline = $accountline_object->unblessed;
 
 my $totalcredit;
 if ( $total <= 0 ) {
@@ -79,25 +74,21 @@ if ( $accountline->{'amountoutstanding'} <= 0 ) {
     $accountline->{'amountoutstandingcredit'} = 1;
 }
 
-my %row = (
-    'date'                    => dt_from_string( $accountline->{'date'}, dateonly => 1 ),
-    'amountcredit'            => $accountline->{'amountcredit'},
-    'amountoutstandingcredit' => $accountline->{'amountoutstandingcredit'},
-    'description'             => $accountline->{'description'},
-    'amount'                  => sprintf( "%.2f", $accountline->{'amount'} ),
-    'amountoutstanding' =>
-      sprintf( "%.2f", $accountline->{'amountoutstanding'} ),
-    'accountno' => $accountline->{'accountno'},
-    accounttype => $accountline->{accounttype},
-    'note'      => $accountline->{'note'},
-);
+my @account_offsets = Koha::Account::Offsets->search( { debit_id => $accountline_object->id } );
+
+my $letter = C4::Letters::getletter( 'circulation', 'ACCOUNT_DEBIT', C4::Context::mybranch, 'print', $patron->lang );
 
 $template->param(
-    patron         => $patron,
-    finesview      => 1,
-    total          => sprintf( "%.2f", $total ),
-    totalcredit    => $totalcredit,
-    accounts       => [$accountline], # FIXME There is always only 1 row!
+    letter  => $letter,
+    patron  => $patron,
+    library => C4::Context::mybranch,
+    offsets => \@account_offsets,
+    debit   => $accountline_object,
+
+    finesview   => 1,
+    total       => sprintf( "%.2f", $total ),
+    totalcredit => $totalcredit,
+    accounts    => [$accountline],           # FIXME There is always only 1 row!
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;