1 package FS::part_event::Action::pkg_referral_credit_pkg;
4 use base qw( FS::part_event::Action::pkg_referral_credit );
6 sub description { 'Credit the referring customer an amount based on the referred package'; }
8 #sub eventtable_hashref {
14 'reasonnum' => { 'label' => 'Credit reason',
15 'type' => 'select-reason',
16 'reason_class' => 'R',
18 'percent' => { 'label' => 'Percent',
19 'type' => 'input-percentage',
22 'what' => { 'label' => 'Of',
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', },
32 sub _calc_referral_credit {
33 my( $self, $cust_pkg ) = @_;
35 my $cust_main = $self->cust_main($cust_pkg);
37 my $part_pkg = $cust_pkg->part_pkg;
39 my $what = $self->option('what');
41 if ( $what eq 'base_recur_permonth' ) { #huh. yuck.
42 if ( $part_pkg->freq !~ /^\d+$/ ) {
43 die 'WARNING: Not crediting customer '. $cust_main->referral_custnum.
44 ' for package '. $cust_pkg->pkgnum.
45 ' ( customer '. $cust_pkg->custnum. ')'.
46 ' - Referral credits not (yet) available for '.
47 ' packages with '. $part_pkg->freq_pretty. ' frequency';
51 my $percent = $self->option('percent');
53 sprintf('%.2f', $part_pkg->$what($cust_pkg) * $percent / 100 );