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',
61 'delay_start' => 'Default delay (days)',
65 { field=>'clone', type=>'hidden',
66 curr_value_callback =>
67 sub { shift->param('clone') },
69 { field=>'pkgnum', type=>'hidden',
70 curr_value_callback =>
71 sub { shift->param('pkgnum') },
74 { field=>'custom', type=>'hidden' },
75 { field=>'family_pkgpart', type=>'hidden' },
76 { field=>'successor', type=>'hidden' },
78 { type => 'columnstart' },
86 {field=>'comment', type=>'text', size=>40 }, #32
87 { field => 'agentnum',
88 type => 'select-agent',
89 disable_empty => ! $acl_edit_global,
90 empty_label => '(global)',
91 onchange => 'agent_changed',
93 {field=>'classnum', type=>'select-pkg_class' },
94 ( $conf->exists('pkg-addon_classnum')
95 ? ( { field=>'addon_classnum',
96 type =>'select-pkg_class',
101 {field=>'disabled', type=>$disabled_type, value=>'Y'},
102 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
104 { type => 'tablebreak-tr-title',
105 value => 'Pricing', #better name?
108 type => 'selectlayers-select',
109 options => [ keys %plan_labels ],
110 labels => \%plan_labels,
111 onchange => 'aux_planchanged(what);',
113 { field => 'setup_fee',
115 onchange => 'setup_changed',
117 { field => 'setup_show_zero',
120 disabled => sub { $setup_show_zero_disabled },
123 type => 'part_pkg_freq',
124 onchange => 'freq_changed',
126 { field => 'recur_fee',
128 disabled => sub { $recur_disabled },
129 onchange => 'recur_changed',
132 { field => 'recur_show_zero',
135 disabled => sub { $recur_show_zero_disabled },
141 #recurring fee (auto-disable)
143 { type => 'columnnext' },
145 {type=>'justtitle', value=>'Taxation' },
146 {field=>'setuptax', type=>'checkbox', value=>'Y'},
147 {field=>'recurtax', type=>'checkbox', value=>'Y'},
148 {field=>'taxclass', type=>'select-taxclass' },
149 { field => 'taxproductnums',
151 value => join(',', @taxproductnums),
153 { field => 'taxproduct_select',
154 type => 'selectlayers',
155 options => [ '(default)', @taxproductnums ],
156 curr_value => '(default)',
157 labels => { ( '(default)' => '(default)' ),
158 map {($_=>$usage_class{$_})}
161 layer_fields => \%taxproduct_fields,
162 layer_values_callback => $taxproduct_values,
163 layers_only => !$taxproducts,
164 cell_style => ( !$taxproducts
170 { type => 'tablebreak-tr-title',
171 value => 'Promotions', #better name?
173 { field=>'promo_code', type=>'text', size=>15 },
175 { type => 'tablebreak-tr-title',
176 value => 'Cost tracking', #better name?
178 { field=>'setup_cost', type=>'money', },
179 { field=>'recur_cost', type=>'money', },
181 ( $conf->exists('part_pkg-delay_start')
182 ? ( { type => 'tablebreak-tr-title',
183 value => 'Delayed start',
185 { field => 'delay_start',
186 type => 'text', size => 6 },
191 { type => 'columnnext' },
193 { field => 'agent_type',
194 type => 'select-agent_types',
195 disabled => ! $acl_edit_global,
196 curr_value_callback => sub {
197 my($cgi, $object, $field) = @_;
198 #in the other callbacks..? hmm.
203 { type => 'tablebreak-tr-title',
204 value => 'Line-item revenue recogition', #better name?
206 { field=>'pay_weight', type=>'text', size=>6 },
207 { field=>'credit_weight', type=>'text', size=>6 },
209 ( $conf->exists('cust_pkg-show_fcc_voice_grade_equivalent')
211 { type => 'tablebreak-tr-title',
212 value => 'FCC Form 477 information',
214 { field=>'fcc_voip_class',
215 type=>'select-voip_class',
217 { field=>'fcc_ds0s', type=>'text', size=>6 },
222 { type => 'columnend' },
224 { 'type' => $report_option ? 'tablebreak-tr-title'
226 'value' => 'Optional report classes',
227 'field' => 'census_title',
229 { 'field' => 'report_option',
230 'type' => $report_option ? 'select-table'
232 'table' => 'part_pkg_report_option',
233 'name_col' => 'name',
234 'hashref' => { 'disabled' => '' },
238 { 'type' => 'tablebreak-tr-title',
239 'value' => 'Term discounts',
241 { 'field' => 'discountnum',
242 'type' => 'select-table',
243 'table' => 'discount',
244 'name_col' => 'name',
245 'hashref' => { %$discountnum_hashref },
246 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
247 'empty_label'=> 'Select discount',
248 'm2_label' => 'Offer discounts for longer terms',
249 'm2m_method' => 'part_pkg_discount',
250 'm2m_dstcol' => 'discountnum',
251 'm2_error_callback' => $discount_error_callback,
254 { 'type' => 'tablebreak-tr-title',
255 'value' => 'Supplemental packages',
258 { 'field' => 'supp_dst_pkgpart',
259 'type' => 'select-part_pkg',
260 'm2_label' => 'Include complete package',
261 'm2m_method' => 'supp_part_pkg_link',
262 'm2m_dstcol' => 'dst_pkgpart',
263 'm2_error_callback' =>
264 &{$m2_error_callback_maker}('supp'),
267 { 'type' => 'tablebreak-tr-title',
268 'value' => 'Pricing add-ons',
271 { 'field' => 'bill_dst_pkgpart',
272 'type' => 'select-part_pkg',
273 'extra_sql' => sub { $pkgpart
274 ? "AND pkgpart != $pkgpart"
277 'm2_label' => 'Include line item(s) from package',
278 'm2m_method' => 'bill_part_pkg_link',
279 'm2m_dstcol' => 'dst_pkgpart',
280 'm2_error_callback' =>
281 &{$m2_error_callback_maker}('bill'),
282 'm2_fields' => [ { 'field' => 'hidden',
283 'type' => 'checkbox',
291 { type => 'tablebreak-tr-title',
294 { type => 'pkg_svc', },
296 { 'field' => 'svc_dst_pkgpart',
297 'label' => 'Also include services from package: ',
298 'type' => 'select-part_pkg',
299 'extra_sql' => sub { $pkgpart
300 ? "AND pkgpart != $pkgpart"
303 'm2_label' => 'Include services of package: ',
304 'm2m_method' => 'svc_part_pkg_link',
305 'm2m_dstcol' => 'dst_pkgpart',
306 'm2_error_callback' =>
307 &{$m2_error_callback_maker}('svc'),
310 { type => 'tablebreak-tr-title',
311 value => 'Price plan options',
320 my $curuser = $FS::CurrentUser::CurrentUser;
322 my $edit_global = 'Edit global package definitions';
323 my $acl_edit = $curuser->access_right('Edit package definitions');
324 my $acl_edit_global = $curuser->access_right($edit_global);
326 my $acl_edit_either = $acl_edit || $acl_edit_global;
328 my $begin_callback = sub {
329 my( $cgi, $fields, $opt ) = @_;
331 unless $acl_edit_either
332 || ( $cgi->param('pkgnum')
333 && $curuser->access_right('Customize customer package')
337 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
339 #arg. access rights for cloning are Hard.
340 # on the one hand we don't really want cloning (customizing a package) to fail
341 # for want of finding the source package in normal usage
342 # on the other hand, we don't want people using the clone link to be able to
344 my $agent_clone_extra_sql =
345 ' ( '. FS::part_pkg->curuser_pkgs_sql.
346 " OR ( part_pkg.custom = 'Y' ) ".
349 my $conf = new FS::Conf;
350 my $taxproducts = $conf->exists('enable_taxproducts');
352 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
353 my %locale_labels = map {
354 ( $_ => 'Package -- '. FS::Locales->description($_) )
357 sort { $locale_labels{$a} cmp $locale_labels{$b} }
361 my %locale_field_labels = (
363 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
368 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
369 " WHERE disabled IS NULL OR disabled = '' ")
371 $sth->execute or die $sth->errstr;
372 my $report_option = $sth->fetchrow_arrayref->[0];
375 # - tr-part_pkg_freq: month_increments_only (from price plans)
377 # - test errors cloning
378 # - test custom pricing
379 # - move the selectlayer divs away from lame layer_callback
381 #my ($query) = $cgi->keywords;
386 my %tax_override = ();
388 my %taxproductnums = map { ($_->classnum => 1) }
389 qsearch('usage_class', { 'disabled' => '' });
390 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
393 my $recur_disabled = 1;
394 my $setup_show_zero_disabled = 0;
395 my $recur_show_zero_disabled = 1;
399 my $splice_locale_fields = sub {
400 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
403 my @locale_fields = (
405 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
406 my $pkg_value = $pkg_value_callback
407 ? $pkg_value_callback eq 'cgiparam'
408 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
409 : &$pkg_value_callback($_)
412 { field => 'pkgpartmsgnum'. $n,
414 value => $pkey_value,
416 { field => 'pkgpartmsgnum'. $n. '_locale',
420 { field => 'pkgpartmsgnum'. $n++. '_pkg',
431 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
435 my $error_callback = sub {
436 my($cgi, $object, $fields, $opt ) = @_;
438 (@agent_type) = $cgi->param('agent_type');
440 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
442 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
444 $recur_disabled = $cgi->param('freq') ? 0 : 1;
445 $recur_show_zero_disabled =
447 ? $cgi->param('recur_fee') > 0 ? 1 : 0
450 foreach ($cgi->param) {
451 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
453 $tax_override{''} = $cgi->param('tax_override');
454 $tax_override{$_} = $cgi->param('tax_override_$_')
455 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
457 #some false laziness w/process
458 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
460 my $options = $cgi->param($plan."__OPTIONS");
461 my @options = split(',', $options);
463 map { my $optionname = $_;
464 my $param = $plan."__$optionname";
465 my $value = join(', ', $cgi->param($param));
466 ( $optionname => $value );
470 $object->set($_ => scalar($cgi->param($_)) )
471 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
473 $pkgpart = $object->pkgpart;
475 &$splice_locale_fields(
479 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
480 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
487 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
489 my $new_object_callback = sub {
490 my( $cgi, $hashref, $fields, $opt ) = @_;
492 my $part_pkg = FS::part_pkg->new( $hashref );
493 $part_pkg->set($_ => '0')
494 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
500 sub set_report_option {
501 my($cgi, $object, $fields ) = @_; #, $opt
503 my @report_option = ();
504 foreach ($object->options) {
505 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
506 /^report_option_(\d+)$/ && (push @report_option, $1);
508 foreach ($object->part_pkg_taxoverride) {
509 $taxproductnums{$_->usage_class} = 1
513 $cgi->param('report_option', join(',', @report_option));
514 foreach my $field ( @$fields ) {
516 ref($field) eq 'HASH' &&
518 $field->{field} eq 'report_option'
520 #$field->{curr_value} = join(',', @report_option);
521 $field->{value} = join(',', @report_option);
526 my $edit_callback = sub {
527 my( $cgi, $object, $fields, $opt ) = @_;
529 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
531 $recur_disabled = $object->freq ? 0 : 1;
533 $recur_show_zero_disabled =
535 ? $object->option('recur_fee') > 0 ? 1 : 0
539 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
541 set_report_option( $cgi, $object, $fields);
543 %options = $object->options;
545 $object->set($_ => $object->option($_, 1))
546 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
548 $pkgpart = $object->pkgpart;
550 &$splice_locale_fields(
554 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
555 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
559 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
560 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
566 my $new_callback = sub {
567 my( $cgi, $object, $fields ) = @_;
569 my $conf = new FS::Conf;
571 if ( $conf->exists('agent_defaultpkg') ) {
572 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
573 @agent_type = map {$_->typenum} qsearch('agent_type',{});
576 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
578 &$splice_locale_fields($fields, '', '');
582 my $clone_callback = sub {
583 my( $cgi, $object, $fields, $opt ) = @_;
585 if ( $cgi->param('pkgnum') ) {
587 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
588 $object->agentnum( $cust_pkg->cust_main->agentnum );
590 $opt->{action} = 'Custom';
592 #my $part_pkg = $clone_part_pkg->clone;
593 #this is all clone does anyway
594 $object->custom('Y');
596 $object->disabled('Y');
598 } else { #when explicitly cloning, not customizing
601 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
605 set_report_option( $cgi, $object, $fields);
607 %options = $object->options;
609 $object->set($_ => $options{$_})
610 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
612 $recur_disabled = $object->freq ? 0 : 1;
614 &$splice_locale_fields(
619 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
620 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
625 my $discount_error_callback = sub {
626 my( $cgi, $object ) = @_;
628 if ( /^discountnum(\d+)$/ &&
629 ( my $discountnum = $cgi->param("discountnum$1") ) )
631 new FS::part_pkg_discount {
632 'pkgpart' => $object->pkgpart,
633 'discountnum' => $discountnum,
642 my $m2_error_callback_maker = sub {
643 my $link_type = shift; #yay closures
645 my( $cgi, $object ) = @_;
648 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
649 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
652 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
654 new FS::part_pkg_link {
655 'link_type' => $link_type,
656 'src_pkgpart' => $object->pkgpart,
657 'dst_pkgpart' => $dst,
668 my $javascript = <<'END';
669 <SCRIPT TYPE="text/javascript">
671 function freq_changed(what) {
672 var freq = what.options[what.selectedIndex].value;
675 what.form.recur_fee.disabled = true;
676 what.form.recur_fee.style.backgroundColor = '#dddddd';
677 what.form.recur_show_zero.disabled = true;
678 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
680 what.form.recur_fee.disabled = false;
681 what.form.recur_fee.style.backgroundColor = '#ffffff';
682 recur_changed( what.form.recur_fee );
683 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
688 function setup_changed(what) {
689 var setup = what.value;
690 if ( parseFloat(setup) == 0 ) {
691 what.form.setup_show_zero.disabled = false;
693 what.form.setup_show_zero.disabled = true;
697 function recur_changed(what) {
698 var recur = what.value;
699 if ( parseFloat(recur) == 0 ) {
700 what.form.recur_show_zero.disabled = false;
702 what.form.recur_show_zero.disabled = true;
706 function agent_changed(what) {
709 if ( what.type == 'select-one' ) {
710 agentnum = what.options[what.selectedIndex].value;
712 agentnum = what.value;
715 if ( agentnum == 0 ) {
716 what.form.agent_type.disabled = false;
717 //what.form.agent_type.style.backgroundColor = '#ffffff';
718 what.form.agent_type.style.visibility = '';
720 what.form.agent_type.disabled = true;
721 //what.form.agent_type.style.backgroundColor = '#dddddd';
722 what.form.agent_type.style.visibility = 'hidden';
727 function aux_planchanged(what) { //?
729 var plan = what.options[what.selectedIndex].value;
730 var table = document.getElementById('TableNumber6') // XXX NOT ROBUST
732 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
733 //table.disabled = false;
734 table.style.visibility = '';
736 //table.disabled = true;
737 table.style.visibility = 'hidden';
745 'Changing the setup or recurring fee will create a new package definition. '.
748 $javascript .= "function confirm_submit(f) {";
749 if ( $conf->exists('part_pkg-lineage') ) {
752 var fields = Array('setup_fee','recur_fee');
753 for(var i=0; i < fields.length; i++) {
754 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
755 return confirm('$warning');
765 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
767 tie my %plan_labels, 'Tie::IxHash',
768 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
771 my $html_bottom = sub {
774 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
776 my $layer_callback = sub {
779 my $html = ntable("#cccccc",2);
783 # <TD ALIGN="right">Recurring fee frequency </TD>
784 # <TD><SELECT NAME="freq">
787 #my @freq = keys %freq;
788 #@freq = grep { /^\d+$/ } @freq
789 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
790 #foreach my $freq ( @freq ) {
791 # $html .= qq(<OPTION VALUE="$freq");
792 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
793 # $html .= ">$freq{$freq}";
796 #$html .= '</SELECT></TD></TR>';
798 my $href = $plans{$layer}->{'fields'};
799 my @fields = exists($plans{$layer}->{'fieldorder'})
800 ? @{$plans{$layer}->{'fieldorder'}}
803 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
805 if(!exists($href->{$field})) {
807 warn "nonexistent part_pkg option: '$field'\n";
811 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
813 my $format = sub { shift };
814 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
816 #XXX these should use elements/ fields... (or this whole thing should
817 #just use layer_fields instead of layer_callback)
819 if ( ! exists($href->{$field}{'type'}) ) {
821 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
822 ( exists($options{$field})
823 ? &$format($options{$field})
824 : $href->{$field}{'default'} ).
827 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
829 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
830 ( exists($options{$field}) && $options{$field}
835 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
839 if $href->{$field}{'type'} eq 'select_multiple';
840 $html .= qq! NAME="${layer}__$field">!;
842 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
843 if exists($href->{$field}{'disable_empty'})
844 && ! $href->{$field}{'disable_empty'};
846 if ( $href->{$field}{'select_table'} ) {
848 qsearch( $href->{$field}{'select_table'},
849 $href->{$field}{'select_hash'} )
851 my $value = $record->getfield($href->{$field}{'select_key'});
852 $html .= qq!<OPTION VALUE="$value"!.
853 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
857 '>'. $record->getfield($href->{$field}{'select_label'});
859 } elsif ( $href->{$field}{'select_options'} ) {
860 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
861 my $label = $href->{$field}{'select_options'}{$key};
862 $html .= qq!<OPTION VALUE="$key"!.
863 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
871 $html .= '<font color="#ff0000">warning: '.
872 "don't know how to retreive options for $field select field".
875 $html .= '</SELECT>';
877 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
880 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
882 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
883 my $label = $href->{$field}{'options'}{$key};
884 $html .= qq!$radio VALUE="$key"!.
885 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
894 $html .= '</TD></TR>';
898 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
899 join(',', keys %{ $href } ). '">';
907 options => [ keys %plan_labels ],
908 labels => \%plan_labels,
909 curr_value => $object->plan,
910 layer_callback => $layer_callback,
911 onchange => 'aux_planchanged(what);',
915 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
916 '<SCRIPT TYPE="text/javascript">'.
917 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
920 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
923 $return .= '</SCRIPT>';
929 my %usage_class = map { ($_->classnum => $_->classname) }
930 qsearch('usage_class', {});
931 $usage_class{setup} = 'Setup';
932 $usage_class{recur} = 'Recurring';
934 my %taxproduct_fields = ();
935 my $end_callback = sub {
936 my( $cgi, $object, $fields, $opt ) = @_;
938 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
940 if ( $object->pkgpart ) {
941 foreach my $usage_class ( '', @taxproductnums ) {
942 $tax_override{$usage_class} =
943 join (",", map $_->taxclassnum,
944 qsearch( 'part_pkg_taxoverride', {
945 'pkgpart' => $object->pkgpart,
946 'usage_class' => $usage_class,
953 map { $_ => [ "taxproductnum_$_",
954 { type => 'select-taxproduct',
955 #label => "$usage_class{$_} tax product",
958 { type => 'select-taxoverride' }
963 $taxproduct_fields{'(default)'} =
964 [ 'taxproductnum', { type => 'select-taxproduct',
965 #label => 'Default tax product',
967 'tax_override', { type => 'select-taxoverride' },
971 my $taxproduct_values = sub {
972 my ($cgi, $object, $flags) = @_;
974 sub { my $layer = shift;
975 my @fields = @{$taxproduct_fields{$layer}};
978 my $field = shift @fields;
980 $field =~ /^taxproductnum_\w+$/ &&
981 push @values, ( $field => $options{"usage_$field"} );
982 $field =~ /^tax_override_(\w+)$/ &&
983 push @values, ( $field => $tax_override{$1} );
984 $field =~ /^taxproductnum$/ &&
985 push @values, ( $field => $object->taxproductnum );
986 $field =~ /^tax_override$/ &&
987 push @values, ( $field => $tax_override{''} );
993 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
998 my $field_callback = sub {
999 my ($cgi, $object, $fieldref) = @_;
1001 my $field = $fieldref->{field};
1002 if ($field eq 'taxproductnums') {
1003 $fieldref->{value} = join(',', @taxproductnums);
1004 } elsif ($field eq 'taxproduct_select') {
1005 $fieldref->{options} = [ '(default)', @taxproductnums ];
1006 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1007 map {( $_ => ($usage_class{$_} || $_) )}
1010 $fieldref->{layer_fields} = \%taxproduct_fields;
1011 $fieldref->{layer_values_callback} = $taxproduct_values;
1015 my $discountnum_hashref = {
1017 'months' => { 'op' => '>', 'value' => 1 },