1 <% include('/elements/header.html', "$action Package Definition", menubar(
2 'View all packages' => popurl(2). 'browse/part_pkg.cgi',
4 % #), ' onLoad="visualize()"');
6 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws.js"></SCRIPT>
7 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws_iframe.js"></SCRIPT>
8 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws_draggable.js"></SCRIPT>
9 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/iframecontentmws.js"></SCRIPT>
11 <% include('/elements/error.html') %>
15 <% itable('',8,1) %><TR><TD VALIGN="top">
19 <% ntable("#cccccc",2) %>
21 <TD ALIGN="right">Package Definition #</TD>
22 <TD BGCOLOR="#ffffff">
23 <% $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)" %>
27 <TD ALIGN="right">Package (customer-visible)</TD>
29 <INPUT TYPE="text" NAME="pkg" SIZE=32 VALUE="<% $part_pkg->pkg %>">
33 <TD ALIGN="right">Comment (customer-hidden)</TD>
35 <INPUT TYPE="text" NAME="comment" SIZE=32 VALUE="<%$part_pkg->comment%>">
38 <% include( '/elements/tr-select-pkg_class.html',
39 'curr_value' => $part_pkg->classnum,
43 <TD ALIGN="right">Promotional code</TD>
45 <INPUT TYPE="text" NAME="promo_code" SIZE=32 VALUE="<%$part_pkg->promo_code%>">
49 <TD ALIGN="right">Disable new orders</TD>
51 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>
57 </TD><TD VALIGN="top">
60 <% ntable("#cccccc", 2) %>
62 <TD ALIGN="right">Setup fee tax exempt</TD>
64 <INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $hashref->{setuptax} eq 'Y' ? ' CHECKED' : '' %>>
68 <TD ALIGN="right">Recurring fee tax exempt</TD>
70 <INPUT TYPE="checkbox" NAME="recurtax" VALUE="Y" <% $hashref->{recurtax} eq 'Y' ? ' CHECKED' : '' %>>
74 % if ( $conf->exists('enable_taxclasses') ) {
77 <TD align="right">Tax class</TD>
79 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
85 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
89 % if ( $conf->exists('enable_taxproducts') ) {
92 <% ntable("#cccccc", 2) %>
94 <TD align="right">Tax product</TD>
96 <INPUT name="part_pkg_taxproduct_taxproductnum" id="taxproductnum" type="hidden" value="<% $hashref->{'taxproductnum'}%>">
97 <INPUT name="part_pkg_taxproduct_description" id="taxproduct_description" type="text" value="<% $taxproduct_description %>" size="12" onclick="overlib( OLiframeContent('part_pkg_taxproduct.html?'+document.getElementById('taxproductnum').value, 800, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
101 <TD colspan="2" align="right">
102 <INPUT name="tax_override" id="tax_override" type="hidden" value="<% $tax_override %>">
103 <A href="javascript:void(0)" onclick="overlib( OLiframeContent('part_pkg_taxoverride.html?'+document.getElementById('tax_override').value, 800, 400, 'tax_product_popup'), CAPTION, 'Edit product tax overrides', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
104 <% $tax_override ? 'Edit tax overrides' : 'Override taxes' %>
113 <INPUT TYPE="hidden" NAME="taxproductnum" VALUE="<% $hashref->{taxproductnum} %>">
120 Line-item revenue recognition
121 <% ntable("#cccccc", 2) %>
122 % tie my %weight, 'Tie::IxHash',
123 % 'pay_weight' => 'Payment',
124 % 'credit_weight' => 'Credit'
126 % foreach my $weight (keys %weight) {
128 <TD ALIGN="right"><% $weight{$weight} %> weight</TD>
130 <INPUT TYPE="text" NAME="<% $weight %>" SIZE=6 VALUE=<% $hashref->{$weight} || 0 %>>
136 </TD><TD VALIGN="top">
138 % if ( $cgi->param('clone') ) {
140 <INPUT TYPE="hidden" NAME="agent_type" VALUE="">
142 % } elsif ( scalar(@all_agent_types) == 1) {
144 <INPUT TYPE="hidden" NAME="agent_type" VALUE="<% $all_agent_types[0] %>">
149 <% ntable("#cccccc", 2) %>
151 <TD ALIGN="right"><% 'Agent Types' %></TD>
153 <% include( '/elements/select-table.html',
154 'element_name' => 'agent_type',
155 'table' => 'agent_type',
156 'name_col' => 'atype',
157 'value' => \@agent_type,
159 'element_etc' => 'size="10"',
170 %my $thead = "\n\n". ntable('#cccccc', 2).
171 % '<TR><TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Quan.</FONT></TH>'.
172 % '<TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Primary</FONT></TH>'.
173 % '<TH BGCOLOR="#dcdcdc">Service</TH></TR>';
175 <BR><BR>Services included
176 <% itable('', 4, 1) %><TR><TD VALIGN="top">
180 %my $where = "WHERE disabled IS NULL OR disabled = ''";
182 % $where .= " OR 0 < ( SELECT quantity FROM pkg_svc
183 % WHERE pkg_svc.svcpart = part_svc.svcpart
184 % AND pkgpart = $pkgpart
187 %my @part_svc = qsearch('part_svc', {}, '', $where);
188 %my $q_part_pkg = $clone_part_pkg || $part_pkg;
189 %my %pkg_svc = map { $_->svcpart => $_ } $q_part_pkg->pkg_svc;
194 %foreach my $part_svc ( @part_svc ) {
195 % my $svcpart = $part_svc->svcpart;
196 % my $pkg_svc = $pkg_svc{$svcpart}
197 % || new FS::pkg_svc ( {
198 % 'pkgpart' => $pkgpart,
199 % 'svcpart' => $svcpart,
201 % 'primary_svc' => '',
203 % if ( $cgi->param('error') ) {
204 % my $primary_svc = ( $pkg_svc->primary_svc =~ /^Y/i );
205 % my $pkg_svc_primary = scalar($cgi->param('pkg_svc_primary'));
206 % $pkg_svc->primary_svc('')
207 % if $primary_svc && $pkg_svc_primary != $svcpart;
208 % $pkg_svc->primary_svc('Y')
209 % if ! $primary_svc && $pkg_svc_primary == $svcpart;
212 % push @fixups, "pkg_svc$svcpart";
215 % if ( $cgi->param("pkg_svc$svcpart") =~ /^\s*(\d+)\s*$/ ) {
217 % } elsif ( $pkg_svc->quantity ) {
218 % $quan = $pkg_svc->quantity;
224 <INPUT TYPE="text" NAME="pkg_svc<% $svcpart %>" SIZE=4 MAXLENGTH=3 VALUE="<% $quan %>">
228 <INPUT TYPE="radio" NAME="pkg_svc_primary" VALUE="<% $svcpart %>" <% $pkg_svc->primary_svc =~ /^Y/i ? ' CHECKED' : '' %>>
232 <A HREF="part_svc.cgi?<% $part_svc->svcpart %>"><% $part_svc->svc %></A> <% $part_svc->disabled =~ /^Y/i ? ' (DISABLED' : '' %>
235 % foreach ( 1 .. $columns-1 ) {
236 % if ( $count == int( $_ * scalar(@part_svc) / $columns ) ) {
239 </TABLE></TD><TD VALIGN="top"><% $thead %>
247 </TR></TABLE></TD></TR></TABLE>
248 % foreach my $f ( qw( clone pkgnum ) ) { #safe, these were untained in %init
249 <INPUT TYPE="hidden" NAME="<% $f %>" VALUE="<% $cgi->param($f) %>">
252 <INPUT TYPE="hidden" NAME="pkgpart" VALUE="<% $part_pkg->pkgpart %>">
255 %# prolly should be in database
256 %tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
258 %my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
259 % split("\n", ($clone_part_pkg||$part_pkg)->plandata );
260 %#warn join("\n", map { "$_: $plandata{$_}" } keys %plandata ). "\n";
262 %tie my %options, 'Tie::IxHash', map { $_=>$plans{$_}->{'name'} } keys %plans;
264 %#my @form_select = ('classnum');
265 %#if ( $conf->exists('enable_taxclasses') ) {
266 %# push @form_select, 'taxclass';
268 %# push @fixups, 'taxclass'; #hidden
270 %my @form_elements = ( 'classnum', 'taxclass', 'agent_type', 'tax_override' );
272 %my @form_radio = ( 'pkg_svc_primary' );
274 %tie my %freq, 'Tie::IxHash', %{FS::part_pkg->freqs_href()};
275 %if ( $part_pkg->dbdef_table->column('freq')->type =~ /(int)/i ) {
276 % delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq;
279 %#this should be replaced by /elements/selectlayers.html
280 %my $widget = new HTML::Widgets::SelectLayers(
281 % 'selected_layer' => $part_pkg->plan,
282 % 'options' => \%options,
283 % 'form_name' => 'dummy',
284 % 'form_action' => 'process/part_pkg.cgi',
285 % 'form_elements' => \@form_elements,
286 % 'form_text' => [ qw(pkg comment promo_code clone pkgnum pkgpart),
287 % qw(pay_weight credit_weight), #keys(%weight),
291 % 'form_checkbox' => [ qw(setuptax recurtax disabled) ],
292 % 'form_radio' => \@form_radio,
293 % 'layer_callback' => sub {
295 % my $html = qq!<INPUT TYPE="hidden" NAME="plan" VALUE="$layer">!.
296 % ntable("#cccccc",2);
299 % <TD ALIGN="right">Recurring fee frequency </TD>
300 % <TD><SELECT NAME="freq">
303 % my @freq = keys %freq;
304 % @freq = grep { /^\d+$/ } @freq
305 % if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
306 % foreach my $freq ( @freq ) {
307 % $html .= qq(<OPTION VALUE="$freq");
308 % $html .= ' SELECTED' if $freq eq $part_pkg->freq;
309 % $html .= ">$freq{$freq}";
311 % $html .= '</SELECT></TD></TR>';
313 % my $href = $plans{$layer}->{'fields'};
314 % foreach my $field ( exists($plans{$layer}->{'fieldorder'})
315 % ? @{$plans{$layer}->{'fieldorder'}}
319 % $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
321 % my $format = sub { shift };
322 % $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
324 % if ( ! exists($href->{$field}{'type'}) ) {
326 % $html .= qq!<INPUT TYPE="text" NAME="$field" VALUE="!.
327 % ( exists($plandata{$field})
328 % ? &$format($plandata{$field})
329 % : $href->{$field}{'default'} ).
330 % qq!" onChange="fchanged(this)">!;
332 % } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
334 % $html .= qq!<INPUT TYPE="checkbox" NAME="$field" VALUE=1 !.
335 % ( exists($plandata{$field}) && $plandata{$field}
340 % } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
342 % $html .= '<SELECT';
343 % $html .= ' MULTIPLE'
344 % if $href->{$field}{'type'} eq 'select_multiple';
345 % $html .= qq! NAME="$field" onChange="fchanged(this)">!;
347 % if ( $href->{$field}{'select_table'} ) {
348 % foreach my $record (
349 % qsearch( $href->{$field}{'select_table'},
350 % $href->{$field}{'select_hash'} )
352 % my $value = $record->getfield($href->{$field}{'select_key'});
353 % $html .= qq!<OPTION VALUE="$value"!.
354 % ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
358 % '>'. $record->getfield($href->{$field}{'select_label'});
360 % } elsif ( $href->{$field}{'select_options'} ) {
361 % foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
362 % my $label = $href->{$field}{'select_options'}{$key};
363 % $html .= qq!<OPTION VALUE="$key"!.
364 % ( $plandata{$field} =~ /(^|, *)$key *(,|$)/ #XXX fix
372 % $html .= '<font color="#ff0000">warning: '.
373 % "don't know how to retreive options for $field select field".
376 % $html .= '</SELECT>';
378 % } elsif ( $href->{$field}{'type'} eq 'radio' ) {
381 % qq!<INPUT TYPE="radio" NAME="$field" onChange="fchanged(this)"!;
383 % foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
384 % my $label = $href->{$field}{'options'}{$key};
385 % $html .= qq!$radio VALUE="$key"!.
386 % ( $plandata{$field} =~ /(^|, *)$key *(,|$)/ #XXX fix
395 % $html .= '</TD></TR>';
397 % $html .= '</TABLE>';
399 % $html .= '<INPUT TYPE="hidden" NAME="plandata" VALUE="'.
400 % join(',', keys %{ $href } ). '">'.
403 % $html .= '<INPUT TYPE="submit" VALUE="'.
404 % ( $action eq 'Custom'
405 % ? 'Customize package'
406 % : ( $hashref->{pkgpart} ? "Apply changes" : "Add package" )
408 % '" onClick="fchanged(this)">';
418 <BR><BR>Price plan <% $widget->html %>
420 <% include('/elements/footer.html') %>
423 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
424 $cgi->param('clone', $1);
426 $cgi->param('clone', '');
428 if ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
429 $cgi->param('pkgnum', $1);
431 $cgi->param('pkgnum', '');
434 my $curuser = $FS::CurrentUser::CurrentUser;
437 unless $curuser->access_right('Edit package definitions')
438 || $curuser->access_right('Edit global package definitions')
439 || ( $cgi->param('pkgnum') && $curuser->access_right('Customize customer package') );
441 my ($query) = $cgi->keywords;
443 my $conf = new FS::Conf;
447 my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
448 if ( $cgi->param('error') ) {
449 $part_pkg = new FS::part_pkg ( {
450 map { $_, scalar($cgi->param($_)) } fields('part_pkg')
452 (@agent_type) = $cgi->param('agent_type');
453 $tax_override = $cgi->param('tax_override');
457 my $clone_part_pkg = '';
459 if ( $cgi->param('clone') ) {
460 $pkgpart = $cgi->param('clone');
461 #$action = 'Custom Pricing';
463 $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
464 $part_pkg ||= $clone_part_pkg->clone;
465 $part_pkg->disabled('Y') unless $cgi->param('error');
466 } elsif ( $query && $query =~ /^(\d+)$/ ) {
467 (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1})
470 join (",", map {$_->taxnum} qsearch('part_pkg_taxoverride',{'pkgpart'=>$1}))
472 $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
473 $pkgpart = $part_pkg->pkgpart;
475 unless ( $part_pkg ) {
476 $part_pkg = new FS::part_pkg {};
477 $part_pkg->plan('flat');
478 @agent_type = @all_agent_types if $conf->exists('agent_defaultpkg');
482 unless ( $part_pkg->plan ) { #backwards-compat
483 $part_pkg->plan('flat');
484 $part_pkg->plandata("setup_fee=". $part_pkg->setup. "\n".
485 "recur_fee=". $part_pkg->recur. "\n");
487 $action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
488 my $hashref = $part_pkg->hashref;
489 my $taxproduct_description = $part_pkg->taxproduct_description;