[freeside-commits] freeside/FS/FS Schema.pm, 1.198, 1.199 cust_bill.pm, 1.278, 1.279 cust_main.pm, 1.498, 1.499 cust_pkg.pm, 1.158, 1.159 part_pkg.pm, 1.101, 1.102

Ivan,,, ivan at wavetail.420.am
Thu Mar 18 00:59:53 PDT 2010


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

Modified Files:
	Schema.pm cust_bill.pm cust_main.pm cust_pkg.pm part_pkg.pm 
Log Message:
disable auto-billing of specific customer packages, RT#6378

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.198
retrieving revision 1.199
diff -u -w -d -r1.198 -r1.199
--- Schema.pm	12 Mar 2010 03:36:35 -0000	1.198
+++ Schema.pm	18 Mar 2010 07:59:51 -0000	1.199
@@ -1259,6 +1259,7 @@
         'change_pkgpart',      'int', 'NULL', '', '', '',
         'change_locationnum',  'int', 'NULL', '', '', '',
         'manual_flag',        'char', 'NULL',  1, '', '', 
+        'no_auto',            'char', 'NULL',  1, '', '', 
         'quantity',            'int', 'NULL', '', '', '',
       ],
       'primary_key' => 'pkgnum',
@@ -1435,7 +1436,7 @@
         'pay_weight',    'real',    'NULL', '', '', '',
         'credit_weight', 'real',    'NULL', '', '', '',
         'agentnum',      'int',     'NULL', '', '', '', 
-
+        'no_auto',      'char',     'NULL',  1, '', '', 
       ],
       'primary_key' => 'pkgpart',
       'unique' => [],

Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.278
retrieving revision 1.279
diff -u -w -d -r1.278 -r1.279
--- cust_bill.pm	8 Mar 2010 10:57:06 -0000	1.278
+++ cust_bill.pm	18 Mar 2010 07:59:51 -0000	1.279
@@ -356,11 +356,24 @@
 
 sub cust_pkg {
   my $self = shift;
-  my @cust_pkg = map { $_->cust_pkg } $self->cust_bill_pkg;
+  my @cust_pkg = map { $_->pkgnum > 0 ? $_->cust_pkg : () }
+                     $self->cust_bill_pkg;
   my %saw = ();
   grep { ! $saw{$_->pkgnum}++ } @cust_pkg;
 }
 
+=item no_auto
+
+Returns true if any of the packages (or their definitions) corresponding to the
+line items for this invoice have the no_auto flag set.
+
+=cut
+
+sub no_auto {
+  my $self = shift;
+  grep { $_->no_auto || $_->part_pkg->no_auto } $self->cust_pkg;
+}
+
 =item open_cust_bill_pkg
 
 Returns the open line items for this invoice.
@@ -1899,6 +1912,14 @@
   $cust_main->realtime_bop($method, $amount,
     'description' => $description,
     'invnum'      => $self->invnum,
+#this didn't do what we want, it just calls apply_payments_and_credits
+#    'apply'       => 1,
+    'apply_to_invoice' => 1,
+ #what we want:
+ #this changes application behavior: auto payments
+                        #triggered against a specific invoice are now applied
+                        #to that invoice instead of oldest open.
+                        #seem okay to me...
   );
 
 }

Index: part_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg.pm,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -w -d -r1.101 -r1.102
--- part_pkg.pm	30 Jan 2010 07:38:31 -0000	1.101
+++ part_pkg.pm	18 Mar 2010 07:59:51 -0000	1.102
@@ -462,6 +462,7 @@
     || $self->ut_textn('taxclass')
     || $self->ut_enum('disabled', [ '', 'Y' ] )
     || $self->ut_enum('custom', [ '', 'Y' ] )
+    || $self->ut_enum('no_auto', [ '', 'Y' ])
     #|| $self->ut_moneyn('setup_cost')
     #|| $self->ut_moneyn('recur_cost')
     || $self->ut_floatn('setup_cost')
@@ -908,9 +909,11 @@
   map { $_->optionname => $_->optionvalue } $self->part_pkg_option;
 }
 
-=item option OPTIONNAME
+=item option OPTIONNAME [ QUIET ]
 
-Returns the option value for the given name, or the empty string.
+Returns the option value for the given name, or the empty string.  If a true
+value is passed as the second argument, warnings about missing the option
+will be suppressed.
 
 =cut
 

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.498
retrieving revision 1.499
diff -u -w -d -r1.498 -r1.499
--- cust_main.pm	12 Mar 2010 21:29:04 -0000	1.498
+++ cust_main.pm	18 Mar 2010 07:59:51 -0000	1.499
@@ -2696,15 +2696,21 @@
     return $error;
   }
 
-  my @cust_bill_pkg = ();
+  #keep auto-charge and non-auto-charge line items separate
+  my @passes = ( '', 'no_auto' );
+
+  my %cust_bill_pkg = map { $_ => [] } @passes;
 
   ###
   # find the packages which are due for billing, find out how much they are
   # & generate invoice database.
   ###
 
-  my( $total_setup, $total_recur, $postal_charge ) = ( 0, 0, 0 );
-  my %taxlisthash;
+  my %total_setup   = map { my $z = 0; $_ => \$z; } @passes;
+  my %total_recur   = map { my $z = 0; $_ => \$z; } @passes;
+
+  my %taxlisthash = map { $_ => {} } @passes;
+
   my @precommit_hooks = ();
 
   $options{'pkg_list'} ||= [ $self->ncancelled_pkgs ];  #param checks?
@@ -2727,14 +2733,16 @@
 
       $cust_pkg->set($_, $hash{$_}) foreach qw ( setup last_bill bill );
 
+      my $pass = ($cust_pkg->no_auto || $part_pkg->no_auto) ? 'no_auto' : '';
+
       my $error =
         $self->_make_lines( 'part_pkg'            => $part_pkg,
                             'cust_pkg'            => $cust_pkg,
                             'precommit_hooks'     => \@precommit_hooks,
-                            'line_items'          => \@cust_bill_pkg,
-                            'setup'               => \$total_setup,
-                            'recur'               => \$total_recur,
-                            'tax_matrix'          => \%taxlisthash,
+                            'line_items'          => $cust_bill_pkg{$pass},
+                            'setup'               => $total_setup{$pass},
+                            'recur'               => $total_recur{$pass},
+                            'tax_matrix'          => $taxlisthash{$pass},
                             'time'                => $time,
                             'real_pkgpart'        => $real_pkgpart,
                             'options'             => \%options,
@@ -2748,11 +2756,17 @@
 
   } #foreach my $cust_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;
-    return '';
-  }
+  #if the customer isn't on an automatic payby, everything can go on a single
+  #invoice anyway?
+  #if ( $cust_main->payby !~ /^(CARD|CHEK)$/ ) {
+    #merge everything into one list
+  #}
+
+  foreach my $pass (@passes) { # keys %cust_bill_pkg ) {
+
+    my @cust_bill_pkg = @{ $cust_bill_pkg{$pass} };
+
+    next unless @cust_bill_pkg; #don't create an invoice w/o line items
 
   if ( scalar( grep { $_->recur && $_->recur > 0 } @cust_bill_pkg) ||
          !$conf->exists('postal_invoice-recurring_only')
@@ -2777,9 +2791,9 @@
                               'cust_pkg'            => $postal_pkg,
                               'precommit_hooks'     => \@precommit_hooks,
                               'line_items'          => \@cust_bill_pkg,
-                              'setup'               => \$total_setup,
-                              'recur'               => \$total_recur,
-                              'tax_matrix'          => \%taxlisthash,
+                                'setup'               => $total_setup{$pass},
+                                'recur'               => $total_recur{$pass},
+                                'tax_matrix'          => $taxlisthash{$pass},
                               'time'                => $time,
                               'real_pkgpart'        => $real_pkgpart,
                               'options'             => \%postal_options,
@@ -2795,7 +2809,7 @@
   }
 
   my $listref_or_error =
-    $self->calculate_taxes( \@cust_bill_pkg, \%taxlisthash, $invoice_time);
+      $self->calculate_taxes( \@cust_bill_pkg, $taxlisthash{$pass}, $invoice_time);
 
   unless ( ref( $listref_or_error ) ) {
     $dbh->rollback if $oldAutoCommit;
@@ -2803,7 +2817,8 @@
   }
 
   foreach my $taxline ( @$listref_or_error ) {
-    $total_setup = sprintf('%.2f', $total_setup+$taxline->setup );
+      ${ $total_setup{$pass} } =
+        sprintf('%.2f', ${ $total_setup{$pass} } + $taxline->setup );
     push @cust_bill_pkg, $taxline;
   }
 
@@ -2835,7 +2850,7 @@
 
   }
 
-  my $charged = sprintf('%.2f', $total_setup + $total_recur );
+    my $charged = sprintf('%.2f', ${ $total_setup{$pass} } + ${ $total_recur{$pass} } );
 
   my @cust_bill = $self->cust_bill;
   my $balance = $self->balance;
@@ -2872,6 +2887,7 @@
     }
   }
     
+  } #foreach my $pass ( keys %cust_bill_pkg )
 
   foreach my $hook ( @precommit_hooks ) { 
     eval {
@@ -7549,12 +7565,14 @@
   my ( $pkg, $comment, $additional );
   my ( $setuptax, $taxclass );   #internal taxes
   my ( $taxproduct, $override ); #vendor (CCH) taxes
+  my $no_auto = '';
   my $cust_pkg_ref = '';
   my ( $bill_now, $invoice_terms ) = ( 0, '' );
   if ( ref( $_[0] ) ) {
     $amount     = $_[0]->{amount};
     $quantity   = exists($_[0]->{quantity}) ? $_[0]->{quantity} : 1;
     $start_date = exists($_[0]->{start_date}) ? $_[0]->{start_date} : '';
+    $no_auto    = exists($_[0]->{no_auto}) ? $_[0]->{no_auto} : '';
     $pkg        = exists($_[0]->{pkg}) ? $_[0]->{pkg} : 'One-time charge';
     $comment    = exists($_[0]->{comment}) ? $_[0]->{comment}
                                            : '$'. sprintf("%.2f",$amount);
@@ -7632,6 +7650,7 @@
     'pkgpart'    => $pkgpart,
     'quantity'   => $quantity,
     'start_date' => $start_date,
+    'no_auto'    => $no_auto,
   } );
 
   $error = $cust_pkg->insert;

Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.158
retrieving revision 1.159
diff -u -w -d -r1.158 -r1.159
--- cust_pkg.pm	13 Mar 2010 23:50:54 -0000	1.158
+++ cust_pkg.pm	18 Mar 2010 07:59:51 -0000	1.159
@@ -525,6 +525,7 @@
     || $self->ut_numbern('cancel')
     || $self->ut_numbern('adjourn')
     || $self->ut_numbern('expire')
+    || $self->ut_enum('no_auto', [ '', 'Y' ])
   ;
   return $error if $error;
 



More information about the freeside-commits mailing list