diff options
Diffstat (limited to 'FS')
| -rw-r--r-- | FS/FS/Schema.pm | 33 | ||||
| -rw-r--r-- | FS/FS/cust_pkg.pm | 24 | 
2 files changed, 42 insertions, 15 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index fb065be15..a343a38db 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -642,22 +642,29 @@ sub tables_hashref {      'cust_pkg' => {        'columns' => [ -        'pkgnum',    'serial',    '',   '', '', '',  -        'custnum',   'int',    '',   '', '', '',  -        'pkgpart',   'int',    '',   '', '', '',  -        'otaker',    'varchar', '', 32, '', '',  -        'setup',     @date_type, '', '',  -        'bill',      @date_type, '', '',  -        'last_bill', @date_type, '', '',  -        'susp',      @date_type, '', '',  -        'adjourn',   @date_type, '', '',  -        'cancel',    @date_type, '', '',  -        'expire',    @date_type, '', '',  -        'manual_flag', 'char', 'NULL', 1, '', '',  +        'pkgnum',         'serial',    '',   '', '', '',  +        'custnum',        'int',    '',   '', '', '',  +        'pkgpart',        'int',    '',   '', '', '',  +        'otaker',         'varchar', '', 32, '', '',  +        'setup',          @date_type, '', '',  +        'bill',           @date_type, '', '',  +        'last_bill',      @date_type, '', '',  +        'susp',           @date_type, '', '',  +        'adjourn',        @date_type, '', '',  +        'cancel',         @date_type, '', '',  +        'expire',         @date_type, '', '',  +        'change_date',    @date_type, '', '', +        'change_pkgnum',  'int', 'NULL', '', '', '', +        'change_pkgpart', 'int', 'NULL', '', '', '', +        'manual_flag',    'char', 'NULL', 1, '', '',         ],        'primary_key' => 'pkgnum',        'unique' => [], -      'index' => [ ['custnum'], ['pkgpart'] ], +      'index' => [ ['custnum'], ['pkgpart'], +                   ['setup'], ['last_bill'], ['bill'], ['susp'], ['adjourn'], +                   ['expire'], ['cancel'], +                   ['change_date'], +                 ],      },      'cust_pkg_option' => { diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index a64d01464..444282ceb 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -737,6 +737,18 @@ sub part_pkg {      : qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );  } +=item old_cust_pkg + +Returns the cancelled package this package was changed from, if any. + +=cut + +sub old_cust_pkg { +  my $self = shift; +  return '' unless $self->change_pkgnum; +  qsearchs('cust_pkg', { 'pkgnum' => $self->change_pkgnum } ); +} +  =item calc_setup  Calls the I<calc_setup> of the FS::part_pkg object associated with this billing @@ -1495,9 +1507,17 @@ sub order {    my $change = scalar(@old_cust_pkg) != 0;    my %hash = ();  -  if ( scalar(@old_cust_pkg) == 1 ) { +  if ( scalar(@old_cust_pkg) == 1 && scalar(@$pkgparts) == 1 ) { + +    my $time = time; +      #$hash{$_} = $old_cust_pkg[0]->$_() foreach qw( last_bill bill ); -    $hash{'setup'} = time; +     +    #$hash{$_} = $old_cust_pkg[0]->$_() foreach qw( setup ); +    $hash{'setup'} = $time if $old_cust_pkg[0]->setup; + +    $hash{'change_date'} = $time; +    $hash{"change_$_"}  = $old_cust_pkg[0]->$_() foreach qw( pkgnum pkgpart );    }    # Create the new packages.  | 
