summaryrefslogtreecommitdiff
path: root/FS/FS/part_event/Condition/cust_payments.pm
blob: 477ecdbb0d4263138f7452c66be14a5aa4ba86df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package FS::part_event::Condition::cust_payments;

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

sub description { 'Customer total payments (amount)'; }

sub option_fields {
  (
    'over' => { 'label'      => 'Customer total payments at least',
                'type'       => 'money',
                'value'      => '0.00', #default
              },
  );
}

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

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

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

  $cust_main->total_paid >= $over;

}

#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;