self-service changes to support e-liance portal, RT#24968
authorIvan Kohler <ivan@freeside.biz>
Mon, 20 Jan 2014 07:56:48 +0000 (23:56 -0800)
committerIvan Kohler <ivan@freeside.biz>
Mon, 20 Jan 2014 07:56:48 +0000 (23:56 -0800)
FS/FS/ClientAPI/MyAccount.pm
FS/FS/ClientAPI/Signup.pm
FS/FS/cust_main.pm

index d7914d6..862cceb 100644 (file)
@@ -555,7 +555,9 @@ sub customer_info_short {
                       1, ##nobalance
                     );
 
-    $return{name} = $cust_main->first. ' '. $cust_main->get('last');
+warn    $return{first}  = $cust_main->first;
+warn    $return{'last'} = $cust_main->get('last');
+    $return{name}   = $cust_main->first. ' '. $cust_main->get('last');
 
     $return{payby} = $cust_main->payby;
 
@@ -565,8 +567,10 @@ sub customer_info_short {
     }
     #maybe a little more expensive, but it should be cached by now
     for (@location_editable_fields) {
-      $return{$_} = $cust_main->bill_location->get($_);
-      $return{'ship_'.$_} = $cust_main->ship_location->get($_);
+      $return{$_} = $cust_main->bill_location->get($_)
+        if $cust_main->bill_locationnum;
+      $return{'ship_'.$_} = $cust_main->ship_location->get($_)
+        if $cust_main->ship_locationnum;
     }
  
     if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) {
index 8d8c39e..29ec239 100644 (file)
@@ -879,6 +879,7 @@ sub new_customer {
 #false laziness w/ above
 # fresh restart to support "free account" portals with 3.x/4.x-style
 #  addressless accounts
+# and a contact (for self-service login)
 sub new_customer_minimal {
   my $packet = shift;
 
@@ -938,68 +939,87 @@ sub new_customer_minimal {
                          ? split( /\s*\,\s*/, $packet->{'invoicing_list'} )
                          : ();
 
+  use Tie::RefHash;
+  tie my %hash, 'Tie::RefHash', ();
+  my @svc = ();
+
   $packet->{'pkgpart'} =~ /^(\d+)$/ or '' =~ /^()$/;
   my $pkgpart = $1;
-  return { 'error' => 'Please select a package' } unless $pkgpart; #msgcat
 
-  my $part_pkg =
-    qsearchs( 'part_pkg', { 'pkgpart' => $pkgpart } )
-      or return { 'error' => "WARNING: unknown pkgpart: $pkgpart" };
-  my $svcpart = $part_pkg->svcpart($svc_x);
+  if ( $pkgpart ) {
 
-  my $cust_pkg = new FS::cust_pkg ( {
-    #later#'custnum' => $custnum,
-    'pkgpart'    => $packet->{'pkgpart'},
-  } );
-  #my $error = $cust_pkg->check;
-  #return { 'error' => $error } if $error;
+    my $part_pkg =
+      qsearchs( 'part_pkg', { 'pkgpart' => $pkgpart } )
+        or return { 'error' => "WARNING: unknown pkgpart: $pkgpart" };
+    my $svcpart = $part_pkg->svcpart($svc_x);
 
-  #should be all auto-magic and shit
-  my @svc = ();
-  if ( $svc_x eq 'svc_acct' ) {
-
-    my $svc = new FS::svc_acct {
-      'svcpart'   => $svcpart,
-      map { $_ => $packet->{$_} }
-        qw( username _password sec_phrase popnum domsvc ),
-    };
+    my $cust_pkg = new FS::cust_pkg ( {
+      #later#'custnum' => $custnum,
+      'pkgpart'    => $packet->{'pkgpart'},
+    } );
+    #my $error = $cust_pkg->check;
+    #return { 'error' => $error } if $error;
 
-    push @svc, $svc;
+    #should be all auto-magic and shit
+    if ( $svc_x eq 'svc_acct' ) {
 
-  } elsif ( $svc_x eq 'svc_phone' ) {
+      my $svc = new FS::svc_acct {
+        'svcpart'   => $svcpart,
+        map { $_ => $packet->{$_} }
+          qw( username _password sec_phrase popnum domsvc ),
+      };
 
-    push @svc, new FS::svc_phone ( {
-      'svcpart' => $svcpart,
-       map { $_ => $packet->{$_} }
-         qw( countrycode phonenum sip_password pin ),
-    } );
+      push @svc, $svc;
 
-  } elsif ( $svc_x eq 'svc_pbx' ) {
+    } elsif ( $svc_x eq 'svc_phone' ) {
 
-    push @svc, new FS::svc_pbx ( {
+      push @svc, new FS::svc_phone ( {
         'svcpart' => $svcpart,
-        map { $_ => $packet->{$_} } 
-          qw( id title ),
-        } );
-  
-  } else {
-    die "unknown signup service $svc_x";
+         map { $_ => $packet->{$_} }
+           qw( countrycode phonenum sip_password pin ),
+      } );
+
+    } elsif ( $svc_x eq 'svc_pbx' ) {
+
+      push @svc, new FS::svc_pbx ( {
+          'svcpart' => $svcpart,
+          map { $_ => $packet->{$_} } 
+            qw( id title ),
+          } );
+    
+    } else {
+      die "unknown signup service $svc_x";
+    }
+
+    foreach my $svc ( @svc ) {
+      my $y = $svc->setdefault; # arguably should be in new method
+      return { 'error' => $y } if $y && !ref($y);
+      #$error = $svc->check;
+      #return { 'error' => $error } if $error;
+    }
+
+    use Tie::RefHash;
+    tie my %hash, 'Tie::RefHash';
+    $hash{ $cust_pkg } = \@svc;
+
   }
 
-  foreach my $svc ( @svc ) {
-    my $y = $svc->setdefault; # arguably should be in new method
-    return { 'error' => $y } if $y && !ref($y);
-    #$error = $svc->check;
-    #return { 'error' => $error } if $error;
+  my %opt = ();
+  if ( $invoicing_list[0] && $packet->{'_password'} ) {
+    $opt{'contact'} = [
+      new FS::contact { 'first'        => $cust_main->first,
+                        'last'         => $cust_main->get('last'),
+                        '_password'    => $packet->{'_password'},
+                        'emailaddress' => $invoicing_list[0],
+                        'selfservice_access' => 'Y',
+                      }
+    ];
   }
 
-  use Tie::RefHash;
-  tie my %hash, 'Tie::RefHash';
-  %hash = ( $cust_pkg => \@svc );
-  #msgcat
   my $error = $cust_main->insert(
     \%hash,
     \@invoicing_list,
+    %opt,
   );
   return { 'error' => $error } if $error;
 
index 9e3c285..0da2364 100644 (file)
@@ -350,6 +350,9 @@ created and inserted.
 
 If I<prospectnum> is set, moves contacts and locations from that prospect.
 
+If I<contact> is set to an arrayref of FS::contact objects, inserts those
+new contacts with this new customer.
+
 =cut
 
 sub insert {
@@ -538,6 +541,21 @@ sub insert {
 
   }
 
+  my $contact = delete $options{'contact'};
+  if ( $contact ) {
+
+    foreach my $c ( @$contact ) {
+      $c->custnum($self->custnum);
+      my $error = $c->insert;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return $error;
+      }
+
+    }
+
+  }
+
   warn "  setting cust_main_exemption\n"
     if $DEBUG > 1;