Bug 17894 - Remove and replace WriteOffFee
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 12 Jan 2017 18:45:40 +0000 (18:45 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Thu, 19 Jan 2017 11:15:26 +0000 (11:15 +0000)
WriteOffFee is the last of the "payment" subroutines that need to be
merged into Koha::Account::pay ( as a writeoff is really just type of
payment ).

Test Plan:
1) Apply this patch
2) Verify the writeoff, and writeoff all buttons still work

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
C4/Accounts.pm
members/pay.pl
t/db_dependent/Accounts.t

index 17f7e69..3942c39 100644 (file)
@@ -33,20 +33,19 @@ use Data::Dumper qw(Dumper);
 use vars qw(@ISA @EXPORT);
 
 BEGIN {
-       require Exporter;
-       @ISA    = qw(Exporter);
-       @EXPORT = qw(
-               &manualinvoice
-               &getnextacctno
-               &getcharges
-               &ModNote
-               &getcredits
-               &getrefunds
-               &chargelostitem
-               &ReversePayment
-        &WriteOffFee
-        &purge_zero_balance_fees
-       );
+    require Exporter;
+    @ISA    = qw(Exporter);
+    @EXPORT = qw(
+      &manualinvoice
+      &getnextacctno
+      &getcharges
+      &ModNote
+      &getcredits
+      &getrefunds
+      &chargelostitem
+      &ReversePayment
+      &purge_zero_balance_fees
+    );
 }
 
 =head1 NAME
@@ -350,36 +349,6 @@ sub ReversePayment {
 
 }
 
-=head2 WriteOffFee
-
-  WriteOffFee( $borrowernumber, $accountline_id, $itemnum, $accounttype, $amount, $branch, $payment_note );
-
-Write off a fine for a patron.
-C<$borrowernumber> is the patron's borrower number.
-C<$accountline_id> is the accountline_id of the fee to write off.
-C<$itemnum> is the itemnumber of of item whose fine is being written off.
-C<$accounttype> is the account type of the fine being written off.
-C<$amount> is a floating-point number, giving the amount that is being written off.
-C<$branch> is the branchcode of the library where the writeoff occurred.
-C<$payment_note> is the note to attach to this payment
-
-=cut
-
-sub WriteOffFee {
-    my ( $borrowernumber, $accountlines_id, $itemnum, $accounttype, $amount, $branch, $payment_note ) = @_;
-
-    my $line = Koha::Account::Lines->find($accountlines_id);
-    return Koha::Account->new( { patron_id => $borrowernumber } )->pay(
-        {
-            amount     => $amount,
-            lines      => [$line],
-            type       => 'writeoff',
-            note       => $payment_note,
-            library_id => $branch,
-        }
-    );
-}
-
 =head2 purge_zero_balance_fees
 
   purge_zero_balance_fees( $days );
index bfca78b..7e008d4 100755 (executable)
@@ -88,11 +88,18 @@ if ($writeoff_all) {
     writeoff_all(@names);
 } elsif ($writeoff_item) {
     my $accountlines_id = $input->param('accountlines_id');
-    my $itemno       = $input->param('itemnumber');
-    my $account_type = $input->param('accounttype');
     my $amount       = $input->param('amountoutstanding');
     my $payment_note = $input->param("payment_note");
-    WriteOffFee( $borrowernumber, $accountlines_id, $itemno, $account_type, $amount, $branch, $payment_note );
+
+    Koha::Account->new( { patron_id => $borrowernumber } )->pay(
+        {
+            amount     => $amount,
+            lines      => [Koha::Account::Lines->find($accountlines_id)],
+            type       => 'writeoff',
+            note       => $payment_note,
+            library_id => $branch,
+        }
+    );
 }
 
 for (@names) {
@@ -153,7 +160,7 @@ sub add_accounts_to_template {
 sub get_for_redirect {
     my ( $name, $name_in, $money ) = @_;
     my $s     = q{&} . $name . q{=};
-    my $value = $input->param($name_in);
+    my $value = uri_escape_utf8( $input->param($name_in) );
     if ( !defined $value ) {
         $value = ( $money == 1 ) ? 0 : q{};
     }
@@ -175,8 +182,8 @@ sub redirect_to_paycollect {
     $redirect .= get_for_redirect( 'amount', "amount$line_no", 1 );
     $redirect .=
       get_for_redirect( 'amountoutstanding', "amountoutstanding$line_no", 1 );
-    $redirect .= uri_escape_utf8( get_for_redirect( 'description', "description$line_no", 0 ) );
-    $redirect .= uri_escape_utf8( get_for_redirect( 'title', "title$line_no", 0 ) );
+    $redirect .= get_for_redirect( 'description', "description$line_no", 0 );
+    $redirect .= get_for_redirect( 'title', "title$line_no", 0 );
     $redirect .= get_for_redirect( 'itemnumber',   "itemnumber$line_no",   0 );
     $redirect .= get_for_redirect( 'notify_id',    "notify_id$line_no",    0 );
     $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
@@ -190,23 +197,28 @@ sub redirect_to_paycollect {
 sub writeoff_all {
     my @params = @_;
     my @wo_lines = grep { /^accountlines_id\d+$/ } @params;
+
+    my $borrowernumber = $input->param('borrowernumber');
+
     for (@wo_lines) {
         if (/(\d+)/) {
-            my $value       = $1;
-            my $accounttype = $input->param("accounttype$value");
-
-            #    my $borrowernum    = $input->param("borrowernumber$value");
-            my $itemno    = $input->param("itemnumber$value");
-            my $amount    = $input->param("amountoutstanding$value");
+            my $value           = $1;
+            my $amount          = $input->param("amountoutstanding$value");
             my $accountlines_id = $input->param("accountlines_id$value");
-            my $payment_note = $input->param("payment_note_$value");
-            WriteOffFee( $borrowernumber, $accountlines_id, $itemno, $accounttype, $amount, $branch, $payment_note );
+            my $payment_note    = $input->param("payment_note_$value");
+            Koha::Account->new( { patron_id => $borrowernumber } )->pay(
+                {
+                    amount => $amount,
+                    lines  => [ Koha::Account::Lines->find($accountlines_id) ],
+                    type   => 'writeoff',
+                    note   => $payment_note,
+                    library_id => $branch,
+                }
+            );
         }
     }
 
-    $borrowernumber = $input->param('borrowernumber');
-    print $input->redirect(
-        "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
+    print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
     return;
 }
 
index d1cc6db..505ce2f 100644 (file)
@@ -45,7 +45,6 @@ can_ok( 'C4::Accounts',
         getcredits
         getrefunds
         ReversePayment
-        WriteOffFee
         purge_zero_balance_fees )
 );