add skip_dcontext_suffix to skip CDRs with dcontext ending in a definable string...
[freeside.git] / FS / FS / part_pkg / bulk.pm
1 package FS::part_pkg::bulk;
2 use base qw( FS::part_pkg::bulk_Common );
3
4 use strict;
5 use vars qw($DEBUG $me %info);
6 use Date::Format;
7 use List::Util qw( max );
8 use FS::Conf;
9
10 $DEBUG = 0;
11 $me = '[FS::part_pkg::bulk]';
12
13 %info = (
14   'name' => 'Bulk billing based on number of active services (during billing period)',
15   'inherit_fields' => [ 'bulk_Common', 'global_Mixin' ],
16   'fields' => {
17     'no_prorate'    => { 'name' => 'Don\'t prorate recurring fees on services '.
18                                    'active for a partial month',
19                          'type' => 'checkbox',
20                        },
21   },
22   'fieldorder' => [ 'no_prorate' ],
23   'weight' => 51,
24 );
25
26
27 sub _bulk_cust_svc {
28   my( $self, $cust_pkg, $sdate ) = @_;
29                        #   END      START
30   return $self->_only_svcs_filter($cust_pkg->h_cust_svc( $$sdate, $cust_pkg->last_bill ));
31 }
32
33 sub _bulk_setup {
34   my( $self, $cust_pkg, $h_cust_svc ) = @_;
35   ($h_cust_svc->date_inserted < $cust_pkg->last_bill)
36     ? $self->option('svc_setup_fee')
37     : 0;
38 }
39
40 sub _bulk_recur {
41   my( $self, $cust_pkg, $h_cust_svc, $sdate ) = @_;
42
43   return ($self->option('svc_recur_fee'), '')
44     if $self->option('no_prorate',1);
45
46   my $last_bill = $cust_pkg->last_bill;
47
48   return (0, '') if $$sdate == $last_bill;
49
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;
53
54   my $recur_charge = $self->option('svc_recur_fee') 
55                                    * ( $svc_end - $svc_start )
56                                    / ( $$sdate  - $last_bill );
57
58   return (0, '') unless $recur_charge;
59
60   my $svc_details .= ' ('.  time2str('%x', $svc_start).
61                   ' - '. time2str('%x', $svc_end  ). ')';
62
63   ( $recur_charge, $svc_details );
64
65 }
66
67 1;
68