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