From: ivan Date: Thu, 4 Feb 2010 20:39:56 +0000 (+0000) Subject: discounts, RT#6679 X-Git-Tag: root_of_svc_elec_features~487 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=4cacb3fa439b56fc7c9a742b69ec3f6ffd660433 discounts, RT#6679 --- 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' ] + : []; + 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 %} @@ -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} } : (); 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', @_ ) %> - ID="<% $opt{input_id} || $opt{id}.'_input0' %>"><% include('input-text.html', @_ ) %> + <% $cell_style %> ID="<% $opt{input_id} || $opt{id}.'_input0' %>"><% include('input-text.html', @_ ) %> @@ -10,4 +10,6 @@ my %opt = @_; my $cell_style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : ''; +my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : ''; + 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') ) { - + % } else { <% $opt{'label'} || 'Discount' %> - + > <% include( '/elements/select-discount.html', 'curr_value' => $discountnum, + 'onchange' => $name.'_changed', %opt, ) %> +% # a weird kind of false laziness w/edit/discount.html + + + + + <% include( '/elements/tr-select.html', + 'label' => 'Discount Type', + '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' => 'Discount Amount', + 'field' => $name. '_amount', + 'id' => $name. '_amount', + 'default' => '0.00', + #XXX 'curr_value' => + 'colspan' => $opt{'colspan'}, + ) + %> + + <% include( '/elements/tr-input-percentage.html', + 'label' => 'Discount Percentage', + 'field' => $name. '_percent', + 'id' => $name. '_percent', + 'default' => '0', + #XXX 'curr_value' => + 'colspan' => $opt{'colspan'}, + ) + %> + + <% include( '/elements/tr-input-text.html', + 'label' => 'Discount # of Months', + 'field' => $name. '_months', + 'id' => $name. '_months', + 'size' => 2, + 'postfix' => qq((blank for non-expiring discount)), + #XXX 'curr_value' => + 'colspan' => $opt{'colspan'}, + ) + %> + + + % } <%init> @@ -23,5 +159,15 @@ my $discountnum = $opt{'curr_value'} || $opt{'value'}; $opt{'discount'} ||= [ qsearch( 'discount', { disabled=>'' } ) ]; - +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'}.'"' : ''; + + 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', @_ ) %> - > + <% $style %>>