Bug 31028: Update patron and biblio includes to remove whitespace
[koha-ffzg.git] / members / paycollect.pl
index d69b406..b189107 100755 (executable)
@@ -32,6 +32,8 @@ use Koha::Patrons;
 use Koha::Patron::Categories;
 use Koha::AuthorisedValues;
 use Koha::Account;
+use Koha::Account::Lines;
+use Koha::AdditionalFields;
 use Koha::Token;
 use Koha::DateUtils qw( output_pref );
 
@@ -57,7 +59,6 @@ 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 } );
 
-my $borrower       = $patron->unblessed;
 my $account        = $patron->account;
 my $category       = $patron->category;
 my $user           = $input->remote_user;
@@ -88,14 +89,12 @@ if ( $pay_individual || $writeoff_individual ) {
     my $amountoutstanding = $input->param('amountoutstanding');
     my $itemnumber  = $input->param('itemnumber');
     my $description  = $input->param('description');
-    my $title        = $input->param('title');
     $total_due = $amountoutstanding;
     $template->param(
         debit_type_code    => $debit_type_code,
         accountlines_id    => $accountlines_id,
         amount            => $amount,
         amountoutstanding => $amountoutstanding,
-        title             => $title,
         itemnumber        => $itemnumber,
         individual_description => $description,
         payment_note    => $payment_note,
@@ -173,6 +172,23 @@ if ( $total_paid and $total_paid ne '0.00' ) {
             );
             $payment_id = $pay_result->{payment_id};
 
+            my @additional_fields;
+            my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:credit' });
+            while ( my $field = $accountline_fields->next ) {
+                my $value = $input->param('additional_field_' . $field->id);
+                if (defined $value) {
+                    push @additional_fields, {
+                        id => $field->id,
+                        value => $value,
+                    };
+                }
+            }
+            if (@additional_fields) {
+                my $payment = Koha::Account::Lines->find($payment_id);
+                $payment->set_additional_fields(\@additional_fields);
+            }
+
+
             $url = "/cgi-bin/koha/members/pay.pl";
         } else {
             if ($selected_accts) {
@@ -216,6 +232,22 @@ if ( $total_paid and $total_paid ne '0.00' ) {
             }
             $payment_id = $pay_result->{payment_id};
 
+            my @additional_fields;
+            my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:credit' });
+            while ( my $field = $accountline_fields->next ) {
+                my $value = $input->param('additional_field_' . $field->id);
+                if (defined $value) {
+                    push @additional_fields, {
+                        id => $field->id,
+                        value => $value,
+                    };
+                }
+            }
+            if (@additional_fields) {
+                my $payment = Koha::Account::Lines->find($payment_id);
+                $payment->set_additional_fields(\@additional_fields);
+            }
+
             $url = "/cgi-bin/koha/members/boraccount.pl";
         }
         # It's possible renewals took place, parse any renew results
@@ -239,8 +271,6 @@ if ( $total_paid and $total_paid ne '0.00' ) {
     $total_paid = '0.00';    #TODO not right with pay_individual
 }
 
-$template->param(%$borrower);
-
 if ( $input->param('error_over') ) {
     $template->param( error_over => 1, total_due => scalar $input->param('amountoutstanding') );
 }
@@ -254,6 +284,7 @@ $template->param(
     total          => $total_due,
 
     csrf_token => Koha::Token->new->generate_csrf( { session_id => scalar $input->cookie('CGISESSID') } ),
+    available_additional_fields => [ Koha::AdditionalFields->search({ tablename => 'accountlines:credit' })->as_list ],
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;