add logo_file support to welcome_letter and fix leaving temp files around for invoice...
authorivan <ivan>
Tue, 10 Aug 2010 06:28:40 +0000 (06:28 +0000)
committerivan <ivan>
Tue, 10 Aug 2010 06:28:40 +0000 (06:28 +0000)
FS/FS/cust_bill.pm
FS/FS/cust_main.pm
conf/welcome_letter

index 4bd9aa1..3e7109e 100644 (file)
@@ -3039,6 +3039,7 @@ sub print_ps {
 
   my ($file, $lfile) = $self->print_latex(@_);
   my $ps = generate_ps($file);
+  unlink($file.'.tex');
   unlink($lfile);
 
   $ps;
@@ -3067,6 +3068,7 @@ sub print_pdf {
 
   my ($file, $lfile) = $self->print_latex(@_);
   my $pdf = generate_pdf($file);
+  unlink($file.'.tex');
   unlink($lfile);
 
   $pdf;
index 955daf8..e107e6c 100644 (file)
@@ -8937,6 +8937,7 @@ I<$returnaddress> - the return address defaults to invoice_latexreturnaddress or
 
 =cut
 
+# a lot like cust_bill::print_latex
 sub generate_letter {
   my ($self, $template, %options) = @_;
 
@@ -9000,6 +9001,17 @@ sub generate_letter {
   $letter_data{company_name} = $conf->config('company_name', $self->agentnum);
 
   my $dir = $FS::UID::conf_dir."/cache.". $FS::UID::datasrc;
+
+  my $lh = new File::Temp( TEMPLATE => 'letter.'. $self->custnum. '.XXXXXXXX',
+                           DIR      => $dir,
+                           SUFFIX   => '.eps',
+                           UNLINK   => 0,
+                         ) or die "can't open temp file: $!\n";
+  print $lh $conf->config_binary('logo.eps', $self->agentnum)
+    or die "can't write temp file: $!\n";
+  close $lh;
+  $letter_data{'logo_file'} = $lh->filename;
+
   my $fh = new File::Temp( TEMPLATE => 'letter.'. $self->custnum. '.XXXXXXXX',
                            DIR      => $dir,
                            SUFFIX   => '.tex',
@@ -9009,7 +9021,8 @@ sub generate_letter {
   $letter_template->fill_in( OUTPUT => $fh, HASH => \%letter_data );
   close $fh;
   $fh->filename =~ /^(.*).tex$/ or die "unparsable filename: ". $fh->filename;
-  return $1;
+  return ($1, $letter_data{'logo_file'});
+
 }
 
 =item print_ps TEMPLATE 
@@ -9020,8 +9033,12 @@ Returns an postscript letter filled in from TEMPLATE, as a scalar.
 
 sub print_ps {
   my $self = shift;
-  my $file = $self->generate_letter(@_);
-  FS::Misc::generate_ps($file);
+  my($file, $lfile) = $self->generate_letter(@_);
+  my $ps = FS::Misc::generate_ps($file);
+  unlink($file.'.tex');
+  unlink($lfile);
+
+  $ps;
 }
 
 =item print TEMPLATE
index be7b484..b95a715 100644 (file)
@@ -67,7 +67,7 @@
     \returninset
     \makebox{
       \begin{tabular}{ll}
-        \includegraphics{[@-- $conf_dir --@]/logo.eps} &
+        \includegraphics{[@-- $logo_file --@]} &
         \begin{minipage}[b]{5.5cm}
 [@-- $returnaddress --@]
         \end{minipage}
@@ -75,7 +75,7 @@
     }
   }
   { % ... pages
-    %\includegraphics{[@-- $conf_dir --@]/logo.eps}    % Uncomment if you want the logo on all pages.
+    %\includegraphics{[@-- $logo_file --@]}    % Uncomment if you want the logo on all pages.
   }
 }