4 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
5 $cgi->param('clone', $1);
7 $cgi->param('clone', '');
9 if ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
10 $cgi->param('pkgnum', $1);
12 $cgi->param('pkgnum', '');
15 my ($query) = $cgi->keywords;
18 if ( $cgi->param('error') ) {
19 $part_pkg = new FS::part_pkg ( {
20 map { $_, scalar($cgi->param($_)) } fields('part_pkg')
23 my $clone_part_pkg = '';
24 if ( $cgi->param('clone') ) {
25 $action = 'Custom Pricing';
26 $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
27 $part_pkg ||= $clone_part_pkg->clone;
28 $part_pkg->disabled('Y');
29 } elsif ( $query && $query =~ /^(\d+)$/ ) {
30 $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
32 unless ( $part_pkg ) {
33 $part_pkg = new FS::part_pkg {};
34 $part_pkg->plan('flat');
37 unless ( $part_pkg->plan ) { #backwards-compat
38 $part_pkg->plan('flat');
39 $part_pkg->plandata("setup_fee=". $part_pkg->setup. "\n".
40 "recur_fee=". $part_pkg->recur. "\n");
42 $action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
43 my $hashref = $part_pkg->hashref;
47 <%= header("$action Package Definition", menubar(
48 'Main Menu' => popurl(2),
49 'View all packages' => popurl(2). 'browse/part_pkg.cgi',
52 <% #), ' onLoad="visualize()"'); %>
54 <% if ( $cgi->param('error') ) { %>
55 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
58 <% #print '<FORM ACTION="', popurl(1), 'process/part_pkg.cgi" METHOD=POST>'; %>
63 #if ( $cgi->param('clone') ) {
64 # print qq!<INPUT TYPE="hidden" NAME="clone" VALUE="!, $cgi->param('clone'), qq!">!;
66 #if ( $cgi->param('pkgnum') ) {
67 # print qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="!, $cgi->param('pkgnum'), qq!">!;
70 #print qq!<INPUT TYPE="hidden" NAME="pkgpart" VALUE="$hashref->{pkgpart}">!,
73 <%= itable('',8,1) %><TR><TD VALIGN="top">
77 <%= ntable("#cccccc",2) %>
79 <TD ALIGN="right">Package Definition #</TD>
80 <TD BGCOLOR="#ffffff">
81 <%= $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)" %>
85 <TD ALIGN="right">Package (customer-visible)</TD>
87 <INPUT TYPE="text" NAME="pkg" SIZE=32 VALUE="<%= $part_pkg->pkg %>">
91 <TD ALIGN="right">Comment (customer-hidden)</TD>
93 <INPUT TYPE="text" NAME="comment" SIZE=32 VALUE="<%=$part_pkg->comment%>">
97 <TD ALIGN="right">Promotional code</TD>
99 <INPUT TYPE="text" NAME="promo_code" SIZE=32 VALUE="<%=$part_pkg->promo_code%>">
103 <TD ALIGN="right">Disable new orders</TD>
105 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<%= $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>
111 </TD><TD VALIGN="top">
114 <%= ntable("#cccccc", 2) %>
116 <TD ALIGN="right">Setup fee tax exempt</TD>
120 print '<INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y"';
121 print ' CHECKED' if $hashref->{setuptax} eq "Y";
126 <TR><TD ALIGN="right">Recurring fee tax exempt</TD><TD>
129 print '<INPUT TYPE="checkbox" NAME="recurtax" VALUE="Y"';
130 print ' CHECKED' if $hashref->{recurtax} eq "Y";
135 my $conf = new FS::Conf;
136 #false laziness w/ view/cust_main.cgi quick order
137 if ( $conf->exists('enable_taxclasses') ) {
138 print '<TR><TD ALIGN="right">Tax class</TD><TD><SELECT NAME="taxclass">';
139 my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
141 $sth->execute or die $sth->errstr;
142 foreach my $taxclass ( map $_->[0], @{$sth->fetchall_arrayref} ) {
143 print qq!<OPTION VALUE="$taxclass"!;
144 print ' SELECTED' if $taxclass eq $hashref->{taxclass};
145 print qq!>$taxclass</OPTION>!;
147 print '</SELECT></TD></TR>';
150 '<INPUT TYPE="hidden" NAME="taxclass" VALUE="'. $hashref->{taxclass}. '">';
161 my $thead = "\n\n". ntable('#cccccc', 2).
162 '<TR><TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Quan.</FONT></TH>';
163 $thead .= '<TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Primary</FONT></TH>'
164 if dbdef->table('pkg_svc')->column('primary_svc');
165 $thead .= '<TH BGCOLOR="#dcdcdc">Service</TH></TR>';
167 #unless ( $cgi->param('clone') ) {
170 #print <<END, $thead;
171 print <<END, itable('', 4, 1), '<TR><TD VALIGN="top">', $thead;
172 <BR><BR>Services included
179 my @part_svc = qsearch( 'part_svc', { 'disabled' => '' } );
180 foreach my $part_svc ( @part_svc ) {
181 my $svcpart = $part_svc->svcpart;
182 my $pkgpart = $cgi->param('clone') || $part_pkg->pkgpart;
183 my $pkg_svc = $pkgpart && qsearchs( 'pkg_svc', {
184 'pkgpart' => $pkgpart,
185 'svcpart' => $svcpart,
186 } ) || new FS::pkg_svc ( {
187 'pkgpart' => $pkgpart,
188 'svcpart' => $svcpart,
192 #? #next unless $pkg_svc;
194 push @fixups, "pkg_svc$svcpart";
196 #unless ( defined ($cgi->param('clone')) && $cgi->param('clone') ) {
199 print '<TR>'; # if $count == 0 ;
200 print qq!<TD><INPUT TYPE="text" NAME="pkg_svc$svcpart" SIZE=4 MAXLENGTH=3 VALUE="!,
201 $cgi->param("pkg_svc$svcpart") || $pkg_svc->quantity || 0,
203 if ( dbdef->table('pkg_svc')->column('primary_svc') ) {
204 print qq!<TD><INPUT TYPE="radio" NAME="pkg_svc_primary" VALUE="$svcpart"!;
205 print ' CHECKED' if $pkg_svc->primary_svc =~ /^Y/i;
208 print qq!<TD><A HREF="part_svc.cgi?!,$part_svc->svcpart,
209 qq!">!, $part_svc->getfield('svc'), "</A></TD></TR>";
210 # print "</TABLE></TD><TD>$thead" if ++$count == int(scalar(@part_svc) / 2);
212 foreach ( 1 .. $columns-1 ) {
213 print "</TABLE></TD><TD VALIGN=\"top\">$thead"
214 if $count == int( $_ * scalar(@part_svc) / $columns );
217 print qq!<INPUT TYPE="hidden" NAME="pkg_svc$svcpart" VALUE="!,
218 $cgi->param("pkg_svc$svcpart") || $pkg_svc->quantity || 0, qq!">\n!;
222 #unless ( $cgi->param('clone') ) {
225 print "</TR></TABLE></TD></TR></TABLE>";
226 #print "</TR></TABLE>";
229 foreach my $f ( qw( clone pkgnum ) ) {
230 print qq!<INPUT TYPE="hidden" NAME="$f" VALUE="!. $cgi->param($f). '">';
232 print '<INPUT TYPE="hidden" NAME="pkgpart" VALUE="'. $part_pkg->pkgpart. '">';
234 # prolly should be in database
235 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
237 my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
238 split("\n", ($clone_part_pkg||$part_pkg)->plandata );
239 #warn join("\n", map { "$_: $plandata{$_}" } keys %plandata ). "\n";
241 tie my %options, 'Tie::IxHash', map { $_=>$plans{$_}->{'name'} } keys %plans;
243 my @form_select = ();
244 if ( $conf->exists('enable_taxclasses') ) {
245 push @form_select, 'taxclass';
247 push @fixups, 'taxclass'; #hidden
251 if ( dbdef->table('pkg_svc')->column('primary_svc') ) {
252 push @form_radio, 'pkg_svc_primary';
255 tie my %freq, 'Tie::IxHash', %FS::part_pkg::freq;
256 if ( $part_pkg->dbdef_table->column('freq')->type =~ /(int)/i ) {
257 delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq;
260 my $widget = new HTML::Widgets::SelectLayers(
261 'selected_layer' => $part_pkg->plan,
262 'options' => \%options,
263 'form_name' => 'dummy',
264 'form_action' => 'process/part_pkg.cgi',
265 'form_text' => [ qw(pkg comment promo_code clone pkgnum pkgpart),
268 'form_checkbox' => [ qw(setuptax recurtax disabled) ],
269 'form_radio' => \@form_radio,
270 'form_select' => \@form_select,
271 'layer_callback' => sub {
273 my $html = qq!<INPUT TYPE="hidden" NAME="plan" VALUE="$layer">!.
277 <TD ALIGN="right">Recurring fee frequency </TD>
278 <TD><SELECT NAME="freq">
281 my @freq = keys %freq;
282 @freq = grep { /^\d+$/ } @freq
283 if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
284 foreach my $freq ( @freq ) {
285 $html .= qq(<OPTION VALUE="$freq");
286 $html .= ' SELECTED' if $freq eq $part_pkg->freq;
287 $html .= ">$freq{$freq}";
289 $html .= '</SELECT></TD></TR>';
291 my $href = $plans{$layer}->{'fields'};
292 foreach my $field ( exists($plans{$layer}->{'fieldorder'})
293 ? @{$plans{$layer}->{'fieldorder'}}
297 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
299 if ( ! exists($href->{$field}{'type'}) ) {
300 $html .= qq!<INPUT TYPE="text" NAME="$field" VALUE="!.
301 ( exists($plandata{$field})
303 : $href->{$field}{'default'} ).
304 qq!" onChange="fchanged(this)">!;
305 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
308 if $href->{$field}{'type'} eq 'select_multiple';
309 $html .= qq! NAME="$field" onChange="fchanged(this)">!;
311 qsearch( $href->{$field}{'select_table'},
312 $href->{$field}{'select_hash'} )
314 my $value = $record->getfield($href->{$field}{'select_key'});
315 $html .= qq!<OPTION VALUE="$value"!.
316 ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
319 '>'. $record->getfield($href->{$field}{'select_label'})
321 $html .= '</SELECT>';
324 $html .= '</TD></TR>';
328 $html .= '<INPUT TYPE="hidden" NAME="plandata" VALUE="'.
329 join(',', keys %{ $href } ). '">'.
332 $html .= '<INPUT TYPE="submit" VALUE="'.
333 ( $hashref->{pkgpart} ? "Apply changes" : "Add package" ).
334 '" onClick="fchanged(this)">';
343 <BR><BR>Price plan <%= $widget->html %>