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);
16 aux_planchanged(document.edit_topform.plan)"',
18 'begin_callback' => $begin_callback,
19 'end_callback' => $end_callback,
20 'new_hashref_callback' => $new_hashref_callback,
21 'new_object_callback' => $new_object_callback,
22 'new_callback' => $new_callback,
23 'clone_callback' => $clone_callback,
24 'edit_callback' => $edit_callback,
25 'error_callback' => $error_callback,
26 'field_callback' => $field_callback,
28 'onsubmit' => 'confirm_submit',
31 'pkgpart' => 'Package Definition',
34 'comment' => 'Comment (customer-hidden)',
35 'classnum' => 'Package class',
36 'addon_classnum' => 'Restrict additional orders to package class',
37 'promo_code' => 'Promotional code',
38 'freq' => 'Recurring fee frequency',
39 'setuptax' => 'Setup fee tax exempt',
40 'recurtax' => 'Recurring fee tax exempt',
41 'taxclass' => 'Tax class',
42 'taxproduct_select'=> 'Tax products',
43 'plan' => 'Price plan',
44 'disabled' => 'Disable new orders',
45 'disable_line_item_date_ranges' => 'Disable line item date ranges',
46 'setup_cost' => 'Setup cost',
47 'recur_cost' => 'Recur cost',
48 'pay_weight' => 'Payment weight',
49 'credit_weight' => 'Credit weight',
50 'agentnum' => 'Agent',
51 'setup_fee' => 'Setup fee',
52 'setup_show_zero' => 'Show zero setup',
53 'recur_fee' => 'Recurring fee',
54 'recur_show_zero' => 'Show zero recurring',
55 ( map { ( "setup_fee_$_" => "Setup fee $_",
56 "recur_fee_$_" => "Recurring fee $_",
59 $conf->config('currencies')
61 'discountnum' => 'Offer discounts for longer terms',
62 'bill_dst_pkgpart' => 'Include line item(s) from package',
63 'svc_dst_pkgpart' => 'Include services of package',
64 'supp_dst_pkgpart' => 'Include complete package',
65 'report_option' => 'Report classes',
66 'fcc_ds0s' => 'Voice-grade equivalents',
67 'fcc_voip_class' => 'Category',
71 { field=>'clone', type=>'hidden',
72 curr_value_callback =>
73 sub { shift->param('clone') },
75 { field=>'pkgnum', type=>'hidden',
76 curr_value_callback =>
77 sub { shift->param('pkgnum') },
80 { field=>'custom', type=>'hidden' },
81 { field=>'family_pkgpart', type=>'hidden' },
82 { field=>'successor', type=>'hidden' },
84 { type => 'columnstart' },
92 {field=>'comment', type=>'text', size=>40 }, #32
93 { field => 'agentnum',
94 type => 'select-agent',
95 disable_empty => ! $acl_edit_global,
96 empty_label => '(global)',
97 onchange => 'agent_changed',
99 {field=>'classnum', type=>'select-pkg_class' },
100 ( $conf->exists('pkg-addon_classnum')
101 ? ( { field=>'addon_classnum',
102 type =>'select-pkg_class',
107 {field=>'disabled', type=>$disabled_type, value=>'Y'},
108 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
110 { type => 'tablebreak-tr-title',
111 value => 'Pricing', #better name?
114 type => 'selectlayers-select',
115 options => [ keys %plan_labels ],
116 labels => \%plan_labels,
117 onchange => 'aux_planchanged(what);',
119 { field => 'setup_fee',
121 onchange => 'setup_changed',
123 { field => 'setup_show_zero',
126 disabled => sub { $setup_show_zero_disabled },
128 ( map { +{ field => "setup_fee_$_",
130 prefix=> currency_symbol($_, SYM_HTML),
134 sort $conf->config('currencies')
137 type => 'part_pkg_freq',
138 onchange => 'freq_changed',
140 { field => 'recur_fee',
142 disabled => sub { $recur_disabled },
143 onchange => 'recur_changed',
145 { field => 'recur_show_zero',
148 disabled => sub { $recur_show_zero_disabled },
150 ( map { +{ field => "recur_fee_$_",
152 prefix=> currency_symbol($_, SYM_HTML),
156 sort $conf->config('currencies')
162 #recurring fee (auto-disable)
164 { type => 'columnnext' },
166 {type=>'justtitle', value=>'Taxation' },
167 {field=>'setuptax', type=>'checkbox', value=>'Y'},
168 {field=>'recurtax', type=>'checkbox', value=>'Y'},
169 {field=>'taxclass', type=>'select-taxclass' },
170 { field => 'taxproductnums',
172 value => join(',', @taxproductnums),
174 { field => 'taxproduct_select',
175 type => 'selectlayers',
176 options => [ '(default)', @taxproductnums ],
177 curr_value => '(default)',
178 labels => { ( '(default)' => '(default)' ),
179 map {($_=>$usage_class{$_})}
182 layer_fields => \%taxproduct_fields,
183 layer_values_callback => $taxproduct_values,
184 layers_only => !$taxproducts,
185 cell_style => ( !$taxproducts
191 { type => 'tablebreak-tr-title',
192 value => 'Promotions', #better name?
194 { field=>'promo_code', type=>'text', size=>15 },
196 { type => 'tablebreak-tr-title',
197 value => 'Cost tracking', #better name?
199 { field=>'setup_cost', type=>'money', },
200 { field=>'recur_cost', type=>'money', },
202 { type => 'columnnext' },
204 { field => 'agent_type',
205 type => 'select-agent_types',
206 disabled => ! $acl_edit_global,
207 curr_value_callback => sub {
208 my($cgi, $object, $field) = @_;
209 #in the other callbacks..? hmm.
214 { type => 'tablebreak-tr-title',
215 value => 'Line-item revenue recogition', #better name?
217 { field=>'pay_weight', type=>'text', size=>6 },
218 { field=>'credit_weight', type=>'text', size=>6 },
220 ( $conf->exists('cust_pkg-show_fcc_voice_grade_equivalent')
222 { type => 'tablebreak-tr-title',
223 value => 'FCC Form 477 information',
225 { field=>'fcc_voip_class',
226 type=>'select-voip_class',
228 { field=>'fcc_ds0s', type=>'text', size=>6 },
234 { type => 'columnend' },
236 { 'type' => $report_option ? 'tablebreak-tr-title'
238 'value' => 'Optional report classes',
239 'field' => 'census_title',
241 { 'field' => 'report_option',
242 'type' => $report_option ? 'select-table'
244 'table' => 'part_pkg_report_option',
245 'name_col' => 'name',
246 'hashref' => { 'disabled' => '' },
250 { 'type' => 'tablebreak-tr-title',
251 'value' => 'Term discounts',
253 { 'field' => 'discountnum',
254 'type' => 'select-table',
255 'table' => 'discount',
256 'name_col' => 'name',
257 'hashref' => { %$discountnum_hashref },
258 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
259 'empty_label'=> 'Select discount',
260 'm2_label' => 'Offer discounts for longer terms',
261 'm2m_method' => 'part_pkg_discount',
262 'm2m_dstcol' => 'discountnum',
263 'm2_error_callback' => $discount_error_callback,
266 { 'type' => 'tablebreak-tr-title',
267 'value' => 'Supplemental packages',
270 { 'field' => 'supp_dst_pkgpart',
271 'type' => 'select-part_pkg',
272 'm2_label' => 'Include complete package',
273 'm2m_method' => 'supp_part_pkg_link',
274 'm2m_dstcol' => 'dst_pkgpart',
275 'm2_error_callback' =>
276 &{$m2_error_callback_maker}('supp'),
279 { 'type' => 'tablebreak-tr-title',
280 'value' => 'Pricing add-ons',
283 { 'field' => 'bill_dst_pkgpart',
284 'type' => 'select-part_pkg',
285 'extra_sql' => sub { $pkgpart
286 ? "AND pkgpart != $pkgpart"
289 'm2_label' => 'Include line item(s) from package',
290 'm2m_method' => 'bill_part_pkg_link',
291 'm2m_dstcol' => 'dst_pkgpart',
292 'm2_error_callback' =>
293 &{$m2_error_callback_maker}('bill'),
294 'm2_fields' => [ { 'field' => 'hidden',
295 'type' => 'checkbox',
303 { type => 'tablebreak-tr-title',
306 { type => 'pkg_svc', },
308 { 'field' => 'svc_dst_pkgpart',
309 'label' => 'Also include services from package: ',
310 'type' => 'select-part_pkg',
311 'extra_sql' => sub { $pkgpart
312 ? "AND pkgpart != $pkgpart"
315 'm2_label' => 'Include services of package: ',
316 'm2m_method' => 'svc_part_pkg_link',
317 'm2m_dstcol' => 'dst_pkgpart',
318 'm2_error_callback' =>
319 &{$m2_error_callback_maker}('svc'),
322 { type => 'tablebreak-tr-title',
323 value => 'Price plan options',
330 my $curuser = $FS::CurrentUser::CurrentUser;
332 my $edit_global = 'Edit global package definitions';
333 my $acl_edit = $curuser->access_right('Edit package definitions');
334 my $acl_edit_global = $curuser->access_right($edit_global);
336 my $acl_edit_either = $acl_edit || $acl_edit_global;
338 my $begin_callback = sub {
339 my( $cgi, $fields, $opt ) = @_;
341 unless $acl_edit_either
342 || ( $cgi->param('pkgnum')
343 && $curuser->access_right('Customize customer package')
347 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
349 #arg. access rights for cloning are Hard.
350 # on the one hand we don't really want cloning (customizing a package) to fail
351 # for want of finding the source package in normal usage
352 # on the other hand, we don't want people using the clone link to be able to
354 my $agent_clone_extra_sql =
355 ' ( '. FS::part_pkg->curuser_pkgs_sql.
356 " OR ( part_pkg.custom = 'Y' ) ".
359 my $conf = new FS::Conf;
360 my $taxproducts = $conf->exists('enable_taxproducts');
362 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
363 my %locale_labels = map {
364 ( $_ => 'Package -- '. FS::Locales->description($_) )
367 sort { $locale_labels{$a} cmp $locale_labels{$b} }
371 my %locale_field_labels = (
373 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
378 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
379 " WHERE disabled IS NULL OR disabled = '' ")
381 $sth->execute or die $sth->errstr;
382 my $report_option = $sth->fetchrow_arrayref->[0];
385 # - tr-part_pkg_freq: month_increments_only (from price plans)
387 # - test errors cloning
388 # - test custom pricing
389 # - move the selectlayer divs away from lame layer_callback
391 #my ($query) = $cgi->keywords;
396 my %tax_override = ();
398 my %taxproductnums = map { ($_->classnum => 1) }
399 qsearch('usage_class', { 'disabled' => '' });
400 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
403 my $recur_disabled = 1;
404 my $setup_show_zero_disabled = 0;
405 my $recur_show_zero_disabled = 1;
409 my $splice_locale_fields = sub {
410 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
413 my @locale_fields = (
415 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
416 my $pkg_value = $pkg_value_callback
417 ? $pkg_value_callback eq 'cgiparam'
418 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
419 : &$pkg_value_callback($_)
422 { field => 'pkgpartmsgnum'. $n,
424 value => $pkey_value,
426 { field => 'pkgpartmsgnum'. $n. '_locale',
430 { field => 'pkgpartmsgnum'. $n++. '_pkg',
441 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
445 my $error_callback = sub {
446 my($cgi, $object, $fields, $opt ) = @_;
448 (@agent_type) = $cgi->param('agent_type');
450 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
452 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
454 $recur_disabled = $cgi->param('freq') ? 0 : 1;
455 $recur_show_zero_disabled =
457 ? $cgi->param('recur_fee') > 0 ? 1 : 0
460 foreach ($cgi->param) {
461 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
463 $tax_override{''} = $cgi->param('tax_override');
464 $tax_override{$_} = $cgi->param('tax_override_$_')
465 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
467 #some false laziness w/process
468 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
470 my $options = $cgi->param($plan."__OPTIONS");
471 my @options = split(',', $options);
473 map { my $optionname = $_;
474 my $param = $plan."__$optionname";
475 my $value = join(', ', $cgi->param($param));
476 ( $optionname => $value );
480 $object->set($_ => scalar($cgi->param($_)) )
481 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
483 foreach my $currency ( $conf->config('currencies') ) {
484 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
485 foreach (qw( setup_fee recur_fee )) {
486 my $param = $_.'_'.$currency;
487 $object->set( $param, $cgi->param($param) );
491 $pkgpart = $object->pkgpart;
493 &$splice_locale_fields(
497 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
498 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
505 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
507 my $new_object_callback = sub {
508 my( $cgi, $hashref, $fields, $opt ) = @_;
510 my $part_pkg = FS::part_pkg->new( $hashref );
511 $part_pkg->set($_ => '0')
512 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
518 sub set_report_option {
519 my($cgi, $object, $fields ) = @_; #, $opt
521 my @report_option = ();
522 foreach ($object->options) {
523 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
524 /^report_option_(\d+)$/ && (push @report_option, $1);
526 foreach ($object->part_pkg_taxoverride) {
527 $taxproductnums{$_->usage_class} = 1
531 $cgi->param('report_option', join(',', @report_option));
532 foreach my $field ( @$fields ) {
534 ref($field) eq 'HASH' &&
536 $field->{field} eq 'report_option'
538 #$field->{curr_value} = join(',', @report_option);
539 $field->{value} = join(',', @report_option);
544 my $edit_callback = sub {
545 my( $cgi, $object, $fields, $opt ) = @_;
547 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
549 $recur_disabled = $object->freq ? 0 : 1;
551 $recur_show_zero_disabled =
553 ? $object->option('recur_fee') > 0 ? 1 : 0
557 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
559 set_report_option( $cgi, $object, $fields);
561 %options = $object->options;
563 $object->set($_ => $object->option($_, 1))
564 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
566 foreach my $currency ( $conf->config('currencies') ) {
567 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
568 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
569 foreach keys %part_pkg_currency;
572 $pkgpart = $object->pkgpart;
574 &$splice_locale_fields(
578 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
579 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
583 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
584 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
590 my $new_callback = sub {
591 my( $cgi, $object, $fields ) = @_;
593 my $conf = new FS::Conf;
595 if ( $conf->exists('agent_defaultpkg') ) {
596 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
597 @agent_type = map {$_->typenum} qsearch('agent_type',{});
600 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
602 &$splice_locale_fields($fields, '', '');
606 my $clone_callback = sub {
607 my( $cgi, $object, $fields, $opt ) = @_;
609 if ( $cgi->param('pkgnum') ) {
611 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
612 $object->agentnum( $cust_pkg->cust_main->agentnum );
614 $opt->{action} = 'Custom';
616 #my $part_pkg = $clone_part_pkg->clone;
617 #this is all clone does anyway
618 $object->custom('Y');
620 $object->disabled('Y');
622 } else { #when explicitly cloning, not customizing
625 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
629 set_report_option( $cgi, $object, $fields);
631 %options = $object->options;
633 $object->set($_ => $options{$_})
634 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
636 foreach my $currency ( $conf->config('currencies') ) {
637 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
638 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
639 foreach keys %part_pkg_currency;
642 $recur_disabled = $object->freq ? 0 : 1;
644 &$splice_locale_fields(
649 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
650 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
655 my $discount_error_callback = sub {
656 my( $cgi, $object ) = @_;
658 if ( /^discountnum(\d+)$/ &&
659 ( my $discountnum = $cgi->param("discountnum$1") ) )
661 new FS::part_pkg_discount {
662 'pkgpart' => $object->pkgpart,
663 'discountnum' => $discountnum,
672 my $m2_error_callback_maker = sub {
673 my $link_type = shift; #yay closures
675 my( $cgi, $object ) = @_;
678 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
679 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
682 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
684 new FS::part_pkg_link {
685 'link_type' => $link_type,
686 'src_pkgpart' => $object->pkgpart,
687 'dst_pkgpart' => $dst,
698 my $javascript = <<'END';
699 <SCRIPT TYPE="text/javascript">
701 function freq_changed(what) {
702 var freq = what.options[what.selectedIndex].value;
705 what.form.recur_fee.disabled = true;
706 what.form.recur_fee.style.backgroundColor = '#dddddd';
707 what.form.recur_show_zero.disabled = true;
708 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
710 what.form.recur_fee.disabled = false;
711 what.form.recur_fee.style.backgroundColor = '#ffffff';
712 recur_changed( what.form.recur_fee );
713 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
718 function setup_changed(what) {
719 var setup = what.value;
720 if ( parseFloat(setup) == 0 ) {
721 what.form.setup_show_zero.disabled = false;
723 what.form.setup_show_zero.disabled = true;
727 function recur_changed(what) {
728 var recur = what.value;
729 if ( parseFloat(recur) == 0 ) {
730 what.form.recur_show_zero.disabled = false;
732 what.form.recur_show_zero.disabled = true;
736 function agent_changed(what) {
739 if ( what.type == 'select-one' ) {
740 agentnum = what.options[what.selectedIndex].value;
742 agentnum = what.value;
745 if ( agentnum == 0 ) {
746 what.form.agent_type.disabled = false;
747 //what.form.agent_type.style.backgroundColor = '#ffffff';
748 what.form.agent_type.style.visibility = '';
750 what.form.agent_type.disabled = true;
751 //what.form.agent_type.style.backgroundColor = '#dddddd';
752 what.form.agent_type.style.visibility = 'hidden';
757 function aux_planchanged(what) { //?
759 var plan = what.options[what.selectedIndex].value;
761 var term_table = document.getElementById('TableNumber7') // XXX NOT ROBUST
762 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
763 //term_table.disabled = false;
764 term_table.style.visibility = '';
766 //term_table.disabled = true;
767 term_table.style.visibility = 'hidden';
770 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
773 for ( var i=0; i < form.length; i++ ) {
774 if ( currency_regex.test(form[i].name) ) {
775 if ( plan == 'currency_fixed' ) {
776 form[i].disabled = false;
778 form[i].disabled = true;
788 'Changing the setup or recurring fee will create a new package definition. '.
791 $javascript .= "function confirm_submit(f) {";
792 if ( $conf->exists('part_pkg-lineage') ) {
795 var fields = Array('setup_fee','recur_fee');
796 for(var i=0; i < fields.length; i++) {
797 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
798 return confirm('$warning');
808 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
810 tie my %plan_labels, 'Tie::IxHash',
811 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
814 my $html_bottom = sub {
817 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
819 my $layer_callback = sub {
822 my $html = ntable("#cccccc",2);
826 # <TD ALIGN="right">Recurring fee frequency </TD>
827 # <TD><SELECT NAME="freq">
830 #my @freq = keys %freq;
831 #@freq = grep { /^\d+$/ } @freq
832 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
833 #foreach my $freq ( @freq ) {
834 # $html .= qq(<OPTION VALUE="$freq");
835 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
836 # $html .= ">$freq{$freq}";
839 #$html .= '</SELECT></TD></TR>';
841 my $href = $plans{$layer}->{'fields'};
842 my @fields = exists($plans{$layer}->{'fieldorder'})
843 ? @{$plans{$layer}->{'fieldorder'}}
846 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
848 if(!exists($href->{$field})) {
850 warn "nonexistent part_pkg option: '$field'\n";
854 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
856 my $format = sub { shift };
857 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
859 #XXX these should use elements/ fields... (or this whole thing should
860 #just use layer_fields instead of layer_callback)
862 if ( ! exists($href->{$field}{'type'}) ) {
864 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
865 ( exists($options{$field})
866 ? &$format($options{$field})
867 : $href->{$field}{'default'} ).
870 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
872 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
873 ( exists($options{$field}) && $options{$field}
878 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
882 if $href->{$field}{'type'} eq 'select_multiple';
883 $html .= qq! NAME="${layer}__$field">!;
885 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
886 if exists($href->{$field}{'disable_empty'})
887 && ! $href->{$field}{'disable_empty'};
889 if ( $href->{$field}{'select_table'} ) {
891 qsearch( $href->{$field}{'select_table'},
892 $href->{$field}{'select_hash'} )
894 my $value = $record->getfield($href->{$field}{'select_key'});
895 $html .= qq!<OPTION VALUE="$value"!.
896 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
900 '>'. $record->getfield($href->{$field}{'select_label'});
902 } elsif ( $href->{$field}{'select_options'} ) {
903 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
904 my $label = $href->{$field}{'select_options'}{$key};
905 $html .= qq!<OPTION VALUE="$key"!.
906 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
914 $html .= '<font color="#ff0000">warning: '.
915 "don't know how to retreive options for $field select field".
918 $html .= '</SELECT>';
920 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
923 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
925 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
926 my $label = $href->{$field}{'options'}{$key};
927 $html .= qq!$radio VALUE="$key"!.
928 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
937 $html .= '</TD></TR>';
941 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
942 join(',', keys %{ $href } ). '">';
950 options => [ keys %plan_labels ],
951 labels => \%plan_labels,
952 curr_value => $object->plan,
953 layer_callback => $layer_callback,
954 onchange => 'aux_planchanged(what);',
958 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
959 '<SCRIPT TYPE="text/javascript">'.
960 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
963 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
966 $return .= '</SCRIPT>';
972 my %usage_class = map { ($_->classnum => $_->classname) }
973 qsearch('usage_class', {});
974 $usage_class{setup} = 'Setup';
975 $usage_class{recur} = 'Recurring';
977 my %taxproduct_fields = ();
978 my $end_callback = sub {
979 my( $cgi, $object, $fields, $opt ) = @_;
981 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
983 if ( $object->pkgpart ) {
984 foreach my $usage_class ( '', @taxproductnums ) {
985 $tax_override{$usage_class} =
986 join (",", map $_->taxclassnum,
987 qsearch( 'part_pkg_taxoverride', {
988 'pkgpart' => $object->pkgpart,
989 'usage_class' => $usage_class,
996 map { $_ => [ "taxproductnum_$_",
997 { type => 'select-taxproduct',
998 #label => "$usage_class{$_} tax product",
1001 { type => 'select-taxoverride' }
1006 $taxproduct_fields{'(default)'} =
1007 [ 'taxproductnum', { type => 'select-taxproduct',
1008 #label => 'Default tax product',
1010 'tax_override', { type => 'select-taxoverride' },
1014 my $taxproduct_values = sub {
1015 my ($cgi, $object, $flags) = @_;
1017 sub { my $layer = shift;
1018 my @fields = @{$taxproduct_fields{$layer}};
1021 my $field = shift @fields;
1023 $field =~ /^taxproductnum_\w+$/ &&
1024 push @values, ( $field => $options{"usage_$field"} );
1025 $field =~ /^tax_override_(\w+)$/ &&
1026 push @values, ( $field => $tax_override{$1} );
1027 $field =~ /^taxproductnum$/ &&
1028 push @values, ( $field => $object->taxproductnum );
1029 $field =~ /^tax_override$/ &&
1030 push @values, ( $field => $tax_override{''} );
1036 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1037 return({ @result });
1041 my $field_callback = sub {
1042 my ($cgi, $object, $fieldref) = @_;
1044 my $field = $fieldref->{field};
1045 if ($field eq 'taxproductnums') {
1046 $fieldref->{value} = join(',', @taxproductnums);
1047 } elsif ($field eq 'taxproduct_select') {
1048 $fieldref->{options} = [ '(default)', @taxproductnums ];
1049 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1050 map {( $_ => ($usage_class{$_} || $_) )}
1053 $fieldref->{layer_fields} = \%taxproduct_fields;
1054 $fieldref->{layer_values_callback} = $taxproduct_values;
1058 my $discountnum_hashref = {
1060 'months' => { 'op' => '>', 'value' => 1 },