proper use of date_format config for international date formats, RT#7009
[freeside.git] / FS / FS / part_event / Action / pkg_referral_credit_pkg.pm
1 package FS::part_event::Action::pkg_referral_credit_pkg;
2
3 use strict;
4 use base qw( FS::part_event::Action::pkg_referral_credit );
5
6 sub description { 'Credit the referring customer an amount based on the referred package'; }
7
8 #sub eventtable_hashref {
9 #  { 'cust_pkg' => 1 };
10 #}
11
12 sub option_fields {
13   ( 
14     'reasonnum' => { 'label'        => 'Credit reason',
15                      'type'         => 'select-reason',
16                      'reason_class' => 'R',
17                    },
18     'percent'   => { 'label'   => 'Percent',
19                      'type'    => 'input-percentage',
20                      'default' => '100',
21                    },
22     'what' => { 'label'   => 'Of',
23                 'type'    => 'select',
24                 #also add some way to specify in the package def, no?
25                 'options' => [ qw( base_recur_permonth ) ],
26                 'labels'  => { 'base_recur_permonth' => 'Base monthly fee', },
27               },
28   );
29
30 }
31
32 sub _calc_referral_credit {
33   my( $self, $cust_pkg ) = @_;
34
35   my $cust_main = $self->cust_main($cust_pkg);
36
37   my $part_pkg = $cust_pkg->part_pkg;
38
39   my $what = $self->option('what');
40
41   #false laziness w/Condition/cust_payments_pkg.pm
42   if ( $what eq 'base_recur_permonth' ) { #huh.  yuck.
43     if ( $part_pkg->freq !~ /^\d+$/ ) {
44       die 'WARNING: Not crediting customer '. $cust_main->referral_custnum.
45           ' for package '. $cust_pkg->pkgnum.
46           ' ( customer '. $cust_pkg->custnum. ')'.
47           ' - Referral credits not (yet) available for '.
48           ' packages with '. $part_pkg->freq_pretty. ' frequency';
49     }
50   }
51
52   my $percent = $self->option('percent');
53
54   sprintf('%.2f', $part_pkg->$what($cust_pkg) * $percent / 100 );
55
56 }
57
58 1;