optionally generate line items which are fully discounted, RT10481
authorlevinse <levinse>
Thu, 13 Jan 2011 16:35:16 +0000 (16:35 +0000)
committerlevinse <levinse>
Thu, 13 Jan 2011 16:35:16 +0000 (16:35 +0000)
FS/FS/Conf.pm
FS/FS/cust_bill.pm
FS/FS/cust_bill_pkg.pm
FS/FS/cust_main/Billing.pm

index e3fc7e3..ea9a536 100644 (file)
@@ -653,6 +653,13 @@ my %payment_gateway_options = (
     'description' => 'IP address to assign to new virtual hosts',
     'type'        => 'text',
   },
+  
+  {
+    'key'         => 'discount-show-always',
+    'section'     => 'billing',
+    'description' => 'Generate a line item on an invoice even when a package is discounted 100%',
+    'type'        => 'checkbox',
+  },
 
   {
     'key'         => 'encryption',
index 7727c99..b54a1d1 100644 (file)
@@ -4125,19 +4125,23 @@ sub _items_cust_bill_pkg {
   my $summary_page = $opt{summary_page} || '';
   my $multilocation = $opt{multilocation} || '';
   my $multisection = $opt{multisection} || '';
+  my $discount_show_always = 0;
 
   my @b = ();
   my ($s, $r, $u) = ( undef, undef, undef );
   foreach my $cust_bill_pkg ( @$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, { %$_ }
-          unless $_->{amount} == 0;
+          unless ( $_->{amount} == 0 && !$discount_show_always );
         $_ = undef;
       }
     }
@@ -4211,7 +4215,8 @@ sub _items_cust_bill_pkg {
 
         }
 
-        if ( ( $cust_bill_pkg->recur != 0  || $cust_bill_pkg->setup == 0 ) &&
+        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' )
            )
         {
@@ -4336,7 +4341,7 @@ sub _items_cust_bill_pkg {
       $_->{amount}      =~ s/^\-0\.00$/0.00/;
       $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ),
       push @b, { %$_ }
-        unless $_->{amount} == 0;
+           unless ( $_->{amount} == 0 && !$discount_show_always );
     }
   }
 
index d396f82..aa6c90b 100644 (file)
@@ -874,6 +874,17 @@ sub cust_bill_pkg_detail {
 
 }
 
+=item cust_bill_pkg_discount 
+
+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 } );
+}
+
 =back
 
 =head1 BUGS
index 9fa1e41..7ae3d45 100644 (file)
@@ -584,17 +584,23 @@ sub _omit_zero_value_bundles {
   my @cust_bill_pkg = ();
   my @cust_bill_pkg_bundle = ();
   my $sum = 0;
+  my $discount_show_always = 0;
 
   foreach my $cust_bill_pkg ( @_ ) {
+    $discount_show_always = ($cust_bill_pkg->get('discounts')
+                               && scalar(@{$cust_bill_pkg->get('discounts')})
+                               && $conf->exists('discount-show-always'));
     if (scalar(@cust_bill_pkg_bundle) && !$cust_bill_pkg->pkgpart_override) {
-      push @cust_bill_pkg, @cust_bill_pkg_bundle if $sum > 0;
+      push @cust_bill_pkg, @cust_bill_pkg_bundle 
+                       if ($sum > 0 || ($sum == 0 && $discount_show_always));
       @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;
+  push @cust_bill_pkg, @cust_bill_pkg_bundle
+                       if ($sum > 0 || ($sum == 0 && $discount_show_always));
 
   (@cust_bill_pkg);
 
@@ -956,9 +962,13 @@ sub _make_lines {
       return "negative recur $recur for pkgnum ". $cust_pkg->pkgnum;
     }
 
+    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
+         (!$part_pkg->hidden && $options{has_hidden}) || #include some $0 lines
+        $discount_show_always ) 
     {
 
       warn "    charges (setup=$setup, recur=$recur); adding line items\n"
@@ -1004,9 +1014,11 @@ sub _make_lines {
       # handle taxes
       ###
 
-      my $error = 
-        $self->_handle_taxes($part_pkg, $taxlisthash, $cust_bill_pkg, $cust_pkg, $options{invoice_time}, $real_pkgpart, \%options);
-      return $error if $error;
+      unless ( $discount_show_always ) {
+         my $error = 
+           $self->_handle_taxes($part_pkg, $taxlisthash, $cust_bill_pkg, $cust_pkg, $options{invoice_time}, $real_pkgpart, \%options);
+         return $error if $error;
+      }
 
       push @$cust_bill_pkgs, $cust_bill_pkg;