Lines 41-47
use C4::Members; # GetBorrowersWhoHavexxxBorrowed.
Link Here
|
41 |
use C4::Circulation; # AnonymiseIssueHistory. |
41 |
use C4::Circulation; # AnonymiseIssueHistory. |
42 |
use C4::VirtualShelves (); #no import |
42 |
use C4::VirtualShelves (); #no import |
43 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
43 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
|
|
44 |
use Koha::Database; |
44 |
use Date::Calc qw/Today Add_Delta_YM/; |
45 |
use Date::Calc qw/Today Add_Delta_YM/; |
|
|
46 |
use Koha::List::Patron; |
45 |
|
47 |
|
46 |
my $cgi = new CGI; |
48 |
my $cgi = new CGI; |
47 |
|
49 |
|
Lines 64-69
my $borrower_dateexpiry =
Link Here
|
64 |
$params->{borrower_dateexpiry} |
66 |
$params->{borrower_dateexpiry} |
65 |
? dt_from_string $params->{borrower_dateexpiry} |
67 |
? dt_from_string $params->{borrower_dateexpiry} |
66 |
: undef; |
68 |
: undef; |
|
|
69 |
my $patron_list_id = $params->{patron_list_id}; |
67 |
|
70 |
|
68 |
my $borrower_categorycode = $params->{'borrower_categorycode'} || q{}; |
71 |
my $borrower_categorycode = $params->{'borrower_categorycode'} || q{}; |
69 |
|
72 |
|
Lines 81-108
if ( $step == 2 ) {
Link Here
|
81 |
|
84 |
|
82 |
my %checkboxes = map { $_ => 1 } split /\0/, $params->{'checkbox'}; |
85 |
my %checkboxes = map { $_ => 1 } split /\0/, $params->{'checkbox'}; |
83 |
|
86 |
|
84 |
my $totalDel; |
|
|
85 |
my $membersToDelete; |
87 |
my $membersToDelete; |
86 |
if ( $checkboxes{borrower} ) { |
88 |
if ($patron_list_id) { |
87 |
$membersToDelete = GetBorrowersToExpunge( |
89 |
my @patron_list_patrons = |
88 |
_get_selection_params($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) |
90 |
Koha::Database->new()->schema()->resultset('PatronListPatron') |
89 |
); |
91 |
->search( { patron_list_id => $patron_list_id } ); |
90 |
_skip_borrowers_with_nonzero_balance( $membersToDelete ); |
92 |
$membersToDelete = \@patron_list_patrons; |
91 |
$totalDel = scalar @$membersToDelete; |
|
|
92 |
|
93 |
} |
93 |
} |
94 |
my $totalAno; |
94 |
else { |
|
|
95 |
if ( $checkboxes{borrower} ) { |
96 |
$membersToDelete = GetBorrowersToExpunge( |
97 |
_get_selection_params( |
98 |
$not_borrowered_since, |
99 |
$borrower_dateexpiry, |
100 |
$borrower_categorycode, |
101 |
) |
102 |
); |
103 |
} |
104 |
} |
105 |
_skip_borrowers_with_nonzero_balance($membersToDelete); |
106 |
|
95 |
my $membersToAnonymize; |
107 |
my $membersToAnonymize; |
96 |
if ( $checkboxes{issue} ) { |
108 |
if ( $checkboxes{issue} ) { |
97 |
$membersToAnonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); |
109 |
$membersToAnonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); |
98 |
$totalAno = scalar @$membersToAnonymize; |
|
|
99 |
} |
110 |
} |
100 |
|
111 |
|
101 |
$template->param( |
112 |
$template->param( |
102 |
totalToDelete => $totalDel, |
|
|
103 |
totalToAnonymize => $totalAno, |
104 |
memberstodelete_list => $membersToDelete, |
113 |
memberstodelete_list => $membersToDelete, |
105 |
memberstoanonymize_list => $membersToAnonymize, |
114 |
memberstoanonymize_list => $membersToAnonymize, |
|
|
115 |
patron_list_id => $patron_list_id, |
106 |
); |
116 |
); |
107 |
} |
117 |
} |
108 |
|
118 |
|
Lines 114-131
elsif ( $step == 3 ) {
Link Here
|
114 |
|
124 |
|
115 |
# delete members |
125 |
# delete members |
116 |
if ($do_delete) { |
126 |
if ($do_delete) { |
117 |
my $membersToDelete = GetBorrowersToExpunge( |
127 |
my $membersToDelete; |
118 |
_get_selection_params($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) |
128 |
if ($patron_list_id) { |
119 |
); |
129 |
my @patron_list_patrons = |
120 |
_skip_borrowers_with_nonzero_balance( $membersToDelete ); |
130 |
Koha::Database->new()->schema()->resultset('PatronListPatron') |
|
|
131 |
->search( { patron_list_id => $patron_list_id } ); |
132 |
$membersToDelete = \@patron_list_patrons; |
133 |
} |
134 |
else { |
135 |
$membersToDelete = GetBorrowersToExpunge( |
136 |
_get_selection_params( |
137 |
$not_borrowered_since, $borrower_dateexpiry, |
138 |
$borrower_categorycode |
139 |
) |
140 |
); |
141 |
} |
142 |
_skip_borrowers_with_nonzero_balance($membersToDelete); |
143 |
|
121 |
$totalDel = scalar(@$membersToDelete); |
144 |
$totalDel = scalar(@$membersToDelete); |
122 |
$radio = $params->{'radio'}; |
145 |
$radio = $params->{'radio'}; |
123 |
for ( my $i = 0 ; $i < $totalDel ; $i++ ) { |
146 |
for ( my $i = 0 ; $i < $totalDel ; $i++ ) { |
124 |
$radio eq 'testrun' && last; |
147 |
$radio eq 'testrun' && last; |
125 |
my $borrowernumber = $membersToDelete->[$i]->{'borrowernumber'}; |
148 |
my $borrowernumber = $membersToDelete->[$i]->{'borrowernumber'} |
126 |
$radio eq 'trash' && MoveMemberToDeleted( $borrowernumber ); |
149 |
|| $membersToDelete->[$i]->get_column('borrowernumber'); |
127 |
C4::VirtualShelves::HandleDelBorrower( $borrowernumber ); |
150 |
$radio eq 'trash' && MoveMemberToDeleted($borrowernumber); |
128 |
DelMember( $borrowernumber ); |
151 |
C4::VirtualShelves::HandleDelBorrower($borrowernumber); |
|
|
152 |
DelMember($borrowernumber); |
129 |
} |
153 |
} |
130 |
$template->param( |
154 |
$template->param( |
131 |
do_delete => '1', |
155 |
do_delete => '1', |
Lines 146-151
elsif ( $step == 3 ) {
Link Here
|
146 |
trash => ( $radio eq "trash" ) ? (1) : (0), |
170 |
trash => ( $radio eq "trash" ) ? (1) : (0), |
147 |
testrun => ( $radio eq "testrun" ) ? 1: 0, |
171 |
testrun => ( $radio eq "testrun" ) ? 1: 0, |
148 |
); |
172 |
); |
|
|
173 |
} else { # $step == 1 |
174 |
$template->param( patron_lists => [ GetPatronLists() ] ); |
149 |
} |
175 |
} |
150 |
|
176 |
|
151 |
$template->param( |
177 |
$template->param( |
Lines 164-170
sub _skip_borrowers_with_nonzero_balance {
Link Here
|
164 |
my $borrowers = shift; |
190 |
my $borrowers = shift; |
165 |
my $balance; |
191 |
my $balance; |
166 |
@$borrowers = map { |
192 |
@$borrowers = map { |
167 |
(undef, undef, $balance) = GetMemberIssuesAndFines( $_->{borrowernumber} ); |
193 |
(undef, undef, $balance) = GetMemberIssuesAndFines( $_->{borrowernumber} || $_->get_column('borrowernumber') ); |
168 |
($balance != 0) ? (): ($_); |
194 |
($balance != 0) ? (): ($_); |
169 |
} @$borrowers; |
195 |
} @$borrowers; |
170 |
} |
196 |
} |
171 |
- |
|
|