diff options
-rwxr-xr-x | LedgerSMB/Template.pm | 43 | ||||
-rw-r--r-- | bin/gl.pl | 22 |
2 files changed, 62 insertions, 3 deletions
diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm index 5248ab78..03bcbc34 100755 --- a/LedgerSMB/Template.pm +++ b/LedgerSMB/Template.pm @@ -228,6 +228,11 @@ sub render { 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 _http_output_file { 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; @@ -431,6 +431,7 @@ qq|<input name="l_description" class=checkbox type=checkbox value=Y checked> | } 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 @@ sub generate_report { 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 @@ sub generate_report { 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 => \@buttons, @@ -819,10 +830,19 @@ sub generate_report { 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 => 'seneca@localhost', + from => 'seneca@localhost', + subject => 'CSV GL report', + }); +} sub gl_subtotal_tt { |