X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_svc.pm;h=01b8e10749547fc26b4ac37401179e3f9d9bdd15;hb=0141b002ab937b2b3a21a92c3728bc3101f4668a;hp=beea3f1bc60d6b4064e55e1b14188278aa0370de;hpb=fb7f3203c7d839ae3964d5e2cac71892422a10d1;p=freeside.git diff --git a/FS/FS/part_svc.pm b/FS/FS/part_svc.pm index beea3f1bc..01b8e1074 100644 --- a/FS/FS/part_svc.pm +++ b/FS/FS/part_svc.pm @@ -1,5 +1,6 @@ package FS::part_svc; +use base qw(FS::o2m_Common FS::Record); use strict; use vars qw( @ISA $DEBUG ); use Tie::IxHash; @@ -10,8 +11,7 @@ use FS::part_export; use FS::export_svc; use FS::cust_svc; use FS::part_svc_class; - -@ISA = qw(FS::Record); +use FS::part_svc_msgcat; $DEBUG = 0; @@ -146,9 +146,9 @@ sub insert { foreach my $field (fields($svcdb), @fields) { next if $field eq 'svcnum'; my $prefix = $svcdb.'__'; - if ( defined( $self->getfield($prefix.$_.'_flag')) - or defined($self->getfield($prefix.$_.'_required')) - or length($self->getfield($prefix.$_.'_label')) + if ( defined( $self->getfield($prefix.$field.'_flag')) + or defined($self->getfield($prefix.$field.'_required')) + or length($self->getfield($prefix.$field.'_label')) ) { my $part_svc_column = $self->part_svc_column($field); my $previous = qsearchs('part_svc_column', { @@ -285,9 +285,9 @@ sub replace { foreach my $field (fields($svcdb),@fields) { next if $field eq 'svcnum'; my $prefix = $svcdb.'__'; - if ( defined( $new->getfield($prefix.$_.'_flag')) - or defined($new->getfield($prefix.$_.'_required')) - or length($new->getfield($prefix.$_.'_label')) + if ( defined( $new->getfield($prefix.$field.'_flag')) + or defined($new->getfield($prefix.$field.'_required')) + or length($new->getfield($prefix.$field.'_label')) ) { my $part_svc_column = $new->part_svc_column($field); my $previous = qsearchs('part_svc_column', { @@ -561,6 +561,9 @@ is specified as B<0>, returns the number of unlinked customer services. sub num_cust_svc { my $self = shift; + return $self->{Hash}{num_cust_svc} + if !@_ && exists($self->{Hash}{num_cust_svc}); + my @param = ( $self->svcpart ); my( $join, $and ) = ( '', '' ); @@ -583,6 +586,26 @@ sub num_cust_svc { $sth->fetchrow_arrayref->[0]; } +=item num_cust_svc_cancelled + +Returns the number of associated customer services that are +attached to cancelled packages. + +=cut + +sub num_cust_svc_cancelled { + my $self = shift; + my $sth = dbh->prepare( + "SELECT COUNT(*) FROM cust_svc + LEFT JOIN cust_pkg USING ( pkgnum ) + WHERE svcpart = ? + AND cust_pkg.cancel IS NOT NULL" + ) or die dbh->errstr; + $sth->execute($self->svcpart) + or die $sth->errstr; + $sth->fetchrow_arrayref->[0]; +} + =item svc_x Returns a list of associated FS::svc_* records. @@ -594,6 +617,24 @@ sub svc_x { map { $_->svc_x } $self->cust_svc; } +=item svc_locale LOCALE + +Returns a customer-viewable service definition label in the chosen LOCALE. +If there is no entry for that locale or if LOCALE is empty, returns +part_svc.svc. + +=cut + +sub svc_locale { + my( $self, $locale ) = @_; + return $self->svc unless $locale; + my $part_svc_msgcat = qsearchs('part_svc_msgcat', { + svcpart => $self->svcpart, + locale => $locale + }) or return $self->svc; + $part_svc_msgcat->svc; +} + =back =head1 CLASS METHODS @@ -851,6 +892,12 @@ sub process { $param->{'svcpart'} = $new->getfield('svcpart'); } + $error ||= $new->process_o2m( + 'table' => 'part_svc_msgcat', + 'params' => $param, + 'fields' => [ 'locale', 'svc' ], + ); + die "$error\n" if $error; }