X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg.pm;h=afdd41d59fd83dc46515bcf4ad8c770bf91dfef6;hb=4d75191d9cc9ef91b82cd6ff4be96cdc8f82e480;hp=face10a5a8b2c113f77c47da0ab34c1ab7433687;hpb=e69b549276439ab52dc6eadcbeaf3b5409926edb;p=freeside.git diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index face10a5a..afdd41d59 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -4,7 +4,6 @@ use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::Sales_Mixin FS::m2m_Common FS::option_Common ); use strict; -use vars qw( $disable_agentcheck $DEBUG $me $upgrade ); use Carp qw(cluck); use Scalar::Util qw( blessed ); use List::Util qw(min max); @@ -49,12 +48,9 @@ use FS::svc_forward; # for sending cancel emails in sub cancel use FS::Conf; -$DEBUG = 0; -$me = '[FS::cust_pkg]'; +our ($disable_agentcheck, $DEBUG, $me, $import) = (0, 0, '[FS::cust_pkg]', 0); -$disable_agentcheck = 0; - -$upgrade = 0; #go away after setup+start dates cleaned up for old customers +our $upgrade = 0; #go away after setup+start dates cleaned up for old customers sub _cache { my $self = shift; @@ -298,37 +294,40 @@ sub insert { my $part_pkg = $self->part_pkg; - # if the package def says to start only on the first of the month: - if ( $part_pkg->option('start_1st', 1) && !$self->start_date ) { - my ($sec,$min,$hour,$mday,$mon,$year) = (localtime(time) )[0,1,2,3,4,5]; - $mon += 1 unless $mday == 1; - until ( $mon < 12 ) { $mon -= 12; $year++; } - $self->start_date( timelocal_nocheck(0,0,0,1,$mon,$year) ); - } - - # set up any automatic expire/adjourn/contract_end timers - # based on the start date - foreach my $action ( qw(expire adjourn contract_end) ) { - my $months = $part_pkg->option("${action}_months",1); - if($months and !$self->$action) { - my $start = $self->start_date || $self->setup || time; - $self->$action( $part_pkg->add_freq($start, $months) ); + if (! $import) { + # if the package def says to start only on the first of the month: + if ( $part_pkg->option('start_1st', 1) && !$self->start_date ) { + my ($sec,$min,$hour,$mday,$mon,$year) = (localtime(time) )[0,1,2,3,4,5]; + $mon += 1 unless $mday == 1; + until ( $mon < 12 ) { $mon -= 12; $year++; } + $self->start_date( timelocal_nocheck(0,0,0,1,$mon,$year) ); } - } - # if this package has "free days" and delayed setup fee, tehn - # set start date that many days in the future. - # (this should have been set in the UI, but enforce it here) - if ( ! $options{'change'} - && ( my $free_days = $part_pkg->option('free_days',1) ) - && $part_pkg->option('delay_setup',1) - #&& ! $self->start_date - ) - { - $self->start_date( $part_pkg->default_start_date ); + # set up any automatic expire/adjourn/contract_end timers + # based on the start date + foreach my $action ( qw(expire adjourn contract_end) ) { + my $months = $part_pkg->option("${action}_months",1); + if($months and !$self->$action) { + my $start = $self->start_date || $self->setup || time; + $self->$action( $part_pkg->add_freq($start, $months) ); + } + } + + # if this package has "free days" and delayed setup fee, tehn + # set start date that many days in the future. + # (this should have been set in the UI, but enforce it here) + if ( ! $options{'change'} + && ( my $free_days = $part_pkg->option('free_days',1) ) + && $part_pkg->option('delay_setup',1) + #&& ! $self->start_date + ) + { + $self->start_date( $part_pkg->default_start_date ); + } } - $self->order_date(time); + # set order date unless it was specified as part of an import + $self->order_date(time) unless $import && $self->order_date; local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -364,7 +363,7 @@ sub insert { my $conf = new FS::Conf; - if ( $conf->config('ticket_system') && $options{ticket_subject} ) { + if ( ! $import && $conf->config('ticket_system') && $options{ticket_subject} ) { #this init stuff is still inefficient, but at least its limited to # the small number (any?) folks using ticket emailing on pkg order @@ -394,7 +393,7 @@ sub insert { ); } - if ($conf->config('welcome_letter') && $self->cust_main->num_pkgs == 1) { + if (! $import && $conf->config('welcome_letter') && $self->cust_main->num_pkgs == 1) { my $queue = new FS::queue { 'job' => 'FS::cust_main::queueable_print', }; @@ -1860,7 +1859,7 @@ sub change { if ( $opt->{cust_main} ) { my $cust_main = $opt->{cust_main}; unless ( $cust_main->custnum ) { - my $error = $cust_main->insert; + my $error = $cust_main->insert( @{ $opt->{cust_main_insert_args}||[] } ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return "inserting cust_main (transaction rolled back): $error"; @@ -2751,12 +2750,12 @@ the results. sub cust_svc { my $self = shift; cluck "cust_pkg->cust_svc called" if $DEBUG > 2; - $self->_sort_cust_svc( $self->cust_svc_unsorted_arrayref ); + $self->_sort_cust_svc( $self->cust_svc_unsorted_arrayref(@_) ); } sub cust_svc_unsorted { my $self = shift; - @{ $self->cust_svc_unsorted_arrayref }; + @{ $self->cust_svc_unsorted_arrayref(@_) }; } sub cust_svc_unsorted_arrayref { @@ -3314,13 +3313,6 @@ sub _labels_short { Returns the parent customer object (see L). -=cut - -sub cust_main { - my $self = shift; - qsearchs( 'cust_main', { 'custnum' => $self->custnum } ); -} - =item balance Returns the balance for this specific package, when using @@ -3462,8 +3454,7 @@ sub attribute_since_sqlradacct { foreach my $cust_svc ( grep { my $part_svc = $_->part_svc; - $part_svc->svcdb eq 'svc_acct' - && scalar($part_svc->part_export_usage); + scalar($part_svc->part_export_usage); } $self->cust_svc ) { $sum += $cust_svc->attribute_since_sqlradacct($start, $end, $attrib); @@ -3867,13 +3858,6 @@ sub recharge { =item cust_pkg_discount -=cut - -sub cust_pkg_discount { - my $self = shift; - qsearch('cust_pkg_discount', { 'pkgnum' => $self->pkgnum } ); -} - =item cust_pkg_discount_active =cut @@ -3887,13 +3871,6 @@ sub cust_pkg_discount_active { Returns a list of all voice usage counters attached to this package. -=cut - -sub cust_pkg_usage { - my $self = shift; - qsearch('cust_pkg_usage', { pkgnum => $self->pkgnum }); -} - =item apply_usage OPTIONS Takes the following options: @@ -4287,21 +4264,29 @@ For FCC 477 reporting, mostly. =item location_cust -Limit to packages whose service location is the same as the customer's +Limit to packages whose service locations are the same as the customer's default service location. =item location_nocust -Limit to packages whose service location is not the customer's default +Limit to packages whose service locations are not the customer's default service location. =item location_census -Limit to packages whose service location has a census tract. +Limit to packages whose service locations have census tracts. =item location_nocensus -Limit to packages whose service location doesn't have a census tract. +Limit to packages whose service locations do not have a census tract. + +=item location_geocode + +Limit to packages whose locations have geocodes. + +=item location_geocode + +Limit to packages whose locations do not have geocodes. =back @@ -4545,6 +4530,10 @@ sub search { my $op = $params->{location_census} ? "IS NOT NULL" : "IS NULL"; push @where, "cust_location.censustract $op"; } + if ( $params->{location_geocode} xor $params->{location_nogeocode} ) { + my $op = $params->{location_geocode} ? "IS NOT NULL" : "IS NULL"; + push @where, "cust_location.geocode $op"; + } ### # parse part_pkg