From 960c55002469c33ea9b0a949ad473a705e1b6cf9 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Sun, 19 Jan 2014 23:56:48 -0800 Subject: [PATCH] self-service changes to support e-liance portal, RT#24968 --- FS/FS/ClientAPI/MyAccount.pm | 10 ++-- FS/FS/ClientAPI/Signup.pm | 108 +++++++++++++++++++++++++------------------ FS/FS/cust_main.pm | 18 ++++++++ 3 files changed, 89 insertions(+), 47 deletions(-) diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index d7914d64f..862cceb2a 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -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)$/ ) { diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm index 8d8c39e67..29ec23972 100644 --- a/FS/FS/ClientAPI/Signup.pm +++ b/FS/FS/ClientAPI/Signup.pm @@ -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; diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 9e3c285c2..0da2364f1 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -350,6 +350,9 @@ created and inserted. If I is set, moves contacts and locations from that prospect. +If I 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; -- 2.11.0