% $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>
% }
% }
% $row++;
% }# foreach @rate_region
% if ( !$opt{regionnum} ) {
-%# global default
+% # 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
+% # default rate: set a null region for this cdr type
<B>
<& .detail_box,
- detail => $rate->default_detail,
+ detail => $rate->default_detail($cdrtypenum),
ratetimenum => '',
- cdrtypenum => '',
+ cdrtypenum => $cdrtypenum,
regionnum => '',
ratenum => $rate->ratenum
&>
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";
}