Bug 22359: Improvements to payment collection inputs
[koha-ffzg.git] / members / printinvoice.pl
index 5988325..79b8673 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 ) {
@@ -87,17 +82,25 @@ my %row = (
     'amount'                  => sprintf( "%.2f", $accountline->{'amount'} ),
     'amountoutstanding' =>
       sprintf( "%.2f", $accountline->{'amountoutstanding'} ),
-    'accountno' => $accountline->{'accountno'},
-    accounttype => $accountline->{accounttype},
-    'note'      => $accountline->{'note'},
+    'debit_type_code' => $accountline->{'debit_type_code'},
+    '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;