This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / FS / FS / part_event / Condition / cust_payments_pkg.pm
1 package FS::part_event::Condition::cust_payments_pkg;
2
3 use strict;
4 use base qw( FS::part_event::Condition );
5
6 sub description { 'Customer total payments (multiplier of package)'; }
7
8 sub eventtable_hashref {
9   { 'cust_pkg' => 1 };
10 }
11
12 sub option_fields {
13   (
14     'over_times' => { 'label'      => 'Customer total payments as least',
15                       'type'       => 'text',
16                       'value'      => '1', #default
17                     },
18     'what' => { 'label'   => 'Times',
19                 'type'    => 'select',
20                 #also add some way to specify in the package def, no?
21                 'options' => [ qw( base_recur_permonth ) ],
22                 'labels'  => { 'base_recur_permonth' => 'Base monthly fee', },
23               },
24   );
25 }
26
27 sub condition {
28   my($self, $cust_pkg) = @_;
29
30   my $cust_main = $self->cust_main($cust_pkg);
31
32   my $part_pkg = $cust_pkg->part_pkg;
33
34   my $over_times = $self->option('over_times');
35   $over_times = 0 unless length($over_times);
36
37   my $what = $self->option('what');
38
39   #false laziness w/Condition/cust_payments_pkg.pm
40   if ( $what eq 'base_recur_permonth' ) { #huh.  yuck.
41     if ( $part_pkg->freq !~ /^\d+$/ ) {
42       die 'WARNING: Not crediting customer '. $cust_main->referral_custnum.
43           ' for package '. $cust_pkg->pkgnum.
44           ' ( customer '. $cust_pkg->custnum. ')'.
45           ' - Referral credits not (yet) available for '.
46           ' packages with '. $part_pkg->freq_pretty. ' frequency';
47     }
48   }
49
50   $cust_main->total_paid >= $over_times * $part_pkg->$what($cust_pkg);
51
52 }
53
54 #XXX add for efficiency.  could use cust_main::total_paid_sql
55 #use FS::cust_main;
56 #sub condition_sql {
57 #  my( $class, $table ) = @_;
58 #
59 #  my $over = $class->condition_sql_option('balance');
60 #
61 #  my $balance_sql = FS::cust_main->balance_sql;
62 #
63 #  "$balance_sql > $over";
64 #
65 #}
66
67 1;
68