36e808fec89a4dd2ac5a6b44a38a4960456b1b7a
[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                          ],
21      'fields'         => [
22                            'regionname',
23                            sub { shift->dest_region->prefixes_short },
24                            sub { shift->min_included.
25                                  '&nbsp;<FONT SIZE="-1">(edit)</FONT>';
26                                },
27                            sub { $money_char. shift->min_charge.
28                                  '&nbsp;<FONT SIZE="-1">(edit)</FONT>';
29                                },
30                            sub { $granularity{ shift->sec_granularity } },
31                          ],
32      'links'          => [ '', '', $edit_link,    $edit_link,    '' ],
33      'link_onclicks'  => [ '', '', $edit_onclick, $edit_onclick, '' ],
34      'align'          => 'llrrc',
35    )
36 %>
37 <%once>
38
39 tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
40
41 my $conf = new FS::Conf;
42 my $money_char = $conf->config('money_char') || '$';
43
44 my $join =
45   ' JOIN rate_region ON ( rate_detail.dest_regionnum = rate_region.regionnum )';
46
47 my $edit_link = [ 'javascript:void(0);', sub { ''; } ];
48
49 my $edit_onclick = sub {
50   my $rate_detail = shift;
51   my $ratedetailnum = $rate_detail->ratedetailnum;
52   include( '/elements/popup_link_onclick.html',
53              'action'      => "${p}edit/rate_detail.html?$ratedetailnum",
54              'actionlabel' => 'Edit rate',
55              'height'      => 420,
56              #default# 'width'       => 540,
57              #default# 'color'       => '#333399',
58          );
59 };
60
61 </%once>
62 <%init>
63
64 die "access denied"
65   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
66
67 my $html_init = include('/elements/init_overlib.html');
68
69 $cgi->param('ratenum') =~ /^(\d+)$/ or die "unparsable ratenum";
70 my $ratenum = $1;
71 my $rate = qsearchs('rate', { 'ratenum' => $ratenum } )
72   or die "unknown ratenum $ratenum";
73 my $ratename = $rate->ratename;
74 my $title = "$ratename rates";
75
76 my @where = ();
77
78 if ( $cgi->param('countrycode') =~ /^(\d+)$/ ) { 
79   my $countrycode = $1;
80   push @where, "0 < ( SELECT COUNT(*) FROM rate_prefix
81                         WHERE rate_prefix.regionnum = rate_region.regionnum
82                           AND countrycode = '$countrycode'
83                     )
84                ";
85   $title .= " for +$countrycode";
86 }
87
88 my $where = scalar(@where) ? ' AND '.join(' AND ', @where ) : '';
89
90 </%init>