diff options
author | ivan <ivan> | 2010-02-04 20:39:56 +0000 |
---|---|---|
committer | ivan <ivan> | 2010-02-04 20:39:56 +0000 |
commit | 4cacb3fa439b56fc7c9a742b69ec3f6ffd660433 (patch) | |
tree | 7b91bf502c5bcc974b30431fd8c96bf0bfab3288 | |
parent | 1bfbab83c338f6a11ae26c4d197ad775c568ebde (diff) |
discounts, RT#6679
-rw-r--r-- | FS/FS/discount.pm | 2 | ||||
-rw-r--r-- | httemplate/edit/discount.html | 2 | ||||
-rw-r--r-- | httemplate/elements/select-discount.html | 20 | ||||
-rw-r--r-- | httemplate/elements/select-table.html | 14 | ||||
-rw-r--r-- | httemplate/elements/tr-input-text.html | 4 | ||||
-rw-r--r-- | httemplate/elements/tr-select-discount.html | 154 | ||||
-rw-r--r-- | httemplate/elements/tr-select.html | 4 |
7 files changed, 186 insertions, 14 deletions
diff --git a/FS/FS/discount.pm b/FS/FS/discount.pm index 457c9d681..6771510d0 100644 --- a/FS/FS/discount.pm +++ b/FS/FS/discount.pm @@ -142,7 +142,7 @@ sub description_short { my $conf = new FS::Conf; my $money_char = $conf->config('money_char') || '$'; - my $desc = ''; + my $desc = $self->name ? $self->name.': ' : ''; $desc .= $money_char. sprintf('%.2f/month ', $self->amount) if $self->amount > 0; $desc .= $self->percent. '% ' diff --git a/httemplate/edit/discount.html b/httemplate/edit/discount.html index 24d8fa507..4f440b2cb 100644 --- a/httemplate/edit/discount.html +++ b/httemplate/edit/discount.html @@ -4,6 +4,8 @@ 'fields' => [ 'name', { field => 'disabled', type => 'checkbox', value=>'Y', }, + # a weird kind of false laziness + # w/elements/tr-select-discount.html { field => '_type', type => 'select', options => \@_type_options, onchange => '_type_changed', diff --git a/httemplate/elements/select-discount.html b/httemplate/elements/select-discount.html index e0b6e6cbe..b7f1fa5be 100644 --- a/httemplate/elements/select-discount.html +++ b/httemplate/elements/select-discount.html @@ -1,10 +1,11 @@ <% include( '/elements/select-table.html', - 'table' => 'discount', - 'name_col' => 'description', - 'order_by' => 'ORDER BY discountnum', #XXX weight - 'value' => $discountnum, - 'empty_label' => '(none)', - 'hashref' => { 'disabled' => '' }, + 'table' => 'discount', + 'name_col' => 'description', + 'order_by' => 'ORDER BY discountnum', #XXX weight + 'value' => $discountnum, + 'empty_label' => '(none)', + 'hashref' => { 'disabled' => '' }, + 'post_options' => $post_options, %opt, ) %> @@ -16,5 +17,12 @@ my $discountnum = $opt{'curr_value'} || $opt{'value'}; $opt{'records'} = delete $opt{'discount'} if $opt{'discount'}; +my $curuser = $FS::CurrentUser::CurrentUser; + +#make an opt if we need to turn this off +my $post_options = $curuser->access_right('Custom discount customer package') + ? [ -1 => 'Custom discount' ] + : []; + </%init> diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html index 4d8d9a988..3e25c9f49 100644 --- a/httemplate/elements/select-table.html +++ b/httemplate/elements/select-table.html @@ -31,6 +31,7 @@ Example: #basic params controlling the resulting <SELECT> 'pre_options' => [ 'value' => 'option' ], #before normal options + 'post_options' => [ 'value' => 'option' ], #after normal options 'empty_label' => '', #better specify it though, the default might change 'multiple' => 0, # bool 'disable_empty' => 0, # bool (implied by multiple) @@ -103,6 +104,16 @@ Example: %> % } +% while ( @post_options ) { +% my $post_opt = shift(@post_options); +% my $post_label = shift(@post_options); +% my $selected = ( ref($value) && $value->{$post_opt} ) +% || ( $value eq $post_opt ); + <OPTION VALUE="<% $post_opt %>" + <% $selected ? 'SELECTED' : '' %> + ><% $post_label %> +% } + </SELECT> %} @@ -180,6 +191,7 @@ if ( ref( $value ) eq 'ARRAY' ) { $value = { map { $_ => 1 } @$value }; } -my @pre_options = $opt{pre_options} ? @{ $opt{pre_options} } : (); +my @pre_options = $opt{pre_options} ? @{ $opt{pre_options} } : (); +my @post_options = $opt{post_options} ? @{ $opt{post_options} } : (); </%init> diff --git a/httemplate/elements/tr-input-text.html b/httemplate/elements/tr-input-text.html index 81efa1fe5..21279339e 100644 --- a/httemplate/elements/tr-input-text.html +++ b/httemplate/elements/tr-input-text.html @@ -1,6 +1,6 @@ <% include('tr-td-label.html', @_ ) %> - <TD <% $cell_style %> ID="<% $opt{input_id} || $opt{id}.'_input0' %>"><% include('input-text.html', @_ ) %></TD> + <TD <% $colspan %> <% $cell_style %> ID="<% $opt{input_id} || $opt{id}.'_input0' %>"><% include('input-text.html', @_ ) %></TD> </TR> @@ -10,4 +10,6 @@ my %opt = @_; my $cell_style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : ''; +my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : ''; + </%init> diff --git a/httemplate/elements/tr-select-discount.html b/httemplate/elements/tr-select-discount.html index 4ff8d1357..df221da96 100644 --- a/httemplate/elements/tr-select-discount.html +++ b/httemplate/elements/tr-select-discount.html @@ -1,20 +1,156 @@ -% if ( scalar(@{ $opt{'discount'} }) == 0 ) { +% if ( scalar(@{ $opt{'discount'} }) == 0 +% && ! $curuser->access_right('Custom discount customer package') ) { - <INPUT TYPE="hidden" NAME="<% $opt{'element_name'} || $opt{'field'} || 'discountnum' %>" VALUE=""> + <INPUT TYPE="hidden" NAME="<% $name %>" VALUE="<% $discountnum %>"> % } else { <TR> <TD ALIGN="right"><% $opt{'label'} || '<B>Discount</B>' %></TD> - <TD> + <TD <% $colspan %>> <% include( '/elements/select-discount.html', 'curr_value' => $discountnum, + 'onchange' => $name.'_changed', %opt, ) %> </TD> </TR> +% # a weird kind of false laziness w/edit/discount.html + + <INPUT TYPE="hidden" NAME="<% $name %>_disabled" VALUE="Y"> + + + <% include( '/elements/tr-select.html', + 'label' => '<B>Discount Type</B>', + 'field' => $name. '__type', + 'id' => $name. '__type', + 'options' => \@_type_options, + #XXX 'curr_value' => + 'onchange' => '_type_changed', + 'colspan' => $opt{'colspan'}, + ) + %> + + <% include( '/elements/tr-input-money.html', + 'label' => '<B>Discount Amount</B>', + 'field' => $name. '_amount', + 'id' => $name. '_amount', + 'default' => '0.00', + #XXX 'curr_value' => + 'colspan' => $opt{'colspan'}, + ) + %> + + <% include( '/elements/tr-input-percentage.html', + 'label' => '<B>Discount Percentage</B>', + 'field' => $name. '_percent', + 'id' => $name. '_percent', + 'default' => '0', + #XXX 'curr_value' => + 'colspan' => $opt{'colspan'}, + ) + %> + + <% include( '/elements/tr-input-text.html', + 'label' => '<B>Discount # of Months</B>', + 'field' => $name. '_months', + 'id' => $name. '_months', + 'size' => 2, + 'postfix' => qq(<FONT SIZE="-1" ID="${name}_months_postfix"><I>(blank for non-expiring discount)</I></FONT>), + #XXX 'curr_value' => + 'colspan' => $opt{'colspan'}, + ) + %> + + <SCRIPT TYPE="text/javascript"> + +% my $ge = 'document.getElementById'; + + function <% $name %>_changed(what) { + var <% $name %> = what.options[what.selectedIndex].value; + + if ( <% $name %> == '-1' ) { + <% $ge %>('<% $name %>__type_label0').style.display = ''; + <% $ge %>('<% $name %>__type_label0').style.visibility = ''; + <% $ge %>('<% $name %>__type').style.display = ''; + <% $ge %>('<% $name %>__type').style.visibility = ''; +% #XXX retrieve previous visibility for amount, percent :/ + <% $ge %>('<% $name %>_months_label0').style.display = ''; + <% $ge %>('<% $name %>_months_label0').style.visibility = ''; + <% $ge %>('<% $name %>_months').style.display = ''; + <% $ge %>('<% $name %>_months').style.visibility = ''; + <% $ge %>('<% $name %>_months_postfix').style.display = ''; + <% $ge %>('<% $name %>_months_postfix').style.visibility = ''; + } else { + + <% $ge %>('<% $name %>__type_label0').style.display = 'none'; + <% $ge %>('<% $name %>__type_label0').style.visibility = 'hidden'; + <% $ge %>('<% $name %>__type').style.display = 'none'; + <% $ge %>('<% $name %>__type').style.visibility = 'hidden'; + +% #XXX save visibility settings for amount, percent :/ + <% $ge %>('<% $name %>_amount_label0').style.display = 'none'; + <% $ge %>('<% $name %>_amount_label0').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_amount').style.display = 'none'; + <% $ge %>('<% $name %>_amount').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_amount_input0').style.display = 'none'; + <% $ge %>('<% $name %>_amount_input0').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_percent_label0').style.display = 'none'; + <% $ge %>('<% $name %>_percent_label0').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_percent').style.display = 'none'; + <% $ge %>('<% $name %>_percent').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_percent_input0').style.display = 'none'; + <% $ge %>('<% $name %>_percent_input0').style.visibility = 'hidden'; + + <% $ge %>('<% $name %>_months_label0').style.display = 'none'; + <% $ge %>('<% $name %>_months_label0').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_months').style.display = 'none'; + <% $ge %>('<% $name %>_months').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_months_postfix').style.display = 'none'; + <% $ge %>('<% $name %>_months_postfix').style.visibility = 'hidden'; + + } + + } + + function <% $name %>__type_changed(what) { + var _type = what.options[what.selectedIndex].value; + + if ( <% $name %>__type == '<% $select %>' ) { + <% $ge %>('<% $name %>_amount_label0').style.display = 'none'; + <% $ge %>('<% $name %>_amount_label0').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_amount').style.display = 'none'; + <% $ge %>('<% $name %>_amount').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_percent_label0').style.display = 'none'; + <% $ge %>('<% $name %>_percent_label0').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_percent').style.display = 'none'; + <% $ge %>('<% $name %>_percent').style.visibility = 'hidden'; + } else if ( <% $name %>__type == 'Amount' ) { + <% $ge %>('<% $name %>_amount_label0').style.display = ''; + <% $ge %>('<% $name %>_amount_label0').style.visibility = ''; + <% $ge %>('<% $name %>_amount').style.display = ''; + <% $ge %>('<% $name %>_amount').style.visibility = ''; + <% $ge %>('<% $name %>_percent_label0').style.display = 'none'; + <% $ge %>('<% $name %>_percent_label0').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_percent').style.display = 'none'; + <% $ge %>('<% $name %>_percent').style.visibility = 'hidden'; + } else if ( <% $name %>__type == 'Percentage' ) { + <% $ge %>('<% $name %>_amount_label0').style.display = 'none'; + <% $ge %>('<% $name %>_amount_label0').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_amount').style.display = 'none'; + <% $ge %>('<% $name %>_amount').style.visibility = 'hidden'; + <% $ge %>('<% $name %>_percent_label0').style.display = ''; + <% $ge %>('<% $name %>_percent_label0').style.visibility = ''; + <% $ge %>('<% $name %>_percent').style.display = ''; + <% $ge %>('<% $name %>_percent').style.visibility = ''; + } + + } + + </SCRIPT> + % } <%init> @@ -23,5 +159,15 @@ my $discountnum = $opt{'curr_value'} || $opt{'value'}; $opt{'discount'} ||= [ qsearch( 'discount', { disabled=>'' } ) ]; -</%init> +my $curuser = $FS::CurrentUser::CurrentUser; + +my $name = $opt{'element_name'} || $opt{'field'} || 'discountnum'; + +my $select = 'Select discount type'; +my @_type_options = ( 'Amount', 'Percentage' ); +unshift @_type_options, $select; + +my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : ''; + +</%init> diff --git a/httemplate/elements/tr-select.html b/httemplate/elements/tr-select.html index 07b0a01d5..f9d54f118 100644 --- a/httemplate/elements/tr-select.html +++ b/httemplate/elements/tr-select.html @@ -1,6 +1,6 @@ <% include('tr-td-label.html', @_ ) %> - <TD <% $style %>> + <TD <% $colspan %> <% $style %>> <SELECT NAME = "<% $opt{field} %>" ID = "<% $opt{id} %>" @@ -58,4 +58,6 @@ my $style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : ''; my $curr_value = $opt{'curr_value'}; +my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : ''; + </%init> |