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?regionnum='.$r->regionnum %>"><% $_ %></A>
42 % elsif ( !$opt{'ratenum'} ) {
45 <A HREF="<% $p.'edit/rate.cgi?ratenum='.$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' %>
55 % if ( $detail->min_cost ) {
56 (<% $money_char.$detail->min_cost %> cost)
60 <% granularity_detail($detail) %>
61 <% min_included_detail($detail) %>
62 <% conn_charge_detail($detail) %>
63 <TR><TD><% ( $rate_time || $cdrtypenum ) ? delete_link($detail) : '' %>
68 <% add_link($rate, $region, $rate_time, $cdrtypenum) %>
72 % } # foreach @rate_time
75 % }# foreach @rate_region
80 tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
81 tie my %conn_secs, 'Tie::IxHash', FS::rate_detail::conn_secs();
83 my $conf = new FS::Conf;
84 my $money_char = $conf->config('money_char') || '$';
87 '<FONT SIZE="-1">'.shift.'</FONT>'
89 my $edit_hint = small('(edit)');
92 my $rate_detail = shift;
93 my $ratedetailnum = $rate_detail->ratedetailnum;
94 '<A HREF="javascript:void(0);" onclick="'.
95 include( '/elements/popup_link_onclick.html',
96 'action' => "${p}edit/rate_detail.html?$ratedetailnum",
97 'actionlabel' => 'Edit rate',
99 #default# 'width' => 540,
100 #default# 'color' => '#333399',
105 my ($rate, $region, $rate_time, $cdrtypenum) = @_;
106 '<A HREF="javascript:void(0);" onclick="'.
107 include( '/elements/popup_link_onclick.html',
108 'action' => "${p}edit/rate_detail.html?ratenum=".
113 ($rate_time ? $rate_time->ratetimenum : '').
114 ";cdrtypenum=$cdrtypenum",
115 'actionlabel' => 'Add rate',
117 ).'">'.small('(add)').'</A>'
121 my $rate_detail = shift;
122 my $ratedetailnum = $rate_detail->ratedetailnum;
123 my $onclick = include( '/elements/popup_link_onclick.html',
124 'action' => "${p}misc/delete-rate_detail.html?$ratedetailnum",
125 'actionlabel' => 'Delete rate',
130 $onclick = "if(confirm('Delete this rate?')) { $onclick }";
131 qq!<A HREF="javascript:void(0);" onclick="$onclick">!.small('(delete)').'</A>'
134 sub granularity_detail {
135 my $rate_detail = shift;
136 if($rate_detail->sec_granularity != 60 && $rate_detail->sec_granularity > 0) {
138 small('in '.$granularity{$rate_detail->sec_granularity}.' increments').
144 sub min_included_detail {
145 my $rate_detail = shift;
146 if($rate_detail->min_included) {
148 small( $rate_detail->min_included .
149 ($rate_detail->sec_granularity ?
150 ' minutes included' :
151 ' calls included') ).
157 sub conn_charge_detail {
158 my $rate_detail = shift;
159 if($rate_detail->conn_charge > 0) {
160 #return '' unless $rate_detail->conn_charge > 0 || $rate_detail->conn_sec;
162 small( $money_char. $rate_detail->conn_charge.
163 ( $rate_detail->conn_cost
164 ? ' ('. $money_char.$rate_detail->conn_cost. ' cost)'
167 ' for '. $conn_secs{$rate_detail->conn_sec}
178 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
181 my $ratenum = $opt{'ratenum'} || '';
182 my $regionnum = $opt{'regionnum'} || '';
183 my $cdrtypenum = $opt{'cdrtypenum'} || '';
185 # either of these, if the $opt isn't passed, will be set to the
186 # correct object when generating each row.
187 my $rate = qsearchs('rate', { 'ratenum' => $ratenum } ) if $ratenum;
188 my $region = qsearchs('rate_region', { 'regionnum' => $regionnum }) if $regionnum;
190 my @rate_time = qsearch('rate_time', {});
192 map( { $_->ratetimename } @rate_time ),
194 my @hlinks = map( {$p.'edit/rate_time.cgi?'.$_->ratetimenum} @rate_time ), '';
195 my @rtns = ( map( { $_->ratetimenum } @rate_time ), '' );
201 @rows = qsearch('rate_region',
202 { ratenum => $ratenum, regionnum => $regionnum });
206 if ( $opt{'countrycode'} ) {
207 $where = "WHERE 0 < (
208 SELECT COUNT(*) FROM rate_prefix
209 WHERE rate_prefix.regionnum = rate_region.regionnum
210 AND countrycode = '$opt{countrycode}'
213 @rows = qsearch({ table => 'rate_region',
217 #die "no region found" if !@rows;
219 unshift @header, 'Region', 'Prefix(es)';
220 unshift @hlinks, '', '';
222 foreach my $region (@rows) {
223 push @details, [ map { qsearchs('rate_detail',
224 { 'ratenum' => $ratenum,
225 'dest_regionnum' => $region->regionnum,
226 'cdrtypenum' => $cdrtypenum,
227 'ratetimenum' => $_ } ) or ''
232 elsif ( $regionnum ) {
233 @rows = qsearch('rate', {}) or die "no rate plans found";
234 unshift @header, 'Rate plan';
236 foreach my $rate (@rows) {
237 push @details, [ map { qsearchs('rate_detail',
238 { 'ratenum' => $rate->ratenum,
239 'dest_regionnum' => $regionnum,
240 'cdrtypenum' => $cdrtypenum,
241 'ratetimenum' => $_ } ) or ''
247 die "no ratenum or regionnum specified";