Bug 17599: (QA followup) Perltidy really long lines
[koha.git] / tools / cleanborrowers.pl
index 4cc9169..a1c2135 100755 (executable)
@@ -39,6 +39,8 @@ use C4::Output;
 use C4::Members;        # GetBorrowersWhoHavexxxBorrowed.
 use C4::Circulation;    # AnonymiseIssueHistory.
 use Koha::DateUtils qw( dt_from_string output_pref );
+use Koha::Patron::Categories;
+use Koha::Patrons;
 use Date::Calc qw/Today Add_Delta_YM/;
 use Koha::List::Patron;
 
@@ -63,6 +65,10 @@ my $borrower_dateexpiry =
   $params->{borrower_dateexpiry}
   ? dt_from_string $params->{borrower_dateexpiry}
   : undef;
+my $borrower_lastseen =
+  $params->{borrower_lastseen}
+  ? dt_from_string $params->{borrower_lastseen}
+  : undef;
 my $patron_list_id = $params->{patron_list_id};
 
 my $borrower_categorycode = $params->{'borrower_categorycode'} || q{};
@@ -79,6 +85,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 
 my $branch = $params->{ branch } || '*';
 $template->param( current_branch => $branch );
+$template->param( OnlyMine => C4::Context->only_my_library );
 
 if ( $step == 2 ) {
 
@@ -90,6 +97,7 @@ if ( $step == 2 ) {
              _get_selection_params(
                   $not_borrowed_since,
                   $borrower_dateexpiry,
+                  $borrower_lastseen,
                   $borrower_categorycode,
                   $patron_list_id,
                   $branch
@@ -126,6 +134,7 @@ elsif ( $step == 3 ) {
                 _get_selection_params(
                     $not_borrowed_since,
                     $borrower_dateexpiry,
+                    $borrower_lastseen,
                     $borrower_categorycode,
                     $patron_list_id,
                     $branch
@@ -138,9 +147,9 @@ elsif ( $step == 3 ) {
         for ( my $i = 0 ; $i < $totalDel ; $i++ ) {
             $radio eq 'testrun' && last;
             my $borrowernumber = $patrons_to_delete->[$i]->{'borrowernumber'};
-            $radio eq 'trash' && MoveMemberToDeleted($borrowernumber);
-            C4::Members::HandleDelBorrower($borrowernumber);
-            DelMember($borrowernumber);
+            my $patron = Koha::Patrons->find($borrowernumber);
+            $radio eq 'trash' && $patron->move_to_deleted;
+            $patron->delete;
         }
         $template->param(
             do_delete => '1',
@@ -171,12 +180,15 @@ elsif ( $step == 3 ) {
     $template->param( patron_lists => [ @non_empty_lists ] );
 }
 
+my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']});
+
 $template->param(
     step                   => $step,
     not_borrowed_since   => $not_borrowed_since,
     borrower_dateexpiry    => $borrower_dateexpiry,
+    borrower_lastseen      => $borrower_lastseen,
     last_issue_date        => $last_issue_date,
-    borrower_categorycodes => GetBorrowercategoryList(),
+    borrower_categorycodes => $patron_categories,
     borrower_categorycode  => $borrower_categorycode,
 );
 
@@ -193,7 +205,7 @@ sub _skip_borrowers_with_nonzero_balance {
 }
 
 sub _get_selection_params {
-    my ($not_borrowed_since, $borrower_dateexpiry,
+    my ($not_borrowed_since, $borrower_dateexpiry, $borrower_lastseen,
         $borrower_categorycode, $patron_list_id, $branch) = @_;
 
     my $params = {};
@@ -207,6 +219,11 @@ sub _get_selection_params {
         dateformat => 'iso',
         dateonly   => 1
     }) if $borrower_dateexpiry;
+    $params->{last_seen} = output_pref({
+        dt         => $borrower_lastseen,
+        dateformat => 'iso',
+        dateonly   => 1
+    }) if $borrower_lastseen;
     $params->{category_code} = $borrower_categorycode if $borrower_categorycode;
     $params->{patron_list_id} = $patron_list_id if $patron_list_id;