X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg.pm;h=f2c3cccf59ffdcc48a8a294ec94627e41158aac2;hb=42682206b4ba30de01c82743042f5fb9d48a93ed;hp=7b85bdfdd5a12059c383fc010ae97079787fbace;hpb=e605a0b7181ac66bcf8a74de117efc87e869c978;p=freeside.git diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 7b85bdfdd..f2c3cccf5 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -14,7 +14,6 @@ use FS::cust_svc; use FS::part_pkg; use FS::cust_main; use FS::cust_location; -use FS::type_pkgs; use FS::pkg_svc; use FS::cust_bill_pkg; use FS::cust_pkg_detail; @@ -440,9 +439,7 @@ replace methods. sub check { my $self = shift; - $self->locationnum('') - if defined($self->locationnum) && length($self->locationnum) - && ( $self->locationnum == 0 || $self->locationnum == -1 ); + $self->locationnum('') if !$self->locationnum || $self->locationnum == -1; my $error = $self->ut_numbern('pkgnum') @@ -1138,6 +1135,21 @@ sub change { return "Unable to transfer all services from package ". $self->pkgnum; } + #reset usage if changing pkgpart + if ($self->pkgpart != $cust_pkg->pkgpart) { + my $part_pkg = $cust_pkg->part_pkg; + $error = $part_pkg->reset_usage($cust_pkg, $part_pkg->is_prepaid + ? () + : ( 'null' => 1 ) + ) + if $part_pkg->can('reset_usage'); + + if ($error) { + $dbh->rollback if $oldAutoCommit; + return "Error setting usage values: $error"; + } + } + #Good to go, cancel old package. $error = $self->cancel( quiet=>1 ); if ($error) { @@ -2366,10 +2378,11 @@ sub location_sql { # '?' placeholders in _location_sql_where my @bill_param; if ( $ornull ) { - @bill_param = qw( county county county state state state country ); + @bill_param = qw( county county state state state country ); } else { - @bill_param = qw( county county state state country ); + @bill_param = qw( county state state country ); } + unshift @bill_param, 'county'; # unless $nec; my $main_where; my @main_param; @@ -2380,7 +2393,7 @@ sub location_sql { AND ". _location_sql_where('cust_main', '', $ornull ). " ) OR ( ship_last IS NOT NULL AND ship_last != '' - AND ". _location_sql_where('cust_main', 'ship_', $ornull). " + AND ". _location_sql_where('cust_main', 'ship_', $ornull ). " ) )"; # AND payby != 'COMP' @@ -2398,10 +2411,13 @@ sub location_sql { my @param; if ( $conf->exists('tax-pkg_address') ) { + my $loc_where = _location_sql_where( 'cust_location', '', $ornull ); + $where = " ( - ( cust_pkg.locationnum IS NULL AND $main_where ) - OR ( cust_pkg.locationnum IS NOT NULL AND ". _location_sql_where('cust_location', '', $ornull). " ) - )"; + ( cust_pkg.locationnum IS NULL AND $main_where ) + OR ( cust_pkg.locationnum IS NOT NULL AND $loc_where ) + ) + "; @param = ( @main_param, @bill_param ); } else { @@ -2415,15 +2431,22 @@ sub location_sql { } -#subroutine, helper for able +#subroutine, helper for location_sql sub _location_sql_where { - my $table = shift; + my $table = shift; my $prefix = @_ ? shift : ''; my $ornull = @_ ? shift : ''; + +# $ornull = $ornull ? " OR ( ? IS NULL AND $table.${prefix}county IS NULL ) " : ''; + $ornull = $ornull ? ' OR ? IS NULL ' : ''; + + my $or_empty_county = " OR ( ? = '' AND $table.${prefix}county IS NULL ) "; + my $or_empty_state = " OR ( ? = '' AND $table.${prefix}state IS NULL ) "; + " - ( $table.${prefix}county = ? OR ? = '' $ornull ) - AND ( $table.${prefix}state = ? OR ? = '' $ornull ) + ( $table.${prefix}county = ? $or_empty_county $ornull ) + AND ( $table.${prefix}state = ? $or_empty_state $ornull ) AND $table.${prefix}country = ? "; } @@ -2704,11 +2727,11 @@ All svc_accts which are part of this package have their values reset. =cut sub set_usage { - my ($self, $valueref) = @_; + my ($self, $valueref, %opt) = @_; foreach my $cust_svc ($self->cust_svc){ my $svc_x = $cust_svc->svc_x; - $svc_x->set_usage($valueref) + $svc_x->set_usage($valueref, %opt) if $svc_x->can("set_usage"); } }