add skip_dcontext_suffix to skip CDRs with dcontext ending in a definable string...
[freeside.git] / FS / FS / part_pkg / prorate.pm
1 package FS::part_pkg::prorate;
2 use base qw( FS::part_pkg::flat );
3
4 use strict;
5 use vars qw(%info);
6 use Time::Local qw(timelocal);
7 #use FS::Record qw(qsearch qsearchs);
8
9 %info = (
10   'name' => 'First partial month pro-rated, then flat-rate (selectable billing day)',
11   'shortname' => 'Prorate (Nth of month billing)',
12   'inherit_fields' => [ 'flat', 'usage_Mixin', 'global_Mixin' ],
13   'fields' => {
14     'recur_temporality' => {'disabled' => 1},
15     'sync_bill_date' => {'disabled' => 1},
16     'cutoff_day' => { 'name' => 'Billing Day (1 - 28)',
17                       'default' => 1,
18                     },
19
20     'add_full_period'=> { 'name' => 'When prorating first month, also bill '.
21                                     'for one full period after that',
22                           'type' => 'checkbox',
23                         },
24     'prorate_round_day'=> {
25                           'name' => 'Round the prorated period',
26                           'type' => 'select',
27                           'select_options' => \%FS::part_pkg::prorate_Mixin::prorate_round_day_opts,
28                         },
29     'prorate_defer_bill'=> {
30                         'name' => 'Defer the first bill until the billing day',
31                         'type' => 'checkbox',
32                         },
33     'prorate_verbose' => {
34                         'name' => 'Show prorate details on the invoice',
35                         'type' => 'checkbox',
36                         },
37   },
38   'fieldorder' => [ 'cutoff_day', 'prorate_defer_bill', 'add_full_period', 'prorate_round_day', 'prorate_verbose' ],
39   'freq' => 'm',
40   'weight' => 20,
41 );
42
43 sub calc_recur {
44   my $self = shift;
45   #my($cust_pkg, $sdate, $details, $param ) = @_;
46   my $cust_pkg = $_[0];
47
48   my $charge = $self->calc_prorate(@_, $self->cutoff_day($cust_pkg));
49
50   $charge += $self->usageprice_recur(@_);
51   $cust_pkg->apply_usageprice(); #$sdate for prorating?
52
53   my $discount = $self->calc_discount(@_);
54
55   sprintf( '%.2f', ($cust_pkg->quantity || 1) * ($charge - $discount) );
56
57 }
58
59 sub cutoff_day {
60   my( $self, $cust_pkg ) = @_;
61   my $prorate_day = $cust_pkg->cust_main->prorate_day;
62   $prorate_day ? ( $prorate_day )
63                : split(/\s*,\s*/, $self->option('cutoff_day', 1) || '1');
64 }
65
66 1;