[freeside-commits] freeside/FS/FS/part_event/Condition cust_payments_pkg.pm, NONE, 1.1 cust_payments.pm, 1.1, 1.2

Ivan,,, ivan at wavetail.420.am
Fri Jul 3 17:47:55 PDT 2009


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

Modified Files:
	cust_payments.pm 
Added Files:
	cust_payments_pkg.pm 
Log Message:
add condition based on total customer payments as a multiplier of a specific package, RT#3983

Index: cust_payments.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_event/Condition/cust_payments.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cust_payments.pm	22 Nov 2008 22:17:28 -0000	1.1
+++ cust_payments.pm	4 Jul 2009 00:47:53 -0000	1.2
@@ -3,7 +3,7 @@
 use strict;
 use base qw( FS::part_event::Condition );
 
-sub description { 'Customer total payments'; }
+sub description { 'Customer total payments (amount)'; }
 
 sub option_fields {
   (

--- NEW FILE: cust_payments_pkg.pm ---
package FS::part_event::Condition::cust_payments_pkg;

use strict;
use base qw( FS::part_event::Condition );

sub description { 'Customer total payments (multiplier of package)'; }

sub eventtable_hashref {
  { 'cust_pkg' => 1 };
}

sub option_fields {
  (
    'over_times' => { 'label'      => 'Customer total payments as least',
                      'type'       => 'text',
                      'value'      => '1', #default
                    },
    'what' => { 'label'   => 'Times',
                'type'    => 'select',
                #also add some way to specify in the package def, no?
                'options' => [ qw( base_recur_permonth ) ],
                'labels'  => { 'base_recur_permonth' => 'Base monthly fee', },
              },
  );
}

sub condition {
  my($self, $cust_pkg) = @_;

  my $cust_main = $self->cust_main($cust_pkg);

  my $part_pkg = $cust_pkg->part_pkg;

  my $over_times = $self->option('over_times');
  $over_times = 0 unless length($over_times);

  my $what = $self->option('what');

  #false laziness w/Condition/cust_payments_pkg.pm
  if ( $what eq 'base_recur_permonth' ) { #huh.  yuck.
    if ( $part_pkg->freq !~ /^\d+$/ ) {
      die 'WARNING: Not crediting customer '. $cust_main->referral_custnum.
          ' for package '. $cust_pkg->pkgnum.
          ' ( customer '. $cust_pkg->custnum. ')'.
          ' - Referral credits not (yet) available for '.
          ' packages with '. $part_pkg->freq_pretty. ' frequency';
    }
  }

  $cust_main->total_paid >= $over_times * $part_pkg->$what($cust_pkg);

}

#XXX add for efficiency.  could use cust_main::total_paid_sql
#use FS::cust_main;
#sub condition_sql {
#  my( $class, $table ) = @_;
#
#  my $over = $class->condition_sql_option('balance');
#
#  my $balance_sql = FS::cust_main->balance_sql;
#
#  "$balance_sql > $over";
#
#}

1;




More information about the freeside-commits mailing list