summaryrefslogtreecommitdiff
path: root/FS/FS/part_event/Action/pkg_referral_credit_pkg.pm
blob: eb9b5107c41f88d88a9f1e8ffc45b934a20090a9 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package FS::part_event::Action::pkg_referral_credit_pkg;

use strict;
use base qw( FS::part_event::Action::pkg_referral_credit );

sub description { 'Credit the referring customer an amount based on the referred package'; }

#sub eventtable_hashref {
#  { 'cust_pkg' => 1 };
#}

sub option_fields {
  ( 
    'reasonnum' => { 'label'        => 'Credit reason',
                     'type'         => 'select-reason',
                     'reason_class' => 'R',
                   },
    'percent'   => { 'label'   => 'Percent',
                     'type'    => 'input-percentage',
                     'default' => '100',
                   },
    'what' => { 'label'   => 'Of',
                'type'    => 'select',
                #also add some way to specify in the package def, no?
                'options' => [ qw( base_recur_permonth ) ],
                'labels'  => { 'base_recur_permonth' => 'Base monthly fee', },
              },
  );

}

sub _calc_referral_credit {
  my( $self, $cust_pkg ) = @_;

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

  my $part_pkg = $cust_pkg->part_pkg;

  my $what = $self->option('what');

  #false laziness w/Condition/cust_payments_pkg.pm
  if ( $what eq 'base_recur_permonth' ) { #huh.  yuck.
    if ( $part_pkg->freq !~ /^\d+$/ ) {
      die 'WARNING: Not crediting customer '. $cust_main->referral_custnum.
          ' for package '. $cust_pkg->pkgnum.
          ' ( customer '. $cust_pkg->custnum. ')'.
          ' - Referral credits not (yet) available for '.
          ' packages with '. $part_pkg->freq_pretty. ' frequency';
    }
  }

  my $percent = $self->option('percent');

  sprintf('%.2f', $part_pkg->$what($cust_pkg) * $percent / 100 );

}

1;