maestro cust status as reqeusted, RT#8712
authorivan <ivan>
Sat, 26 Jun 2010 09:34:10 +0000 (09:34 +0000)
committerivan <ivan>
Sat, 26 Jun 2010 09:34:10 +0000 (09:34 +0000)
FS/FS/Conf.pm
FS/FS/Maestro.pm [new file with mode: 0644]
FS/FS/Schema.pm
FS/FS/XMLRPC.pm
FS/FS/svc_pbx.pm
FS/MANIFEST
httemplate/misc/xmlrpc.cgi

index 01f88a7..99c4876 100644 (file)
@@ -3578,6 +3578,14 @@ and customer address. Include units.',
   },
 
   {
+    'key'         => 'mc-outbound_packages',
+    'section'     => '',
+    'description' => "Don't use this.",
+    'type'        => 'select-part_pkg',
+    'multiple'    => 1,
+  },
+
+  {
     'key'         => 'disable-cust-pkg_class',
     'section'     => 'UI',
     'description' => 'Disable the two-step dropdown for selecting package class and package, and return to the classic single dropdown.',
diff --git a/FS/FS/Maestro.pm b/FS/FS/Maestro.pm
new file mode 100644 (file)
index 0000000..20dbad6
--- /dev/null
@@ -0,0 +1,79 @@
+package FS::Maestro;
+
+use Date::Format;
+use FS::Conf;
+use FS::Record qw( qsearchs );
+use FS::cust_main;
+
+sub customer_status {
+  my( $custnum ) = shift; #@_;
+
+  my $cust_main = qsearchs( 'cust_main' => { 'custnum' => $custnum } )
+   or return { 'status' => 'E',
+               'error'  => "$custnum not found" };
+
+  my @cust_pkg = $cust_main->cust_pkg;
+
+  my @cust_svc = map $_->cust_svc, @cust_pkg;
+
+  ###
+  # find $svc_pbx
+  ##
+
+  my @cust_svc_pbx =
+    grep { my($n,$l,$t) = $_->label; $_->t eq 'svc_pbx' }
+    @cust_svc;
+
+  #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
+  }
+
+  my $cust_svc_pbx = $cust_svc_pbx[0];
+
+  my $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 }, @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 );
+
+  ###
+  # return the info
+  ###
+
+  { 
+    'status' => substr($cust_main->ucfirst_status,0,1), #what they asked for..
+    'name'   => $cust_main->name,
+    'email'  => $cust_main->invoicing_list_emailonly_scalar,
+    'max_lines'        => $svc_pbx->max_extensions,
+    'max_simultaneous' => $svc_pbx->max_simultaneous,
+    'outbound_service' => $outbound_service,
+    'good_till' => $good_till,
+    'products'  => [ map $_->pkgpart, grep !$_->get('cancel'), @cust_pkg ],
+  };
+
+}
+
+1;
index 01512f9..73392e8 100644 (file)
@@ -2799,10 +2799,11 @@ sub tables_hashref {
 
     'svc_pbx' => {
       'columns' => [
-        'svcnum',         'int',     '',      '', '', '', 
-        'id',             'int', 'NULL',      '', '', '', 
-        'title',      'varchar', 'NULL', $char_d, '', '', 
-        'max_extensions', 'int', 'NULL',      '', '', '',
+        'svcnum',           'int',     '',      '', '', '', 
+        'id',               'int', 'NULL',      '', '', '', 
+        'title',        'varchar', 'NULL', $char_d, '', '', 
+        'max_extensions',   'int', 'NULL',      '', '', '',
+        'max_simultaneous', 'int', 'NULL',      '', '', '',
       ],
       'primary_key' => 'svcnum',
       'unique' => [],
index fb0e5ac..73ce13f 100644 (file)
@@ -1,7 +1,7 @@
-package FS::XMLRPC;
+ package FS::XMLRPC;
 
 use strict;
-use vars qw( @ISA $DEBUG );
+use vars qw( $DEBUG );
 use Frontier::RPC2;
 
 # Instead of 'use'ing freeside modules on the fly below, just preload them now.
@@ -11,9 +11,9 @@ use FS::Conf;
 use FS::Record;
 use FS::cust_main;
 
-use Data::Dumper;
+use FS::Maestro;
 
-@ISA = qw( );
+use Data::Dumper;
 
 $DEBUG = 0;
 
@@ -131,9 +131,9 @@ sub _serve { #Subroutine, not method
 
     }
 
-    warn Dumper(@result) if $DEBUG;
-
-    if (grep { UNIVERSAL::can($_, 'hashref') ? 0 : 1 } @result) {
+    if ( scalar(@result) == 1 && ref($result[0]) eq 'HASH' ) {
+      return $result[0];
+    } elsif (grep { UNIVERSAL::can($_, 'hashref') ? 0 : 1 } @result) {
       #warn "FS::XMLRPC: One or more objects returned from '${fssub}' doesn't " .
       #     "support the 'hashref' method.";
       
@@ -147,8 +147,8 @@ sub _serve { #Subroutine, not method
     return [ $FS::VERSION ];
   } # else...
 
-  warn "Unhandle XMLRPC request '${method_name}'";
-  return [];
+  warn "Unhandled XMLRPC request '${method_name}'";
+  return {};
 
 }
 
index 6ae0418..21aaa4e 100644 (file)
@@ -55,6 +55,10 @@ PBX name
 
 Maximum number of extensions
 
+=item max_simultaneous
+
+Maximum number of simultaneous users
+
 =back
 
 =head1 METHODS
@@ -85,6 +89,7 @@ sub table_info {
       'id'    => 'ID',
       'title' => 'Name',
       'max_extensions' => 'Maximum number of User Extensions',
+      'max_simultaneous' => 'Maximum number of simultaneous users',
 #      'field'         => 'Description',
 #      'another_field' => { 
 #                           'label'     => 'Description',
@@ -206,15 +211,15 @@ returns the error, otherwise returns false.
 
 =cut
 
-sub replace {
-  my ( $new, $old ) = ( shift, shift );
-  my $error;
-
-  $error = $new->SUPER::replace($old);
-  return $error if $error;
-
-  '';
-}
+#sub replace {
+#  my ( $new, $old ) = ( shift, shift );
+#  my $error;
+#
+#  $error = $new->SUPER::replace($old);
+#  return $error if $error;
+#
+#  '';
+#}
 
 =item suspend
 
index b358c83..03d56ac 100644 (file)
@@ -44,6 +44,7 @@ FS/Cron/backup.pm
 FS/Cron/bill.pm
 FS/Cron/vacuum.pm
 FS/Daemon.pm
+FS/Maestro.pm
 FS/Misc.pm
 FS/Record.pm
 FS/Report.pm
index 1d0383f..14bf9ef 100644 (file)
@@ -1,18 +1,16 @@
-%
-%
-%  my $request_xml = $cgi->param('POSTDATA');
-%
-%  #$r->log_error($request_xml);
-%
-%  my $fsxmlrpc = new FS::XMLRPC;
-%  my ($error, $response_xml) = $fsxmlrpc->serve($request_xml);
-%  
-%  #$r->log_error($error) if $error;
-%
-%  http_header('Content-Type' => 'text/xml',
-%              'Content-Length' => length($response_xml));
-%
-%  print $response_xml;
-%
-%
+<% $response_xml %>\
+<%init>
 
+my $request_xml = $cgi->param('POSTDATA');
+
+#warn $request_xml;
+
+my $fsxmlrpc = new FS::XMLRPC;
+my ($error, $response_xml) = $fsxmlrpc->serve($request_xml);
+
+#warn $error;
+
+http_header('Content-Type' => 'text/xml',
+            'Content-Length' => length($response_xml));
+
+</%init>