[freeside-commits] freeside/httemplate/browse rate_time.html, NONE, 1.1 rate.cgi, 1.8, 1.9 rate_detail.html, 1.6, 1.7
Mark Wells
mark at wavetail.420.am
Wed Jun 30 18:53:52 PDT 2010
Update of /home/cvs/cvsroot/freeside/httemplate/browse
In directory wavetail.420.am:/tmp/cvs-serv1454/httemplate/browse
Modified Files:
rate.cgi rate_detail.html
Added Files:
rate_time.html
Log Message:
voip_cdr call rating by day and time, RT#4763
--- NEW FILE: rate_time.html ---
<% 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>
Index: rate.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/browse/rate.cgi,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -d -r1.8 -r1.9
--- rate.cgi 7 Jan 2009 00:14:33 -0000 1.8
+++ rate.cgi 1 Jul 2010 01:53:50 -0000 1.9
@@ -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',
Index: rate_detail.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/browse/rate_detail.html,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -d -r1.6 -r1.7
--- rate_detail.html 21 Mar 2010 23:13:24 -0000 1.6
+++ rate_detail.html 1 Jul 2010 01:53:50 -0000 1.7
@@ -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', at 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 @@
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',
+ ) . '">'
+}
+
+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',
);
-};
-my $edit_hint = ' <FONT SIZE="-1">(edit)</FONT>';
+ $onclick = "if(confirm('Delete this rate?')) { $onclick }";
+ qq!<A HREF="javascript:void(0);" onclick="$onclick">!.small('(delete)').'</A>'
+}
-my $conn_charge_sub = sub {
+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;
- $money_char. $rate_detail->conn_charge.
- ($rate_detail->conn_sec ? ' for '.$conn_secs{$rate_detail->conn_sec} : '').
- $edit_hint;
-};
+ '<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 @@
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 $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 @@
$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>
More information about the freeside-commits
mailing list