Lines 40-46
use C4::Output;
Link Here
|
40 |
use C4::Members; # GetBorrowersWhoHavexxxBorrowed. |
40 |
use C4::Members; # GetBorrowersWhoHavexxxBorrowed. |
41 |
use C4::Circulation; # AnonymiseIssueHistory. |
41 |
use C4::Circulation; # AnonymiseIssueHistory. |
42 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
42 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
|
|
43 |
use Koha::Database; |
43 |
use Date::Calc qw/Today Add_Delta_YM/; |
44 |
use Date::Calc qw/Today Add_Delta_YM/; |
|
|
45 |
use Koha::List::Patron; |
44 |
|
46 |
|
45 |
my $cgi = new CGI; |
47 |
my $cgi = new CGI; |
46 |
|
48 |
|
Lines 63-68
my $borrower_dateexpiry =
Link Here
|
63 |
$params->{borrower_dateexpiry} |
65 |
$params->{borrower_dateexpiry} |
64 |
? dt_from_string $params->{borrower_dateexpiry} |
66 |
? dt_from_string $params->{borrower_dateexpiry} |
65 |
: undef; |
67 |
: undef; |
|
|
68 |
my $patron_list_id = $params->{patron_list_id}; |
66 |
|
69 |
|
67 |
my $borrower_categorycode = $params->{'borrower_categorycode'} || q{}; |
70 |
my $borrower_categorycode = $params->{'borrower_categorycode'} || q{}; |
68 |
|
71 |
|
Lines 80-107
if ( $step == 2 ) {
Link Here
|
80 |
|
83 |
|
81 |
my %checkboxes = map { $_ => 1 } split /\0/, $params->{'checkbox'}; |
84 |
my %checkboxes = map { $_ => 1 } split /\0/, $params->{'checkbox'}; |
82 |
|
85 |
|
83 |
my $totalDel; |
86 |
my $patrons_to_delete; |
84 |
my $membersToDelete; |
|
|
85 |
if ( $checkboxes{borrower} ) { |
87 |
if ( $checkboxes{borrower} ) { |
86 |
$membersToDelete = GetBorrowersToExpunge( |
88 |
$patrons_to_delete = GetBorrowersToExpunge( |
87 |
_get_selection_params($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) |
89 |
_get_selection_params( |
|
|
90 |
$not_borrowered_since, |
91 |
$borrower_dateexpiry, |
92 |
$borrower_categorycode, |
93 |
$patron_list_id, |
94 |
) |
88 |
); |
95 |
); |
89 |
_skip_borrowers_with_nonzero_balance( $membersToDelete ); |
|
|
90 |
$totalDel = scalar @$membersToDelete; |
91 |
|
92 |
} |
96 |
} |
93 |
my $totalAno; |
97 |
_skip_borrowers_with_nonzero_balance($patrons_to_delete); |
94 |
my $membersToAnonymize; |
98 |
|
|
|
99 |
my $members_to_anonymize; |
95 |
if ( $checkboxes{issue} ) { |
100 |
if ( $checkboxes{issue} ) { |
96 |
$membersToAnonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); |
101 |
$members_to_anonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); |
97 |
$totalAno = scalar @$membersToAnonymize; |
|
|
98 |
} |
102 |
} |
99 |
|
103 |
|
100 |
$template->param( |
104 |
$template->param( |
101 |
totalToDelete => $totalDel, |
105 |
patrons_to_delete => $patrons_to_delete, |
102 |
totalToAnonymize => $totalAno, |
106 |
patrons_to_anonymize => $members_to_anonymize, |
103 |
memberstodelete_list => $membersToDelete, |
107 |
patron_list_id => $patron_list_id, |
104 |
memberstoanonymize_list => $membersToAnonymize, |
|
|
105 |
); |
108 |
); |
106 |
} |
109 |
} |
107 |
|
110 |
|
Lines 113-130
elsif ( $step == 3 ) {
Link Here
|
113 |
|
116 |
|
114 |
# delete members |
117 |
# delete members |
115 |
if ($do_delete) { |
118 |
if ($do_delete) { |
116 |
my $membersToDelete = GetBorrowersToExpunge( |
119 |
my $patrons_to_delete = GetBorrowersToExpunge( |
117 |
_get_selection_params($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) |
120 |
_get_selection_params( |
118 |
); |
121 |
$not_borrowered_since, $borrower_dateexpiry, |
119 |
_skip_borrowers_with_nonzero_balance( $membersToDelete ); |
122 |
$borrower_categorycode, $patron_list_id |
120 |
$totalDel = scalar(@$membersToDelete); |
123 |
) |
|
|
124 |
); |
125 |
_skip_borrowers_with_nonzero_balance($patrons_to_delete); |
126 |
|
127 |
$totalDel = scalar(@$patrons_to_delete); |
121 |
$radio = $params->{'radio'}; |
128 |
$radio = $params->{'radio'}; |
122 |
for ( my $i = 0 ; $i < $totalDel ; $i++ ) { |
129 |
for ( my $i = 0 ; $i < $totalDel ; $i++ ) { |
123 |
$radio eq 'testrun' && last; |
130 |
$radio eq 'testrun' && last; |
124 |
my $borrowernumber = $membersToDelete->[$i]->{'borrowernumber'}; |
131 |
my $borrowernumber = $patrons_to_delete->[$i]->{'borrowernumber'} |
125 |
$radio eq 'trash' && MoveMemberToDeleted( $borrowernumber ); |
132 |
|| $patrons_to_delete->[$i]->get_column('borrowernumber'); |
126 |
C4::Members::HandleDelBorrower( $borrowernumber ); |
133 |
$radio eq 'trash' && MoveMemberToDeleted($borrowernumber); |
127 |
DelMember( $borrowernumber ); |
134 |
C4::Members::HandleDelBorrower($borrowernumber); |
|
|
135 |
DelMember($borrowernumber); |
128 |
} |
136 |
} |
129 |
$template->param( |
137 |
$template->param( |
130 |
do_delete => '1', |
138 |
do_delete => '1', |
Lines 145-150
elsif ( $step == 3 ) {
Link Here
|
145 |
trash => ( $radio eq "trash" ) ? (1) : (0), |
153 |
trash => ( $radio eq "trash" ) ? (1) : (0), |
146 |
testrun => ( $radio eq "testrun" ) ? 1: 0, |
154 |
testrun => ( $radio eq "testrun" ) ? 1: 0, |
147 |
); |
155 |
); |
|
|
156 |
} else { # $step == 1 |
157 |
my @all_lists = GetPatronLists(); |
158 |
my @non_empty_lists; |
159 |
foreach my $list (@all_lists){ |
160 |
my @patrons = $list->patron_list_patrons(); |
161 |
if( scalar @patrons ) { push(@non_empty_lists,$list) } |
162 |
} |
163 |
$template->param( patron_lists => [ @non_empty_lists ] ); |
148 |
} |
164 |
} |
149 |
|
165 |
|
150 |
$template->param( |
166 |
$template->param( |
Lines 163-175
sub _skip_borrowers_with_nonzero_balance {
Link Here
|
163 |
my $borrowers = shift; |
179 |
my $borrowers = shift; |
164 |
my $balance; |
180 |
my $balance; |
165 |
@$borrowers = map { |
181 |
@$borrowers = map { |
166 |
(undef, undef, $balance) = GetMemberIssuesAndFines( $_->{borrowernumber} ); |
182 |
(undef, undef, $balance) = GetMemberIssuesAndFines( $_->{borrowernumber} || $_->get_column('borrowernumber') ); |
167 |
($balance != 0) ? (): ($_); |
183 |
($balance != 0) ? (): ($_); |
168 |
} @$borrowers; |
184 |
} @$borrowers; |
169 |
} |
185 |
} |
170 |
|
186 |
|
171 |
sub _get_selection_params { |
187 |
sub _get_selection_params { |
172 |
my ($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) = @_; |
188 |
my ($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode, $patron_list_id) = @_; |
173 |
|
189 |
|
174 |
my $params = {}; |
190 |
my $params = {}; |
175 |
$params->{not_borrowered_since} = output_pref({ |
191 |
$params->{not_borrowered_since} = output_pref({ |
Lines 183-188
sub _get_selection_params {
Link Here
|
183 |
dateonly => 1 |
199 |
dateonly => 1 |
184 |
}) if $borrower_dateexpiry; |
200 |
}) if $borrower_dateexpiry; |
185 |
$params->{category_code} = $borrower_categorycode if $borrower_categorycode; |
201 |
$params->{category_code} = $borrower_categorycode if $borrower_categorycode; |
|
|
202 |
$params->{patron_list_id} = $patron_list_id if $patron_list_id; |
186 |
|
203 |
|
187 |
return $params; |
204 |
return $params; |
188 |
}; |
205 |
}; |
189 |
- |
|
|