2 <% include('/edit/elements/rate_detail.html',
9 'countrycode' => '237',
12 If regionnum is specified, this produces column headers plus
13 one row of rate details for that region (in all time periods).
14 Otherwise, there's one row for each region in the specified
15 countrycode (or each region anywhere, if there is no countrycode),
16 with row headers showing the region name and prefixes.
19 <% include('/elements/table-grid.html') %>
23 % my $hlink = $hlinks[$col];
26 <% $hlink ? qq!<A HREF="$hlink">$_</A>! : $_ %>
32 % foreach my $r (@rows) {
34 % if ( !$opt{'regionnum'} ) {
36 % foreach ($r->regionname, $r->prefixes_short) {
38 <A HREF="<% $p.'edit/rate_region.cgi?'.$r->regionnum %>"><% $_ %></A>
42 % elsif ( !$opt{'ratenum'} ) {
45 <A HREF="<% $p.'edit/rate.cgi?'.$r->ratenum %>"><% $r->ratename %></A>
48 % foreach my $rate_time (@rate_time, '') {
50 % my $detail = $details[$row][$col];
52 <TABLE CLASS="inv" STYLE="border:none">
53 <TR><TD><% edit_link($detail) %><% $money_char.$detail->min_charge %>
54 <% $detail->sec_granularity ? ' / minute':' / call' %>
57 <% granularity_detail($detail) %>
58 <% min_included_detail($detail) %>
59 <% conn_charge_detail($detail) %>
60 <TR><TD><% $rate_time ? delete_link($detail) : '' %></TD></TR>
64 <% add_link($rate, $region, $rate_time) %>
68 % } # foreach @rate_time
71 % }# foreach @rate_region
76 tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
77 tie my %conn_secs, 'Tie::IxHash', FS::rate_detail::conn_secs();
79 my $conf = new FS::Conf;
80 my $money_char = $conf->config('money_char') || '$';
83 '<FONT SIZE="-1">'.shift.'</FONT>'
85 my $edit_hint = small('(edit)');
88 my $rate_detail = shift;
89 my $ratedetailnum = $rate_detail->ratedetailnum;
90 '<A HREF="javascript:void(0);" onclick="'.
91 include( '/elements/popup_link_onclick.html',
92 'action' => "${p}edit/rate_detail.html?$ratedetailnum",
93 'actionlabel' => 'Edit rate',
95 #default# 'width' => 540,
96 #default# 'color' => '#333399',
101 my ($rate, $region, $rate_time) = @_;
102 '<A HREF="javascript:void(0);" onclick="'.
103 include( '/elements/popup_link_onclick.html',
104 'action' => "${p}edit/rate_detail.html?ratenum=".
109 ';ratetimenum='.$rate_time->ratetimenum :
111 'actionlabel' => 'Add rate',
113 ).'">'.small('(add)').'</A>'
117 my $rate_detail = shift;
118 my $ratedetailnum = $rate_detail->ratedetailnum;
119 my $onclick = include( '/elements/popup_link_onclick.html',
120 'action' => "${p}misc/delete-rate_detail.html?$ratedetailnum",
121 'actionlabel' => 'Delete rate',
126 $onclick = "if(confirm('Delete this rate?')) { $onclick }";
127 qq!<A HREF="javascript:void(0);" onclick="$onclick">!.small('(delete)').'</A>'
130 sub granularity_detail {
131 my $rate_detail = shift;
132 if($rate_detail->sec_granularity != 60 && $rate_detail->sec_granularity > 0) {
134 small('in '.$granularity{$rate_detail->sec_granularity}.' increments').
140 sub min_included_detail {
141 my $rate_detail = shift;
142 if($rate_detail->min_included) {
144 small( $rate_detail->min_included .
145 ($rate_detail->sec_granularity ?
146 ' minutes included' :
147 ' calls included') ).
153 sub conn_charge_detail {
154 my $rate_detail = shift;
155 if($rate_detail->conn_charge > 0) {
156 #return '' unless $rate_detail->conn_charge > 0 || $rate_detail->conn_sec;
158 small( $money_char. $rate_detail->conn_charge.
159 ' for '.$conn_secs{$rate_detail->conn_sec}
170 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
173 my $ratenum = $opt{'ratenum'} || '';
174 my $regionnum = $opt{'regionnum'} || '';
176 # either of these, if the $opt isn't passed, will be set to the
177 # correct object when generating each row.
178 my $rate = qsearchs('rate', { 'ratenum' => $ratenum } ) if $ratenum;
179 my $region = qsearchs('rate_region', { 'regionnum' => $regionnum }) if $regionnum;
181 my @rate_time = qsearch('rate_time', {});
183 map( { $_->ratetimename } @rate_time ),
185 my @hlinks = map( {$p.'edit/rate_time.cgi?'.$_->ratetimenum} @rate_time ), '';
186 my @rtns = ( map( { $_->ratetimenum } @rate_time ), '' );
192 @rows = qsearch('rate_region',
193 { ratenum => $ratenum, regionnum => $regionnum });
197 if ( $opt{'countrycode'} ) {
198 $where = "WHERE 0 < (
199 SELECT COUNT(*) FROM rate_prefix
200 WHERE rate_prefix.regionnum = rate_region.regionnum
201 AND countrycode = '$opt{countrycode}'
204 @rows = qsearch({ table => 'rate_region',
208 die "no region found" if !@rows;
210 unshift @header, 'Region', 'Prefix(es)';
211 unshift @hlinks, '', '';
213 foreach my $region (@rows) {
214 push @details, [ map { qsearchs('rate_detail',
215 { 'ratenum' => $ratenum,
216 'dest_regionnum' => $region->regionnum,
217 'ratetimenum' => $_ } ) or ''
222 elsif ( $regionnum ) {
223 @rows = qsearch('rate', {}) or die "no rate plans found";
224 unshift @header, 'Rate plan';
226 foreach my $rate (@rows) {
227 push @details, [ map { qsearchs('rate_detail',
228 { 'ratenum' => $rate->ratenum,
229 'dest_regionnum' => $regionnum,
230 'ratetimenum' => $_ } ) or ''
236 die "no ratenum or regionnum specified";