X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Ftr-select-reason.html;h=35659755367a88a677a7b689c1a50b2e8b361427;hb=251d07aa41b6830a0a2f2a51c14fa94586d843c2;hp=9a670a26b50f91cba6b3a0c08d8398eb847ccb8d;hpb=57e56b312682dbca92ae1b0c994091f7da17f0b1;p=freeside.git diff --git a/httemplate/elements/tr-select-reason.html b/httemplate/elements/tr-select-reason.html index 9a670a26b..356597553 100755 --- a/httemplate/elements/tr-select-reason.html +++ b/httemplate/elements/tr-select-reason.html @@ -6,8 +6,8 @@ Example: #required 'field' => 'reasonnum', - 'reason_class' => 'C', # currently 'C', 'R', or 'S' - # for cancel, credit, or suspend + 'reason_class' => 'C', # currently 'C', 'R', 'F', 'S' or 'X' + # for cancel, credit, refund, suspend or void credit #recommended 'cgi' => $cgi, #easiest way for things to be properly "sticky" on errors @@ -29,113 +29,126 @@ Example: +% # note style improvements. +% # - no more conditionally included code here +% # - callers are not expected to pass javascript fragments +% # - no redundant checking of ACLs or parameters +% # - form fields are grouped for easy management +% # - use the standard select-table widget instead of ad hoc crap - - <% mt('Reason') |h %> - - - - +%# sadly can't just use add_inline here, as we have non-text fields +<& tr-select-table.html, + 'label' => 'Reason', + 'field' => $name, + 'id' => $id, + 'table' => 'reason', + 'records' => \@reasons, + 'label_callback' => sub { my $reason = shift; + $reason->type . ' : ' . $reason->reason }, + 'disable_empty' => 1, + 'pre_options' => [ 0 => 'Select reason...' ], + 'post_options' => \@post_options, + 'curr_value' => $init_reason, + 'onchange' => $id.'_changed()', +&> + +% # "add new reason" fields +% # should be a
, but that doesn't fit well into the table + +% if ( $curuser->access_right($add_access_right) ) { + + + + + <& tr-input-text.html, + label => 'New reason', + field => $id.'_new_reason' + &> % my @types = qsearch( 'reason_type', { 'class' => $class } ); % if (scalar(@types) < 1) { # we should never reach this - - - -% }elsif (scalar(@types) == 1) { - - - - - -% }else{ - - - - - + + + +% } elsif (scalar(@types) == 1) { + <& tr-fixed.html, + label => 'Reason type', + field => $id.'_new_reason_type', + curr_value => $types[0]->typenum, + formatted_value => $types[0]->type, + &> +% } else { # more than one type, the normal case + <& tr-select-table.html, + label => 'Reason type', + field => $id.'_new_reason_type', + table => 'reason_type', + name_col => 'type', + hashref => { 'class' => $class }, + disable_empty => 1, + &> +% } # scalar(@types) + +% if ( $class eq 'S' ) { + <& tr-checkbox.html, + label => 'Credit the unused portion of service when suspending', + field => $id.'_new_unused_credit', + value => 'Y' + &> + <& tr-select-part_pkg.html, + label => 'Charge this fee when unsuspending', + field => $id.'_new_unsuspend_pkgpart', + hashref => { disabled => '', freq => '0' }, + empty_label => 'none', + &> + <& tr-checkbox.html, + label => 'Hold unsuspension fee until the next bill', + field => $id.'_new_unsuspend_hold', + value => 'Y', + &> % } +
-

<% mt('No reason types. Please add some.') |h %>

-
-

<% mt('Reason Type') |h %>

-
-

<% $types[0]->type %> - -

-

<% mt('Reason Type') |h %>

-
- -
+

<% mt('No reason types. Please add some.') |h %>

+
+ + +% } # if the current user can add a reason -% if ( $class eq 'S' ) { +% # container for hints - + -% } - - - -

<% mt('New Reason') |h %>

- - " style="display:<% $display %>"> - <%init> +my $curuser = $FS::CurrentUser::CurrentUser; my %opt = @_; my $name = $opt{'field'}; @@ -148,11 +161,8 @@ if ( $opt{'cgi'} ) { $init_reason = $opt{'curr_value'}; } -my $controlledbutton = $opt{'control_button'}; - -( my $func_suffix = $name ) =~ s/\./_/g; - -my $id = $opt{'id'} || $func_suffix; +my $id = $opt{'id'} || $name; +$id =~ s/\./_/g; # for edit/part_event my $add_access_right; if ($class eq 'C') { @@ -161,45 +171,29 @@ if ($class eq 'C') { $add_access_right = 'Add on-the-fly suspend reason'; } elsif ($class eq 'R') { $add_access_right = 'Add on-the-fly credit reason'; +} elsif ($class eq 'F') { + $add_access_right = 'Add on-the-fly refund reason'; +} elsif ($class eq 'X') { + $add_access_right = 'Add on-the-fly void credit reason'; } else { die "illegal class: $class"; } -my( $display, $disabled ) = ( 'none', 'DISABLED' ); -my( $init_type, $init_newreason ) = ( '', '' ); -if ($init_reason == -1 || ref($init_reason) ) { - - $display = 'inline'; - $disabled = ''; - - if ( ref($init_reason) ) { - $init_type = $init_reason->{'typenum'}; - $init_newreason = $init_reason->{'reason'}; - $init_reason = -1; - } elsif ( $opt{'cgi'} ) { - $init_type = $opt{'cgi'}->param( "new${name}T" ); - $init_newreason = $opt{'cgi'}->param( "new$name" ); - } - -} - -my $extra_sql = - "WHERE class = '$class' and (disabled = '' OR disabled is NULL)"; - my @reasons = qsearch({ - table => 'reason', - hashref => {}, - extra_sql => $extra_sql, - addl_from => 'LEFT JOIN reason_type '. - ' ON reason_type.typenum = reason.reason_type', - order_by => 'ORDER BY reason_type.type ASC, reason.reason ASC', + 'table' => 'reason', + 'addl_from' => ' LEFT JOIN reason_type'. + ' ON (reason.reason_type = reason_type.typenum)', + 'hashref' => { disabled => '' }, + 'extra_sql' => " AND reason_type.class = '$class'", + 'order_by' => ' ORDER BY type, reason', }); -my @hints; +my %all_hints; if ( $class eq 'S' ) { my $conf = FS::Conf->new; - @hints = ( '' ); + %all_hints = ( 0 => '', -1 => '' ); foreach my $reason (@reasons) { + my @hints; if ( $reason->unsuspend_pkgpart ) { my $part_pkg = FS::part_pkg->by_key($reason->unsuspend_pkgpart); if ( $part_pkg ) { @@ -223,15 +217,17 @@ if ( $class eq 'S' ) { 'Unsuspend pkg #'.$reason->unsuspend_pkgpart. ' not found.'; } - } else { #no unsuspend_pkgpart - push @hints, ''; } + if ( $reason->unused_credit ) { + push @hints, mt('The customer will be credited for unused time.'); + } + $all_hints{ $reason->reasonnum } = join('
', @hints); } - push @hints, ''; # for the "new reason" case - @hints = map {''.$_.''} @hints; } - -my $curuser = $FS::CurrentUser::CurrentUser; +my @post_options; +if ( $curuser->access_right($add_access_right) ) { + @post_options = ( -1 => 'Add new reason' ); +}