Bug 22359: Improvements to payment collection inputs
[koha-ffzg.git] / members / moremember.pl
index d68e6ef..f083203 100755 (executable)
@@ -53,9 +53,20 @@ BEGIN {
 my $input = CGI->new;
 $debug or $debug = $input->param('debug') || 0;
 
+
+my $print = $input->param('print');
+
+my $template_name;
+
+if (defined $print and $print eq "brief") {
+        $template_name = "members/moremember-brief.tt";
+} else {
+        $template_name = "members/moremember.tt";
+}
+
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
-        template_name   => "members/moremember.tt",
+        template_name   => $template_name,
         query           => $input,
         type            => "intranet",
         authnotrequired => 0,
@@ -68,7 +79,7 @@ my $error = $input->param('error');
 $template->param( error => $error ) if ( $error );
 
 my $patron         = Koha::Patrons->find( $borrowernumber );
-my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
+my $logged_in_user = Koha::Patrons->find( $loggedinuser );
 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
 
 my $category_type = $patron->category->category_type;
@@ -85,28 +96,35 @@ if ( $patron->is_debarred ) {
         $template->param( 'userdebarreddate' => $patron->debarred );
     }
 }
+$template->param( flagged => 1 ) if $patron->account_locked;
 
 my @relatives;
-if ( my $guarantor = $patron->guarantor ) {
-    $template->param( guarantor => $guarantor );
-    push @relatives, $guarantor->borrowernumber;
-    push @relatives, $_->borrowernumber for $patron->siblings;
-} elsif ( $patron->contactname || $patron->contactfirstname ) {
-    $template->param(
-        guarantor => {
-            firstname => $patron->contactfirstname,
-            surname   => $patron->contactname,
-        }
-    );
-} else {
-    my @guarantees = $patron->guarantees;
-    $template->param( guarantees => \@guarantees );
-    push @relatives, $_->borrowernumber for @guarantees;
+my $guarantor_relationships = $patron->guarantor_relationships;
+my @guarantees              = $patron->guarantee_relationships->guarantees;
+my @guarantors              = $guarantor_relationships->guarantors;
+if (@guarantors) {
+    push( @relatives, $_->id ) for @guarantors;
+    push( @relatives, $_->id ) for $patron->siblings();
 }
+else {
+    push( @relatives, $_->id ) for @guarantees;
+}
+$template->param(
+    guarantor_relationships => $guarantor_relationships,
+    guarantees              => \@guarantees,
+);
 
 my $relatives_issues_count =
     Koha::Checkouts->count({ borrowernumber => \@relatives });
 
+# Calculate and display patron's age
+if ( !$patron->is_valid_age ) {
+    $template->param( age_limitations => 1 );
+    $template->param( age_low => $patron->category->dateofbirthrequired );
+    $template->param( age_high => $patron->category->upperagelimit );
+}
+$template->param( age => $patron->get_age );
+
 # Generate CSRF token for upload and delete image buttons
 $template->param(
     csrf_token => Koha::Token->new->generate_csrf({ session_id => $input->cookie('CGISESSID'),}),
@@ -191,6 +209,7 @@ $template->param(
     housebound_role => scalar $patron->housebound_role,
     relatives_issues_count => $relatives_issues_count,
     relatives_borrowernumbers => \@relatives,
+    logged_in_user => $logged_in_user,
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;