Bug 21087: Fix create_superlibrarian.pl script
[koha.git] / Koha / Clubs.pm
index fff88d8..eeaf4ef 100644 (file)
@@ -22,6 +22,7 @@ use Modern::Perl;
 use Carp;
 
 use Koha::Database;
+use Koha::DateUtils qw( dt_from_string );
 
 use Koha::Club;
 
@@ -56,6 +57,20 @@ sub get_enrollable {
         }
     }
 
+    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
+
+    # Only clubs with no end date or an end date in the future can be enrolled in
+    $params->{'-and'} = [
+        -or => [
+            date_end => { '>=' => $dtf->format_datetime( dt_from_string() ) },
+            date_end => undef,
+        ],
+        -or => [
+            'me.branchcode' => $borrower->branchcode,
+            'me.branchcode' => undef,
+        ]
+    ];
+
     my $rs = $self->_resultset()->search( $params, { prefetch => 'club_template' } );
 
     if (wantarray) {