use strict;
use base qw( FS::Record );
use Text::Template;
-use FS::Misc qw( generate_email send_email );
+use FS::Misc qw( generate_email send_email do_print );
use FS::Conf;
use FS::Record qw( qsearch qsearchs );
use FS::UID qw( dbh );
use HTML::Entities qw( decode_entities encode_entities ) ;
use HTML::FormatText;
use HTML::TreeBuilder;
+use Encode;
use File::Temp;
use IPC::Run qw(run);
# @cust_msg = ('cust_msg' => $cust_msg);
# }
+ my $text_body = encode('UTF-8',
+ HTML::FormatText->new(leftmargin => 0, rightmargin => 70)
+ ->format( HTML::TreeBuilder->new_from_content($body) )
+ );
(
'custnum' => $cust_main->custnum,
'msgnum' => $self->msgnum,
'bcc' => $self->bcc_addr || undef,
'subject' => $subject,
'html_body' => $body,
- 'text_body' => HTML::FormatText->new(leftmargin => 0, rightmargin => 70
- )->format( HTML::TreeBuilder->new_from_content($body) ),
+ 'text_body' => $text_body
);
}
my %hash = $self->prepare(%opt);
my $html = $hash{'html_body'};
- my $tmp = 'msg'.$self->msgnum.'-'.time2str('%Y%m%d', time).'-XXXXXXXX';
- my $dir = "$FS::UID::cache_dir/cache.$FS::UID::datasrc";
-
# Graphics/stylesheets should probably go in /var/www on the Freeside
# machine.
my $kit = PDF::WebKit->new(\$html); #%options
# hack to use our wrapper script
$kit->configure(sub { shift->wkhtmltopdf('freeside-wkhtmltopdf') });
- my $fh = File::Temp->new(
- TEMPLATE => $tmp,
- DIR => $dir,
- UNLINK => 0,
- SUFFIX => '.pdf'
- );
- print $fh $kit->to_pdf;
- close $fh;
- return $fh->filename;
+ $kit->to_pdf;
}
=item print OPTIONS
=cut
sub print {
- my $file = render(@_);
- my @lpr = $conf->config('lpr');
- run ([@lpr, '-r'], '<', $file)
- or die "lpr error:\n$?\n";
+ my( $self, %opt ) = @_;
+ do_print( [ $self->render(%opt) ], agentnum=>$opt{cust_main}->agentnum );
}
-
# helper sub for package dates
my $ymd = sub { $_[0] ? time2str('%Y-%m-%d', $_[0]) : '' };