suspend event option to skip packages with a start_date, RT#83847
[freeside.git] / FS / FS / part_event / Action / pkg_employee_credit.pm
1 package FS::part_event::Action::pkg_employee_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 ordering employee 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 $employee = $cust_pkg->access_user;
16   return "No customer record for employee ". $employee->username
17     unless $employee->user_custnum;
18
19   my $employee_cust_main = $employee->user_cust_main;
20     #? or return "No customer record for employee ". $employee->username;
21
22   my $warning = '';
23   my $amount    = $self->_calc_credit($cust_pkg, $employee, \$warning);
24   return $warning unless $amount > 0;
25
26   my $reasonnum = $self->option('reasonnum');
27
28   my $error = $employee_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   );
35   die "Error crediting customer ". $employee_cust_main->custnum.
36       " for employee commission: $error"
37     if $error;
38
39 }
40
41 1;