}
}
- my $free_days = $part_pkg->option('free_days');
+ my $free_days = $part_pkg->option('free_days',1);
if ( $free_days && $part_pkg->option('delay_setup',1) ) { #&& !$self->start_date
my ($mday,$mon,$year) = (localtime(time) )[3,4,5];
#my $start_date = ($self->start_date || timelocal(0,0,0,$mday,$mon,$year)) + 86400 * $free_days;
#schwartz
map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
- map { [ $_, $_->svc_x->table_info->{'cancel_weight'} ]; }
+ map { [ $_, $_->svc_x ? $_->svc_x->table_info->{'cancel_weight'} : -1 ]; }
qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
) {
my $part_svc = $cust_svc->part_svc;
}
}
+ my %hash = $self->hash;
+ if ( $date ) {
+ $hash{'adjourn'} = $date;
+ } else {
+ $hash{'susp'} = $suspend_time;
+ }
+ my $new = new FS::cust_pkg ( \%hash );
+ $error = $new->replace( $self, options => { $self->options } );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
unless ( $date ) {
my @labels = ();
}
- my %hash = $self->hash;
- if ( $date ) {
- $hash{'adjourn'} = $date;
- } else {
- $hash{'susp'} = $suspend_time;
- }
- my $new = new FS::cust_pkg ( \%hash );
- $error = $new->replace( $self, options => { $self->options } );
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
- }
-
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
''; #no errors
$sth->fetchrow_arrayref->[0];
}
-=item cust_svc [ SVCPART ]
+=item cust_svc [ SVCPART ] (old, deprecated usage)
+
+=item cust_svc [ OPTION => VALUE ... ] (current usage)
Returns the services for this package, as FS::cust_svc objects (see
-L<FS::cust_svc>). If a svcpart is specified, return only the matching
-services.
+L<FS::cust_svc>). Available options are svcpart and svcdb. If either is
+spcififed, returns only the matching services.
=cut
return () unless $self->num_cust_svc(@_);
- if ( @_ ) {
- return qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum,
- 'svcpart' => shift, } );
+ my %opt = ();
+ if ( @_ && $_[0] =~ /^\d+/ ) {
+ $opt{svcpart} = shift;
+ } elsif ( @_ && ref($_[0]) eq 'HASH' ) {
+ %opt = %{ $_[0] };
+ } elsif ( @_ ) {
+ %opt = @_;
+ }
+
+ my %search = (
+ 'table' => 'cust_svc',
+ 'hashref' => { 'pkgnum' => $self->pkgnum },
+ );
+ if ( $opt{svcpart} ) {
+ $search{hashref}->{svcpart} = $opt{'svcpart'};
+ }
+ if ( $opt{'svcdb'} ) {
+ $search{addl_from} = ' LEFT JOIN part_svc USING ( svcpart ) ';
+ $search{hashref}->{svcdb} = $opt{'svcdb'};
}
cluck "cust_pkg->cust_svc called" if $DEBUG > 2;
#if ( $self->{'_svcnum'} ) {
# values %{ $self->{'_svcnum'}->cache };
#} else {
- $self->_sort_cust_svc(
- [ qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } ) ]
- );
+ $self->_sort_cust_svc( [ qsearch(\%search) ] );
#}
}
}
-=item num_cust_svc [ SVCPART ]
+=item num_cust_svc [ SVCPART ] (old, deprecated usage)
-Returns the number of provisioned services for this package. If a svcpart is
-specified, counts only the matching services.
+=item num_cust_svc [ OPTION => VALUE ... ] (current usage)
+
+Returns the number of services for this package. Available options are svcpart
+and svcdb. If either is spcififed, returns only the matching services.
=cut
cluck "cust_pkg->num_cust_svc called, _num_cust_svc:".$self->{'_num_cust_svc'}
if $DEBUG > 2;
- my $sql = 'SELECT COUNT(*) FROM cust_svc WHERE pkgnum = ?';
- $sql .= ' AND svcpart = ?' if @_;
+ my %opt = ();
+ if ( @_ && $_[0] =~ /^\d+/ ) {
+ $opt{svcpart} = shift;
+ } elsif ( @_ && ref($_[0]) eq 'HASH' ) {
+ %opt = %{ $_[0] };
+ } elsif ( @_ ) {
+ %opt = @_;
+ }
+
+ my $select = 'SELECT COUNT(*) FROM cust_svc ';
+ my $where = ' WHERE pkgnum = ? ';
+ my @param = ($self->pkgnum);
+
+ if ( $opt{'svcpart'} ) {
+ $where .= ' AND svcpart = ? ';
+ push @param, $opt{'svcpart'};
+ }
+ if ( $opt{'svcdb'} ) {
+ $select .= ' LEFT JOIN part_svc USING ( svcpart ) ';
+ $where .= ' AND svcdb = ? ';
+ push @param, $opt{'svcdb'};
+ }
- my $sth = dbh->prepare($sql) or die dbh->errstr;
- $sth->execute($self->pkgnum, @_) or die $sth->errstr;
+ my $sth = dbh->prepare("$select $where") or die dbh->errstr;
+ $sth->execute(@param) or die $sth->errstr;
$sth->fetchrow_arrayref->[0];
}
$self->part_pkg->pkg_svc;
}
-=item part_svc
+=item part_svc [ OPTION => VALUE ... ]
Returns a list of FS::part_svc objects representing provisioned and available
services included in this package. Each FS::part_svc object also has the
=item cust_pkg_svc (services) - array reference containing the provisioned services, as cust_svc objects
-svcnum
-label -> ($cust_svc->label)[1]
-
=back
+Accepts one option: summarize_size. If specified and non-zero, will omit the
+extra cust_pkg_svc option for objects where num_cust_svc is this size or
+greater.
+
=cut
+#svcnum
+#label -> ($cust_svc->label)[1]
+
sub part_svc {
my $self = shift;
+ my %opt = @_;
#XXX some sort of sort order besides numeric by svcpart...
my @part_svc = sort { $a->svcpart <=> $b->svcpart } map {
$part_svc->{'Hash'}{'num_avail'} =
max( 0, $pkg_svc->quantity - $num_cust_svc );
$part_svc->{'Hash'}{'cust_pkg_svc'} =
- $num_cust_svc ? [ $self->cust_svc($part_svc->svcpart) ] : [];
+ $num_cust_svc ? [ $self->cust_svc($part_svc->svcpart) ] : []
+ unless exists($opt{summarize_size}) && $opt{summarize_size} > 0
+ && $num_cust_svc >= $opt{summarize_size};
$part_svc->{'Hash'}{'hidden'} = $pkg_svc->hidden;
$part_svc;
} $self->part_pkg->pkg_svc;
sub set_usage {
my ($self, $valueref, %opt) = @_;
- foreach my $cust_svc ($self->cust_svc){
+ #only svc_acct can set_usage for now
+ foreach my $cust_svc ( $self->cust_svc( 'svcdb'=>'svc_acct' ) ) {
my $svc_x = $cust_svc->svc_x;
$svc_x->set_usage($valueref, %opt)
if $svc_x->can("set_usage");
sub recharge {
my ($self, $valueref) = @_;
- foreach my $cust_svc ($self->cust_svc){
+ #only svc_acct can set_usage for now
+ foreach my $cust_svc ( $self->cust_svc( 'svcdb'=>'svc_acct' ) ) {
my $svc_x = $cust_svc->svc_x;
$svc_x->recharge($valueref)
if $svc_x->can("recharge");
} @report_option;
}
- my @report_option_any = ();
- if ( exists($params->{'report_option_any'}) ) {
- if ( ref($params->{'report_option_any'}) eq 'ARRAY' ) {
- @report_option_any = @{ $params->{'report_option_any'} };
- } elsif ( $params->{'report_option_any'} =~ /^([,\d]*)$/ ) {
+ foreach my $any ( grep /^report_option_any/, keys %$params ) {
+
+ my @report_option_any = ();
+ if ( ref($params->{$any}) eq 'ARRAY' ) {
+ @report_option_any = @{ $params->{$any} };
+ } elsif ( $params->{$any} =~ /^([,\d]*)$/ ) {
@report_option_any = split(',', $1);
}
- }
+ if (@report_option_any) {
+ # this will result in the empty set for the dangling comma case as it should
+ push @where, ' ( '. join(' OR ',
+ map{ "0 < ( SELECT count(*) FROM part_pkg_option
+ WHERE part_pkg_option.pkgpart = part_pkg.pkgpart
+ AND optionname = 'report_option_$_'
+ AND optionvalue = '1' )"
+ } @report_option_any
+ ). ' ) ';
+ }
- if (@report_option_any) {
- # this will result in the empty set for the dangling comma case as it should
- push @where, ' ( '. join(' OR ',
- map{ "0 < ( SELECT count(*) FROM part_pkg_option
- WHERE part_pkg_option.pkgpart = part_pkg.pkgpart
- AND optionname = 'report_option_$_'
- AND optionvalue = '1' )"
- } @report_option_any
- ). ' ) ';
}
###