diff options
author | Ivan Kohler <ivan@freeside.biz> | 2015-01-28 02:26:52 -0800 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2015-01-28 02:26:52 -0800 |
commit | 2e4fa975e054554beac71883436b143267d7aa12 (patch) | |
tree | 246c066d8497d8db3f47a809caddfbd2e67d2264 /FS/FS | |
parent | f4b7701c4c1e574ebe29e05db694d131d2799b35 (diff) | |
parent | e43f8075d053e3f1d969d8f762ab510a2de126de (diff) |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/Conf.pm | 17 | ||||
-rw-r--r-- | FS/FS/Cron/agent_email.pm | 5 | ||||
-rw-r--r-- | FS/FS/Cron/upload.pm | 5 | ||||
-rw-r--r-- | FS/FS/Template_Mixin.pm | 40 | ||||
-rw-r--r-- | FS/FS/Upgrade.pm | 16 | ||||
-rw-r--r-- | FS/FS/cust_bill.pm | 3 | ||||
-rw-r--r-- | FS/FS/cust_credit.pm | 5 | ||||
-rw-r--r-- | FS/FS/cust_main.pm | 5 | ||||
-rw-r--r-- | FS/FS/cust_main/Billing_Realtime.pm | 5 | ||||
-rw-r--r-- | FS/FS/cust_pay.pm | 5 | ||||
-rw-r--r-- | FS/FS/cust_pkg.pm | 5 | ||||
-rw-r--r-- | FS/FS/discount.pm | 7 | ||||
-rw-r--r-- | FS/FS/msg_template.pm | 6 | ||||
-rw-r--r-- | FS/FS/part_export/send_email.pm | 2 | ||||
-rw-r--r-- | FS/FS/pay_batch.pm | 5 | ||||
-rw-r--r-- | FS/FS/quotation.pm | 6 | ||||
-rw-r--r-- | FS/FS/upload_target.pm | 5 |
17 files changed, 117 insertions, 25 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index f9a1696..239e304 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1233,9 +1233,24 @@ sub reason_type_options { { 'key' => 'invoice_from', 'section' => 'required', - 'description' => 'Return address on email invoices', + 'description' => 'Return address on email invoices (address only, see invoice_from_name)', 'type' => 'text', 'per_agent' => 1, + 'validate' => sub { $_[0] =~ + /^[^@]+\@[[:alnum:]-]+(\.[[:alnum:]-]+)+$/ + ? '' : 'Invalid email address'; + } + }, + + { + 'key' => 'invoice_from_name', + 'section' => 'invoicing', + 'description' => 'Return name on email invoices (set address in invoice_from)', + 'type' => 'text', + 'per_agent' => 1, + 'validate' => sub { (($_[0] =~ /[^[:alnum:][:space:]]/) && ($_[0] !~ /^\".*\"$/)) + ? 'Invalid name. Use quotation marks around names that contain punctuation.' + : '' } }, { diff --git a/FS/FS/Cron/agent_email.pm b/FS/FS/Cron/agent_email.pm index 992aa35..623b920 100644 --- a/FS/FS/Cron/agent_email.pm +++ b/FS/FS/Cron/agent_email.pm @@ -29,7 +29,10 @@ sub agent_email { RT::ConnectToDatabase(); } - my $from = $conf->config('invoice_from'); + my $from = $conf->config('invoice_from_name') ? + $conf->config('invoice_from_name') . ' <' . + $conf->config('invoice_from') . '>' : + $conf->config('invoice_from'); my $outbuf = '';; my( $fs_interp, $rt_interp ) = mason_interps('standalone', 'outbuf'=>\$outbuf); diff --git a/FS/FS/Cron/upload.pm b/FS/FS/Cron/upload.pm index 03ed366..fa1762f 100644 --- a/FS/FS/Cron/upload.pm +++ b/FS/FS/Cron/upload.pm @@ -508,7 +508,10 @@ sub prepare_report { ( to => $to, - from => $conf->config('invoice_from', $agentnum), + from => $conf->config('invoice_from_name', $agentnum) ? + $conf->config('invoice_from_name', $agentnum) . ' <' . + $conf->config('invoice_from', $agentnum) . '>' : + $conf->config('invoice_from', $agentnum), subject => $subject, body => $body, ); diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index 1fed7f1..9669ac2 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -347,8 +347,8 @@ sub print_generic { if ( $format eq 'latex' && grep { /^%%Detail/ } @invoice_template ) { #change this to a die when the old code is removed - # it's been almost ten years, changing it to a die on the next release. - warn "old-style invoice template $templatefile; ". + # it's been almost ten years, changing it to a die + die "old-style invoice template $templatefile; ". "patch with conf/invoice_latex.diff or use new conf/invoice_latex*\n"; #$old_latex = 'true'; #@invoice_template = _translate_old_latex_format(@invoice_template); @@ -1172,6 +1172,12 @@ sub print_generic { join(', ', map "$_=>".$line_item->{$_}, keys %$line_item). "\n" if $DEBUG > 1; + push @buf, ( [ $line_item->{'description'}, + $money_char. sprintf("%10.2f", $line_item->{'amount'}), + ], + map { [ " ". $_, '' ] } @{$line_item->{'ext_description'}}, + ); + $line_item->{'ref'} = $line_item->{'pkgnum'}; $line_item->{'product_code'} = $line_item->{'pkgpart'} || 'N/A'; # mt()? $line_item->{'section'} = $section; @@ -1184,11 +1190,6 @@ sub print_generic { $line_item->{'ext_description'} ||= []; push @detail_items, $line_item; - push @buf, ( [ $line_item->{'description'}, - $money_char. sprintf("%10.2f", $line_item->{'amount'}), - ], - map { [ " ". $_, '' ] } @{$line_item->{'ext_description'}}, - ); } if ( $section->{'description'} ) { @@ -3448,8 +3449,29 @@ sub _items_cust_bill_pkg { ext_description => \@ext, }; foreach my $cust_bill_pkg_discount (@discounts) { - my $def = $cust_bill_pkg_discount->cust_pkg_discount->discount; - push @ext, &{$escape_function}( $def->description ); + my $discount = $cust_bill_pkg_discount->cust_pkg_discount->discount; + my $discount_desc = $discount->description_short; + + if ($discount->months) { + + # calculate months remaining after this invoice + my $used = FS::Record->scalar_sql( + 'SELECT SUM(months) FROM cust_bill_pkg_discount + JOIN cust_bill_pkg USING (billpkgnum) + JOIN cust_bill USING (invnum) + WHERE pkgdiscountnum = ? AND _date <= ?', + $cust_bill_pkg_discount->pkgdiscountnum, + $self->_date + ); + $used ||= 0; + my $remaining = sprintf('%.2f', $discount->months - $used); + # append "for X months (Y months remaining)" + $discount_desc .= $self->mt(' for [quant,_1,month] ([quant,_2,month] remaining)', + $cust_bill_pkg_discount->months, + $remaining + ); + } # else it's not time-limited + push @ext, &{$escape_function}($discount_desc); } } diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index 381fd5f..5d092ed 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -46,6 +46,22 @@ sub upgrade_config { my $conf = new FS::Conf; + if ($conf->config('invoice_from') =~ /\<(.*)\>/) { + my $realemail = $1; + $realemail =~ s/^\s*//; # remove leading spaces + $realemail =~ s/\s*$//; # remove trailing spaces + my $realname = $conf->config('invoice_from'); + $realname =~ s/\<.*\>//; # remove email address + $realname =~ s/^\s*//; # remove leading spaces + $realname =~ s/\s*$//; # remove trailing spaces + # properly quote names that contain punctuation + if (($realname =~ /[^[:alnum:][:space:]]/) && ($realname !~ /^\".*\"$/)) { + $realname = '"' . $realname . '"'; + } + $conf->set('invoice_from_name', $realname); + $conf->set('invoice_from', $realemail); + } + $conf->touch('payment_receipt') if $conf->exists('payment_receipt_email') || $conf->config('payment_receipt_msgnum'); diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index bcfbbc7..6ded57f 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -1085,6 +1085,9 @@ sub email { # this is where we set the From: address $from ||= $self->_agent_invoice_from || #XXX should go away + $conf->config('invoice_from_name', $self->cust_main->agentnum ) ? + $conf->config('invoice_from_name', $self->cust_main->agentnum ) . ' <' . + $conf->config('invoice_from', $self->cust_main->agentnum ) . '>' : $conf->config('invoice_from', $self->cust_main->agentnum ); my @invoicing_list = $self->cust_main->invoicing_list_emailonly; diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index df2a6cc..6f4f720 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -282,7 +282,10 @@ sub delete { my $cust_main = $self->cust_main; my $error = send_email( - 'from' => $conf->config('invoice_from', $self->cust_main->agentnum), + 'from' => $conf->config('invoice_from_name', $self->cust_main->agentnum) ? + $conf->config('invoice_from_name', $self->cust_main->agentnum) . ' <' . + $conf->config('invoice_from', $self->cust_main->agentnum) . '>' : + $conf->config('invoice_from', $self->cust_main->agentnum), #invoice_from??? well as good as any 'to' => $conf->config('deletecredits'), 'subject' => 'FREESIDE NOTIFICATION: Credit deleted', diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 30dbc04..1ed1d4a 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -4327,7 +4327,10 @@ sub notify { return unless $conf->exists($template); - my $from = $conf->config('invoice_from', $self->agentnum) + my $from = $conf->config('invoice_from_name', $self->agentnum) ? + $conf->config('invoice_from_name', $self->agentnum) . ' <' . + $conf->config('invoice_from', $self->agentnum) . '>' : + $conf->config('invoice_from', $self->agentnum) if $conf->exists('invoice_from', $self->agentnum); $from = $options{from} if exists($options{from}); diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm index 330a454..f9f3754 100644 --- a/FS/FS/cust_main/Billing_Realtime.pm +++ b/FS/FS/cust_main/Billing_Realtime.pm @@ -1109,7 +1109,10 @@ sub _realtime_bop_result { }; my $error = send_email( - 'from' => $conf->config('invoice_from', $self->agentnum ), + 'from' => $conf->config('invoice_from_name', $self->agentnum ) ? + $conf->config('invoice_from_name', $self->agentnum ) . ' <' . + $conf->config('invoice_from', $self->agentnum ) . '>' : + $conf->config('invoice_from', $self->agentnum ), 'to' => [ grep { $_ ne 'POST' } $self->invoicing_list ], 'subject' => 'Your payment could not be processed', 'body' => [ $template->fill_in(HASH => $templ_hash) ], diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index df567a5..e44278d 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -694,7 +694,10 @@ sub send_receipt { 'msgtype' => 'receipt', }; $error = $queue->insert( - 'from' => $conf->config('invoice_from', $cust_main->agentnum), + 'from' => $conf->config('invoice_from_name', $cust_main->agentnum ) ? + $conf->config('invoice_from_name', $cust_main->agentnum ) . ' <' . + $conf->config('invoice_from', $cust_main->agentnum ) . '>' : + $conf->config('invoice_from', $cust_main->agentnum ), #invoice_from??? well as good as any 'to' => \@invoicing_list, 'subject' => 'Payment receipt', diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 5c82ad2..ccf63db 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -947,7 +947,10 @@ sub cancel { } else { $error = send_email( - 'from' => $conf->config('invoice_from', $self->cust_main->agentnum), + 'from' => $conf->config('invoice_from_name', $self->cust_main->agentnum) ? + $conf->config('invoice_from_name', $self->cust_main->agentnum) . ' <' . + $conf->config('invoice_from', $self->cust_main->agentnum) . '>' : + $conf->config('invoice_from', $self->cust_main->agentnum), 'to' => \@invoicing_list, 'subject' => ( $conf->config('cancelsubject') || 'Cancellation Notice' ), 'body' => [ map "$_\n", $conf->config('cancelmessage') ], diff --git a/FS/FS/discount.pm b/FS/FS/discount.pm index 0561f9c..361e0b4 100644 --- a/FS/FS/discount.pm +++ b/FS/FS/discount.pm @@ -173,7 +173,12 @@ sub description_short { my $conf = new FS::Conf; my $money_char = $conf->config('money_char') || '$'; - my $desc = $self->name ? $self->name.': ' : ''; + my $desc; + if ( $self->name ) { + $desc = $self->name . ': '; + } else { + $desc = 'Discount of '; + } $desc .= $money_char. sprintf('%.2f/month', $self->amount) if $self->amount > 0; diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm index 65890e1..70a8e49 100644 --- a/FS/FS/msg_template.pm +++ b/FS/FS/msg_template.pm @@ -398,8 +398,10 @@ sub prepare { $from_addr = scalar( $conf->config($opt{'from_config'}, $cust_main->agentnum) ); } - $from_addr ||= scalar( $conf->config('invoice_from', - $cust_main->agentnum) ); + $from_addr ||= $conf->config('invoice_from_name', $cust_main->agentnum) ? + $conf->config('invoice_from_name', $cust_main->agentnum) . ' <' . + $conf->config('invoice_from', $cust_main->agentnum) . '>' : + $conf->config('invoice_from', $cust_main->agentnum); } # my @cust_msg = (); # if ( $conf->exists('log_sent_mail') and !$opt{'preview'} ) { diff --git a/FS/FS/part_export/send_email.pm b/FS/FS/part_export/send_email.pm index 537a562..9afc254 100644 --- a/FS/FS/part_export/send_email.pm +++ b/FS/FS/part_export/send_email.pm @@ -80,7 +80,7 @@ tie my %options, 'Tie::IxHash', ( ); %info = ( - 'svc' => [qw( svc_acct svc_broadband svc_phone svc_domain )], + 'svc' => [qw( svc_acct svc_hardware svc_broadband svc_phone svc_domain )], 'desc' => 'Send an email message', 'options' => \%options, diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm index b6b69f3..3079db1 100644 --- a/FS/FS/pay_batch.pm +++ b/FS/FS/pay_batch.pm @@ -749,7 +749,10 @@ sub import_from_gateway { my $body = "Import from gateway ".$gateway->label."\n".$error_text; send_email( to => $mail_on_error, - from => $conf->config('invoice_from'), + from => $conf->config('invoice_from_name') ? + $conf->config('invoice_from_name') . ' <' . + $conf->config('invoice_from') . '>' : + $conf->config('invoice_from'), subject => $subject, body => $body, ); diff --git a/FS/FS/quotation.pm b/FS/FS/quotation.pm index 75a592d..774495a 100644 --- a/FS/FS/quotation.pm +++ b/FS/FS/quotation.pm @@ -183,8 +183,10 @@ sub email { # this is where we set the From: address $from ||= $conf->config('quotation_from', $self->cust_or_prospect->agentnum ) - || $conf->config('invoice_from', $self->cust_or_prospect->agentnum ); - + || ($conf->config('invoice_from_name', $self->cust_or_prospect->agentnum ) ? + $conf->config('invoice_from_name', $self->cust_or_prospect->agentnum ) . ' <' . + $conf->config('invoice_from', $self->cust_or_prospect->agentnum ) . '>' : + $conf->config('invoice_from', $self->cust_or_prospect->agentnum )); $self->SUPER::email( { 'from' => $from, %$opt, diff --git a/FS/FS/upload_target.pm b/FS/FS/upload_target.pm index 33088cb..73d2a04 100644 --- a/FS/FS/upload_target.pm +++ b/FS/FS/upload_target.pm @@ -163,7 +163,10 @@ sub put { # (maybe use only the raw content, so that we don't have to supply a # customer for substitutions? ewww.) my %message = ( - 'from' => $conf->config('invoice_from'), + 'from' => $conf->config('invoice_from_name') ? + $conf->config('invoice_from_name') . ' <' . + $conf->config('invoice_from') . '>' : + $conf->config('invoice_from'), 'to' => $to, 'subject' => $self->subject, 'nobody' => 1, |