6bf46bf7cb5f7d33f0ea92388069919d75bbf26c
[freeside.git] / httemplate / edit / process / prepay_credit.cgi
1 %
2 %my $hashref = {};
3 %
4 %my $agent = '';
5 %if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
6 %  $agent = qsearchs('agent', { 'agentnum' => $hashref->{agentnum}=$1 } );
7 %}
8 %
9 %my $error = '';
10 %
11 %my $num = 0;
12 %if ( $cgi->param('num') =~ /^\s*(\d+)\s*$/ ) {
13 %  $num = $1;
14 %} else {
15 %  $error = 'Illegal number of prepaid cards: '. $cgi->param('num');
16 %}
17 %
18 %$hashref->{amount}    = $cgi->param('amount');
19 %$hashref->{seconds}   = $cgi->param('seconds') * $cgi->param('multiplier');
20 %$hashref->{upbytes}   = $cgi->param('upbytes') * $cgi->param('upmultiplier');
21 %$hashref->{downbytes} = $cgi->param('downbytes') * $cgi->param('downmultiplier');
22 %$hashref->{totalbytes} = $cgi->param('totalbytes') * $cgi->param('totalmultiplier');
23 %
24 %$error ||= FS::prepay_credit::generate( $num,
25 %                                        scalar($cgi->param('type')), 
26 %                                        $hashref
27 %                                      );
28 %
29 %unless ( ref($error) ) {
30 %  $cgi->param('error', $error );
31 %
32 <%
33   $cgi->redirect(popurl(3). "edit/prepay_credit.cgi?". $cgi->query_string )
34 %>
35 % } else { 
36
37
38 <% include("/elements/header.html", "$num prepaid cards generated".
39               ( $agent ? ' for '.$agent->agent : '' ),
40             menubar( 'Main menu' => popurl(3) )
41           )
42 %>
43
44 <FONT SIZE="+1">
45 % foreach my $card ( @$error ) { 
46
47   <code><% $card %></code>
48   -
49   <% $hashref->{amount} ? sprintf('$%.2f', $hashref->{amount} ) : '' %>
50   <% $hashref->{amount} && $hashref->{seconds} ? 'and' : '' %>
51   <% $hashref->{seconds} ? duration_exact($hashref->{seconds}) : '' %>
52   <% $hashref->{upbytes}   ? FS::UI::Web::bytecount_unexact($hashref->{upbytes}) : '' %>
53   <% $hashref->{downbytes} ? FS::UI::Web::bytecount_unexact($hashref->{downbytes}) : '' %>
54   <% $hashref->{totalbytes} ? FS::UI::Web::bytecount_unexact($hashref->{totalbytes}) : '' %>
55   <br>
56 % } 
57
58
59 </FONT>
60
61 </BODY></HTML>
62 % } 
63