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 142-161
foreach my $type (@types) {
Link Here
|
142 |
my $message_id = 0; |
136 |
my $message_id = 0; |
143 |
if ($outfile) { |
137 |
if ($outfile) { |
144 |
$message_id = C4::Letters::EnqueueLetter( |
138 |
$message_id = C4::Letters::EnqueueLetter( |
145 |
{ |
139 |
{ letter => $letter, |
146 |
letter => $letter, |
|
|
147 |
borrowernumber => $issues->{'borrowernumber'}, |
140 |
borrowernumber => $issues->{'borrowernumber'}, |
148 |
message_transport_type => 'phone', |
141 |
message_transport_type => 'phone', |
149 |
} |
142 |
} |
150 |
); |
143 |
); |
151 |
} |
144 |
} |
152 |
|
145 |
|
153 |
print $OUT |
146 |
print $OUT "\"$format\",\"$language\",\"$type\",\"$issues->{level}\",\"$issues->{cardnumber}\",\"$issues->{patron_title}\",\"$issues->{firstname}\","; |
154 |
"\"$format\",\"$language\",\"$type\",\"$issues->{level}\",\"$issues->{cardnumber}\",\"$issues->{patron_title}\",\"$issues->{firstname}\","; |
147 |
print $OUT "\"$issues->{surname}\",\"$issues->{phone}\",\"$issues->{email}\",\"$library_code\","; |
155 |
print $OUT |
148 |
print $OUT "\"$issues->{site}\",\"$issues->{site_name}\",\"$issues->{barcode}\",\"$due_date\",\"$issues->{title}\",\"$message_id\"\n"; |
156 |
"\"$issues->{surname}\",\"$issues->{phone}\",\"$issues->{email}\",\"$library_code\","; |
|
|
157 |
print $OUT |
158 |
"\"$issues->{site}\",\"$issues->{site_name}\",\"$issues->{barcode}\",\"$due_date\",\"$issues->{title}\",\"$message_id\"\n"; |
159 |
} |
149 |
} |
160 |
} |
150 |
} |
161 |
|
151 |
|
Lines 217-224
This field can be blank if all messages are from a single library.
Link Here
|
217 |
=cut |
207 |
=cut |
218 |
|
208 |
|
219 |
sub GetOverdueIssues { |
209 |
sub GetOverdueIssues { |
220 |
my $query = |
210 |
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, |
211 |
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, |
212 |
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 |
213 |
issues.branchcode as site, branches.branchname as site_name |
Lines 239-252
sub GetOverdueIssues {
Link Here
|
239 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
228 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
240 |
if ( $issue->{'daysoverdue'} == $issue->{'delay1'} ) { |
229 |
if ( $issue->{'daysoverdue'} == $issue->{'delay1'} ) { |
241 |
$issue->{'level'} = 1; |
230 |
$issue->{'level'} = 1; |
242 |
} |
231 |
} elsif ( $issue->{'daysoverdue'} == $issue->{'delay2'} ) { |
243 |
elsif ( $issue->{'daysoverdue'} == $issue->{'delay2'} ) { |
|
|
244 |
$issue->{'level'} = 2; |
232 |
$issue->{'level'} = 2; |
245 |
} |
233 |
} elsif ( $issue->{'daysoverdue'} == $issue->{'delay3'} ) { |
246 |
elsif ( $issue->{'daysoverdue'} == $issue->{'delay3'} ) { |
|
|
247 |
$issue->{'level'} = 3; |
234 |
$issue->{'level'} = 3; |
248 |
} |
235 |
} else { |
249 |
else { |
|
|
250 |
|
236 |
|
251 |
# this shouldn't ever happen, based our SQL criteria |
237 |
# this shouldn't ever happen, based our SQL criteria |
252 |
} |
238 |
} |
Lines 256-263
sub GetOverdueIssues {
Link Here
|
256 |
} |
242 |
} |
257 |
|
243 |
|
258 |
sub GetPredueIssues { |
244 |
sub GetPredueIssues { |
259 |
my $query = |
245 |
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, |
246 |
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 |
247 |
issues.branchcode as site, branches.branchname as site_name |
263 |
FROM borrowers JOIN issues USING (borrowernumber) |
248 |
FROM borrowers JOIN issues USING (borrowernumber) |
Lines 282-289
sub GetPredueIssues {
Link Here
|
282 |
} |
267 |
} |
283 |
|
268 |
|
284 |
sub GetWaitingHolds { |
269 |
sub GetWaitingHolds { |
285 |
my $query = |
270 |
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, |
271 |
borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, reserves.waitingdate, |
288 |
reserves.branchcode AS site, branches.branchname AS site_name, |
272 |
reserves.branchcode AS site, branches.branchname AS site_name, |
289 |
TO_DAYS(NOW())-TO_DAYS(reserves.waitingdate) AS days_since_waiting |
273 |
TO_DAYS(NOW())-TO_DAYS(reserves.waitingdate) AS days_since_waiting |
Lines 304-342
sub GetWaitingHolds {
Link Here
|
304 |
my @results; |
288 |
my @results; |
305 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
289 |
while ( my $issue = $sth->fetchrow_hashref() ) { |
306 |
my @waitingdate = split( /-/, $issue->{'waitingdate'} ); |
290 |
my @waitingdate = split( /-/, $issue->{'waitingdate'} ); |
307 |
my @date_due = |
291 |
my @date_due = Add_Delta_Days( $waitingdate[0], $waitingdate[1], $waitingdate[2], $pickupdelay ); |
308 |
Add_Delta_Days( $waitingdate[0], $waitingdate[1], $waitingdate[2], |
292 |
$issue->{'date_due'} = sprintf( "%04d-%02d-%02d", $date_due[0], $date_due[1], $date_due[2] ); |
309 |
$pickupdelay ); |
293 |
$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 |
|
294 |
|
314 |
my $days_to_subtract = 0; |
295 |
my $days_to_subtract = 0; |
315 |
my $calendar = C4::Calendar->new( branchcode => $issue->{'site'} ); |
296 |
my $calendar = C4::Calendar->new( branchcode => $issue->{'site'} ); |
316 |
while ( |
297 |
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++; |
298 |
$days_to_subtract++; |
328 |
} |
299 |
} |
329 |
$issue->{'days_since_waiting'} = |
300 |
$issue->{'days_since_waiting'} = $issue->{'days_since_waiting'} - $days_to_subtract; |
330 |
$issue->{'days_since_waiting'} - $days_to_subtract; |
301 |
|
331 |
|
302 |
if ( ( grep $_ eq $issue->{'days_since_waiting'}, @holds_waiting_days_to_call ) |
332 |
if ( |
303 |
|| !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; |
304 |
push @results, $issue; |
341 |
} |
305 |
} |
342 |
} |
306 |
} |
343 |
- |
|
|