1 package FS::part_event::Action::Mixin::credit_pkg;
5 sub eventtable_hashref {
11 'reasonnum' => { 'label' => 'Credit reason',
12 'type' => 'select-reason',
13 'reason_class' => 'R',
15 'percent' => { 'label' => 'Percent',
16 'type' => 'input-percentage',
22 #add additional ways to specify in the package def
24 base_recur_permonth cust_bill_pkg_recur recur_cost_permonth
28 'base_recur_permonth' => 'Base monthly fee',
29 'cust_bill_pkg_recur' => 'Actual invoiced amount of most recent'.
31 'recur_cost_permonth' => 'Monthly cost',
32 'unit_setup' => 'Setup fee',
33 'setup_cost' => 'Setup cost',
39 #my %no_cust_pkg = ( 'setup_cost' => 1 );
42 my( $self, $cust_pkg ) = @_;
44 my $cust_main = $self->cust_main($cust_pkg);
46 my $part_pkg = $cust_pkg->part_pkg;
48 my $what = $self->option('what');
50 #false laziness w/Condition/cust_payments_pkg.pm
51 if ( $what =~ /_permonth$/ ) { #huh. yuck.
52 if ( $part_pkg->freq !~ /^\d+$/ ) {
53 die 'WARNING: Not crediting for package '. $cust_pkg->pkgnum.
54 ' ( customer '. $cust_pkg->custnum. ')'.
55 ' - credits not (yet) available for '.
56 ' packages with '. $part_pkg->freq_pretty. ' frequency';
60 my $percent = $self->_calc_credit_percent($cust_pkg);
62 #my @arg = $no_cust_pkg{$what} ? () : ($cust_pkg);
63 my @arg = ($what eq 'setup_cost') ? () : ($cust_pkg);
65 sprintf('%.2f', $part_pkg->$what(@arg) * $percent / 100 );
69 sub _calc_credit_percent {
70 my( $self, $cust_pkg ) = @_;
71 $self->option('percent');