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 recur_margin_permonth
25 unit_setup setup_cost setup_margin
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',
34 'setup_margin' => 'Setup margin (fee minus cost)',
35 'recur_margin_permonth' => 'Monthly margin (fee minus cost)',
41 #my %no_cust_pkg = ( 'setup_cost' => 1 );
44 my( $self, $cust_pkg ) = @_;
46 my $cust_main = $self->cust_main($cust_pkg);
48 my $part_pkg = $cust_pkg->part_pkg;
50 my $what = $self->option('what');
52 #false laziness w/Condition/cust_payments_pkg.pm
53 if ( $what =~ /_permonth$/ ) { #huh. yuck.
54 if ( $part_pkg->freq !~ /^\d+$/ ) {
55 die 'WARNING: Not crediting for package '. $cust_pkg->pkgnum.
56 ' ( customer '. $cust_pkg->custnum. ')'.
57 ' - credits not (yet) available for '.
58 ' packages with '. $part_pkg->freq_pretty. ' frequency';
62 my $percent = $self->_calc_credit_percent($cust_pkg);
64 #my @arg = $no_cust_pkg{$what} ? () : ($cust_pkg);
65 my @arg = ($what eq 'setup_cost') ? () : ($cust_pkg);
67 sprintf('%.2f', $part_pkg->$what(@arg) * $percent / 100 );
71 sub _calc_credit_percent {
72 my( $self, $cust_pkg ) = @_;
73 $self->option('percent');