[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1791] trunk



Revision: 1791
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1791&view=rev
Author:   tetragon
Date:     2007-10-18 18:50:19 -0700 (Thu, 18 Oct 2007)

Log Message:
-----------
Add email support to new templating system, ex-parse_template email needs update
Add email output to GL report for a simple test (hardcoded addresses)

Modified Paths:
--------------
    trunk/LedgerSMB/Template.pm
    trunk/bin/gl.pl

Modified: trunk/LedgerSMB/Template.pm
===================================================================
--- trunk/LedgerSMB/Template.pm	2007-10-19 01:46:57 UTC (rev 1790)
+++ trunk/LedgerSMB/Template.pm	2007-10-19 01:50:19 UTC (rev 1791)
@@ -228,6 +228,11 @@
 	my $post = $format->can('postprocess')->($self);
 	if (!$self->{'noauto'}) {
 		$self->output;
+		# Clean up
+		if ($self->{rendered}) {
+			unlink($self->{rendered}) or
+				throw Error::Simple 'Unable to delete output file';
+		}
 	}
 	return $post;
 }
@@ -296,12 +301,46 @@
 
 sub _email_output {
 	my $self = shift;
-	my $mail = new LedgerSMB::Mailer;
-	#TODO stub
+	my $args = $self->{output_args};
+
+	my @mailmime;
+	if (!$self->{rendered} and !$args->{attach}) {
+		$args->{message} .= $self->{output};
+		@mailmime = ('contenttype', $self->{mimeytype});
+	}
+
+	my $mail = new LedgerSMB::Mailer(
+		from => $args->{from} || $self->{user}->{email},
+		to => $args->{to},
+		cc => $args->{cc},
+		bcc => $args->{bcc},
+		subject => $args->{subject},
+		notify => $args->{notify},
+		message => $args->{message},
+		@mailmime,
+	);
+	if ($args->{attach} or $self->{mimetype} !~ m#^text/# or $self->{rendered}) {
+		my @attachment;
+		my $name = $args->{filename};
+		if ($self->{rendered}) {
+			@attachment = ('file', $self->{rendered});
+			$name ||= $self->{rendered};
+		} else {
+			@attachment = ('data', $self->{output});
+		}
+		$mail->attach(
+			mimetype => $self->{mimetype},
+			filename => $name,
+			strip => $$,
+			@attachment,
+			);
+	}
+	$mail->send;
 }
 
 sub _lpr_output {
 	my $self = shift;
 	#TODO stub
 }
+
 1;

Modified: trunk/bin/gl.pl
===================================================================
--- trunk/bin/gl.pl	2007-10-19 01:46:57 UTC (rev 1790)
+++ trunk/bin/gl.pl	2007-10-19 01:50:19 UTC (rev 1791)
@@ -431,6 +431,7 @@
 }
 
 sub generate_report {
+    my $output_options = shift;
 
     $form->{sort} = "transdate" unless $form->{sort};
     $form->{amountfrom} = $form->parse_amount(\%myconfig, $form->{amountfrom});
@@ -788,6 +789,13 @@
         type => 'submit',
         class => 'submit',
     };
+    push @buttons, {
+        name => 'action',
+        value => 'csv_email_gl_report',
+        text => $locale->text('Email CSV Report'),
+        type => 'submit',
+        class => 'submit',
+    };
 
 ##SC: Taking this out for now...
 ##    if ( $form->{lynx} ) {
@@ -807,7 +815,10 @@
         locale => $locale,
         path => 'UI',
         template => 'form-dynatable',
-        format => ($format ne 'CSV')? 'HTML': 'CSV');
+        format => ($format ne 'CSV')? 'HTML': 'CSV',
+        output_options => $output_options,
+        );
+    $template->{method} = 'email' if $output_options;
     $template->render({
         form => \%$form,
         buttons => ..hidden..,
@@ -819,10 +830,19 @@
         row_alignment => \%row_alignment,
         totals => \%column_data,
     });
+    $form->info($locale->text('GL report sent to [_1]', $form->{login}));
 
 }
 
 sub csv_gl_report { &generate_report }
+sub csv_email_gl_report {
+    ##SC: XXX hardcoded test values
+    &generate_report({
+        to => '..hidden..',
+        from => '..hidden..',
+        subject => 'CSV GL report',
+    });
+}
 
 sub gl_subtotal_tt {
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.