Merge remote-tracking branch 'upstream/master'
authorRob Van Dam <rvandam00@gmail.com>
Thu, 7 Nov 2013 22:27:24 +0000 (15:27 -0700)
committerRob Van Dam <rvandam00@gmail.com>
Thu, 7 Nov 2013 22:27:24 +0000 (15:27 -0700)
Conflicts:
FS/FS/cust_pkg.pm

1  2 
FS/FS/cust_pkg.pm

diff --combined FS/FS/cust_pkg.pm
@@@ -4,6 -4,7 +4,6 @@@ use base qw( FS::otaker_Mixin FS::cust_
               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);
@@@ -48,8 -49,13 +48,10 @@@ 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;
    my ( $hashref, $cache ) = @_;
@@@ -292,40 -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) );
 -  }
 +  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) );
 +    }
  
 -  # 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) );
 +    # 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 );
 +    # 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';
  
    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
                 );
    }
  
 -  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',
      };
@@@ -655,7 -658,7 +657,7 @@@ sub check 
    return $error if $error;
  
    return "A package with both start date (future start) and setup date (already started) will never bill"
-     if $self->start_date && $self->setup;
+     if $self->start_date && $self->setup && ! $upgrade;
  
    return "A future unsuspend date can only be set for a package with a suspend date"
      if $self->resume and !$self->susp and !$self->adjourn;
@@@ -4282,6 -4285,32 +4284,32 @@@ boolean; if true, returns only package
  Limit to packages with a service location in the specified state and country.
  For FCC 477 reporting, mostly.
  
+ =item location_cust
+ Limit to packages whose service locations are the same as the customer's 
+ default service location.
+ =item location_nocust
+ Limit to packages whose service locations are not the customer's default 
+ service location.
+ =item location_census
+ Limit to packages whose service locations have census tracts.
+ =item location_nocensus
+ 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
  
  =cut
@@@ -4514,6 -4543,22 +4542,22 @@@ sub search 
    }
  
    ###
+   # location_* flags
+   ###
+   if ( $params->{location_cust} xor $params->{location_nocust} ) {
+     my $op = $params->{location_cust} ? '=' : '!=';
+     push @where, "cust_location.locationnum $op cust_main.ship_locationnum";
+   }
+   if ( $params->{location_census} xor $params->{location_nocensus} ) {
+     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
    ###