diff options
author | mark <mark> | 2010-07-22 00:11:56 +0000 |
---|---|---|
committer | mark <mark> | 2010-07-22 00:11:56 +0000 |
commit | 342e2bfbe6aad470ab9dee40640f8ac7d9653003 (patch) | |
tree | bf350b2d3876651ee0c4487b0e321ec21f839f0c /httemplate/edit | |
parent | c26fea8a168f255412a8065c0a04758c9b0d340d (diff) |
cdr rating by day and time, part 2, RT#4763
Diffstat (limited to 'httemplate/edit')
-rwxr-xr-x | httemplate/edit/process/rate_region.cgi | 21 | ||||
-rw-r--r-- | httemplate/edit/process/rate_time.cgi | 42 | ||||
-rw-r--r-- | httemplate/edit/rate.cgi | 8 | ||||
-rw-r--r-- | httemplate/edit/rate_region.cgi | 114 | ||||
-rw-r--r-- | httemplate/edit/rate_time.cgi | 49 |
5 files changed, 81 insertions, 153 deletions
diff --git a/httemplate/edit/process/rate_region.cgi b/httemplate/edit/process/rate_region.cgi index 8036f7388..d342e605a 100755 --- a/httemplate/edit/process/rate_region.cgi +++ b/httemplate/edit/process/rate_region.cgi @@ -1,6 +1,8 @@ %if ( $error ) { % $cgi->param('error', $error); <% $cgi->redirect(popurl(2). "rate_region.cgi?". $cgi->query_string ) %> +%} elsif ( $action eq 'Add' ) { +<% $cgi->redirect(popurl(2). "rate_region.cgi?$regionnum") %> %} else { <% $cgi->redirect(popurl(3). "browse/rate_region.html") %> %} @@ -11,6 +13,7 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); my $regionnum = $cgi->param('regionnum'); +my $action = $regionnum ? 'Edit' : 'Add'; my $old = qsearchs('rate_region', { 'regionnum' => $regionnum } ) if $regionnum; @@ -33,24 +36,12 @@ my @rate_prefix = map { 'npa' => $_, } } @npa; - -my @dest_detail = map { - my $ratenum = $_->ratenum; - new FS::rate_detail { - 'ratenum' => $ratenum, - map { $_ => $cgi->param("$_$ratenum") } - qw( min_included conn_charge conn_sec min_charge sec_granularity classnum ) - }; -} qsearch('rate', {} ); - - +# we no longer process dest_detail records here my $error; if ( $regionnum ) { - $error = $new->replace($old, 'rate_prefix' => \@rate_prefix, - 'dest_detail' => \@dest_detail, ); + $error = $new->replace($old, 'rate_prefix' => \@rate_prefix ); } else { - $error = $new->insert( 'rate_prefix' => \@rate_prefix, - 'dest_detail' => \@dest_detail, ); + $error = $new->insert( 'rate_prefix' => \@rate_prefix ); $regionnum = $new->getfield('regionnum'); } diff --git a/httemplate/edit/process/rate_time.cgi b/httemplate/edit/process/rate_time.cgi index 48ed2739e..4fa78ce6d 100644 --- a/httemplate/edit/process/rate_time.cgi +++ b/httemplate/edit/process/rate_time.cgi @@ -44,12 +44,13 @@ else { #!$ratetimenum, adding new $ratetimenum = $rate_time->ratetimenum; } +my @new_ints; if(!$delete and !$error) { - foreach my $i (map { /stime(\d+)/ } keys(%vars)) { - my $stime = str2wtime($vars{"stime$i"}); - my $etime = str2wtime($vars{"etime$i"}); - next if !defined($stime) or !defined($etime); - #warn "$i: $stime-$etime"; + foreach my $i (map { /^sd(\d+)$/ } keys(%vars)) { + my $stime = l2wtime(@vars{"sd$i", "sh$i", "sm$i", "sa$i"}); + my $etime = l2wtime(@vars{"ed$i", "eh$i", "em$i", "ea$i"}); + #warn "$i: $stime - $etime"; + next if !defined($stime) or !defined($etime) or $etime == $stime; # try to avoid needlessly wiping and replacing intervals every # time this is edited. if( %old_ints ) { @@ -63,12 +64,9 @@ if(!$delete and !$error) { next; #$i } } - my $new_int = FS::rate_time_interval->new({ ratetimenum => $ratetimenum, - stime => $stime, - etime => $etime, } ); - $error = $new_int->insert; - #warn "inserting $stime-$etime\n"; - last if $error; + push @new_ints, FS::rate_time_interval->new({ ratetimenum => $ratetimenum, + stime => $stime, + etime => $etime, } ); } } if(!$error) { @@ -78,17 +76,19 @@ if(!$error) { last if $error; } } +if(!$error) { + # do this last to avoid overlap errors with deleted intervals + foreach (@new_ints) { + $error = $_->insert; + #warn "inserting $stime-$etime\n"; + last if $error; + } +} -sub str2wtime { - my %days; - @days{qw(Sun Mon Tue Wed Thu Fri Sat)} = (0..6); - my $str = shift; - my ($d, $h, $m, $s, $ampm) = - ($str =~ /^(\w{3}) (\d{2}):(\d{2}):(\d{2}) (\w{2})$/); - return () if !$d; - $h += 24*$days{$d} + ($ampm eq 'PM' ? 12 : 0); +sub l2wtime { + my ($d, $h, $m, $a) = @_; + $h += 24*$d + 12*$a; $m += 60*$h; - $s += 60*$m; - return $s; + return 60*$m } </%init> diff --git a/httemplate/edit/rate.cgi b/httemplate/edit/rate.cgi index 75c714322..13717dc1a 100644 --- a/httemplate/edit/rate.cgi +++ b/httemplate/edit/rate.cgi @@ -22,9 +22,15 @@ Rate plan <INPUT NAME="submit" TYPE="button" VALUE="<% $rate->ratenum ? "Apply changes" : "Add rate plan" %>" onClick="document.OneTrueForm.submit.disabled=true; process();"> - </FORM> +% if($rate->ratenum) { +<BR><BR><FONT SIZE="+2">Rates in this plan</FONT> +<% include('/edit/elements/rate_detail.html', + 'ratenum' => $rate->ratenum +) %> +% } + <% include('/elements/footer.html') %> <%init> diff --git a/httemplate/edit/rate_region.cgi b/httemplate/edit/rate_region.cgi index f77c0dbe7..cae30030a 100644 --- a/httemplate/edit/rate_region.cgi +++ b/httemplate/edit/rate_region.cgi @@ -35,113 +35,19 @@ </TABLE> -%# rate plan info - -<BR> - -<% include('/elements/table-grid.html') %> -% my $bgcolor1 = '#eeeeee'; -% my $bgcolor2 = '#ffffff'; -% my $bgcolor = ''; - - <TR> - <TH CLASS="grid" BGCOLOR="#cccccc"> - Rate plan - </TH> - <TH CLASS="grid" BGCOLOR="#cccccc"> - <FONT SIZE=-1>Included<BR>minutes/calls</FONT> - </TH> - <TH CLASS="grid" BGCOLOR="#cccccc"> - <FONT SIZE=-1>Connection<BR>charge</FONT> - </TH> - <TH CLASS="grid" BGCOLOR="#cccccc"> - <FONT SIZE=-1>Connection<BR>charge for</FONT> - </TH> - <TH CLASS="grid" BGCOLOR="#cccccc"> - <FONT SIZE=-1>Charge per<BR>minute/call</FONT> - </TH> - <TH CLASS="grid" BGCOLOR="#cccccc"> - <FONT SIZE=-1>Granularity</FONT> - </TH> - <TH CLASS="grid" BGCOLOR="#cccccc"> - <FONT SIZE=-1>Usage class</FONT> - </TH> - </TR> - -% foreach my $rate ( qsearch('rate', {}) ) { -% -% my $n = $rate->ratenum; -% my $rate_detail = $rate->dest_detail($rate_region) -% || new FS::rate_region { 'min_included' => 0, -% 'min_charge' => 0, -% 'sec_granularity' => '60' -% }; -% -% if ( $bgcolor eq $bgcolor1 ) { -% $bgcolor = $bgcolor2; -% } else { -% $bgcolor = $bgcolor1; -% } - - <TR> - - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"> - <A HREF="<%$p%>edit/rate.cgi?<% $rate->ratenum %>"><% $rate->ratename %></A> - </TD> - - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"> - <INPUT TYPE="text" SIZE=9 NAME="min_included<%$n%>" VALUE="<% $cgi->param("min_included$n") || $rate_detail->min_included |h %>"> - </TD> - - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"> - <%$money_char%><INPUT TYPE="text" SIZE=9 NAME="conn_charge<%$n%>" VALUE="<% $cgi->param("conn_charge$n") || $rate_detail->conn_charge |h %>"> - </TD> - - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"> - <SELECT NAME="conn_sec<%$n%>"> -% foreach my $conn_sec ( keys %conn_secs ) { -% my $curr_value = $cgi->param("conn_sec$n") || $rate_detail->conn_sec; -% my $selected = ($conn_sec==$curr_value) ? ' SELECTED' : ''; - <OPTION VALUE="<% $conn_sec %>" <%$selected%>><% $conn_secs{$conn_sec} %></OPTION> -% } - </TD> - - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"> - <%$money_char%><INPUT TYPE="text" SIZE=6 NAME="min_charge<%$n%>" VALUE="<% $cgi->param("min_charge$n") || $rate_detail->min_charge |h %>"> - </TD> - - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"> - <SELECT NAME="sec_granularity<%$n%>"> -% foreach my $granularity ( keys %granularity ) { - <OPTION VALUE="<%$granularity%>"<% $granularity == ( $cgi->param("sec_granularity$n") || $rate_detail->sec_granularity ) ? ' SELECTED' : '' %>><%$granularity{$granularity}%> -% } - </SELECT> - </TD> - - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"> - <% include( '/elements/select-table.html', - 'element_name' => "classnum$n", - 'table' => 'usage_class', - 'name_col' => 'classname', - 'empty_label' => '(default)', - 'hashref' => { disabled => '' }, - 'curr_value' => ( $cgi->param("classnum$n") || - $rate_detail->classnum ), - ) - %> - </TD> - - </TR> - -% } - -</TABLE> - - <BR><BR> <INPUT TYPE="submit" VALUE="<% $rate_region->regionnum ? "Apply changes" : "Add region" %>"> - </FORM> +%# rate plan info, if the region has been created yet + +% if($rate_region->regionnum) { +<BR> +<BR> +<FONT SIZE="+2">Rates in this region</FONT> +<% include('/edit/elements/rate_detail.html', + 'regionnum' => $rate_region->regionnum, +) %> +% } <% include('/elements/footer.html') %> <%once> diff --git a/httemplate/edit/rate_time.cgi b/httemplate/edit/rate_time.cgi index 230aef82d..eca8fbb61 100644 --- a/httemplate/edit/rate_time.cgi +++ b/httemplate/edit/rate_time.cgi @@ -1,9 +1,10 @@ -<% include("/elements/header.html","$action Time Period", menubar( +<% include("/elements/header.html", { title => "$action Time Period" }) %> +<% include("/elements/menubar.html", 'Rate plans' => "${p}browse/rate.cgi", - ) ) -%> - + ) %> +<BR> <% include('/elements/error.html') %> +<BR> <FORM METHOD="POST" ACTION="<% "${p}edit/process/rate_time.cgi" %>"> <INPUT TYPE="hidden" NAME="ratetimenum" VALUE="<% $ratetimenum %>"> @@ -15,12 +16,10 @@ </TR> </TABLE> <% include('/elements/auto-table.html', - header => [ 'Start', 'End' ], - fields => [ 'stime', 'etime' ], - size => [ 18, 18 ], - maxl => [ 15, 15 ], - align => [ 'right', 'right' ], - data => \@data, + 'header' => [ '', 'Start','','', '','End','','' ], + 'fields' => [ qw(sd sh sm sa ed eh em ea) ], + 'select' => [ ($day, $hour, $min, $ampm) x 2 ], + 'data' => \@data, ) %> <INPUT TYPE="submit" VALUE="<% $rate_time ? 'Apply changes' : 'Add period'%>"> </FORM> @@ -29,16 +28,42 @@ <% include('/elements/footer.html') %> <%init> -my $ratetimenum = ($cgi->keywords)[0] || ''; +my $ratetimenum = ($cgi->keywords)[0] || $cgi->param('ratetimenum') || ''; my $action = 'Add'; my $rate_time; my @data = (); +my $day = [ 0 => 'Sun', + 1 => 'Mon', + 2 => 'Tue', + 3 => 'Wed', + 4 => 'Thu', + 5 => 'Fri', + 6 => 'Sat', ]; +my $hour = [ map( {$_, sprintf('%02d',$_) } 0..11 )]; +my $min = [ map( {$_, sprintf('%02d',$_) } 0,30 )]; +my $ampm = [ 0 => 'AM', 1 => 'PM' ]; if($ratetimenum) { $action = 'Edit'; $rate_time = qsearchs('rate_time', {ratetimenum => $ratetimenum}) or die "ratetimenum $ratetimenum not found"; - @data = $rate_time->description; + if($cgi->param('error')) { + my %vars = $cgi->Vars; + foreach my $i (sort {$a <=> $b } map { /^sd(\d+)$/ } keys(%vars)) { + push @data, [ @vars{"sd$i", "sh$i", "sm$i", "sa$i", + "ed$i", "eh$i", "em$i", "ea$i"} ]; + } + } + else { + foreach my $interval ($rate_time->intervals) { + push @data, [ map { int($_/86400) % 7, + int($_/3600) % 12, + int($_/60) % 60, + int($_/43200) % 2, } + ( $interval->stime, $interval->etime ) + ]; + } + } } </%init> |