1 package FS::part_event::Action::pkg_sales_credit;
2 use base qw( FS::part_event::Action::Mixin::credit_flat
3 FS::part_event::Action );
7 sub description { 'Credit the sales person a specific amount'; }
9 sub eventtable_hashref {
14 my( $self, $cust_pkg, $cust_event ) = @_;
16 my $cust_main = $self->cust_main($cust_pkg);
18 my $sales = $cust_pkg->sales;
19 $sales ||= $self->cust_main($cust_pkg)->sales
20 if $self->option('cust_main_sales');
22 return '' unless $sales; #no sales person, no credit
24 die "No customer record for sales person ". $sales->salesperson
25 unless $sales->sales_custnum;
27 my $sales_cust_main = $sales->sales_cust_main;
28 #? or return "No customer record for sales person ". $sales->salesperson;
31 my $amount = $self->_calc_credit($cust_pkg, $sales, \$warning);
32 return $warning unless $amount > 0;
34 my $reasonnum = $self->option('reasonnum');
36 my $error = $sales_cust_main->credit(
39 'eventnum' => $cust_event->eventnum,
40 'addlinfo' => 'for customer #'. $cust_main->display_custnum.
41 ': '.$cust_main->name.
42 ', package #'. $cust_pkg->pkgnum,
43 'commission_salesnum' => $sales->salesnum,
44 'commission_pkgnum' => $cust_pkg->pkgnum,
46 die "Error crediting customer ". $sales_cust_main->custnum.
47 " for sales commission: $error"