[freeside-commits] freeside/FS/FS/part_event/Action fee.pm, 1.7.2.1, 1.7.2.2 cust_bill_fee_percent.pm, 1.7.2.1, 1.7.2.2

Ivan,,, ivan at wavetail.420.am
Sun Dec 20 13:48:57 PST 2009


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

Modified Files:
      Tag: FREESIDE_1_9_BRANCH
	fee.pm cust_bill_fee_percent.pm 
Log Message:
late fee package class specified in the event action instead of a global finance_pkgclass config, RT#6617

Index: fee.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_event/Action/fee.pm,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -u -d -r1.7.2.1 -r1.7.2.2
--- fee.pm	12 Oct 2009 06:43:50 -0000	1.7.2.1
+++ fee.pm	20 Dec 2009 21:48:55 -0000	1.7.2.2
@@ -10,17 +10,24 @@
 sub option_fields {
   ( 
     'charge'   => { label=>'Amount', type=>'money', }, # size=>7, },
-    'reason'   => 'Reason',
+    'reason'   => 'Reason (invoice line item)',
+    'classnum' => { label=>'Package class' => type=>'select-pkg_class', },
     'taxclass' => { label=>'Tax class', type=>'select-taxclass', },
-    'nextbill' => { label=>'Hold late fee until next invoice',
-                    type=>'checkbox', value=>'Y' },
     'setuptax' => { label=>'Late fee is tax exempt',
                     type=>'checkbox', value=>'Y' },
+    'nextbill' => { label=>'Hold late fee until next invoice',
+                    type=>'checkbox', value=>'Y' },
   );
 }
 
 sub default_weight { 10; }
 
+sub _calc_fee {
+  #my( $self, $cust_object ) = @_;
+  my $self = shift;
+  $self->option('charge');
+}
+
 sub do_action {
   my( $self, $cust_object ) = @_;
 
@@ -29,14 +36,16 @@
   my $conf = new FS::Conf;
 
   my %charge = (
-    'amount'   => $self->option('charge'),
+    'amount'   => $self->_calc_fee($cust_object),
     'pkg'      => $self->option('reason'),
     'taxclass' => $self->option('taxclass'),
-    'classnum' => scalar($conf->config('finance_pkgclass')),
+    'classnum' => ( $self->option('classnum')
+                      || scalar($conf->config('finance_pkgclass')) ),
     'setuptax' => $self->option('setuptax'),
   );
 
-  $charge{'start_date'} = $cust_main->next_bill_date #unless its more than N months away?
+  #unless its more than N months away?
+  $charge{'start_date'} = $cust_main->next_bill_date
     if $self->option('nextbill');
 
   my $error = $cust_main->charge( \%charge );

Index: cust_bill_fee_percent.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_event/Action/cust_bill_fee_percent.pm,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -u -d -r1.7.2.1 -r1.7.2.2
--- cust_bill_fee_percent.pm	12 Oct 2009 06:43:49 -0000	1.7.2.1
+++ cust_bill_fee_percent.pm	20 Dec 2009 21:48:55 -0000	1.7.2.2
@@ -1,7 +1,8 @@
 package FS::part_event::Action::cust_bill_fee_percent;
 
 use strict;
-use base qw( FS::part_event::Action );
+use base qw( FS::part_event::Action::fee );
+use Tie::IxHash;
 
 sub description { 'Late fee (percentage of invoice)'; }
 
@@ -9,49 +10,19 @@
   { 'cust_bill' => 1 };
 }
 
-sub event_stage { 'pre-bill'; }
-
 sub option_fields {
-  ( 
-    'percent'  => { label=>'Percent', size=>2, },
-    'reason'   => 'Reason',
-    'taxclass' => { label=>'Tax class', type=>'select-taxclass', },
-    'nextbill' => { label=>'Hold late fee until next invoice',
-                    type=>'checkbox', value=>'Y' },
-    'setuptax' => { label=>'Late fee is tax exempt',
-                    type=>'checkbox', value=>'Y' },
-  );
-}
-
-sub default_weight { 10; }
-
-sub do_action {
-  my( $self, $cust_bill ) = @_;
-
-  #my $cust_main = $self->cust_main($cust_bill);
-  my $cust_main = $cust_bill->cust_main;
-
-  my $conf = new FS::Conf;
-
-  my $amount =
-    sprintf('%.2f', $cust_bill->owed * $self->option('percent') / 100 );
-
-  my %charge = (
-    'amount'   => $amount,
-    'pkg'      => $self->option('reason'),
-    'taxclass' => $self->option('taxclass'),
-    'classnum' => scalar($conf->config('finance_pkgclass')),
-    'setuptax' => $self->option('setuptax'),
-  );
-
-  $charge{'start_date'} = $cust_main->next_bill_date #unless its more than N months away?
-    if $self->option('nextbill');
+  my $class = shift;
 
-  my $error = $cust_main->charge( \%charge );
+  my $t = tie my %option_fields, 'Tie::IxHash', $class->SUPER::option_fields();
+  $t->Shift; #assumes charge is first
+  $t->Unshift( 'percent'  => { label=>'Percent', size=>2, } );
 
-  die $error if $error;
+  %option_fields;
+}
 
-  '';
+sub _calc_fee {
+  my( $self, $cust_bill ) = @_;
+  sprintf('%.2f', $cust_bill->owed * $self->option('percent') / 100 );
 }
 
 1;



More information about the freeside-commits mailing list