summaryrefslogtreecommitdiff
path: root/httemplate/browse/rate_detail.html
blob: 23bc23ff89cbddf55aeb4c0cd427173e39cc4bd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<% include( 'elements/browse.html',
     'title'          => $title,
     'name_singular'  => 'rate',
     'html_init'      => $html_init,
     'menubar'        => [ 'Rate plans' => $p.'browse/rate.cgi' ],
     'query'          => {
                           'table'     => 'rate_detail',
                           'addl_from' => $join,
                           'hashref'   => { 'ratenum' => $ratenum },
                           'extra_sql' => $where,
                         },
     'count_query'    => "SELECT COUNT(*) FROM rate_detail $join".
                         " WHERE ratenum = $ratenum $where",
     'header'         => [
                           'Region',
                           'Prefix(es)',
                           'Included<BR>minutes',
                           'Charge per<BR>minute',
                           'Granularity',
                           'Usage class',
                         ],
     'fields'         => [
                           'regionname',
                           sub { shift->dest_region->prefixes_short },
                           sub { shift->min_included.
                                 '&nbsp;<FONT SIZE="-1">(edit)</FONT>';
                               },
                           sub { $money_char. shift->min_charge.
                                 '&nbsp;<FONT SIZE="-1">(edit)</FONT>';
                               },
                           sub { $granularity{ shift->sec_granularity } },
                           'classname',
                         ],
     'links'          => [ '', '', $edit_link,    $edit_link,    '', '' ],
     'link_onclicks'  => [ '', '', $edit_onclick, $edit_onclick, '', '' ],
     'align'          => 'llrrcc',
   )
%>
<%once>

tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();

my $conf = new FS::Conf;
my $money_char = $conf->config('money_char') || '$';

my $join =
  ' JOIN rate_region ON ( rate_detail.dest_regionnum = rate_region.regionnum )';

my $edit_link = [ 'javascript:void(0);', sub { ''; } ];

my $edit_onclick = sub {
  my $rate_detail = shift;
  my $ratedetailnum = $rate_detail->ratedetailnum;
  include( '/elements/popup_link_onclick.html',
             'action'      => "${p}edit/rate_detail.html?$ratedetailnum",
             'actionlabel' => 'Edit rate',
             'height'      => 420,
             #default# 'width'       => 540,
             #default# 'color'       => '#333399',
         );
};

</%once>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');

my $html_init = include('/elements/init_overlib.html');

$cgi->param('ratenum') =~ /^(\d+)$/ or die "unparsable ratenum";
my $ratenum = $1;
my $rate = qsearchs('rate', { 'ratenum' => $ratenum } )
  or die "unknown ratenum $ratenum";
my $ratename = $rate->ratename;
my $title = "$ratename rates";

my @where = ();

if ( $cgi->param('countrycode') =~ /^(\d+)$/ ) { 
  my $countrycode = $1;
  push @where, "0 < ( SELECT COUNT(*) FROM rate_prefix
                        WHERE rate_prefix.regionnum = rate_region.regionnum
                          AND countrycode = '$countrycode'
                    )
               ";
  $title .= " for +$countrycode";
}

my $where = scalar(@where) ? ' AND '.join(' AND ', @where ) : '';

</%init>