diff options
author | ivan <ivan> | 2008-11-22 22:17:28 +0000 |
---|---|---|
committer | ivan <ivan> | 2008-11-22 22:17:28 +0000 |
commit | 58f99accce35aa76abe9ff852f6c6ee84e8ce712 (patch) | |
tree | 4403996ba0953f5826d5b84b99d9f99f6629683e /FS/FS/part_event/Action/pkg_referral_credit.pm | |
parent | 1d84feb7fe821b547e211ad03e5c200c8f218797 (diff) |
referral credits overhaul, use billing events, agents can self-configure, limit to once-per-customer, depend on any time from referred package, referred customer payment, specific packages, partial staged credits, RT#3983
Diffstat (limited to 'FS/FS/part_event/Action/pkg_referral_credit.pm')
-rw-r--r-- | FS/FS/part_event/Action/pkg_referral_credit.pm | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/FS/FS/part_event/Action/pkg_referral_credit.pm b/FS/FS/part_event/Action/pkg_referral_credit.pm new file mode 100644 index 0000000..98d9820 --- /dev/null +++ b/FS/FS/part_event/Action/pkg_referral_credit.pm @@ -0,0 +1,60 @@ +package FS::part_event::Action::pkg_referral_credit; + +use strict; +use base qw( FS::part_event::Action ); + +sub description { 'Credit the referring customer a specific amount'; } + +sub eventtable_hashref { + { 'cust_pkg' => 1 }; +} + +sub option_fields { + ( + 'reasonnum' => { 'label' => 'Credit reason', + 'type' => 'select-reason', + 'reason_class' => 'R', + }, + 'amount' => { 'label' => 'Credit amount', + 'type' => 'money', + }, + ); + +} + +#a little false laziness w/pkg_referral_credit_pkg +sub do_action { + my( $self, $cust_pkg ) = @_; + + my $cust_main = $self->cust_main($cust_pkg); + +# my $part_pkg = $cust_pkg->part_pkg; + + return 'No referring customer' unless $cust_main->referral_custnum; + + my $referring_cust_main = $cust_main->referring_cust_main; + return 'Referring customer is cancelled' + if $referring_cust_main->status eq 'cancelled'; + + my $amount = $self->_calc_referral_credit($cust_pkg); + my $reasonnum = $self->option('reasonnum'); + + my $error = $referring_cust_main->credit( + $amount, + \$reasonnum, + 'addlinfo' => + 'for customer #'. $cust_main->display_custnum. ': '.$cust_main->name, + ); + die "Error crediting customer ". $cust_main->referral_custnum. + " for referral: $error" + if $error; + +} + +sub _calc_referral_credit { + my( $self, $cust_pkg ) = @_; + + $self->option('amount'); +} + +1; |