1 package FS::part_pkg::prorate;
2 use base qw( FS::part_pkg::flat );
6 use Time::Local qw(timelocal);
7 #use FS::Record qw(qsearch qsearchs);
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' ],
14 'recur_temporality' => {'disabled' => 1},
15 'sync_bill_date' => {'disabled' => 1},
16 'cutoff_day' => { 'name' => 'Billing Day (1 - 28)',
20 'add_full_period'=> { 'name' => 'When prorating first month, also bill '.
21 'for one full period after that',
24 'prorate_round_day'=> {
25 'name' => 'Round the prorated period',
27 'select_options' => \%FS::part_pkg::prorate_Mixin::prorate_round_day_opts,
29 'prorate_defer_bill'=> {
30 'name' => 'Defer the first bill until the billing day',
33 'prorate_verbose' => {
34 'name' => 'Show prorate details on the invoice',
38 'fieldorder' => [ 'cutoff_day', 'prorate_defer_bill', 'add_full_period', 'prorate_round_day', 'prorate_verbose' ],
45 #my($cust_pkg, $sdate, $details, $param ) = @_;
48 my $charge = $self->calc_prorate(@_, $self->cutoff_day($cust_pkg));
50 $charge += $self->usageprice_recur(@_);
51 $cust_pkg->apply_usageprice(); #$sdate for prorating?
53 my $discount = $self->calc_discount(@_);
55 sprintf( '%.2f', ($cust_pkg->quantity || 1) * ($charge - $discount) );
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');