From dbb388836b7951a3db49deda05a1ff9ba5125c17 Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 30 Nov 2006 02:27:57 +0000 Subject: prepaid download/upload tracking --- httemplate/edit/prepay_credit.cgi | 41 ++++++++++++++++++++++++-- httemplate/edit/process/prepay_credit.cgi | 8 ++++-- httemplate/misc/process/recharge_svc.html | 46 +++++++++++++++++++++++++++++ httemplate/misc/recharge_svc.html | 48 +++++++++++++++++++++++++++++++ httemplate/search/prepay_credit.html | 11 +++++-- httemplate/view/cust_main/packages.html | 34 +++++++++++++++++----- 6 files changed, 174 insertions(+), 14 deletions(-) create mode 100755 httemplate/misc/process/recharge_svc.html create mode 100755 httemplate/misc/recharge_svc.html (limited to 'httemplate') diff --git a/httemplate/edit/prepay_credit.cgi b/httemplate/edit/prepay_credit.cgi index f563e253b..7ce44c087 100644 --- a/httemplate/edit/prepay_credit.cgi +++ b/httemplate/edit/prepay_credit.cgi @@ -11,7 +11,16 @@ % 3600 => 'hours', %; % -%$cgi->param('multiplier', '60') unless $cgi->param('multiplier'); +%tie my %bytemultiplier, 'Tie::IxHash', +% 1 => 'bytes', +% 1000 => 'Kbytes', +% 1000000 => 'Mbytes', +% 1000000000 => 'Gbytes', +%; +% +%$cgi->param('multiplier', '60') unless $cgi->param('multiplier'); +%$cgi->param('upmultiplier', '1000000') unless $cgi->param('upmultiplier'); +%$cgi->param('downmultiplier', '1000000') unless $cgi->param('downmultiplier'); % % @@ -46,9 +55,11 @@ Generate -
Value: + + + + + + + +
Value: $ -and/or +and/or +
and/or + + upload +
and/or + + download +


diff --git a/httemplate/edit/process/prepay_credit.cgi b/httemplate/edit/process/prepay_credit.cgi index fb15fd8e4..ba4296900 100644 --- a/httemplate/edit/process/prepay_credit.cgi +++ b/httemplate/edit/process/prepay_credit.cgi @@ -15,8 +15,10 @@ % $error = 'Illegal number of prepaid cards: '. $cgi->param('num'); %} % -%$hashref->{amount} = $cgi->param('amount'); -%$hashref->{seconds} = $cgi->param('seconds') * $cgi->param('multiplier'); +%$hashref->{amount} = $cgi->param('amount'); +%$hashref->{seconds} = $cgi->param('seconds') * $cgi->param('multiplier'); +%$hashref->{upbytes} = $cgi->param('upbytes') * $cgi->param('upmultiplier'); +%$hashref->{downbytes} = $cgi->param('downbytes') * $cgi->param('downmultiplier'); % %$error ||= FS::prepay_credit::generate( $num, % scalar($cgi->param('type')), @@ -46,6 +48,8 @@ <% $hashref->{amount} ? sprintf('$%.2f', $hashref->{amount} ) : '' %> <% $hashref->{amount} && $hashref->{seconds} ? 'and' : '' %> <% $hashref->{seconds} ? duration_exact($hashref->{seconds}) : '' %> + <% $hashref->{upbytes} ? FS::UI::Web::bytecount_unexact($hashref->{upbytes}) : '' %> + <% $hashref->{downbytes} ? FS::UI::Web::bytecount_unexact($hashref->{downbytes}) : '' %>
% } diff --git a/httemplate/misc/process/recharge_svc.html b/httemplate/misc/process/recharge_svc.html new file mode 100755 index 000000000..ae526689e --- /dev/null +++ b/httemplate/misc/process/recharge_svc.html @@ -0,0 +1,46 @@ +% +% +%#untaint svcnum +%my $svcnum = $cgi->param('svcnum'); +%$svcnum =~ /^(\d+)$/ || die "Illegal svcnum"; +%$svcnum = $1; +% +%#untaint prepaid +%my $prepaid = $cgi->param('prepaid'); +%$prepaid =~ /^(\w*)$/; +%$prepaid = $1; +% +%my $error = ''; +%my $svc_acct = qsearchs( 'svc_acct', {'svcnum'=>$svcnum} ); +%$error = "Can't recharge service $svcnum. " unless $svc_acct; +% +%my $cust_main = $svc_acct->cust_svc->cust_pkg->cust_main; +% +%my $oldAutoCommit = $FS::UID::AutoCommit; +%local $FS::UID::AutoCommit = 0; +%my $dbh = dbh; +% +% +%unless ($error) { +% +%my ($amount, $seconds, $up, $down) = (0, 0, 0, 0); +%$error = $cust_main->get_prepay($prepaid, \$amount, \$seconds, \$up, \$down) +% || $svc_acct->increment_seconds($seconds) +% || $svc_acct->increment_upbytes($up) +% || $svc_acct->increment_downbytes($down) +% || $svc_acct->increment_totalbytes($up + $down) +% || $cust_main->insert_cust_pay_prepay( $amount, $prepaid ); +%} +% +%if ($error) { +% $cgi->param('error', $error); +% $dbh->rollback if $oldAutoCommit; +% print $cgi->redirect(popurl(2). "recharge_svc.html?". $cgi->query_string ); +%} +% +<% header("Package recharged") %> + + + diff --git a/httemplate/misc/recharge_svc.html b/httemplate/misc/recharge_svc.html new file mode 100755 index 000000000..61f738455 --- /dev/null +++ b/httemplate/misc/recharge_svc.html @@ -0,0 +1,48 @@ +<% include('/elements/header-popup.html', 'Recharge Service' ) %> + +% if ( $cgi->param('error') ) { + Error: <% $cgi->param('error') %> +

+% } + +
+ + +

+<% "Recharge $svcnum: $label - $value" %> +<% ntable("#cccccc", 2) %> + + + Enter prepaid card: + + + + + +
+ + +
+ + + +<%init> +my($svcnum, $cust_svc, $label, $value, $prepaid); +if ( $cgi->param('error') ) { + $svcnum = $cgi->param('svcnum'); + $prepaid = $cgi->param('prepaid'); +} elsif ( $cgi->param('svcnum') =~ /^(\d+)$/ ) { + $svcnum = $1; +} else { + die "illegal query ". $cgi->keywords; +} + +my $title = 'Recharge Service'; + +$cust_svc = qsearchs('cust_svc', {'svcnum' => $svcnum}); +die "No such service: $svcnum" unless $cust_svc; + +($label, $value) = $cust_svc->label; + + + diff --git a/httemplate/search/prepay_credit.html b/httemplate/search/prepay_credit.html index dff8a3d9a..fecb12f2a 100644 --- a/httemplate/search/prepay_credit.html +++ b/httemplate/search/prepay_credit.html @@ -9,7 +9,6 @@ %my $count_query = 'SELECT COUNT(*) FROM prepay_credit'; %$count_query .= ' WHERE agentnum = '. $agent->agentnum if $agent; % -% <% include( 'elements/search.html', 'title' => 'Unused Prepaid Cards'. ($agent ? ' for '. $agent->agent : ''), @@ -23,16 +22,24 @@ }, 'count_query' => $count_query, #'redirect' => $link, - 'header' => [ '#', qw(Amount Time Agent) ], + 'header' => [ '#', qw(Amount Time Upload Download Agent) ], 'fields' => [ 'identifier', sub { sprintf('$%.2f', shift->amount ) }, sub { my $c = shift; $c ? duration_exact($c->seconds) : '' }, + sub { my $c = shift; + $c ? FS::UI::Web::bytecount_unexact($c->upbytes) : '' + }, + sub { my $c = shift; + $c ? FS::UI::Web::bytecount_unexact($c->downbytes) : '' + }, sub { my $agent = shift->agent; $agent ? $agent->agent : ''; }, ], 'links' => [ + '', + '', '', '', '', diff --git a/httemplate/view/cust_main/packages.html b/httemplate/view/cust_main/packages.html index f93a0764b..0a386f265 100755 --- a/httemplate/view/cust_main/packages.html +++ b/httemplate/view/cust_main/packages.html @@ -343,17 +343,31 @@ Current packages % foreach my $service (@{$svcpart->{services}}) { - <%svc_link($svcpart,$service)%> + <%svc_link($svcpart,$service)%> <%svc_label_link($svcpart,$service)%> -% if ( $curuser->access_right('Unprovision customer service') ) { - - ( <%svc_unprovision_link($service)%> ) - + -% } +% if ( $curuser->access_right('Recharge customer service') +% && ($svcpart->{'svcdb'} eq 'svc_acct') +% && ($service->{seconds} ne '' +% || $service->{upbytes} ne '' +% || $service->{downbytes} ne '' +% || $service->{totalbytes} ne '' ) +% ) { + ( <%svc_recharge_link($service)%> ) +% } + + + + +% if ( $curuser->access_right('Unprovision customer service') ) { + ( <%svc_unprovision_link($service)%> ) +% } + + % } % if ( ! $pkg->{'cancel'} @@ -371,7 +385,6 @@ Current packages % } - % } #end display packages @@ -440,6 +453,7 @@ Current packages % my $svc = { % 'svcnum' => $cust_svc->svcnum, % 'label' => ($cust_svc->label)[1], +% $cust_svc->svc_x->hash, % }; % % #false laziness with above, to catch extraneous services. whole @@ -516,6 +530,12 @@ Current packages % qq!'Permanently unprovision and delete this service?')">Unprovision!; %} % +%sub svc_recharge_link { +% my $svc = shift or return ''; +% +% qq!Recharge!; +%} +% %# This should be generalized to use config options to determine order. %sub pkgsort_pkgnum_cancel { % if ($a->{cancel} and $b->{cancel}) { -- cgit v1.2.1