- #$self->email_invoice(\%opt)
- $self->email(\%opt)
- if ( grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list or !@invoicing_list )
- && ! $self->invoice_noemail;
-
- $opt{'lpr'} = $lpr;
- #$self->print_invoice(\%opt)
- $self->print(\%opt)
- if grep { $_ eq 'POST' } @invoicing_list; #postal
-
- #this has never been used post-$ORIGINAL_ISP afaik
- $self->fax_invoice(\%opt)
- if grep { $_ eq 'FAX' } @invoicing_list; #fax
-
- '';
-
-}
-
-=item email HASHREF | [ TEMPLATE [ , INVOICE_FROM ] ]
-
-Emails this invoice.
-
-Options can be passed as a hashref (recommended) or as a list of up to
-two values for templatename and invoice_from.
-
-I<template>, if specified, is the name of a suffix for alternate invoices.
-
-I<invoice_from>, if specified, overrides the default email invoice From: address.
-
-I<notice_name>, if specified, overrides "Invoice" as the name of the sent document (templates from 10/2009 or newer required)
-
-=cut
-
-sub queueable_email {
- my %opt = @_;
-
- my $self = qsearchs('cust_bill', { 'invnum' => $opt{invnum} } )
- or die "invalid invoice number: " . $opt{invnum};
-
- my %args = ( 'template' => $opt{template} );
- $args{$_} = $opt{$_}
- foreach grep { exists($opt{$_}) && $opt{$_} }
- qw( invoice_from notice_name no_coupon );
-
- my $error = $self->email( \%args );
- die $error if $error;
-
-}
-
-#sub email_invoice {
-sub email {
- my $self = shift;
- return if $self->hide;
- my $conf = $self->conf;
-
- my( $template, $invoice_from, $notice_name, $no_coupon );
- if ( ref($_[0]) ) {
- my $opt = shift;
- $template = $opt->{'template'} || '';
- $invoice_from = $opt->{'invoice_from'};
- $notice_name = $opt->{'notice_name'} || 'Invoice';
- $no_coupon = $opt->{'no_coupon'} || 0;
- } else {
- $template = scalar(@_) ? shift : '';
- $invoice_from = shift if scalar(@_);
- $notice_name = 'Invoice';
- $no_coupon = 0;
- }
-
- $invoice_from ||= $self->_agent_invoice_from || #XXX should go away
- $conf->config('invoice_from', $self->cust_main->agentnum );
-
- my @invoicing_list = grep { $_ !~ /^(POST|FAX)$/ }
- $self->cust_main->invoicing_list;
-
- if ( ! @invoicing_list ) { #no recipients
- if ( $conf->exists('cust_bill-no_recipients-error') ) {
- die 'No recipients for customer #'. $self->custnum;
- } else {
- #default: better to notify this person than silence
- @invoicing_list = ($invoice_from);
- }
- }
-
- my $subject = $self->email_subject($template);
-
- my $error = send_email(
- $self->generate_email(
- 'from' => $invoice_from,
- 'to' => [ grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ],
- 'subject' => $subject,
- 'template' => $template,
- 'notice_name' => $notice_name,
- 'no_coupon' => $no_coupon,
- )
- );
- die "can't email invoice: $error\n" if $error;
- #die "$error\n" if $error;
-
-}
-
-sub email_subject {
- my $self = shift;
- my $conf = $self->conf;
-
- #my $template = scalar(@_) ? shift : '';
- #per-template?
-
- my $subject = $conf->config('invoice_subject', $self->cust_main->agentnum)
- || 'Invoice';
-
- my $cust_main = $self->cust_main;
- my $name = $cust_main->name;
- my $name_short = $cust_main->name_short;
- my $invoice_number = $self->invnum;
- my $invoice_date = $self->_date_pretty;
-
- eval qq("$subject");
-}
-
-=item lpr_data HASHREF | [ TEMPLATE ]
-
-Returns the postscript or plaintext for this invoice as an arrayref.
-
-Options can be passed as a hashref (recommended) or as a single optional value
-for template.
-
-I<template>, if specified, is the name of a suffix for alternate invoices.
-
-I<notice_name>, if specified, overrides "Invoice" as the name of the sent document (templates from 10/2009 or newer required)
-
-=cut
-
-sub lpr_data {
- my $self = shift;
- my $conf = $self->conf;
- my( $template, $notice_name );
- if ( ref($_[0]) ) {
- my $opt = shift;
- $template = $opt->{'template'} || '';
- $notice_name = $opt->{'notice_name'} || 'Invoice';
- } else {
- $template = scalar(@_) ? shift : '';
- $notice_name = 'Invoice';
- }
-
- my %opt = (
- 'template' => $template,
- 'notice_name' => $notice_name,
- );
-
- my $method = $conf->exists('invoice_latex') ? 'print_ps' : 'print_text';
- [ $self->$method( \%opt ) ];
-}
-
-=item print HASHREF | [ TEMPLATE ]
-
-Prints this invoice.
-
-Options can be passed as a hashref (recommended) or as a single optional
-value for template.
-
-I<template>, if specified, is the name of a suffix for alternate invoices.
-
-I<notice_name>, if specified, overrides "Invoice" as the name of the sent document (templates from 10/2009 or newer required)
-
-=cut
-
-#sub print_invoice {
-sub print {
- my $self = shift;
- return if $self->hide;
- my $conf = $self->conf;
-
- my( $template, $notice_name, $lpr );
- if ( ref($_[0]) ) {
- my $opt = shift;
- $template = $opt->{'template'} || '';
- $notice_name = $opt->{'notice_name'} || 'Invoice';
- $lpr = $opt->{'lpr'}
- } else {
- $template = scalar(@_) ? shift : '';
- $notice_name = 'Invoice';
- $lpr = '';
- }
-
- my %opt = (
- 'template' => $template,
- 'notice_name' => $notice_name,
- );
-
- if($conf->exists('invoice_print_pdf')) {
- # Add the invoice to the current batch.
- $self->batch_invoice(\%opt);
- }
- else {
- do_print(
- $self->lpr_data(\%opt),
- 'agentnum' => $self->cust_main->agentnum,
- 'lpr' => $lpr,
- );
- }
-}
-
-=item fax_invoice HASHREF | [ TEMPLATE ]
-
-Faxes this invoice.
-
-Options can be passed as a hashref (recommended) or as a single optional
-value for template.
-
-I<template>, if specified, is the name of a suffix for alternate invoices.
-
-I<notice_name>, if specified, overrides "Invoice" as the name of the sent document (templates from 10/2009 or newer required)
-
-=cut
-
-sub fax_invoice {
- my $self = shift;
- return if $self->hide;
- my $conf = $self->conf;
-
- my( $template, $notice_name );
- if ( ref($_[0]) ) {
- my $opt = shift;
- $template = $opt->{'template'} || '';
- $notice_name = $opt->{'notice_name'} || 'Invoice';
- } else {
- $template = scalar(@_) ? shift : '';
- $notice_name = 'Invoice';
- }
-
- die 'FAX invoice destination not (yet?) supported with plain text invoices.'
- unless $conf->exists('invoice_latex');
-
- my $dialstring = $self->cust_main->getfield('fax');
- #Check $dialstring?
-
- my %opt = (
- 'template' => $template,
- 'notice_name' => $notice_name,
- );
-
- my $error = send_fax( 'docdata' => $self->lpr_data(\%opt),
- 'dialstring' => $dialstring,
- );
- die $error if $error;
-
-}
-
-=item batch_invoice [ HASHREF ]
-
-Place this invoice into the open batch (see C<FS::bill_batch>). If there
-isn't an open batch, one will be created.