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' %>
57 <% granularity_detail($detail) %>
58 <% min_included_detail($detail) %>
59 <% conn_charge_detail($detail) %>
60 <TR><TD><% ( $rate_time || $cdrtypenum ) ? delete_link($detail) : '' %>
65 <% add_link($rate, $region, $rate_time, $cdrtypenum) %>
69 % } # foreach @rate_time
72 % }# foreach @rate_region
77 tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
78 tie my %conn_secs, 'Tie::IxHash', FS::rate_detail::conn_secs();
80 my $conf = new FS::Conf;
81 my $money_char = $conf->config('money_char') || '$';
84 '<FONT SIZE="-1">'.shift.'</FONT>'
86 my $edit_hint = small('(edit)');
89 my $rate_detail = shift;
90 my $ratedetailnum = $rate_detail->ratedetailnum;
91 '<A HREF="javascript:void(0);" onclick="'.
92 include( '/elements/popup_link_onclick.html',
93 'action' => "${p}edit/rate_detail.html?$ratedetailnum",
94 'actionlabel' => 'Edit rate',
96 #default# 'width' => 540,
97 #default# 'color' => '#333399',
102 my ($rate, $region, $rate_time, $cdrtypenum) = @_;
103 '<A HREF="javascript:void(0);" onclick="'.
104 include( '/elements/popup_link_onclick.html',
105 'action' => "${p}edit/rate_detail.html?ratenum=".
110 ($rate_time ? $rate_time->ratetimenum : '').
111 ";cdrtypenum=$cdrtypenum",
112 'actionlabel' => 'Add rate',
114 ).'">'.small('(add)').'</A>'
118 my $rate_detail = shift;
119 my $ratedetailnum = $rate_detail->ratedetailnum;
120 my $onclick = include( '/elements/popup_link_onclick.html',
121 'action' => "${p}misc/delete-rate_detail.html?$ratedetailnum",
122 'actionlabel' => 'Delete rate',
127 $onclick = "if(confirm('Delete this rate?')) { $onclick }";
128 qq!<A HREF="javascript:void(0);" onclick="$onclick">!.small('(delete)').'</A>'
131 sub granularity_detail {
132 my $rate_detail = shift;
133 if($rate_detail->sec_granularity != 60 && $rate_detail->sec_granularity > 0) {
135 small('in '.$granularity{$rate_detail->sec_granularity}.' increments').
141 sub min_included_detail {
142 my $rate_detail = shift;
143 if($rate_detail->min_included) {
145 small( $rate_detail->min_included .
146 ($rate_detail->sec_granularity ?
147 ' minutes included' :
148 ' calls included') ).
154 sub conn_charge_detail {
155 my $rate_detail = shift;
156 if($rate_detail->conn_charge > 0) {
157 #return '' unless $rate_detail->conn_charge > 0 || $rate_detail->conn_sec;
159 small( $money_char. $rate_detail->conn_charge.
160 ' for '.$conn_secs{$rate_detail->conn_sec}
171 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
174 my $ratenum = $opt{'ratenum'} || '';
175 my $regionnum = $opt{'regionnum'} || '';
176 my $cdrtypenum = $opt{'cdrtypenum'} || '';
178 # either of these, if the $opt isn't passed, will be set to the
179 # correct object when generating each row.
180 my $rate = qsearchs('rate', { 'ratenum' => $ratenum } ) if $ratenum;
181 my $region = qsearchs('rate_region', { 'regionnum' => $regionnum }) if $regionnum;
183 my @rate_time = qsearch('rate_time', {});
185 map( { $_->ratetimename } @rate_time ),
187 my @hlinks = map( {$p.'edit/rate_time.cgi?'.$_->ratetimenum} @rate_time ), '';
188 my @rtns = ( map( { $_->ratetimenum } @rate_time ), '' );
194 @rows = qsearch('rate_region',
195 { ratenum => $ratenum, regionnum => $regionnum });
199 if ( $opt{'countrycode'} ) {
200 $where = "WHERE 0 < (
201 SELECT COUNT(*) FROM rate_prefix
202 WHERE rate_prefix.regionnum = rate_region.regionnum
203 AND countrycode = '$opt{countrycode}'
206 @rows = qsearch({ table => 'rate_region',
210 die "no region found" if !@rows;
212 unshift @header, 'Region', 'Prefix(es)';
213 unshift @hlinks, '', '';
215 foreach my $region (@rows) {
216 push @details, [ map { qsearchs('rate_detail',
217 { 'ratenum' => $ratenum,
218 'dest_regionnum' => $region->regionnum,
219 'cdrtypenum' => $cdrtypenum,
220 'ratetimenum' => $_ } ) or ''
225 elsif ( $regionnum ) {
226 @rows = qsearch('rate', {}) or die "no rate plans found";
227 unshift @header, 'Rate plan';
229 foreach my $rate (@rows) {
230 push @details, [ map { qsearchs('rate_detail',
231 { 'ratenum' => $rate->ratenum,
232 'dest_regionnum' => $regionnum,
233 'cdrtypenum' => $cdrtypenum,
234 'ratetimenum' => $_ } ) or ''
240 die "no ratenum or regionnum specified";