my $parents = $info{$name}->{'inherit_fields'} || [];
my (%fields, %field_exists, @fieldorder);
foreach my $parent ($name, @$parents) {
+ if ( !exists($info{$parent}) ) {
+ warn "$name tried to inherit from nonexistent '$parent'\n";
+ next;
+ }
%fields = ( # avoid replacing existing fields
%{ $info{$parent}->{'fields'} || {} },
%fields
next if $field_exists{$_};
$field_exists{$_} = 1;
# allow inheritors to remove inherited fields from the fieldorder
- push @fieldorder, $_ if !exists($fields{$_}->{'disabled'});
+ push @fieldorder, $_ if !exists($fields{$_}) or
+ !exists($fields{$_}->{'disabled'});
}
}
$plans{$name}->{'fields'} = \%fields;
%info = (
'name' => 'VoIP rating of CDR records for termination partners.',
'shortname' => 'VoIP/telco CDR termination',
- 'inherit_fields' => [ 'global_Mixin' ],
+ 'inherit_fields' => [ 'prorate_Mixin', 'global_Mixin' ],
'fields' => {
#'cdr_column' => { 'name' => 'Column from CDR records',
# 'type' => 'select',
'subscription',
'default' => '1',
},
- 'add_full_period'=> { 'name' => 'When prorating first month, also bill '.
- 'for one full period after that',
- 'type' => 'checkbox',
- },
-
'recur_method' => { 'name' => 'Recurring fee method',
#'type' => 'radio',
#'options' => \%recur_method,
},
#cdr_column
- 'fieldorder' => [qw(
- recur_temporality recur_method cutoff_day
- add_full_period
+ 'fieldorder' => [qw( recur_temporality recur_method cutoff_day ),
+ FS::part_pkg::prorate_Mixin::fieldorder,
+ qw(
output_format usage_section summarize_usage usage_mandate
)
],
);
-sub calc_setup {
- my($self, $cust_pkg ) = @_;
- $self->option('setup_fee');
-}
-
sub calc_recur {
my $self = shift;
my($cust_pkg, $sdate, $details, $param ) = @_;
%info = (
'name' => 'Flat rate (anniversary billing)',
'shortname' => 'Anniversary',
- 'inherit_fields' => [ 'usage_Mixin', 'global_Mixin' ],
+ 'inherit_fields' => [ 'prorate_Mixin', 'usage_Mixin', 'global_Mixin' ],
'fields' => {
#false laziness w/voip_cdr.pm
'recur_temporality' => { 'name' => 'Charge recurring fee for period',
'the customer\'s next bill date',
'type' => 'checkbox',
},
+ 'prorate_round_day' => {
+ 'name' => 'When synchronizing, round the prorated '.
+ 'period to the nearest full day',
+ 'type' => 'checkbox',
+ },
+ 'add_full_period' => { 'disabled' => 1 }, # doesn't make sense with sync?
+
'suspend_bill' => { 'name' => 'Continue recurring billing while suspended',
'type' => 'checkbox',
},
'fieldorder' => [ qw( recur_temporality
expire_months adjourn_months
contract_end_months
- start_1st sync_bill_date prorate_defer_bill
+ start_1st
+ sync_bill_date prorate_defer_bill prorate_round_day
suspend_bill unsuspend_adjust_bill
externalid ),
],
'type' => 'checkbox',
},
'prorate_round_day'=> {
- 'name' => 'When prorating first month, round to '.
- 'the nearest full day',
+ 'name' => 'Round the prorated period to the nearest '.
+ 'full day',
'type' => 'checkbox',
},
'prorate_defer_bill'=> {
@ISA = qw(FS::part_pkg);
%info = (
'disabled' => 1,
+ # define all fields that are referenced in this code
+ 'fields' => {
+ 'add_full_period' => {
+ 'name' => 'When prorating first month, also bill for one full '.
+ 'period after that',
+ 'type' => 'checkbox',
+ },
+ 'prorate_round_day' => {
+ 'name' => 'When prorating, round to the nearest full day',
+ 'type' => 'checkbox',
+ },
+ 'prorate_defer_bill' => {
+ 'name' => 'When prorating, defer the first bill until the '.
+ 'billing day',
+ 'type' => 'checkbox',
+ },
+ },
+ 'fieldorder' => [ qw(prorate_defer_bill prorate_round_day add_full_period) ],
);
+sub fieldorder {
+ @{ $info{'fieldorder'} }
+}
+
=head1 NAME
FS::part_pkg::prorate_Mixin - Mixin class for part_pkg:: classes that
# only works for freq >= 1 month; probably can't be fixed
my ($sec, $min, $hour, $mday, $mon, $year) = (localtime($mnow))[0..5];
if( $self->option('prorate_round_day',1) ) {
- $mday++ if $hour >= 12;
+ # If the time is 12:00-23:59, move to the next day by adding 18
+ # hours to $mnow. Because of DST this can end up from 05:00 to 18:59
+ # but it's always within the next day.
+ $mnow += 64800 if $hour >= 12;
+ # Get the new day, month, and year.
+ ($mday,$mon,$year) = (localtime($mnow))[3..5];
+ # Then set $mnow to midnight on that day.
$mnow = timelocal(0,0,0,$mday,$mon,$year);
}
my $mend;
$self->option('recur_fee', 1) || 0;
}
+sub calc_setup {
+ # moved from all descendant packages which just had $self->option('setup_fee')
+ my($self, $cust_pkg, $sdate, $details, $param) = @_;
+ return 0 if $self->prorate_setup($cust_pkg, $sdate);
+ $self->option('setup_fee');
+}
+
sub cutoff_day {
# prorate/subscription only; we don't support sync_bill_date here
my $self = shift;
%info = (
'name' => 'Base charge plus additional fees for external services from a configurable SQL query',
'shortname' => 'External SQL query',
- 'inherit_fields' => [ 'global_Mixin' ],
+ 'inherit_fields' => [ 'prorate_Mixin', 'global_Mixin' ],
'fields' => {
'cutoff_day' => { 'name' => 'Billing Day (1 - 28) for prorating or '.
'subscription',
'default' => '1',
},
- 'add_full_period'=> { 'name' => 'When prorating first month, also bill '.
- 'for one full period after that',
- 'type' => 'checkbox',
- },
'recur_method' => { 'name' => 'Recurring fee method',
#'type' => 'radio',
'default' => '',
},
},
- 'fieldorder' => [qw( recur_method cutoff_day
- add_full_period datasrc db_username db_password query
+ 'fieldorder' => [qw( recur_method cutoff_day ),
+ FS::part_pkg::prorate_Mixin::fieldorder,
+ qw( datasrc db_username db_password query
)],
'weight' => '58',
);
%info = (
'name' => 'VoIP rating by plan of CDR records in an internal (or external) SQL table',
'shortname' => 'VoIP/telco CDR rating (standard)',
- 'inherit_fields' => [ 'global_Mixin' ],
+ 'inherit_fields' => [ 'prorate_Mixin', 'global_Mixin' ],
'fields' => {
'suspend_bill' => { 'name' => 'Continue recurring billing while suspended',
'type' => 'checkbox',
'subscription',
'default' => '1',
},
- 'add_full_period'=> { 'name' => 'When prorating first month, also bill '.
- 'for one full period after that',
- 'type' => 'checkbox',
- },
'recur_method' => { 'name' => 'Recurring fee method',
#'type' => 'radio',
#'options' => \%recur_method,
},
'fieldorder' => [qw(
recur_temporality
- recur_method cutoff_day
- add_full_period
+ recur_method cutoff_day ),
+ FS::part_pkg::prorate_Mixin::fieldorder,
+ qw(
cdr_svc_method
rating_method ratenum intrastate_ratenum
min_charge min_included
$str;
}
-sub calc_setup {
- my($self, $cust_pkg ) = @_;
- $self->option('setup_fee');
-}
-
sub calc_recur {
my $self = shift;
my($cust_pkg, $sdate, $details, $param ) = @_;
%info = (
'name' => 'VoIP flat rate pricing of CDRs for inbound calls',
'shortname' => 'VoIP/telco CDR rating (inbound)',
- 'inherit_fields' => [ 'global_Mixin' ],
+ 'inherit_fields' => [ 'prorate_Mixin', 'global_Mixin' ],
'fields' => {
#false laziness w/flat.pm
'recur_temporality' => { 'name' => 'Charge recurring fee for period',
'subscription',
'default' => '1',
},
- 'add_full_period'=> { 'name' => 'When prorating first month, also bill '.
- 'for one full period after that',
- 'type' => 'checkbox',
- },
'recur_method' => { 'name' => 'Recurring fee method',
'type' => 'select',
},
'fieldorder' => [qw(
recur_temporality
- recur_method cutoff_day add_full_period
- min_charge min_included sec_granularity
+ recur_method cutoff_day ),
+ FS::part_pkg::prorate_Mixin::fieldorder,
+ qw( min_charge min_included sec_granularity
default_prefix
disable_tollfree
use_amaflags
$str;
}
-sub calc_setup {
- my($self, $cust_pkg ) = @_;
- $self->option('setup_fee');
-}
-
sub calc_recur {
my $self = shift;
my($cust_pkg, $sdate, $details, $param ) = @_;