Lines 34-40
use Koha::Script -cron;
Link Here
|
34 |
use C4::Context; |
34 |
use C4::Context; |
35 |
use C4::Overdues qw( Getoverdues CalcFine UpdateFine ); |
35 |
use C4::Overdues qw( Getoverdues CalcFine UpdateFine ); |
36 |
use Getopt::Long qw( GetOptions ); |
36 |
use Getopt::Long qw( GetOptions ); |
37 |
use Carp qw( carp croak ); |
37 |
use Carp qw( carp croak ); |
38 |
use File::Spec; |
38 |
use File::Spec; |
39 |
use Try::Tiny qw( catch try ); |
39 |
use Try::Tiny qw( catch try ); |
40 |
|
40 |
|
Lines 56-67
my $command_line_options = join(" ",@ARGV);
Link Here
|
56 |
cronlogaction({ info => $command_line_options }); |
56 |
cronlogaction({ info => $command_line_options }); |
57 |
|
57 |
|
58 |
GetOptions( |
58 |
GetOptions( |
59 |
'h|help' => \$help, |
59 |
'h|help' => \$help, |
60 |
'v|verbose' => \$verbose, |
60 |
'v|verbose' => \$verbose, |
61 |
'l|log' => \$log, |
61 |
'l|log' => \$log, |
62 |
'o|out:s' => \$output_dir, |
62 |
'o|out:s' => \$output_dir, |
63 |
'm|maxdays:i' => \$maxdays, |
63 |
'm|maxdays:i' => \$maxdays, |
64 |
'i|verifyissue' => \$verify_issue, |
64 |
'i|verifyissue' => \$verify_issue, |
65 |
'maxfinesdays=i' => \$maxfinesdays |
65 |
'maxfinesdays=i' => \$maxfinesdays |
66 |
); |
66 |
); |
67 |
my $usage = << 'ENDUSAGE'; |
67 |
my $usage = << 'ENDUSAGE'; |
Lines 88-120
if ($help) {
Link Here
|
88 |
exit; |
88 |
exit; |
89 |
} |
89 |
} |
90 |
|
90 |
|
91 |
my $script_handler = Koha::Script->new({ script => $0 }); |
91 |
my $script_handler = Koha::Script->new( { script => $0 } ); |
92 |
|
92 |
|
93 |
try { |
93 |
try { |
94 |
$script_handler->lock_exec; |
94 |
$script_handler->lock_exec; |
95 |
} |
95 |
} catch { |
96 |
catch { |
|
|
97 |
my $message = "Skipping execution of $0 ($_)"; |
96 |
my $message = "Skipping execution of $0 ($_)"; |
98 |
print STDERR "$message\n" |
97 |
print STDERR "$message\n" |
99 |
if $verbose; |
98 |
if $verbose; |
100 |
cronlogaction({ info => $message }); |
99 |
cronlogaction( { info => $message } ); |
101 |
exit; |
100 |
exit; |
102 |
}; |
101 |
}; |
103 |
|
102 |
|
104 |
my @borrower_fields = |
103 |
cronlogaction( { info => $command_line_options } ); |
105 |
qw(cardnumber categorycode surname firstname email phone address citystate); |
104 |
|
106 |
my @item_fields = qw(itemnumber barcode date_due); |
105 |
my @borrower_fields = qw(cardnumber categorycode surname firstname email phone address citystate); |
107 |
my @other_fields = qw(days_overdue fine); |
106 |
my @item_fields = qw(itemnumber barcode date_due); |
108 |
my $libname = C4::Context->preference('LibraryName'); |
107 |
my @other_fields = qw(days_overdue fine); |
109 |
my $control = C4::Context->preference('CircControl'); |
108 |
my $libname = C4::Context->preference('LibraryName'); |
110 |
my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
109 |
my $control = C4::Context->preference('CircControl'); |
111 |
my $mode = C4::Context->preference('finesMode'); |
110 |
my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
112 |
my $delim = "\t"; # ? C4::Context->preference('CSVDelimiter') || "\t"; |
111 |
my $mode = C4::Context->preference('finesMode'); |
|
|
112 |
my $delim = "\t"; # ? C4::Context->preference('CSVDelimiter') || "\t"; |
113 |
|
113 |
|
114 |
my %is_holiday; |
114 |
my %is_holiday; |
115 |
my $today = dt_from_string(); |
115 |
my $today = dt_from_string(); |
116 |
my $filename; |
116 |
my $filename; |
117 |
if ($log or $output_dir) { |
117 |
if ( $log or $output_dir ) { |
118 |
$filename = get_filename($output_dir); |
118 |
$filename = get_filename($output_dir); |
119 |
} |
119 |
} |
120 |
|
120 |
|
Lines 133-149
for my $overdue ( @{$overdues} ) {
Link Here
|
133 |
next if $overdue->{itemlost}; |
133 |
next if $overdue->{itemlost}; |
134 |
|
134 |
|
135 |
if ( !defined $overdue->{borrowernumber} ) { |
135 |
if ( !defined $overdue->{borrowernumber} ) { |
136 |
carp |
136 |
carp "ERROR in Getoverdues : issues.borrowernumber IS NULL. Repair 'issues' table now! Skipping record.\n"; |
137 |
"ERROR in Getoverdues : issues.borrowernumber IS NULL. Repair 'issues' table now! Skipping record.\n"; |
|
|
138 |
next; |
137 |
next; |
139 |
} |
138 |
} |
140 |
my $patron = Koha::Patrons->find( $overdue->{borrowernumber} ); |
139 |
my $patron = Koha::Patrons->find( $overdue->{borrowernumber} ); |
141 |
my $branchcode = |
140 |
my $branchcode = |
142 |
( $control eq 'ItemHomeLibrary' ) ? $overdue->{$branch_type} |
141 |
( $control eq 'ItemHomeLibrary' ) ? $overdue->{$branch_type} |
143 |
: ( $control eq 'PatronLibrary' ) ? $patron->branchcode |
142 |
: ( $control eq 'PatronLibrary' ) ? $patron->branchcode |
144 |
: $overdue->{branchcode}; |
143 |
: $overdue->{branchcode}; |
145 |
|
144 |
|
146 |
# In final case, CircControl must be PickupLibrary. (branchcode comes from issues table here). |
145 |
# In final case, CircControl must be PickupLibrary. (branchcode comes from issues table here). |
147 |
if ( !exists $is_holiday{$branchcode} ) { |
146 |
if ( !exists $is_holiday{$branchcode} ) { |
148 |
$is_holiday{$branchcode} = set_holiday( $branchcode, $today ); |
147 |
$is_holiday{$branchcode} = set_holiday( $branchcode, $today ); |
149 |
} |
148 |
} |
Lines 154-176
for my $overdue ( @{$overdues} ) {
Link Here
|
154 |
} |
153 |
} |
155 |
++$counted; |
154 |
++$counted; |
156 |
|
155 |
|
157 |
my ( $amount, $unitcounttotal, $unitcount); |
156 |
my ( $amount, $unitcounttotal, $unitcount ); |
158 |
if ( defined($maxfinesdays) && $maxfinesdays <= $datedue->delta_days( $today )->in_units( 'days' ) ) { |
157 |
if ( defined($maxfinesdays) && $maxfinesdays <= $datedue->delta_days($today)->in_units('days') ) { |
159 |
my $itype = $overdue->{itemtype} || $overdue->{itype}; |
158 |
my $itype = $overdue->{itemtype} || $overdue->{itype}; |
160 |
my $data = Koha::CirculationRules->get_effective_rule( { rule_name => 'overduefinescap', categorycode => $patron->categorycode, itemtype => $itype, branchcode => $branchcode } ); |
159 |
my $data = Koha::CirculationRules->get_effective_rule( |
161 |
if ( defined($data->rule_value) ) { |
160 |
{ |
162 |
$amount = $data->rule_value; |
161 |
rule_name => 'overduefinescap', categorycode => $patron->categorycode, itemtype => $itype, |
|
|
162 |
branchcode => $branchcode |
163 |
} |
164 |
); |
165 |
if ( defined( $data->rule_value ) ) { |
166 |
$amount = $data->rule_value; |
163 |
$unitcount = 'n/a'; |
167 |
$unitcount = 'n/a'; |
164 |
} |
168 |
} else { |
165 |
else { |
169 |
print |
166 |
print "No overduefinescap defined for {branchcode = $branchcode, itemtype = $itype and categorycode = $patron->categorycode}\n"; |
170 |
"No overduefinescap defined for {branchcode = $branchcode, itemtype = $itype and categorycode = $patron->categorycode}\n"; |
167 |
} |
171 |
} |
168 |
} |
172 |
} |
169 |
if (!$amount) { |
173 |
if ( !$amount ) { |
170 |
( $amount, $unitcounttotal, $unitcount ) = CalcFine( $overdue, $patron->categorycode, $branchcode, $datedue, $today ); |
174 |
( $amount, $unitcounttotal, $unitcount ) = |
|
|
175 |
CalcFine( $overdue, $patron->categorycode, $branchcode, $datedue, $today ); |
171 |
} |
176 |
} |
172 |
|
177 |
|
173 |
|
|
|
174 |
# Don't update the fine if today is a holiday. |
178 |
# Don't update the fine if today is a holiday. |
175 |
# This ensures that dropbox mode will remove the correct amount of fine. |
179 |
# This ensures that dropbox mode will remove the correct amount of fine. |
176 |
if ( |
180 |
if ( |
Lines 178-189
for my $overdue ( @{$overdues} ) {
Link Here
|
178 |
&& ( !$is_holiday{$branchcode} |
182 |
&& ( !$is_holiday{$branchcode} |
179 |
|| C4::Context->preference('ChargeFinesOnClosedDays') ) |
183 |
|| C4::Context->preference('ChargeFinesOnClosedDays') ) |
180 |
&& ( $amount && $amount > 0 ) |
184 |
&& ( $amount && $amount > 0 ) |
181 |
) |
185 |
) |
182 |
{ |
186 |
{ |
183 |
if ( $verify_issue ) { |
187 |
if ($verify_issue) { |
|
|
188 |
|
184 |
# if the issue changed before the script got to it, then pass on it. |
189 |
# if the issue changed before the script got to it, then pass on it. |
185 |
my $issue = Koha::Checkouts->find({ issue_id => $overdue->{issue_id} }); |
190 |
my $issue = Koha::Checkouts->find( { issue_id => $overdue->{issue_id} } ); |
186 |
if ( ! $issue or $issue->date_due ne $overdue->{date_due} ) { |
191 |
if ( !$issue or $issue->date_due ne $overdue->{date_due} ) { |
187 |
$counted--; |
192 |
$counted--; |
188 |
next; |
193 |
next; |
189 |
} |
194 |
} |
Lines 203-216
for my $overdue ( @{$overdues} ) {
Link Here
|
203 |
if ($filename) { |
208 |
if ($filename) { |
204 |
my @cells; |
209 |
my @cells; |
205 |
push @cells, |
210 |
push @cells, |
206 |
map { defined $borrower->{$_} ? $borrower->{$_} : q{} } |
211 |
map { defined $borrower->{$_} ? $borrower->{$_} : q{} } @borrower_fields; |
207 |
@borrower_fields; |
|
|
208 |
push @cells, map { $overdue->{$_} } @item_fields; |
212 |
push @cells, map { $overdue->{$_} } @item_fields; |
209 |
push @cells, $unitcounttotal, $amount; |
213 |
push @cells, $unitcounttotal, $amount; |
210 |
say {$fh} join $delim, @cells; |
214 |
say {$fh} join $delim, @cells; |
211 |
} |
215 |
} |
212 |
} |
216 |
} |
213 |
if ($filename){ |
217 |
if ($filename) { |
214 |
close $fh; |
218 |
close $fh; |
215 |
} |
219 |
} |
216 |
|
220 |
|
Lines 231-237
Number of Overdue Items:
Link Here
|
231 |
EOM |
235 |
EOM |
232 |
} |
236 |
} |
233 |
|
237 |
|
234 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
238 |
cronlogaction( { action => 'End', info => "COMPLETED" } ); |
235 |
|
239 |
|
236 |
sub set_holiday { |
240 |
sub set_holiday { |
237 |
my ( $branch, $dt ) = @_; |
241 |
my ( $branch, $dt ) = @_; |
Lines 252-258
sub get_filename {
Link Here
|
252 |
$name =~ s/\W//; |
256 |
$name =~ s/\W//; |
253 |
$name .= join q{}, q{_}, $today->ymd(), '.log'; |
257 |
$name .= join q{}, q{_}, $today->ymd(), '.log'; |
254 |
$name = File::Spec->catfile( $directory, $name ); |
258 |
$name = File::Spec->catfile( $directory, $name ); |
255 |
if ($verbose && $log) { |
259 |
if ( $verbose && $log ) { |
256 |
say "writing to $name"; |
260 |
say "writing to $name"; |
257 |
} |
261 |
} |
258 |
return $name; |
262 |
return $name; |
259 |
- |
|
|