1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
<%doc>
Example:
include( '/elements/tr-select-reason.html',
#required
'field' => 'reasonnum',
'reason_class' => 'C', # currently 'C', 'R', 'F', or 'S'
# for cancel, credit, refund, or suspend
#recommended
'cgi' => $cgi, #easiest way for things to be properly "sticky" on errors
#optional
'control_button' => 'element_name', #button to be enabled when a reason is
#selected
'id' => 'element_id',
#deprecated ways to keep things "sticky" on errors
# (requires duplicate code in each using file to parse cgi params)
'curr_value' => $curr_value,
'curr_value' => {
'typenum' => $typenum,
'reason' => $reason,
},
)
</%doc>
<SCRIPT TYPE="text/javascript">
function sh_add<% $func_suffix %>()
{
var hints = <% encode_json(\@hints) %>;
var select_reason = document.getElementById('<% $id %>');
% if ( $class eq 'S' ) {
document.getElementById('<% $id %>_hint').innerHTML =
hints[select_reason.selectedIndex];
% }
if (select_reason.selectedIndex == 0){
<% $controlledbutton ? $controlledbutton.'.disabled = true;' : ';' %>
}else{
<% $controlledbutton ? $controlledbutton.'.disabled = false;' : ';' %>
}
%if ($curuser->access_right($add_access_right)){
if (select_reason.selectedIndex ==
(select_reason.length - 1)) {
document.getElementById('new<% $id %>').disabled = false;
document.getElementById('new<% $id %>').style.display = 'inline';
document.getElementById('new<% $id %>Label').style.display = 'inline';
document.getElementById('new<% $id %>T').disabled = false;
document.getElementById('new<% $id %>T').style.display = 'inline';
document.getElementById('new<% $id %>TLabel').style.display = 'inline';
} else {
document.getElementById('new<% $id %>').disabled = true;
document.getElementById('new<% $id %>').style.display = 'none';
document.getElementById('new<% $id %>Label').style.display = 'none';
document.getElementById('new<% $id %>T').disabled = true;
document.getElementById('new<% $id %>T').style.display = 'none';
document.getElementById('new<% $id %>TLabel').style.display = 'none';
}
%}
}
</SCRIPT>
<TR>
<TD ALIGN="right"><% mt('Reason') |h %></TD>
<TD>
<SELECT id="<% $id %>" name="<% $name %>" onFocus="sh_add<% $func_suffix %>()" onChange="sh_add<% $func_suffix %>()">
<OPTION VALUE="" <% ($init_reason eq '') ? 'SELECTED' : '' %>><% mt('Select Reason...') |h %></OPTION>
% foreach my $reason (@reasons) {
<OPTION VALUE="<% $reason->reasonnum %>" <% ($init_reason == $reason->reasonnum) ? 'SELECTED' : '' %>><% $reason->reasontype->type %> : <% $reason->reason %></OPTION>
% }
% if ($curuser->access_right($add_access_right)) {
<OPTION VALUE="-1" <% ($init_reason == -1) ? 'SELECTED' : '' %>><% mt('Add new reason') |h %></OPTION>
% }
%
</SELECT>
</TD>
</TR>
% my @types = qsearch( 'reason_type', { 'class' => $class } );
% if (scalar(@types) < 1) { # we should never reach this
<TR>
<TD ALIGN="right">
<P><% mt('No reason types. Please add some.') |h %></P>
</TD>
</TR>
% }elsif (scalar(@types) == 1) {
<TR>
<TD ALIGN="right">
<P id="new<% $name %>TLabel" style="display:<% $display %>"><% mt('Reason Type') |h %></P>
</TD>
<TD>
<P id="new<% $name %>T" disabled="<% $disabled %>" style="display:<% $display %>"><% $types[0]->type %>
<INPUT type="hidden" name="new<% $name %>T" value="<% $types[0]->typenum %>">
</TD>
</TR>
% }else{
<TR>
<TD ALIGN="right">
<P id="new<% $id %>TLabel" style="display:<% $display %>"><% mt('Reason Type') |h %></P>
</TD>
<TD>
<SELECT id="new<% $id %>T" name="new<% $name %>T" "<% $disabled %>" style="display:<% $display %>">
% for my $type (@types) {
<OPTION VALUE="<% $type->typenum %>" <% ($init_type == $type->typenum) ? 'SELECTED' : '' %>><% $type->type %></OPTION>
% }
</SELECT>
</TD>
</TR>
% }
% if ( $class eq 'S' ) {
<TR>
<TD COLSPAN=2 ALIGN="center" id="<% $id %>_hint">
</TD>
</TR>
% }
<TR>
<TD ALIGN="right">
<P id="new<% $id %>Label" style="display:<% $display %>"><% mt('New Reason') |h %></P>
</TD>
<TD><INPUT id="new<% $id %>" name="new<% $name %>" type="text" value="<% $init_newreason |h %>" "<% $disabled %>" style="display:<% $display %>"></TD>
</TR>
<%init>
my %opt = @_;
my $name = $opt{'field'};
my $class = $opt{'reason_class'};
my $init_reason;
if ( $opt{'cgi'} ) {
$init_reason = $opt{'cgi'}->param($name);
} else {
$init_reason = $opt{'curr_value'};
}
my $controlledbutton = $opt{'control_button'};
( my $func_suffix = $name ) =~ s/\./_/g;
my $id = $opt{'id'} || $func_suffix;
my $add_access_right;
if ($class eq 'C') {
$add_access_right = 'Add on-the-fly cancel reason';
} elsif ($class eq 'S') {
$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';
} 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',
});
my @hints;
if ( $class eq 'S' ) {
my $conf = FS::Conf->new;
@hints = ( '' );
foreach my $reason (@reasons) {
if ( $reason->unsuspend_pkgpart ) {
my $part_pkg = FS::part_pkg->by_key($reason->unsuspend_pkgpart);
if ( $part_pkg ) {
if ( $part_pkg->option('setup_fee',1) > 0 and
$part_pkg->option('recur_fee',1) == 0 ) {
# the usual case
push @hints,
mt('A [_1] unsuspension fee will apply.',
($conf->config('money_char') || '$') .
sprintf('%.2f', $part_pkg->option('setup_fee'))
);
} else {
# oddball cases--not really supported
push @hints,
mt('An unsuspension package will apply: [_1]',
$part_pkg->price_info
);
}
} else { #no $part_pkg
push @hints,
'<FONT COLOR="#ff0000">Unsuspend pkg #'.$reason->unsuspend_pkgpart.
' not found.</FONT>';
}
} else { #no unsuspend_pkgpart
push @hints, '';
}
}
push @hints, ''; # for the "new reason" case
@hints = map {'<FONT SIZE="-1">'.$_.'</FONT>'} @hints;
}
my $curuser = $FS::CurrentUser::CurrentUser;
</%init>
|