Lines 37-100
use C4::Context;
Link Here
|
37 |
use C4::Items; |
37 |
use C4::Items; |
38 |
use C4::Circulation qw/LostItem/; |
38 |
use C4::Circulation qw/LostItem/; |
39 |
use Getopt::Long; |
39 |
use Getopt::Long; |
|
|
40 |
use Pod::Usage; |
41 |
use Koha::Borrowers; |
40 |
|
42 |
|
41 |
my $lost; # key=lost value, value=num days. |
43 |
my $lost; # key=lost value, value=num days. |
42 |
my ($charge, $verbose, $confirm, $quiet); |
44 |
my ($charge, $verbose, $confirm, $quiet); |
43 |
my $endrange = 366; |
45 |
my $endrange = 366; |
44 |
my $mark_returned = 0; |
46 |
my $mark_returned = 0; |
|
|
47 |
my $borrower_category = []; |
48 |
my $skip_borrower_category = []; |
49 |
my $help=0; |
50 |
my $man=0; |
51 |
my $list_categories = 0; |
45 |
|
52 |
|
46 |
GetOptions( |
53 |
GetOptions( |
47 |
'lost=s%' => \$lost, |
54 |
'lost=s%' => \$lost, |
48 |
'c|charge=s' => \$charge, |
55 |
'c|charge=s' => \$charge, |
49 |
'confirm' => \$confirm, |
56 |
'confirm' => \$confirm, |
50 |
'verbose' => \$verbose, |
57 |
'v|verbose' => \$verbose, |
51 |
'quiet' => \$quiet, |
58 |
'quiet' => \$quiet, |
52 |
'maxdays=s' => \$endrange, |
59 |
'maxdays=s' => \$endrange, |
53 |
'mark-returned' => \$mark_returned, |
60 |
'mark-returned' => \$mark_returned, |
|
|
61 |
'h|help' => \$help, |
62 |
'man|manual' => \$man, |
63 |
'category=s' => $borrower_category, |
64 |
'skip-category=s' => $skip_borrower_category, |
65 |
'list-categories' => \$list_categories, |
54 |
); |
66 |
); |
55 |
|
67 |
|
56 |
my $usage = << 'ENDUSAGE'; |
68 |
if ( $man ) { |
57 |
longoverdue.pl : This cron script set lost values on overdue items and optionally sets charges the patron's account |
69 |
pod2usage( -verbose => 2 |
58 |
for the item's replacement price. It is designed to be run as a nightly job. The command line options that globally |
70 |
-exitval => 0 |
59 |
define this behavior for this script will likely be moved into Koha's core circulation / issuing rules code in a |
71 |
); |
60 |
near-term release, so this script is not intended to have a long lifetime. |
72 |
} |
|
|
73 |
|
74 |
if ( $help ) { |
75 |
pod2usage( -verbose => 1, |
76 |
-exitval => 0 |
77 |
); |
78 |
} |
79 |
|
80 |
if ( scalar @$borrower_category && scalar @$skip_borrower_category) { |
81 |
pod2usage( -verbose => 1, |
82 |
-message => "The options --category and --skip-category are mually exclusive.\n" |
83 |
. "Use one or the other.", |
84 |
-exitval => 1 |
85 |
); |
86 |
} |
87 |
|
88 |
if ( $list_categories ) { |
89 |
my @categories = sort map { uc $_->[0] } @{ C4::Context->dbh->selectall_arrayref(q|SELECT categorycode FROM categories|) }; |
90 |
print "\nBorrowrer Categories: " . join( " ", @categories ) . "\n\n"; |
91 |
exit 0; |
92 |
} |
93 |
|
94 |
=head1 SYNOPSIS |
95 |
|
96 |
longoverdue.pl [ --help | -h | --man | --list-categories ] |
97 |
longoverdue.pl --lost | -l DAYS=LOST_CODE [ --charge | -c CHARGE_CODE ] [ --verbose | -v ] [ --quiet ] |
98 |
[ --maxdays MAX_DAYS ] [ --mark-returned ] [ --category BORROWER_CATEGORY ] ... |
99 |
[ --skip-category BORROWER_CATEGORY ] ... |
100 |
[ --commit ] |
101 |
|
102 |
|
103 |
WARNING: Flippant use of this script could set all or most of the items in your catalog to Lost and charge your |
104 |
patrons for them! |
105 |
|
106 |
WARNING: This script is known to be faulty. It is NOT recommended to use multiple --lost options. |
107 |
See http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=2883 |
108 |
|
109 |
=cut |
110 |
|
111 |
=head1 OPTIONS |
61 |
|
112 |
|
62 |
This script takes the following parameters : |
113 |
This script takes the following parameters : |
63 |
|
114 |
|
64 |
--lost | -l This option takes the form of n=lv, |
115 |
=over 8 |
65 |
where n is num days overdue, and lv is the lost value. See warning below. |
116 |
|
|
|
117 |
=item B<--lost | -l> |
118 |
|
119 |
This option takes the form of n=lv, where n is num days overdue, and lv is the lost value. See warning above. |
120 |
|
121 |
=item B<--charge | -c> |
122 |
|
123 |
This specifies what lost value triggers Koha to charge the account for the lost item. Replacement costs are not charged if this is not specified. |
124 |
|
125 |
=item B<--verbose | -v> |
126 |
|
127 |
verbose. |
128 |
|
129 |
=item B<--confirm> |
130 |
|
131 |
confirm. without this option, the script will report the number of affected items and return without modifying any records. |
132 |
|
133 |
=item B<--quiet> |
134 |
|
135 |
suppress summary output. |
136 |
|
137 |
=item B<--maxdays> |
138 |
|
139 |
Specifies the end of the range of overdue days to deal with (defaults to 366). This value is universal to all lost num days overdue passed. |
66 |
|
140 |
|
67 |
--charge | -c This specifies what lost value triggers Koha to charge the account for the |
141 |
=item B<--mark-returned> |
68 |
lost item. Replacement costs are not charged if this is not specified. |
|
|
69 |
|
142 |
|
70 |
--verbose | v verbose. |
143 |
When an item is marked lost, remove it from the borrowers issued items. |
71 |
|
144 |
|
72 |
--confirm confirm. without this option, the script will report the number of affected items and |
145 |
=item B<--category> |
73 |
return without modifying any records. |
|
|
74 |
|
146 |
|
75 |
--quiet suppress summary output. |
147 |
Act on the listed borrower category code (borrowers.categorycode). |
|
|
148 |
Exclude all others. This may be specified multiple times to include multiple categories. |
149 |
May not be used with B<--skip-category> |
76 |
|
150 |
|
77 |
--maxdays Specifies the end of the range of overdue days to deal with (defaults to 366). This |
151 |
=item B<--skip-category> |
78 |
value is universal to all lost num days overdue passed. |
|
|
79 |
|
152 |
|
80 |
--mark-returned When an item is marked lost, remove it from the borrowers issued items. |
153 |
Act on all available borrower category codes, except those listed. |
|
|
154 |
This may be specified multiple times, to exclude multiple categories. |
155 |
May not be used with B<--category> |
156 |
|
157 |
=item B<--list-categories> |
158 |
|
159 |
List borrower categories available for use by B<--category> or |
160 |
B<--skip-category>, and exit. |
161 |
|
162 |
=item B<--help | -h> |
163 |
|
164 |
Display short help message an exit. |
165 |
|
166 |
=item B<--man | --manual > |
167 |
|
168 |
Display entire manual and exit. |
169 |
|
170 |
=back |
171 |
|
172 |
=cut |
173 |
|
174 |
=head1 Description |
175 |
|
176 |
This cron script set lost values on overdue items and optionally sets charges the patron's account |
177 |
for the item's replacement price. It is designed to be run as a nightly job. The command line options that globally |
178 |
define this behavior for this script will likely be moved into Koha's core circulation / issuing rules code in a |
179 |
near-term release, so this script is not intended to have a long lifetime. |
180 |
|
181 |
|
182 |
=cut |
183 |
|
184 |
=head1 Examples |
81 |
|
185 |
|
82 |
examples : |
|
|
83 |
$PERL5LIB/misc/cronjobs/longoverdue.pl --lost 30=1 |
186 |
$PERL5LIB/misc/cronjobs/longoverdue.pl --lost 30=1 |
84 |
Would set LOST=1 after 30 days (up to one year), but not charge the account. |
187 |
Would set LOST=1 after 30 days (up to one year), but not charge the account. |
85 |
This would be suitable for the Koha default LOST authorized value of 1 -> 'Lost'. |
188 |
This would be suitable for the Koha default LOST authorized value of 1 -> 'Lost'. |
86 |
|
189 |
|
87 |
$PERL5LIB/misc/cronjobs/longoverdue.pl --lost 60=2 --charge 2 |
190 |
$PERL5LIB/misc/cronjobs/longoverdue.pl --lost 60=2 --charge 2 |
88 |
Would set LOST=2 after 60 days (up to one year), and charge the account when setting LOST=2. |
191 |
Would set LOST=2 after 60 days (up to one year), and charge the account when setting LOST=2. |
89 |
This would be suitable for the Koha default LOST authorized value of 2 -> 'Long Overdue' |
192 |
This would be suitable for the Koha default LOST authorized value of 2 -> 'Long Overdue' |
90 |
|
|
|
91 |
WARNING: Flippant use of this script could set all or most of the items in your catalog to Lost and charge your |
92 |
patrons for them! |
93 |
|
94 |
WARNING: This script is known to be faulty. It is NOT recommended to use multiple --lost options. |
95 |
See http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=2883 |
96 |
|
193 |
|
97 |
ENDUSAGE |
194 |
=cut |
98 |
|
195 |
|
99 |
# FIXME: We need three pieces of data to operate: |
196 |
# FIXME: We need three pieces of data to operate: |
100 |
# ~ lower bound (number of days), |
197 |
# ~ lower bound (number of days), |
Lines 104-112
ENDUSAGE
Link Here
|
104 |
# FIXME: do checks on --lost ranges to make sure they are exclusive. |
201 |
# FIXME: do checks on --lost ranges to make sure they are exclusive. |
105 |
# FIXME: do checks on --lost ranges to make sure the authorized values exist. |
202 |
# FIXME: do checks on --lost ranges to make sure the authorized values exist. |
106 |
# FIXME: do checks on --lost ranges to make sure don't go past endrange. |
203 |
# FIXME: do checks on --lost ranges to make sure don't go past endrange. |
107 |
# FIXME: convert to using pod2usage |
204 |
# |
108 |
# FIXME: allow --help or -h |
|
|
109 |
# |
110 |
if ( ! defined($lost) ) { |
205 |
if ( ! defined($lost) ) { |
111 |
my $longoverdue_value = C4::Context->preference('DefaultLongOverdueLostValue'); |
206 |
my $longoverdue_value = C4::Context->preference('DefaultLongOverdueLostValue'); |
112 |
my $longoverdue_days = C4::Context->preference('DefaultLongOverdueDays'); |
207 |
my $longoverdue_days = C4::Context->preference('DefaultLongOverdueDays'); |
Lines 114-121
if ( ! defined($lost) ) {
Link Here
|
114 |
$lost->{$longoverdue_days} = $longoverdue_value; |
209 |
$lost->{$longoverdue_days} = $longoverdue_value; |
115 |
} |
210 |
} |
116 |
else { |
211 |
else { |
117 |
print $usage; |
212 |
pod2usage( { |
118 |
die "ERROR: No --lost (-l) option defined"; |
213 |
-exitval => 1, |
|
|
214 |
-msg => q|ERROR: No --lost (-l) option defined|, |
215 |
} ); |
119 |
} |
216 |
} |
120 |
} |
217 |
} |
121 |
if ( ! defined($charge) ) { |
218 |
if ( ! defined($charge) ) { |
Lines 151-160
sub longoverdue_sth {
Link Here
|
151 |
return C4::Context->dbh->prepare($query); |
248 |
return C4::Context->dbh->prepare($query); |
152 |
} |
249 |
} |
153 |
|
250 |
|
154 |
#FIXME - Should add a 'system' user and get suitable userenv for it for logging, etc. |
251 |
my $dbh = C4::Context->dbh; |
|
|
252 |
my @available_categories = map { uc $_->[0] } @{ $dbh->selectall_arrayref(q|SELECT categorycode FROM categories|) }; |
253 |
$borrower_category = [ map { uc $_ } @$borrower_category ]; |
254 |
$skip_borrower_category = [ map { uc $_} @$skip_borrower_category ]; |
255 |
my %category_to_process; |
256 |
for my $cat ( @$borrower_category ) { |
257 |
unless ( grep { /^$cat$/ } @available_categories ) { |
258 |
pod2usage( |
259 |
'-exitval' => 1, |
260 |
'-message' => "The category $cat does not exist in the database", |
261 |
); |
262 |
} |
263 |
$category_to_process{$cat} = 1; |
264 |
} |
265 |
if ( @$skip_borrower_category ) { |
266 |
for my $cat ( @$skip_borrower_category ) { |
267 |
unless ( grep { /^$cat$/ } @available_categories ) { |
268 |
pod2usage( |
269 |
'-exitval' => 1, |
270 |
'-message' => "The category $cat does not exist in the database", |
271 |
); |
272 |
} |
273 |
} |
274 |
%category_to_process = map { $_ => 1 } @available_categories; |
275 |
%category_to_process = ( %category_to_process, map { $_ => 0 } @$skip_borrower_category ); |
276 |
} |
277 |
|
278 |
my $filter_borrower_categories = ( scalar @$borrower_category || scalar @$skip_borrower_category ); |
155 |
|
279 |
|
156 |
my $count; |
280 |
my $count; |
157 |
# my @ranges = map { |
|
|
158 |
my @report; |
281 |
my @report; |
159 |
my $total = 0; |
282 |
my $total = 0; |
160 |
my $i = 0; |
283 |
my $i = 0; |
Lines 169-180
foreach my $startrange (sort keys %$lost) {
Link Here
|
169 |
my ($date1) = bounds($startrange); |
292 |
my ($date1) = bounds($startrange); |
170 |
my ($date2) = bounds( $endrange); |
293 |
my ($date2) = bounds( $endrange); |
171 |
# print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose); |
294 |
# print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose); |
172 |
$verbose and |
295 |
$verbose and |
173 |
printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i, |
296 |
printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i, |
174 |
$startrange, $endrange, $date2, $date1, $lostvalue; |
297 |
$startrange, $endrange, $date2, $date1, $lostvalue; |
175 |
$sth_items->execute($startrange, $endrange, $lostvalue); |
298 |
$sth_items->execute($startrange, $endrange, $lostvalue); |
176 |
$count=0; |
299 |
$count=0; |
177 |
while (my $row=$sth_items->fetchrow_hashref) { |
300 |
ITEM: while (my $row=$sth_items->fetchrow_hashref) { |
|
|
301 |
if( $filter_borrower_categories ) { |
302 |
my $category = uc Koha::Borrowers->find( $row->{borrowernumber} )->categorycode(); |
303 |
next ITEM unless ( $category_to_process{ $category } ); |
304 |
} |
178 |
printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose); |
305 |
printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose); |
179 |
if($confirm) { |
306 |
if($confirm) { |
180 |
ModItem({ itemlost => $lostvalue }, $row->{'biblionumber'}, $row->{'itemnumber'}); |
307 |
ModItem({ itemlost => $lostvalue }, $row->{'biblionumber'}, $row->{'itemnumber'}); |
181 |
- |
|
|