X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FTemplate_Mixin.pm;h=37dcf2a5e708a0696e9dba95b15f9878ef4c28be;hb=11ca9a51a76837f1821b2b0e8972c78bf221c6a1;hp=c5a416b5147912bc457d821b39f210e3dbd4d25f;hpb=1b84c08aa4c0d92120150dc27b5af6deca484c38;p=freeside.git diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index c5a416b51..37dcf2a5e 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -817,35 +817,36 @@ sub print_generic { my @include = ( [ $tc, 'notes' ], [ 'invoice_', 'footer' ], [ 'invoice_', 'smallfooter', ], + [ 'invoice_', 'watermark' ], ); push @include, [ $tc, 'coupon', ] unless $params{'no_coupon'}; foreach my $i (@include) { + # load the configuration for this sub-template + my($base, $include) = @$i; my $inc_file = $conf->key_orbase("$base$format$include", $template); - my @inc_src; - - if ( $conf->exists($inc_file, $agentnum) - && length( $conf->config($inc_file, $agentnum) ) ) { - - @inc_src = $conf->config($inc_file, $agentnum); - - } else { - - $inc_file = $conf->key_orbase("${base}latex$include", $template); - my $convert_map = $convert_maps{$format}{$include}; - - @inc_src = map { s/\[\@--/$delimiters{$format}[0]/g; - s/--\@\]/$delimiters{$format}[1]/g; - $_; - } - &$convert_map( $conf->config($inc_file, $agentnum) ); + my @inc_src = $conf->config($inc_file, $agentnum); + if (!@inc_src) { + my $converter = $convert_maps{$format}{$include}; + if ( $converter ) { + # then attempt to convert LaTeX to the requested format + $inc_file = $conf->key_orbase($base.'latex'.$include, $template); + @inc_src = &$converter( $conf->config($inc_file, $agentnum) ); + foreach (@inc_src) { + # this isn't included in the convert_maps + my ($open, $close) = @{ $delimiters{$format} }; + s/\[\@--/$open/g; + s/--\@\]/$close/g; + } + } + } # else @inc_src is empty and that's fine - } + # make a Text::Template out of it my $inc_tt = new Text::Template ( TYPE => 'ARRAY', @@ -859,6 +860,8 @@ sub print_generic { die $error; } + # fill in variables + $invoice_data{$include} = $inc_tt->fill_in( HASH => \%invoice_data ); $invoice_data{$include} =~ s/\n+$// @@ -906,7 +909,8 @@ sub print_generic { if $DEBUG > 1; my $unsquelched = $params{unsquelch_cdr} || $cust_main->squelch_cdr ne 'Y'; - my $multisection = $conf->exists($tc.'sections', $cust_main->agentnum) || + my $multisection = $self->has_sections; + $conf->exists($tc.'sections', $cust_main->agentnum) || $conf->exists($tc.'sections_by_location', $cust_main->agentnum); $invoice_data{'multisection'} = $multisection; my $late_sections; @@ -1215,7 +1219,6 @@ sub print_generic { List::Util::first { $_->{description} eq $tax_description } @sections; if (!$tax_section) { $tax_section = { 'description' => $tax_description }; - push @sections, $tax_section if $multisection; } $tax_section->{tax_section} = 1; # mark this section as containing taxes # if this is an existing tax section, we're merging the tax items into it. @@ -1231,6 +1234,8 @@ sub print_generic { #$tax_section->{'sort_weight'} = $tax_weight; my @items_tax = $self->_items_tax; + push @sections, $tax_section if $multisection and @items_tax > 0; + foreach my $tax ( @items_tax ) { $taxtotal += $tax->{'amount'}; @@ -1647,7 +1652,10 @@ sub print_generic { sub notice_name { '('.shift->table.')'; } -sub template_conf { 'invoice_'; } +# this is not supposed to happen +sub template_conf { warn "bare FS::Template_Mixin::template_conf"; + 'invoice_'; +} # helper routine for generating date ranges sub _prior_month30s { @@ -2093,11 +2101,20 @@ sub generate_email { if (!@text) { - warn "$me generating plain text invoice" - if $DEBUG; + if ( $conf->config($tc.'template') ) { - # 'print_text' argument is no longer used - @text = $self->print_text(\%args); + warn "$me generating plain text invoice" + if $DEBUG; + + # 'print_text' argument is no longer used + @text = $self->print_text(\%args); + + } else { + + warn "$me no plain text version exists; sending empty message body" + if $DEBUG; + + } }