X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FMyAccount.pm;h=08e3f7e4b2938642dad0c871b02a0cd7a6011089;hb=852f0115eef0a9013ffb6ff59eb9b569625d90f1;hp=784a33f616171ce8f0ebbc08e7d5bdea2ac8bf16;hpb=6e8323cf946ef3684a6846aa6afde7fe3692994e;p=freeside.git diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 784a33f61..08e3f7e4b 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -27,6 +27,7 @@ use FS::TicketSystem; use FS::ClientAPI_SessionCache; use FS::cust_svc; use FS::svc_acct; +use FS::svc_forward; use FS::svc_domain; use FS::svc_phone; use FS::svc_external; @@ -120,7 +121,7 @@ sub skin_info { ) ), ( map { $_ => $conf->exists("selfservice-$_", $agentnum ) } - qw( menu_skipblanks menu_skipheadings menu_nounderline ) + qw( menu_skipblanks menu_skipheadings menu_nounderline no_logo ) ), ( map { $_ => scalar($conf->config_binary("selfservice-$_", $agentnum)) } qw( title_left_image title_right_image @@ -150,12 +151,25 @@ sub login_info { %{ skin_info($p) }, 'phone_login' => $conf->exists('selfservice_server-phone_login'), 'single_domain'=> scalar($conf->config('selfservice_server-single_domain')), + 'banner_url' => scalar($conf->config('selfservice-login_banner_url')), + 'banner_image_md5' => + md5_hex($conf->config_binary('selfservice-login_banner_image')), ); return \%info; } +sub login_banner_image { + my $p = shift; + my $conf = new FS::Conf; + my $image = $conf->config_binary('selfservice-login_banner_image'); + return { + 'md5' => md5_hex($image), + 'image' => $image, + }; +} + #false laziness w/FS::ClientAPI::passwd::passwd sub login { my $p = shift; @@ -556,6 +570,12 @@ sub edit_info { or return { 'error' => "unknown custnum $custnum" }; my $new = new FS::cust_main { $cust_main->hash }; + # Avoid accidentally changing the service address. + if ( !$new->has_ship_address ) { + $new->set( $_ => $new->get($_) ) + foreach $new->addr_fields; + } + $new->set( $_ => $p->{$_} ) foreach grep { exists $p->{$_} } @cust_main_editable_fields; @@ -584,7 +604,7 @@ sub edit_info { $p->{'payinfo1'} =~ /^([\dx]+)$/ or return { 'error' => "illegal account number ". $p->{'payinfo1'} }; my $payinfo1 = $1; - $p->{'payinfo2'} =~ /^([\dx\.]+)$/ # . turned on by -require-bank-branch? + $p->{'payinfo2'} =~ /^([\dx\.]+)$/ # . turned on by echeck-country CA ? or return { 'error' => "illegal ABA/routing number ". $p->{'payinfo2'} }; my $payinfo2 = $1; $payinfo = $payinfo1. '@'. $payinfo2; @@ -715,7 +735,7 @@ sub payment_info { $return{payinfo2} = $payinfo2; $return{paytype} = $cust_main->paytype; $return{paystate} = $cust_main->paystate; - + $return{payname} = $cust_main->payname; # override 'first/last name' default from above, if any. Is instution-name here. (#15819) } if ( $conf->config('prepayment_discounts-credit_type') ) { @@ -789,7 +809,7 @@ sub validate_payment { $payinfo = $p->{'payinfo'}; - #more intelligent mathing will be needed here if you change + #more intelligent matching will be needed here if you change #card_masking_method and don't remove existing paymasks $payinfo = $cust_main->payinfo if $cust_main->paymask eq $payinfo; @@ -911,11 +931,19 @@ sub do_process_payment { if ( $validate->{'save'} ) { my $new = new FS::cust_main { $cust_main->hash }; - if ($validate->{'payby'} eq 'CARD' || $validate->{'payby'} eq 'DCRD') { + if ($payby eq 'CARD' || $payby eq 'DCRD') { $new->set( $_ => $validate->{$_} ) - foreach qw( payname paystart_month paystart_year payissue payip - address1 address2 city state zip country ); + foreach qw( payname paystart_month paystart_year payissue payip ); $new->set( 'payby' => $validate->{'auto'} ? 'CARD' : 'DCRD' ); + + # Avoid accidentally changing the service address. + if ( !$new->has_ship_address ) { + $new->set( "ship_$_" => $new->get($_) ) + foreach $new->addr_fields; + } + $new->set( $_ => $validate->{$_} ) + foreach qw(address1 address2 city state country zip); + } elsif ($payby eq 'CHEK' || $payby eq 'DCHK') { $new->set( $_ => $validate->{$_} ) foreach qw( payname payip paytype paystate @@ -1140,7 +1168,10 @@ sub invoice_pdf { return { 'error' => '', 'invnum' => $invnum, - 'invoice_pdf' => $cust_bill->print_pdf( { unsquelch_cdr => 1 } ), + 'invoice_pdf' => $cust_bill->print_pdf({ + 'unsquelch_cdr' => 1, + 'locale' => $p->{'locale'}, + }), }; } @@ -1154,10 +1185,15 @@ sub legacy_invoice { my $legacyinvnum = $p->{'legacyinvnum'}; - my $legacy_cust_bill = qsearchs('legacy_cust_bill', { + my %hash = ( 'legacyinvnum' => $legacyinvnum, 'custnum' => $custnum, - }) or return { 'error' => "Can't find legacyinvnum" }; + ); + + my $legacy_cust_bill = + qsearchs('legacy_cust_bill', { %hash, 'locale' => $p->{'locale'} } ) + || qsearchs('legacy_cust_bill', \%hash ) + or return { 'error' => "Can't find legacyinvnum" }; #my %return; @@ -1236,9 +1272,12 @@ sub list_invoices { my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) or return { 'error' => "unknown custnum $custnum" }; - my @cust_bill = $cust_main->cust_bill; + my $conf = new FS::Conf; + my @legacy_cust_bill = $cust_main->legacy_cust_bill; + my @cust_bill = grep ! $_->hide, $cust_main->cust_bill; + my $balance = 0; return { 'error' => '', @@ -1410,6 +1449,9 @@ sub list_svcs { next if $pkgnum && $cust_pkg->pkgnum != $pkgnum; push @cust_svc, @{[ $cust_pkg->cust_svc ]}; #@{[ ]} to force array context } + + @cust_svc = grep { $_->part_svc->selfservice_access ne 'hidden' } @cust_svc; + if ( $p->{'svcdb'} ) { my $svcdb = ref($p->{'svcdb'}) eq 'HASH' ? $p->{'svcdb'} @@ -1433,14 +1475,18 @@ sub list_svcs { map { my $svc_x = $_->svc_x; my($label, $value) = $_->label; - my $svcdb = $_->part_svc->svcdb; - my $part_pkg = $_->cust_pkg->part_pkg; + my $part_svc = $_->part_svc; + my $svcdb = $part_svc->svcdb; + my $cust_pkg = $_->cust_pkg; + my $part_pkg = $cust_pkg->part_pkg; my %hash = ( - 'svcnum' => $_->svcnum, - 'svcdb' => $svcdb, - 'label' => $label, - 'value' => $value, + 'svcnum' => $_->svcnum, + 'svcdb' => $svcdb, + 'label' => $label, + 'value' => $value, + 'pkg_status' => $cust_pkg->status, + 'readonly' => ( $part_svc->selfservice_access eq 'readonly' ), ); if ( $svcdb eq 'svc_acct' ) { @@ -1490,7 +1536,8 @@ sub list_svcs { } sub _customer_svc_x { - my($custnum, $svcnum, $table) = @_; + my($custnum, $svcnum, $table) = (shift, shift, shift); + my $hashref = ref($svcnum) ? $svcnum : { 'svcnum' => $svcnum }; $custnum =~ /^(\d+)$/ or die "illegal custnum"; my $search = " AND custnum = $1"; @@ -1501,12 +1548,128 @@ sub _customer_svc_x { 'addl_from' => 'LEFT JOIN cust_svc USING ( svcnum ) '. 'LEFT JOIN cust_pkg USING ( pkgnum ) ',#. #'LEFT JOIN cust_main USING ( custnum ) ', - 'hashref' => { 'svcnum' => $svcnum, }, + 'hashref' => $hashref, 'extra_sql' => $search, #important } ); } +sub svc_status_html { + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + #XXX only svc_dsl for now + my $svc_x = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_dsl') + or return { 'error' => "Service not found" }; + + my $html = $svc_x->getstatus_html; + + return { 'html' => $html }; + +} + +sub svc_status_hash { + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + #XXX only svc_acct for now + my $svc_x = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_acct') + or return { 'error' => "Service not found" }; + + my ( $html, $hashref ) = $svc_x->export_getstatus; + return $hashref; + +} + +sub set_svc_status_hash { + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + #XXX only svc_acct for now + my $svc_x = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_acct') + or return { 'error' => "Service not found" }; + + warn "set_svc_status_hash ". join(' / ', map "$_=>".$p->{$_}, keys %$p ) + if $DEBUG; + my $error = $svc_x->export_setstatus($p); #$p? returns error? + return { 'error' => $error } if $error; + + return {}; #? { 'error' => '' } + +} + + +sub acct_forward_info { + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + my $svc_forward = _customer_svc_x( $custnum, + { 'srcsvc' => $p->{'svcnum'} }, + 'svc_forward', + ) + or return { 'error' => '', + 'dst' => '', + }; + + return { 'error' => '', + 'dst' => $svc_forward->dst || $svc_forward->dstsvc_acct->email, + }; + +} + +sub process_acct_forward { + my $p = shift; + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + my $old = _customer_svc_x( $custnum, + { 'srcsvc' => $p->{'svcnum'} }, + 'svc_forward', + ); + + if ( $p->{'dst'} eq '' ) { + if ( $old ) { + my $error = $old->delete; + return { 'error' => $error }; + } + return { 'error' => '' }; + } + + my $new = new FS::svc_forward { 'srcsvc' => $p->{'svcnum'}, + 'dst' => $p->{'dst'}, + }; + + my $error; + if ( $old ) { + $new->svcnum($old->svcnum); + my $cust_svc = $old->cust_svc; + $new->svcpart($old->svcpart); + $new->pkgnuym($old->pkgnum); + $error = $new->replace($old); + } else { + my $conf = new FS::Conf; + $new->svcpart($conf->config('selfservice-svc_forward_svcpart')); + + my $svc_acct = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_acct' ) + or return { 'error' => 'No service' }; #how would we even get here? + + $new->pkgnum( $svc_acct->cust_svc->pkgnum ); + + $error = $new->insert; + } + + return { 'error' => $error }; + +} + sub list_dsl_devices { my $p = shift; @@ -1620,9 +1783,10 @@ sub list_support_usage { } sub _list_cdr_usage { - my($svc_phone, $begin, $end) = @_; - map [ $_->downstream_csv('format' => 'default', 'keeparray' => 1) ], #XXX config for format - $svc_phone->get_cdrs( 'begin'=>$begin, 'end'=>$end, ); + # XXX CDR type support... + my($svc_phone, $begin, $end, %opt) = @_; + map [ $_->downstream_csv(%opt, 'keeparray' => 1) ], + $svc_phone->get_cdrs( 'begin'=>$begin, 'end'=>$end, ); } sub list_cdr_usage { @@ -1647,12 +1811,26 @@ sub _usage_details { return { 'error' => 'No service selected in list_svc_usage' } unless $svc_x; - my $header = $svcdb eq 'svc_phone' - ? [ split(',', FS::cdr::invoice_header('default') ) ] #XXX - : []; - my $cust_pkg = $svc_x->cust_svc->cust_pkg; my $freq = $cust_pkg->part_pkg->freq; + my %callback_opt; + my $header = []; + if ( $svcdb eq 'svc_phone' ) { + my $format = $cust_pkg->part_pkg->option('output_format') || ''; + $format = '' if $format =~ /^sum_/; + # sensible default if there is no format or it's a summary format + if ( $cust_pkg->part_pkg->plan eq 'voip_inbound' ) { + $format ||= 'source_default'; + $callback_opt{inbound} = 1; + } + else { + $format ||= 'default'; + } + + $callback_opt{format} = $format; + $header = [ split(',', FS::cdr::invoice_header($format) ) ]; + } + my $start = $cust_pkg->setup; #my $end = $cust_pkg->bill; # or time? my $end = time; @@ -1662,7 +1840,9 @@ sub _usage_details { $p->{ending} = $end; } - my (@usage) = &$callback($svc_x, $p->{beginning}, $p->{ending}); + my (@usage) = &$callback($svc_x, $p->{beginning}, $p->{ending}, + %callback_opt + ); #kinda false laziness with FS::cust_main::bill, but perhaps #we should really change this bit to DateTime and DateTime::Duration @@ -2332,7 +2512,7 @@ sub myaccount_passwd { unless $svc_acct->check_password($p->{'old_password'}); } - $svc_acct->_password($p->{'new_password'}); + $svc_acct->set_password($p->{'new_password'}); my $error = $svc_acct->replace(); my($label, $value) = $svc_acct->cust_svc->label; @@ -2473,7 +2653,7 @@ sub process_reset_passwd { my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $svcnum } ) or return { 'error' => "Service not found" }; - $svc_acct->_password($p->{'new_password'}); + $svc_acct->set_password($p->{'new_password'}); my $error = $svc_acct->replace(); my($label, $value) = $svc_acct->cust_svc->label;