X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill.pm;h=e70bb324740ee9502c4bd805bbe82f3b4195916d;hb=a638ae8bdba35169f61f2729d8f3491496992b55;hp=93c179a2ab30d046d1c4acfb4e8fafff3fc12552;hpb=f7afca1829f8496509d10806439c37fcc1349135;p=freeside.git diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 93c179a2a..e70bb3247 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -318,6 +318,80 @@ sub owed { $balance; } + +=item generate_email PARAMHASH + +PARAMHASH can contain the following: + +=over 4 + +=item from => sender address, required + +=item tempate => alternate template name, optional + +=item print_text => text attachment arrayref, optional + +=item subject => email subject, optional + +=back + +Returns an argument list to be passed to L. + +=cut + +sub generate_email { + + my $self = shift; + my %args = @_; + + my $mimeparts; + if ($conf->exists('invoice_email_pdf')) { + #warn "[FS::cust_bill::send] creating PDF attachment"; + #mime parts arguments a la MIME::Entity->build(). + $mimeparts = [ + { + 'Type' => 'application/pdf', + 'Encoding' => 'base64', + 'Data' => [ $self->print_pdf('', $args{'template'}) ], + 'Disposition' => 'attachment', + 'Filename' => 'invoice.pdf', + }, + ]; + } + + my $email_text; + if ($conf->exists('invoice_email_pdf') + and scalar($conf->config('invoice_email_pdf_note'))) { + + #warn "[FS::cust_bill::send] using 'invoice_email_pdf_note'"; + $email_text = [ map { $_ . "\n" } $conf->config('invoice_email_pdf_note') ]; + } else { + #warn "[FS::cust_bill::send] not using 'invoice_email_pdf_note'"; + if (ref($args{'print_text'}) eq 'ARRAY') { + $email_text = $args{'print_text'}; + } else { + $email_text = [ $self->print_text('', $args{'template'}) ]; + } + } + + my @invoicing_list; + if (ref($args{'to'} eq 'ARRAY')) { + @invoicing_list = @{$args{'to'}}; + } else { + @invoicing_list = grep { $_ ne 'POST' } $self->cust_main->invoicing_list; + } + + return ( + 'from' => $args{'from'}, + 'to' => [ @invoicing_list ], + 'subject' => (($args{'subject'}) ? $args{'subject'} : 'Invoice'), + 'body' => $email_text, + 'mimeparts' => $mimeparts, + ); + + +} + =item send [ TEMPLATENAME [ , AGENTNUM [ , INVOICE_FROM ] ] ] Sends this invoice to the destinations configured for this customer: send @@ -350,10 +424,11 @@ sub send { @invoicing_list = ($invoice_from) unless @invoicing_list; my $error = send_email( - 'from' => $invoice_from, - 'to' => [ grep { $_ ne 'POST' } @invoicing_list ], - 'subject' => 'Invoice', - 'body' => \@print_text, + $self->generate_email( + 'from' => $invoice_from, + 'to' => [ grep { $_ ne 'POST' } @invoicing_list ], + 'print_text' => [ @print_text ], + ) ); die "can't email invoice: $error\n" if $error; #die "$error\n" if $error; @@ -681,7 +756,7 @@ sub batch_card { 'state' => $cust_main->getfield('state'), 'zip' => $cust_main->getfield('zip'), 'country' => $cust_main->getfield('country'), - 'cardnum' => $cust_main->getfield('payinfo'), + 'cardnum' => $cust_main->payinfo, 'exp' => $cust_main->getfield('paydate'), 'payname' => $cust_main->getfield('payname'), 'amount' => $self->owed, @@ -1192,12 +1267,12 @@ sub print_ps { my $sfile = shell_quote $file; system("pslatex $sfile.tex >/dev/null 2>&1") == 0 - or die "pslatex $file.tex failed: $!"; + or die "pslatex $file.tex failed; see $file.log for details?\n"; system("pslatex $sfile.tex >/dev/null 2>&1") == 0 - or die "pslatex $file.tex failed: $!"; + or die "pslatex $file.tex failed; see $file.log for details?\n"; system('dvips', '-q', '-t', 'letter', "$file.dvi", '-o', "$file.ps" ) == 0 - or die "dvips failed: $!"; + or die "dvips failed"; open(POSTSCRIPT, "<$file.ps") or die "can't open $file.ps: $! (error in LaTeX template?)\n";