X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FMyAccount.pm;h=e3afac14ada2edf7f1cceda58e8d1d6d0d6cd337;hb=14c5096e04f0d1ac2a19a3c6c41e537a9aa0f78c;hp=74c4b335106a66da499f65979760513eeaeee4f9;hpb=9c4526fcca8fcf9bd836780611c52afd62247866;p=freeside.git diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 74c4b3351..e3afac14a 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -25,6 +25,8 @@ use FS::svc_acct; use FS::svc_domain; use FS::svc_phone; use FS::svc_external; +use FS::svc_dsl; +use FS::dsl_device; use FS::part_svc; use FS::cust_main; use FS::cust_bill; @@ -44,13 +46,23 @@ $me = '[FS::ClientAPI::MyAccount]'; use vars qw( @cust_main_editable_fields ); @cust_main_editable_fields = qw( first last company address1 address2 city - county state zip country daytime night fax + county state zip country + daytime night fax mobile ship_first ship_last ship_company ship_address1 ship_address2 ship_city - ship_state ship_zip ship_country ship_daytime ship_night ship_fax + ship_state ship_zip ship_country + ship_daytime ship_night ship_fax ship_mobile + locale payby payinfo payname paystart_month paystart_year payissue payip ss paytype paystate stateid stateid_state ); +BEGIN { #preload to reduce time customer_info takes + if ( $FS::TicketSystem::system ) { + warn "$me: initializing ticket system\n" if $DEBUG; + FS::TicketSystem->init(); + } +} + sub _cache { $cache ||= new FS::ClientAPI_SessionCache( { 'namespace' => 'FS::ClientAPI::MyAccount', @@ -378,6 +390,7 @@ sub customer_info { ); $return{name} = $cust_main->first. ' '. $cust_main->get('last'); + $return{ship_name} = $cust_main->ship_first. ' '. $cust_main->get('ship_last'); for (@cust_main_editable_fields) { $return{$_} = $cust_main->get($_); @@ -422,6 +435,7 @@ sub customer_info { if ( $session->{'svcnum'} ) { my $cust_svc = qsearchs('cust_svc', { 'svcnum' => $session->{'svcnum'} }); $return{'svc_label'} = ($cust_svc->label)[1] if $cust_svc; + $return{'svcnum'} = $session->{'svcnum'}; } } elsif ( $session->{'svcnum'} ) { #no customer record @@ -467,27 +481,29 @@ sub customer_info_short { ); $return{name} = $cust_main->first. ' '. $cust_main->get('last'); + $return{ship_name} = $cust_main->ship_first. ' '. $cust_main->get('ship_last'); $return{payby} = $cust_main->payby; #none of these are terribly expensive if we want 'em... - #for (@cust_main_editable_fields) { - # $return{$_} = $cust_main->get($_); - #} - # - #if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) { - # $return{payinfo} = $cust_main->paymask; - # @return{'month', 'year'} = $cust_main->paydate_monthyear; - #} - # - #$return{'invoicing_list'} = - # join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list ); + for (@cust_main_editable_fields) { + $return{$_} = $cust_main->get($_); + } + + if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) { + $return{payinfo} = $cust_main->paymask; + @return{'month', 'year'} = $cust_main->paydate_monthyear; + } + + $return{'invoicing_list'} = + join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list ); #$return{'postal_invoicing'} = # 0 < ( grep { $_ eq 'POST' } $cust_main->invoicing_list ); if ( $session->{'svcnum'} ) { my $cust_svc = qsearchs('cust_svc', { 'svcnum' => $session->{'svcnum'} }); $return{'svc_label'} = ($cust_svc->label)[1] if $cust_svc; + $return{'svcnum'} = $session->{'svcnum'}; } } elsif ( $session->{'svcnum'} ) { #no customer record @@ -547,7 +563,7 @@ sub edit_info { $p->{'payinfo1'} =~ /^([\dx]+)$/ or return { 'error' => "illegal account number ". $p->{'payinfo1'} }; my $payinfo1 = $1; - $p->{'payinfo2'} =~ /^([\dx]+)$/ + $p->{'payinfo2'} =~ /^([\dx\.]+)$/ # . turned on by -require-bank-branch? or return { 'error' => "illegal ABA/routing number ". $p->{'payinfo2'} }; my $payinfo2 = $1; $payinfo = $payinfo1. '@'. $payinfo2; @@ -1296,12 +1312,18 @@ sub list_svcs { my $cust_main = qsearchs('cust_main', $search ) or return { 'error' => "unknown custnum $custnum" }; + my $pkgnum = $session->{'pkgnum'} || $p->{'pkgnum'} || ''; + if ( ! $pkgnum && $p->{'svcnum'} ) { + my $cust_svc = qsearchs('cust_svc', { 'svcnum' => $p->{'svcnum'} } ); + $pkgnum = $cust_svc->pkgnum if $cust_svc; + } + my @cust_svc = (); #foreach my $cust_pkg ( $cust_main->ncancelled_pkgs ) { foreach my $cust_pkg ( $p->{'ncancelled'} ? $cust_main->ncancelled_pkgs : $cust_main->unsuspended_pkgs ) { - next if $session->{'pkgnum'} && $cust_pkg->pkgnum != $session->{'pkgnum'}; + next if $pkgnum && $cust_pkg->pkgnum != $pkgnum; push @cust_svc, @{[ $cust_pkg->cust_svc ]}; #@{[ ]} to force array context } if ( $p->{'svcdb'} ) { @@ -1342,6 +1364,7 @@ sub list_svcs { %hash, 'username' => $svc_x->username, 'email' => $svc_x->email, + 'finger' => $svc_x->finger, 'seconds' => $svc_x->seconds, 'upbytes' => display_bytecount($svc_x->upbytes), 'downbytes' => display_bytecount($svc_x->downbytes), @@ -1358,11 +1381,21 @@ sub list_svcs { # more... ); - } elsif ( $svcdb eq 'svc_phone' || $svcdb eq 'svc_port' ) { - %hash = ( - %hash, - ); + } elsif ( $svcdb eq 'svc_dsl' ) { + $hash{'phonenum'} = $svc_x->phonenum; + if ( $svc_x->first || $svc_x->get('last') || $svc_x->company ) { + $hash{'name'} = $svc_x->first. ' '. $svc_x->get('last'); + $hash{'name'} = $svc_x->company. ' ('. $hash{'name'}. ')' + if $svc_x->company; + } else { + $hash{'name'} = $cust_main->name; + } } + # elsif ( $svcdb eq 'svc_phone' || $svcdb eq 'svc_port' ) { + # %hash = ( + # %hash, + # ); + #} \%hash; } @@ -1372,6 +1405,82 @@ sub list_svcs { } +sub _customer_svc_x { + my($custnum, $svcnum, $table) = @_; + + $custnum =~ /^(\d+)$/ or die "illegal custnum"; + my $search = " AND custnum = $1"; + #$search .= " AND agentnum = ". $session->{'agentnum'} if $context eq 'agent'; + + qsearchs( { + 'table' => ($table || 'svc_acct'), + 'addl_from' => 'LEFT JOIN cust_svc USING ( svcnum ) '. + 'LEFT JOIN cust_pkg USING ( pkgnum ) ',#. + #'LEFT JOIN cust_main USING ( custnum ) ', + 'hashref' => { 'svcnum' => $svcnum, }, + 'extra_sql' => $search, #important + } ); + +} + +sub list_dsl_devices { + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + my $svc_dsl = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_dsl' ) + or return { 'error' => "Service not found" }; + + return { + 'devices' => [ map { + +{ 'mac_addr' => $_->mac_addr }; + } $svc_dsl->dsl_device + ], + }; + +} + +sub add_dsl_device { + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + my $svc_dsl = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_dsl' ) + or return { 'error' => "Service not found" }; + + return { 'error' => 'No MAC address supplied' } + unless length($p->{'mac_addr'}); + + my $dsl_device = new FS::dsl_device { 'svcnum' => $svc_dsl->svcnum, + 'mac_addr' => scalar($p->{'mac_addr'}), + }; + my $error = $dsl_device->insert; + return { 'error' => $error }; + +} + +sub delete_dsl_device { + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + my $svc_dsl = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_dsl' ) + or return { 'error' => "Service not found" }; + + my $dsl_device = qsearchs('dsl_device', { 'svcnum' => $svc_dsl->svcnum, + 'mac_addr' => scalar($p->{'mac_addr'}), + } + ) + or return { 'error' => 'Unknown MAC address: '. $p->{'mac_addr'} }; + + my $error = $dsl_device->delete; + return { 'error' => $error }; + +} + sub port_graph { my $p = shift; _usage_details( \&_port_graph, $p, @@ -2134,6 +2243,11 @@ sub myaccount_passwd { } ) or return { 'error' => "Service not found" }; + if ( exists($p->{'old_password'}) ) { + return { 'error' => "Incorrect password." } + unless $svc_acct->check_password($p->{'old_password'}); + } + $svc_acct->_password($p->{'new_password'}); my $error = $svc_acct->replace();