@@ -, +, @@ Notices misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl --- C4/Letters.pm | 11 +++- .../thirdparty/TalkingTech_itiva_outbound.pl | 58 +++++++++++++------ 2 files changed, 51 insertions(+), 18 deletions(-) --- a/C4/Letters.pm +++ a/C4/Letters.pm @@ -932,7 +932,16 @@ ENDSQL $params->{'reply_address'}, # reply_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]) --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl +++ a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl @@ -62,6 +62,7 @@ my $help; my $outfile; my $skip_patrons_with_email; my $patron_branchcode; +my $use_tt; # maps to convert I-tiva terms to Koha terms my $type_module_map = { @@ -77,15 +78,16 @@ my $type_notice_map = { }; GetOptions( - 'o|output:s' => \$outfile, - 'v' => \$verbose, - 'lang:s' => \$language, - 'type:s' => \@types, - 'w|waiting-hold-day:s' => \@holds_waiting_days_to_call, - 'c|code|library-code:s' => \$library_code, + 'o|output:s' => \$outfile, + 'v' => \$verbose, + 'lang:s' => \$language, + 'type:s' => \@types, + 'w|waiting-hold-day:s' => \@holds_waiting_days_to_call, + 'c|code|library-code:s' => \$library_code, 's|skip-patrons-with-email' => \$skip_patrons_with_email, - 'pb|patron-branchcode:s' => \$patron_branchcode, - 'h|help' => \$help, + 'pb|patron-branchcode:s' => \$patron_branchcode, + 'tt|template-toolkit' => \$use_tt, + 'h|help' => \$help, ); $language = uc($language); @@ -141,9 +143,20 @@ foreach my $type (@types) { letter_code => $code, lang => 'default', # It does not sound useful to send a lang here 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', ); @@ -160,9 +173,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 ( $use_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"; + } } } @@ -230,6 +248,12 @@ OPTIONAL Limits the the patrons to generate notices for based on the patron's home library. Items and holds from other libraries will still be included for the given patron. +=item B<--template-toolkit> + +OPTIONAL. If set, processes the notice content as Template Toolkit syntax and sends the content as the CSV line instead +of generated a fixed CSV line. This allows the contents of the CSV file to be created dynamically instead of using the +fixed format that is outputted without this flag. + =back =cut @@ -242,7 +266,7 @@ sub GetOverdueIssues { 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, 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) @@ -283,7 +307,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) @@ -313,7 +337,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) --