Lines 25-37
use C4::Log qw/logaction/;
Link Here
|
25 |
use Koha::DateUtils; |
25 |
use Koha::DateUtils; |
26 |
use Getopt::Long; |
26 |
use Getopt::Long; |
27 |
|
27 |
|
28 |
my ($help, $verbose, $confirm, $log); |
28 |
my ($help, $verbose, $confirm, $log, $stdout_log); |
29 |
|
29 |
|
30 |
GetOptions( |
30 |
GetOptions( |
31 |
'h|help' => \$help, |
31 |
'h|help' => \$help, |
32 |
'v|verbose' => \$verbose, |
32 |
'v|verbose' => \$verbose, |
33 |
'l|log' => \$log, |
33 |
'l|log' => \$log, |
34 |
'c|confirm' => \$confirm |
34 |
'c|confirm' => \$confirm, |
|
|
35 |
'p|print' => \$stdout_log |
35 |
); |
36 |
); |
36 |
|
37 |
|
37 |
my $usage = << 'ENDUSAGE'; |
38 |
my $usage = << 'ENDUSAGE'; |
Lines 44-49
This script has the following parameters :
Link Here
|
44 |
-h --help: this message |
45 |
-h --help: this message |
45 |
-l --log: log changes to the system logs |
46 |
-l --log: log changes to the system logs |
46 |
-c --confirm: commit changes (test only mode if not present) |
47 |
-c --confirm: commit changes (test only mode if not present) |
|
|
48 |
-p --print: output affected fine records details to the STDOUT |
47 |
-v --verbose |
49 |
-v --verbose |
48 |
|
50 |
|
49 |
ENDUSAGE |
51 |
ENDUSAGE |
Lines 55-61
ENDUSAGE
Link Here
|
55 |
} |
57 |
} |
56 |
|
58 |
|
57 |
Bug_17135_fix({ |
59 |
Bug_17135_fix({ |
58 |
'verbose' => $verbose, 'log' => $log, 'confirm' => $confirm |
60 |
'verbose' => $verbose, 'log' => $log, |
|
|
61 |
'confirm' => $confirm, 'stdout_log' => $stdout_log |
59 |
}); |
62 |
}); |
60 |
|
63 |
|
61 |
exit 0; |
64 |
exit 0; |
Lines 67-72
sub Bug_17135_fix {
Link Here
|
67 |
my $verbose = $params->{'verbose'}; |
70 |
my $verbose = $params->{'verbose'}; |
68 |
my $log = $params->{'log'}; |
71 |
my $log = $params->{'log'}; |
69 |
my $confirm = $params->{'confirm'}; |
72 |
my $confirm = $params->{'confirm'}; |
|
|
73 |
my $stdout_log = $params->{'stdout_log'}; |
70 |
|
74 |
|
71 |
my $control = C4::Context->preference('CircControl'); |
75 |
my $control = C4::Context->preference('CircControl'); |
72 |
my $mode = C4::Context->preference('finesMode'); |
76 |
my $mode = C4::Context->preference('finesMode'); |
Lines 170-198
sub Bug_17135_fix {
Link Here
|
170 |
}; |
174 |
}; |
171 |
} |
175 |
} |
172 |
|
176 |
|
173 |
Warn("Fine records with mismatched old vs current due dates: $different_dates_cnt") if $verbose; |
177 |
if ($verbose) { |
174 |
Warn("Non-accruing accountlines FU records (item not due): ".$not_due_not_accruning_cnt); |
178 |
Warn("Fine records with mismatched old vs current due dates: $different_dates_cnt"); |
175 |
Warn("Non-accruing accountlines FU records (item due): ".$due_not_accruning_cnt); |
179 |
Warn("Non-accruing accountlines FU records (item not due): ".$not_due_not_accruning_cnt); |
|
|
180 |
Warn("Non-accruing accountlines FU records (item due): ".$due_not_accruning_cnt); |
181 |
} |
176 |
|
182 |
|
|
|
183 |
if (@$forfixing > 0) { |
184 |
Warn("Dry run (test only mode), skipping ".scalar(@$forfixing)." database changes.") unless ($confirm); |
185 |
} |
186 |
my $updated_cnt = 0; |
177 |
my $update_sql = "UPDATE accountlines SET accounttype = 'F' WHERE accounttype = 'FU' AND accountlines_id = ? LIMIT 1"; |
187 |
my $update_sql = "UPDATE accountlines SET accounttype = 'F' WHERE accounttype = 'FU' AND accountlines_id = ? LIMIT 1"; |
178 |
for my $fine (@$forfixing) { |
188 |
for my $fine (@$forfixing) { |
179 |
my $logentry = "Closing old FU fine (Bug 17135); accountlines_id=".$fine->{accountlines_id}; |
189 |
my $logentry = "Closing old FU fine (Bug 17135); accountlines_id=".$fine->{accountlines_id}; |
180 |
$logentry .= " issue_id=".$fine->{issue_id}." amount=".$fine->{amount}; |
190 |
$logentry .= " issue_id=".$fine->{issue_id}." amount=".$fine->{amount}; |
181 |
$logentry .= "; due dates (old, current): '".$fine->{old_date_due}."', '".$fine->{current_due_date}."'"; |
191 |
$logentry .= "; due dates (old, current): '".$fine->{old_date_due}."', '".$fine->{current_due_date}."'"; |
182 |
$logentry .= "; reason: ".$fine->{log_entry}; |
192 |
$logentry .= "; reason: ".$fine->{log_entry}; |
|
|
193 |
print($logentry."\n") if ($stdout_log); |
183 |
|
194 |
|
184 |
unless ($mode eq 'production') { |
195 |
next unless ($confirm && $mode eq 'production'); |
185 |
print $logentry."\n"; ## FIXME? |
196 |
my $rows_affected = $dbh->do($update_sql, undef, $fine->{accountlines_id}); |
186 |
next; |
197 |
$updated_cnt += $rows_affected; |
187 |
} |
|
|
188 |
unless ($confirm) { |
189 |
Warn("Dry run (test only mode), skipping database changes."); |
190 |
last; |
191 |
} |
192 |
|
193 |
$dbh->do($update_sql, undef, $fine->{accountlines_id}); |
194 |
logaction("FINES", "FU", $fine->{borrowernumber}, $logentry) if ($log); |
198 |
logaction("FINES", "FU", $fine->{borrowernumber}, $logentry) if ($log); |
195 |
} |
199 |
} |
|
|
200 |
if (@$forfixing > 0 && $confirm && $mode eq 'production') { |
201 |
Warn("Database update done, $updated_cnt".((@$forfixing == $updated_cnt)? "": "/".scalar(@$forfixing))." fine records closed successfully."); |
202 |
} |
196 |
} |
203 |
} |
197 |
|
204 |
|
198 |
sub getFinesForChecking { |
205 |
sub getFinesForChecking { |
Lines 203-208
sub getFinesForChecking {
Link Here
|
203 |
LEFT JOIN issues iss USING (issue_id) |
210 |
LEFT JOIN issues iss USING (issue_id) |
204 |
WHERE accounttype = 'FU' |
211 |
WHERE accounttype = 'FU' |
205 |
AND iss.issue_id IS NOT NULL |
212 |
AND iss.issue_id IS NOT NULL |
|
|
213 |
AND iss.borrowernumber = acc.borrowernumber |
214 |
AND iss.itemnumber = acc.itemnumber |
206 |
ORDER BY acc.borrowernumber, acc.issue_id |
215 |
ORDER BY acc.borrowernumber, acc.issue_id |
207 |
"; |
216 |
"; |
208 |
|
217 |
|
Lines 212-216
sub getFinesForChecking {
Link Here
|
212 |
} |
221 |
} |
213 |
|
222 |
|
214 |
sub Warn { |
223 |
sub Warn { |
215 |
print STDERR join("\n", @_, ''); |
224 |
print join("\n", @_, ''); |
216 |
} |
225 |
} |
217 |
- |
|
|