23bc23ff89cbddf55aeb4c0cd427173e39cc4bd0
[freeside.git] / httemplate / browse / rate_detail.html
1 <% include( 'elements/browse.html',
2      'title'          => $title,
3      'name_singular'  => 'rate',
4      'html_init'      => $html_init,
5      'menubar'        => [ 'Rate plans' => $p.'browse/rate.cgi' ],
6      'query'          => {
7                            'table'     => 'rate_detail',
8                            'addl_from' => $join,
9                            'hashref'   => { 'ratenum' => $ratenum },
10                            'extra_sql' => $where,
11                          },
12      'count_query'    => "SELECT COUNT(*) FROM rate_detail $join".
13                          " WHERE ratenum = $ratenum $where",
14      'header'         => [
15                            'Region',
16                            'Prefix(es)',
17                            'Included<BR>minutes',
18                            'Charge per<BR>minute',
19                            'Granularity',
20                            'Usage class',
21                          ],
22      'fields'         => [
23                            'regionname',
24                            sub { shift->dest_region->prefixes_short },
25                            sub { shift->min_included.
26                                  '&nbsp;<FONT SIZE="-1">(edit)</FONT>';
27                                },
28                            sub { $money_char. shift->min_charge.
29                                  '&nbsp;<FONT SIZE="-1">(edit)</FONT>';
30                                },
31                            sub { $granularity{ shift->sec_granularity } },
32                            'classname',
33                          ],
34      'links'          => [ '', '', $edit_link,    $edit_link,    '', '' ],
35      'link_onclicks'  => [ '', '', $edit_onclick, $edit_onclick, '', '' ],
36      'align'          => 'llrrcc',
37    )
38 %>
39 <%once>
40
41 tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
42
43 my $conf = new FS::Conf;
44 my $money_char = $conf->config('money_char') || '$';
45
46 my $join =
47   ' JOIN rate_region ON ( rate_detail.dest_regionnum = rate_region.regionnum )';
48
49 my $edit_link = [ 'javascript:void(0);', sub { ''; } ];
50
51 my $edit_onclick = sub {
52   my $rate_detail = shift;
53   my $ratedetailnum = $rate_detail->ratedetailnum;
54   include( '/elements/popup_link_onclick.html',
55              'action'      => "${p}edit/rate_detail.html?$ratedetailnum",
56              'actionlabel' => 'Edit rate',
57              'height'      => 420,
58              #default# 'width'       => 540,
59              #default# 'color'       => '#333399',
60          );
61 };
62
63 </%once>
64 <%init>
65
66 die "access denied"
67   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
68
69 my $html_init = include('/elements/init_overlib.html');
70
71 $cgi->param('ratenum') =~ /^(\d+)$/ or die "unparsable ratenum";
72 my $ratenum = $1;
73 my $rate = qsearchs('rate', { 'ratenum' => $ratenum } )
74   or die "unknown ratenum $ratenum";
75 my $ratename = $rate->ratename;
76 my $title = "$ratename rates";
77
78 my @where = ();
79
80 if ( $cgi->param('countrycode') =~ /^(\d+)$/ ) { 
81   my $countrycode = $1;
82   push @where, "0 < ( SELECT COUNT(*) FROM rate_prefix
83                         WHERE rate_prefix.regionnum = rate_region.regionnum
84                           AND countrycode = '$countrycode'
85                     )
86                ";
87   $title .= " for +$countrycode";
88 }
89
90 my $where = scalar(@where) ? ' AND '.join(' AND ', @where ) : '';
91
92 </%init>