diff options
author | ivan <ivan> | 2010-01-30 07:38:32 +0000 |
---|---|---|
committer | ivan <ivan> | 2010-01-30 07:38:32 +0000 |
commit | 0fcdc36642e1430f02ebf5326740e231883bd41f (patch) | |
tree | e5633883c65370134141202c40c616d35481d434 /httemplate/edit | |
parent | 11b586f0fad8164514d272cee321e12bde6a49ef (diff) |
discounts, RT#6679
Diffstat (limited to 'httemplate/edit')
-rw-r--r-- | httemplate/edit/discount.html | 137 | ||||
-rw-r--r-- | httemplate/edit/elements/edit.html | 3 | ||||
-rw-r--r-- | httemplate/edit/process/discount.html | 28 |
3 files changed, 167 insertions, 1 deletions
diff --git a/httemplate/edit/discount.html b/httemplate/edit/discount.html new file mode 100644 index 000000000..24d8fa507 --- /dev/null +++ b/httemplate/edit/discount.html @@ -0,0 +1,137 @@ +<% include( 'elements/edit.html', + 'name' => 'Discount', + 'table' => 'discount', + 'fields' => [ + 'name', + { field => 'disabled', type => 'checkbox', value=>'Y', }, + { field => '_type', type => 'select', + options => \@_type_options, + onchange => '_type_changed', + }, + { field => 'amount', type => 'money', + default => '0.00', + #cell_style => $amount_style, + }, + { field => 'percent', type => 'percentage', + default => 0, + #cell_style => $percent_style, + }, + { field => 'months', type => 'text', size => 2, + postfix => '<BR><FONT SIZE="-1"><I>(blank for non-expiring discount)</I></FONT>', + }, + ], + 'labels' => { + 'discountnum' => 'Discount #', + 'name' => 'Name ', + 'disabled' => 'Disabled ', + '_type' => 'Type ', + 'amount' => 'Amount ', + 'percent' => 'Percentage ', + 'months' => '# of Months', + }, + 'viewall_dir' => 'browse', + 'new_callback' => $new_callback, + 'edit_callback' => $edit_callback, + 'error_callback' => $error_callback, + 'html_init' => $javascript, + 'body_etc' => 'onLoad="_type_changed(document.edit_topform._type)"', + ) +%> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my @_type_options = ( 'Amount', 'Percentage' ); + +#my $amount_style = ''; +#my $percent_style = ''; + +#my $hide = 'display:none;visibility:hidden'; +my $select = 'Select discount type'; + +my $new_callback = sub { + #my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; + + #$amount_style = $hide; + #$percent_style = $hide; + unshift @_type_options, $select; +}; + +my $edit_callback = sub { + #my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; + my( $cgi, $object ) = @_; + + if ( $object->amount > 0 && $object->percent == 0 ) { + $object->set('_type', 'Amount'); + #$percent_style = $hide; + } elsif ( $object->amount == 0 && $object->percent > 0 ) { + $object->set('_type', 'Percentage'); + #$amount_style = $hide; + } elsif ( $object->amount == 0 && $object->percent == 0 ) { + #$amount_style = $hide; + #$percent_style = $hide; + unshift @_type_options, $select; + } else { + die "discount.amount and discount.percent not yet handled by web UI"; + } + +}; + +my $error_callback = sub { + #my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; + my( $cgi, $object ) = @_; + + if ( $cgi->param('_type') eq 'Amount' ) { + $object->set('_type', 'Amount'); + #A$percent_style = $hide; + } elsif ( $cgi->param('_type') eq 'Percentage' ) { + $object->set('_type', 'Percentage'); + #$amount_style = $hide; + } else { + #$amount_style = $hide; + #$percent_style = $hide; + unshift @_type_options, $select; + } + +}; + +my $javascript = <<END; + <SCRIPT TYPE="text/javascript"> + function _type_changed(what) { + var _type = what.options[what.selectedIndex].value; + + if ( _type == '$select' ) { + document.getElementById('amount_label').style.display = 'none'; + document.getElementById('amount_label').style.visibility = 'hidden'; + document.getElementById('amount_input0').style.display = 'none'; + document.getElementById('amount_input0').style.visibility = 'hidden'; + document.getElementById('percent_label').style.display = 'none'; + document.getElementById('percent_label').style.visibility = 'hidden'; + document.getElementById('percent_input0').style.display = 'none'; + document.getElementById('percent_input0').style.visibility = 'hidden'; + } else if ( _type == 'Amount' ) { + document.getElementById('amount_label').style.display = ''; + document.getElementById('amount_label').style.visibility = ''; + document.getElementById('amount_input0').style.display = ''; + document.getElementById('amount_input0').style.visibility = ''; + document.getElementById('percent_label').style.display = 'none'; + document.getElementById('percent_label').style.visibility = 'hidden'; + document.getElementById('percent_input0').style.display = 'none'; + document.getElementById('percent_input0').style.visibility = 'hidden'; + } else if ( _type == 'Percentage' ) { + document.getElementById('amount_label').style.display = 'none'; + document.getElementById('amount_label').style.visibility = 'hidden'; + document.getElementById('amount_input0').style.display = 'none'; + document.getElementById('amount_input0').style.visibility = 'hidden'; + document.getElementById('percent_label').style.display = ''; + document.getElementById('percent_label').style.visibility = ''; + document.getElementById('percent_input0').style.display = ''; + document.getElementById('percent_input0').style.visibility = ''; + } + + } + </SCRIPT> +END + +</%init> diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 4fe32c15d..3e8b6b8ed 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -250,6 +250,7 @@ Example: % #text and derivitives % 'size' => $f->{'size'}, % 'maxlength' => $f->{'maxlength'}, +% 'postfix' => $f->{'postfix'}, % % #checkbox, title, fixed, hidden % #& deprecated weird value hashref used only by reason.html @@ -372,7 +373,7 @@ Example: % $table = $f->{'m2name_table'}; % $col = $f->{'m2name_namecol'}; % } elsif ( $f->{'o2m_table'} ) { -% $table = $f->{'o2m_table'}; +% $table = $f->{'o2m_tbekable'}; % $col = dbdef->table($f->{'o2m_table'})->primary_key; % } elsif ( $f->{'m2m_method'} ) { % $table = $f->{'m2m_method'}; diff --git a/httemplate/edit/process/discount.html b/httemplate/edit/process/discount.html new file mode 100644 index 000000000..54307b708 --- /dev/null +++ b/httemplate/edit/process/discount.html @@ -0,0 +1,28 @@ +<% include( 'elements/process.html', + 'table' => 'discount', + 'viewall_dir' => 'browse', + 'precheck_callback' => $precheck_callback, + ) +%> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $precheck_callback = sub { + my( $cgi ) = @_; + + if ( $cgi->param('_type') eq 'Select discount type' ) { + return 'Please select a discount type'; + } elsif ( $cgi->param('_type') eq 'Amount' ) { + $cgi->param('percent', '0'); + return 'Amount must be greater than 0' unless $cgi->param('amount') > 0; + } elsif ( $cgi->param('_type') eq 'Percentage' ) { + $cgi->param('amount', '0.00'); + return 'Percentage must be greater than 0' unless $cgi->param('percent') > 0; + } + + ''; +}; + +</%init> |