Bug 22120: Add price formattig to patron summary print
[koha.git] / members / moremember.pl
index ebbdcac..faaa95e 100755 (executable)
@@ -50,14 +50,11 @@ use C4::Biblio;
 use C4::Form::MessagingPreferences;
 use List::MoreUtils qw/uniq/;
 use C4::Members::Attributes qw(GetBorrowerAttributes);
+use Koha::Account::Lines;
 use Koha::AuthorisedValues;
 use Koha::CsvProfiles;
 use Koha::Patron::Debarments qw(GetDebarments);
 use Koha::Patron::Messages;
-use Module::Load;
-if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
-    load Koha::NorwegianPatronDB, qw( NLGetSyncDataFromBorrowernumber );
-}
 #use Smart::Comments;
 #use Data::Dumper;
 use DateTime;
@@ -121,11 +118,8 @@ my $error = $input->param('error');
 $template->param( error => $error ) if ( $error );
 
 my $patron         = Koha::Patrons->find( $borrowernumber );
-my $userenv = C4::Context->userenv;
-if ( $userenv and $userenv->{number} ) { # Allow DB user to create a superlibrarian patron
-    my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
-    output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
-}
+my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
+output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
 
 my $issues        = $patron->checkouts;
 my $balance       = $patron->account->balance;
@@ -147,7 +141,6 @@ foreach (qw(dateenrolled dateexpiry dateofbirth)) { # FIXME This should be remov
     }
     $data->{$_} = dt_from_string( $userdate );
 }
-$data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
 
 for (qw(gonenoaddress lost borrowernotes)) {
         $data->{$_} and $template->param(flagged => 1) and last;
@@ -168,12 +161,6 @@ if ( $patron->is_debarred ) {
 
 $data->{ "sex_".$data->{'sex'}."_p" } = 1 if defined $data->{sex};
 
-if ( $category_type eq 'C') {
-    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;
-}
-
 my @relatives;
 if ( my $guarantor = $patron->guarantor ) {
     $template->param( guarantor => $guarantor );
@@ -206,6 +193,7 @@ if ( C4::Context->preference("IndependentBranches") ) {
         $samebranch = 1;
     }
     else {
+        my $userenv = C4::Context->userenv;
         $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
     }
 }
@@ -215,18 +203,12 @@ else {
 my $library = Koha::Libraries->find( $data->{branchcode})->unblessed;
 @{$data}{keys %$library} = values %$library; # merge in all branch columns # FIXME This is really ugly, we should pass the library instead
 
-my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
-
 # If printing a page, send the account informations to the template
-if ($print eq "page") {
-    foreach my $accountline (@$accts) {
-        $accountline->{amount} = sprintf '%.2f', $accountline->{amount};
-        $accountline->{amountoutstanding} = sprintf '%.2f', $accountline->{amountoutstanding};
-
-        if ($accountline->{accounttype} ne 'F' && $accountline->{accounttype} ne 'FU'){
-            $accountline->{printtitle} = 1;
-        }
-    }
+if (defined $print and $print eq "page") {
+    my $accts = Koha::Account::Lines->search(
+        { borrowernumber => $patron->borrowernumber, amountoutstanding => { '>' => 0 } },
+        { order_by       => { -desc => 'accountlines_id' } }
+    );
     $template->param( accounts => $accts );
 }
 
@@ -255,23 +237,6 @@ if ($borrowernumber) {
           ->count( { borrowernumber => $borrowernumber } ) );
 }
 
-# current alert subscriptions
-my $alerts = getalert($borrowernumber);
-foreach (@$alerts) {
-    $_->{ $_->{type} } = 1;
-    $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
-}
-
-# Add sync data to the user data
-if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
-    my $sync = NLGetSyncDataFromBorrowernumber( $borrowernumber );
-    if ( $sync ) {
-        $data->{'sync'}       = $sync->sync;
-        $data->{'syncstatus'} = $sync->syncstatus;
-        $data->{'lastsync'}   = $sync->lastsync;
-    }
-}
-
 # Generate CSRF token for upload and delete image buttons
 $template->param(
     csrf_token => Koha::Token->new->generate_csrf({ session_id => $input->cookie('CGISESSID'),}),
@@ -334,12 +299,23 @@ my $patron_messages = Koha::Patron::Messages->search(
     }
 );
 
+if( $patron_messages->count > 0 ){
+    $template->param( patron_messages => $patron_messages );
+}
 
 # Display the language description instead of the code
 # Note that this is certainly wrong
 my ( $subtag, $region ) = split '-', $patron->lang;
 my $translated_language = C4::Languages::language_get_description( $subtag, $subtag, 'language' );
 
+# if the expiry date is before today ie they have expired
+if ( $patron->is_expired || $patron->is_going_to_expire ) {
+    $template->param(
+        flagged => 1
+    );
+}
+
+my $total = $patron->account->balance;
 $template->param(
     patron          => $patron,
     translated_language => $translated_language,
@@ -358,7 +334,6 @@ $template->param(
     PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20,
     relatives_issues_count => $relatives_issues_count,
     relatives_borrowernumbers => \@relatives,
-    patron_messages       => $patron_messages,
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;