summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorivan <ivan>2011-11-14 04:31:31 +0000
committerivan <ivan>2011-11-14 04:31:31 +0000
commit3db061f538c06804bd0a52b9ef8be3dc6b6db82e (patch)
tree7335808809768c4dcc6c8c85aebfa3ec365398ea /httemplate
parent3892b13ea137969a2b4f880883960e58003cc1b3 (diff)
rate tiers for vnes, RT#14903
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/browse/rate_tier.html53
-rw-r--r--httemplate/edit/elements/edit.html2
-rw-r--r--httemplate/edit/process/rate_tier.html15
-rw-r--r--httemplate/edit/rate_tier.html54
-rw-r--r--httemplate/elements/menu.html4
-rw-r--r--httemplate/elements/rate_tier_detail.html66
-rw-r--r--httemplate/elements/tr-rate_tier_detail.html24
7 files changed, 216 insertions, 2 deletions
diff --git a/httemplate/browse/rate_tier.html b/httemplate/browse/rate_tier.html
new file mode 100644
index 000000000..d84080857
--- /dev/null
+++ b/httemplate/browse/rate_tier.html
@@ -0,0 +1,53 @@
+<% include( 'elements/browse.html',
+ 'title' => 'Tiering plans',
+ 'name_singular' => 'tiering plan',
+ 'menubar' => [ 'Add a new tier plan' =>
+ $p.'edit/rate_tier.html',
+ ],
+ 'query' => { 'table' => 'rate_tier', },
+ 'count_query' => 'SELECT COUNT(*) FROM rate_tier',
+ 'header' => [ 'Plan', 'Tiers', ],
+ 'fields' => [ 'tiername',
+ $details_sub,
+ ],
+ 'links' => [ $link, ],
+ #'disableable' => 1,
+ #'disabled_statuspos' => 1,
+ )
+%>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my $conf = new FS::Conf;
+my $money_char = $conf->config('money_char') || '$';
+
+my $link = [ "${p}edit/rate_tier.html?", 'tiernum' ];
+
+my $details_sub = sub {
+ my $rate_tier = shift;
+
+ [ [ { 'data' => 'Minimum quantity',
+ 'align' => 'center',
+ },
+ { 'data' => 'Charge per minute/call',
+ 'align' => 'center',
+ },
+ ],
+ map { my $rate_tier_detail = $_;
+ [
+ { 'data' => $rate_tier_detail->min_quan,
+ 'align' => 'right',
+ },
+ { 'data' => $money_char. $rate_tier_detail->min_charge,
+ 'align' => 'right',
+ },
+ ];
+ }
+ $rate_tier->rate_tier_detail
+ ];
+
+};
+
+</%init>
diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html
index 6db54fd48..4e896f239 100644
--- a/httemplate/edit/elements/edit.html
+++ b/httemplate/edit/elements/edit.html
@@ -549,7 +549,7 @@ Example:
// only spawn if we're the last element... return if not
- var field_regex = /(\d+)(_[a-z]+)?$/;
+ var field_regex = /(\d+)(_[a-z_]+)?$/;
var match = field_regex.exec(what.name);
if ( !match ) {
alert(what.name + " didn't match for " + what);
diff --git a/httemplate/edit/process/rate_tier.html b/httemplate/edit/process/rate_tier.html
new file mode 100644
index 000000000..f29edbb50
--- /dev/null
+++ b/httemplate/edit/process/rate_tier.html
@@ -0,0 +1,15 @@
+<% include( 'elements/process.html',
+ 'table' => 'rate_tier',
+ 'viewall_dir' => 'browse',
+ 'process_o2m' => {
+ 'table' => 'rate_tier_detail',
+ 'fields' => [qw( min_quan min_charge )],
+ },
+ )
+%>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+</%init>
diff --git a/httemplate/edit/rate_tier.html b/httemplate/edit/rate_tier.html
new file mode 100644
index 000000000..f9df4b5ce
--- /dev/null
+++ b/httemplate/edit/rate_tier.html
@@ -0,0 +1,54 @@
+<% include( 'elements/edit.html',
+ 'table' => 'rate_tier',
+ 'name_singular' => 'tiering plan',
+ 'fields' => [
+ 'tiername',
+ #{ field=>'disabled', type=>'checkbox', value=>'Y' },
+ { 'field' => 'tierdetailnum',
+ 'type' => 'rate_tier_detail',
+ 'colspan' => 2,
+ 'o2m_table' => 'rate_tier_detail',
+ 'm2_label' => 'Tier',
+ 'm2_error_callback' => $m2_error_callback,
+ },
+ ],
+ 'labels' => { 'tiernum' => 'Plan #',
+ 'tiername' => 'Tiering plan',
+ 'tierdetailnum' => 'Tier',
+ },
+ 'viewall_dir' => 'browse',
+ )
+%>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my $m2_error_callback = sub {
+ my($cgi, $object) = @_;
+
+ #process_o2m fields in process/rate_tier.html
+ my @fields = qw( min_quan min_charge );
+ my @gfields = ( '', map "_$_", @fields );
+
+ map {
+ if ( /^tierdetailnum(\d+)$/ ) {
+ my $num = $1;
+ if ( grep $cgi->param("tierdetailnum$num$_"), @gfields ) {
+ my $x = new FS::rate_tier_detail {
+ 'tierdetailnum' => scalar($cgi->param("tierdetailnum$num")),
+ map { $_ => scalar($cgi->param("tierdetailnum${num}_$_")) }
+ @fields,
+ };
+ $x;
+ } else {
+ ();
+ }
+ } else {
+ ();
+ }
+ }
+ $cgi->param;
+};
+
+</%init>
diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html
index b29b00595..48270da36 100644
--- a/httemplate/elements/menu.html
+++ b/httemplate/elements/menu.html
@@ -25,7 +25,7 @@
% 'style' => 'color:#999999',
% 'actionlabel' => emt('About'),
% 'width' => 300,
-% 'height' => 360,
+% 'height' => 375,
% 'color' => '#7e0079',
% 'scrolling' => 'no',
% );
@@ -503,6 +503,8 @@ tie my %config_billing_rates, 'Tie::IxHash',
'Usage classes' => [ $fsurl.'browse/usage_class.html', 'Usage classes define groups of usage for taxation.' ],
'Time periods' => [ $fsurl.'browse/rate_time.html', 'Time periods define days and hours for rate plans' ],
'Edit rates with Excel' => [ $fsurl.'misc/rate_edit_excel.html', 'Download and edit rates with Excel, then upload changes.' ], #"Edit with Excel" ?
+ 'separator' => '', #its a separator!
+ 'Tiering plans' => [ $fsurl.'browse/rate_tier.html', 'Rating tiers' ],
;
tie my %config_billing, 'Tie::IxHash';
diff --git a/httemplate/elements/rate_tier_detail.html b/httemplate/elements/rate_tier_detail.html
new file mode 100644
index 000000000..ef1f38b8a
--- /dev/null
+++ b/httemplate/elements/rate_tier_detail.html
@@ -0,0 +1,66 @@
+% unless ( $opt{'js_only'} ) {
+
+ <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
+
+ <TABLE>
+ <TR>
+% foreach my $field ( @fields ) {
+%
+% my $value = $rate_tier_detail->get($field);
+
+ <TD>
+ <% $field eq 'min_charge' ? $money_char : '' %>
+ <INPUT TYPE = "text"
+ NAME = "<%$name%>_<%$field%>"
+ ID = "<%$id%>_<%$field%>"
+ SIZE = "<% $size{$field} || 15 %>"
+ STYLE = "text-align:right"
+ VALUE = "<% scalar($cgi->param($name."_$field"))
+ || $value |h %>"
+ <% $onchange %>
+ ><BR>
+ <FONT SIZE="-1"><% $label{$field} %></FONT>
+ </TD>
+% }
+ </TR>
+ </TABLE>
+
+% }
+<%init>
+
+my( %opt ) = @_;
+
+my $conf = new FS::Conf;
+my $money_char = $conf->config('money_char') || '$';
+
+my $name = $opt{'element_name'} || $opt{'field'} || 'tierdetailnum';
+my $id = $opt{'id'} || 'tierdetailnum';
+
+my $curr_value = $opt{'curr_value'} || $opt{'value'};
+
+my $onchange = '';
+if ( $opt{'onchange'} ) {
+ $onchange = $opt{'onchange'};
+ $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
+ $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack. all onchange
+ #callbacks should act the same
+ $onchange = 'onChange="'. $onchange. '"';
+}
+
+my $rate_tier_detail;
+if ( $curr_value ) {
+ $rate_tier_detail = qsearchs('rate_tier_detail', { 'tierdetailnum' => $curr_value } );
+} else {
+ $rate_tier_detail = new FS::rate_tier_detail {};
+}
+
+my %size = ( 'title' => 12 );
+
+tie my %label, 'Tie::IxHash',
+ 'min_quan' => 'Minimum quantity',
+ 'min_charge' => 'Charge per minute/call',
+;
+
+my @fields = keys %label;
+
+</%init>
diff --git a/httemplate/elements/tr-rate_tier_detail.html b/httemplate/elements/tr-rate_tier_detail.html
new file mode 100644
index 000000000..7b6f26b57
--- /dev/null
+++ b/httemplate/elements/tr-rate_tier_detail.html
@@ -0,0 +1,24 @@
+% unless ( $opt{'js_only'} ) {
+
+ <% include('tr-td-label.html', %opt) %>
+ <TD <% $cell_style %>>
+
+% }
+%
+ <% include( '/elements/rate_tier_detail.html', %opt ) %>
+%
+% unless ( $opt{'js_only'} ) {
+
+ </TD>
+ </TR>
+
+% }
+<%init>
+
+my( %opt ) = @_;
+
+my $cell_style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';
+
+$opt{'label'} ||= 'Tier';
+
+</%init>