1 package FS::part_pkg::bulk;
2 use base qw( FS::part_pkg::bulk_Common );
5 use vars qw($DEBUG $me %info);
7 use List::Util qw( max );
11 $me = '[FS::part_pkg::bulk]';
14 'name' => 'Bulk billing based on number of active services (during billing period)',
15 'inherit_fields' => [ 'bulk_Common', 'global_Mixin' ],
17 'no_prorate' => { 'name' => 'Don\'t prorate recurring fees on services '.
18 'active for a partial month',
22 'fieldorder' => [ 'no_prorate' ],
28 my( $self, $cust_pkg, $sdate ) = @_;
30 return $self->_only_svcs_filter($cust_pkg->h_cust_svc( $$sdate, $cust_pkg->last_bill ));
34 my( $self, $cust_pkg, $h_cust_svc ) = @_;
35 ($h_cust_svc->date_inserted < $cust_pkg->last_bill)
36 ? $self->option('svc_setup_fee')
41 my( $self, $cust_pkg, $h_cust_svc, $sdate ) = @_;
43 return ($self->option('svc_recur_fee'), '')
44 if $self->option('no_prorate',1);
46 my $last_bill = $cust_pkg->last_bill;
48 return (0, '') if $$sdate == $last_bill;
50 my $svc_start = max( $h_cust_svc->date_inserted, $last_bill);
51 my $svc_end = $h_cust_svc->date_deleted;
52 $svc_end = ( !$svc_end || $svc_end > $$sdate ) ? $$sdate : $svc_end;
54 my $recur_charge = $self->option('svc_recur_fee')
55 * ( $svc_end - $svc_start )
56 / ( $$sdate - $last_bill );
58 return (0, '') unless $recur_charge;
60 my $svc_details .= ' ('. time2str('%x', $svc_start).
61 ' - '. time2str('%x', $svc_end ). ')';
63 ( $recur_charge, $svc_details );