Bug 11175: (follow-up) Use clean_search_term
[koha-ffzg.git] / Koha / Patrons.pm
index 0b65756..8e8bed9 100644 (file)
@@ -20,17 +20,14 @@ package Koha::Patrons;
 
 use Modern::Perl;
 
-use Carp;
 
 use Koha::Database;
-use Koha::DateUtils;
+use Koha::DateUtils qw( dt_from_string );
 
 use Koha::ArticleRequests;
-use Koha::ArticleRequest::Status;
 use Koha::Patron;
 use Koha::Exceptions::Patron;
 use Koha::Patron::Categories;
-use Date::Calc qw( Today Add_Delta_YMD );
 
 use base qw(Koha::Objects);
 
@@ -233,6 +230,26 @@ sub delete {
     return $patrons_deleted;
 }
 
+=head3 filter_by_expiration_date
+
+    Koha::Patrons->filter_by_expiration_date{{ days => $x });
+
+    Returns set of Koha patron objects expired $x days.
+
+=cut
+
+sub filter_by_expiration_date {
+    my ( $class, $params ) = @_;
+
+    return $class->filter_by_last_update(
+        {
+            timestamp_column_name => 'dateexpiry',
+            days                  => $params->{days} || 0,
+            days_inclusive        => 1,
+        }
+    );
+}
+
 =head3 search_unsubscribed
 
     Koha::Patrons->search_unsubscribed;
@@ -397,10 +414,10 @@ sub search_patrons_to_update_category {
     }
     if ($params->{fine_min} || $params->{fine_max}) {
         $query{join} = ["accountlines"];
-        $query{select} = ["borrowernumber", "accountlines.amountoutstanding" ];
+        $query{columns} = ["borrowernumber"];
         $query{group_by} = ["borrowernumber"];
-        $query{having} = \['sum(accountlines.amountoutstanding) <= ?',$params->{fine_max}] if defined $params->{fine_max};
-        $query{having} = \['sum(accountlines.amountoutstanding) >= ?',$params->{fine_min}] if defined $params->{fine_min};
+        $query{having} = \['COALESCE(sum(accountlines.amountoutstanding),0) <= ?',$params->{fine_max}] if defined $params->{fine_max};
+        $query{having} = \['COALESCE(sum(accountlines.amountoutstanding),0) >= ?',$params->{fine_min}] if defined $params->{fine_min};
     }
     return $self->search($search_params,\%query);
 }
@@ -446,7 +463,7 @@ sub filter_by_attribute_type {
 
 my $patrons = Koha::Patrons->filter_by_attribute_value($attribute_value);
 
-Return a Koha::Patrons set with patrong having the attribute value passed in paramter.
+Return a Koha::Patrons set with patrong having the attribute value passed in parameter.
 
 =cut