projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix MIME::Entity usage for perl 5.18+, RT#77890
[freeside.git]
/
FS
/
FS
/
Template_Mixin.pm
diff --git
a/FS/FS/Template_Mixin.pm
b/FS/FS/Template_Mixin.pm
index
04ea1eb
..
c97e84e
100644
(file)
--- a/
FS/FS/Template_Mixin.pm
+++ b/
FS/FS/Template_Mixin.pm
@@
-10,6
+10,7
@@
use vars qw( $invoice_lines @buf ); #yuck
use List::Util qw(sum); #can't import first, it conflicts with cust_main.first
use Date::Format;
use Date::Language;
use List::Util qw(sum); #can't import first, it conflicts with cust_main.first
use Date::Format;
use Date::Language;
+use Time::Local qw( timelocal );
use Text::Template 1.20;
use File::Temp 0.14;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use Text::Template 1.20;
use File::Temp 0.14;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
@@
-147,6
+148,10
@@
sub print_latex {
$template ||= $self->_agent_template
if $self->can('_agent_template');
$template ||= $self->_agent_template
if $self->can('_agent_template');
+ #the new way
+ $self->set('mode', $params{mode})
+ if $params{mode};
+
my $pkey = $self->primary_key;
my $tmp_template = $self->table. '.'. $self->$pkey. '.XXXXXXXX';
my $pkey = $self->primary_key;
my $tmp_template = $self->table. '.'. $self->$pkey. '.XXXXXXXX';
@@
-561,6
+566,7
@@
sub print_generic {
'notice_name' => $notice_name, # escape?
'current_charges' => sprintf("%.2f", $self->charged),
'duedate' => $self->due_date2str('rdate'), #date_format?
'notice_name' => $notice_name, # escape?
'current_charges' => sprintf("%.2f", $self->charged),
'duedate' => $self->due_date2str('rdate'), #date_format?
+ 'duedate_long' => $self->due_date2str('long'),
#customer info
'custnum' => $cust_main->display_custnum,
#customer info
'custnum' => $cust_main->display_custnum,
@@
-1059,7
+1065,7
@@
sub print_generic {
# start setting up summary subtotals
my @summary_subtotals;
my $method = $conf->config('summary_subtotals_method');
# start setting up summary subtotals
my @summary_subtotals;
my $method = $conf->config('summary_subtotals_method');
- if ( $method and $method ne $conf->config($tc.'sections_method') ) {
+ if (
( ref($self) ne 'FS::quotation' ) and
$method and $method ne $conf->config($tc.'sections_method') ) {
# then re-section them by the correct method
my %section_method = ( by_category => 1 );
if ( $conf->config('summary_subtotals_method') eq 'location' ) {
# then re-section them by the correct method
my %section_method = ( by_category => 1 );
if ( $conf->config('summary_subtotals_method') eq 'location' ) {
@@
-1150,14
+1156,27
@@
sub print_generic {
if ( $invoice_data{finance_section} &&
$section->{'description'} eq $invoice_data{finance_section} );
if ( $invoice_data{finance_section} &&
$section->{'description'} eq $invoice_data{finance_section} );
- $section->{'subtotal'} = $other_money_char.
- sprintf('%.2f', $section->{'subtotal'})
- if
$multisection;
+ if ( $multisection ) {
+
+ if
( ref($section->{'subtotal'}) ) {
- # continue some normalization
- $section->{'amount'} = $section->{'subtotal'}
- if $multisection;
+ $section->{'subtotal'} =
+ sprintf("$other_money_char%.2f to $other_money_char%.2f",
+ $section->{'subtotal'}[0],
+ $section->{'subtotal'}[1]
+ );
+
+ } else {
+ $section->{'subtotal'} = $other_money_char.
+ sprintf('%.2f', $section->{'subtotal'})
+
+ }
+
+ # continue some normalization
+ $section->{'amount'} = $section->{'subtotal'}
+
+ }
if ( $section->{'description'} ) {
push @buf, ( [ &$escape_function($section->{'description'}), '' ],
if ( $section->{'description'} ) {
push @buf, ( [ &$escape_function($section->{'description'}), '' ],
@@
-1356,7
+1375,16
@@
sub print_generic {
foreach ( @new_total_items ) {
my ($item, $amount) = ($_->{'total_item'}, $_->{'total_amount'});
$_->{'total_item'} = &$embolden_function( $item );
foreach ( @new_total_items ) {
my ($item, $amount) = ($_->{'total_item'}, $_->{'total_amount'});
$_->{'total_item'} = &$embolden_function( $item );
+
+ if ( ref($amount) ) {
+ $_->{'total_amount'} = &$embolden_function(
+ $other_money_char.$amount->[0]. ' to '.
+ $other_money_char.$amount->[1]
+ );
+ } else {
$_->{'total_amount'} = &$embolden_function( $other_money_char.$amount );
$_->{'total_amount'} = &$embolden_function( $other_money_char.$amount );
+ }
+
# but if it's multisection, don't append to @total_items. the adjust
# section has all this stuff
push @total_items, $_ if !$multisection;
# but if it's multisection, don't append to @total_items. the adjust
# section has all this stuff
push @total_items, $_ if !$multisection;
@@
-1635,24
+1663,24
@@
sub print_generic {
die "no invoice_lines() functions in template?"
if ( $format eq 'template' && !$wasfunc );
die "no invoice_lines() functions in template?"
if ( $format eq 'template' && !$wasfunc );
- if ($format eq 'template') {
+ if ( $invoice_lines ) {
+ $invoice_data{'total_pages'} = int( scalar(@buf) / $invoice_lines );
+ $invoice_data{'total_pages'}++
+ if scalar(@buf) % $invoice_lines;
+ }
- if ( $invoice_lines ) {
- $invoice_data{'total_pages'} = int( scalar(@buf) / $invoice_lines );
- $invoice_data{'total_pages'}++
- if scalar(@buf) % $invoice_lines;
+ #setup subroutine for the template
+ $invoice_data{invoice_lines} = sub {
+ my $lines = shift || scalar(@buf);
+ map {
+ scalar(@buf)
+ ? shift @buf
+ : [ '', '' ];
}
}
+ ( 1 .. $lines );
+ };
- #setup subroutine for the template
- $invoice_data{invoice_lines} = sub {
- my $lines = shift || scalar(@buf);
- map {
- scalar(@buf)
- ? shift @buf
- : [ '', '' ];
- }
- ( 1 .. $lines );
- };
+ if ($format eq 'template') {
my $lines;
my @collect;
my $lines;
my @collect;
@@
-1915,6
+1943,12
@@
sub due_date {
my $duedate = '';
if ( $self->terms =~ /^\s*Net\s*(\d+)\s*$/ ) {
$duedate = $self->_date() + ( $1 * 86400 );
my $duedate = '';
if ( $self->terms =~ /^\s*Net\s*(\d+)\s*$/ ) {
$duedate = $self->_date() + ( $1 * 86400 );
+ } elsif ( $self->terms =~ /^End of Month$/ ) {
+ my ($mon,$year) = (localtime($self->_date) )[4,5];
+ $mon++;
+ until ( $mon < 12 ) { $mon -= 12; $year++; }
+ my $nextmonth_first = timelocal(0,0,0,1,$mon,$year);
+ $duedate = $nextmonth_first - 86400;
}
$duedate;
}
}
$duedate;
}
@@
-1942,8
+1976,12
@@
sub balance_due_msg {
# _items_total) and not here
# (yes, or if invoice_sections is enabled; this is just for compatibility)
if ( $self->due_date ) {
# _items_total) and not here
# (yes, or if invoice_sections is enabled; this is just for compatibility)
if ( $self->due_date ) {
- $msg .= ' - ' . $self->mt('Please pay by'). ' '.
- $self->due_date2str('short');
+ my $please_pay_by =
+ $self->conf->config('invoice_pay_by_msg', $self->agentnum)
+ || 'Please pay by [_1]';
+ $msg .= ' - ' . $self->mt($please_pay_by, $self->due_date2str('short')).
+ ' '
+ unless $self->conf->config_bool('invoice_omit_due_date',$self->agentnum);
} elsif ( $self->terms ) {
$msg .= ' - '. $self->mt($self->terms);
}
} elsif ( $self->terms ) {
$msg .= ' - '. $self->mt($self->terms);
}
@@
-2069,6
+2107,7
@@
Returns an argument list to be passed to L<FS::Misc::send_email>.
=cut
use MIME::Entity;
=cut
use MIME::Entity;
+use Encode;
sub generate_email {
sub generate_email {
@@
-2136,7
+2175,7
@@
sub generate_email {
if $DEBUG;
# 'print_text' argument is no longer used
if $DEBUG;
# 'print_text' argument is no longer used
- @text = $self->print_text(\%args);
+ @text =
map Encode::encode_utf8($_),
$self->print_text(\%args);
} else {
} else {
@@
-2231,7
+2270,7
@@
sub generate_email {
' </title>',
' </head>',
' <body bgcolor="#e8e8e8">',
' </title>',
' </head>',
' <body bgcolor="#e8e8e8">',
-
$html
,
+
Encode::encode_utf8($html)
,
' </body>',
'</html>',
],
' </body>',
'</html>',
],
@@
-2352,12
+2391,19
@@
sub mimebuild_pdf {
);
}
);
}
+=item postal_mail_fsinc
+
+Sends this invoice to the Freeside Internet Services, Inc. print and mail
+service.
+=cut
use CAM::PDF;
use CAM::PDF;
+use IO::Socket::SSL;
use LWP::UserAgent;
use HTTP::Request::Common qw( POST );
use JSON::XS;
use LWP::UserAgent;
use HTTP::Request::Common qw( POST );
use JSON::XS;
+use MIME::Base64;
sub postal_mail_fsinc {
my ( $self, %opt ) = @_;
sub postal_mail_fsinc {
my ( $self, %opt ) = @_;
@@
-2389,14
+2435,21
@@
sub postal_mail_fsinc {
} else {
die "Unparsable company_address; contact support\@freeside.biz\n";
}
} else {
die "Unparsable company_address; contact support\@freeside.biz\n";
}
+ $company_city =~ s/,$//;
my $file = $self->print_pdf(%opt, 'no_addresses' => 1);
my $pages = CAM::PDF->new($file)->numPages;
my $file = $self->print_pdf(%opt, 'no_addresses' => 1);
my $pages = CAM::PDF->new($file)->numPages;
- my $ua = LWP::UserAgent->new( 'ssl_opts' => { 'verify_hostname'=>0 });
+ my $ua = LWP::UserAgent->new(
+ 'ssl_opts' => {
+ verify_hostname => 0,
+ SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
+ SSL_version => 'SSLv3',
+ }
+ );
my $response = $ua->request( POST $url, [
'support-key' => scalar($conf->config('support-key')),
my $response = $ua->request( POST $url, [
'support-key' => scalar($conf->config('support-key')),
- 'file' =>
$file
,
+ 'file' =>
encode_base64($file)
,
'pages' => $pages,
#from:
'pages' => $pages,
#from:
@@
-2425,7
+2478,8
@@
sub postal_mail_fsinc {
'country' => $bill_location->country,
]);
'country' => $bill_location->country,
]);
- die "Print connection error: ". $response->message. "\n"
+ die "Print connection error: ". $response->message.
+ ' ('. $response->as_string. ")\n"
unless $response->is_success;
local $@;
unless $response->is_success;
local $@;
@@
-2434,28
+2488,11
@@
sub postal_mail_fsinc {
die $content->{error}."\n"
if $content->{error};
die $content->{error}."\n"
if $content->{error};
-}
-
-1;
- 'address1' => $bill_location->address1,
- 'address2' => $bill_location->address2,
- 'city' => $bill_location->city,
- 'state' => $bill_location->state,
- 'zip' => $bill_location->zip,
- 'country' => $bill_location->country,
- ]);
- die "Print connection error: ". $response->message
-
unless $response->is_success
;
+ #TODO: store this so we can query for a status later
+
warn "Invoice printed, ID ". $content->{id}. "\n"
;
- local $@;
- my $content = eval { decode_json($response->content) };
- die "Print JSON error : $@\n" if $@;
-
- die $content->{error}."\n"
- if $content->{error};
-
- #TODO: get some kind of letter ID back we can later retreive a status on
+ $content->{id};
}
=item _items_sections OPTIONS
}
=item _items_sections OPTIONS
@@
-3177,7
+3214,9
@@
sub _items_cust_bill_pkg {
# for location labels: use default location on the invoice date
my $default_locationnum;
# for location labels: use default location on the invoice date
my $default_locationnum;
- if ( $self->custnum ) {
+ if ( $conf->exists('invoice-all_pkg_addresses') ) {
+ $default_locationnum = 0; # treat them all as non-default
+ } elsif ( $self->custnum ) {
my $h_cust_main;
my @h_search = FS::h_cust_main->sql_h_search($self->_date);
$h_cust_main = qsearchs({
my $h_cust_main;
my @h_search = FS::h_cust_main->sql_h_search($self->_date);
$h_cust_main = qsearchs({
@@
-3285,7
+3324,7
@@
sub _items_cust_bill_pkg {
my @details = $cust_bill_pkg->details;
# and I guess they're never bundled either?
my @details = $cust_bill_pkg->details;
# and I guess they're never bundled either?
- if (
$cust_bill_pkg->setup != 0
) {
+ if (
( $cust_bill_pkg->setup != 0 ) || ( $cust_bill_pkg->setup_show_zero )
) {
my $description = $desc;
$description .= ' Setup'
if $cust_bill_pkg->recur != 0
my $description = $desc;
$description .= ' Setup'
if $cust_bill_pkg->recur != 0
@@
-3306,7
+3345,7
@@
sub _items_cust_bill_pkg {
),
};
}
),
};
}
- if (
$cust_bill_pkg->recur != 0
) {
+ if (
( $cust_bill_pkg->recur != 0 ) || ( $cust_bill_pkg->recur_show_zero )
) {
#push @b, {
$r = {
'pkgnum' => $cust_bill_pkg->pkgpart, #so it displays in Ref
#push @b, {
$r = {
'pkgnum' => $cust_bill_pkg->pkgpart, #so it displays in Ref
@@
-3356,6
+3395,7
@@
sub _items_cust_bill_pkg {
# append the word 'Setup' to the setup line if there's going to be
# a recur line for the same package (i.e. not a one-time charge)
# append the word 'Setup' to the setup line if there's going to be
# a recur line for the same package (i.e. not a one-time charge)
+ # XXX localization
my $description = $desc;
$description .= ' Setup'
if $cust_bill_pkg->recur != 0
my $description = $desc;
$description .= ' Setup'
if $cust_bill_pkg->recur != 0
@@
-3376,8
+3416,11
@@
sub _items_cust_bill_pkg {
# always pass the svc_label through to the template, even if
# not displaying it as an ext_description
my @svc_labels = map &{$escape_function}($_),
# always pass the svc_label through to the template, even if
# not displaying it as an ext_description
my @svc_labels = map &{$escape_function}($_),
- $cust_pkg->h_labels_short($self->_date, undef, 'I');
-
+ $cust_pkg->h_labels_short($self->_date,
+ undef,
+ 'I',
+ $self->conf->{locale},
+ );
$svc_label = $svc_labels[0];
unless ( $cust_pkg->part_pkg->hide_svc_detail
$svc_label = $svc_labels[0];
unless ( $cust_pkg->part_pkg->hide_svc_detail
@@
-3467,7
+3510,9
@@
sub _items_cust_bill_pkg {
push @dates, undef if !$prev;
my @svc_labels = map &{$escape_function}($_),
push @dates, undef if !$prev;
my @svc_labels = map &{$escape_function}($_),
- $cust_pkg->h_labels_short(@dates, 'I');
+ $cust_pkg->h_labels_short(@dates,
+ 'I',
+ $self->conf->{locale});
$svc_label = $svc_labels[0];
# show service labels, unless...
$svc_label = $svc_labels[0];
# show service labels, unless...