Lines 31-36
BEGIN {
Link Here
|
31 |
use Getopt::Long; |
31 |
use Getopt::Long; |
32 |
use Pod::Usage; |
32 |
use Pod::Usage; |
33 |
use Date::Calc qw(Add_Delta_Days); |
33 |
use Date::Calc qw(Add_Delta_Days); |
|
|
34 |
use Text::CSV; |
34 |
|
35 |
|
35 |
use C4::Context; |
36 |
use C4::Context; |
36 |
use C4::Items; |
37 |
use C4::Items; |
Lines 44-56
sub usage {
Link Here
|
44 |
exit; |
45 |
exit; |
45 |
} |
46 |
} |
46 |
|
47 |
|
47 |
die |
48 |
die "TalkingTechItivaPhoneNotification system preference not activated... dying\n" |
48 |
"TalkingTechItivaPhoneNotification system preference not activated... dying\n" |
|
|
49 |
unless ( C4::Context->preference("TalkingTechItivaPhoneNotification") ); |
49 |
unless ( C4::Context->preference("TalkingTechItivaPhoneNotification") ); |
50 |
|
50 |
|
51 |
# Database handle |
51 |
# Database handle |
52 |
my $dbh = C4::Context->dbh; |
52 |
my $dbh = C4::Context->dbh; |
53 |
|
53 |
|
|
|
54 |
# CSV object |
55 |
my $csv = Text::CSV->new( { always_quote => 1, eol => "\n", escape_char => '\\', } ) or die "Cannot use CSV: " . Text::CSV->error_diag(); |
56 |
|
54 |
# Options |
57 |
# Options |
55 |
my $verbose; |
58 |
my $verbose; |
56 |
my $language = "EN"; |
59 |
my $language = "EN"; |
Lines 92-99
pod2usage( -verbose => 1 ) if $help;
Link Here
|
92 |
my $OUT; |
95 |
my $OUT; |
93 |
if ( defined $outfile ) { |
96 |
if ( defined $outfile ) { |
94 |
open( $OUT, '>', "$outfile" ) || die("Cannot open output file"); |
97 |
open( $OUT, '>', "$outfile" ) || die("Cannot open output file"); |
95 |
} |
98 |
} else { |
96 |
else { |
|
|
97 |
print "No output file defined; printing to STDOUT\n" |
99 |
print "No output file defined; printing to STDOUT\n" |
98 |
if ( defined $verbose ); |
100 |
if ( defined $verbose ); |
99 |
open( $OUT, '>', "&STDOUT" ) || die("Couldn't duplicate STDOUT: $!"); |
101 |
open( $OUT, '>', "&STDOUT" ) || die("Couldn't duplicate STDOUT: $!"); |
Lines 103-123
my $format = 'V'; # format for phone notifications
Link Here
|
103 |
|
105 |
|
104 |
foreach my $type (@types) { |
106 |
foreach my $type (@types) { |
105 |
$type = uc($type); #just in case lower or mixed-case was supplied |
107 |
$type = uc($type); #just in case lower or mixed-case was supplied |
106 |
my $module = |
108 |
my $module = $type_module_map->{$type}; #since the module is required to get the letter |
107 |
$type_module_map->{$type}; #since the module is required to get the letter |
109 |
my $code = $type_notice_map->{$type}; #to get the Koha name of the notice |
108 |
my $code = $type_notice_map->{$type}; #to get the Koha name of the notice |
|
|
109 |
|
110 |
|
110 |
my @loop; |
111 |
my @loop; |
111 |
if ( $type eq 'OVERDUE' ) { |
112 |
if ( $type eq 'OVERDUE' ) { |
112 |
@loop = GetOverdueIssues(); |
113 |
@loop = GetOverdueIssues(); |
113 |
} |
114 |
} elsif ( $type eq 'PREOVERDUE' ) { |
114 |
elsif ( $type eq 'PREOVERDUE' ) { |
|
|
115 |
@loop = GetPredueIssues(); |
115 |
@loop = GetPredueIssues(); |
116 |
} |
116 |
} elsif ( $type eq 'RESERVE' ) { |
117 |
elsif ( $type eq 'RESERVE' ) { |
|
|
118 |
@loop = GetWaitingHolds(); |
117 |
@loop = GetWaitingHolds(); |
119 |
} |
118 |
} else { |
120 |
else { |
|
|
121 |
print "Unknown or unsupported message type $type; skipping...\n" |
119 |
print "Unknown or unsupported message type $type; skipping...\n" |
122 |
if ( defined $verbose ); |
120 |
if ( defined $verbose ); |
123 |
next; |
121 |
next; |
Lines 142-161
foreach my $type (@types) {
Link Here
|
142 |
my $message_id = 0; |
140 |
my $message_id = 0; |
143 |
if ($outfile) { |
141 |
if ($outfile) { |
144 |
$message_id = C4::Letters::EnqueueLetter( |
142 |
$message_id = C4::Letters::EnqueueLetter( |
145 |
{ |
143 |
{ letter => $letter, |
146 |
letter => $letter, |
|
|
147 |
borrowernumber => $issues->{'borrowernumber'}, |
144 |
borrowernumber => $issues->{'borrowernumber'}, |
148 |
message_transport_type => 'phone', |
145 |
message_transport_type => 'phone', |
149 |
} |
146 |
} |
150 |
); |
147 |
); |
151 |
} |
148 |
} |
152 |
|
149 |
|
153 |
print $OUT |
150 |
$csv->print( |
154 |
"\"$format\",\"$language\",\"$type\",\"$issues->{level}\",\"$issues->{cardnumber}\",\"$issues->{patron_title}\",\"$issues->{firstname}\","; |
151 |
$OUT, |
155 |
print $OUT |
152 |
[ $format, $language, $type, $issues->{level}, $issues->{cardnumber}, $issues->{patron_title}, |
156 |
"\"$issues->{surname}\",\"$issues->{phone}\",\"$issues->{email}\",\"$library_code\","; |
153 |
$issues->{firstname}, $issues->{surname}, $issues->{phone}, $issues->{email}, $library_code, $issues->{site}, |
157 |
print $OUT |
154 |
$issues->{site_name}, $issues->{barcode}, $due_date, $issues->{title}, $message_id |
158 |
"\"$issues->{site}\",\"$issues->{site_name}\",\"$issues->{barcode}\",\"$due_date\",\"$issues->{title}\",\"$message_id\"\n"; |
155 |
] |
|
|
156 |
); |
159 |
} |
157 |
} |
160 |
} |
158 |
} |
161 |
|
159 |
|
Lines 217-224
This field can be blank if all messages are from a single library.
Link Here
|
217 |
=cut |
215 |
=cut |
218 |
|
216 |
|
219 |
sub GetOverdueIssues { |
217 |
sub GetOverdueIssues { |
220 |
my $query = |
218 |
my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
221 |
"SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
|
|
222 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due, |
219 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due, |
223 |
max(overduerules.branchcode) as rulebranch, TO_DAYS(NOW())-TO_DAYS(date_due) as daysoverdue, delay1, delay2, delay3, |
220 |
max(overduerules.branchcode) as rulebranch, TO_DAYS(NOW())-TO_DAYS(date_due) as daysoverdue, delay1, delay2, delay3, |
224 |
issues.branchcode as site, branches.branchname as site_name |
221 |
issues.branchcode as site, branches.branchname as site_name |
Lines 239-252
sub GetOverdueIssues {
Link Here
|
239 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
236 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
240 |
if ( $issue->{'daysoverdue'} == $issue->{'delay1'} ) { |
237 |
if ( $issue->{'daysoverdue'} == $issue->{'delay1'} ) { |
241 |
$issue->{'level'} = 1; |
238 |
$issue->{'level'} = 1; |
242 |
} |
239 |
} elsif ( $issue->{'daysoverdue'} == $issue->{'delay2'} ) { |
243 |
elsif ( $issue->{'daysoverdue'} == $issue->{'delay2'} ) { |
|
|
244 |
$issue->{'level'} = 2; |
240 |
$issue->{'level'} = 2; |
245 |
} |
241 |
} elsif ( $issue->{'daysoverdue'} == $issue->{'delay3'} ) { |
246 |
elsif ( $issue->{'daysoverdue'} == $issue->{'delay3'} ) { |
|
|
247 |
$issue->{'level'} = 3; |
242 |
$issue->{'level'} = 3; |
248 |
} |
243 |
} else { |
249 |
else { |
|
|
250 |
|
244 |
|
251 |
# this shouldn't ever happen, based our SQL criteria |
245 |
# this shouldn't ever happen, based our SQL criteria |
252 |
} |
246 |
} |
Lines 256-263
sub GetOverdueIssues {
Link Here
|
256 |
} |
250 |
} |
257 |
|
251 |
|
258 |
sub GetPredueIssues { |
252 |
sub GetPredueIssues { |
259 |
my $query = |
253 |
my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
260 |
"SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
|
|
261 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due, |
254 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due, |
262 |
issues.branchcode as site, branches.branchname as site_name |
255 |
issues.branchcode as site, branches.branchname as site_name |
263 |
FROM borrowers JOIN issues USING (borrowernumber) |
256 |
FROM borrowers JOIN issues USING (borrowernumber) |
Lines 282-289
sub GetPredueIssues {
Link Here
|
282 |
} |
275 |
} |
283 |
|
276 |
|
284 |
sub GetWaitingHolds { |
277 |
sub GetWaitingHolds { |
285 |
my $query = |
278 |
my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
286 |
"SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
|
|
287 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, reserves.waitingdate, |
279 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, reserves.waitingdate, |
288 |
reserves.branchcode AS site, branches.branchname AS site_name, |
280 |
reserves.branchcode AS site, branches.branchname AS site_name, |
289 |
TO_DAYS(NOW())-TO_DAYS(reserves.waitingdate) AS days_since_waiting |
281 |
TO_DAYS(NOW())-TO_DAYS(reserves.waitingdate) AS days_since_waiting |
Lines 304-342
sub GetWaitingHolds {
Link Here
|
304 |
my @results; |
296 |
my @results; |
305 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
297 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
306 |
my @waitingdate = split( /-/, $issue->{'waitingdate'} ); |
298 |
my @waitingdate = split( /-/, $issue->{'waitingdate'} ); |
307 |
my @date_due = |
299 |
my @date_due = Add_Delta_Days( $waitingdate[0], $waitingdate[1], $waitingdate[2], $pickupdelay ); |
308 |
Add_Delta_Days( $waitingdate[0], $waitingdate[1], $waitingdate[2], |
300 |
$issue->{'date_due'} = sprintf( "%04d-%02d-%02d", $date_due[0], $date_due[1], $date_due[2] ); |
309 |
$pickupdelay ); |
301 |
$issue->{'level'} = 1; # only one level for Hold Waiting notifications |
310 |
$issue->{'date_due'} = |
|
|
311 |
sprintf( "%04d-%02d-%02d", $date_due[0], $date_due[1], $date_due[2] ); |
312 |
$issue->{'level'} = 1; # only one level for Hold Waiting notifications |
313 |
|
302 |
|
314 |
my $days_to_subtract = 0; |
303 |
my $days_to_subtract = 0; |
315 |
my $calendar = C4::Calendar->new( branchcode => $issue->{'site'} ); |
304 |
my $calendar = C4::Calendar->new( branchcode => $issue->{'site'} ); |
316 |
while ( |
305 |
while ( $calendar->isHoliday( reverse( Add_Delta_Days( $waitingdate[0], $waitingdate[1], $waitingdate[2], $days_to_subtract ) ) ) ) { |
317 |
$calendar->isHoliday( |
|
|
318 |
reverse( |
319 |
Add_Delta_Days( |
320 |
$waitingdate[0], $waitingdate[1], |
321 |
$waitingdate[2], $days_to_subtract |
322 |
) |
323 |
) |
324 |
) |
325 |
) |
326 |
{ |
327 |
$days_to_subtract++; |
306 |
$days_to_subtract++; |
328 |
} |
307 |
} |
329 |
$issue->{'days_since_waiting'} = |
308 |
$issue->{'days_since_waiting'} = $issue->{'days_since_waiting'} - $days_to_subtract; |
330 |
$issue->{'days_since_waiting'} - $days_to_subtract; |
309 |
|
331 |
|
310 |
if ( ( grep $_ eq $issue->{'days_since_waiting'}, @holds_waiting_days_to_call ) |
332 |
if ( |
311 |
|| !scalar(@holds_waiting_days_to_call) ) { |
333 |
( |
|
|
334 |
grep $_ eq $issue->{'days_since_waiting'}, |
335 |
@holds_waiting_days_to_call |
336 |
) |
337 |
|| !scalar(@holds_waiting_days_to_call) |
338 |
) |
339 |
{ |
340 |
push @results, $issue; |
312 |
push @results, $issue; |
341 |
} |
313 |
} |
342 |
} |
314 |
} |
343 |
- |
|
|