X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Frate.cgi;h=55fe319cfb577672b63e3561a7a77bfcd9d97c79;hb=b91bcdff200acb281c58c4ba5ef8482b335ecdbc;hp=4a4b70ea32a3f521f6a5b2382145c973b9d7c558;hpb=2f41d7382dac4f151de86ce06ad9846c89f56791;p=freeside.git diff --git a/httemplate/edit/rate.cgi b/httemplate/edit/rate.cgi index 4a4b70ea3..55fe319cf 100644 --- a/httemplate/edit/rate.cgi +++ b/httemplate/edit/rate.cgi @@ -1,95 +1,55 @@ -<% - -my($rate, $error); - -if ( $cgi->param('magic') eq 'process' ) { - - my $ratenum = $cgi->param('ratenum'); - - my $old = qsearchs('rate', { 'ratenum' => $ratenum } ) if $ratenum; - - my @rate_detail = map { - my $regionnum = $_->regionnum; - if ( $cgi->param("sec_granularity$regionnum") ) { - new FS::rate_detail { - 'dest_regionnum' => $regionnum, - map { $_ => scalar($cgi->param("$_$regionnum")) } - qw( min_included min_charge sec_granularity ) - }; - } else { - new FS::rate_detail { - 'dest_regionnum' => $regionnum, - 'min_included' => 0, - 'min_charge' => 0, - 'sec_granularity' => '60' - }; - } - } qsearch('rate_region', {} ); - - $rate = new FS::rate ( { - map { - $_, scalar($cgi->param($_)); - } fields('rate') - } ); - - if ( $ratenum ) { - warn "$rate replacing $old ($ratenum)\n"; - $error = $rate->replace($old, 'rate_detail' => \@rate_detail ); - } else { - warn "inserting $rate\n"; - $error = $rate->insert( 'rate_detail' => \@rate_detail ); - $ratenum = $rate->getfield('ratenum'); - } - - unless ( $error ) { - print $cgi->redirect("${p}browse/rate.cgi"); - myexit; - } - -} elsif ( $cgi->keywords ) { - my($query) = $cgi->keywords; - $query =~ /^(\d+)$/; - $rate = qsearchs( 'rate', { 'ratenum' => $1 } ); -} else { #adding - $rate = new FS::rate {}; -} -my $action = $rate->ratenum ? 'Edit' : 'Add'; - -my $p1 = popurl(1); - -my %granularity = ( - '6' => '6 second', - '60' => 'minute', -); - -my $nous = < - -<%= header("$action Rate plan", menubar( +% +% +%my $rate; +%if ( $cgi->keywords ) { +% my($query) = $cgi->keywords; +% $query =~ /^(\d+)$/; +% $rate = qsearchs( 'rate', { 'ratenum' => $1 } ); +%} else { #adding +% $rate = new FS::rate {}; +%} +%my $action = $rate->ratenum ? 'Edit' : 'Add'; +% +%my $p1 = popurl(1); +% +%my %granularity = ( +% '1', => '1 second', +% '6' => '6 second', +% '30' => '30 second', # '1/2 minute', +% '60' => 'minute', +%); +% +%#my $nous = < $p, 'View all rate plans' => "${p}browse/rate.cgi", )) %> -<% if ( $error ) { %> -Error: <%= $error %>
-<% } %> - -
- - +<% include('/elements/progress-init.html', + 'OneTrueForm', + [ 'rate', 'min_', 'sec_' ], + 'process/rate.cgi', + $p.'browse/rate.cgi', + ) +%> + + Rate plan - +

-<%= table() %> +<% table() %> Region Prefix(es) @@ -97,49 +57,62 @@ Rate plan Charge per
minute
Granularity +% foreach my $rate_region ( +% #sort { lc($a->regionname) cmp lc($b->regionname) } +% qsearch({ +% 'table' => 'rate_region', +% 'hashref' => {}, +% 'order_by' => 'ORDER BY lc(regionname)', +% +% #'select' => 'DISTINCT ON ( regionnum ) rate_region.*', +% #... +% #'addl_from' => 'INNER JOIN rate_prefix USING ( regionnum )', +% #'extra_sql' => "WHERE countrycode != '1'", +% +% # 'ORDER BY regionname' +% # ERROR: SELECT DISTINCT ON expressions must +% # match initial ORDER BY expressions +% # also, DISTINCT ON is a Pg-ism +% }) +% ) { +% my $n = $rate_region->regionnum; +% my $rate_detail = +% $rate->dest_detail($rate_region) +% || new FS::rate_detail { 'min_included' => 0, +% 'min_charge' => 0, +% 'sec_granularity' => '60' +% }; +% + -<% foreach my $rate_region ( - qsearch( 'rate_region', - {}, - '', - "$nous ORDER BY regionname", - ) - ) { - my $n = $rate_region->regionnum; - my $rate_detail = - $rate->dest_detail($rate_region) - || new FS::rate_detail { 'min_included' => 0, - 'min_charge' => 0, - 'sec_granularity' => '60' - }; -%> - <%= $rate_region->regionname %> - <%= $rate_region->prefixes_short %> - min_included %>"> - $min_charge ) %>"> + <% $rate_region->regionname %> + <% $rate_region->prefixes_short %> + min_included %>"> + $min_charge ) %>"> - +% foreach my $granularity ( keys %granularity ) { + +