Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / edit / rate_detail.html
1 <% include('elements/edit.html',
2      'popup'  => 1,
3      'name'   => $name,
4      'table'  => 'rate_detail',
5      'labels' => { 'ratedetailnum'       => 'Rate', #should hide...
6                    'dest_regionname'     => 'Region',
7                    'dest_prefixes_short' => 'Prefix(es)',
8                    'rate_time_name'      => 'Time period',
9                    'min_included'        => 'Included minutes/calls',
10                    'region_group'        => 'Region Group',
11                    'conn_charge'         => 'Retail connection charge',
12                    'conn_sec'            => 'For',
13                    'min_charge'          => 'Retail charge per minute/call',
14                    'sec_granularity'     => 'Granularity',
15                    'conn_cost'           => 'Wholesale connection cost',
16                    'min_cost'            => 'Wholesale cost per minute/call',
17                    'classnum'            => 'Usage class',
18                  },
19      'fields' => [
20                    { field=>'ratenum',             type=>'hidden', },
21                    { field=>'orig_regionnum',      type=>'hidden', },
22                    { field=>'dest_regionnum',      type=>'hidden', },
23                    { field=>'ratetimenum',         type=>'hidden', },
24                    { field=>'cdrtypenum',          type=>'hidden', },
25                    { field=>'dest_regionname',     type=>'fixed',  },
26                    { field=>'dest_prefixes_short', type=>'fixed',  },
27                    { field=>'rate_time_name',      type=>'fixed',  },
28                    { field => 'region_group',
29                      type => 'checkbox',
30                      value => 'Y',
31                    },
32                    { field=>'min_included',        type=>'text',  size=>5 },
33                    { field=>'conn_charge',         type=>'money', size=>4 },
34                    { field=>'conn_cost',         type=>'money', size=>4 },
35                    { field          =>'conn_sec',
36                       type          =>'select',
37                       options       => [ keys %conn_secs ],
38                       labels        => \%conn_secs,
39                       disable_empty => 1,
40                    },
41                    { field=>'min_charge',          type=>'money', size=>4 },
42                    { field=>'min_cost',          type=>'money', size=>4 },
43                    { field         =>'sec_granularity',
44                      type          =>'select',
45                      options       => [ keys %granularity ],
46                      labels        => \%granularity,
47                      disable_empty => 1,
48                    },
49                    { field         =>'classnum',
50                      type          =>'select-table',
51                      table         =>'usage_class',
52                      name_col      =>'classname',
53                      empty_label   =>'(default)',
54                      hashref        =>{ disabled => '' },
55                    },
56
57                  ],
58      'new_hashref_callback' => sub {
59         { ratenum        => scalar($cgi->param('ratenum')),
60           dest_regionnum => scalar($cgi->param('dest_regionnum')),
61           ratetimenum    => scalar($cgi->param('ratetimenum')),
62           cdrtypenum     => scalar($cgi->param('cdrtypenum')),
63           min_included   => 0,
64           conn_charge    => 0,
65         }
66       },
67    )
68 %>
69 <%once>
70
71 tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
72 tie my %conn_secs,   'Tie::IxHash', FS::rate_detail::conn_secs();
73
74 </%once>
75 <%init>
76
77 my $conf = new FS::Conf;
78 die "access denied"
79   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
80
81 #slightly inefficient, i suppose an edit+error callback would be better
82 my $name = 'rate';
83 my ($keywords) = $cgi->keywords;
84 if (    $keywords                    =~ /^(\d+)$/
85      || $cgi->param('ratedetailnum') =~ /^(\d+)$/ ) {
86   my $rate_detail = qsearchs('rate_detail', { 'ratedetailnum' => $1 } )
87     or die "unknown ratedetailnum $1";
88   $name =
89     $rate_detail->rate->ratename. ' rate for '. $rate_detail->dest_regionname;
90 }
91
92 #sec_granularity should default to 60!  for new rates when this gets used for em
93
94 </%init>