Lines 42-51
use Koha::DateUtils;
Link Here
|
42 |
my $help; |
42 |
my $help; |
43 |
my $verbose; |
43 |
my $verbose; |
44 |
my $output_dir; |
44 |
my $output_dir; |
|
|
45 |
my $log; |
45 |
|
46 |
|
46 |
GetOptions( |
47 |
GetOptions( |
47 |
'h|help' => \$help, |
48 |
'h|help' => \$help, |
48 |
'v|verbose' => \$verbose, |
49 |
'v|verbose' => \$verbose, |
|
|
50 |
'l|log' => \$log, |
49 |
'o|out:s' => \$output_dir, |
51 |
'o|out:s' => \$output_dir, |
50 |
); |
52 |
); |
51 |
my $usage = << 'ENDUSAGE'; |
53 |
my $usage = << 'ENDUSAGE'; |
Lines 58-63
calculated but not applied.
Link Here
|
58 |
|
60 |
|
59 |
This script has the following parameters : |
61 |
This script has the following parameters : |
60 |
-h --help: this message |
62 |
-h --help: this message |
|
|
63 |
-l --log: log the output to a file |
61 |
-o --out: ouput directory for logs (defaults to env or /tmp if !exist) |
64 |
-o --out: ouput directory for logs (defaults to env or /tmp if !exist) |
62 |
-v --verbose |
65 |
-v --verbose |
63 |
|
66 |
|
Lines 81-91
my %is_holiday;
Link Here
|
81 |
my $today = DateTime->now( time_zone => C4::Context->tz() ); |
84 |
my $today = DateTime->now( time_zone => C4::Context->tz() ); |
82 |
my $filename = get_filename($output_dir); |
85 |
my $filename = get_filename($output_dir); |
83 |
|
86 |
|
84 |
open my $fh, '>>', $filename or croak "Cannot write file $filename: $!"; |
87 |
my $fh; |
85 |
print {$fh} join $delim, ( @borrower_fields, @item_fields, @other_fields ); |
88 |
if ($log) { |
86 |
print {$fh} "\n"; |
89 |
open $fh, '>>', $filename or croak "Cannot write file $filename: $!"; |
87 |
|
90 |
print {$fh} join $delim, ( @borrower_fields, @item_fields, @other_fields ); |
88 |
my $counted = 0; |
91 |
print {$fh} "\n"; |
|
|
92 |
} |
93 |
my $counted = 0; |
89 |
my $overdues = Getoverdues(); |
94 |
my $overdues = Getoverdues(); |
90 |
for my $overdue ( @{$overdues} ) { |
95 |
for my $overdue ( @{$overdues} ) { |
91 |
if ( !defined $overdue->{borrowernumber} ) { |
96 |
if ( !defined $overdue->{borrowernumber} ) { |
Lines 126-144
for my $overdue ( @{$overdues} ) {
Link Here
|
126 |
); |
131 |
); |
127 |
} |
132 |
} |
128 |
} |
133 |
} |
129 |
my @cells; |
134 |
if ($log) { |
130 |
push @cells, |
135 |
my @cells; |
131 |
map { defined $borrower->{$_} ? $borrower->{$_} : q{} } @borrower_fields; |
136 |
push @cells, |
132 |
push @cells, map { $overdue->{$_} } @item_fields; |
137 |
map { defined $borrower->{$_} ? $borrower->{$_} : q{} } |
133 |
push @cells, $type, $unitcounttotal, $amount; |
138 |
@borrower_fields; |
134 |
say {$fh} join $delim, @cells; |
139 |
push @cells, map { $overdue->{$_} } @item_fields; |
|
|
140 |
push @cells, $type, $unitcounttotal, $amount; |
141 |
say {$fh} join $delim, @cells; |
142 |
} |
143 |
} |
144 |
if ($log){ |
145 |
close $fh; |
135 |
} |
146 |
} |
136 |
close $fh; |
|
|
137 |
|
147 |
|
138 |
if ($verbose) { |
148 |
if ($verbose) { |
139 |
my $overdue_items = @{$overdues}; |
149 |
my $overdue_items = @{$overdues}; |
140 |
print <<"EOM"; |
150 |
print <<"EOM"; |
141 |
Fines assessment -- $today -- Saved to $filename |
151 |
Fines assessment -- $today |
|
|
152 |
EOM |
153 |
if ($log) { |
154 |
say "Saved to $filename"; |
155 |
} |
156 |
print <<"EOM"; |
142 |
Number of Overdue Items: |
157 |
Number of Overdue Items: |
143 |
counted $overdue_items |
158 |
counted $overdue_items |
144 |
reported $counted |
159 |
reported $counted |
Lines 165-171
sub get_filename {
Link Here
|
165 |
$name =~ s/\W//; |
180 |
$name =~ s/\W//; |
166 |
$name .= join q{}, q{_}, $today->ymd(), '.log'; |
181 |
$name .= join q{}, q{_}, $today->ymd(), '.log'; |
167 |
$name = File::Spec->catfile( $directory, $name ); |
182 |
$name = File::Spec->catfile( $directory, $name ); |
168 |
if ($verbose) { |
183 |
if ($verbose && $log) { |
169 |
say "writing to $name"; |
184 |
say "writing to $name"; |
170 |
} |
185 |
} |
171 |
return $name; |
186 |
return $name; |
172 |
- |
|
|