From 7e2c7ed7cd39d90a1717909ebc7c9d5fb48bd50c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9rick?= <frederick.capovilla@libeo.com>
Date: Fri, 3 May 2013 17:04:38 -0400
Subject: [PATCH] [PATCH] Bug 8687: Improvements in the overdue_notices.pl script

- UTF-8 support in the HTML output
- Add the cardnumber and phone columns to the csv output

Patch sponsored by the CCSR ( http://www.ccsr.qc.ca )
---
 misc/cronjobs/overdue_notices.pl |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl
index 5f285c0..8ceb3e6 100755
--- a/misc/cronjobs/overdue_notices.pl
+++ b/misc/cronjobs/overdue_notices.pl
@@ -60,7 +60,7 @@ overdue_notices.pl
    -max          <days>           maximum days overdue to deal with
    -library      <branchname>     only deal with overdues from this library (repeatable : several libraries can be given)
    -csv          <filename>       populate CSV file
-   -html         <filename>       Output html to file
+   -html         <filedir>        Output html to file directory or to STDOUT if none specified
    -itemscontent <list of fields> item information in templates
    -borcat       <categorycode>   category code that must be included
    -borcatout    <categorycode>   category code that must be excluded
@@ -362,7 +362,7 @@ if ( defined $csvfilename ) {
     } else {
         open $csv_fh, ">", $csvfilename or die "unable to open $csvfilename: $!";
     }
-    if ( $csv->combine(qw(name surname address1 address2 zipcode city country email itemcount itemsinfo)) ) {
+    if ( $csv->combine(qw(name surname address1 address2 zipcode city country email phone cardnumber itemcount itemsinfo)) ) {
         print $csv_fh $csv->string, "\n";
     } else {
         $verbose and warn 'combine failed on argument: ' . $csv->error_input;
@@ -376,11 +376,13 @@ if ( defined $htmlfilename ) {
     $html_fh = *STDOUT;
   } else {
     my $today = DateTime->now(time_zone => C4::Context->tz );
-    open $html_fh, ">",File::Spec->catdir ($htmlfilename,"notices-".$today->ymd().".html");
+    my $htmlfile = File::Spec->catdir ($htmlfilename,"notices-".$today->ymd().".html");
+    open $html_fh, ">:encoding(UTF-8)", $htmlfile or die "unable to open $htmlfile; $! (Be sure to create the directory)\n";
   }
   
   print $html_fh "<html>\n";
   print $html_fh "<head>\n";
+  print $html_fh "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
   print $html_fh "<style type='text/css'>\n";
   print $html_fh "pre {page-break-after: always;}\n";
   print $html_fh "pre {white-space: pre-wrap;}\n";
@@ -451,7 +453,7 @@ END_SQL
             # <date> <itemcount> <firstname> <lastname> <address1> <address2> <address3> <city> <postcode> <country>
 
             my $borrower_sql = <<'END_SQL';
-SELECT distinct(issues.borrowernumber), firstname, surname, address, address2, city, zipcode, country, email, emailpro, B_email
+SELECT distinct(issues.borrowernumber), firstname, surname, address, address2, city, zipcode, country, email, emailpro, B_email, phone, cardnumber
 FROM   issues,borrowers,categories
 WHERE  issues.borrowernumber=borrowers.borrowernumber
 AND    borrowers.categorycode=categories.categorycode
@@ -595,6 +597,8 @@ END_SQL
                             country        => $data->{'country'},
                             email          => $notice_email,
                             itemcount      => $itemcount,
+                            phone          => $data->{'phone'},
+                            cardnumber     => $data->{'cardnumber'},
                             titles         => $titles,
                             outputformat   => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '',
                         }
@@ -752,7 +756,7 @@ sub prepare_letter_for_printing {
     if ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'csv' ) {
         if ($csv->combine(
                 $params->{'firstname'}, $params->{'lastname'}, $params->{'address1'},  $params->{'address2'}, $params->{'postcode'},
-                $params->{'city'}, $params->{'country'}, $params->{'email'}, $params->{'itemcount'}, $params->{'titles'}
+                $params->{'city'}, $params->{'country'}, $params->{'email'}, $params->{'phone'}, $params->{'cardnumber'}, $params->{'itemcount'}, $params->{'titles'}
             )
           ) {
             return $csv->string, "\n";
-- 
1.7.2.5