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);
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 'discountnum' => 'Offer discounts for longer terms',
56 'bill_dst_pkgpart' => 'Include line item(s) from package',
57 'svc_dst_pkgpart' => 'Include services of package',
58 'supp_dst_pkgpart' => 'When ordering package, also order',
59 'report_option' => 'Report classes',
60 'fcc_ds0s' => 'Voice-grade equivalents',
61 'fcc_voip_class' => 'Category',
62 'delay_start' => 'Default delay (days)',
66 { field=>'clone', type=>'hidden',
67 curr_value_callback =>
68 sub { shift->param('clone') },
70 { field=>'pkgnum', type=>'hidden',
71 curr_value_callback =>
72 sub { shift->param('pkgnum') },
75 { field=>'custom', type=>'hidden' },
76 { field=>'family_pkgpart', type=>'hidden' },
77 { field=>'successor', type=>'hidden' },
79 { type => 'columnstart' },
87 {field=>'comment', type=>'text', size=>40 }, #32
88 { field => 'agentnum',
89 type => 'select-agent',
90 disable_empty => ! $acl_edit_global,
91 empty_label => '(global)',
92 onchange => 'agent_changed',
94 {field=>'classnum', type=>'select-pkg_class' },
95 ( $conf->exists('pkg-addon_classnum')
96 ? ( { field=>'addon_classnum',
97 type =>'select-pkg_class',
102 {field=>'disabled', type=>$disabled_type, value=>'Y'},
103 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
105 { type => 'tablebreak-tr-title',
106 value => 'Pricing', #better name?
109 type => 'selectlayers-select',
110 options => [ keys %plan_labels ],
111 labels => \%plan_labels,
112 onchange => 'aux_planchanged(what);',
114 { field => 'setup_fee',
116 onchange => 'setup_changed',
118 { field => 'setup_show_zero',
121 disabled => sub { $setup_show_zero_disabled },
124 type => 'part_pkg_freq',
125 onchange => 'freq_changed',
127 { field => 'recur_fee',
129 disabled => sub { $recur_disabled },
130 onchange => 'recur_changed',
133 { field => 'recur_show_zero',
136 disabled => sub { $recur_show_zero_disabled },
142 #recurring fee (auto-disable)
144 { type => 'columnnext' },
146 {type=>'justtitle', value=>'Taxation' },
147 {field=>'setuptax', type=>'checkbox', value=>'Y'},
148 {field=>'recurtax', type=>'checkbox', value=>'Y'},
149 {field=>'taxclass', type=>'select-taxclass' },
150 { field => 'taxproductnums',
152 value => join(',', @taxproductnums),
154 { field => 'taxproduct_select',
155 type => 'selectlayers',
156 options => [ '(default)', @taxproductnums ],
157 curr_value => '(default)',
158 labels => { ( '(default)' => '(default)' ),
159 map {($_=>$usage_class{$_})}
162 layer_fields => \%taxproduct_fields,
163 layer_values_callback => $taxproduct_values,
164 layers_only => !$taxproducts,
165 cell_style => ( !$taxproducts
171 { type => 'tablebreak-tr-title',
172 value => 'Promotions', #better name?
174 { field=>'promo_code', type=>'text', size=>15 },
176 { type => 'tablebreak-tr-title',
177 value => 'Cost tracking', #better name?
180 ( $curuser->access_right('Edit package definition costs')
181 ? ( { field=>'setup_cost', type=>'money', },
182 { field=>'recur_cost', type=>'money', },
184 : ( { field=>'setup_cost', type=>'fixed', },
185 { field=>'recur_cost', type=>'fixed', },
189 ( $conf->exists('part_pkg-delay_start')
190 ? ( { type => 'tablebreak-tr-title',
191 value => 'Delayed start',
193 { field => 'delay_start',
194 type => 'text', size => 6 },
199 { type => 'columnnext' },
201 { field => 'agent_type',
202 type => 'select-agent_types',
203 disabled => ! $acl_edit_global,
204 curr_value_callback => sub {
205 my($cgi, $object, $field) = @_;
206 #in the other callbacks..? hmm.
211 { type => 'tablebreak-tr-title',
212 value => 'Line-item revenue recogition', #better name?
214 { field=>'pay_weight', type=>'text', size=>6 },
215 { field=>'credit_weight', type=>'text', size=>6 },
217 ( $conf->exists('cust_pkg-show_fcc_voice_grade_equivalent')
219 { type => 'tablebreak-tr-title',
220 value => 'FCC Form 477 information',
222 { field=>'fcc_voip_class',
223 type=>'select-voip_class',
225 { field=>'fcc_ds0s', type=>'text', size=>6 },
230 { type => 'columnend' },
232 { 'type' => $report_option ? 'tablebreak-tr-title'
234 'value' => 'Optional report classes',
235 'field' => 'census_title',
237 { 'field' => 'report_option',
238 'type' => $report_option ? 'select-table'
240 'table' => 'part_pkg_report_option',
241 'name_col' => 'name',
242 'hashref' => { 'disabled' => '' },
246 { 'type' => 'tablebreak-tr-title',
247 'value' => 'Term discounts',
249 { 'field' => 'discountnum',
250 'type' => 'select-table',
251 'table' => 'discount',
252 'name_col' => 'name',
253 'hashref' => { %$discountnum_hashref },
254 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
255 'empty_label'=> 'Select discount',
256 'm2_label' => 'Offer discounts for longer terms',
257 'm2m_method' => 'part_pkg_discount',
258 'm2m_dstcol' => 'discountnum',
259 'm2_error_callback' => $discount_error_callback,
262 { 'type' => 'tablebreak-tr-title',
263 'value' => 'Pricing add-ons',
266 { 'field' => 'bill_dst_pkgpart',
267 'type' => 'select-part_pkg',
268 'extra_sql' => sub { $pkgpart
269 ? "AND pkgpart != $pkgpart"
272 'm2_label' => 'Include line item(s) from package',
273 'm2m_method' => 'bill_part_pkg_link',
274 'm2m_dstcol' => 'dst_pkgpart',
275 'm2_error_callback' =>
276 &{$m2_error_callback_maker}('bill'),
277 'm2_fields' => [ { 'field' => 'hidden',
278 'type' => 'checkbox',
286 { type => 'tablebreak-tr-title',
289 { type => 'pkg_svc', },
291 { 'field' => 'svc_dst_pkgpart',
292 'label' => 'Also include services from package: ',
293 'type' => 'select-part_pkg',
294 'extra_sql' => sub { $pkgpart
295 ? "AND pkgpart != $pkgpart"
298 'm2_label' => 'Include services of package: ',
299 'm2m_method' => 'svc_part_pkg_link',
300 'm2m_dstcol' => 'dst_pkgpart',
301 'm2_error_callback' =>
302 &{$m2_error_callback_maker}('svc'),
305 { 'type' => 'tablebreak-tr-title',
306 'value' => 'Supplemental packages',
308 'include_opt_callback' => sub {
309 'id' => 'show_supp_pkgs',
312 { 'field' => 'supp_dst_pkgpart',
313 'type' => 'select-part_pkg',
314 'm2_label' => 'When ordering package, also order',
315 'm2m_method' => 'supp_part_pkg_link',
316 'm2m_dstcol' => 'dst_pkgpart',
317 'm2_error_callback' =>
318 &{$m2_error_callback_maker}('supp'),
321 { type => 'tablebreak-tr-title',
322 value => 'Price plan options',
331 my $curuser = $FS::CurrentUser::CurrentUser;
333 my $edit_global = 'Edit global package definitions';
334 my $acl_edit = $curuser->access_right('Edit package definitions');
335 my $acl_edit_global = $curuser->access_right($edit_global);
337 my $acl_edit_either = $acl_edit || $acl_edit_global;
339 my $begin_callback = sub {
340 my( $cgi, $fields, $opt ) = @_;
342 unless $acl_edit_either
343 || ( $cgi->param('pkgnum')
344 && $curuser->access_right('Customize customer package')
348 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
350 #arg. access rights for cloning are Hard.
351 # on the one hand we don't really want cloning (customizing a package) to fail
352 # for want of finding the source package in normal usage
353 # on the other hand, we don't want people using the clone link to be able to
355 my $agent_clone_extra_sql =
356 ' ( '. FS::part_pkg->curuser_pkgs_sql.
357 " OR ( part_pkg.custom = 'Y' ) ".
360 my $conf = new FS::Conf;
361 my $taxproducts = $conf->exists('enable_taxproducts');
363 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
364 my %locale_labels = map {
365 ( $_ => 'Package -- '. FS::Locales->description($_) )
368 sort { $locale_labels{$a} cmp $locale_labels{$b} }
372 my %locale_field_labels = (
374 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
379 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
380 " WHERE disabled IS NULL OR disabled = '' ")
382 $sth->execute or die $sth->errstr;
383 my $report_option = $sth->fetchrow_arrayref->[0];
386 # - tr-part_pkg_freq: month_increments_only (from price plans)
388 # - test errors cloning
389 # - test custom pricing
390 # - move the selectlayer divs away from lame layer_callback
392 #my ($query) = $cgi->keywords;
397 my %tax_override = ();
399 my %taxproductnums = map { ($_->classnum => 1) }
400 qsearch('usage_class', { 'disabled' => '' });
401 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
404 my $recur_disabled = 1;
405 my $setup_show_zero_disabled = 0;
406 my $recur_show_zero_disabled = 1;
410 my $splice_locale_fields = sub {
411 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
414 my @locale_fields = (
416 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
417 my $pkg_value = $pkg_value_callback
418 ? $pkg_value_callback eq 'cgiparam'
419 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
420 : &$pkg_value_callback($_)
423 { field => 'pkgpartmsgnum'. $n,
425 value => $pkey_value,
427 { field => 'pkgpartmsgnum'. $n. '_locale',
431 { field => 'pkgpartmsgnum'. $n++. '_pkg',
442 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
446 my $error_callback = sub {
447 my($cgi, $object, $fields, $opt ) = @_;
449 (@agent_type) = $cgi->param('agent_type');
451 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
453 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
455 $recur_disabled = $cgi->param('freq') ? 0 : 1;
456 $recur_show_zero_disabled =
458 ? $cgi->param('recur_fee') > 0 ? 1 : 0
461 foreach ($cgi->param) {
462 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
464 $tax_override{''} = $cgi->param('tax_override');
465 $tax_override{$_} = $cgi->param('tax_override_$_')
466 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
468 #some false laziness w/process
469 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
471 my $options = $cgi->param($plan."__OPTIONS");
472 my @options = split(',', $options);
474 map { my $optionname = $_;
475 my $param = $plan."__$optionname";
476 my $value = join(', ', $cgi->param($param));
477 ( $optionname => $value );
481 $object->set($_ => scalar($cgi->param($_)) )
482 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
484 $pkgpart = $object->pkgpart;
486 &$splice_locale_fields(
490 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
491 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
498 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
500 my $new_object_callback = sub {
501 my( $cgi, $hashref, $fields, $opt ) = @_;
503 my $part_pkg = FS::part_pkg->new( $hashref );
504 $part_pkg->set($_ => '0')
505 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
511 sub set_report_option {
512 my($cgi, $object, $fields ) = @_; #, $opt
514 my @report_option = ();
515 foreach ($object->options) {
516 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
517 /^report_option_(\d+)$/ && (push @report_option, $1);
519 foreach ($object->part_pkg_taxoverride) {
520 $taxproductnums{$_->usage_class} = 1
524 $cgi->param('report_option', join(',', @report_option));
525 foreach my $field ( @$fields ) {
527 ref($field) eq 'HASH' &&
529 $field->{field} eq 'report_option'
531 #$field->{curr_value} = join(',', @report_option);
532 $field->{value} = join(',', @report_option);
537 my $edit_callback = sub {
538 my( $cgi, $object, $fields, $opt ) = @_;
540 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
542 $recur_disabled = $object->freq ? 0 : 1;
544 $recur_show_zero_disabled =
546 ? $object->option('recur_fee') > 0 ? 1 : 0
550 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
552 set_report_option( $cgi, $object, $fields);
554 %options = $object->options;
556 $object->set($_ => $object->option($_, 1))
557 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
559 $pkgpart = $object->pkgpart;
561 &$splice_locale_fields(
565 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
566 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
570 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
571 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
577 my $new_callback = sub {
578 my( $cgi, $object, $fields ) = @_;
580 my $conf = new FS::Conf;
582 if ( $conf->exists('agent_defaultpkg') ) {
583 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
584 @agent_type = map {$_->typenum} qsearch('agent_type',{});
587 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
589 &$splice_locale_fields($fields, '', '');
593 my $clone_callback = sub {
594 my( $cgi, $object, $fields, $opt ) = @_;
596 if ( $cgi->param('pkgnum') ) {
598 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
599 $object->agentnum( $cust_pkg->cust_main->agentnum );
601 $opt->{action} = 'Custom';
603 #my $part_pkg = $clone_part_pkg->clone;
604 #this is all clone does anyway
605 $object->custom('Y');
607 $object->disabled('Y');
609 } else { #when explicitly cloning, not customizing
612 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
616 set_report_option( $cgi, $object, $fields);
618 %options = $object->options;
620 $object->set($_ => $options{$_})
621 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
623 $recur_disabled = $object->freq ? 0 : 1;
625 &$splice_locale_fields(
630 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
631 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
636 my $discount_error_callback = sub {
637 my( $cgi, $object ) = @_;
639 if ( /^discountnum(\d+)$/ &&
640 ( my $discountnum = $cgi->param("discountnum$1") ) )
642 new FS::part_pkg_discount {
643 'pkgpart' => $object->pkgpart,
644 'discountnum' => $discountnum,
653 my $m2_error_callback_maker = sub {
654 my $link_type = shift; #yay closures
656 my( $cgi, $object ) = @_;
659 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
660 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
663 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
665 new FS::part_pkg_link {
666 'link_type' => $link_type,
667 'src_pkgpart' => $object->pkgpart,
668 'dst_pkgpart' => $dst,
679 my $javascript = <<'END';
680 <SCRIPT TYPE="text/javascript">
682 function freq_changed(what) {
683 var freq = what.options[what.selectedIndex].value;
686 what.form.recur_fee.disabled = true;
687 what.form.recur_fee.style.backgroundColor = '#dddddd';
688 what.form.recur_show_zero.disabled = true;
689 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
691 what.form.recur_fee.disabled = false;
692 what.form.recur_fee.style.backgroundColor = '#ffffff';
693 recur_changed( what.form.recur_fee );
694 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
699 function setup_changed(what) {
700 var setup = what.value;
701 if ( parseFloat(setup) == 0 ) {
702 what.form.setup_show_zero.disabled = false;
704 what.form.setup_show_zero.disabled = true;
708 function recur_changed(what) {
709 var recur = what.value;
710 if ( parseFloat(recur) == 0 ) {
711 what.form.recur_show_zero.disabled = false;
713 what.form.recur_show_zero.disabled = true;
717 function agent_changed(what) {
720 if ( what.type == 'select-one' ) {
721 agentnum = what.options[what.selectedIndex].value;
723 agentnum = what.value;
726 if ( agentnum == 0 ) {
727 what.form.agent_type.disabled = false;
728 //what.form.agent_type.style.backgroundColor = '#ffffff';
729 what.form.agent_type.style.visibility = '';
731 what.form.agent_type.disabled = true;
732 //what.form.agent_type.style.backgroundColor = '#dddddd';
733 what.form.agent_type.style.visibility = 'hidden';
738 function aux_planchanged(what) { //?
740 var plan = what.options[what.selectedIndex].value;
741 var table = document.getElementById('TableNumber6') // XXX NOT ROBUST
743 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
744 //table.disabled = false;
745 table.style.visibility = '';
747 //table.disabled = true;
748 table.style.visibility = 'hidden';
753 // some magic to make "supplemental packages" less obvious
754 var supp_pkg_rows = [];
755 function show_supp_pkgs_click() {
756 supp_pkg_rows[0].style.display = '';
758 this.style.backgroundColor = '';
759 this.style.border = '';
760 this.style.padding = '';
763 function hide_supp_pkgs() {
764 var all_selects = document.getElementsByTagName('select');
765 for (var i=0; i < all_selects.length; i++) {
766 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
767 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
770 if ( supp_pkg_rows.length == 1 ) {
771 // there are none configured, so hide the row to create a new one
772 supp_pkg_rows[0].style.display = 'none';
773 var button = document.getElementById('show_supp_pkgs');
774 button.onclick = show_supp_pkgs_click;
775 button.style.backgroundColor = '#cccccc';
776 button.style.border = '1px solid #7e0079';
777 button.style.padding = '1px';
784 'Changing the setup or recurring fee will create a new package definition. '.
787 $javascript .= "function confirm_submit(f) {";
788 if ( $conf->exists('part_pkg-lineage') ) {
791 var fields = Array('setup_fee','recur_fee');
792 for(var i=0; i < fields.length; i++) {
793 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
794 return confirm('$warning');
804 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
806 tie my %plan_labels, 'Tie::IxHash',
807 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
810 my $html_bottom = sub {
813 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
815 my $layer_callback = sub {
818 my $html = ntable("#cccccc",2);
822 # <TD ALIGN="right">Recurring fee frequency </TD>
823 # <TD><SELECT NAME="freq">
826 #my @freq = keys %freq;
827 #@freq = grep { /^\d+$/ } @freq
828 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
829 #foreach my $freq ( @freq ) {
830 # $html .= qq(<OPTION VALUE="$freq");
831 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
832 # $html .= ">$freq{$freq}";
835 #$html .= '</SELECT></TD></TR>';
837 my $href = $plans{$layer}->{'fields'};
838 my @fields = exists($plans{$layer}->{'fieldorder'})
839 ? @{$plans{$layer}->{'fieldorder'}}
842 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
844 if(!exists($href->{$field})) {
846 warn "nonexistent part_pkg option: '$field'\n";
849 if ( exists($href->{$field}->{display_if}) ) {
850 my %args = ( 'plan' => $layer ); # anything else?
851 my $display = &{ $href->{$field}->{display_if} }(%args);
855 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
857 my $format = sub { shift };
858 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
860 #XXX these should use elements/ fields... (or this whole thing should
861 #just use layer_fields instead of layer_callback)
863 if ( ! exists($href->{$field}{'type'}) ) {
865 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
866 ( exists($options{$field})
867 ? &$format($options{$field})
868 : $href->{$field}{'default'} ).
871 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
873 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
874 ( exists($options{$field}) && $options{$field}
879 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
883 if $href->{$field}{'type'} eq 'select_multiple';
884 $html .= qq! NAME="${layer}__$field">!;
886 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
887 if exists($href->{$field}{'disable_empty'})
888 && ! $href->{$field}{'disable_empty'};
890 if ( $href->{$field}{'select_table'} ) {
892 qsearch( $href->{$field}{'select_table'},
893 $href->{$field}{'select_hash'} )
895 my $value = $record->getfield($href->{$field}{'select_key'});
896 $html .= qq!<OPTION VALUE="$value"!.
897 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
901 '>'. $record->getfield($href->{$field}{'select_label'});
903 } elsif ( $href->{$field}{'select_options'} ) {
904 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
905 my $label = $href->{$field}{'select_options'}{$key};
906 $html .= qq!<OPTION VALUE="$key"!.
907 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
915 $html .= '<font color="#ff0000">warning: '.
916 "don't know how to retreive options for $field select field".
919 $html .= '</SELECT>';
921 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
924 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
926 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
927 my $label = $href->{$field}{'options'}{$key};
928 $html .= qq!$radio VALUE="$key"!.
929 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
938 $html .= '</TD></TR>';
942 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
943 join(',', keys %{ $href } ). '">';
951 options => [ keys %plan_labels ],
952 labels => \%plan_labels,
953 curr_value => $object->plan,
954 layer_callback => $layer_callback,
955 onchange => 'aux_planchanged(what);',
959 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
960 '<SCRIPT TYPE="text/javascript">'.
961 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
964 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
967 $return .= '</SCRIPT>';
973 my %usage_class = map { ($_->classnum => $_->classname) }
974 qsearch('usage_class', {});
975 $usage_class{setup} = 'Setup';
976 $usage_class{recur} = 'Recurring';
978 my %taxproduct_fields = ();
979 my $end_callback = sub {
980 my( $cgi, $object, $fields, $opt ) = @_;
982 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
984 if ( $object->pkgpart ) {
985 foreach my $usage_class ( '', @taxproductnums ) {
986 $tax_override{$usage_class} =
987 join (",", map $_->taxclassnum,
988 qsearch( 'part_pkg_taxoverride', {
989 'pkgpart' => $object->pkgpart,
990 'usage_class' => $usage_class,
997 map { $_ => [ "taxproductnum_$_",
998 { type => 'select-taxproduct',
999 #label => "$usage_class{$_} tax product",
1002 { type => 'select-taxoverride' }
1007 $taxproduct_fields{'(default)'} =
1008 [ 'taxproductnum', { type => 'select-taxproduct',
1009 #label => 'Default tax product',
1011 'tax_override', { type => 'select-taxoverride' },
1015 my $taxproduct_values = sub {
1016 my ($cgi, $object, $flags) = @_;
1018 sub { my $layer = shift;
1019 my @fields = @{$taxproduct_fields{$layer}};
1022 my $field = shift @fields;
1024 $field =~ /^taxproductnum_\w+$/ &&
1025 push @values, ( $field => $options{"usage_$field"} );
1026 $field =~ /^tax_override_(\w+)$/ &&
1027 push @values, ( $field => $tax_override{$1} );
1028 $field =~ /^taxproductnum$/ &&
1029 push @values, ( $field => $object->taxproductnum );
1030 $field =~ /^tax_override$/ &&
1031 push @values, ( $field => $tax_override{''} );
1037 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1038 return({ @result });
1042 my $field_callback = sub {
1043 my ($cgi, $object, $fieldref) = @_;
1045 my $field = $fieldref->{field};
1046 if ($field eq 'taxproductnums') {
1047 $fieldref->{value} = join(',', @taxproductnums);
1048 } elsif ($field eq 'taxproduct_select') {
1049 $fieldref->{options} = [ '(default)', @taxproductnums ];
1050 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1051 map {( $_ => ($usage_class{$_} || $_) )}
1054 $fieldref->{layer_fields} = \%taxproduct_fields;
1055 $fieldref->{layer_values_callback} = $taxproduct_values;
1059 my $discountnum_hashref = {
1061 'months' => { 'op' => '>', 'value' => 1 },