1 <% include('/elements/header.html', "$action Package Definition", menubar(
2 'View all packages' => popurl(2). 'browse/part_pkg.cgi',
4 % #), ' onLoad="visualize()"');
6 <% include('/elements/error.html') %>
10 <% itable('',8,1) %><TR><TD VALIGN="top">
14 <% ntable("#cccccc",2) %>
16 <TD ALIGN="right">Package Definition #</TD>
17 <TD BGCOLOR="#ffffff">
18 <% $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)" %>
22 <TD ALIGN="right">Package (customer-visible)</TD>
24 <INPUT TYPE="text" NAME="pkg" SIZE=32 VALUE="<% $part_pkg->pkg %>">
28 <TD ALIGN="right">Comment (customer-hidden)</TD>
30 <INPUT TYPE="text" NAME="comment" SIZE=32 VALUE="<%$part_pkg->comment%>">
33 <% include( '/elements/tr-select-pkg_class.html', $part_pkg->classnum ) %>
35 <TD ALIGN="right">Promotional code</TD>
37 <INPUT TYPE="text" NAME="promo_code" SIZE=32 VALUE="<%$part_pkg->promo_code%>">
41 <TD ALIGN="right">Disable new orders</TD>
43 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>
49 </TD><TD VALIGN="top">
52 <% ntable("#cccccc", 2) %>
54 <TD ALIGN="right">Setup fee tax exempt</TD>
56 <INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $hashref->{setuptax} eq 'Y' ? ' CHECKED' : '' %>>
60 <TD ALIGN="right">Recurring fee tax exempt</TD>
62 <INPUT TYPE="checkbox" NAME="recurtax" VALUE="Y" <% $hashref->{recurtax} eq 'Y' ? ' CHECKED' : '' %>>
66 % if ( $conf->exists('enable_taxclasses') ) {
69 <TD align="right">Tax class</TD>
71 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
77 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
84 Line-item revenue recognition
85 <% ntable("#cccccc", 2) %>
86 % tie my %weight, 'Tie::IxHash',
87 % 'pay_weight' => 'Payment',
88 % 'credit_weight' => 'Credit'
90 % foreach my $weight (keys %weight) {
92 <TD ALIGN="right"><% $weight{$weight} %> weight</TD>
94 <INPUT TYPE="text" NAME="<% $weight %>" SIZE=6 VALUE=<% $hashref->{$weight} || 0 %>>
100 </TD><TD VALIGN="top">
102 % if ( $cgi->param('clone') ) {
104 <INPUT TYPE="hidden" NAME="agent_type" VALUE="">
106 % } elsif ( scalar(@all_agent_types) == 1) {
108 <INPUT TYPE="hidden" NAME="agent_type" VALUE="<% $all_agent_types[0] %>">
113 <% ntable("#cccccc", 2) %>
115 <TD ALIGN="right"><% 'Agent Types' %></TD>
117 <% include( '/elements/select-table.html',
118 'element_name' => 'agent_type',
119 'table' => 'agent_type',
120 'name_col' => 'atype',
121 'value' => \@agent_type,
123 'element_etc' => 'size="10"',
134 %my $thead = "\n\n". ntable('#cccccc', 2).
135 % '<TR><TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Quan.</FONT></TH>'.
136 % '<TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Primary</FONT></TH>'.
137 % '<TH BGCOLOR="#dcdcdc">Service</TH></TR>';
139 <BR><BR>Services included
140 <% itable('', 4, 1) %><TR><TD VALIGN="top">
144 %my $where = "WHERE disabled IS NULL OR disabled = ''";
146 % $where .= " OR 0 < ( SELECT quantity FROM pkg_svc
147 % WHERE pkg_svc.svcpart = part_svc.svcpart
148 % AND pkgpart = $pkgpart
151 %my @part_svc = qsearch('part_svc', {}, '', $where);
152 %my $q_part_pkg = $clone_part_pkg || $part_pkg;
153 %my %pkg_svc = map { $_->svcpart => $_ } $q_part_pkg->pkg_svc;
158 %foreach my $part_svc ( @part_svc ) {
159 % my $svcpart = $part_svc->svcpart;
160 % my $pkg_svc = $pkg_svc{$svcpart}
161 % || new FS::pkg_svc ( {
162 % 'pkgpart' => $pkgpart,
163 % 'svcpart' => $svcpart,
165 % 'primary_svc' => '',
167 % if ( $cgi->param('error') ) {
168 % my $primary_svc = ( $pkg_svc->primary_svc =~ /^Y/i );
169 % my $pkg_svc_primary = scalar($cgi->param('pkg_svc_primary'));
170 % $pkg_svc->primary_svc('')
171 % if $primary_svc && $pkg_svc_primary != $svcpart;
172 % $pkg_svc->primary_svc('Y')
173 % if ! $primary_svc && $pkg_svc_primary == $svcpart;
176 % push @fixups, "pkg_svc$svcpart";
179 % if ( $cgi->param("pkg_svc$svcpart") =~ /^\s*(\d+)\s*$/ ) {
181 % } elsif ( $pkg_svc->quantity ) {
182 % $quan = $pkg_svc->quantity;
188 <INPUT TYPE="text" NAME="pkg_svc<% $svcpart %>" SIZE=4 MAXLENGTH=3 VALUE="<% $quan %>">
192 <INPUT TYPE="radio" NAME="pkg_svc_primary" VALUE="<% $svcpart %>" <% $pkg_svc->primary_svc =~ /^Y/i ? ' CHECKED' : '' %>>
196 <A HREF="part_svc.cgi?<% $part_svc->svcpart %>"><% $part_svc->svc %></A> <% $part_svc->disabled =~ /^Y/i ? ' (DISABLED' : '' %>
199 % foreach ( 1 .. $columns-1 ) {
200 % if ( $count == int( $_ * scalar(@part_svc) / $columns ) ) {
203 </TABLE></TD><TD VALIGN="top"><% $thead %>
211 </TR></TABLE></TD></TR></TABLE>
212 % foreach my $f ( qw( clone pkgnum ) ) { #safe, these were untained in %init
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
234 %my @form_elements = ( 'classnum', 'taxclass', 'agent_type' );
236 %my @form_radio = ( 'pkg_svc_primary' );
238 %tie my %freq, 'Tie::IxHash', %{FS::part_pkg->freqs_href()};
239 %if ( $part_pkg->dbdef_table->column('freq')->type =~ /(int)/i ) {
240 % delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq;
243 %my $widget = new HTML::Widgets::SelectLayers(
244 % 'selected_layer' => $part_pkg->plan,
245 % 'options' => \%options,
246 % 'form_name' => 'dummy',
247 % 'form_action' => 'process/part_pkg.cgi',
248 % 'form_elements' => \@form_elements,
249 % 'form_text' => [ qw(pkg comment promo_code clone pkgnum pkgpart),
250 % qw(pay_weight credit_weight), #keys(%weight),
253 % 'form_checkbox' => [ qw(setuptax recurtax disabled) ],
254 % 'form_radio' => \@form_radio,
255 % 'layer_callback' => sub {
257 % my $html = qq!<INPUT TYPE="hidden" NAME="plan" VALUE="$layer">!.
258 % ntable("#cccccc",2);
261 % <TD ALIGN="right">Recurring fee frequency </TD>
262 % <TD><SELECT NAME="freq">
265 % my @freq = keys %freq;
266 % @freq = grep { /^\d+$/ } @freq
267 % if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
268 % foreach my $freq ( @freq ) {
269 % $html .= qq(<OPTION VALUE="$freq");
270 % $html .= ' SELECTED' if $freq eq $part_pkg->freq;
271 % $html .= ">$freq{$freq}";
273 % $html .= '</SELECT></TD></TR>';
275 % my $href = $plans{$layer}->{'fields'};
276 % foreach my $field ( exists($plans{$layer}->{'fieldorder'})
277 % ? @{$plans{$layer}->{'fieldorder'}}
281 % $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
283 % my $format = sub { shift };
284 % $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
285 % if ( ! exists($href->{$field}{'type'}) ) {
286 % $html .= qq!<INPUT TYPE="text" NAME="$field" VALUE="!.
287 % ( exists($plandata{$field})
288 % ? &$format($plandata{$field})
289 % : $href->{$field}{'default'} ).
290 % qq!" onChange="fchanged(this)">!;
291 % } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
292 % $html .= qq!<INPUT TYPE="checkbox" NAME="$field" VALUE=1 !.
293 % ( exists($plandata{$field}) && $plandata{$field}
297 % } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
298 % $html .= '<SELECT';
299 % $html .= ' MULTIPLE'
300 % if $href->{$field}{'type'} eq 'select_multiple';
301 % $html .= qq! NAME="$field" onChange="fchanged(this)">!;
303 % if ( $href->{$field}{'select_table'} ) {
304 % foreach my $record (
305 % qsearch( $href->{$field}{'select_table'},
306 % $href->{$field}{'select_hash'} )
308 % my $value = $record->getfield($href->{$field}{'select_key'});
309 % $html .= qq!<OPTION VALUE="$value"!.
310 % ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
314 % '>'. $record->getfield($href->{$field}{'select_label'});
316 % } elsif ( $href->{$field}{'select_options'} ) {
317 % foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
318 % my $value = $href->{$field}{'select_options'}{$key};
319 % $html .= qq!<OPTION VALUE="$key"!.
320 % ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
328 % $html .= '<font color="#ff0000">warning: '.
329 % "don't know how to retreive options for $field select field".
332 % $html .= '</SELECT>';
335 % $html .= '</TD></TR>';
337 % $html .= '</TABLE>';
339 % $html .= '<INPUT TYPE="hidden" NAME="plandata" VALUE="'.
340 % join(',', keys %{ $href } ). '">'.
343 % $html .= '<INPUT TYPE="submit" VALUE="'.
344 % ( $action eq 'Custom'
345 % ? 'Customize package'
346 % : ( $hashref->{pkgpart} ? "Apply changes" : "Add package" )
348 % '" onClick="fchanged(this)">';
358 <BR><BR>Price plan <% $widget->html %>
360 <% include('/elements/footer.html') %>
364 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
366 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
367 $cgi->param('clone', $1);
369 $cgi->param('clone', '');
371 if ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
372 $cgi->param('pkgnum', $1);
374 $cgi->param('pkgnum', '');
377 my ($query) = $cgi->keywords;
379 my $conf = new FS::Conf;
382 my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
383 if ( $cgi->param('error') ) {
384 $part_pkg = new FS::part_pkg ( {
385 map { $_, scalar($cgi->param($_)) } fields('part_pkg')
387 (@agent_type) = $cgi->param('agent_type');
391 my $clone_part_pkg = '';
393 if ( $cgi->param('clone') ) {
394 $pkgpart = $cgi->param('clone');
395 #$action = 'Custom Pricing';
397 $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
398 $part_pkg ||= $clone_part_pkg->clone;
399 $part_pkg->disabled('Y') unless $cgi->param('error');
400 } elsif ( $query && $query =~ /^(\d+)$/ ) {
401 (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1})
403 $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
404 $pkgpart = $part_pkg->pkgpart;
406 unless ( $part_pkg ) {
407 $part_pkg = new FS::part_pkg {};
408 $part_pkg->plan('flat');
409 @agent_type = @all_agent_types if $conf->exists('agent_defaultpkg');
413 unless ( $part_pkg->plan ) { #backwards-compat
414 $part_pkg->plan('flat');
415 $part_pkg->plandata("setup_fee=". $part_pkg->setup. "\n".
416 "recur_fee=". $part_pkg->recur. "\n");
418 $action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
419 my $hashref = $part_pkg->hashref;