From 1eff7a1cd742bab7a0084d55f74b2f53c1f84e64 Mon Sep 17 00:00:00 2001 From: levinse Date: Mon, 20 Dec 2010 03:14:47 +0000 Subject: [PATCH] self-service improvements: DIDs, RT10885 --- FS/FS/ClientAPI/MyAccount.pm | 84 +++++++++++++++++++++++ FS/FS/Conf.pm | 7 ++ fs_selfservice/FS-SelfService/SelfService.pm | 3 +- fs_selfservice/FS-SelfService/cgi/selfservice.cgi | 44 ++++++++++-- fs_selfservice/FS-SelfService/cgi/ws_list.html | 27 +++++++- 5 files changed, 155 insertions(+), 10 deletions(-) diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index f5c81e1b8..f6a71cd9b 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -32,6 +32,9 @@ use FS::payby; use FS::acct_rt_transaction; use HTML::Entities; use FS::TicketSystem; +use Text::CSV_XS; +use IO::Scalar; +use Spreadsheet::WriteExcel; $DEBUG = 0; $me = '[FS::ClientAPI::MyAccount]'; @@ -1790,6 +1793,85 @@ sub create_ticket { } +sub did_report { + my $p = shift; + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + return { error => 'requested format not implemented' } + unless ($p->{'format'} eq 'csv' || $p->{'format'} eq 'xls'); + + my $conf = new FS::Conf; + my $age_threshold = 0; + $age_threshold = time() - $conf->config('selfservice-recent-did-age') + if ($p->{'recentonly'} && $conf->exists('selfservice-recent-did-age')); + + my $search = { 'custnum' => $custnum }; + $search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent'; + my $cust_main = qsearchs('cust_main', $search ) + or return { 'error' => "unknown custnum $custnum" }; + +# does it make more sense to just run one sql query for this instead of all the +# insanity below? would increase performance greately for large data sets? + my @svc_phone = (); + foreach my $cust_pkg ( $cust_main->ncancelled_pkgs ) { + my @part_svc = $cust_pkg->part_svc; + foreach my $part_svc ( @part_svc ) { + if($part_svc->svcdb eq 'svc_phone'){ + my @cust_pkg_svc = @{$part_svc->cust_pkg_svc}; + foreach my $cust_pkg_svc ( @cust_pkg_svc ) { + push @svc_phone, $cust_pkg_svc->svc_x + if $cust_pkg_svc->date_inserted >= $age_threshold; + } + } + } + } + + my $csv; + my $xls; + my($xls_r,$xls_c) = (0,0); + my $xls_workbook; + my $content = ''; + my @fields = qw( countrycode phonenum pin sip_password phone_name ); + if($p->{'format'} eq 'csv') { + $csv = new Text::CSV_XS { 'always_quote' => 1, + 'eol' => "\n", + }; + return { 'error' => 'Unable to create CSV' } unless $csv->combine(@fields); + $content .= $csv->string; + } + elsif($p->{'format'} eq 'xls') { + my $XLS1 = new IO::Scalar \$content; + $xls_workbook = Spreadsheet::WriteExcel->new($XLS1) + or return { 'error' => "Error opening .xls file: $!" }; + $xls = $xls_workbook->add_worksheet('DIDs'); + foreach ( @fields ) { + $xls->write(0,$xls_c++,$_); + } + $xls_r++; + } + + foreach my $svc_phone ( @svc_phone ) { + my @cols = map { $svc_phone->$_ } @fields; + if($p->{'format'} eq 'csv') { + return { 'error' => 'Unable to create CSV' } + unless $csv->combine(@cols); + $content .= $csv->string; + } + elsif($p->{'format'} eq 'xls') { + $xls_c = 0; + foreach ( @cols ) { + $xls->write($xls_r,$xls_c++,$_); + } + $xls_r++; + } + } + + $xls_workbook->close() if $p->{'format'} eq 'xls'; + + { content => $content, format => $p->{'format'}, }; +} + sub get_ticket { my $p = shift; my($context, $session, $custnum) = _custoragent_session_custnum($p); @@ -1799,6 +1881,8 @@ sub get_ticket { FS::TicketSystem->init(); if(length($p->{'reply'})) { +# currently this allows anyone to correspond on any ticket as fs_selfservice +# probably bad... my @err_or_res = FS::TicketSystem->correspond_ticket( '', #create RT session based on FS CurrentUser (fs_selfservice) 'ticket_id' => $p->{'ticket_id'}, diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index e975fe1d3..22e761f4a 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2278,6 +2278,13 @@ and customer address. Include units.', }, { + 'key' => 'selfservice-recent-did-age', + 'section' => 'self-service', + 'description' => 'If specified, defines "recent", in number of seconds, for "Download recently allocated DIDs" in self-service.', + 'type' => 'text', + }, + + { 'key' => 'selfservice_server-view-wholesale', 'section' => 'self-service', 'description' => 'If enabled, use a wholesale package view in the self-service.', diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index 135feebd5..b992ac941 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -61,7 +61,8 @@ $socket .= '.'.$tag if defined $tag && length($tag); 'unprovision_svc' => 'MyAccount/unprovision_svc', 'myaccount_passwd' => 'MyAccount/myaccount_passwd', 'create_ticket' => 'MyAccount/create_ticket', - 'get_ticket' => 'MyAccount/get_ticket', + 'get_ticket' => 'MyAccount/get_ticket', + 'did_report' => 'MyAccount/did_report', 'signup_info' => 'Signup/signup_info', 'skin_info' => 'MyAccount/skin_info', 'access_info' => 'MyAccount/access_info', diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi index acd64146e..72e49b47c 100644 --- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -16,7 +16,7 @@ use FS::SelfService qw( part_svc_info provision_acct provision_external unprovision_svc change_pkg suspend_pkg domainselector list_svcs list_svc_usage list_cdr_usage list_support_usage - myaccount_passwd list_invoices create_ticket get_ticket + myaccount_passwd list_invoices create_ticket get_ticket did_report mason_comp ); @@ -73,7 +73,7 @@ $session_id = $cgi->param('session'); #order|pw_list XXX ??? $cgi->param('action') =~ - /^(myaccount|tktcreate|tktview|invoices|view_invoice|make_payment|make_ach_payment|make_term_payment|make_thirdparty_payment|payment_results|ach_payment_results|recharge_prepay|recharge_results|logout|change_bill|change_ship|change_pay|process_change_bill|process_change_ship|process_change_pay|customer_order_pkg|process_order_pkg|customer_change_pkg|process_change_pkg|process_order_recharge|provision|provision_svc|process_svc_acct|process_svc_external|delete_svc|view_usage|view_usage_details|view_cdr_details|view_support_details|change_password|process_change_password|customer_suspend_pkg|process_suspend_pkg)$/ + /^(myaccount|tktcreate|tktview|didreport|invoices|view_invoice|make_payment|make_ach_payment|make_term_payment|make_thirdparty_payment|payment_results|ach_payment_results|recharge_prepay|recharge_results|logout|change_bill|change_ship|change_pay|process_change_bill|process_change_ship|process_change_pay|customer_order_pkg|process_order_pkg|customer_change_pkg|process_change_pkg|process_order_recharge|provision|provision_svc|process_svc_acct|process_svc_external|delete_svc|view_usage|view_usage_details|view_cdr_details|view_support_details|change_password|process_change_password|customer_suspend_pkg|process_suspend_pkg)$/ or die "unknown action ". $cgi->param('action'); my $action = $1; @@ -83,9 +83,9 @@ $FS::SelfService::DEBUG = $DEBUG; my $result = eval "&$action();"; die $@ if $@; -if ( $result->{error} eq "Can't resume session" - || $result->{error} eq "Expired session" ) { #ick - +#fixed "Use of uninitialized value in string eq"; very annoying when developing +if ( $result->{error} && ($result->{error} eq "Can't resume session" + || $result->{error} eq "Expired session") ) { my $login_info = login_info(); do_template('login', $login_info); exit; @@ -619,6 +619,15 @@ sub logout { FS::SelfService::logout( 'session_id' => $session_id ); } +sub didreport { + my $result = did_report( 'session_id' => $session_id, + 'format' => $cgi->param('type'), + 'recentonly' => $cgi->param('recentonly'), + ); + die $result->{'error'} if exists $result->{'error'} && $result->{'error'}; + $result; +} + sub provision { my $result = list_pkgs( 'session_id' => $session_id ); die $result->{'error'} if exists $result->{'error'} && $result->{'error'}; @@ -778,10 +787,31 @@ sub do_template { or die $Text::Template::ERROR; #warn "filling in $template with $fill_in\n"; - print $cgi->header( '-expires' => 'now' ), - $template->fill_in( PACKAGE => 'FS::SelfService::_selfservicecgi', + + if($result && ref($result) && $result->{'format'} && $result->{'content'} + && $result->{'format'} eq 'csv') { + print $cgi->header('-expires' => 'now', + '-Content-Type' => 'text/csv', + '-Content-Disposition' => "attachment;filename=output.csv", + ), + $result->{'content'}; + } + elsif($result && ref($result) && $result->{'format'} && $result->{'content'} + && $result->{'format'} eq 'xls') { + print $cgi->header('-expires' => 'now', + '-Content-Type' => 'application/vnd.ms-excel', + '-Content-Disposition' => "attachment;filename=output.xls", + '-Content-Length' => length($result->{'content'}), + ), + $result->{'content'}; + } + else { + print $cgi->header( '-expires' => 'now' ), + $template->fill_in( PACKAGE => 'FS::SelfService::_selfservicecgi', HASH => $fill_in ); + } + } #*FS::SelfService::_selfservicecgi::include = \&Text::Template::fill_in_file; diff --git a/fs_selfservice/FS-SelfService/cgi/ws_list.html b/fs_selfservice/FS-SelfService/cgi/ws_list.html index 93425e107..f4beedf33 100644 --- a/fs_selfservice/FS-SelfService/cgi/ws_list.html +++ b/fs_selfservice/FS-SelfService/cgi/ws_list.html @@ -55,6 +55,8 @@ else { $pkgparts{$pkg->{pkgpart}}{pkg} = $part_pkg->{pkg}; } + $OUT .= "
"; + $OUT .= qq! !; my($pkgpart,$counts); while(($pkgpart,$count) = each %pkgparts){ @@ -68,8 +70,10 @@ else { } $OUT .= "
PackageStatus
"; + $OUT .= qq!
!; + if ( @login_svcpart ) { - $OUT .= "


Self-service accounts
"; + $OUT .= "Self-service accounts
"; foreach my $pkg ( @cust_pkg ) { @cust_svc = @{$pkg->{cust_svc}}; @part_svc = @{$pkg->{part_svc}}; @@ -98,6 +102,25 @@ else { } # foreach cust_pkg } # login_svcpart -} + my $hasPhone = 0; + foreach my $pkg ( @cust_pkg ) { + @cust_svc = @{$pkg->{cust_svc}}; + foreach my $cust_svc ( @cust_svc ) { + @label = @{$cust_svc->{'label'}}; + $hasPhone = 1 if $label[2] eq 'svc_phone'; + } + } + if ( $hasPhone ) { + $link = "${url}didreport;type="; + $OUT .= "


Download currently allocated DIDs:
"; + $OUT .= qq!   CSV | + Excel!; + $OUT .= "

Download recently allocated DIDs:
"; + $OUT .= qq!   CSV | + Excel!; + } + + $OUT .= "
"; +} %> -- 2.11.0