[freeside-commits] freeside/FS/FS cust_main.pm, 1.464.2.42, 1.464.2.43 cust_bill.pm, 1.263.2.25, 1.263.2.26

Jeff Finucane,420,, jeff at wavetail.420.am
Wed Aug 18 12:38:38 PDT 2010


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv26752/FS/FS

Modified Files:
      Tag: FREESIDE_1_9_BRANCH
	cust_main.pm cust_bill.pm 
Log Message:
allow sections to work without 'separate_usage,' correct packages hidden behind zero value packages, correct section handling, and fix propogation of other display attributes to child packages

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.464.2.42
retrieving revision 1.464.2.43
diff -u -w -d -r1.464.2.42 -r1.464.2.43
--- cust_main.pm	16 Aug 2010 17:50:58 -0000	1.464.2.42
+++ cust_main.pm	18 Aug 2010 19:38:34 -0000	1.464.2.43
@@ -2749,7 +2749,13 @@
     my $real_pkgpart = $cust_pkg->pkgpart;
     my %hash = $cust_pkg->hash;
 
-    foreach my $part_pkg ( $cust_pkg->part_pkg->self_and_bill_linked ) {
+    # we could implement this bit as FS::part_pkg::has_hidden, but we already
+    # suffer from performance issues
+    $options{has_hidden} = 0;
+    my @part_pkg = $cust_pkg->part_pkg->self_and_bill_linked;
+    $options{has_hidden} = 1 if ($part_pkg[1] && $part_pkg[1]->hidden);
+ 
+    foreach my $part_pkg ( @part_pkg ) {
 
       $cust_pkg->set($_, $hash{$_}) foreach qw ( setup last_bill bill );
 
@@ -2774,6 +2780,8 @@
 
   } #foreach my $cust_pkg
 
+  @cust_bill_pkg = _omit_zero_value_bundles(@cust_bill_pkg);
+
   unless ( @cust_bill_pkg ) { #don't create an invoice w/o line items
     #but do commit any package date cycling that happened
     $dbh->commit or die $dbh->errstr if $oldAutoCommit;
@@ -2795,7 +2803,14 @@
     } elsif ( $postal_pkg ) {
 
       my $real_pkgpart = $postal_pkg->pkgpart;
-      foreach my $part_pkg ( $postal_pkg->part_pkg->self_and_bill_linked ) {
+      # we could implement this bit as FS::part_pkg::has_hidden, but we alre
+ady
+      # suffer from performance issues
+      $options{has_hidden} = 0;
+      my @part_pkg = $postal_pkg->part_pkg->self_and_bill_linked;
+      $options{has_hidden} = 1 if ($part_pkg[1] && $part_pkg[1]->hidden);
+ 
+      foreach my $part_pkg ( @part_pkg ) {
         my %postal_options = %options;
         delete $postal_options{cancel};
         my $error =
@@ -2816,6 +2831,9 @@
         }
       }
 
+      # it's silly to have a zero value postal_pkg, but....
+      @cust_bill_pkg = _omit_zero_value_bundles(@cust_bill_pkg);
+
     }
 
   }
@@ -3037,6 +3055,27 @@
   ''; #no error
 }
 
+#discard bundled packages of 0 value
+sub _omit_zero_value_bundles {
+
+  my @cust_bill_pkg = ();
+  my @cust_bill_pkg_bundle = ();
+  my $sum = 0;
+
+  foreach my $cust_bill_pkg ( @_ ) {
+    if (scalar(@cust_bill_pkg_bundle) && !$cust_bill_pkg->pkgpart_override) {
+      push @cust_bill_pkg, @cust_bill_pkg_bundle if $sum > 0;
+      @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;
+
+  (@cust_bill_pkg);
+
+}
 
 sub _make_lines {
   my ($self, %params) = @_;
@@ -3177,7 +3216,7 @@
   # If $cust_pkg has been modified, update it (if we're a real pkgpart)
   ###
 
-  if ( $lineitems ) {
+  if ( $lineitems || $options{has_hidden} ) {
 
     if ( $cust_pkg->modified && $cust_pkg->pkgpart == $real_pkgpart ) {
       # hmm.. and if just the options are modified in some weird price plan?
@@ -3201,7 +3240,10 @@
       return "negative recur $recur for pkgnum ". $cust_pkg->pkgnum;
     }
 
-    if ( $setup != 0 || $recur != 0 ) {
+    if ( $setup != 0 ||
+         $recur != 0 ||
+         !$part_pkg->hidden && $options{has_hidden} ) #include some $0 lines
+    {
 
       warn "    charges (setup=$setup, recur=$recur); adding line items\n"
         if $DEBUG > 1;
@@ -3358,16 +3400,15 @@
  
   my @display = ();
   my $separate = $conf->exists('separate_usage');
-  my $usage_mandate = $cust_pkg->part_pkg->option('usage_mandate', 'Hush!');
-  if ( $separate || $cust_bill_pkg->hidden || $usage_mandate ) {
-
     my $temp_pkg = new FS::cust_pkg { pkgpart => $real_pkgpart };
-    my %hash = $cust_bill_pkg->hidden  # maybe for all bill linked?
-               ? (  'section' => $temp_pkg->part_pkg->categoryname )
-               : ();
+  my $usage_mandate = $temp_pkg->part_pkg->option('usage_mandate', 'Hush!');
+  my $section = $temp_pkg->part_pkg->categoryname;
+  if ( $separate || $section || $usage_mandate ) {
 
-    my $section = $cust_pkg->part_pkg->option('usage_section', 'Hush!');
-    my $summary = $cust_pkg->part_pkg->option('summarize_usage', 'Hush!');
+    my %hash = ( 'section' => $section );
+
+    $section = $temp_pkg->part_pkg->option('usage_section', 'Hush!');
+    my $summary = $temp_pkg->part_pkg->option('summarize_usage', 'Hush!');
     if ( $separate ) {
       push @display, new FS::cust_bill_pkg_display { type => 'S', %hash };
       push @display, new FS::cust_bill_pkg_display { type => 'R', %hash };
@@ -3389,8 +3430,10 @@
       $hash{post_total} = 'Y';
     }
 
+    if ($separate || $usage_mandate) {
     $hash{section} = $section if ($separate || $usage_mandate);
     push @display, new FS::cust_bill_pkg_display { type => 'U', %hash };
+    }
 
   }
   $cust_bill_pkg->set('display', \@display);
@@ -3442,6 +3485,9 @@
         $taxlisthash->{ $totname } ||= [ $tot ];
         push @{ $taxlisthash->{ $totname  } }, $hashref_or_error->{amount};
 
+        # it's silly to have a zero value postal_pkg, but....
+        @cust_bill_pkg = _omit_zero_value_bundles(@cust_bill_pkg);
+
       }
     }
 

Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.263.2.25
retrieving revision 1.263.2.26
diff -u -w -d -r1.263.2.25 -r1.263.2.26
--- cust_bill.pm	18 Aug 2010 04:42:16 -0000	1.263.2.25
+++ cust_bill.pm	18 Aug 2010 19:38:36 -0000	1.263.2.26
@@ -2611,6 +2611,7 @@
     $options{'skip_usage'} =
       scalar(@$extra_sections) && !grep{$section == $_} @$extra_sections;
     $options{'multilocation'} = $multilocation;
+    $options{'multisection'} = $multisection;
 
     foreach my $line_item ( $self->_items_pkg(%options) ) {
       my $detail = {
@@ -3946,6 +3947,7 @@
   my $section = $opt{section}->{description} if $opt{section};
   my $summary_page = $opt{summary_page} || '';
   my $multilocation = $opt{multilocation} || '';
+  my $multisection = $opt{multisection} || '';
 
   my @b = ();
   my ($s, $r, $u) = ( undef, undef, undef );
@@ -3967,7 +3969,8 @@
                                  ? $_->section eq $section
                                  : 1
                                }
-                          grep { !$_->summary || !$summary_page }
+                          #grep { !$_->summary || !$summary_page } # bunk!
+                          grep { !$_->summary || $multisection }
                           $cust_bill_pkg->cust_bill_pkg_display
                         )
     {
@@ -4026,7 +4029,7 @@
 
         }
 
-        if ( $cust_bill_pkg->recur != 0 &&
+        if ( ( $cust_bill_pkg->recur != 0  || $cust_bill_pkg->setup == 0 ) &&
              ( !$type || $type eq 'R' || $type eq 'U' )
            )
         {
@@ -4096,7 +4099,7 @@
               };
             }
 
-          } elsif ( $amount ) {  # && $type eq 'U'
+          } else {  # $type eq 'U'
 
             if ( $cust_bill_pkg->hidden ) {
               $u->{amount}      += $amount;



More information about the freeside-commits mailing list