From: Ivan Kohler Date: Fri, 27 Dec 2013 07:35:38 +0000 (-0800) Subject: for prepaid, display the time period triggered by a 0 recurring with freq in the... X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=484f64be9482f5ab1a7a76778b1c406a68b8929e for prepaid, display the time period triggered by a 0 recurring with freq in the setup line item, RT#26274 --- diff --git a/FS/FS/TemplateItem_Mixin.pm b/FS/FS/TemplateItem_Mixin.pm index 8b0e16a2d..7df75d450 100644 --- a/FS/FS/TemplateItem_Mixin.pm +++ b/FS/FS/TemplateItem_Mixin.pm @@ -1,15 +1,21 @@ package FS::TemplateItem_Mixin; use strict; -use vars qw( $DEBUG $me ); # but NOT $conf +use vars qw( $DEBUG $me $conf $date_format ); use Carp; +use Date::Format; use FS::UID; use FS::Record qw( qsearch qsearchs dbh ); +use FS::Conf; use FS::part_pkg; use FS::cust_pkg; $DEBUG = 0; $me = '[FS::TemplateItem_Mixin]'; +FS::UID->install_callback( sub { + $conf = new FS::Conf; + $date_format = $conf->config('date_format') || '%x'; #/YY +} ); =item cust_pkg @@ -63,6 +69,51 @@ sub desc { } } +=item time_period_pretty PART_PKG, AGENTNUM + +Returns a formatted time period for this line item. + +=cut + +sub time_period_pretty { + my( $self, $part_pkg, $agentnum ) = @_; + + #more efficient to look some of this conf stuff up outside the + # invoice/template display loop we're called from + # (Template_Mixin::_invoice_cust_bill_pkg) and pass them in as options + + return '' if $conf->exists('disable_line_item_date_ranges') + || $part_pkg->option('disable_line_item_date_ranges',1) + || ! $self->sdate + || ! $self->edate; + + my $date_style = ''; + $date_style = $conf->config( 'cust_bill-line_item-date_style-non_monhtly', + $agentnum + ) + if $part_pkg && $part_pkg->freq !~ /^1m?$/; + $date_style ||= $conf->config( 'cust_bill-line_item-date_style', + $agentnum + ); + + my $time_period; + if ( defined($date_style) && $date_style eq 'month_of' ) { + $time_period = time2str('The month of %B', $self->sdate); + } elsif ( defined($date_style) && $date_style eq 'X_month' ) { + my $desc = $conf->config( 'cust_bill-line_item-date_description', + $agentnum + ); + $desc .= ' ' unless $desc =~ /\s$/; + $time_period = $desc. time2str('%B', $self->sdate); + } else { + $time_period = time2str($date_format, $self->sdate). + " - ". time2str($date_format, $self->edate); + } + + " ($time_period)"; + +} + =item details [ OPTION => VALUE ... ] Returns an array of detail information for the invoice line item. diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index 2314c02c1..2d9be618f 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -15,6 +15,7 @@ use Locale::Country; use Cwd; use FS::UID; use FS::Record qw( qsearch qsearchs ); +use FS::Conf; use FS::Misc qw( generate_ps generate_pdf ); use FS::pkg_category; use FS::pkg_class; @@ -2485,6 +2486,7 @@ sub _items_cust_bill_pkg { if $DEBUG > 1; my $cust_pkg = $cust_bill_pkg->cust_pkg; + my $part_pkg = $cust_pkg->part_pkg; # which pkgpart to show for display purposes? my $pkgpart = $cust_bill_pkg->pkgpart_override || $cust_pkg->pkgpart; @@ -2493,7 +2495,7 @@ sub _items_cust_bill_pkg { # things with them my %item_dates = (); %item_dates = map { $_ => $cust_bill_pkg->$_ } ('sdate', 'edate') - unless $cust_pkg->part_pkg->option('disable_line_item_date_ranges',1); + unless $part_pkg->option('disable_line_item_date_ranges',1); if ( (!$type || $type eq 'S') && ( $cust_bill_pkg->setup != 0 @@ -2511,6 +2513,14 @@ sub _items_cust_bill_pkg { || $discount_show_always || $cust_bill_pkg->recur_show_zero; + $description .= $cust_bill_pkg->time_period_pretty( $part_pkg, + $self->agentnum ) + if $part_pkg->is_prepaid #for prepaid, "display the validity period + # triggered by the recurring charge freq + # (RT#26274) + && $cust_bill_pkg->recur == 0 + && ! $cust_bill_pkg->recur_show_zero; + my @d = (); my $svc_label; unless ( $cust_pkg->part_pkg->hide_svc_detail @@ -2581,37 +2591,8 @@ sub _items_cust_bill_pkg { my $part_pkg = $cust_pkg->part_pkg; - #pry be a bit more efficient to look some of this conf stuff up - # outside the loop - unless ( - $conf->exists('disable_line_item_date_ranges') - || $part_pkg->option('disable_line_item_date_ranges',1) - || ! $cust_bill_pkg->sdate - || ! $cust_bill_pkg->edate - ) { - my $time_period; - my $date_style = ''; - $date_style = $conf->config( 'cust_bill-line_item-date_style-non_monhtly', - $self->agentnum - ) - if $part_pkg && $part_pkg->freq !~ /^1m?$/; - $date_style ||= $conf->config( 'cust_bill-line_item-date_style', - $self->agentnum - ); - if ( defined($date_style) && $date_style eq 'month_of' ) { - $time_period = time2str('The month of %B', $cust_bill_pkg->sdate); - } elsif ( defined($date_style) && $date_style eq 'X_month' ) { - my $desc = $conf->config( 'cust_bill-line_item-date_description', - $self->agentnum - ); - $desc .= ' ' unless $desc =~ /\s$/; - $time_period = $desc. time2str('%B', $cust_bill_pkg->sdate); - } else { - $time_period = time2str($date_format, $cust_bill_pkg->sdate). - " - ". time2str($date_format, $cust_bill_pkg->edate); - } - $description .= " ($time_period)"; - } + $description .= $cust_bill_pkg->time_period_pretty( $part_pkg, + $self->agentnum ); my @d = (); my @seconds = (); # for display of usage info