merge NG auth, RT#21563
[freeside.git] / FS / FS / part_event / Condition / cust_bill_owed_percent.pm
1 package FS::part_event::Condition::cust_bill_owed_percent;
2
3 use strict;
4 use FS::cust_bill;
5
6 use base qw( FS::part_event::Condition );
7
8 sub description {
9   'Percentage 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 option_fields {
20   (
21     'owed' => { 'label'      => 'Percentage of invoice owed over',
22                 'type'       => 'percentage',
23                 'value'      => '0', #default
24               },
25   );
26 }
27
28 sub condition {
29   #my($self, $cust_bill, %opt) = @_;
30   my($self, $cust_bill) = @_;
31
32   my $percent = $self->option('owed') || 0;
33   my $over = sprintf('%.2f',
34       $cust_bill->charged * $percent / 100);
35
36   $cust_bill->owed > $over;
37 }
38
39 sub condition_sql {
40   my( $class, $table ) = @_;
41
42   # forces the option to be an integer--do we care?
43   my $percent = $class->condition_sql_option_integer('owed');
44
45   my $owed_sql = FS::cust_bill->owed_sql;
46
47   "$owed_sql > CAST( cust_bill.charged * $percent / 100 AS DECIMAL(10,2) )";
48 }
49
50 1;