5 include( '/elements/tr-select-reason.html',
8 'field' => 'reasonnum',
9 'reason_class' => 'C', # currently 'C', 'R', or 'S'
10 # for cancel, credit, or suspend
13 'cgi' => $cgi, #easiest way for things to be properly "sticky" on errors
16 'control_button' => 'element_name', #button to be enabled when a reason is
20 #deprecated ways to keep things "sticky" on errors
21 # (requires duplicate code in each using file to parse cgi params)
22 'curr_value' => $curr_value,
24 'typenum' => $typenum,
32 <SCRIPT TYPE="text/javascript">
33 function sh_add<% $func_suffix %>()
35 var hints = <% encode_json(\@hints) %>;
36 var select_reason = document.getElementById('<% $id %>');
38 % if ( $class eq 'S' ) {
39 document.getElementById('<% $id %>_hint').innerHTML =
40 hints[select_reason.selectedIndex];
43 if (select_reason.selectedIndex == 0){
44 <% $controlledbutton ? $controlledbutton.'.disabled = true;' : ';' %>
46 <% $controlledbutton ? $controlledbutton.'.disabled = false;' : ';' %>
49 %if ($curuser->access_right($add_access_right)){
51 if (select_reason.selectedIndex ==
52 (select_reason.length - 1)) {
53 document.getElementById('new<% $id %>').disabled = false;
54 document.getElementById('new<% $id %>').style.display = 'inline';
55 document.getElementById('new<% $id %>Label').style.display = 'inline';
56 document.getElementById('new<% $id %>T').disabled = false;
57 document.getElementById('new<% $id %>T').style.display = 'inline';
58 document.getElementById('new<% $id %>TLabel').style.display = 'inline';
60 document.getElementById('new<% $id %>').disabled = true;
61 document.getElementById('new<% $id %>').style.display = 'none';
62 document.getElementById('new<% $id %>Label').style.display = 'none';
63 document.getElementById('new<% $id %>T').disabled = true;
64 document.getElementById('new<% $id %>T').style.display = 'none';
65 document.getElementById('new<% $id %>TLabel').style.display = 'none';
74 <TD ALIGN="right"><% mt('Reason') |h %></TD>
76 <SELECT id="<% $id %>" name="<% $name %>" onFocus="sh_add<% $func_suffix %>()" onChange="sh_add<% $func_suffix %>()">
77 <OPTION VALUE="" <% ($init_reason eq '') ? 'SELECTED' : '' %>><% mt('Select Reason...') |h %></OPTION>
78 % foreach my $reason (@reasons) {
79 <OPTION VALUE="<% $reason->reasonnum %>" <% ($init_reason == $reason->reasonnum) ? 'SELECTED' : '' %>><% $reason->reasontype->type %> : <% $reason->reason %></OPTION>
81 % if ($curuser->access_right($add_access_right)) {
82 <OPTION VALUE="-1" <% ($init_reason == -1) ? 'SELECTED' : '' %>><% mt('Add new reason') |h %></OPTION>
89 % my @types = qsearch( 'reason_type', { 'class' => $class } );
90 % if (scalar(@types) < 1) { # we should never reach this
93 <P><% mt('No reason types. Please add some.') |h %></P>
96 % }elsif (scalar(@types) == 1) {
99 <P id="new<% $name %>TLabel" style="display:<% $display %>"><% mt('Reason Type') |h %></P>
102 <P id="new<% $name %>T" disabled="<% $disabled %>" style="display:<% $display %>"><% $types[0]->type %>
103 <INPUT type="hidden" name="new<% $name %>T" value="<% $types[0]->typenum %>">
111 <P id="new<% $id %>TLabel" style="display:<% $display %>"><% mt('Reason Type') |h %></P>
114 <SELECT id="new<% $id %>T" name="new<% $name %>T" "<% $disabled %>" style="display:<% $display %>">
115 % for my $type (@types) {
116 <OPTION VALUE="<% $type->typenum %>" <% ($init_type == $type->typenum) ? 'SELECTED' : '' %>><% $type->type %></OPTION>
123 % if ( $class eq 'S' ) {
125 <TD COLSPAN=2 ALIGN="center" id="<% $id %>_hint">
132 <P id="new<% $id %>Label" style="display:<% $display %>"><% mt('New Reason') |h %></P>
134 <TD><INPUT id="new<% $id %>" name="new<% $name %>" type="text" value="<% $init_newreason |h %>" "<% $disabled %>" style="display:<% $display %>"></TD>
141 my $name = $opt{'field'};
142 my $class = $opt{'reason_class'};
146 $init_reason = $opt{'cgi'}->param($name);
148 $init_reason = $opt{'curr_value'};
151 my $controlledbutton = $opt{'control_button'};
153 ( my $func_suffix = $name ) =~ s/\./_/g;
155 my $id = $opt{'id'} || $func_suffix;
157 my $add_access_right;
159 $add_access_right = 'Add on-the-fly cancel reason';
160 } elsif ($class eq 'S') {
161 $add_access_right = 'Add on-the-fly suspend reason';
162 } elsif ($class eq 'R') {
163 $add_access_right = 'Add on-the-fly credit reason';
165 die "illegal class: $class";
168 my( $display, $disabled ) = ( 'none', 'DISABLED' );
169 my( $init_type, $init_newreason ) = ( '', '' );
170 if ($init_reason == -1 || ref($init_reason) ) {
175 if ( ref($init_reason) ) {
176 $init_type = $init_reason->{'typenum'};
177 $init_newreason = $init_reason->{'reason'};
179 } elsif ( $opt{'cgi'} ) {
180 $init_type = $opt{'cgi'}->param( "new${name}T" );
181 $init_newreason = $opt{'cgi'}->param( "new$name" );
187 "WHERE class = '$class' and (disabled = '' OR disabled is NULL)";
189 my @reasons = qsearch({
192 extra_sql => $extra_sql,
193 addl_from => 'LEFT JOIN reason_type '.
194 ' ON reason_type.typenum = reason.reason_type',
195 order_by => 'ORDER BY reason_type.type ASC, reason.reason ASC',
199 if ( $class eq 'S' ) {
200 my $conf = FS::Conf->new;
202 foreach my $reason (@reasons) {
203 if ( $reason->unsuspend_pkgpart ) {
204 my $part_pkg = FS::part_pkg->by_key($reason->unsuspend_pkgpart);
206 if ( $part_pkg->option('setup_fee',1) > 0 and
207 $part_pkg->option('recur_fee',1) == 0 ) {
210 mt('A [_1] unsuspension fee will apply.',
211 ($conf->config('money_char') || '$') .
212 sprintf('%.2f', $part_pkg->option('setup_fee'))
215 # oddball cases--not really supported
217 mt('An unsuspension package will apply: [_1]',
218 $part_pkg->price_info
221 } else { #no $part_pkg
223 '<FONT COLOR="#ff0000">Unsuspend pkg #'.$reason->unsuspend_pkgpart.
224 ' not found.</FONT>';
226 } else { #no unsuspend_pkgpart
230 push @hints, ''; # for the "new reason" case
231 @hints = map {'<FONT SIZE="-1">'.$_.'</FONT>'} @hints;
235 my $curuser = $FS::CurrentUser::CurrentUser;