suspend event option to skip packages with a start_date, RT#83847
[freeside.git] / FS / FS / part_event / Action / pkg_agent_credit.pm
1 package FS::part_event::Action::pkg_agent_credit;
2
3 use strict;
4 use base qw( FS::part_event::Action::Mixin::credit_flat
5              FS::part_event::Action );
6
7 sub description { 'Credit the agent a specific amount'; }
8
9 #a little false laziness w/pkg_referral_credit
10 sub do_action {
11   my( $self, $cust_pkg, $cust_event ) = @_;
12
13   my $cust_main = $self->cust_main($cust_pkg);
14
15   my $agent = $cust_main->agent;
16   return "No customer record for agent ". $agent->agent
17     unless $agent->agent_custnum;
18
19   my $agent_cust_main = $agent->agent_cust_main;
20     #? or return "No customer record for agent ". $agent->agent;
21
22   my $warning = '';
23   my $amount = $self->_calc_credit($cust_pkg, $agent, \$warning);
24   return $warning unless $amount > 0;
25
26   my $reasonnum = $self->option('reasonnum');
27
28   my $error = $agent_cust_main->credit(
29     $amount, 
30     \$reasonnum,
31     'eventnum'            => $cust_event->eventnum,
32     'addlinfo'            => 'for customer #'. $cust_main->display_custnum.
33                                           ': '.$cust_main->name,
34     'commission_agentnum' => $agent->agentnum,
35     'commission_pkgnum'   => $cust_pkg->pkgnum,
36   );
37   die "Error crediting customer ". $agent_cust_main->custnum.
38       " for agent commission: $error"
39     if $error;
40
41 }
42
43 1;