summaryrefslogtreecommitdiff
path: root/FS/FS/part_event/Condition/balance_under.pm
blob: 5e1903468844f5a69dea80caa50ded2c3d70e14e (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
package FS::part_event::Condition::balance_under;

use strict;
use FS::cust_main;

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

sub description { 'Customer balance (under)'; }

sub option_fields {
  (
    'balance' => { 'label'      => 'Balance under (or equal to)',
                   'type'       => 'money',
                   'value'      => '0.00', #default
                 },
  );
}

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

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

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

  $cust_main->balance <= $under;
}

sub condition_sql {
  my( $class, $table ) = @_;

  my $under = $class->condition_sql_option('balance');

  my $balance_sql = FS::cust_main->balance_sql;

  "$balance_sql <= $under";

}

1;