Option to ignore old CDRs, RT#81480
[freeside.git] / httemplate / edit / rate_region.cgi
1 <% include("/elements/header.html","$action Region", menubar(
2       'View all regions' => "${p}browse/rate_region.html",
3     ))
4 %>
5
6 <% include('/elements/error.html') %>
7
8 <FORM ACTION="<%$p1%>process/rate_region.cgi" METHOD=POST>
9
10 <INPUT TYPE="hidden" NAME="regionnum" VALUE="<% $rate_region->regionnum %>">
11
12 %# region info
13
14 <% ntable('#cccccc') %>
15
16   <TR>
17     <TH ALIGN="right">Region name</TH>
18     <TD><INPUT TYPE="text" NAME="regionname" SIZE=32 VALUE="<% $rate_region->regionname %>"></TR>
19   </TR>
20
21   <TR>
22     <TH ALIGN="right">Country code</TH>
23     <TD><INPUT TYPE="text" NAME="countrycode" SIZE=4 MAXLENGTH=3 VALUE="<% $countrycode %>"></TR>
24   </TR>
25
26   <TR>
27     <TD ALIGN="right">
28       <B>Prefixes</B>
29       <BR><FONT SIZE="-1">(comma-separated)</FONT>
30     </TD>
31     <TD>
32       <TEXTAREA NAME="npa" WRAP=SOFT><% join(', ', map { $_->npa. (length($_->nxx) ? '-'.$_->nxx : '') } @rate_prefix ) %></TEXTAREA>
33     </TD>
34   </TR>
35
36   <& /elements/tr-checkbox.html,
37     label       => 'Exact match',
38     field       => 'exact_match',
39     cell_style  => 'font-weight: bold',
40     value       => 'Y',
41     curr_value  => $rate_region->exact_match
42   &>
43
44 </TABLE>
45
46 <BR>
47 <INPUT TYPE="submit" VALUE="<% $rate_region->regionnum ? "Apply changes" : "Add region" %>">
48 </FORM>
49 %# rate plan info, if the region has been created yet
50
51 % if($rate_region->regionnum) {
52 <BR><BR><FONT SIZE="+2">Rates in this region</FONT>
53 % if ( my $select_cdr_type = include('/elements/select-cdr_type.html',
54 %  'curr_value'   => $cdrtypenum,
55 %  'onchange'     => 'form.submit();',
56 %  'name_col'     => 'cdrtypename',
57 %  'value_col'    => 'cdrtypenum',
58 %  'empty_label'  => '(default)',
59 % ) ) {
60 <FORM ACTION="<%$cgi->url%>" METHOD="GET">
61 <INPUT TYPE="hidden" NAME="regionnum"   VALUE="<% $rate_region->regionnum %>">
62 <FONT SIZE="+1">Usage type: <% $select_cdr_type %></FONT>
63 </FORM>
64 % }
65 <% include('/edit/elements/rate_detail.html',
66             'regionnum'   => $rate_region->regionnum,
67             'cdrtypenum'  => $cdrtypenum,
68 ) %>
69 % }
70
71 <% include('/elements/footer.html') %>
72 <%once>
73
74 tie my %conn_secs,   'Tie::IxHash', FS::rate_detail::conn_secs();
75
76 </%once>
77 <%init>
78
79 die "access denied"
80   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
81
82 my $conf = new FS::Conf;
83 my $money_char = $conf->config('money_char') || '$';
84
85 my $rate_region;
86 if ( $cgi->param('error') ) {
87   $rate_region = new FS::rate_region ( {
88     map { $_, scalar($cgi->param($_)) } fields('rate_region')
89   } );
90 } elsif ( $cgi->param('regionnum') ) {
91   $cgi->param('regionnum') =~ /^(\d+)$/ or die "unparseable regionnum";
92   $rate_region = qsearchs( 'rate_region', { 'regionnum' => $1 } )
93     or die "unknown regionnum $1\n";
94 } else { #adding
95   $rate_region = new FS::rate_region {};
96 }
97 my $action = $rate_region->regionnum ? 'Edit' : 'Add';
98
99 my $p1 = popurl(1);
100
101 tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
102
103 my @rate_prefix = $rate_region->rate_prefix;
104 my $countrycode = '';
105 if ( @rate_prefix ) {
106   $countrycode = $rate_prefix[0]->countrycode;
107   foreach my $rate_prefix ( @rate_prefix ) {
108     errorpage('multiple country codes per region not yet supported by web UI')
109       unless $rate_prefix->countrycode eq $countrycode;
110   }
111 }
112 my $cdrtypenum = '';
113 if ( $cgi->param('cdrtypenum') =~ /^(\d+)$/ ) {
114   $cdrtypenum = $1;
115 }
116 </%init>