Bug 21066: Code changes needed for replacing opac_news.timestamp
[srvgit] / members / pay.pl
index 32c8c36..d78debc 100755 (executable)
@@ -39,6 +39,7 @@ use C4::Stats;
 use C4::Koha;
 use C4::Overdues;
 use Koha::Patrons;
+use Koha::Items;
 
 use Koha::Patron::Categories;
 use URI::Escape;
@@ -65,9 +66,10 @@ if ( !$borrowernumber ) {
 
 my $payment_id = $input->param('payment_id');
 our $change_given = $input->param('change_given');
+our @renew_results = $input->multi_param('renew_result');
 
 # get borrower details
-my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
+my $logged_in_user = Koha::Patrons->find( $loggedinuser );
 our $patron         = Koha::Patrons->find($borrowernumber);
 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
 
@@ -112,10 +114,10 @@ elsif ( $input->param('confirm_writeoff') ) {
               . "&error_over=1" );
 
     } else {
-        Koha::Account->new( { patron_id => $borrowernumber } )->pay(
+        $payment_id = Koha::Account->new( { patron_id => $borrowernumber } )->pay(
             {
                 amount     => $amount,
-                lines      => [ scalar Koha::Account::Lines->find($accountlines_id) ],
+                lines      => [ Koha::Account::Lines->find($accountlines_id) ],
                 type       => 'WRITEOFF',
                 note       => $payment_note,
                 interface  => C4::Context->interface,
@@ -135,10 +137,27 @@ for (@names) {
     }
 }
 
+# Populate an arrayref with everything we need to display any
+# renew results that occurred based on what we were passed
+my $renew_results_display = [];
+foreach my $renew_result(@renew_results) {
+    my ($itemnumber, $success, $info) = split(/,/, $renew_result);
+    my $item = Koha::Items->find($itemnumber);
+    if ($success) {
+        $info = uri_unescape($info);
+    }
+    push @{$renew_results_display}, {
+        item => $item,
+        success => $success,
+        info => $info
+    };
+}
+
 $template->param(
     finesview  => 1,
     payment_id => $payment_id,
     change_given => $change_given,
+    renew_results => $renew_results_display
 );
 
 add_accounts_to_template();
@@ -222,7 +241,7 @@ sub writeoff_all {
             Koha::Account->new( { patron_id => $borrowernumber } )->pay(
                 {
                     amount => $amount,
-                    lines  => [ scalar Koha::Account::Lines->find($accountlines_id) ],
+                    lines  => [ Koha::Account::Lines->find($accountlines_id) ],
                     type   => 'WRITEOFF',
                     note   => $payment_note,
                     interface  => C4::Context->interface,