Bug 17600: Standardize our EXPORT_OK
[srvgit] / misc / cronjobs / overdue_notices.pl
index 7b50f25..a1c2211 100755 (executable)
@@ -24,12 +24,12 @@ BEGIN {
 
     # find Koha's Perl modules
     # test carefully before changing this
-    use FindBin;
+    use FindBin ();
     eval { require "$FindBin::Bin/../kohalib.pl" };
 }
 
-use Getopt::Long;
-use Pod::Usage;
+use Getopt::Long qw( GetOptions );
+use Pod::Usage qw( pod2usage );
 use Text::CSV_XS;
 use DateTime;
 use DateTime::Duration;
@@ -37,10 +37,10 @@ use DateTime::Duration;
 use Koha::Script -cron;
 use C4::Context;
 use C4::Letters;
-use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes parse_overdues_letter);
-use C4::Log;
-use Koha::Patron::Debarments qw(AddUniqueDebarment);
-use Koha::DateUtils;
+use C4::Overdues qw( GetOverdueMessageTransportTypes parse_overdues_letter );
+use C4::Log qw( cronlogaction );
+use Koha::Patron::Debarments qw( AddUniqueDebarment );
+use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Calendar;
 use Koha::Libraries;
 use Koha::Acquisition::Currencies;
@@ -412,7 +412,7 @@ binmode( STDOUT, ':encoding(UTF-8)' );
 our $csv;       # the Text::CSV_XS object
 our $csv_fh;    # the filehandle to the CSV file.
 if ( defined $csvfilename ) {
-    my $sep_char = C4::Context->preference('delimiter') || ';';
+    my $sep_char = C4::Context->preference('CSVDelimiter') || ';';
     $sep_char = "\t" if ($sep_char eq 'tabulation');
     $csv = Text::CSV_XS->new( { binary => 1 , sep_char => $sep_char } );
     if ( $csvfilename eq '' ) {
@@ -469,8 +469,7 @@ foreach my $branchcode (@branches) {
     }
 
     my $library             = Koha::Libraries->find($branchcode);
-    my $admin_email_address = $library->branchemail
-      || C4::Context->preference('KohaAdminEmailAddress');
+    my $admin_email_address = $library->from_email_address;
     my $branch_email_address = C4::Context->preference('AddressForFailedOverdueNotices')
       || $library->inbound_email_address;
     my @output_chunks;    # may be sent to mail or stdout or csv file.
@@ -624,7 +623,14 @@ END_SQL
                     }
                 }
 
-                my $letter = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"}, $branchcode, undef, $patron->lang );
+                my $letter = Koha::Notice::Templates->find_effective_template(
+                    {
+                        module     => 'circulation',
+                        code       => $overdue_rules->{"letter$i"},
+                        branchcode => $branchcode,
+                        lang       => $patron->lang
+                    }
+                );
 
                 unless ($letter) {
                     $verbose and warn qq|Message '$overdue_rules->{"letter$i"}' content not found|;
@@ -715,7 +721,16 @@ END_SQL
                     splice @items, $PrintNoticesMaxLines if $effective_mtt eq 'print' && $PrintNoticesMaxLines && scalar @items > $PrintNoticesMaxLines;
                     #catch the case where we are sending a print to someone with an email
 
-                    my $letter_exists = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"}, $branchcode, $effective_mtt, $patron->lang ) ? 1 : 0;
+                    my $letter_exists = Koha::Notice::Templates->find_effective_template(
+                        {
+                            module     => 'circulation',
+                            code       => $overdue_rules->{"letter$i"},
+                            message_transport_type => $effective_mtt,
+                            branchcode => $branchcode,
+                            lang       => $patron->lang
+                        }
+                    );
+
                     my $letter = parse_overdues_letter(
                         {   letter_code     => $overdue_rules->{"letter$i"},
                             borrowernumber  => $borrowernumber,
@@ -826,7 +841,7 @@ END_SQL
         # Generate the content of the csv with headers
         my $content;
         if ( defined $csvfilename ) {
-            my $delimiter = C4::Context->preference('delimiter') || ';';
+            my $delimiter = C4::Context->preference('CSVDelimiter') || ';';
             $content = join($delimiter, qw(title name surname address1 address2 zipcode city country email itemcount itemsinfo due_date issue_date)) . "\n";
         }
         else {