new rate editor
authorivan <ivan>
Thu, 10 Jan 2008 21:53:49 +0000 (21:53 +0000)
committerivan <ivan>
Thu, 10 Jan 2008 21:53:49 +0000 (21:53 +0000)
FS/FS/rate_detail.pm
httemplate/browse/rate.cgi
httemplate/edit/elements/edit.html
httemplate/edit/process/rate_region.cgi
httemplate/edit/rate.cgi
httemplate/edit/rate_region.cgi

index 6f023f5..7f8c89e 100644 (file)
@@ -126,6 +126,18 @@ sub check {
   $self->SUPER::check;
 }
 
+=item rate 
+
+Returns the parent call plan (see L<FS::rate>) associated with this call plan
+rate.
+
+=cut
+
+sub rate {
+  my $self = shift;
+  qsearchs('rate', { 'ratenum' => $self->ratenum } );
+}
+
 =item orig_region 
 
 Returns the origination region (see L<FS::rate_region>) associated with this
@@ -150,6 +162,31 @@ sub dest_region {
   qsearchs('rate_region', { 'regionnum' => $self->dest_regionnum } );
 }
 
+=item dest_regionname
+
+Returns the name of the destination region (see L<FS::rate_region>) associated
+with this call plan rate.
+
+=cut
+
+sub dest_regionname {
+  my $self = shift;
+  $self->dest_region->regionname;
+}
+
+=item dest_regionname
+
+Returns a short list of the prefixes for the destination region
+(see L<FS::rate_region>) associated with this call plan rate.
+
+=cut
+
+sub dest_prefixes_short {
+  my $self = shift;
+  $self->dest_region->prefixes_short;
+}
+
+
 =back
 
 =head1 BUGS
index 584891a..b20c45c 100644 (file)
@@ -1,34 +1,64 @@
 <% include( 'elements/browse.html',
-                 'title'       => 'Rate plans',
-                 'menubar'     => [ 'Main menu' => $p, ],
-                 'html_init'   => $html_init,
-                 'name'        => 'rate plans',
-                 'query'       => { 'table'     => 'rate',
-                                    'hashref'   => {},
-                                    'extra_sql' => 'ORDER BY ratenum',
-                                  },
-                 'count_query' => $count_query,
-                 'header'      => [ '#', 'Rate plan', ],
-                 'fields'      => [ 'ratenum', 'ratename' ],
-                 'links'       => [ $link, $link ],
-             )
+              'title'       => 'Rate plans',
+              'menubar'     => [ 'Regions and Prefixes' =>
+                                   $p.'browse/rate_region.html',
+                               ],
+              'html_init'   => $html_init,
+              'name'        => 'rate plans',
+              'query'       => { 'table'     => 'rate',
+                                 'hashref'   => {},
+                                 'extra_sql' => 'ORDER BY ratenum',
+                               },
+              'count_query' => $count_query,
+              'header'      => [ '#',       'Rate plan', 'Rates'    ],
+              'fields'      => [ 'ratenum', 'ratename',  $rates_sub ],
+              'links'       => [ $link,     $link,       ''         ],
+          )
 %>
+<%once>
+
+my $sth = dbh->prepare("SELECT DISTINCT(countrycode) FROM rate_prefix")
+  or die dbh->errstr;
+$sth->execute or die $sth->errstr;
+my @all_countrycodes = map $_->[0], @{ $sth->fetchall_arrayref };
+my $all_countrycodes = join("\n", map qq(<OPTION VALUE="$_">$_),
+                                      @all_countrycodes
+                           );
+
+my $rates_sub = sub {
+  my $rate = shift;
+  my $ratenum = $rate->ratenum;
+
+  qq( <FORM METHOD="GET" ACTION="${p}browse/rate_detail.html">
+        <INPUT TYPE="hidden" NAME="ratenum" VALUE="$ratenum">
+        <SELECT NAME="countrycode" onChange="this.form.submit();">
+          <OPTION SELECTED>Select Country Code
+          <OPTION VALUE="">(all)
+          $all_countrycodes
+        </SELECT>
+      </FORM>
+    );
+
+
+};
+
+</%once>
 <%init>
 
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
 
 my $html_init = 
-'Rate plans, regions and prefixes for VoIP and call billing.<BR><BR>'.
-qq!<A HREF="${p}edit/rate.cgi"><I>Add a rate plan</I></A>!.
-qq! | <A HREF="${p}edit/rate_region.cgi"><I>Add a region</I></A>!.
-'<BR><BR>
- <SCRIPT>
- function rate_areyousure(href) {
-  if (confirm("Are you sure you want to delete this rate plan?") == true)
-    window.location.href = href;
- }
</SCRIPT>';
+  'Rate plans for VoIP and call billing.<BR><BR>'.
+  qq!<A HREF="${p}edit/rate.cgi"><I>Add a rate plan</I></A>!.
+  '<BR><BR>
+   <SCRIPT>
+   function rate_areyousure(href) {
+    if (confirm("Are you sure you want to delete this rate plan?") == true)
+      window.location.href = href;
+   }
+   </SCRIPT>
 ';
 
 my $count_query = 'SELECT COUNT(*) FROM rate';
 
index bd362e1..ad52f7a 100644 (file)
@@ -173,6 +173,10 @@ Example:
 %     if $opt{'debug'};
 %
 %   my %include_common = (
+%
+%     #text and derivitives
+%     'size'          => $f->{'size'},
+%
 %     #checkbox, title, fixed, fixedhidden
 %     #& deprecated weird value hashref used only by reason.html
 %     'value'         => $f->{'value'},
index 7532245..3933ff3 100755 (executable)
@@ -1,52 +1,53 @@
-%
-%
-%my $regionnum = $cgi->param('regionnum');
-%
-%my $old = qsearchs('rate_region', { 'regionnum' => $regionnum } ) if $regionnum;
-%
-%my $new = new FS::rate_region ( {
-%  map {
-%    $_, scalar($cgi->param($_));
-%  } ( fields('rate_region') )
-%} );
-%
-%my $countrycode = $cgi->param('countrycode');
-%my @npa = split(/\s*,\s*/, $cgi->param('npa'));
-%$npa[0] = '' unless @npa;
-%my @rate_prefix = map {
-%                        new FS::rate_prefix {
-%                          'countrycode' => $countrycode,
-%                          'npa'         => $_,
-%                        }
-%                      } @npa;
-%
-%my @dest_detail = map {
-%  my $ratenum = $_->ratenum;
-%  new FS::rate_detail {
-%    'ratenum'  => $ratenum,
-%    map { $_ => $cgi->param("$_$ratenum") }
-%        qw( min_included min_charge sec_granularity )
-%  };
-%} qsearch('rate', {} );
-%
-%
-%my $error;
-%if ( $regionnum ) {
-%  $error = $new->replace($old, 'rate_prefix' => \@rate_prefix,
-%                               'dest_detail' => \@dest_detail, );
-%} else {
-%  $error = $new->insert( 'rate_prefix' => \@rate_prefix,
-%                         'dest_detail' => \@dest_detail, );
-%  $regionnum = $new->getfield('regionnum');
-%}
-%
 %if ( $error ) {
 %  $cgi->param('error', $error);
-%  print $cgi->redirect(popurl(2). "rate_region.cgi?". $cgi->query_string );
+<% $cgi->redirect(popurl(2). "rate_region.cgi?". $cgi->query_string ) %>
 %} else { 
-%  #print $cgi->redirect(popurl(3). "browse/rate_region.cgi");
-%  print $cgi->redirect(popurl(3). "browse/rate.cgi");
+<% $cgi->redirect(popurl(3). "browse/rate_region.html") %>
 %}
-%
-%
+<%init>
+
+my $conf = new FS::Conf;
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my $regionnum = $cgi->param('regionnum');
+
+my $old = qsearchs('rate_region', { 'regionnum' => $regionnum } ) if $regionnum;
+
+my $new = new FS::rate_region ( {
+  map {
+    $_, scalar($cgi->param($_));
+  } ( fields('rate_region') )
+} );
+
+my $countrycode = $cgi->param('countrycode');
+my @npa = split(/\s*,\s*/, $cgi->param('npa'));
+$npa[0] = '' unless @npa;
+my @rate_prefix = map {
+                        new FS::rate_prefix {
+                          'countrycode' => $countrycode,
+                          'npa'         => $_,
+                        }
+                      } @npa;
+
+my @dest_detail = map {
+  my $ratenum = $_->ratenum;
+  new FS::rate_detail {
+    'ratenum'  => $ratenum,
+    map { $_ => $cgi->param("$_$ratenum") }
+        qw( min_included min_charge sec_granularity )
+  };
+} qsearch('rate', {} );
+
+
+my $error;
+if ( $regionnum ) {
+  $error = $new->replace($old, 'rate_prefix' => \@rate_prefix,
+                               'dest_detail' => \@dest_detail, );
+} else {
+  $error = $new->insert( 'rate_prefix' => \@rate_prefix,
+                         'dest_detail' => \@dest_detail, );
+  $regionnum = $new->getfield('regionnum');
+}
 
+</%init>
index c44364d..269b3b0 100644 (file)
@@ -1,34 +1,3 @@
-%
-%
-%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 = <<END;
-%#  WHERE 0 < ( SELECT COUNT(*) FROM rate_prefix
-%#               WHERE rate_region.regionnum = rate_prefix.regionnum
-%#                 AND countrycode != '1'
-%#            )
-%#END
-%
-%
-
-
 <% include("/elements/header.html","$action Rate plan", menubar(
       'Main Menu' => $p,
       'View all rate plans' => "${p}browse/rate.cgi",
@@ -49,72 +18,27 @@ Rate plan
 <INPUT TYPE="text" NAME="ratename" SIZE=32 VALUE="<% $rate->ratename %>">
 <BR><BR>
 
-<% table() %>
-<TR>
-  <TH>Region</TH>
-  <TH>Prefix(es)</TH>
-  <TH><FONT SIZE=-1>Included<BR>minutes</FONT></TH>
-  <TH><FONT SIZE=-1>Charge per<BR>minute</FONT></TH>
-  <TH><FONT SIZE=-1>Granularity</FONT></TH>
-</TR>
-% foreach my $rate_region (
-%     #sort { lc($a->regionname) cmp lc($b->regionname) }
-%     qsearch({
-%               'table'     => 'rate_region',
-%               'hashref'   => {},
-%               'order_by'  => 'ORDER BY LOWER(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'
-%                              };
-%
-
-
-  <TR>
-    <TD><A HREF="<%$p%>edit/rate_region.cgi?<% $rate_region->regionnum %>"><% $rate_region->regionname %></A></TD>
-    <TD><% $rate_region->prefixes_short %></TD>
-    <TD><INPUT TYPE="text" SIZE=5 NAME="min_included<%$n%>" VALUE="<% $cgi->param("min_included$n") || $rate_detail->min_included %>"></TD>
-    <TD>$<INPUT TYPE="text" SIZE=4 NAME="min_charge<%$n%>" VALUE="<% sprintf('%.2f', $cgi->param("min_charge$n") || $rate_detail->min_charge ) %>"></TD>
-    <TD>
-      <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>
-  </TR>
-% } 
+<INPUT NAME="submit" TYPE="button" VALUE="<% 
+  $rate->ratenum ? "Apply changes" : "Add rate plan"
+%>" onClick="document.OneTrueForm.submit.disabled=true; process();">
 
+</FORM>
 
-<TR>
-  <TD COLSPAN=5 ALIGN="center">
-    <A HREF="<%$p%>edit/rate_region.cgi"><I>Add a region</I></A>
-  </TD>
-</TR>
+<% include('/elements/footer.html') %>
 
-</TABLE>
+<%init>
 
-<BR><INPUT NAME="submit" TYPE="button" VALUE="<% 
-  $rate->ratenum ? "Apply changes" : "Add rate plan"
-%>" onClick="document.OneTrueForm.submit.disabled=true; process();">
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
 
-    </FORM>
-  </BODY>
-</HTML>
+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';
 
+</%init>
index d55c0de..47d1888 100644 (file)
@@ -1,43 +1,5 @@
-<!-- mason kludge -->
-%
-%
-%my $rate_region;
-%if ( $cgi->param('error') ) {
-%  $rate_region = new FS::rate_region ( {
-%    map { $_, scalar($cgi->param($_)) } fields('rate_region')
-%  } );
-%} elsif ( $cgi->keywords ) {
-%  my($query) = $cgi->keywords;
-%  $query =~ /^(\d+)$/;
-%  $rate_region = qsearchs( 'rate_region', { 'regionnum' => $1 } );
-%} else { #adding
-%  $rate_region = new FS::rate_region {};
-%}
-%my $action = $rate_region->regionnum ? 'Edit' : 'Add';
-%
-%my $p1 = popurl(1);
-%
-%my %granularity = (
-%  '6'  => '6 second',
-%  '60' => 'minute',
-%);
-%
-%my @rate_prefix = $rate_region->rate_prefix;
-%my $countrycode = '';
-%if ( @rate_prefix ) {
-%  $countrycode = $rate_prefix[0]->countrycode;
-%  foreach my $rate_prefix ( @rate_prefix ) {
-%    errorpage('multiple country codes per region not yet supported by web UI')
-%      unless $rate_prefix->countrycode eq $countrycode;
-%  }
-%}
-%
-%
-
-
 <% include("/elements/header.html","$action Region", menubar(
-      'Main Menu' => $p,
-      #'View all regions' => "${p}browse/rate_region.cgi",
+      'View all regions' => "${p}browse/rate_region.html",
     ))
 %>
 
 
 <INPUT TYPE="hidden" NAME="regionnum" VALUE="<% $rate_region->regionnum %>">
 
+%# region info
+
 <% ntable('#cccccc') %>
-<TR>
-  <TH ALIGN="right">Region name</TH>
-  <TD><INPUT TYPE="text" NAME="regionname" SIZE=32 VALUE="<% $rate_region->regionname %>"></TR>
-</TR>
 
-<TR>
-  <TH ALIGN="right">Country code</TH>
-  <TD><INPUT TYPE="text" NAME="countrycode" SIZE=4 MAXLENGTH=3 VALUE="<% $countrycode %>"></TR>
-</TR>
+  <TR>
+    <TH ALIGN="right">Region name</TH>
+    <TD><INPUT TYPE="text" NAME="regionname" SIZE=32 VALUE="<% $rate_region->regionname %>"></TR>
+  </TR>
 
+  <TR>
+    <TH ALIGN="right">Country code</TH>
+    <TD><INPUT TYPE="text" NAME="countrycode" SIZE=4 MAXLENGTH=3 VALUE="<% $countrycode %>"></TR>
+  </TR>
 
-<TR>
-  <TH ALIGN="right">Prefixes</TH>
-  <TD>
-    <TEXTAREA NAME="npa" WRAP=SOFT><% join(', ', map $_->npa, @rate_prefix ) %></TEXTAREA>
-  </TD>
-</TR>
+  <TR>
+    <TD ALIGN="right">
+      <B>Prefixes</B>
+      <BR><FONT SIZE="-1">(comma-separated)</FONT>
+    </TD>
+    <TD>
+      <TEXTAREA NAME="npa" WRAP=SOFT><% join(', ', map $_->npa, @rate_prefix ) %></TEXTAREA>
+    </TD>
+  </TR>
 
 </TABLE>
 
+%# rate plan info
+
 <BR>
-<% table() %>
-<TR>
-  <TH>Rate plan</TH>
-  <TH><FONT SIZE=-1>Included<BR>minutes</FONT></TH>
-  <TH><FONT SIZE=-1>Charge per<BR>minute</FONT></TH>
-  <TH><FONT SIZE=-1>Granularity</FONT></TH>
-</TR>
+
+<% 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</FONT>
+    </TH>
+    <TH CLASS="grid" BGCOLOR="#cccccc">
+      <FONT SIZE=-1>Charge per<BR>minute</FONT>
+    </TH>
+    <TH CLASS="grid" BGCOLOR="#cccccc">
+      <FONT SIZE=-1>Granularity</FONT>
+    </TH>
+  </TR>
+
 % foreach my $rate ( qsearch('rate', {}) ) {
 %
 %  my $n = $rate->ratenum;
 %                                             'sec_granularity' => '60'
 %                                           };
 %
-%
+% if ( $bgcolor eq $bgcolor1 ) {
+%   $bgcolor = $bgcolor2;
+% } else {
+%   $bgcolor = $bgcolor1;
+% }
 
   <TR>
-    <TD><A HREF="<%$p%>edit/rate.cgi?<% $rate->ratenum %>"><% $rate->ratename %></TD>
-    <TD><INPUT TYPE="text" SIZE=5 NAME="min_included<%$n%>" VALUE="<% $cgi->param("min_included$n") || $rate_detail->min_included %>"></TD>
-    <TD>$<INPUT TYPE="text" SIZE=4 NAME="min_charge<%$n%>" VALUE="<% sprintf('%.2f', $cgi->param("min_charge$n") || $rate_detail->min_charge ) %>"></TD>
-    <TD>
-      <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}%>
-% } 
+    <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=5 NAME="min_included<%$n%>" VALUE="<% $cgi->param("min_included$n") || $rate_detail->min_included %>">
+    </TD>
+
+    <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
+      $<INPUT TYPE="text" SIZE=4 NAME="min_charge<%$n%>" VALUE="<% sprintf('%.2f', $cgi->param("min_charge$n") || $rate_detail->min_charge ) %>">
+    </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>
+
   </TR>
-% } 
 
+% } 
 
 </TABLE>
 
-<BR><BR><INPUT TYPE="submit" VALUE="<% 
-  $rate_region->regionnum ? "Apply changes" : "Add region"
-%>">
-
-    </FORM>
-  </BODY>
-</HTML>
-
 
+<BR><BR>
+<INPUT TYPE="submit" VALUE="<% $rate_region->regionnum ? "Apply changes" : "Add region" %>">
+
+</FORM>
+
+<% include('/elements/footer.html') %>
+
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my $rate_region;
+if ( $cgi->param('error') ) {
+  $rate_region = new FS::rate_region ( {
+    map { $_, scalar($cgi->param($_)) } fields('rate_region')
+  } );
+} elsif ( $cgi->keywords ) {
+  my($query) = $cgi->keywords;
+  $query =~ /^(\d+)$/ or die "unparsable regionnum";
+  $rate_region = qsearchs( 'rate_region', { 'regionnum' => $1 } )
+    or die "unknown regionnum $1\n";
+} else { #adding
+  $rate_region = new FS::rate_region {};
+}
+my $action = $rate_region->regionnum ? 'Edit' : 'Add';
+
+my $p1 = popurl(1);
+
+tie my %granularity, 'Tie::IxHash',
+  '1', => '1 second',
+  '6'  => '6 second',
+  '30' => '30 second', # '1/2 minute',
+  '60' => 'minute',
+;
+
+my @rate_prefix = $rate_region->rate_prefix;
+my $countrycode = '';
+if ( @rate_prefix ) {
+  $countrycode = $rate_prefix[0]->countrycode;
+  foreach my $rate_prefix ( @rate_prefix ) {
+    errorpage('multiple country codes per region not yet supported by web UI')
+      unless $rate_prefix->countrycode eq $countrycode;
+  }
+}
+
+</%init>