1 <% include( 'elements/edit.html',
2 'post_url' => popurl(1).'process/part_pkg.cgi',
3 'name' => "Package definition",
7 'agent_null_right' => $edit_global,
8 'agent_clone_extra_sql' => $agent_clone_extra_sql,
9 #'viewall_dir' => 'browse',
10 'viewall_url' => $p.'browse/part_pkg.cgi',
11 'html_init' => include('/elements/init_overlib.html').
13 'html_bottom' => $html_bottom,
15 'onLoad="agent_changed(document.edit_topform.agentnum)"',
17 'begin_callback' => $begin_callback,
18 'end_callback' => $end_callback,
19 'new_hashref_callback' => $new_hashref_callback,
20 'new_object_callback' => $new_object_callback,
21 'new_callback' => $new_callback,
22 'clone_callback' => $clone_callback,
23 'edit_callback' => $edit_callback,
24 'error_callback' => $error_callback,
25 'field_callback' => $field_callback,
27 'onsubmit' => 'confirm_submit',
30 'pkgpart' => 'Package Definition',
33 'comment' => 'Comment (customer-hidden)',
34 'classnum' => 'Package class',
35 'addon_classnum' => 'Restrict additional orders to package class',
36 'promo_code' => 'Promotional code',
37 'freq' => 'Recurring fee frequency',
38 'setuptax' => 'Setup fee tax exempt',
39 'recurtax' => 'Recurring fee tax exempt',
40 'taxclass' => 'Tax class',
41 'taxproduct_select'=> 'Tax products',
42 'plan' => 'Price plan',
43 'disabled' => 'Disable new orders',
44 'disable_line_item_date_ranges' => 'Disable line item date ranges',
45 'setup_cost' => 'Setup cost',
46 'recur_cost' => 'Recur cost',
47 'pay_weight' => 'Payment weight',
48 'credit_weight' => 'Credit weight',
49 'agentnum' => 'Agent',
50 'setup_fee' => 'Setup fee',
51 'setup_show_zero' => 'Show zero setup',
52 'recur_fee' => 'Recurring fee',
53 'recur_show_zero' => 'Show zero recurring',
54 'discountnum' => 'Offer discounts for longer terms',
55 'bill_dst_pkgpart' => 'Include line item(s) from package',
56 'svc_dst_pkgpart' => 'Include services of package',
57 'supp_dst_pkgpart' => 'Include complete package',
58 'report_option' => 'Report classes',
59 'fcc_ds0s' => 'Voice-grade equivalents',
60 'fcc_voip_class' => 'Category',
64 { field=>'clone', type=>'hidden',
65 curr_value_callback =>
66 sub { shift->param('clone') },
68 { field=>'pkgnum', type=>'hidden',
69 curr_value_callback =>
70 sub { shift->param('pkgnum') },
73 { field=>'custom', type=>'hidden' },
74 { field=>'family_pkgpart', type=>'hidden' },
75 { field=>'successor', type=>'hidden' },
77 { type => 'columnstart' },
85 {field=>'comment', type=>'text', size=>40 }, #32
86 { field => 'agentnum',
87 type => 'select-agent',
88 disable_empty => ! $acl_edit_global,
89 empty_label => '(global)',
90 onchange => 'agent_changed',
92 {field=>'classnum', type=>'select-pkg_class' },
93 ( $conf->exists('pkg-addon_classnum')
94 ? ( { field=>'addon_classnum',
95 type =>'select-pkg_class',
100 {field=>'disabled', type=>$disabled_type, value=>'Y'},
101 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
103 { type => 'tablebreak-tr-title',
104 value => 'Pricing', #better name?
107 type => 'selectlayers-select',
108 options => [ keys %plan_labels ],
109 labels => \%plan_labels,
110 onchange => 'aux_planchanged(what);',
112 { field => 'setup_fee',
114 onchange => 'setup_changed',
116 { field => 'setup_show_zero',
119 disabled => sub { $setup_show_zero_disabled },
122 type => 'part_pkg_freq',
123 onchange => 'freq_changed',
125 { field => 'recur_fee',
127 disabled => sub { $recur_disabled },
128 onchange => 'recur_changed',
131 { field => 'recur_show_zero',
134 disabled => sub { $recur_show_zero_disabled },
140 #recurring fee (auto-disable)
142 { type => 'columnnext' },
144 {type=>'justtitle', value=>'Taxation' },
145 {field=>'setuptax', type=>'checkbox', value=>'Y'},
146 {field=>'recurtax', type=>'checkbox', value=>'Y'},
147 {field=>'taxclass', type=>'select-taxclass' },
148 { field => 'taxproductnums',
150 value => join(',', @taxproductnums),
152 { field => 'taxproduct_select',
153 type => 'selectlayers',
154 options => [ '(default)', @taxproductnums ],
155 curr_value => '(default)',
156 labels => { ( '(default)' => '(default)' ),
157 map {($_=>$usage_class{$_})}
160 layer_fields => \%taxproduct_fields,
161 layer_values_callback => $taxproduct_values,
162 layers_only => !$taxproducts,
163 cell_style => ( !$taxproducts
169 { type => 'tablebreak-tr-title',
170 value => 'Promotions', #better name?
172 { field=>'promo_code', type=>'text', size=>15 },
174 { type => 'tablebreak-tr-title',
175 value => 'Cost tracking', #better name?
177 { field=>'setup_cost', type=>'money', },
178 { field=>'recur_cost', type=>'money', },
180 { type => 'columnnext' },
182 { field => 'agent_type',
183 type => 'select-agent_types',
184 disabled => ! $acl_edit_global,
185 curr_value_callback => sub {
186 my($cgi, $object, $field) = @_;
187 #in the other callbacks..? hmm.
192 { type => 'tablebreak-tr-title',
193 value => 'Line-item revenue recogition', #better name?
195 { field=>'pay_weight', type=>'text', size=>6 },
196 { field=>'credit_weight', type=>'text', size=>6 },
198 ( $conf->exists('cust_pkg-show_fcc_voice_grade_equivalent')
200 { type => 'tablebreak-tr-title',
201 value => 'FCC Form 477 information',
203 { field=>'fcc_voip_class',
204 type=>'select-voip_class',
206 { field=>'fcc_ds0s', type=>'text', size=>6 },
212 { type => 'columnend' },
214 { 'type' => $report_option ? 'tablebreak-tr-title'
216 'value' => 'Optional report classes',
217 'field' => 'census_title',
219 { 'field' => 'report_option',
220 'type' => $report_option ? 'select-table'
222 'table' => 'part_pkg_report_option',
223 'name_col' => 'name',
224 'hashref' => { 'disabled' => '' },
228 { 'type' => 'tablebreak-tr-title',
229 'value' => 'Term discounts',
231 { 'field' => 'discountnum',
232 'type' => 'select-table',
233 'table' => 'discount',
234 'name_col' => 'name',
235 'hashref' => { %$discountnum_hashref },
236 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
237 'empty_label'=> 'Select discount',
238 'm2_label' => 'Offer discounts for longer terms',
239 'm2m_method' => 'part_pkg_discount',
240 'm2m_dstcol' => 'discountnum',
241 'm2_error_callback' => $discount_error_callback,
244 { 'type' => 'tablebreak-tr-title',
245 'value' => 'Supplemental packages',
248 { 'field' => 'supp_dst_pkgpart',
249 'type' => 'select-part_pkg',
250 'm2_label' => 'Include complete package',
251 'm2m_method' => 'supp_part_pkg_link',
252 'm2m_dstcol' => 'dst_pkgpart',
253 'm2_error_callback' =>
254 &{$m2_error_callback_maker}('supp'),
257 { 'type' => 'tablebreak-tr-title',
258 'value' => 'Pricing add-ons',
261 { 'field' => 'bill_dst_pkgpart',
262 'type' => 'select-part_pkg',
263 'extra_sql' => sub { $pkgpart
264 ? "AND pkgpart != $pkgpart"
267 'm2_label' => 'Include line item(s) from package',
268 'm2m_method' => 'bill_part_pkg_link',
269 'm2m_dstcol' => 'dst_pkgpart',
270 'm2_error_callback' =>
271 &{$m2_error_callback_maker}('bill'),
272 'm2_fields' => [ { 'field' => 'hidden',
273 'type' => 'checkbox',
281 { type => 'tablebreak-tr-title',
284 { type => 'pkg_svc', },
286 { 'field' => 'svc_dst_pkgpart',
287 'label' => 'Also include services from package: ',
288 'type' => 'select-part_pkg',
289 'extra_sql' => sub { $pkgpart
290 ? "AND pkgpart != $pkgpart"
293 'm2_label' => 'Include services of package: ',
294 'm2m_method' => 'svc_part_pkg_link',
295 'm2m_dstcol' => 'dst_pkgpart',
296 'm2_error_callback' =>
297 &{$m2_error_callback_maker}('svc'),
300 { type => 'tablebreak-tr-title',
301 value => 'Price plan options',
310 my $curuser = $FS::CurrentUser::CurrentUser;
312 my $edit_global = 'Edit global package definitions';
313 my $acl_edit = $curuser->access_right('Edit package definitions');
314 my $acl_edit_global = $curuser->access_right($edit_global);
316 my $acl_edit_either = $acl_edit || $acl_edit_global;
318 my $begin_callback = sub {
319 my( $cgi, $fields, $opt ) = @_;
321 unless $acl_edit_either
322 || ( $cgi->param('pkgnum')
323 && $curuser->access_right('Customize customer package')
327 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
329 #arg. access rights for cloning are Hard.
330 # on the one hand we don't really want cloning (customizing a package) to fail
331 # for want of finding the source package in normal usage
332 # on the other hand, we don't want people using the clone link to be able to
334 my $agent_clone_extra_sql =
335 ' ( '. FS::part_pkg->curuser_pkgs_sql.
336 " OR ( part_pkg.custom = 'Y' ) ".
339 my $conf = new FS::Conf;
340 my $taxproducts = $conf->exists('enable_taxproducts');
342 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
343 my %locale_labels = map {
344 ( $_ => 'Package -- '. FS::Locales->description($_) )
347 sort { $locale_labels{$a} cmp $locale_labels{$b} }
351 my %locale_field_labels = (
353 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
358 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
359 " WHERE disabled IS NULL OR disabled = '' ")
361 $sth->execute or die $sth->errstr;
362 my $report_option = $sth->fetchrow_arrayref->[0];
365 # - tr-part_pkg_freq: month_increments_only (from price plans)
367 # - test errors cloning
368 # - test custom pricing
369 # - move the selectlayer divs away from lame layer_callback
371 #my ($query) = $cgi->keywords;
376 my %tax_override = ();
378 my %taxproductnums = map { ($_->classnum => 1) }
379 qsearch('usage_class', { 'disabled' => '' });
380 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
383 my $recur_disabled = 1;
384 my $setup_show_zero_disabled = 0;
385 my $recur_show_zero_disabled = 1;
389 my $splice_locale_fields = sub {
390 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
393 my @locale_fields = (
395 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
396 my $pkg_value = $pkg_value_callback
397 ? $pkg_value_callback eq 'cgiparam'
398 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
399 : &$pkg_value_callback($_)
402 { field => 'pkgpartmsgnum'. $n,
404 value => $pkey_value,
406 { field => 'pkgpartmsgnum'. $n. '_locale',
410 { field => 'pkgpartmsgnum'. $n++. '_pkg',
421 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
425 my $error_callback = sub {
426 my($cgi, $object, $fields, $opt ) = @_;
428 (@agent_type) = $cgi->param('agent_type');
430 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
432 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
434 $recur_disabled = $cgi->param('freq') ? 0 : 1;
435 $recur_show_zero_disabled =
437 ? $cgi->param('recur_fee') > 0 ? 1 : 0
440 foreach ($cgi->param) {
441 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
443 $tax_override{''} = $cgi->param('tax_override');
444 $tax_override{$_} = $cgi->param('tax_override_$_')
445 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
447 #some false laziness w/process
448 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
450 my $options = $cgi->param($plan."__OPTIONS");
451 my @options = split(',', $options);
453 map { my $optionname = $_;
454 my $param = $plan."__$optionname";
455 my $value = join(', ', $cgi->param($param));
456 ( $optionname => $value );
460 $object->set($_ => scalar($cgi->param($_)) )
461 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
463 $pkgpart = $object->pkgpart;
465 &$splice_locale_fields(
469 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
470 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
477 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
479 my $new_object_callback = sub {
480 my( $cgi, $hashref, $fields, $opt ) = @_;
482 my $part_pkg = FS::part_pkg->new( $hashref );
483 $part_pkg->set($_ => '0')
484 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
490 sub set_report_option {
491 my($cgi, $object, $fields ) = @_; #, $opt
493 my @report_option = ();
494 foreach ($object->options) {
495 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
496 /^report_option_(\d+)$/ && (push @report_option, $1);
498 foreach ($object->part_pkg_taxoverride) {
499 $taxproductnums{$_->usage_class} = 1
503 $cgi->param('report_option', join(',', @report_option));
504 foreach my $field ( @$fields ) {
506 ref($field) eq 'HASH' &&
508 $field->{field} eq 'report_option'
510 #$field->{curr_value} = join(',', @report_option);
511 $field->{value} = join(',', @report_option);
516 my $edit_callback = sub {
517 my( $cgi, $object, $fields, $opt ) = @_;
519 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
521 $recur_disabled = $object->freq ? 0 : 1;
523 $recur_show_zero_disabled =
525 ? $object->option('recur_fee') > 0 ? 1 : 0
529 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
531 set_report_option( $cgi, $object, $fields);
533 %options = $object->options;
535 $object->set($_ => $object->option($_, 1))
536 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
538 $pkgpart = $object->pkgpart;
540 &$splice_locale_fields(
544 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
545 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
549 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
550 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
556 my $new_callback = sub {
557 my( $cgi, $object, $fields ) = @_;
559 my $conf = new FS::Conf;
561 if ( $conf->exists('agent_defaultpkg') ) {
562 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
563 @agent_type = map {$_->typenum} qsearch('agent_type',{});
566 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
568 &$splice_locale_fields($fields, '', '');
572 my $clone_callback = sub {
573 my( $cgi, $object, $fields, $opt ) = @_;
575 if ( $cgi->param('pkgnum') ) {
577 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
578 $object->agentnum( $cust_pkg->cust_main->agentnum );
580 $opt->{action} = 'Custom';
582 #my $part_pkg = $clone_part_pkg->clone;
583 #this is all clone does anyway
584 $object->custom('Y');
586 $object->disabled('Y');
588 } else { #when explicitly cloning, not customizing
591 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
595 set_report_option( $cgi, $object, $fields);
597 %options = $object->options;
599 $object->set($_ => $options{$_})
600 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
602 $recur_disabled = $object->freq ? 0 : 1;
604 &$splice_locale_fields(
609 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
610 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
615 my $discount_error_callback = sub {
616 my( $cgi, $object ) = @_;
618 if ( /^discountnum(\d+)$/ &&
619 ( my $discountnum = $cgi->param("discountnum$1") ) )
621 new FS::part_pkg_discount {
622 'pkgpart' => $object->pkgpart,
623 'discountnum' => $discountnum,
632 my $m2_error_callback_maker = sub {
633 my $link_type = shift; #yay closures
635 my( $cgi, $object ) = @_;
638 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
639 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
642 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
644 new FS::part_pkg_link {
645 'link_type' => $link_type,
646 'src_pkgpart' => $object->pkgpart,
647 'dst_pkgpart' => $dst,
658 my $javascript = <<'END';
659 <SCRIPT TYPE="text/javascript">
661 function freq_changed(what) {
662 var freq = what.options[what.selectedIndex].value;
665 what.form.recur_fee.disabled = true;
666 what.form.recur_fee.style.backgroundColor = '#dddddd';
667 what.form.recur_show_zero.disabled = true;
668 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
670 what.form.recur_fee.disabled = false;
671 what.form.recur_fee.style.backgroundColor = '#ffffff';
672 recur_changed( what.form.recur_fee );
673 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
678 function setup_changed(what) {
679 var setup = what.value;
680 if ( parseFloat(setup) == 0 ) {
681 what.form.setup_show_zero.disabled = false;
683 what.form.setup_show_zero.disabled = true;
687 function recur_changed(what) {
688 var recur = what.value;
689 if ( parseFloat(recur) == 0 ) {
690 what.form.recur_show_zero.disabled = false;
692 what.form.recur_show_zero.disabled = true;
696 function agent_changed(what) {
699 if ( what.type == 'select-one' ) {
700 agentnum = what.options[what.selectedIndex].value;
702 agentnum = what.value;
705 if ( agentnum == 0 ) {
706 what.form.agent_type.disabled = false;
707 //what.form.agent_type.style.backgroundColor = '#ffffff';
708 what.form.agent_type.style.visibility = '';
710 what.form.agent_type.disabled = true;
711 //what.form.agent_type.style.backgroundColor = '#dddddd';
712 what.form.agent_type.style.visibility = 'hidden';
717 function aux_planchanged(what) { //?
720 var plan = what.options[what.selectedIndex].value;
721 var table = document.getElementById('TableNumber7') // XXX NOT ROBUST
723 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
724 //table.disabled = false;
725 table.style.visibility = '';
727 //table.disabled = true;
728 table.style.visibility = 'hidden';
736 'Changing the setup or recurring fee will create a new package definition. '.
739 $javascript .= "function confirm_submit(f) {";
740 if ( $conf->exists('part_pkg-lineage') ) {
743 var fields = Array('setup_fee','recur_fee');
744 for(var i=0; i < fields.length; i++) {
745 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
746 return confirm('$warning');
756 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
758 tie my %plan_labels, 'Tie::IxHash',
759 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
762 my $html_bottom = sub {
765 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
767 my $layer_callback = sub {
770 my $html = ntable("#cccccc",2);
774 # <TD ALIGN="right">Recurring fee frequency </TD>
775 # <TD><SELECT NAME="freq">
778 #my @freq = keys %freq;
779 #@freq = grep { /^\d+$/ } @freq
780 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
781 #foreach my $freq ( @freq ) {
782 # $html .= qq(<OPTION VALUE="$freq");
783 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
784 # $html .= ">$freq{$freq}";
787 #$html .= '</SELECT></TD></TR>';
789 my $href = $plans{$layer}->{'fields'};
790 my @fields = exists($plans{$layer}->{'fieldorder'})
791 ? @{$plans{$layer}->{'fieldorder'}}
794 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
796 if(!exists($href->{$field})) {
798 warn "nonexistent part_pkg option: '$field'\n";
802 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
804 my $format = sub { shift };
805 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
807 #XXX these should use elements/ fields... (or this whole thing should
808 #just use layer_fields instead of layer_callback)
810 if ( ! exists($href->{$field}{'type'}) ) {
812 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
813 ( exists($options{$field})
814 ? &$format($options{$field})
815 : $href->{$field}{'default'} ).
818 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
820 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
821 ( exists($options{$field}) && $options{$field}
826 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
830 if $href->{$field}{'type'} eq 'select_multiple';
831 $html .= qq! NAME="${layer}__$field">!;
833 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
834 if exists($href->{$field}{'disable_empty'})
835 && ! $href->{$field}{'disable_empty'};
837 if ( $href->{$field}{'select_table'} ) {
839 qsearch( $href->{$field}{'select_table'},
840 $href->{$field}{'select_hash'} )
842 my $value = $record->getfield($href->{$field}{'select_key'});
843 $html .= qq!<OPTION VALUE="$value"!.
844 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
848 '>'. $record->getfield($href->{$field}{'select_label'});
850 } elsif ( $href->{$field}{'select_options'} ) {
851 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
852 my $label = $href->{$field}{'select_options'}{$key};
853 $html .= qq!<OPTION VALUE="$key"!.
854 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
862 $html .= '<font color="#ff0000">warning: '.
863 "don't know how to retreive options for $field select field".
866 $html .= '</SELECT>';
868 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
871 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
873 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
874 my $label = $href->{$field}{'options'}{$key};
875 $html .= qq!$radio VALUE="$key"!.
876 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
885 $html .= '</TD></TR>';
889 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
890 join(',', keys %{ $href } ). '">';
898 options => [ keys %plan_labels ],
899 labels => \%plan_labels,
900 curr_value => $object->plan,
901 layer_callback => $layer_callback,
905 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
906 '<SCRIPT TYPE="text/javascript">'.
907 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
910 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
913 $return .= '</SCRIPT>';
919 my %usage_class = map { ($_->classnum => $_->classname) }
920 qsearch('usage_class', {});
921 $usage_class{setup} = 'Setup';
922 $usage_class{recur} = 'Recurring';
924 my %taxproduct_fields = ();
925 my $end_callback = sub {
926 my( $cgi, $object, $fields, $opt ) = @_;
928 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
930 if ( $object->pkgpart ) {
931 foreach my $usage_class ( '', @taxproductnums ) {
932 $tax_override{$usage_class} =
933 join (",", map $_->taxclassnum,
934 qsearch( 'part_pkg_taxoverride', {
935 'pkgpart' => $object->pkgpart,
936 'usage_class' => $usage_class,
943 map { $_ => [ "taxproductnum_$_",
944 { type => 'select-taxproduct',
945 #label => "$usage_class{$_} tax product",
948 { type => 'select-taxoverride' }
953 $taxproduct_fields{'(default)'} =
954 [ 'taxproductnum', { type => 'select-taxproduct',
955 #label => 'Default tax product',
957 'tax_override', { type => 'select-taxoverride' },
961 my $taxproduct_values = sub {
962 my ($cgi, $object, $flags) = @_;
964 sub { my $layer = shift;
965 my @fields = @{$taxproduct_fields{$layer}};
968 my $field = shift @fields;
970 $field =~ /^taxproductnum_\w+$/ &&
971 push @values, ( $field => $options{"usage_$field"} );
972 $field =~ /^tax_override_(\w+)$/ &&
973 push @values, ( $field => $tax_override{$1} );
974 $field =~ /^taxproductnum$/ &&
975 push @values, ( $field => $object->taxproductnum );
976 $field =~ /^tax_override$/ &&
977 push @values, ( $field => $tax_override{''} );
983 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
988 my $field_callback = sub {
989 my ($cgi, $object, $fieldref) = @_;
991 my $field = $fieldref->{field};
992 if ($field eq 'taxproductnums') {
993 $fieldref->{value} = join(',', @taxproductnums);
994 } elsif ($field eq 'taxproduct_select') {
995 $fieldref->{options} = [ '(default)', @taxproductnums ];
996 $fieldref->{labels} = { ( '(default)' => '(default)' ),
997 map {( $_ => ($usage_class{$_} || $_) )}
1000 $fieldref->{layer_fields} = \%taxproduct_fields;
1001 $fieldref->{layer_values_callback} = $taxproduct_values;
1005 my $discountnum_hashref = {
1007 'months' => { 'op' => '>', 'value' => 1 },