From 8d284759daa2b231e79f57378e4a40f72e8b9bb0 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 22 Jul 2010 19:42:55 +0000 Subject: [PATCH] cdr rating by day and time, part 2, RT#4763 --- httemplate/edit/elements/rate_detail.html | 239 ++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 httemplate/edit/elements/rate_detail.html diff --git a/httemplate/edit/elements/rate_detail.html b/httemplate/edit/elements/rate_detail.html new file mode 100644 index 000000000..faf11f844 --- /dev/null +++ b/httemplate/edit/elements/rate_detail.html @@ -0,0 +1,239 @@ +<%doc> +<% include('/edit/elements/rate_detail.html', + # required + 'ratenum' => '1', + + # optional + 'regionnum' => '25', + # or + 'countrycode' => '237', +) %> + +If regionnum is specified, this produces column headers plus +one row of rate details for that region (in all time periods). +Otherwise, there's one row for each region in the specified +countrycode (or each region anywhere, if there is no countrycode), +with row headers showing the region name and prefixes. + + +<% include('/elements/table-grid.html') %> + +% my $col = 0; +% foreach (@header) { +% my $hlink = $hlinks[$col]; + + <% $hlink ? qq!$_! : $_ %> + +% $col++; +% } #foreach @header + +% my $row = 0; +% foreach my $r (@rows) { +% $col = 0; +% if ( !$opt{'regionnum'} ) { +% $region = $r; +% foreach ($r->regionname, $r->prefixes_short) { + + <% $_ %> + +% } +% } +% elsif ( !$opt{'ratenum'} ) { +% $rate = $r; + + <% $r->ratename %> + +% } +% foreach my $rate_time (@rate_time, '') { + +% my $detail = $details[$row][$col]; +% if($detail) { + + + <% granularity_detail($detail) %> + <% min_included_detail($detail) %> + <% conn_charge_detail($detail) %> + +
<% edit_link($detail) %><% $money_char.$detail->min_charge %> + <% $detail->sec_granularity ? ' / minute':' / call' %> + <% $edit_hint %> +
<% $rate_time ? delete_link($detail) : '' %>
+% } +% else { #!$detail + <% add_link($rate, $region, $rate_time) %> +% } +% $col++; + +% } # foreach @rate_time + +% $row++; +% }# foreach @rate_region + + +<%once> + +tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities(); +tie my %conn_secs, 'Tie::IxHash', FS::rate_detail::conn_secs(); + +my $conf = new FS::Conf; +my $money_char = $conf->config('money_char') || '$'; + +sub small { + ''.shift.'' +} +my $edit_hint = small('(edit)'); + +sub edit_link { + my $rate_detail = shift; + my $ratedetailnum = $rate_detail->ratedetailnum; + ' 'Edit rate', + 'height' => 420, + #default# 'width' => 540, + #default# 'color' => '#333399', + ) . '">' +} + +sub add_link { + my ($rate, $region, $rate_time) = @_; + ''.small('(add)').'' +} + +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!!.small('(delete)').'' +} + +sub granularity_detail { + my $rate_detail = shift; + if($rate_detail->sec_granularity != 60 && $rate_detail->sec_granularity > 0) { + ''. + small('in '.$granularity{$rate_detail->sec_granularity}.' increments'). + ''; + } + else { '' } +} + +sub min_included_detail { + my $rate_detail = shift; + if($rate_detail->min_included) { + ''. + small( $rate_detail->min_included . + ($rate_detail->sec_granularity ? + ' minutes included' : + ' calls included') ). + '' + } + 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; + ''. + small( $money_char. $rate_detail->conn_charge. + ' for '.$conn_secs{$rate_detail->conn_sec} + ). + '' + } + else { '' } +} + + +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my %opt = @_; +my $ratenum = $opt{'ratenum'} || ''; +my $regionnum = $opt{'regionnum'} || ''; + +# either of these, if the $opt isn't passed, will be set to the +# correct object when generating each row. +my $rate = qsearchs('rate', { 'ratenum' => $ratenum } ) if $ratenum; +my $region = qsearchs('rate_region', { 'regionnum' => $regionnum }) if $regionnum; + +my @rate_time = qsearch('rate_time', {}); +my @header = ( + map( { $_->ratetimename } @rate_time ), + 'Default rate'); +my @hlinks = map( {$p.'edit/rate_time.cgi?'.$_->ratetimenum} @rate_time ), ''; +my @rtns = ( map( { $_->ratetimenum } @rate_time ), '' ); + +my @details; +my @rows; +if ( $ratenum ) { + if ( $regionnum ) { + @rows = qsearch('rate_region', + { ratenum => $ratenum, regionnum => $regionnum }); + } + else { + my $where = ''; + if ( $opt{'countrycode'} ) { + $where = "WHERE 0 < ( + SELECT COUNT(*) FROM rate_prefix + WHERE rate_prefix.regionnum = rate_region.regionnum + AND countrycode = '$opt{countrycode}' + )"; + } + @rows = qsearch({ table => '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, + 'dest_regionnum' => $region->regionnum, + 'ratetimenum' => $_ } ) or '' + } @rtns + ]; + } +} +elsif ( $regionnum ) { + @rows = qsearch('rate', {}) or die "no rate plans found"; + unshift @header, 'Rate plan'; + unshift @hlinks, ''; + foreach my $rate (@rows) { + push @details, [ map { qsearchs('rate_detail', + { 'ratenum' => $rate->ratenum, + 'dest_regionnum' => $regionnum, + 'ratetimenum' => $_ } ) or '' + } @rtns + ]; + } +} +else { + die "no ratenum or regionnum specified"; +} + + -- 2.11.0