Bug 21801: (follow-up) Use ->account
[koha-equinox.git] / members / paycollect.pl
index 5bd9c0e..1cb6cbe 100755 (executable)
@@ -36,7 +36,10 @@ use Koha::Token;
 
 my $input = CGI->new();
 
-my $updatecharges_permissions = $input->param('writeoff_individual') ? 'writeoff' : 'remaining_permissions';
+my $writeoff_individual       = $input->param('writeoff_individual');
+my $type                      = scalar $input->param('type') || 'payment';
+
+my $updatecharges_permissions = ($writeoff_individual || $type eq 'writeoff') ? 'writeoff' : 'remaining_permissions';
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {   template_name   => 'members/paycollect.tt',
         query           => $input,
@@ -54,27 +57,26 @@ 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;
 
-my $branch    = C4::Context->userenv->{'branch'};
-my $total_due = $patron->account->outstanding_debits->total_outstanding;
+my $library_id = C4::Context->userenv->{'branch'};
+my $total_due  = $account->outstanding_debits->total_outstanding;
 
 my $total_paid = $input->param('paid');
 
-my $individual   = $input->param('pay_individual');
-my $writeoff     = $input->param('writeoff_individual');
 my $select_lines = $input->param('selected');
+my $pay_individual   = $input->param('pay_individual');
 my $select       = $input->param('selected_accts');
 my $payment_note = uri_unescape scalar $input->param('payment_note');
 my $payment_type = scalar $input->param('payment_type');
-my $type         = scalar $input->param('type') || 'payment',
 my $accountlines_id;
 
-if ( $individual || $writeoff ) {
-    if ($individual) {
+if ( $pay_individual || $writeoff_individual ) {
+    if ($pay_individual) {
         $template->param( pay_individual => 1 );
-    } elsif ($writeoff) {
+    } elsif ($writeoff_individual) {
         $template->param( writeoff_individual => 1 );
     }
     my $accounttype       = $input->param('accounttype');
@@ -117,14 +119,15 @@ if ( $total_paid and $total_paid ne '0.00' ) {
                 token  => scalar $input->param('csrf_token'),
             });
 
-        if ($individual) {
+        if ($pay_individual) {
             my $line = Koha::Account::Lines->find($accountlines_id);
-            Koha::Account->new( { patron_id => $borrowernumber } )->pay(
+            $account->pay(
                 {
                     lines        => [$line],
                     amount       => $total_paid,
-                    library_id   => $branch,
+                    library_id   => $library_id,
                     note         => $payment_note,
+                    interface    => C4::Context->interface,
                     payment_type => $payment_type,
                 }
             );
@@ -147,27 +150,27 @@ if ( $total_paid and $total_paid ne '0.00' ) {
                     { order_by => 'date' }
                 );
 
-                Koha::Account->new(
-                    {
-                        patron_id => $borrowernumber,
-                    }
-                  )->pay(
+                $account->pay(
                     {
                         type         => $type,
                         amount       => $total_paid,
+                        library_id   => $library_id,
                         lines        => \@lines,
                         note         => $note,
+                        interface    => C4::Context->interface,
                         payment_type => $payment_type,
                     }
                   );
             }
             else {
                 my $note = $input->param('selected_accts_notes');
-                Koha::Account->new( { patron_id => $borrowernumber } )->pay(
+                $account->pay(
                     {
                         amount       => $total_paid,
+                        library_id   => $library_id,
                         note         => $note,
                         payment_type => $payment_type,
+                        interface    => C4::Context->interface
                     }
                 );
             }