diff options
author | ivan <ivan> | 2010-03-30 02:53:10 +0000 |
---|---|---|
committer | ivan <ivan> | 2010-03-30 02:53:10 +0000 |
commit | 548bde0209edab634e5b2ea919e4a2096607d2d0 (patch) | |
tree | 1282e186a9ea756c7faceadf3eee19b9f698aafb /FS/FS/part_event/Action/Mixin | |
parent | 2848f5b5675c28051c3ddbc9b9fb302423a43ca4 (diff) |
employee (otaker / access_user) commissioning, RT#6991
Diffstat (limited to 'FS/FS/part_event/Action/Mixin')
-rw-r--r-- | FS/FS/part_event/Action/Mixin/credit_pkg.pm | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/FS/FS/part_event/Action/Mixin/credit_pkg.pm b/FS/FS/part_event/Action/Mixin/credit_pkg.pm new file mode 100644 index 000000000..aeda92f91 --- /dev/null +++ b/FS/FS/part_event/Action/Mixin/credit_pkg.pm @@ -0,0 +1,63 @@ +package FS::part_event::Action::Mixin::credit_pkg; + +use strict; + +sub eventtable_hashref { + { 'cust_pkg' => 1 }; +} + +sub option_fields { + ( + 'reasonnum' => { 'label' => 'Credit reason', + 'type' => 'select-reason', + 'reason_class' => 'R', + }, + 'percent' => { 'label' => 'Percent', + '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', + }, + }, + ); + +} + +#my %no_cust_pkg = ( 'setup_cost' => 1 ); + +sub _calc_credit { + my( $self, $cust_pkg ) = @_; + + my $cust_main = $self->cust_main($cust_pkg); + + my $part_pkg = $cust_pkg->part_pkg; + + my $what = $self->option('what'); + + #false laziness w/Condition/cust_payments_pkg.pm + if ( $what =~ /_permonth$/ ) { #huh. yuck. + if ( $part_pkg->freq !~ /^\d+$/ ) { + die 'WARNING: Not crediting for package '. $cust_pkg->pkgnum. + ' ( customer '. $cust_pkg->custnum. ')'. + ' - credits not (yet) available for '. + ' packages with '. $part_pkg->freq_pretty. ' frequency'; + } + } + + my $percent = $self->option('percent'); + + #my @arg = $no_cust_pkg{$what} ? () : ($cust_pkg); + my @arg = ($what eq 'setup_cost') ? () : ($cust_pkg); + + sprintf('%.2f', $part_pkg->$what(@arg) * $percent / 100 ); + +} + +1; |