1 package FS::part_pkg::bulk;
4 use vars qw(@ISA $DEBUG $me %info);
6 use FS::part_pkg::flat;
8 @ISA = qw(FS::part_pkg::flat);
11 $me = '[FS::part_pkg::bulk]';
14 'name' => 'Bulk billing based on number of active services',
16 'setup_fee' => { 'name' => 'Setup fee for the entire bulk package',
19 'recur_fee' => { 'name' => 'Recurring fee for the entire bulk package',
22 'svc_setup_fee' => { 'name' => 'Setup fee for each new service',
25 'svc_recur_fee' => { 'name' => 'Recurring fee for each service',
28 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
29 ' of service at cancellation',
33 'fieldorder' => [ 'setup_fee', 'recur_fee', 'svc_setup_fee', 'svc_recur_fee',
38 #some false laziness-ish w/agent.pm... not a lot
40 my($self, $cust_pkg, $sdate, $details ) = @_;
42 my $conf = new FS::Conf;
43 my $money_char = $conf->config('money_char') || '$';
45 my $svc_setup_fee = $self->option('svc_setup_fee');
47 my $last_bill = $cust_pkg->last_bill;
49 return sprintf("%.2f", $self->base_recur($cust_pkg) )
50 unless $$sdate > $last_bill;
52 my $total_svc_charge = 0;
54 warn "$me billing for bulk services from ". time2str('%x', $last_bill).
55 " to ". time2str('%x', $$sdate). "\n"
59 foreach my $h_cust_svc ( $cust_pkg->h_cust_svc( $$sdate, $last_bill ) ) {
61 my @label = $h_cust_svc->label_long( $$sdate, $last_bill );
62 die "fatal: no historical label found, wtf?" unless scalar(@label); #?
63 my $svc_details = $label[0]. ': '. $label[1]. ': ';
67 my $svc_start = $h_cust_svc->date_inserted;
68 if ( $svc_start < $last_bill ) {
69 $svc_start = $last_bill;
70 } elsif ( $svc_setup_fee ) {
71 $svc_charge += $svc_setup_fee;
72 $svc_details .= $money_char. sprintf('%.2f setup, ', $svc_setup_fee);
75 my $svc_end = $h_cust_svc->date_deleted;
76 $svc_end = ( !$svc_end || $svc_end > $$sdate ) ? $$sdate : $svc_end;
79 $self->option('svc_recur_fee') * ( $svc_end - $svc_start )
80 / ( $$sdate - $last_bill );
82 $svc_details .= $money_char. sprintf('%.2f', $recur_charge ).
83 ' ('. time2str('%x', $svc_start).
84 ' - '. time2str('%x', $svc_end ). ')'
87 $svc_charge += $recur_charge;
89 push @$details, $svc_details;
90 $total_svc_charge += $svc_charge;
94 sprintf('%.2f', $self->base_recur($cust_pkg) + $total_svc_charge );
97 sub can_discount { 0; }
103 sub is_free_options {
104 qw( setup_fee recur_fee svc_setup_fee svc_recur_fee );