X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fflat.pm;h=bed86cc8d7a071d0f78d93a6736984ed0f283cca;hb=33f3d32f1d13b8342f208f8633f5f9a3a7bcb392;hp=131f850e9a59f36e6a9e2c997ff080fc5d7be9bd;hpb=e4ae5122522f2d45c68a38eaef337a82029f2fc1;p=freeside.git diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm index 131f850e9..bed86cc8d 100644 --- a/FS/FS/part_pkg/flat.pm +++ b/FS/FS/part_pkg/flat.pm @@ -20,10 +20,11 @@ use FS::part_pkg; ' of service at cancellation', 'type' => 'checkbox', }, + 'externalid' => { 'name' => 'Optional External ID', + 'default' => '', + }, }, - 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit' ], - #'setup' => 'what.setup_fee.value', - #'recur' => 'what.recur_fee.value', + 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit', 'externalid' ], 'weight' => 10, ); @@ -44,37 +45,37 @@ sub base_recur { sub calc_remain { my ($self, $cust_pkg) = @_; - my $time = time; + my $time = time; #should be able to pass this in for credit calculation my $next_bill = $cust_pkg->getfield('bill') || 0; my $last_bill = $cust_pkg->last_bill || 0; return 0 if ! $self->base_recur - || ! $self->option('unused_credit') + || ! $self->option('unused_credit', 1) || ! $last_bill - || ! $next_bill; + || ! $next_bill + || $next_bill < $time; - my $now_date = ParseDate("epoch $time"); - my $last_date = ParseDate("epoch $last_bill"); - my $next_date = ParseDate("epoch $next_bill"); - my $err; - my $delta = DateCalc($now_date,$next_date,\$err, 0); - my $days_remaining = Delta_Format($delta, 4, "%dh"); + my %sec = ( + 'h' => 3600, # 60 * 60 + 'd' => 86400, # 60 * 60 * 24 + 'w' => 604800, # 60 * 60 * 24 * 7 + 'm' => 2629744, # 60 * 60 * 24 * 365.2422 / 12 + ); - my $frequency = $self->freq; + $self->freq =~ /^(\d+)([hdwm]?)$/ + or die 'unparsable frequency: '. $self->freq; + my $freq_sec = $1 * $sec{$2||'m'}; + return 0 unless $freq_sec; - # TODO: Remove this after the frequencies are Data::Manip friendly. - $frequency .= "m" unless $frequency =~ /[wd]$/; + sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec ); - my $freq_delta = ParseDateDelta($frequency); - my $days = Delta_Format($freq_delta,4,"%dh"); - - my $recurring= $self->base_recur; - my $daily = $recurring/$days; - - sprintf("%.2f",($daily * $days_remaining)); } sub is_free_options { qw( setup_fee recur_fee ); } +sub is_prepaid { + 0; #no, we're postpaid +} + 1;