1 package FS::part_event::Action::pkg_referral_credit;
4 use base qw( FS::part_event::Action );
6 sub description { 'Credit the referring customer a specific amount'; }
8 sub eventtable_hashref {
14 'reasonnum' => { 'label' => 'Credit reason',
15 'type' => 'select-reason',
16 'reason_class' => 'R',
18 'amount' => { 'label' => 'Credit amount',
26 my( $self, $cust_pkg, $cust_event ) = @_;
28 my $cust_main = $self->cust_main($cust_pkg);
30 # my $part_pkg = $cust_pkg->part_pkg;
32 return 'No referring customer' unless $cust_main->referral_custnum;
34 my $referring_cust_main = $cust_main->referring_cust_main;
35 return 'Referring customer is cancelled'
36 if $referring_cust_main->status eq 'cancelled';
38 my $amount = $self->_calc_credit($cust_pkg);
39 return '' unless $amount > 0;
41 my $reasonnum = $self->option('reasonnum');
43 my $error = $referring_cust_main->credit(
46 'eventnum' => $cust_event->eventnum,
47 'addlinfo' => 'for customer #'. $cust_main->display_custnum.
48 ': '.$cust_main->name,
50 die "Error crediting customer ". $cust_main->referral_custnum.
51 " for referral: $error"
57 my( $self, $cust_pkg ) = @_;
59 $self->option('amount');