hide start date on package order for specific package definitions, RT#13783
[freeside.git] / FS / FS / part_pkg / flat_comission.pm
1 package FS::part_pkg::flat_comission;
2
3 use strict;
4 use vars qw(@ISA %info);
5 #use FS::Record qw(qsearch qsearchs);
6 use FS::part_pkg::flat;
7
8 @ISA = qw(FS::part_pkg::flat);
9
10 %info = (
11   'name' => 'Flat rate with recurring commission per (any) active package',
12   'shortname' => 'Commission per (any) active package',
13   'inherit_fields' => [ 'global_Mixin' ],
14   'fields' => {
15     'comission_amount' => { 'name' => 'Commission amount per month (per active package)',
16                             'default' => 0,
17                           },
18     'comission_depth'  => { 'name' => 'Number of layers',
19                             'default' => 1,
20                           },
21     'reason_type'      => { 'name' => 'Reason type for commission credits',
22                             'type' => 'select',
23                             'select_table' => 'reason_type',
24                             'select_hash'  => { 'class' => 'R' },
25                             'select_key'   => 'typenum',
26                             'select_label' => 'type',
27                           },
28   },
29   'fieldorder' => [ 'comission_depth', 'comission_amount', 'reason_type' ],
30   #'setup' => 'what.setup_fee.value',
31   #'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 + \';\'',
32   'weight' => 62,
33 );
34
35 sub price_info {
36     my $self = shift;
37     my $str = $self->SUPER::price_info;
38     my $com = $self->option('comission_amount');
39     $str .= ", $com commission" if $com;
40     $str;
41 }
42
43 sub calc_recur {
44   my($self, $cust_pkg ) = @_;
45
46   my $amount = $self->option('comission_amount');
47   my $num_active = scalar(
48     $cust_pkg->cust_main->referral_cust_pkg( $self->option('comission_depth') )
49   );
50
51   my $commission = sprintf('%.2f', $amount*$num_active);
52
53   if ( $commission > 0 ) {
54
55     my $error =
56       $cust_pkg->cust_main->credit( $commission, "commission",
57                                     'reason_type'=>$self->option('reason_type'),
58                                   );
59     die $error if $error;
60
61   }
62
63   $self->option('recur_fee');
64 }
65
66 sub can_discount { 0; }
67
68 1;