[freeside-commits] freeside/FS/FS cust_pkg.pm, 1.164, 1.165 Maestro.pm, 1.4, 1.5

Ivan,,, ivan at wavetail.420.am
Mon Jul 26 23:48:41 PDT 2010


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv20059/FS/FS

Modified Files:
	cust_pkg.pm Maestro.pm 
Log Message:
extend maestro status API for the multi-service scenario, RT#9334

Index: Maestro.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Maestro.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -d -r1.4 -r1.5
--- Maestro.pm	26 Jun 2010 20:50:02 -0000	1.4
+++ Maestro.pm	27 Jul 2010 06:48:39 -0000	1.5
@@ -7,41 +7,102 @@
 
 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
-  ##
+
+    $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" };
+
+    #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_pkg = $cust_main->cust_pkg;
+
+    #things specific to the non-reseller scenario
+
+    $result{'status'} = substr($cust_main->ucfirst_status,0,1);
+
+    $result{'products'} =
+      [ map $_->pkgpart, grep !$_->get('cancel'), @cust_pkg ];
+
+    #find svc_pbx
+
+    my @cust_svc = map $_->cust_svc, @cust_pkg;
 
   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
+               '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];
 
-  my $svc_pbx = $cust_svc_pbx->svc_x;
+    $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');
@@ -53,9 +114,7 @@
           )
     ? 1 : 0;
 
-  ###
   # find "good till" date/time stamp
-  ###
 
   my @active_cust_pkg =
     sort { $a->bill <=> $b->bill }
@@ -63,19 +122,16 @@
     @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..
+  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,
   };
 
 }

Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -w -d -r1.164 -r1.165
--- cust_pkg.pm	29 Jun 2010 04:22:52 -0000	1.164
+++ cust_pkg.pm	27 Jul 2010 06:48:39 -0000	1.165
@@ -1765,6 +1765,16 @@
   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



More information about the freeside-commits mailing list