summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2012-03-24 16:53:33 -0700
committerIvan Kohler <ivan@freeside.biz>2012-03-24 16:53:33 -0700
commit9b759823046afe536b25144726cdbfadbe56b206 (patch)
tree0f212bed6e9b075761dc2fae0aca5e4fb3ebb633
parent07900013773a1a62d6da920644d9fddf6ea01ede (diff)
parentbb6b1e9ed5209a5e28e55c6a7b3a1034575d49b9 (diff)
Merge branch 'master' of git.freeside.biz:/home/git/freeside
-rw-r--r--FS/FS/part_pkg/discount_Mixin.pm4
-rw-r--r--FS/FS/part_pkg/prorate_Mixin.pm21
-rwxr-xr-xFS/FS/svc_broadband.pm48
3 files changed, 47 insertions, 26 deletions
diff --git a/FS/FS/part_pkg/discount_Mixin.pm b/FS/FS/part_pkg/discount_Mixin.pm
index 335ff6d0f..1edf258d6 100644
--- a/FS/FS/part_pkg/discount_Mixin.pm
+++ b/FS/FS/part_pkg/discount_Mixin.pm
@@ -84,7 +84,9 @@ sub calc_discount {
$amount += $discount->amount
if $cust_pkg->pkgpart == $param->{'real_pkgpart'};
$amount += sprintf('%.2f', $discount->percent * $br / 100 );
- my $chg_months = $param->{'months'} || $cust_pkg->part_pkg->freq;
+ my $chg_months = defined($param->{'months'}) ?
+ $param->{'months'} :
+ $cust_pkg->part_pkg->freq;
my $months = $discount->months
? min( $chg_months,
diff --git a/FS/FS/part_pkg/prorate_Mixin.pm b/FS/FS/part_pkg/prorate_Mixin.pm
index 0f40576be..a01b5c409 100644
--- a/FS/FS/part_pkg/prorate_Mixin.pm
+++ b/FS/FS/part_pkg/prorate_Mixin.pm
@@ -2,7 +2,7 @@ package FS::part_pkg::prorate_Mixin;
use strict;
use vars qw( %info );
-use Time::Local qw( timelocal );
+use Time::Local qw( timelocal timelocal_nocheck );
use Date::Format qw( time2str );
%info = (
@@ -202,28 +202,17 @@ sub _endpoints {
}
my $mend;
my $mstart;
- # if cutoff day > 28, force it to the 1st of next month
- if ( $cutoff_day > 28 ) {
- $cutoff_day = 1;
- # and if we are currently after the 28th, roll the current day
- # forward to that day
- if ( $mday > 28 ) {
- $mday = 1;
- #set $mnow = $mend so the amount billed will be zero
- $mnow = timelocal(0,0,0,1,$mon == 11 ? 0 : $mon + 1,$year+($mon==11));
- }
- }
if ( $mday >= $cutoff_day ) {
$mend =
- timelocal(0,0,0,$cutoff_day,$mon == 11 ? 0 : $mon + 1,$year+($mon==11));
+ timelocal_nocheck(0,0,0,$cutoff_day,$mon == 11 ? 0 : $mon + 1,$year+($mon==11));
$mstart =
- timelocal(0,0,0,$cutoff_day,$mon,$year);
+ timelocal_nocheck(0,0,0,$cutoff_day,$mon,$year);
}
else {
$mend =
- timelocal(0,0,0,$cutoff_day,$mon,$year);
+ timelocal_nocheck(0,0,0,$cutoff_day,$mon,$year);
$mstart =
- timelocal(0,0,0,$cutoff_day,$mon == 0 ? 11 : $mon - 1,$year-($mon==0));
+ timelocal_nocheck(0,0,0,$cutoff_day,$mon == 0 ? 11 : $mon - 1,$year-($mon==0));
}
return ($mnow, $mend, $mstart);
}
diff --git a/FS/FS/svc_broadband.pm b/FS/FS/svc_broadband.pm
index 06a300138..2b6be2c6c 100755
--- a/FS/FS/svc_broadband.pm
+++ b/FS/FS/svc_broadband.pm
@@ -464,7 +464,7 @@ sub assign_ip_addr {
my @blocks;
my $ip_addr;
- if ( $self->blocknum and $self->addr_block->routernum == $self->routernum ) {
+ if ( $self->addr_block and $self->addr_block->routernum == $self->routernum ) {
# simple case: user chose a block, find an address in that block
# (this overrides an existing IP address if it's not in the block)
@blocks = ($self->addr_block);
@@ -483,15 +483,13 @@ sub assign_ip_addr {
return '';
}
$ip_addr = $block->next_free_addr;
- last if $ip_addr;
- }
- if ( $ip_addr ) {
- $self->set(ip_addr => $ip_addr->addr);
- return '';
- }
- else {
- return 'No IP address available on this router';
+ if ( $ip_addr ) {
+ $self->set(ip_addr => $ip_addr->addr);
+ $self->set(blocknum => $block->blocknum);
+ return '';
+ }
}
+ return 'No IP address available on this router';
}
=item assign_router
@@ -668,6 +666,38 @@ sub _upgrade_data {
": no routernum in address block ".$addr_block->cidr.", skipped\n";
}
}
+
+ # assign blocknums to services that should have them
+ my @all_blocks = qsearch('addr_block', { });
+ SVC: foreach my $self (
+ qsearch({
+ 'select' => 'svc_broadband.*',
+ 'table' => 'svc_broadband',
+ 'addl_from' => 'JOIN router USING (routernum)',
+ 'hashref' => {},
+ 'extra_sql' => 'WHERE svc_broadband.blocknum IS NULL '.
+ 'AND router.manual_addr IS NULL',
+ })
+ ) {
+
+ next SVC if $self->ip_addr eq '';
+ my $NetAddr = $self->NetAddr;
+ # inefficient, but should only need to run once
+ foreach my $block (@all_blocks) {
+ if ($block->NetAddr->contains($NetAddr)) {
+ $self->set(blocknum => $block->blocknum);
+ my $error = $self->replace;
+ warn "WARNING: error assigning blocknum ".$block->blocknum.
+ " to service ".$self->svcnum."\n$error; skipped\n"
+ if $error;
+ next SVC;
+ }
+ }
+ warn "WARNING: no block found containing ".$NetAddr->addr." for service ".
+ $self->svcnum;
+ #next SVC;
+ }
+
'';
}