use FS::cust_pkg;
use FS::part_svc;
+#i guess this is kind of deprecated in favor of service_status, but keeping it
+#around until they say they don't need it.
sub customer_status {
my( $custnum ) = shift; #@_;
my $svcnum = @_ ? shift : '';
or return { 'status' => 'E',
'error' => "custnum $custnum not found" };
- my( $svc_pbx, $good_till, $outbound_service ) = ( '', '', '' );
- my %result = ();
- if ( $svcnum ) {
-
- ###
- # reseller scenario to maestro (customer w/ multiple packages)
- ###
-
- # find $svc_pbx
-
- $svc_pbx = qsearchs({
- 'table' => 'svc_pbx',
- 'addl_from' => ' LEFT JOIN cust_svc USING ( svcnum ) '.
- ' LEFT JOIN cust_pkg USING ( pkgnum ) ',
- 'hashref' => { 'svcnum' => $svcnum },
- 'extra_sql' => " AND custnum = $custnum",
- })
- or return { 'status' => 'E',
- 'error' => "svcnum $svcnum not found" };
+ return service_status($svcnum) if $svcnum;
- #status in the reseller scenario
+ ###
+ # regular customer to maestro (single package)
+ ###
- my $cust_pkg = $svc_pbx->cust_svc->cust_pkg;
-
- $result{'status'} = substr($cust_pkg->ucfirst_status,0,1);
+ my %result = ();
- # find "outbound service" y/n
+ my @cust_pkg = $cust_main->cust_pkg;
- #XXX outbound service per-reseller ?
- #my @cust_pkg = $cust_main->cust_pkg;
- #
- #my $conf = new FS::Conf;
- #my %outbound_pkgs = map { $_=>1 } $conf->config('mc-outbound_packages');
- #my $outbound_service =
- # scalar( grep { $outbound_pkgs{ $_->pkgpart }
- # && !$_->get('cancel')
- # }
- # @cust_pkg
- # )
- # ? 1 : 0;
+ #things specific to the non-reseller scenario
- # find "good till" date/time stamp (this package)
+ $result{'status'} = substr($cust_main->ucfirst_status,0,1);
- $good_till = time2str('%c', $cust_pkg->bill || time );
+ $result{'products'} =
+ [ map $_->pkgpart, grep !$_->get('cancel'), @cust_pkg ];
- } else {
+ #find svc_pbx
- ###
- # regular customer to maestro (single package)
- ###
+ my @cust_svc = map $_->cust_svc, @cust_pkg;
- my @cust_pkg = $cust_main->cust_pkg;
+ my @cust_svc_pbx =
+ grep { my($n,$l,$t) = $_->label; $t eq 'svc_pbx' }
+ @cust_svc;
- #things specific to the non-reseller scenario
+ if ( ! @cust_svc_pbx ) {
+ return { 'status' => 'E',
+ 'error' => "customer $custnum has no conference service" };
+ } elsif ( scalar(@cust_svc_pbx) > 1 ) {
+ return { 'status' => 'E',
+ 'error' =>
+ "customer $custnum has more than one conference".
+ " service (reseller?); specify a svcnum as a second argument",
+ };
+ }
- $result{'status'} = substr($cust_main->ucfirst_status,0,1);
+ my $cust_svc_pbx = $cust_svc_pbx[0];
- $result{'products'} =
- [ map $_->pkgpart, grep !$_->get('cancel'), @cust_pkg ];
+ my $svc_pbx = $cust_svc_pbx->svc_x;
- #find svc_pbx
+ # find "outbound service" y/n
- my @cust_svc = map $_->cust_svc, @cust_pkg;
+ my $conf = new FS::Conf;
+ my %outbound_pkgs = map { $_=>1 } $conf->config('mc-outbound_packages');
+ $result{'outbound_service'} =
+ scalar( grep { $outbound_pkgs{ $_->pkgpart }
+ && !$_->get('cancel')
+ }
+ @cust_pkg
+ )
+ ? 1 : 0;
- my @cust_svc_pbx =
- grep { my($n,$l,$t) = $_->label; $t eq 'svc_pbx' }
- @cust_svc;
+ # find "good till" date/time stamp
- if ( ! @cust_svc_pbx ) {
- return { 'status' => 'E',
- 'error' => "customer $custnum has no conference service" };
- } elsif ( scalar(@cust_svc_pbx) > 1 ) {
- return { 'status' => 'E',
- 'error' =>
- "customer $custnum has more than one conference".
- " service (reseller?); specify a svcnum as a second argument",
- };
- }
+ my @active_cust_pkg =
+ sort { $a->bill <=> $b->bill }
+ grep { !$_->get('cancel') && $_->part_pkg->freq ne '0' }
+ @cust_pkg;
+ $result{'good_till'} = time2str('%c', $active_cust_pkg[0]->bill || time );
- my $cust_svc_pbx = $cust_svc_pbx[0];
+ return {
+ 'name' => $cust_main->name,
+ 'email' => $cust_main->invoicing_list_emailonly_scalar,
+ #'agentnum' => $cust_main->agentnum,
+ #'agent' => $cust_main->agent->agent,
+ 'max_lines' => $svc_pbx ? $svc_pbx->max_extensions : '',
+ 'max_simultaneous' => $svc_pbx ? $svc_pbx->max_simultaneous : '',
+ %result,
+ };
- $svc_pbx = $cust_svc_pbx->svc_x;
+}
- # find "outbound service" y/n
+sub service_status {
+ my $svcnum = shift;
- my $conf = new FS::Conf;
- my %outbound_pkgs = map { $_=>1 } $conf->config('mc-outbound_packages');
- $outbound_service =
- scalar( grep { $outbound_pkgs{ $_->pkgpart }
- && !$_->get('cancel')
- }
- @cust_pkg
- )
- ? 1 : 0;
+ my $svc_pbx = qsearchs({
+ 'table' => 'svc_pbx',
+ 'addl_from' => ' LEFT JOIN cust_svc USING ( svcnum ) '.
+ ' LEFT JOIN cust_pkg USING ( pkgnum ) ',
+ 'hashref' => { 'svcnum' => $svcnum },
+ #'extra_sql' => " AND custnum = $custnum",
+ })
+ or return { 'status' => 'E',
+ 'error' => "svcnum $svcnum not found" };
- # find "good till" date/time stamp
+ my $cust_pkg = $svc_pbx->cust_svc->cust_pkg;
+ my $cust_main = $cust_pkg->cust_main;
- my @active_cust_pkg =
- sort { $a->bill <=> $b->bill }
- grep { !$_->get('cancel') && $_->part_pkg->freq ne '0' }
- @cust_pkg;
- $good_till = time2str('%c', $active_cust_pkg[0]->bill || time );
+ my %result = ();
- }
+ #status in the reseller scenario
+ $result{'status'} = substr($cust_pkg->ucfirst_status,0,1);
+ $result{'status'} = 'A' if $result{'status'} eq 'N';
+
+ # find "outbound service" y/n
+ my @cust_pkg = $cust_main->cust_pkg;
+ #XXX what about outbound service per-reseller ?
+ my $conf = new FS::Conf;
+ my %outbound_pkgs = map { $_=>1 } $conf->config('mc-outbound_packages');
+ $result{'outbound_service'} =
+ scalar( grep { $outbound_pkgs{ $_->pkgpart }
+ && !$_->get('cancel')
+ }
+ @cust_pkg
+ )
+ ? 1 : 0;
+
+ # find "good till" date/time stamp (this package)
+ $result{'good_till'} = time2str('%c', $cust_pkg->bill || time );
return {
- 'name' => $cust_main->name,
- 'email' => $cust_main->invoicing_list_emailonly_scalar,
- 'agentnum' => $cust_main->agentnum,
- 'agent' => $cust_main->agent->agent,
- 'max_lines' => $svc_pbx ? $svc_pbx->max_extensions : '',
- 'max_simultaneous' => $svc_pbx ? $svc_pbx->max_simultaneous : '',
- 'outbound_service' => $outbound_service,
- 'good_till' => $good_till,
+ 'custnum' => $cust_main->custnum,
+ 'name' => ( $svc_pbx->title || $cust_main->name ),
+ 'email' => $cust_main->invoicing_list_emailonly_scalar,
+ #'agentnum' => $cust_main->agentnum,
+ #'agent' => $cust_main->agent->agent,
+ 'max_lines' => $svc_pbx->max_extensions,
+ 'max_simultaneous' => $svc_pbx->max_simultaneous,
%result,
};
tie my %hash, 'Tie::RefHash';
%hash = ( $cust_pkg => \@svc );
#msgcat
- $error = $cust_main->order_pkgs( \%hash, '', 'noexport' => 1 );
+ $error = $cust_main->order_pkgs( \%hash, 'noexport' => 1 );
return { 'error' => $error } if $error;
# currently they're using this in the reseller scenario, so don't