X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fbulk.pm;h=7c81138c12ce9c7dec96dcd4328f984ec62726d3;hb=15e57a4859d967a13113602b112c4aa197ca6002;hp=3baae380fa16879f1e92354c71c67e0c1172b182;hpb=d4527a3d602aec05eff8b3caf99b65bf710caad1;p=freeside.git diff --git a/FS/FS/part_pkg/bulk.pm b/FS/FS/part_pkg/bulk.pm index 3baae380f..7c81138c1 100644 --- a/FS/FS/part_pkg/bulk.pm +++ b/FS/FS/part_pkg/bulk.pm @@ -1,12 +1,15 @@ package FS::part_pkg::bulk; use strict; -use vars qw(@ISA %info); +use vars qw(@ISA $DEBUG $me %info); use Date::Format; use FS::part_pkg::flat; @ISA = qw(FS::part_pkg::flat); +$DEBUG = 1; +$me = '[FS::part_pkg::bulk]'; + %info = ( 'name' => 'Bulk billing based on number of active services', 'fields' => { @@ -29,7 +32,7 @@ use FS::part_pkg::flat; }, 'fieldorder' => [ 'setup_fee', 'recur_fee', 'svc_setup_fee', 'svc_recur_fee', 'unused_credit', ], - 'weight' => 55, + 'weight' => 50, ); sub calc_recur { @@ -42,34 +45,44 @@ sub calc_recur { my $last_bill = $cust_pkg->last_bill; + return sprintf("%.2f", $self->base_recur($cust_pkg) ) + unless $$sdate > $last_bill; + my $total_svc_charge = 0; + warn "$me billing for bulk services from ". time2str('%x', $last_bill). + " to ". time2str('%x', $$sdate). "\n" + if $DEBUG; + # END START - foreach my $h_svc ( $cust_pkg->h_cust_svc( $$sdate, $last_bill ) ) { + foreach my $h_cust_svc ( $cust_pkg->h_cust_svc( $$sdate, $last_bill ) ) { + + my @label = $h_cust_svc->label_long( $$sdate, $last_bill ); + die "fatal: no historical label found, wtf?" unless scalar(@label); #? + my $svc_details = $label[0]. ': '. $label[1]. ': '; my $svc_charge = 0; - my $svc_details = $h_svc->label. ': '; - my $svc_start = $h_svc->date_inserted; + my $svc_start = $h_cust_svc->date_inserted; if ( $svc_start < $last_bill ) { $svc_start = $last_bill; } elsif ( $svc_setup_fee ) { $svc_charge += $svc_setup_fee; - $details .= $money_char. sprintf('%.2f setup, ', $svc_setup_fee); + $svc_details .= $money_char. sprintf('%.2f setup, ', $svc_setup_fee); } - my $svc_end = $h_svc->date_deleted; + my $svc_end = $h_cust_svc->date_deleted; $svc_end = ( !$svc_end || $svc_end > $$sdate ) ? $$sdate : $svc_end; $svc_charge = $self->option('svc_recur_fee') * ( $svc_end - $svc_start ) / ( $$sdate - $last_bill ); - $details .= $money_char. sprintf('%.2f', $svc_charge ). - ' ('. time2str('%x', $svc_start). - ' - '. time2str('%x', $svc_end ). ')' - if $self->option('svc_recur_fee'); + $svc_details .= $money_char. sprintf('%.2f', $svc_charge ). + ' ('. time2str('%x', $svc_start). + ' - '. time2str('%x', $svc_end ). ')' + if $self->option('svc_recur_fee'); - push @$details, $details; + push @$details, $svc_details; $total_svc_charge += $svc_charge; } @@ -77,7 +90,13 @@ sub calc_recur { sprintf("%.2f", $self->base_recur($cust_pkg) + $total_svc_charge ); } +sub hide_svc_detail { + 1; +} + sub is_free_options { qw( setup_fee recur_fee svc_setup_fee svc_recur_fee ); } +1; +