import torrus 1.0.9
[freeside.git] / FS / FS / part_event / Condition / cust_bill_owed.pm
1 package FS::part_event::Condition::cust_bill_owed;
2
3 use strict;
4 use FS::cust_bill;
5
6 use base qw( FS::part_event::Condition );
7
8 sub description {
9   'Amount owed on specific invoice';
10 }
11
12 sub eventtable_hashref {
13     { 'cust_main' => 0,
14       'cust_bill' => 1,
15       'cust_pkg'  => 0,
16     };
17 }
18
19 sub implicit_flag { 30; }
20
21 sub remove_warning {
22   'Are you sure you want to remove this condition?  Doing so will allow this event to run even for invoices which have no outstanding balance.  Perhaps you want to reset "Amount owed over" to 0 instead of removing the condition entirely?'; #better error msg?
23 }
24
25 sub option_fields {
26   (
27     'owed' => { 'label'      => 'Amount owed over',
28                 'type'       => 'money',
29                 'value'      => '0.00', #default
30               },
31   );
32 }
33
34 sub condition {
35   #my($self, $cust_bill, %opt) = @_;
36   my($self, $cust_bill) = @_;
37
38   my $over = $self->option('owed');
39   $over = 0 unless length($over);
40
41   $cust_bill->owed > $over;
42 }
43
44 sub condition_sql {
45   my( $class, $table ) = @_;
46   
47   my $over = $class->condition_sql_option('owed');
48
49   my $owed_sql = FS::cust_bill->owed_sql;
50
51   "$owed_sql > CAST( $over AS DECIMAL(10,2) )";
52 }
53
54 1;