diff options
author | mark <mark> | 2010-07-01 01:53:50 +0000 |
---|---|---|
committer | mark <mark> | 2010-07-01 01:53:50 +0000 |
commit | de3bf373e97f6875e09fc17d99068a2716bf3b2d (patch) | |
tree | bf5d4908cb57519a99cb8db0266f40d671f9e170 /httemplate/browse | |
parent | 6643a544400f5bed64b75720fdaccb41f01d1e79 (diff) |
voip_cdr call rating by day and time, RT#4763
Diffstat (limited to 'httemplate/browse')
-rw-r--r-- | httemplate/browse/rate.cgi | 2 | ||||
-rw-r--r-- | httemplate/browse/rate_detail.html | 205 | ||||
-rw-r--r-- | httemplate/browse/rate_time.html | 48 |
3 files changed, 198 insertions, 57 deletions
diff --git a/httemplate/browse/rate.cgi b/httemplate/browse/rate.cgi index 02d670fbd..428158a6d 100644 --- a/httemplate/browse/rate.cgi +++ b/httemplate/browse/rate.cgi @@ -2,6 +2,8 @@ 'title' => 'Rate plans', 'menubar' => [ 'Regions and Prefixes' => $p.'browse/rate_region.html', + 'Time Periods' => + $p.'browse/rate_time.html', ], 'html_init' => $html_init, 'name' => 'rate plans', diff --git a/httemplate/browse/rate_detail.html b/httemplate/browse/rate_detail.html index 3371926b4..faaec2c38 100644 --- a/httemplate/browse/rate_detail.html +++ b/httemplate/browse/rate_detail.html @@ -1,39 +1,53 @@ -<% include( 'elements/browse.html', - 'title' => $title, - 'name_singular' => 'rate', - 'html_init' => $html_init, - 'menubar' => [ 'Rate plans' => $p.'browse/rate.cgi' ], - 'query' => { - 'table' => 'rate_detail', - 'addl_from' => $join, - 'hashref' => { 'ratenum' => $ratenum }, - 'extra_sql' => $where, - }, - 'count_query' => "SELECT COUNT(*) FROM rate_detail $join". - " WHERE ratenum = $ratenum $where", - 'header' => [ - 'Region', - 'Prefix(es)', - 'Included<BR>minutes', - 'Connection<BR>charge', - 'Charge per<BR>minute', - 'Granularity', - 'Usage class', - ], - 'fields' => [ - 'regionname', - sub { shift->dest_region->prefixes_short }, - sub { shift->min_included. $edit_hint }, - $conn_charge_sub, - sub { $money_char. shift->min_charge. $edit_hint }, - sub { $granularity{ shift->sec_granularity } }, - 'classname', - ], - 'links' => [ '', '', $edit_link, $edit_link, '', '' ], - 'link_onclicks' => [ '', '', $edit_onclick, $edit_onclick, '', '' ], - 'align' => 'llrrcc', - ) -%> +<% include('/elements/init_overlib.html') %> +<% include('/elements/header.html',$title) %> +<% include('/elements/menubar.html',@menubar) %> +<BR><BR> +<% include('/elements/table-grid.html') %> +<TR> +% my $col = 0; +% foreach (@header) { +% my $hlink = $hlinks[$col]; + <TH CLASS = "grid", + BGCOLOR = "#cccccc"> + <% $hlink ? qq!<A HREF="$hlink">$_</A>! : $_ %> + </TH> +% $col++; +% } #foreach @header +</TR><TR> +% my $row = 0; +% foreach my $region (@rate_region) { +% $col = 0; +% foreach ($region->regionname, $region->prefixes_short) { + <TD> + <A HREF="<% $p.'edit/rate_region.cgi?'.$region->regionnum %>"><% $_ %></A> + </TD> +% } +% foreach my $rate_time (@rate_time, '') { + <TD> +% my $detail = $details[$row][$col]; +% if($detail) { + <TABLE CLASS="inv" STYLE="border:none"> + <TR><TD><% edit_link($detail) %><% $money_char.$detail->min_charge %> + <% $detail->sec_granularity ? ' / minute':' / call' %> + <% $edit_hint %></A> + </TD></TR> + <% granularity_detail($detail) %> + <% min_included_detail($detail) %> + <% conn_charge_detail($detail) %> + <TR><TD><% $rate_time ? delete_link($detail) : '' %></TD></TR> + </TABLE> +% } +% else { #!$detail + <% add_link($ratenum, $region, $rate_time) %> +% } +% $col++; + </TD> +% } # foreach @rate_time +</TR> +% $row++; +% }# foreach @rate_region +<% include('/elements/footer.html') %> + <%once> tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities(); @@ -42,31 +56,92 @@ tie my %conn_secs, 'Tie::IxHash', FS::rate_detail::conn_secs(); my $conf = new FS::Conf; my $money_char = $conf->config('money_char') || '$'; -my $join = - ' JOIN rate_region ON ( rate_detail.dest_regionnum = rate_region.regionnum )'; +my @menubar = ( 'Rate plans' => $p.'browse/rate.cgi', + 'Regions and Prefixes' => $p.'browse/rate_region.html', + 'Time Periods' => $p.'browse/rate_time.html', + ); -my $edit_link = [ 'javascript:void(0);', sub { ''; } ]; +sub small { + '<FONT SIZE="-1">'.shift.'</FONT>' +} +my $edit_hint = small('(edit)'); -my $edit_onclick = sub { +sub edit_link { my $rate_detail = shift; my $ratedetailnum = $rate_detail->ratedetailnum; + '<A HREF="javascript:void(0);" onclick="'. include( '/elements/popup_link_onclick.html', 'action' => "${p}edit/rate_detail.html?$ratedetailnum", 'actionlabel' => 'Edit rate', 'height' => 420, #default# 'width' => 540, #default# 'color' => '#333399', - ); -}; -my $edit_hint = ' <FONT SIZE="-1">(edit)</FONT>'; - -my $conn_charge_sub = sub { - my $rate_detail = shift; - #return '' unless $rate_detail->conn_charge > 0 || $rate_detail->conn_sec; - $money_char. $rate_detail->conn_charge. - ($rate_detail->conn_sec ? ' for '.$conn_secs{$rate_detail->conn_sec} : ''). - $edit_hint; -}; + ) . '">' +} + +sub add_link { + my ($ratenum, $region, $rate_time) = @_; + '<A HREF="javascript:void(0);" onclick="'. + include( '/elements/popup_link_onclick.html', + 'action' => "${p}edit/rate_detail.html?ratenum=$ratenum". + ';dest_regionnum='.$region->regionnum. + ($rate_time ? + ';ratetimenum='.$rate_time->ratetimenum : + ''), + 'actionlabel' => 'Add rate', + 'height' => 420, + ).'">'.small('(add)').'</A>' +} + +sub delete_link { + my $rate_detail = shift; + my $ratedetailnum = $rate_detail->ratedetailnum; + my $onclick = include( '/elements/popup_link_onclick.html', + 'action' => "${p}misc/delete-rate_detail.html?$ratedetailnum", + 'actionlabel' => 'Delete rate', + 'width' => 510, + 'height' => 315, + 'frame' => 'top', + ); + $onclick = "if(confirm('Delete this rate?')) { $onclick }"; + qq!<A HREF="javascript:void(0);" onclick="$onclick">!.small('(delete)').'</A>' +} + +sub granularity_detail { + my $rate_detail = shift; + if($rate_detail->sec_granularity != 60 && $rate_detail->sec_granularity > 0) { + '<TR><TD>'. + small('in '.$granularity{$rate_detail->sec_granularity}.' increments'). + '</TD></TR>'; + } + else { '' } +} + +sub min_included_detail { + my $rate_detail = shift; + if($rate_detail->min_included) { + '<TR><TD>'. + small( $rate_detail->min_included . + ($rate_detail->sec_granularity ? + ' minutes included' : + ' calls included') ). + '</TD></TR>' + } + else { '' } +} + +sub conn_charge_detail { + my $rate_detail = shift; + if($rate_detail->conn_charge > 0) { + #return '' unless $rate_detail->conn_charge > 0 || $rate_detail->conn_sec; + '<TR><TD>'. + small( $money_char. $rate_detail->conn_charge. + ' for '.$conn_secs{$rate_detail->conn_sec} + ). + '</TD></TR>' + } + else { '' } +} </%once> <%init> @@ -74,8 +149,6 @@ my $conn_charge_sub = sub { die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); -my $html_init = include('/elements/init_overlib.html'); - $cgi->param('ratenum') =~ /^(\d+)$/ or die "unparsable ratenum"; my $ratenum = $1; my $rate = qsearchs('rate', { 'ratenum' => $ratenum } ) @@ -83,11 +156,10 @@ my $rate = qsearchs('rate', { 'ratenum' => $ratenum } ) my $ratename = $rate->ratename; my $title = "$ratename rates"; -my @where = (); - +my $where; if ( $cgi->param('countrycode') =~ /^(\d+)$/ ) { my $countrycode = $1; - push @where, "0 < ( SELECT COUNT(*) FROM rate_prefix + $where = "WHERE 0 < ( SELECT COUNT(*) FROM rate_prefix WHERE rate_prefix.regionnum = rate_region.regionnum AND countrycode = '$countrycode' ) @@ -95,6 +167,25 @@ if ( $cgi->param('countrycode') =~ /^(\d+)$/ ) { $title .= " for +$countrycode"; } -my $where = scalar(@where) ? ' AND '.join(' AND ', @where ) : ''; +my @rate_region = qsearch({ table => 'rate_region', + hashref => {}, + extra_sql => $where, + }); + +my @rate_time = qsearch('rate_time', {}); +my @header = ('Region', 'Prefix(es)', + map( { $_->ratetimename } @rate_time ), + '(default)'); +my @hlinks = map {''} @header; + +my @rtns = ( map( { $_->ratetimenum } @rate_time ), '' ); +my @details; +foreach my $region (@rate_region) { + push @details, [ map { qsearchs('rate_detail', + { 'ratenum' => $ratenum, + 'dest_regionnum' => $region->regionnum, + 'ratetimenum' => $_ } ) or '' + } @rtns ]; +} </%init> diff --git a/httemplate/browse/rate_time.html b/httemplate/browse/rate_time.html new file mode 100644 index 000000000..416ded41f --- /dev/null +++ b/httemplate/browse/rate_time.html @@ -0,0 +1,48 @@ +<% include( 'elements/browse.html', + 'title' => 'Rating Time Periods', + 'name_singular' => 'period', + 'menubar' => [ 'Rate plans' => $p.'browse/rate.cgi' ], + 'html_init' => $html_init, + 'query' => { + 'table' => 'rate_time', + 'order_by' => 'ratetimenum', # lacking anything else + 'hashref' => {}, + }, + 'count_query' => 'SELECT COUNT(*) FROM rate_time', + 'header' => \@header, + 'fields' => \@fields, + 'links' => \@links, + 'align' => \@align, + ) +%> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $edit_url = $p.'edit/rate_time.cgi'; + +my $link = [ "$edit_url?", 'ratetimenum' ]; + +my $html_init = + 'Time periods for VoIP and call billing.<BR><BR>'. + qq(<A HREF="$edit_url"><I>Add a new period</I></A><BR><BR>); + +sub interval { + my $i = shift; + '<TABLE>' + .join('', map { '<TR><TD>'.($_->description)[$i].'</TR></TD>' } + shift->intervals + ) . '</TABLE>'; +} + +# inefficient but readable +my $stime_sub = sub { interval(0,shift) }; +my $etime_sub = sub { interval(1,shift) }; + +my @header = ( '#', 'Period', 'Start', 'End' ); +my @fields = ( 'ratetimenum', 'ratetimename', $stime_sub, $etime_sub ); +my @links = ( ($link) x 2 ); +my @align = ( 'right', 'left', 'left' ); + +</%init> |