3 %if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
4 % $cgi->param('clone', $1);
6 % $cgi->param('clone', '');
8 %if ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
9 % $cgi->param('pkgnum', $1);
11 % $cgi->param('pkgnum', '');
14 %my ($query) = $cgi->keywords;
17 %if ( $cgi->param('error') ) {
18 % $part_pkg = new FS::part_pkg ( {
19 % map { $_, scalar($cgi->param($_)) } fields('part_pkg')
24 %my $clone_part_pkg = '';
26 %if ( $cgi->param('clone') ) {
27 % $pkgpart = $cgi->param('clone');
28 % $action = 'Custom Pricing';
29 % $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
30 % $part_pkg ||= $clone_part_pkg->clone;
31 % $part_pkg->disabled('Y'); #isn't sticky on errors
32 %} elsif ( $query && $query =~ /^(\d+)$/ ) {
33 % $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
34 % $pkgpart = $part_pkg->pkgpart;
36 % unless ( $part_pkg ) {
37 % $part_pkg = new FS::part_pkg {};
38 % $part_pkg->plan('flat');
41 %unless ( $part_pkg->plan ) { #backwards-compat
42 % $part_pkg->plan('flat');
43 % $part_pkg->plandata("setup_fee=". $part_pkg->setup. "\n".
44 % "recur_fee=". $part_pkg->recur. "\n");
46 %$action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
47 %my $hashref = $part_pkg->hashref;
52 <% include("/elements/header.html","$action Package Definition", menubar(
53 'Main Menu' => popurl(2),
54 'View all packages' => popurl(2). 'browse/part_pkg.cgi',
56 % #), ' onLoad="visualize()"');
57 % if ( $cgi->param('error') ) {
59 <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
65 <% itable('',8,1) %><TR><TD VALIGN="top">
69 <% ntable("#cccccc",2) %>
71 <TD ALIGN="right">Package Definition #</TD>
72 <TD BGCOLOR="#ffffff">
73 <% $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)" %>
77 <TD ALIGN="right">Package (customer-visible)</TD>
79 <INPUT TYPE="text" NAME="pkg" SIZE=32 VALUE="<% $part_pkg->pkg %>">
83 <TD ALIGN="right">Comment (customer-hidden)</TD>
85 <INPUT TYPE="text" NAME="comment" SIZE=32 VALUE="<%$part_pkg->comment%>">
88 <% include( '/elements/tr-select-pkg_class.html', $part_pkg->classnum ) %>
90 <TD ALIGN="right">Promotional code</TD>
92 <INPUT TYPE="text" NAME="promo_code" SIZE=32 VALUE="<%$part_pkg->promo_code%>">
96 <TD ALIGN="right">Disable new orders</TD>
98 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>
104 </TD><TD VALIGN="top">
107 <% ntable("#cccccc", 2) %>
109 <TD ALIGN="right">Setup fee tax exempt</TD>
111 <INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $hashref->{setuptax} eq 'Y' ? ' CHECKED' : '' %>>
115 <TD ALIGN="right">Recurring fee tax exempt</TD>
117 <INPUT TYPE="checkbox" NAME="recurtax" VALUE="Y" <% $hashref->{recurtax} eq 'Y' ? ' CHECKED' : '' %>>
120 % my $conf = new FS::Conf;
121 % if ( $conf->exists('enable_taxclasses') ) {
125 <TD align="right">Tax class</TD>
127 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
133 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
142 %my $thead = "\n\n". ntable('#cccccc', 2).
143 % '<TR><TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Quan.</FONT></TH>';
144 %$thead .= '<TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Primary</FONT></TH>'
145 % if dbdef->table('pkg_svc')->column('primary_svc');
146 %$thead .= '<TH BGCOLOR="#dcdcdc">Service</TH></TR>';
151 <BR><BR>Services included
152 <% itable('', 4, 1) %><TR><TD VALIGN="top">
156 %my $where = "WHERE disabled IS NULL OR disabled = ''";
158 % $where .= " OR 0 < ( SELECT quantity FROM pkg_svc
159 % WHERE pkg_svc.svcpart = part_svc.svcpart
160 % AND pkgpart = $pkgpart
163 %my @part_svc = qsearch('part_svc', {}, '', $where);
164 %my $q_part_pkg = $clone_part_pkg || $part_pkg;
165 %my %pkg_svc = map { $_->svcpart => $_ } $q_part_pkg->pkg_svc;
170 %foreach my $part_svc ( @part_svc ) {
171 % my $svcpart = $part_svc->svcpart;
172 % my $pkg_svc = $pkg_svc{$svcpart}
173 % || new FS::pkg_svc ( {
174 % 'pkgpart' => $pkgpart,
175 % 'svcpart' => $svcpart,
177 % 'primary_svc' => '',
180 % push @fixups, "pkg_svc$svcpart";
187 <INPUT TYPE="text" NAME="pkg_svc<% $svcpart %>" SIZE=4 MAXLENGTH=3 VALUE="<% $cgi->param("pkg_svc$svcpart") || $pkg_svc->quantity || 0 %>">
191 <INPUT TYPE="radio" NAME="pkg_svc_primary" VALUE="<% $svcpart %>" <% $pkg_svc->primary_svc =~ /^Y/i ? ' CHECKED' : '' %>>
195 <A HREF="part_svc.cgi?<% $part_svc->svcpart %>"><% $part_svc->svc %></A> <% $part_svc->disabled =~ /^Y/i ? ' (DISABLED' : '' %>
198 % foreach ( 1 .. $columns-1 ) {
199 % if ( $count == int( $_ * scalar(@part_svc) / $columns ) ) {
202 </TABLE></TD><TD VALIGN="top"><% $thead %>
210 </TR></TABLE></TD></TR></TABLE>
211 % foreach my $f ( qw( clone pkgnum ) ) {
213 <INPUT TYPE="hidden" NAME="<% $f %>" VALUE="<% $cgi->param($f) %>">
216 <INPUT TYPE="hidden" NAME="pkgpart" VALUE="<% $part_pkg->pkgpart %>">
219 %# prolly should be in database
220 %tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
222 %my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
223 % split("\n", ($clone_part_pkg||$part_pkg)->plandata );
224 %#warn join("\n", map { "$_: $plandata{$_}" } keys %plandata ). "\n";
226 %tie my %options, 'Tie::IxHash', map { $_=>$plans{$_}->{'name'} } keys %plans;
228 %my @form_select = ('classnum');
229 %if ( $conf->exists('enable_taxclasses') ) {
230 % push @form_select, 'taxclass';
232 % push @fixups, 'taxclass'; #hidden
235 %my @form_radio = ();
236 %if ( dbdef->table('pkg_svc')->column('primary_svc') ) {
237 % push @form_radio, 'pkg_svc_primary';
240 %tie my %freq, 'Tie::IxHash', %{FS::part_pkg->freqs_href()};
241 %if ( $part_pkg->dbdef_table->column('freq')->type =~ /(int)/i ) {
242 % delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq;
245 %my $widget = new HTML::Widgets::SelectLayers(
246 % 'selected_layer' => $part_pkg->plan,
247 % 'options' => \%options,
248 % 'form_name' => 'dummy',
249 % 'form_action' => 'process/part_pkg.cgi',
250 % 'form_text' => [ qw(pkg comment promo_code clone pkgnum pkgpart),
253 % 'form_checkbox' => [ qw(setuptax recurtax disabled) ],
254 % 'form_radio' => \@form_radio,
255 % 'form_select' => \@form_select,
256 % 'layer_callback' => sub {
258 % my $html = qq!<INPUT TYPE="hidden" NAME="plan" VALUE="$layer">!.
259 % ntable("#cccccc",2);
262 % <TD ALIGN="right">Recurring fee frequency </TD>
263 % <TD><SELECT NAME="freq">
266 % my @freq = keys %freq;
267 % @freq = grep { /^\d+$/ } @freq
268 % if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
269 % foreach my $freq ( @freq ) {
270 % $html .= qq(<OPTION VALUE="$freq");
271 % $html .= ' SELECTED' if $freq eq $part_pkg->freq;
272 % $html .= ">$freq{$freq}";
274 % $html .= '</SELECT></TD></TR>';
276 % my $href = $plans{$layer}->{'fields'};
277 % foreach my $field ( exists($plans{$layer}->{'fieldorder'})
278 % ? @{$plans{$layer}->{'fieldorder'}}
282 % $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
284 % if ( ! exists($href->{$field}{'type'}) ) {
285 % $html .= qq!<INPUT TYPE="text" NAME="$field" VALUE="!.
286 % ( exists($plandata{$field})
287 % ? $plandata{$field}
288 % : $href->{$field}{'default'} ).
289 % qq!" onChange="fchanged(this)">!;
290 % } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
291 % $html .= qq!<INPUT TYPE="checkbox" NAME="$field" VALUE=1 !.
292 % ( exists($plandata{$field}) && $plandata{$field}
296 % } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
297 % $html .= '<SELECT';
298 % $html .= ' MULTIPLE'
299 % if $href->{$field}{'type'} eq 'select_multiple';
300 % $html .= qq! NAME="$field" onChange="fchanged(this)">!;
302 % if ( $href->{$field}{'select_table'} ) {
303 % foreach my $record (
304 % qsearch( $href->{$field}{'select_table'},
305 % $href->{$field}{'select_hash'} )
307 % my $value = $record->getfield($href->{$field}{'select_key'});
308 % $html .= qq!<OPTION VALUE="$value"!.
309 % ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
313 % '>'. $record->getfield($href->{$field}{'select_label'});
315 % } elsif ( $href->{$field}{'select_options'} ) {
316 % foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
317 % my $value = $href->{$field}{'select_options'}{$key};
318 % $html .= qq!<OPTION VALUE="$key"!.
319 % ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
327 % $html .= '<font color="#ff0000">warning: '.
328 % "don't know how to retreive options for $field select field".
331 % $html .= '</SELECT>';
334 % $html .= '</TD></TR>';
336 % $html .= '</TABLE>';
338 % $html .= '<INPUT TYPE="hidden" NAME="plandata" VALUE="'.
339 % join(',', keys %{ $href } ). '">'.
342 % $html .= '<INPUT TYPE="submit" VALUE="'.
343 % ( $hashref->{pkgpart} ? "Apply changes" : "Add package" ).
344 % '" onClick="fchanged(this)">';
354 <BR><BR>Price plan <% $widget->html %>