1 <% include("/elements/header.html","$action Package Definition", menubar(
2 'Main Menu' => popurl(2),
3 'View all packages' => popurl(2). 'browse/part_pkg.cgi',
5 % #), ' onLoad="visualize()"');
7 % if ( $cgi->param('error') ) {
8 <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
13 <% itable('',8,1) %><TR><TD VALIGN="top">
17 <% ntable("#cccccc",2) %>
19 <TD ALIGN="right">Package Definition #</TD>
20 <TD BGCOLOR="#ffffff">
21 <% $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)" %>
25 <TD ALIGN="right">Package (customer-visible)</TD>
27 <INPUT TYPE="text" NAME="pkg" SIZE=32 VALUE="<% $part_pkg->pkg %>">
31 <TD ALIGN="right">Comment (customer-hidden)</TD>
33 <INPUT TYPE="text" NAME="comment" SIZE=32 VALUE="<%$part_pkg->comment%>">
36 <% include( '/elements/tr-select-pkg_class.html',
37 'curr_value' => $part_pkg->classnum,
41 <TD ALIGN="right">Promotional code</TD>
43 <INPUT TYPE="text" NAME="promo_code" SIZE=32 VALUE="<%$part_pkg->promo_code%>">
47 <TD ALIGN="right">Disable new orders</TD>
49 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>
55 </TD><TD VALIGN="top">
58 <% ntable("#cccccc", 2) %>
60 <TD ALIGN="right">Setup fee tax exempt</TD>
62 <INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $hashref->{setuptax} eq 'Y' ? ' CHECKED' : '' %>>
66 <TD ALIGN="right">Recurring fee tax exempt</TD>
68 <INPUT TYPE="checkbox" NAME="recurtax" VALUE="Y" <% $hashref->{recurtax} eq 'Y' ? ' CHECKED' : '' %>>
72 % if ( $conf->exists('enable_taxclasses') ) {
75 <TD align="right">Tax class</TD>
77 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
83 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
90 Line-item revenue recognition
91 <% ntable("#cccccc", 2) %>
92 % tie my %weight, 'Tie::IxHash',
93 % 'pay_weight' => 'Payment',
94 % 'credit_weight' => 'Credit'
96 % foreach my $weight (keys %weight) {
98 <TD ALIGN="right"><% $weight{$weight} %> weight</TD>
100 <INPUT TYPE="text" NAME="<% $weight %>" SIZE=6 VALUE=<% $hashref->{$weight} || 0 %>>
106 </TD><TD VALIGN="top">
108 % if ( $cgi->param('clone') ) {
110 <INPUT TYPE="hidden" NAME="agent_type" VALUE="">
112 % } elsif ( scalar(@all_agent_types) == 1) {
114 <INPUT TYPE="hidden" NAME="agent_type" VALUE="<% $all_agent_types[0] %>">
119 <% ntable("#cccccc", 2) %>
121 <TD ALIGN="right"><% 'Agent Types' %></TD>
123 <% include( '/elements/select-table.html',
124 'element_name' => 'agent_type',
125 'table' => 'agent_type',
126 'name_col' => 'atype',
127 'value' => \@agent_type,
129 'element_etc' => 'size="10"',
140 %my $thead = "\n\n". ntable('#cccccc', 2).
141 % '<TR><TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Quan.</FONT></TH>'.
142 % '<TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Primary</FONT></TH>'.
143 % '<TH BGCOLOR="#dcdcdc">Service</TH></TR>';
145 <BR><BR>Services included
146 <% itable('', 4, 1) %><TR><TD VALIGN="top">
150 %my $where = "WHERE disabled IS NULL OR disabled = ''";
152 % $where .= " OR 0 < ( SELECT quantity FROM pkg_svc
153 % WHERE pkg_svc.svcpart = part_svc.svcpart
154 % AND pkgpart = $pkgpart
157 %my @part_svc = qsearch('part_svc', {}, '', $where);
158 %my $q_part_pkg = $clone_part_pkg || $part_pkg;
159 %my %pkg_svc = map { $_->svcpart => $_ } $q_part_pkg->pkg_svc;
164 %foreach my $part_svc ( @part_svc ) {
165 % my $svcpart = $part_svc->svcpart;
166 % my $pkg_svc = $pkg_svc{$svcpart}
167 % || new FS::pkg_svc ( {
168 % 'pkgpart' => $pkgpart,
169 % 'svcpart' => $svcpart,
171 % 'primary_svc' => '',
173 % if ( $cgi->param('error') ) {
174 % my $primary_svc = ( $pkg_svc->primary_svc =~ /^Y/i );
175 % my $pkg_svc_primary = scalar($cgi->param('pkg_svc_primary'));
176 % $pkg_svc->primary_svc('')
177 % if $primary_svc && $pkg_svc_primary != $svcpart;
178 % $pkg_svc->primary_svc('Y')
179 % if ! $primary_svc && $pkg_svc_primary == $svcpart;
182 % push @fixups, "pkg_svc$svcpart";
186 <INPUT TYPE="text" NAME="pkg_svc<% $svcpart %>" SIZE=4 MAXLENGTH=3 VALUE="<% $cgi->param("pkg_svc$svcpart") || $pkg_svc->quantity || 0 %>">
190 <INPUT TYPE="radio" NAME="pkg_svc_primary" VALUE="<% $svcpart %>" <% $pkg_svc->primary_svc =~ /^Y/i ? ' CHECKED' : '' %>>
194 <A HREF="part_svc.cgi?<% $part_svc->svcpart %>"><% $part_svc->svc %></A> <% $part_svc->disabled =~ /^Y/i ? ' (DISABLED' : '' %>
197 % foreach ( 1 .. $columns-1 ) {
198 % if ( $count == int( $_ * scalar(@part_svc) / $columns ) ) {
201 </TABLE></TD><TD VALIGN="top"><% $thead %>
209 </TR></TABLE></TD></TR></TABLE>
210 % foreach my $f ( qw( clone pkgnum ) ) {
212 <INPUT TYPE="hidden" NAME="<% $f %>" VALUE="<% $cgi->param($f) %>">
215 <INPUT TYPE="hidden" NAME="pkgpart" VALUE="<% $part_pkg->pkgpart %>">
218 %# prolly should be in database
219 %tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
221 %my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
222 % split("\n", ($clone_part_pkg||$part_pkg)->plandata );
223 %#warn join("\n", map { "$_: $plandata{$_}" } keys %plandata ). "\n";
225 %tie my %options, 'Tie::IxHash', map { $_=>$plans{$_}->{'name'} } keys %plans;
227 %#my @form_select = ('classnum');
228 %#if ( $conf->exists('enable_taxclasses') ) {
229 %# push @form_select, 'taxclass';
231 %# push @fixups, 'taxclass'; #hidden
233 %my @form_elements = ( 'classnum', 'taxclass', 'agent_type' );
235 %my @form_radio = ( 'pkg_svc_primary' );
237 %tie my %freq, 'Tie::IxHash', %{FS::part_pkg->freqs_href()};
238 %if ( $part_pkg->dbdef_table->column('freq')->type =~ /(int)/i ) {
239 % delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq;
242 %my $widget = new HTML::Widgets::SelectLayers(
243 % 'selected_layer' => $part_pkg->plan,
244 % 'options' => \%options,
245 % 'form_name' => 'dummy',
246 % 'form_action' => 'process/part_pkg.cgi',
247 % 'form_elements' => \@form_elements,
248 % 'form_text' => [ qw(pkg comment promo_code clone pkgnum pkgpart),
249 % qw(pay_weight credit_weight), #keys(%weight),
252 % 'form_checkbox' => [ qw(setuptax recurtax disabled) ],
253 % 'form_radio' => \@form_radio,
254 % 'layer_callback' => sub {
256 % my $html = qq!<INPUT TYPE="hidden" NAME="plan" VALUE="$layer">!.
257 % ntable("#cccccc",2);
260 % <TD ALIGN="right">Recurring fee frequency </TD>
261 % <TD><SELECT NAME="freq">
264 % my @freq = keys %freq;
265 % @freq = grep { /^\d+$/ } @freq
266 % if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
267 % foreach my $freq ( @freq ) {
268 % $html .= qq(<OPTION VALUE="$freq");
269 % $html .= ' SELECTED' if $freq eq $part_pkg->freq;
270 % $html .= ">$freq{$freq}";
272 % $html .= '</SELECT></TD></TR>';
274 % my $href = $plans{$layer}->{'fields'};
275 % foreach my $field ( exists($plans{$layer}->{'fieldorder'})
276 % ? @{$plans{$layer}->{'fieldorder'}}
280 % $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
282 % my $format = sub { shift };
283 % $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
284 % if ( ! exists($href->{$field}{'type'}) ) {
285 % $html .= qq!<INPUT TYPE="text" NAME="$field" VALUE="!.
286 % ( exists($plandata{$field})
287 % ? &$format($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 % ( $action eq 'Custom'
344 % ? 'Customize package'
345 % : ( $hashref->{pkgpart} ? "Apply changes" : "Add package" )
347 % '" onClick="fchanged(this)">';
357 <BR><BR>Price plan <% $widget->html %>
362 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
363 $cgi->param('clone', $1);
365 $cgi->param('clone', '');
367 if ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
368 $cgi->param('pkgnum', $1);
370 $cgi->param('pkgnum', '');
373 my ($query) = $cgi->keywords;
375 my $conf = new FS::Conf;
378 my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
379 if ( $cgi->param('error') ) {
380 $part_pkg = new FS::part_pkg ( {
381 map { $_, scalar($cgi->param($_)) } fields('part_pkg')
383 (@agent_type) = $cgi->param('agent_type');
387 my $clone_part_pkg = '';
389 if ( $cgi->param('clone') ) {
390 $pkgpart = $cgi->param('clone');
391 #$action = 'Custom Pricing';
393 $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
394 $part_pkg ||= $clone_part_pkg->clone;
395 $part_pkg->disabled('Y') unless $cgi->param('error');
396 } elsif ( $query && $query =~ /^(\d+)$/ ) {
397 (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1})
399 $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
400 $pkgpart = $part_pkg->pkgpart;
402 unless ( $part_pkg ) {
403 $part_pkg = new FS::part_pkg {};
404 $part_pkg->plan('flat');
405 @agent_type = @all_agent_types if $conf->exists('agent_defaultpkg');
409 unless ( $part_pkg->plan ) { #backwards-compat
410 $part_pkg->plan('flat');
411 $part_pkg->plandata("setup_fee=". $part_pkg->setup. "\n".
412 "recur_fee=". $part_pkg->recur. "\n");
414 $action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
415 my $hashref = $part_pkg->hashref;