X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Felements%2Frate_detail.html;h=73f65d5420c21225d679ee247bfbb174c6b0bddb;hb=833cfe5c9938d33c3e6b97ed610c25a7afa6eb04;hp=7b5ec314ad18c9c1930aa79870fa704c805d77e2;hpb=83e442de6a041fa3b7580d53912eeb1490ddf47c;p=freeside.git diff --git a/httemplate/edit/elements/rate_detail.html b/httemplate/edit/elements/rate_detail.html index 7b5ec314a..73f65d542 100644 --- a/httemplate/edit/elements/rate_detail.html +++ b/httemplate/edit/elements/rate_detail.html @@ -33,9 +33,9 @@ with row headers showing the region name and prefixes. % $col = 0; % if ( !$opt{'regionnum'} ) { % $region = $r; -% foreach ($r->regionname, $r->prefixes_short) { +% foreach ($r->regionname, $r->prefixes_short_sql) { - <% $_ %> + <% $_ |h %> % } % } @@ -61,18 +61,18 @@ with row headers showing the region name and prefixes. % $row++; % }# foreach @rate_region % if ( !$opt{regionnum} ) { -%# global default +% # global default for this cdrtypenum Global default (for calls not matching any prefix) -% # default rate: set a null region +% # default rate: set a null region for this cdr type <& .detail_box, - detail => $rate->default_detail, + detail => $rate->default_detail($cdrtypenum), ratetimenum => '', - cdrtypenum => '', + cdrtypenum => $cdrtypenum, regionnum => '', ratenum => $rate->ratenum &> @@ -252,29 +252,46 @@ my @rtns = ( map( { $_->ratetimenum } @rate_time ), '' ); 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, @@ -284,8 +301,9 @@ if ( $ratenum ) { } @rtns ]; } -} -elsif ( $regionnum ) { + +} elsif ( $regionnum ) { + @rows = qsearch('rate', {}) or die "no rate plans found"; unshift @header, 'Rate plan'; unshift @hlinks, ''; @@ -298,8 +316,8 @@ elsif ( $regionnum ) { } @rtns ]; } -} -else { + +} else { die "no ratenum or regionnum specified"; }