X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fflat_comission_cust.pm;fp=FS%2FFS%2Fpart_pkg%2Fflat_comission_cust.pm;h=5de45c5efbfb764462c311371def7f9d76b8d9a5;hb=6fe8172b11d0369d0b1274d6825ec0c57afe8001;hp=0000000000000000000000000000000000000000;hpb=717d562bcfb691d971a01b738d0b55cdda480cf0;p=freeside.git diff --git a/FS/FS/part_pkg/flat_comission_cust.pm b/FS/FS/part_pkg/flat_comission_cust.pm new file mode 100644 index 000000000..5de45c5ef --- /dev/null +++ b/FS/FS/part_pkg/flat_comission_cust.pm @@ -0,0 +1,53 @@ +package FS::part_pkg::flat_comission_cust; + +use strict; +use vars qw(@ISA %info); +#use FS::Record qw(qsearch qsearchs); +use FS::part_pkg; + +@ISA = qw(FS::part_pkg); + +%info = ( + 'name' => 'Flat rate with recurring commission per active customer', + '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 customer)', + '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_main_ncancelled(\' + what.comission_depth.value+ \')), "commission" ); die $error if $error; \' + what.recur_fee.value + \';\'', + 'weight' => '60', +); + +sub calc_setup { + my($self, $cust_pkg ) = @_; + $self->option('setup_fee'); +} + +sub calc_recur { + my($self, $cust_pkg ) = @_; + + my $amount = $self->option('comission_amount'); + my $num_active = scalar( + $cust_pkg->cust_main->referral_cust_pkgcust_main_ncancelled( + $self->option('comission_depth') + ) + ); + + my $error = $cust_pkg->cust_main->credit( $amount*$num_active, "commission" ); + die $error if $error; + + $self->option('recur_fee'); +} + +1;