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; |
87 |
if ($patron_list_id) { |
85 |
if ( $checkboxes{borrower} ) { |
88 |
my @patron_list_patrons = |
86 |
$membersToDelete = GetBorrowersToExpunge( |
89 |
Koha::Database->new()->schema()->resultset('PatronListPatron') |
87 |
_get_selection_params($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) |
90 |
->search( { patron_list_id => $patron_list_id } ); |
88 |
); |
91 |
$patrons_to_delete = \@patron_list_patrons; |
89 |
_skip_borrowers_with_nonzero_balance( $membersToDelete ); |
|
|
90 |
$totalDel = scalar @$membersToDelete; |
91 |
|
92 |
} |
92 |
} |
93 |
my $totalAno; |
93 |
else { |
94 |
my $membersToAnonymize; |
94 |
if ( $checkboxes{borrower} ) { |
|
|
95 |
$patrons_to_delete = GetBorrowersToExpunge( |
96 |
_get_selection_params( |
97 |
$not_borrowered_since, |
98 |
$borrower_dateexpiry, |
99 |
$borrower_categorycode, |
100 |
) |
101 |
); |
102 |
} |
103 |
} |
104 |
_skip_borrowers_with_nonzero_balance_or_issues($patrons_to_delete); |
105 |
|
106 |
my $members_to_anonymize; |
95 |
if ( $checkboxes{issue} ) { |
107 |
if ( $checkboxes{issue} ) { |
96 |
$membersToAnonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); |
108 |
$members_to_anonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); |
97 |
$totalAno = scalar @$membersToAnonymize; |
|
|
98 |
} |
109 |
} |
99 |
|
110 |
|
100 |
$template->param( |
111 |
$template->param( |
101 |
totalToDelete => $totalDel, |
112 |
patrons_to_delete => $patrons_to_delete, |
102 |
totalToAnonymize => $totalAno, |
113 |
patrons_to_anonymize => $members_to_anonymize, |
103 |
memberstodelete_list => $membersToDelete, |
114 |
patron_list_id => $patron_list_id, |
104 |
memberstoanonymize_list => $membersToAnonymize, |
|
|
105 |
); |
115 |
); |
106 |
} |
116 |
} |
107 |
|
117 |
|
Lines 113-130
elsif ( $step == 3 ) {
Link Here
|
113 |
|
123 |
|
114 |
# delete members |
124 |
# delete members |
115 |
if ($do_delete) { |
125 |
if ($do_delete) { |
116 |
my $membersToDelete = GetBorrowersToExpunge( |
126 |
my $patrons_to_delete; |
117 |
_get_selection_params($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) |
127 |
if ($patron_list_id) { |
118 |
); |
128 |
my @patron_list_patrons = |
119 |
_skip_borrowers_with_nonzero_balance( $membersToDelete ); |
129 |
Koha::Database->new()->schema()->resultset('PatronListPatron') |
120 |
$totalDel = scalar(@$membersToDelete); |
130 |
->search( { patron_list_id => $patron_list_id } ); |
|
|
131 |
$patrons_to_delete = \@patron_list_patrons; |
132 |
} |
133 |
else { |
134 |
$patrons_to_delete = GetBorrowersToExpunge( |
135 |
_get_selection_params( |
136 |
$not_borrowered_since, $borrower_dateexpiry, |
137 |
$borrower_categorycode |
138 |
) |
139 |
); |
140 |
} |
141 |
_skip_borrowers_with_nonzero_balance_or_issues($patrons_to_delete); |
142 |
|
143 |
$totalDel = scalar(@$patrons_to_delete); |
121 |
$radio = $params->{'radio'}; |
144 |
$radio = $params->{'radio'}; |
122 |
for ( my $i = 0 ; $i < $totalDel ; $i++ ) { |
145 |
for ( my $i = 0 ; $i < $totalDel ; $i++ ) { |
123 |
$radio eq 'testrun' && last; |
146 |
$radio eq 'testrun' && last; |
124 |
my $borrowernumber = $membersToDelete->[$i]->{'borrowernumber'}; |
147 |
my $borrowernumber = $patrons_to_delete->[$i]->{'borrowernumber'} |
125 |
$radio eq 'trash' && MoveMemberToDeleted( $borrowernumber ); |
148 |
|| $patrons_to_delete->[$i]->get_column('borrowernumber'); |
126 |
C4::Members::HandleDelBorrower( $borrowernumber ); |
149 |
$radio eq 'trash' && MoveMemberToDeleted($borrowernumber); |
127 |
DelMember( $borrowernumber ); |
150 |
C4::Members::HandleDelBorrower($borrowernumber); |
|
|
151 |
DelMember($borrowernumber); |
128 |
} |
152 |
} |
129 |
$template->param( |
153 |
$template->param( |
130 |
do_delete => '1', |
154 |
do_delete => '1', |
Lines 145-150
elsif ( $step == 3 ) {
Link Here
|
145 |
trash => ( $radio eq "trash" ) ? (1) : (0), |
169 |
trash => ( $radio eq "trash" ) ? (1) : (0), |
146 |
testrun => ( $radio eq "testrun" ) ? 1: 0, |
170 |
testrun => ( $radio eq "testrun" ) ? 1: 0, |
147 |
); |
171 |
); |
|
|
172 |
} else { # $step == 1 |
173 |
$template->param( patron_lists => [ GetPatronLists() ] ); |
148 |
} |
174 |
} |
149 |
|
175 |
|
150 |
$template->param( |
176 |
$template->param( |
Lines 159-170
$template->param(
Link Here
|
159 |
#writing the template |
185 |
#writing the template |
160 |
output_html_with_http_headers $cgi, $cookie, $template->output; |
186 |
output_html_with_http_headers $cgi, $cookie, $template->output; |
161 |
|
187 |
|
162 |
sub _skip_borrowers_with_nonzero_balance { |
188 |
sub _skip_borrowers_with_nonzero_balance_or_issues { |
163 |
my $borrowers = shift; |
189 |
my $borrowers = shift; |
164 |
my $balance; |
190 |
my $balance; |
|
|
191 |
my $issues; |
165 |
@$borrowers = map { |
192 |
@$borrowers = map { |
166 |
(undef, undef, $balance) = GetMemberIssuesAndFines( $_->{borrowernumber} ); |
193 |
(undef, $issues, $balance) = GetMemberIssuesAndFines( $_->{borrowernumber} || $_->get_column('borrowernumber') ); |
167 |
($balance != 0) ? (): ($_); |
194 |
($balance != 0 || $issues != 0) ? (): ($_); |
168 |
} @$borrowers; |
195 |
} @$borrowers; |
169 |
} |
196 |
} |
170 |
|
197 |
|
171 |
- |
|
|