X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FAction%2FMixin%2Fcredit_pkg.pm;h=400ece97b4cc02d4244370a8636ef10722293dbb;hb=ea16cbe4a50fa79872a4f08225863f39b7d28c06;hp=9dcd701a9c621f275f752cd3f9a45355342b901b;hpb=7c9457296c5dd8985eda5a8325ba1254223ec953;p=freeside.git diff --git a/FS/FS/part_event/Action/Mixin/credit_pkg.pm b/FS/FS/part_event/Action/Mixin/credit_pkg.pm index 9dcd701a9..400ece97b 100644 --- a/FS/FS/part_event/Action/Mixin/credit_pkg.pm +++ b/FS/FS/part_event/Action/Mixin/credit_pkg.pm @@ -2,12 +2,19 @@ package FS::part_event::Action::Mixin::credit_pkg; use strict; +# credit_pkg: calculates a credit amount that is some percentage of the +# package charge / cost / margin / some other amount of a package +# +# also provides an option field for the percentage, unless the action knows +# how to calculate its own percentage somehow (has a _calc_credit_percent) + sub eventtable_hashref { { 'cust_pkg' => 1 }; } sub option_fields { - ( + my $class = shift; + my @fields = ( 'reasonnum' => { 'label' => 'Credit reason', 'type' => 'select-reason', 'reason_class' => 'R', @@ -16,24 +23,39 @@ sub option_fields { 'type' => 'input-percentage', 'default' => '100', }, - 'what' => { 'label' => 'Of', - 'type' => 'select', - #add additional ways to specify in the package def - 'options' => [ qw( base_recur_permonth unit_setup recur_cost_permonth setup_cost ) ], - 'labels' => { 'base_recur_permonth' => 'Base monthly fee', - 'unit_setup' => 'Setup fee', - 'recur_cost_permonth' => 'Monthly cost', - 'setup_cost' => 'Setup cost', - }, - }, + 'what' => { + 'label' => 'Of', + 'type' => 'select', + #add additional ways to specify in the package def + 'options' => [qw( + base_recur_permonth cust_bill_pkg_recur recur_cost_permonth recur_margin_permonth + unit_setup setup_cost setup_margin + )], + 'labels' => { + 'base_recur_permonth' => 'Base monthly fee', + 'cust_bill_pkg_recur' => 'Actual invoiced amount of most recent'. + ' recurring charge', + 'recur_cost_permonth' => 'Monthly cost', + 'unit_setup' => 'Setup fee', + 'setup_cost' => 'Setup cost', + 'setup_margin' => 'Setup margin (fee minus cost)', + 'recur_margin_permonth' => 'Monthly margin (fee minus cost)', + }, + }, ); - + if ($class->can('_calc_credit_percent')) { + splice @fields, 2, 2; #remove the percentage option + } + @fields; } -#my %no_cust_pkg = ( 'setup_cost' => 1 ); +# arguments: +# 1. cust_pkg +# 2. recipient of the credit (passed through to _calc_credit_percent) sub _calc_credit { - my( $self, $cust_pkg ) = @_; + my $self = shift; + my $cust_pkg = shift; my $cust_main = $self->cust_main($cust_pkg); @@ -51,18 +73,17 @@ sub _calc_credit { } } - my $percent = $self->_calc_credit_percent($cust_pkg); + my $percent; + if ( $self->can('_calc_credit_percent') ) { + $percent = $self->_calc_credit_percent($cust_pkg, @_); + } else { + $percent = $self->option('percent') || 0; + } - #my @arg = $no_cust_pkg{$what} ? () : ($cust_pkg); my @arg = ($what eq 'setup_cost') ? () : ($cust_pkg); sprintf('%.2f', $part_pkg->$what(@arg) * $percent / 100 ); } -sub _calc_credit_percent { - my( $self, $cust_pkg ) = @_; - $self->option('percent'); -} - 1;