From 217b7f7242e74090065202802da5051658160b75 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 1 Mar 2016 16:34:02 +0000 Subject: [PATCH] Bug 15969 - Allow use of Template Toolkit syntax for Phone Notices By allowing the use of Template Toolkit for generating the outgoing Talking Tech CSV files, we can give libaries more control over the data they send to Itiva. This enhancement would also make it possible to use the script for other services since the output is no longer fixed to a single format. Test Plan: 1) Apply this patch 2) Set up a waiting hold, and overdue checkout, and a non-overdue checkout 3) Generate the CSV file via the script misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl 4) Enable Template Toolkit for the notices and update the notice text to be: [% FILTER remove("\r\n") %] "[% format %]", "[% language %]", "[% type %]", "[% level %]", "[% borrower.cardnumber %]", "[% borrower.title %]", "[% borrower.firstname %]", "[% borrower.surname %]", "[% borrower.phone %]", "[% borrower.email %]", "[% library_code %]", "[% branch.id %]", "[% branch.branchname %]", "[% item.barcode %]", "[% due_date %]", "[% biblio.title %]", "__MESSAGE_ID__" [% END %] 5) Regenerate the notices 6) Compare the originals, note the format is the same Signed-off-by: Sean McGarvey --- C4/Letters.pm | 12 ++++++- .../thirdparty/TalkingTech_itiva_outbound.pl | 37 +++++++++++++++------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index b49367c..43ed4b0 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -664,6 +664,7 @@ sub GetPreparedLetter { surname => $userenv->{surname}, emailaddress => $userenv->{emailaddress}, }, + $substitute ? %$substitute : (), } } ); @@ -979,7 +980,16 @@ ENDSQL $params->{'from_address'}, # from_address $params->{'letter'}->{'content-type'}, # content_type ); - return $dbh->last_insert_id(undef,undef,'message_queue', undef); + + my $id = $dbh->last_insert_id(undef,undef,'message_queue', undef); + + $content = $params->{letter}->{content}; + if ( $content =~ /__MESSAGE_ID__/ ) { + $content =~ s/__MESSAGE_ID__/$id/g; + $dbh->do( "UPDATE message_queue SET content = ? WHERE message_id = ?", undef, ($content, $id) ); + } + + return $id; } =head2 SendQueuedMessages ([$hashref]) diff --git a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl index 18e9f86..63f0b91 100755 --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl +++ b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl @@ -131,9 +131,20 @@ foreach my $type (@types) { module => $module, letter_code => $code, tables => { - borrowers => $issues->{'borrowernumber'}, - biblio => $issues->{'biblionumber'}, - biblioitems => $issues->{'biblionumber'}, + borrowers => $issues->{borrowernumber}, + biblio => $issues->{biblionumber}, + biblioitems => $issues->{biblionumber}, + items => $issues->{itemnumber}, + issues => $issues->{itemnumber}, + branches => $issues->{site}, + }, + substitute => { + format => $format, + language => $language, + type => $type, + level => $issues->{level}, + library_code => $library_code, + due_date => $due_date, }, message_transport_type => 'phone', ); @@ -151,12 +162,14 @@ foreach my $type (@types) { ); } - print $OUT -"\"$format\",\"$language\",\"$type\",\"$issues->{level}\",\"$issues->{cardnumber}\",\"$issues->{patron_title}\",\"$issues->{firstname}\","; - print $OUT -"\"$issues->{surname}\",\"$issues->{phone}\",\"$issues->{email}\",\"$library_code\","; - print $OUT -"\"$issues->{site}\",\"$issues->{site_name}\",\"$issues->{barcode}\",\"$due_date\",\"$issues->{title}\",\"$message_id\"\n"; + if ( $letter->{is_tt} ) { + $letter->{content} =~ s/__MESSAGE_ID__/$message_id/g; + print $OUT $letter->{content}; + } else { + print $OUT "\"$format\",\"$language\",\"$type\",\"$issues->{level}\",\"$issues->{cardnumber}\",\"$issues->{patron_title}\",\"$issues->{firstname}\","; + print $OUT "\"$issues->{surname}\",\"$issues->{phone}\",\"$issues->{email}\",\"$library_code\","; + print $OUT "\"$issues->{site}\",\"$issues->{site_name}\",\"$issues->{barcode}\",\"$due_date\",\"$issues->{title}\",\"$message_id\"\n"; + } } } @@ -222,7 +235,7 @@ sub GetOverdueIssues { "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due, max(overduerules.branchcode) as rulebranch, TO_DAYS(NOW())-TO_DAYS(date_due) as daysoverdue, delay1, delay2, delay3, - issues.branchcode as site, branches.branchname as site_name + issues.branchcode as site, branches.branchname as site_name, items.itemnumber FROM borrowers JOIN issues USING (borrowernumber) JOIN items USING (itemnumber) JOIN biblio USING (biblionumber) @@ -260,7 +273,7 @@ sub GetPredueIssues { my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due, - issues.branchcode as site, branches.branchname as site_name + issues.branchcode as site, branches.branchname as site_name, items.itemnumber FROM borrowers JOIN issues USING (borrowernumber) JOIN items USING (itemnumber) JOIN biblio USING (biblionumber) @@ -286,7 +299,7 @@ sub GetWaitingHolds { my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname, borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, reserves.waitingdate, - reserves.branchcode AS site, branches.branchname AS site_name, + reserves.branchcode AS site, branches.branchname AS site_name, items.itemnumber, TO_DAYS(NOW())-TO_DAYS(reserves.waitingdate) AS days_since_waiting FROM borrowers JOIN reserves USING (borrowernumber) JOIN items USING (itemnumber) -- 2.1.4