package FS::cust_pkg;
use strict;
-use base qw( FS::cust_main_Mixin FS::location_Mixin
- FS::m2m_Common FS::option_Common FS::Record
- );
-use vars qw(@ISA $disable_agentcheck $DEBUG $me);
+use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::location_Mixin
+ FS::m2m_Common FS::option_Common FS::Record );
+use vars qw($disable_agentcheck $DEBUG $me);
use Carp qw(cluck);
use Scalar::Util qw( blessed );
use List::Util qw(max);
date
-=item otaker
+=item usernum
-order taker (assigned automatically if null, see L<FS::UID>)
+order taker (see L<FS::access_user>)
=item manual_flag
sub insert {
my( $self, %options ) = @_;
- if ( $self->part_pkg->option('start_1st') && !$self->start_date ) {
+ if ( $self->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) );
}
- my $expire_months = $self->part_pkg->option('expire_months');
+ my $expire_months = $self->part_pkg->option('expire_months', 1);
if ( $expire_months && !$self->expire ) {
my $start = $self->start_date || $self->setup || time;
: { @_ };
#return "Can't (yet?) change pkgpart!" if $old->pkgpart != $new->pkgpart;
- return "Can't change otaker!" if $old->otaker ne $new->otaker;
+ #return "Can't change otaker!" if $old->otaker ne $new->otaker;
#allow this *sigh*
#return "Can't change setup once it exists!"
|| $self->ut_numbern('cancel')
|| $self->ut_numbern('adjourn')
|| $self->ut_numbern('expire')
+ || $self->ut_enum('no_auto', [ '', 'Y' ])
;
return $error if $error;
}
$self->otaker(getotaker) unless $self->otaker;
- $self->otaker =~ /^(\w{1,32})$/ or return "Illegal otaker";
- $self->otaker($1);
if ( $self->dbdef_table->column('manual_flag') ) {
$self->manual_flag('') if $self->manual_flag eq ' ';
#seems to benchmark slightly faster...
qsearch( {
- 'select' => 'DISTINCT ON (svcpart) part_svc.*',
+ #'select' => 'DISTINCT ON (svcpart) part_svc.*',
+ #MySQL doesn't grok DISINCT ON
+ 'select' => 'DISTINCT part_svc.*',
'table' => 'part_svc',
'addl_from' =>
'LEFT JOIN pkg_svc ON ( pkg_svc.svcpart = part_svc.svcpart
specifies the user for agent virtualization
+=item fcc_line
+
+ boolean selects packages containing fcc form 477 telco lines
+
=back
=cut
push @where, "part_pkg.custom = 'Y'" if $params->{custom};
+ ###
+ # parse fcc_line
+ ###
+
+ push @where, "part_pkg.fcc_ds0s > 0" if $params->{fcc_line};
+
###
# parse censustract
###
'' => {},
);
- foreach my $field (qw( setup last_bill bill adjourn susp expire cancel )) {
+ if( exists($params->{'active'} ) ) {
+ # This overrides all the other date-related fields
+ my($beginning, $ending) = @{$params->{'active'}};
+ push @where,
+ "cust_pkg.setup IS NOT NULL",
+ "cust_pkg.setup <= $ending",
+ "(cust_pkg.cancel IS NULL OR cust_pkg.cancel >= $beginning )",
+ "NOT (".FS::cust_pkg->onetime_sql . ")";
+ }
+ else {
+ foreach my $field (qw( setup last_bill bill adjourn susp expire cancel )) {
- next unless exists($params->{$field});
+ next unless exists($params->{$field});
- my($beginning, $ending) = @{$params->{$field}};
+ my($beginning, $ending) = @{$params->{$field}};
- next if $beginning == 0 && $ending == 4294967295;
+ next if $beginning == 0 && $ending == 4294967295;
- push @where,
- "cust_pkg.$field IS NOT NULL",
- "cust_pkg.$field >= $beginning",
- "cust_pkg.$field <= $ending";
+ push @where,
+ "cust_pkg.$field IS NOT NULL",
+ "cust_pkg.$field >= $beginning",
+ "cust_pkg.$field <= $ending";
- $orderby ||= "ORDER BY cust_pkg.$field";
+ $orderby ||= "ORDER BY cust_pkg.$field";
+ }
}
$orderby ||= 'ORDER BY bill';
}
+=item fcc_477_count
+
+Returns a list of two package counts. The first is a count of packages
+based on the supplied criteria and the second is the count of residential
+packages with those same criteria. Criteria are specified as in the search
+method.
+
+=cut
+
+sub fcc_477_count {
+ my ($class, $params) = @_;
+
+ my $sql_query = $class->search( $params );
+
+ my $count_sql = delete($sql_query->{'count_query'});
+ $count_sql =~ s/ FROM/,count(CASE WHEN cust_main.company IS NULL OR cust_main.company = '' THEN 1 END) FROM/
+ or die "couldn't parse count_sql";
+
+ my $count_sth = dbh->prepare($count_sql)
+ or die "Error preparing $count_sql: ". dbh->errstr;
+ $count_sth->execute
+ or die "Error executing $count_sql: ". $count_sth->errstr;
+ my $count_arrayref = $count_sth->fetchrow_arrayref;
+
+ return ( @$count_arrayref );
+
+}
+
+
=item location_sql
Returns a list: the first item is an SQL fragment identifying matching
'';
}
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data { # class method
+ my ($class, %opts) = @_;
+ $class->_upgrade_otaker(%opts);
+}
+
=back
=head1 BUGS