Lines 44-51
sub usage {
Link Here
|
44 |
exit; |
44 |
exit; |
45 |
} |
45 |
} |
46 |
|
46 |
|
47 |
die |
47 |
die "TalkingTechItivaPhoneNotification system preference not activated... dying\n" |
48 |
"TalkingTechItivaPhoneNotification system preference not activated... dying\n" |
|
|
49 |
unless ( C4::Context->preference("TalkingTechItivaPhoneNotification") ); |
48 |
unless ( C4::Context->preference("TalkingTechItivaPhoneNotification") ); |
50 |
|
49 |
|
51 |
# Database handle |
50 |
# Database handle |
Lines 92-99
pod2usage( -verbose => 1 ) if $help;
Link Here
|
92 |
my $OUT; |
91 |
my $OUT; |
93 |
if ( defined $outfile ) { |
92 |
if ( defined $outfile ) { |
94 |
open( $OUT, '>', "$outfile" ) || die("Cannot open output file"); |
93 |
open( $OUT, '>', "$outfile" ) || die("Cannot open output file"); |
95 |
} |
94 |
} else { |
96 |
else { |
|
|
97 |
print "No output file defined; printing to STDOUT\n" |
95 |
print "No output file defined; printing to STDOUT\n" |
98 |
if ( defined $verbose ); |
96 |
if ( defined $verbose ); |
99 |
open( $OUT, '>', "&STDOUT" ) || die("Couldn't duplicate STDOUT: $!"); |
97 |
open( $OUT, '>', "&STDOUT" ) || die("Couldn't duplicate STDOUT: $!"); |
Lines 103-123
my $format = 'V'; # format for phone notifications
Link Here
|
103 |
|
101 |
|
104 |
foreach my $type (@types) { |
102 |
foreach my $type (@types) { |
105 |
$type = uc($type); #just in case lower or mixed-case was supplied |
103 |
$type = uc($type); #just in case lower or mixed-case was supplied |
106 |
my $module = |
104 |
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 |
105 |
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 |
|
106 |
|
110 |
my @loop; |
107 |
my @loop; |
111 |
if ( $type eq 'OVERDUE' ) { |
108 |
if ( $type eq 'OVERDUE' ) { |
112 |
@loop = GetOverdueIssues(); |
109 |
@loop = GetOverdueIssues(); |
113 |
} |
110 |
} elsif ( $type eq 'PREOVERDUE' ) { |
114 |
elsif ( $type eq 'PREOVERDUE' ) { |
|
|
115 |
@loop = GetPredueIssues(); |
111 |
@loop = GetPredueIssues(); |
116 |
} |
112 |
} elsif ( $type eq 'RESERVE' ) { |
117 |
elsif ( $type eq 'RESERVE' ) { |
|
|
118 |
@loop = GetWaitingHolds(); |
113 |
@loop = GetWaitingHolds(); |
119 |
} |
114 |
} else { |
120 |
else { |
|
|
121 |
print "Unknown or unsupported message type $type; skipping...\n" |
115 |
print "Unknown or unsupported message type $type; skipping...\n" |
122 |
if ( defined $verbose ); |
116 |
if ( defined $verbose ); |
123 |
next; |
117 |
next; |
Lines 143-162
foreach my $type (@types) {
Link Here
|
143 |
my $message_id = 0; |
137 |
my $message_id = 0; |
144 |
if ($outfile) { |
138 |
if ($outfile) { |
145 |
$message_id = C4::Letters::EnqueueLetter( |
139 |
$message_id = C4::Letters::EnqueueLetter( |
146 |
{ |
140 |
{ letter => $letter, |
147 |
letter => $letter, |
|
|
148 |
borrowernumber => $issues->{'borrowernumber'}, |
141 |
borrowernumber => $issues->{'borrowernumber'}, |
149 |
message_transport_type => 'phone', |
142 |
message_transport_type => 'phone', |
150 |
} |
143 |
} |
151 |
); |
144 |
); |
152 |
} |
145 |
} |
153 |
|
146 |
|
154 |
print $OUT |
147 |
print $OUT "\"$format\",\"$language\",\"$type\",\"$issues->{level}\",\"$issues->{cardnumber}\",\"$issues->{patron_title}\",\"$issues->{firstname}\","; |
155 |
"\"$format\",\"$language\",\"$type\",\"$issues->{level}\",\"$issues->{cardnumber}\",\"$issues->{patron_title}\",\"$issues->{firstname}\","; |
148 |
print $OUT "\"$issues->{surname}\",\"$issues->{phone}\",\"$issues->{email}\",\"$library_code\","; |
156 |
print $OUT |
149 |
print $OUT "\"$issues->{site}\",\"$issues->{site_name}\",\"$issues->{barcode}\",\"$due_date\",\"$issues->{title}\",\"$message_id\"\n"; |
157 |
"\"$issues->{surname}\",\"$issues->{phone}\",\"$issues->{email}\",\"$library_code\","; |
|
|
158 |
print $OUT |
159 |
"\"$issues->{site}\",\"$issues->{site_name}\",\"$issues->{barcode}\",\"$due_date\",\"$issues->{title}\",\"$message_id\"\n"; |
160 |
} |
150 |
} |
161 |
} |
151 |
} |
162 |
|
152 |
|
Lines 218-225
This field can be blank if all messages are from a single library.
Link Here
|
218 |
=cut |
208 |
=cut |
219 |
|
209 |
|
220 |
sub GetOverdueIssues { |
210 |
sub GetOverdueIssues { |
221 |
my $query = |
211 |
my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
222 |
"SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
|
|
223 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due, |
212 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due, |
224 |
max(overduerules.branchcode) as rulebranch, TO_DAYS(NOW())-TO_DAYS(date_due) as daysoverdue, delay1, delay2, delay3, |
213 |
max(overduerules.branchcode) as rulebranch, TO_DAYS(NOW())-TO_DAYS(date_due) as daysoverdue, delay1, delay2, delay3, |
225 |
issues.branchcode as site, branches.branchname as site_name |
214 |
issues.branchcode as site, branches.branchname as site_name |
Lines 240-253
sub GetOverdueIssues {
Link Here
|
240 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
229 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
241 |
if ( $issue->{'daysoverdue'} == $issue->{'delay1'} ) { |
230 |
if ( $issue->{'daysoverdue'} == $issue->{'delay1'} ) { |
242 |
$issue->{'level'} = 1; |
231 |
$issue->{'level'} = 1; |
243 |
} |
232 |
} elsif ( $issue->{'daysoverdue'} == $issue->{'delay2'} ) { |
244 |
elsif ( $issue->{'daysoverdue'} == $issue->{'delay2'} ) { |
|
|
245 |
$issue->{'level'} = 2; |
233 |
$issue->{'level'} = 2; |
246 |
} |
234 |
} elsif ( $issue->{'daysoverdue'} == $issue->{'delay3'} ) { |
247 |
elsif ( $issue->{'daysoverdue'} == $issue->{'delay3'} ) { |
|
|
248 |
$issue->{'level'} = 3; |
235 |
$issue->{'level'} = 3; |
249 |
} |
236 |
} else { |
250 |
else { |
|
|
251 |
|
237 |
|
252 |
# this shouldn't ever happen, based our SQL criteria |
238 |
# this shouldn't ever happen, based our SQL criteria |
253 |
} |
239 |
} |
Lines 257-264
sub GetOverdueIssues {
Link Here
|
257 |
} |
243 |
} |
258 |
|
244 |
|
259 |
sub GetPredueIssues { |
245 |
sub GetPredueIssues { |
260 |
my $query = |
246 |
my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
261 |
"SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
|
|
262 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due, |
247 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due, |
263 |
issues.branchcode as site, branches.branchname as site_name |
248 |
issues.branchcode as site, branches.branchname as site_name |
264 |
FROM borrowers JOIN issues USING (borrowernumber) |
249 |
FROM borrowers JOIN issues USING (borrowernumber) |
Lines 283-290
sub GetPredueIssues {
Link Here
|
283 |
} |
268 |
} |
284 |
|
269 |
|
285 |
sub GetWaitingHolds { |
270 |
sub GetWaitingHolds { |
286 |
my $query = |
271 |
my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
287 |
"SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, |
|
|
288 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, reserves.waitingdate, |
272 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, reserves.waitingdate, |
289 |
reserves.branchcode AS site, branches.branchname AS site_name, |
273 |
reserves.branchcode AS site, branches.branchname AS site_name, |
290 |
TO_DAYS(NOW())-TO_DAYS(reserves.waitingdate) AS days_since_waiting |
274 |
TO_DAYS(NOW())-TO_DAYS(reserves.waitingdate) AS days_since_waiting |
Lines 305-343
sub GetWaitingHolds {
Link Here
|
305 |
my @results; |
289 |
my @results; |
306 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
290 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
307 |
my @waitingdate = split( /-/, $issue->{'waitingdate'} ); |
291 |
my @waitingdate = split( /-/, $issue->{'waitingdate'} ); |
308 |
my @date_due = |
292 |
my @date_due = Add_Delta_Days( $waitingdate[0], $waitingdate[1], $waitingdate[2], $pickupdelay ); |
309 |
Add_Delta_Days( $waitingdate[0], $waitingdate[1], $waitingdate[2], |
293 |
$issue->{'date_due'} = sprintf( "%04d-%02d-%02d", $date_due[0], $date_due[1], $date_due[2] ); |
310 |
$pickupdelay ); |
294 |
$issue->{'level'} = 1; # only one level for Hold Waiting notifications |
311 |
$issue->{'date_due'} = |
|
|
312 |
sprintf( "%04d-%02d-%02d", $date_due[0], $date_due[1], $date_due[2] ); |
313 |
$issue->{'level'} = 1; # only one level for Hold Waiting notifications |
314 |
|
295 |
|
315 |
my $days_to_subtract = 0; |
296 |
my $days_to_subtract = 0; |
316 |
my $calendar = C4::Calendar->new( branchcode => $issue->{'site'} ); |
297 |
my $calendar = C4::Calendar->new( branchcode => $issue->{'site'} ); |
317 |
while ( |
298 |
while ( $calendar->isHoliday( reverse( Add_Delta_Days( $waitingdate[0], $waitingdate[1], $waitingdate[2], $days_to_subtract ) ) ) ) { |
318 |
$calendar->isHoliday( |
|
|
319 |
reverse( |
320 |
Add_Delta_Days( |
321 |
$waitingdate[0], $waitingdate[1], |
322 |
$waitingdate[2], $days_to_subtract |
323 |
) |
324 |
) |
325 |
) |
326 |
) |
327 |
{ |
328 |
$days_to_subtract++; |
299 |
$days_to_subtract++; |
329 |
} |
300 |
} |
330 |
$issue->{'days_since_waiting'} = |
301 |
$issue->{'days_since_waiting'} = $issue->{'days_since_waiting'} - $days_to_subtract; |
331 |
$issue->{'days_since_waiting'} - $days_to_subtract; |
302 |
|
332 |
|
303 |
if ( ( grep $_ eq $issue->{'days_since_waiting'}, @holds_waiting_days_to_call ) |
333 |
if ( |
304 |
|| !scalar(@holds_waiting_days_to_call) ) { |
334 |
( |
|
|
335 |
grep $_ eq $issue->{'days_since_waiting'}, |
336 |
@holds_waiting_days_to_call |
337 |
) |
338 |
|| !scalar(@holds_waiting_days_to_call) |
339 |
) |
340 |
{ |
341 |
push @results, $issue; |
305 |
push @results, $issue; |
342 |
} |
306 |
} |
343 |
} |
307 |
} |
344 |
- |
|
|