add package def option to show $0 recurring on invoices, RT#9777
authorivan <ivan>
Fri, 10 Jun 2011 03:33:44 +0000 (03:33 +0000)
committerivan <ivan>
Fri, 10 Jun 2011 03:33:44 +0000 (03:33 +0000)
FS/FS/Schema.pm
FS/FS/cust_bill.pm
FS/FS/cust_bill_pkg.pm
FS/FS/cust_main/Billing.pm
FS/FS/part_pkg.pm
httemplate/browse/part_pkg.cgi
httemplate/edit/part_pkg.cgi
httemplate/elements/checkbox.html
httemplate/elements/input-text.html
httemplate/elements/tr-select-agent.html

index ab4752f..25912a2 100644 (file)
@@ -1626,7 +1626,8 @@ sub tables_hashref {
         'credit_weight', 'real',    'NULL', '', '', '',
         'agentnum',      'int',     'NULL', '', '', '', 
         'fcc_ds0s',      'int',     'NULL', '', '', '', 
-        'no_auto',      'char',     'NULL',  1, '', '', 
+        'no_auto',          'char', 'NULL',  1, '', '', 
+        'recur_show_zero',  'char', 'NULL',  1, '', '',
       ],
       'primary_key' => 'pkgpart',
       'unique' => [],
index fd3b638..7106d1f 100644 (file)
@@ -4575,23 +4575,10 @@ sub _items_cust_bill_pkg {
   foreach my $cust_bill_pkg ( @$cust_bill_pkgs )
   {
 
-    warn "$me _items_cust_bill_pkg considering cust_bill_pkg $cust_bill_pkg\n"
+    warn "$me _items_cust_bill_pkg considering cust_bill_pkg ".
+         $cust_bill_pkg->billpkgnum. ", pkgnum ". $cust_bill_pkg->pkgnum. "\n"
       if $DEBUG > 1;
 
-    $discount_show_always = ($cust_bill_pkg->cust_bill_pkg_discount
-                               && $conf->exists('discount-show-always'));
-
-    foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) {
-      if ( $_ && !$cust_bill_pkg->hidden ) {
-        $_->{amount}      = sprintf( "%.2f", $_->{amount} ),
-        $_->{amount}      =~ s/^\-0\.00$/0.00/;
-        $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ),
-        push @b, { %$_ }
-          unless ( $_->{amount} == 0 && !$discount_show_always );
-        $_ = undef;
-      }
-    }
-
     foreach my $display ( grep { defined($section)
                                  ? $_->section eq $section
                                  : 1
@@ -4670,9 +4657,13 @@ sub _items_cust_bill_pkg {
 
         }
 
-        if ( ( $cust_bill_pkg->recur != 0  || $cust_bill_pkg->setup == 0 || 
-               ($discount_show_always && $cust_bill_pkg->recur == 0) ) &&
-             ( !$type || $type eq 'R' || $type eq 'U' )
+        if (    ( !$type || $type eq 'R' || $type eq 'U' )
+             && (
+                     $cust_bill_pkg->recur != 0
+                  || $cust_bill_pkg->setup == 0
+                  || $discount_show_always
+                  || $cust_bill_pkg->recur_show_zero
+                )
            )
         {
 
@@ -4817,21 +4808,38 @@ sub _items_cust_bill_pkg {
 
     }
 
+    $discount_show_always = ($cust_bill_pkg->cust_bill_pkg_discount
+                                && $conf->exists('discount-show-always'));
+
+    foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) {
+      if ( $_ && !$cust_bill_pkg->hidden ) {
+        $_->{amount}      = sprintf( "%.2f", $_->{amount} ),
+        $_->{amount}      =~ s/^\-0\.00$/0.00/;
+        $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ),
+        push @b, { %$_ }
+          if $_->{amount} != 0
+          || $discount_show_always
+          || $cust_bill_pkg->recur_show_zero;
+        $_ = undef;
+      }
+    }
+
   }
 
+  #foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) {
+  #  if ( $_  ) {
+  #    $_->{amount}      = sprintf( "%.2f", $_->{amount} ),
+  #    $_->{amount}      =~ s/^\-0\.00$/0.00/;
+  #    $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ),
+  #    push @b, { %$_ }
+  #      if $_->{amount} != 0
+  #      || $discount_show_always
+  #  }
+  #}
+
   warn "$me _items_cust_bill_pkg done considering cust_bill_pkgs\n"
     if $DEBUG > 1;
 
-  foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) {
-    if ( $_  ) {
-      $_->{amount}      = sprintf( "%.2f", $_->{amount} ),
-      $_->{amount}      =~ s/^\-0\.00$/0.00/;
-      $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ),
-      push @b, { %$_ }
-        unless ( $_->{amount} == 0 && !$discount_show_always );
-    }
-  }
-
   @b;
 
 }
index 37c4a27..2c79209 100644 (file)
@@ -413,7 +413,8 @@ sub previous_cust_bill_pkg {
 
 Returns an array of detail information for the invoice line item.
 
-Currently available options are: I<format> I<escape_function>
+Currently available options are: I<format>, I<escape_function> and
+I<format_function>.
 
 If I<format> is set to html or latex then the array members are improved
 for tabular appearance in those environments if possible.
@@ -421,6 +422,12 @@ for tabular appearance in those environments if possible.
 If I<escape_function> is set then the array members are processed by this
 function before being returned.
 
+I<format_function> overrides the normal HTML or LaTeX function for returning
+formatted CDRs.  It can be set to a subroutine which returns an empty list
+to skip usage detail:
+
+  'format_function' => sub { () },
+
 =cut
 
 sub details {
@@ -872,7 +879,7 @@ sub cust_bill_pkg_detail {
   my %hash = ( 'billpkgnum' => $self->billpkgnum );
   $hash{classnum} = $classnum if $classnum;
 
-  qsearch ( 'cust_bill_pkg_detail', { %hash  } ),
+  qsearch( 'cust_bill_pkg_detail', \%hash ),
 
 }
 
@@ -883,8 +890,21 @@ Returns the list of associated cust_bill_pkg_discount objects.
 =cut
 
 sub cust_bill_pkg_discount {
-    my $self = shift;
-    qsearch ( 'cust_bill_pkg_discount', { 'billpkgnum' => $self->billpkgnum } );
+  my $self = shift;
+  qsearch( 'cust_bill_pkg_discount', { 'billpkgnum' => $self->billpkgnum } );
+}
+
+=item recur_show_zero
+
+=cut
+
+sub recur_show_zero {
+  my $self = shift;
+
+     $self->recur == 0
+  && $self->pkgnum
+  && $self->cust_pkg->part_pkg->recur_show_zero;
+
 }
 
 =back
index f6a6080..d565a32 100644 (file)
@@ -603,27 +603,47 @@ sub bill {
 
 #discard bundled packages of 0 value
 sub _omit_zero_value_bundles {
+  my @in = @_;
 
   my @cust_bill_pkg = ();
   my @cust_bill_pkg_bundle = ();
   my $sum = 0;
   my $discount_show_always = 0;
 
-  foreach my $cust_bill_pkg ( @_ ) {
+  foreach my $cust_bill_pkg ( @in ) {
+
     $discount_show_always = ($cust_bill_pkg->get('discounts')
                                && scalar(@{$cust_bill_pkg->get('discounts')})
                                && $conf->exists('discount-show-always'));
+
+    warn "  pkgnum ". $cust_bill_pkg->pkgnum.
+         " sum $sum, recur_show_zero ". $cust_bill_pkg->recur_show_zero. "\n"
+      if $DEBUG > 0;
+
     if (scalar(@cust_bill_pkg_bundle) && !$cust_bill_pkg->pkgpart_override) {
       push @cust_bill_pkg, @cust_bill_pkg_bundle 
-                       if ($sum > 0 || ($sum == 0 && $discount_show_always));
+        if $sum > 0
+        || ($sum == 0 && (    $discount_show_always
+                           || grep $_->recur_show_zero, @cust_bill_pkg_bundle )
+           );
       @cust_bill_pkg_bundle = ();
       $sum = 0;
     }
+
     $sum += $cust_bill_pkg->setup + $cust_bill_pkg->recur;
     push @cust_bill_pkg_bundle, $cust_bill_pkg;
+
   }
+
   push @cust_bill_pkg, @cust_bill_pkg_bundle
-                       if ($sum > 0 || ($sum == 0 && $discount_show_always));
+    if $sum > 0
+    || ($sum == 0 && (    $discount_show_always
+                       || grep $_->recur_show_zero, @cust_bill_pkg_bundle )
+       );
+
+  warn "  _omit_zero_value_bundles: ". scalar(@in).
+       '->'. scalar(@cust_bill_pkg). "\n" #. Dumper(@cust_bill_pkg). "\n"
+    if $DEBUG > 2;
 
   (@cust_bill_pkg);
 
@@ -1024,10 +1044,12 @@ sub _make_lines {
     my $discount_show_always = ($recur == 0 && scalar(@discounts) 
                                && $conf->exists('discount-show-always'));
 
-    if ( $setup != 0 ||
-         $recur != 0 ||
-         (!$part_pkg->hidden && $options{has_hidden}) || #include some $0 lines
-        $discount_show_always ) 
+    if (    $setup != 0
+         || $recur != 0
+         || (!$part_pkg->hidden && $options{has_hidden}) #include some $0 lines
+         || $discount_show_always
+         || ($recur == 0 && $part_pkg->recur_show_zero)
+       ) 
     {
 
       warn "    charges (setup=$setup, recur=$recur); adding line items\n"
index 17af4d7..2859700 100644 (file)
@@ -553,6 +553,7 @@ sub check {
     || $self->ut_enum('disabled', [ '', 'Y' ] )
     || $self->ut_enum('custom', [ '', 'Y' ] )
     || $self->ut_enum('no_auto', [ '', 'Y' ])
+    || $self->ut_enum('recur_show_zero', [ '', 'Y' ])
     #|| $self->ut_moneyn('setup_cost')
     #|| $self->ut_moneyn('recur_cost')
     || $self->ut_floatn('setup_cost')
index dd20f8d..ae869dd 100755 (executable)
@@ -226,7 +226,7 @@ push @fields, sub {
     ],
     [
       { data=>( $is_recur
-                  ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
+                  ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee'))
                   : $part_pkg->freq_pretty
               ),
         align=> ( $is_recur ? 'right' : 'center' ),
@@ -239,6 +239,14 @@ push @fields, sub {
         : ()
       ),
     ],
+    [ { data    =>
+          ( $part_pkg->option('recur_fee') == 0 && $part_pkg->recur_show_zero )
+            ? ' (printed on invoices)'
+            : '',
+        align   => 'center', #?
+        colspan => 2,
+      },
+    ],
     ( map { 
             my $dst_pkg = $_->dst_pkg;
             [ 
index be8b0f6..93a3b24 100755 (executable)
@@ -45,6 +45,7 @@
                             'agentnum'         => 'Agent',
                             'setup_fee'        => 'Setup fee',
                             'recur_fee'        => 'Recurring fee',
+                            'recur_show_zero'  => 'Show zero recurring',
                             'discountnum'      => 'Offer discounts for longer terms',
                             'bill_dst_pkgpart' => 'Include line item(s) from package',
                             'svc_dst_pkgpart'  => 'Include services of package',
                               { field    => 'recur_fee',
                                 type     => 'money',
                                 disabled => sub { $recur_disabled },
+                                onchange => 'recur_changed',
                               },
-                                
+
+                              { field    => 'recur_show_zero',
+                                type     => 'checkbox',
+                                value    => 'Y',
+                                disabled => sub { $recur_show_zero_disabled },
+                              },
+
                               #price plan
                               #setup fee
                               #recurring frequency
@@ -324,6 +332,7 @@ my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
 
 my %options = ();
 my $recur_disabled = 1;
+my $recur_show_zero_disabled = 1;
 
 my $pkgpart = '';
 
@@ -335,6 +344,10 @@ my $error_callback = sub {
   $opt->{action} = 'Custom' if $cgi->param('pkgnum');
 
   $recur_disabled = $cgi->param('freq') ? 0 : 1;
+  $recur_show_zero_disabled =
+    $cgi->param('freq')
+      ? $cgi->param('recur_fee') ? 0 : 1
+      : 1;
 
   foreach ($cgi->param) {
     /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
@@ -512,16 +525,34 @@ my $javascript = <<'END';
       if ( freq == '0' ) {
         what.form.recur_fee.disabled = true;
         what.form.recur_fee.style.backgroundColor = '#dddddd';
+        what.form.recur_show_zero.disabled = true;
+        //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
       } else {
         what.form.recur_fee.disabled = false;
         what.form.recur_fee.style.backgroundColor = '#ffffff';
+        what.form.recur_show_zero.disabled = false;
+        //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
       }
 
     }
 
+    function recur_changed(what) {
+      var recur = what.value;
+      if ( recur == 0 ) {
+        what.form.recur_show_zero.disabled = false;
+      } else {
+        what.form.recur_show_zero.disabled = true;
+      }
+    }
+
     function agent_changed(what) {
 
-      var agentnum = what.options[what.selectedIndex].value;
+      var agentnum;
+      if ( what.type == 'select-one' ) {
+        agentnum = what.options[what.selectedIndex].value;
+      } else {
+        agentnum = what.value;
+      }
 
       if ( agentnum == 0 ) {
         what.form.agent_type.disabled = false;
index 5176070..91efe85 100644 (file)
@@ -6,6 +6,7 @@
                                 ? ' CHECKED'
                                 : ''
                            %>
+                           <% $opt{disabled} %>
                            <% $onchange %>
                     ><% $opt{'postfix'} %>
 <%init>
@@ -16,4 +17,9 @@ my $onchange = $opt{'onchange'}
                  ? 'onChange="'. $opt{'onchange'}. '(this)"'
                  : '';
 
+$opt{'disabled'} = &{ $opt{'disabled'} }( \%opt )
+  if ref($opt{'disabled'}) eq 'CODE';
+$opt{'disabled'} = 'DISABLED'
+  if $opt{'disabled'} && $opt{'disabled'} !~ /disabled/i; # uuh... yeah?
+
 </%init>
index fb50a50..8279415 100644 (file)
@@ -15,7 +15,9 @@ my %opt = @_;
 my $value = length($opt{curr_value}) ? $opt{curr_value} : $opt{value};
 
 my $onchange = $opt{'onchange'}
-                 ? 'onChange="'. $opt{'onchange'}. '(this)"'
+                 ? join(' ', map $_.'="'. $opt{'onchange'}. '(this)"',
+                                 qw( onChange onKeyDown onKeyUp onKeyPress )
+                       )
                  : '';
 
 my $size = $opt{'size'}
index 0985d1a..ce03c40 100644 (file)
@@ -24,7 +24,11 @@ Example:
 </%doc>
 % if ( scalar(@agents) == 1 ) { 
 
-  <INPUT TYPE="hidden" NAME="<% $opt{'field'} || 'agentnum' %>" VALUE="<% $agents[0]->agentnum %>">
+  <INPUT TYPE  = "hidden"
+         NAME  = "<% $opt{'field'} || 'agentnum' %>"
+         ID    = "<% $opt{'field'} || 'agentnum' %>"
+         VALUE = "<% $agents[0]->agentnum %>"
+  >
 
 %# YUCK.  empty row so we don't throw g_row in edit.html off :/
   <TR>