show imported region and rate #s, RT#83146
[freeside.git] / httemplate / edit / rate.cgi
index 9aa4e72..c0e8d93 100644 (file)
-<%
-
-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,
+<& /elements/header.html,
+  "$action Rate plan",
+  menubar(
       'View all rate plans' => "${p}browse/rate.cgi",
-    ))
-%>
+      'View packages that use this plan' => "${p}browse/part_pkg.cgi?ratenum="
+                                            . $rate->ratenum,
+  )
+&>
 
-<%= include('/elements/progress-init.html',
+<% include('/elements/progress-init.html',
               'OneTrueForm',
-              [ 'rate', 'min_', 'sec_' ],
+              [ 'rate', 'agentnum' ],
               'process/rate.cgi',
               $p.'browse/rate.cgi',
            )
 %>
 <FORM NAME="OneTrueForm">
-<INPUT TYPE="hidden" NAME="ratenum" VALUE="<%= $rate->ratenum %>">
-
-Rate plan
-<INPUT TYPE="text" NAME="ratename" SIZE=32 VALUE="<%= $rate->ratename %>">
-<BR><BR>
+<INPUT TYPE="hidden" NAME="ratenum" VALUE="<% $rate->ratenum %>">
 
-<%= 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({
-               'select'    => 'DISTINCT ON ( regionnum ) rate_region.*',
-               'table'     => 'rate_region',
-               'hashref'   => {},
-               #'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
-            })
-   ) {
-     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'
-                              };
-%>
+<TABLE CLASS="fsinnerbox">
 
-  <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>
+<& /elements/tr-select-agent.html,
+     disable_empty => ! $FS::CurrentUser::CurrentUser->access_right('Configuration'), #, 'Edit global CDR rates'
+     empty_label   => '(global)',
+&>
 
-<% } %>
+% if ( $rate->agent_rateid ) {
+    <TR>
+      <TH ALIGN="right">Legacy #</TH>
+      <TD><% $rate->agent_rateid |h %></TD>
+    </TR>
+% }
 
 <TR>
-  <TD COLSPAN=5 ALIGN="center">
-    <A HREF="<%=$p%>edit/rate_region.cgi"><I>Add a region</I></A>
-  </TD>
+  <TH>Rate plan</TH>
+  <TD><INPUT TYPE="text" NAME="ratename" SIZE=32 VALUE="<% $rate->ratename %>"></TD>
 </TR>
-
 </TABLE>
+<BR>
 
-<BR><INPUT NAME="submit" TYPE="button" VALUE="<%= 
+<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>
+% if ( my $select_cdr_type = include('/elements/select-cdr_type.html',
+%  'curr_value'   => $cdrtypenum,
+%  'onchange'     => 'form.submit();',
+%  'name_col'     => 'cdrtypename',
+%  'value_col'    => 'cdrtypenum',
+%  'empty_label'  => '(default)',
+% ) ) {
+<FORM ACTION="<%$cgi->url%>" METHOD="GET">
+<INPUT TYPE="hidden" NAME="ratenum" VALUE="<% $rate->ratenum %>">
+<INPUT TYPE="hidden" NAME="countrycode" VALUE="<% $countrycode %>">
+<FONT SIZE="+1">Usage type: <% $select_cdr_type %></FONT>
+</FORM>
+% }
+
+<% include('/edit/elements/rate_detail.html',
+            'ratenum'     => $rate->ratenum,
+            'countrycode' => $countrycode,
+            'cdrtypenum'  => $cdrtypenum,
+) %>
+% }
+
+<% include('/elements/footer.html') %>
+
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
 
-    </FORM>
-  </BODY>
-</HTML>
+my $rate;
+if ( $cgi->param('ratenum') ) {
+  $cgi->param('ratenum') =~ /^(\d+)$/;
+  $rate = qsearchs( 'rate', { 'ratenum' => $1 } );
+} else { #adding
+  $rate = new FS::rate {};
+}
+my $action = $rate->ratenum ? 'Edit' : 'Add';
 
+my $countrycode = '';
+if ( $cgi->param('countrycode') =~ /^(\d+)$/ ) {
+  $countrycode = $1;
+}
+
+my $cdrtypenum = '';
+if ( $cgi->param('cdrtypenum') =~ /^(\d+)$/ ) {
+  $cdrtypenum = $1;
+}
+</%init>