X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fflat_comission.pm;h=0bc1e7cb42f72524aa5cfc30b9d7e3b79d18ddae;hb=b8baeb2b7fb88b2b17740bedb379ec41d04de358;hp=d39347015359574f8266a71cd8455677d72184f7;hpb=5fc8c5edf574ab024d4646914b6432d458e2ffbd;p=freeside.git diff --git a/FS/FS/part_pkg/flat_comission.pm b/FS/FS/part_pkg/flat_comission.pm index d39347015..0bc1e7cb4 100644 --- a/FS/FS/part_pkg/flat_comission.pm +++ b/FS/FS/part_pkg/flat_comission.pm @@ -3,35 +3,41 @@ package FS::part_pkg::flat_comission; use strict; use vars qw(@ISA %info); #use FS::Record qw(qsearch qsearchs); -use FS::part_pkg; +use FS::part_pkg::flat; -@ISA = qw(FS::part_pkg); +@ISA = qw(FS::part_pkg::flat); %info = ( - 'name' => 'Flat rate with recurring commission per (any) active package', - 'fields' => { - 'setup_fee' => { 'name' => 'Setup fee for this package', - 'default' => 0, - }, - 'recur_fee' => { 'name' => 'Recurring fee for this package', - 'default' => 0, - }, - 'comission_amount' => { 'name' => 'Commission amount per month (per active package)', - 'default' => 0, - }, - 'comission_depth' => { 'name' => 'Number of layers', - 'default' => 1, - }, - }, - 'fieldorder' => [ 'setup_fee', 'recur_fee', 'comission_depth', 'comission_amount' ], - #'setup' => 'what.setup_fee.value', - #'recur' => '\'my $error = $cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar($cust_pkg->cust_main->referral_cust_pkg(\' + what.comission_depth.value+ \')), "commission" ); die $error if $error; \' + what.recur_fee.value + \';\'', - 'weight' => 62, + 'name' => 'Flat rate with recurring commission per (any) active package', + 'shortname' => 'Commission per (any) active package', + 'inherit_fields' => [ 'global_Mixin' ], + 'fields' => { + 'comission_amount' => { 'name' => 'Commission amount per month (per active package)', + 'default' => 0, + }, + 'comission_depth' => { 'name' => 'Number of layers', + 'default' => 1, + }, + 'reason_type' => { 'name' => 'Reason type for commission credits', + 'type' => 'select', + 'select_table' => 'reason_type', + 'select_hash' => { 'class' => 'R' }, + 'select_key' => 'typenum', + 'select_label' => 'type', + }, + }, + 'fieldorder' => [ 'comission_depth', 'comission_amount', 'reason_type' ], + #'setup' => 'what.setup_fee.value', + #'recur' => '\'my $error = $cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar($cust_pkg->cust_main->referral_cust_pkg(\' + what.comission_depth.value+ \')), "commission" ); die $error if $error; \' + what.recur_fee.value + \';\'', + 'weight' => 62, ); -sub calc_setup { - my($self, $cust_pkg ) = @_; - $self->option('setup_fee'); +sub price_info { + my $self = shift; + my $str = $self->SUPER::price_info; + my $com = $self->option('comission_amount'); + $str .= ", $com commission" if $com; + $str; } sub calc_recur { @@ -42,10 +48,21 @@ sub calc_recur { $cust_pkg->cust_main->referral_cust_pkg( $self->option('comission_depth') ) ); - my $error = $cust_pkg->cust_main->credit( $amount*$num_active, "commission" ); - die $error if $error; + my $commission = sprintf('%.2f', $amount*$num_active); + + if ( $commission > 0 ) { + + my $error = + $cust_pkg->cust_main->credit( $commission, "commission", + 'reason_type'=>$self->option('reason_type'), + ); + die $error if $error; + + } $self->option('recur_fee'); } +sub can_discount { 0; } + 1;