% $col = 0;
% if ( !$opt{'regionnum'} ) {
% $region = $r;
-% foreach ($r->regionname, $r->prefixes_short) {
+% foreach ($r->regionname, $r->prefixes_short_sql) {
<TD>
- <A HREF="<% $p.'edit/rate_region.cgi?regionnum='.$r->regionnum %>"><% $_ %></A>
+ <A HREF="<% $p.'edit/rate_region.cgi?regionnum='.$r->regionnum %>"><% $_ |h %></A>
</TD>
% }
% }
% }
% foreach my $rate_time (@rate_time, '') {
<TD>
-% my $detail = $details[$row][$col];
-% if($detail) {
+ <& .detail_box,
+ detail => $details[$row][$col],
+ ratetimenum => ($rate_time ? $rate_time->ratetimenum : ''),
+ cdrtypenum => $cdrtypenum,
+ regionnum => $region->regionnum,
+ ratenum => $rate->ratenum
+ &>
+% $col++;
+ </TD>
+% } # foreach @rate_time
+</TR>
+% $row++;
+% }# foreach @rate_region
+% if ( !$opt{regionnum} ) {
+% # global default for this cdrtypenum
+<TR>
+ <TD COLSPAN=2 STYLE="padding-top: 10px">
+ <B>Global default</B> (for calls not matching any prefix)
+ </TD>
+ <TD STYLE="padding-top: 10px">
+% # default rate: set a null region for this cdr type
+ <B>
+ <& .detail_box,
+ detail => $rate->default_detail($cdrtypenum),
+ ratetimenum => '',
+ cdrtypenum => $cdrtypenum,
+ regionnum => '',
+ ratenum => $rate->ratenum
+ &>
+ </B>
+ </TD>
+% }
+</TABLE>
+<%def .detail_box>
+<%args>
+$detail => undef,
+$ratetimenum
+$cdrtypenum
+$regionnum
+$ratenum
+</%args>
+% if ($detail) {
<TABLE CLASS="inv" STYLE="border:none">
- <TR><TD><% edit_link($detail) %><% $money_char.$detail->min_charge %>
+ <TR><TD><% edit_link($detail) %>
+% if ( $detail->min_charge > 0 or $detail->conn_charge > 0) {
+ <% $money_char.$detail->min_charge %>
<% $detail->sec_granularity ? ' / minute':' / call' %>
% if ( $detail->min_cost ) {
(<% $money_char.$detail->min_cost %> cost)
% }
+% if ( $detail->upstream_mult_charge > 0
+% or $detail->upstream_mult_cost > 0) {
+ <BR>+
+% }
+% }
+% if ( $detail->upstream_mult_charge > 0
+% or $detail->upstream_mult_cost > 0) {
+ <% $detail->upstream_mult_charge %> × upstream price
+% if ( $detail->upstream_mult_cost > 0 ) {
+ (<% $detail->upstream_mult_cost %> cost)
+% }
+% }
+% if ( $detail->upstream_mult_charge == 0
+% and $detail->min_charge == 0
+% and $detail->conn_charge == 0 ) {
+ Free
+% }
<% $edit_hint %></A>
</TD></TR>
<% granularity_detail($detail) %>
<% min_included_detail($detail) %>
<% conn_charge_detail($detail) %>
- <TR><TD><% ( $rate_time || $cdrtypenum ) ? delete_link($detail) : '' %>
+ <TR><TD><% ( $ratetimenum || $cdrtypenum ) ? delete_link($detail) : '' %>
</TD></TR>
</TABLE>
-% }
-% else { #!$detail
- <% add_link($rate, $region, $rate_time, $cdrtypenum) %>
-% }
-% $col++;
- </TD>
-% } # foreach @rate_time
-</TR>
-% $row++;
-% }# foreach @rate_region
-</TABLE>
-
+% } else {
+ <% add_link($ratenum, $regionnum, $ratetimenum, $cdrtypenum) %>
+% }
+</%def>
<%once>
tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
include( '/elements/popup_link_onclick.html',
'action' => "${p}edit/rate_detail.html?$ratedetailnum",
'actionlabel' => 'Edit rate',
- 'height' => 460,
+ 'height' => 550,
+ 'width' => 580,
#default# 'width' => 540,
#default# 'color' => '#333399',
) . '">'
}
sub add_link {
- my ($rate, $region, $rate_time, $cdrtypenum) = @_;
+ my ($ratenum, $regionnum, $ratetimenum, $cdrtypenum) = @_;
'<A HREF="javascript:void(0);" onclick="'.
include( '/elements/popup_link_onclick.html',
'action' => "${p}edit/rate_detail.html?ratenum=".
- $rate->ratenum.
+ $ratenum.
';dest_regionnum='.
- $region->regionnum.
+ $regionnum.
';ratetimenum='.
- ($rate_time ? $rate_time->ratetimenum : '').
+ ($ratetimenum || '').
";cdrtypenum=$cdrtypenum",
'actionlabel' => 'Add rate',
- 'height' => 460,
+ 'width' => 580,
+ 'height' => 550,
).'">'.small('(add)').'</A>'
}
sub granularity_detail {
my $rate_detail = shift;
- if($rate_detail->sec_granularity != 60 && $rate_detail->sec_granularity > 0) {
+ if(
+ $rate_detail->sec_granularity != 60
+ && $rate_detail->sec_granularity > 0
+ && $rate_detail->min_charge > 0) {
'<TR><TD>'.
small('in '.$granularity{$rate_detail->sec_granularity}.' increments').
'</TD></TR>';
my @details;
my @rows;
+
+my %rate_region = (
+ 'select' => 'rate_region.*, '.
+ "STRING_AGG(countrycode || ' ' || npa, ',') AS prefixes",
+ 'table' => 'rate_region',
+ 'addl_from' => 'LEFT JOIN rate_prefix USING ( regionnum ) ',
+ 'extra_sql' => 'GROUP BY ( rate_region.regionnum )',
+ 'order_by' => 'ORDER BY ( regionname )',
+);
+
if ( $ratenum ) {
+
if ( $regionnum ) {
- @rows = qsearch('rate_region',
- { ratenum => $ratenum, regionnum => $regionnum });
- }
- else {
- my $where = '';
+
+ @rows = qsearch({
+ %rate_region,
+ 'hashref' => { ratenum => $ratenum, regionnum => $regionnum },
+ });
+
+ } else {
+
if ( $opt{'countrycode'} ) {
- $where = "WHERE 0 < (
+ $rate_region{extra_sql} =
+ "WHERE 0 < (
SELECT COUNT(*) FROM rate_prefix
WHERE rate_prefix.regionnum = rate_region.regionnum
AND countrycode = '$opt{countrycode}'
- )";
+ ) ".
+ $rate_region{extra_sql};
}
- @rows = qsearch({ table => 'rate_region',
+ @rows = qsearch({ %rate_region,
hashref => {},
- extra_sql => $where,
- });
+ });
#die "no region found" if !@rows;
unshift @header, 'Region', 'Prefix(es)';
unshift @hlinks, '', '';
+
}
+
foreach my $region (@rows) {
push @details, [ map { qsearchs('rate_detail',
{ 'ratenum' => $ratenum,
} @rtns
];
}
-}
-elsif ( $regionnum ) {
+
+} elsif ( $regionnum ) {
+
@rows = qsearch('rate', {}) or die "no rate plans found";
unshift @header, 'Rate plan';
unshift @hlinks, '';
} @rtns
];
}
-}
-else {
+
+} else {
die "no ratenum or regionnum specified";
}