summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2010-07-27 06:48:39 +0000
committerivan <ivan>2010-07-27 06:48:39 +0000
commit2b96da0344fe5f46caf80257890312de444d935b (patch)
treef4c5bcec6a03d4b1d282bb10cf105f2e43390766
parent53d8528049b4374004ee807aaab39d91f7fb107a (diff)
extend maestro status API for the multi-service scenario, RT#9334
-rw-r--r--FS/FS/Maestro.pm154
-rw-r--r--FS/FS/cust_pkg.pm10
-rw-r--r--httemplate/misc/maestro-customer_status-test.html10
-rw-r--r--httemplate/misc/maestro-customer_status.cgi8
4 files changed, 124 insertions, 58 deletions
diff --git a/FS/FS/Maestro.pm b/FS/FS/Maestro.pm
index e395c5a..2061f28 100644
--- a/FS/FS/Maestro.pm
+++ b/FS/FS/Maestro.pm
@@ -7,75 +7,131 @@ use FS::cust_main;
sub customer_status {
my( $custnum ) = shift; #@_;
+ my $svcnum = @_ ? shift : '';
- my $cust_main = qsearchs( 'cust_main' => { 'custnum' => $custnum } )
- or return { 'status' => 'E',
- 'error' => "$custnum not found" };
+ my $curuser = $FS::CurrentUser::CurrentUser;
- my @cust_pkg = $cust_main->cust_pkg;
+ my $cust_main = qsearchs({
+ 'table' => 'cust_main',
+ 'hashref' => { 'custnum' => $custnum },
+ 'extra_sql' => ' AND '. $curuser->agentnums_sql,
+ })
+ or return { 'status' => 'E',
+ 'error' => "custnum $custnum not found" };
- my @cust_svc = map $_->cust_svc, @cust_pkg;
+ my( $svc_pbx, $good_till, $outbound_service ) = ( '', '', '' );
+ my %result = ();
+ if ( $svcnum ) {
+
+ ###
+ # reseller scenario to maestro (customer w/ multiple packages)
+ ###
- ###
- # find $svc_pbx
- ##
+ # find $svc_pbx
- my @cust_svc_pbx =
- grep { my($n,$l,$t) = $_->label; $t eq 'svc_pbx' }
- @cust_svc;
+ $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" };
- #i tried sofa king hard to explain to them why passing a custnum instead
- #of a conference id was a bad idea, but i can't make them understand...
- 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; there should be a way to specify which one you want",
- }; #maybe list them... and work with a pkgnum
- }
+ #status in the reseller scenario
+
+ my $cust_pkg = $svc_pbx->cust_svc->cust_pkg;
+
+ $result{'status'} = substr($cust_pkg->ucfirst_status,0,1);
+
+ # find "outbound service" y/n
+
+ #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;
+
+ # find "good till" date/time stamp (this package)
+
+ $good_till = time2str('%c', $cust_pkg->bill || time );
+
+ } else {
+
+ ###
+ # regular customer to maestro (single package)
+ ###
- my $cust_svc_pbx = $cust_svc_pbx[0];
+ my @cust_pkg = $cust_main->cust_pkg;
- my $svc_pbx = $cust_svc_pbx->svc_x;
+ #things specific to the non-reseller scenario
- ###
- # find "outbound service" y/n
- ###
+ $result{'status'} = substr($cust_main->ucfirst_status,0,1);
- 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;
+ $result{'products'} =
+ [ map $_->pkgpart, grep !$_->get('cancel'), @cust_pkg ];
- ###
- # find "good till" date/time stamp
- ###
+ #find svc_pbx
- my @active_cust_pkg =
- sort { $a->bill <=> $b->bill }
- grep { !$_->get('cancel') && $_->part_pkg->freq ne '0' }
- @cust_pkg;
- my $good_till =time2str('%c', $active_cust_pkg[0]->bill || time );
+ my @cust_svc = map $_->cust_svc, @cust_pkg;
- ###
- # return the info
- ###
+ my @cust_svc_pbx =
+ grep { my($n,$l,$t) = $_->label; $t eq 'svc_pbx' }
+ @cust_svc;
+
+ 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 $cust_svc_pbx = $cust_svc_pbx[0];
+
+ $svc_pbx = $cust_svc_pbx->svc_x;
+
+ # find "outbound service" y/n
+
+ 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;
+
+ # find "good till" date/time stamp
+
+ my @active_cust_pkg =
+ sort { $a->bill <=> $b->bill }
+ grep { !$_->get('cancel') && $_->part_pkg->freq ne '0' }
+ @cust_pkg;
+ my $good_till = time2str('%c', $active_cust_pkg[0]->bill || time );
+
+ }
- {
- 'status' => substr($cust_main->ucfirst_status,0,1), #what they asked for..
+ return {
'name' => $cust_main->name,
'email' => $cust_main->invoicing_list_emailonly_scalar,
'max_lines' => $svc_pbx ? $svc_pbx->max_extensions : '',
'max_simultaneous' => $svc_pbx ? $svc_pbx->max_simultaneous : '',
'outbound_service' => $outbound_service,
'good_till' => $good_till,
- 'products' => [ map $_->pkgpart, grep !$_->get('cancel'), @cust_pkg ],
+ %result,
};
}
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index fdd8ddb..fea693e 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -1765,6 +1765,16 @@ sub status {
return 'active';
}
+=item ucfirst_status
+
+Returns the status with the first character capitalized.
+
+=cut
+
+sub ucfirst_status {
+ ucfirst(shift->status);
+}
+
=item statuses
Class method that returns the list of possible status strings for packages
diff --git a/httemplate/misc/maestro-customer_status-test.html b/httemplate/misc/maestro-customer_status-test.html
index 86e5b1f..0064929 100644
--- a/httemplate/misc/maestro-customer_status-test.html
+++ b/httemplate/misc/maestro-customer_status-test.html
@@ -1,8 +1,8 @@
<% include('/elements/header.html', {
- 'title' => "Customer $query status",
+ 'title' => "Customer $custnum status",
}) %>
-<% include('/elements/small_custview.html', $query, '', 1) %>
+<% include('/elements/small_custview.html', $custnum, '', 1) %>
<BR>
<table style="border:1px solid #000000">
@@ -21,11 +21,11 @@
my $return;
-my($query) = $cgi->keywords;
-if ( $query =~ /^(\d+)$/ ) {
+my($custnum, $svcnum) = $cgi->keywords;
+if ( $custnum =~ /^(\d+)$/ ) {
use FS::Maestro;
- $return = FS::Maestro::customer_status($1);
+ $return = FS::Maestro::customer_status($1, $svcnum);
} else {
$return = { 'error' => 'No custnum' };
diff --git a/httemplate/misc/maestro-customer_status.cgi b/httemplate/misc/maestro-customer_status.cgi
index abd0fb4..8e82a02 100644
--- a/httemplate/misc/maestro-customer_status.cgi
+++ b/httemplate/misc/maestro-customer_status.cgi
@@ -3,14 +3,14 @@
my $uri = new URI;
-my($query) = $cgi->keywords;
-if ( $query =~ /^(\d+)$/ ) {
+my($custnum, $svcnum) = $cgi->keywords;
+if ( $custnum =~ /^(\d+)$/ ) {
use FS::Maestro;
- $uri->query_form( FS::Maestro::customer_status($1) );
+ $return = FS::Maestro::customer_status($1, $svcnum);
} else {
- $uri->query_form( { 'error' => 'No custnum' } );
+ $return = { 'error' => 'No custnum' };
}
</%init>