don't consider disabled report classes, don't load up the whole table just to see...
[freeside.git] / httemplate / edit / part_pkg.cgi
1 <% include( 'elements/edit.html',
2               'post_url'              => popurl(1).'process/part_pkg.cgi',
3               'name'                  => "Package definition",
4               'table'                 => 'part_pkg',
5
6               'agent_virt'            => 1,
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').
12                                          $javascript,
13               'html_bottom'           => $html_bottom,
14               'body_etc'              =>
15                 'onLoad="agent_changed(document.edit_topform.agentnum)"',
16
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,
26
27               'labels' => { 
28                             'pkgpart'          => 'Package Definition',
29                             'pkg'              => 'Package (customer-visible)',
30                             'comment'          => 'Comment (customer-hidden)',
31                             'classnum'         => 'Package class',
32                             'addon_classnum'   => 'Restrict additional orders to package class',
33                             'promo_code'       => 'Promotional code',
34                             'freq'             => 'Recurring fee frequency',
35                             'setuptax'         => 'Setup fee tax exempt',
36                             'recurtax'         => 'Recurring fee tax exempt',
37                             'taxclass'         => 'Tax class',
38                             'taxproduct_select'=> 'Tax products',
39                             'plan'             => 'Price plan',
40                             'disabled'         => 'Disable new orders',
41                             'setup_cost'       => 'Setup cost',
42                             'recur_cost'       => 'Recur cost',
43                             'pay_weight'       => 'Payment weight',
44                             'credit_weight'    => 'Credit weight',
45                             'agentnum'         => 'Agent',
46                             'setup_fee'        => 'Setup fee',
47                             'recur_fee'        => 'Recurring fee',
48                             'bill_dst_pkgpart' => 'Include line item(s) from package',
49                             'svc_dst_pkgpart'  => 'Include services of package',
50                             'report_option'    => 'Report classes',
51                           },
52
53               'fields' => [
54                             { field=>'clone',  type=>'hidden',
55                               curr_value_callback =>
56                                 sub { shift->param('clone') },
57                             },
58                             { field=>'pkgnum', type=>'hidden',
59                               curr_value_callback =>
60                                 sub { shift->param('pkgnum') },
61                             },
62
63                             { field=>'custom',  type=>'hidden' },
64
65                             { type => 'columnstart' },
66                             
67                               { field     => 'pkg',
68                                 type      => 'text',
69                                 size      => 40, #32
70                                 maxlength => 50,
71                               },
72                               {field=>'comment',  type=>'text', size=>40 }, #32
73                               { field         => 'agentnum',
74                                 type          => 'select-agent',
75                                 disable_empty => ! $acl_edit_global,
76                                 empty_label   => '(global)',
77                                 onchange      => 'agent_changed',
78                               },
79                               {field=>'classnum', type=>'select-pkg_class' },
80                               ( $conf->exists('pkg-addon_classnum')
81                                   ? ( { field=>'addon_classnum',
82                                         type =>'select-pkg_class',
83                                       }
84                                     )
85                                    : ()
86                               ),
87                               {field=>'disabled', type=>$disabled_type, value=>'Y'},
88
89                               { type  => 'tablebreak-tr-title',
90                                 value => 'Pricing', #better name?
91                               },
92                               { field => 'plan',
93                                 type  => 'selectlayers-select',
94                                 options => [ keys %plan_labels ],
95                                 labels  => \%plan_labels,
96                               },
97                               { field => 'setup_fee',
98                                 type  => 'money',
99                               },
100                               { field    => 'freq',
101                                 type     => 'part_pkg_freq',
102                                 onchange => 'freq_changed',
103                               },
104                               { field    => 'recur_fee',
105                                 type     => 'money',
106                                 disabled => sub { $recur_disabled },
107                               },
108                                 
109                               #price plan
110                               #setup fee
111                               #recurring frequency
112                               #recurring fee (auto-disable)
113
114                             { type => 'columnnext' },
115
116                               {type=>'justtitle', value=>'Taxation' },
117                               {field=>'setuptax', type=>'checkbox', value=>'Y'},
118                               {field=>'recurtax', type=>'checkbox', value=>'Y'},
119                               {field=>'taxclass', type=>'select-taxclass' },
120                               { field => 'taxproductnums',
121                                 type  => 'hidden',
122                                 value => join(',', @taxproductnums),
123                               },
124                               { field => 'taxproduct_select',
125                                 type  => 'selectlayers',
126                                 options => [ '(default)', @taxproductnums ],
127                                 curr_value => '(default)',
128                                 labels  => { ( '(default)' => '(default)' ),
129                                              map {($_=>$usage_class{$_})}
130                                              @taxproductnums
131                                            },
132                                 layer_fields => \%taxproduct_fields,
133                                 layer_values_callback => $taxproduct_values,
134                                 layers_only  =>   !$taxproducts,
135                                 cell_style   => ( !$taxproducts
136                                                   ? 'display:none'
137                                                   : ''
138                                                 ),
139                               },
140
141                               { type  => 'tablebreak-tr-title',
142                                 value => 'Promotions', #better name?
143                               },
144                               { field=>'promo_code', type=>'text', size=>15 },
145
146                               { type  => 'tablebreak-tr-title',
147                                 value => 'Cost tracking', #better name?
148                               },
149                               { field=>'setup_cost', type=>'money', },
150                               { field=>'recur_cost', type=>'money', },
151
152                             { type => 'columnnext' },
153
154                               { field    => 'agent_type',
155                                 type     => 'select-agent_types',
156                                 disabled => ! $acl_edit_global,
157                                 curr_value_callback => sub {
158                                   my($cgi, $object, $field) = @_;
159                                   #in the other callbacks..?  hmm.
160                                   \@agent_type;
161                                 },
162                               },
163
164                               { type  => 'tablebreak-tr-title',
165                                 value => 'Line-item revenue recogition', #better name?
166                               },
167                               { field=>'pay_weight',    type=>'text', size=>6 },
168                               { field=>'credit_weight', type=>'text', size=>6 },
169
170
171                             { type => 'columnend' },
172
173                             { 'type'  => $census ? 'tablebreak-tr-title'
174                                                  : 'hidden',
175                               'value' => 'Optional report classes',
176                               'field' => 'census_title',
177                             },
178                             { 'field'    => 'report_option',
179                               'type'     => $census ? 'select-table' : 'hidden',
180                               'table'    => 'part_pkg_report_option',
181                               'name_col' => 'name',
182                               'multiple' => 1,
183                             },
184
185
186                             { 'type'    => 'tablebreak-tr-title',
187                               'value'   => 'Pricing add-ons',
188                               'colspan' => 4,
189                             },
190                             { 'field'      => 'bill_dst_pkgpart',
191                               'type'       => 'select-part_pkg',
192                               'm2_label'   => 'Include line item(s) from package',
193                               'm2m_method' => 'bill_part_pkg_link',
194                               'm2m_dstcol' => 'dst_pkgpart',
195                               'm2_error_callback' =>
196                                 &{$m2_error_callback_maker}('bill'),
197                               'm2_fields' => [ { 'field' => 'hidden',
198                                                  'type'  => 'checkbox',
199                                                  'value' => 'Y',
200                                                  'curr_value' => '',
201                                                  'label' => 'Bundle',
202                                                },
203                                              ],
204                             },
205
206                             { type  => 'tablebreak-tr-title',
207                               value => 'Services',
208                             },
209                             { type => 'pkg_svc', },
210
211                             { 'field'      => 'svc_dst_pkgpart',
212                               'label'      => 'Also include services from package: ',
213                               'type'       => 'select-part_pkg',
214                               'm2_label'   => 'Include services of package: ',
215                               'm2m_method' => 'svc_part_pkg_link',
216                               'm2m_dstcol' => 'dst_pkgpart',
217                               'm2_error_callback' =>
218                                 &{$m2_error_callback_maker}('svc'),
219                             },
220
221                             { type  => 'tablebreak-tr-title',
222                               value => 'Price plan options',
223                             },
224
225                           ],
226
227            )
228 %>
229 <%init>
230
231 my $curuser = $FS::CurrentUser::CurrentUser;
232
233 my $edit_global = 'Edit global package definitions';
234 my $acl_edit        = $curuser->access_right('Edit package definitions');
235 my $acl_edit_global = $curuser->access_right($edit_global);
236
237 my $acl_edit_either = $acl_edit || $acl_edit_global;
238
239 my $begin_callback = sub {
240   my( $cgi, $fields, $opt ) = @_;
241   die "access denied"
242     unless $acl_edit_either
243         || ( $cgi->param('pkgnum')
244              && $curuser->access_right('Customize customer package')
245            );
246 };
247
248 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
249
250 #arg.  access rights for cloning are Hard.
251 # on the one hand we don't really want cloning (customizing a package) to fail 
252 #  for want of finding the source package in normal usage
253 # on the other hand, we don't want people using the clone link to be able to
254 #  see 
255 my $agent_clone_extra_sql = 
256   ' ( '. FS::part_pkg->curuser_pkgs_sql.
257   "   OR ( part_pkg.custom = 'Y' ) ".
258   ' ) ';
259
260 my $conf = new FS::Conf;
261 my $taxproducts = $conf->exists('enable_taxproducts');
262
263 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
264                        "  WHERE disabled IS NULL OR disabled = ''  ")
265   or die dbh->errstr;
266 $sth->execute or die $sth->errstr;
267 my $census = $sth->fetchrow_arrayref->[0];
268
269 #XXX
270 # - tr-part_pkg_freq: month_increments_only (from price plans)
271 # - test cloning
272 # - test errors cloning
273 # - test custom pricing
274 # - move the selectlayer divs away from lame layer_callback
275
276 #my ($query) = $cgi->keywords;
277 #
278 #my $part_pkg = '';
279
280 my @agent_type = ();
281 my %tax_override = ();
282
283 my %taxproductnums = map { ($_->classnum => 1) }
284                      qsearch('usage_class', { 'disabled' => '' });
285 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
286
287 my %options = ();
288 my $recur_disabled = 1;
289
290 my $error_callback = sub {
291   my($cgi, $object, $fields, $opt ) = @_;
292
293   (@agent_type) = $cgi->param('agent_type');
294
295   $opt->{action} = 'Custom' if $cgi->param('pkgnum');
296
297   $recur_disabled = $cgi->param('freq') ? 0 : 1;
298
299   foreach ($cgi->param) {
300     /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
301   }
302   $tax_override{''} = $cgi->param('tax_override');
303   $tax_override{$_} = $cgi->param('tax_override_$_')
304     foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
305
306   #some false laziness w/process
307   $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
308   my $plan = $1;
309   my $options = $cgi->param($plan."__OPTIONS");
310   my @options = split(',', $options);
311   %options =
312     map { my $optionname = $_;
313           my $param = $plan."__$optionname";
314           my $value = join(', ', $cgi->param($param));
315           ( $optionname => $value );
316         }
317         @options;
318
319   #$cgi->param($_, $options{$_}) foreach (qw( setup_fee recur_fee ));
320   $object->set($_ => scalar($cgi->param($_)) )
321     foreach (qw( setup_fee recur_fee ));
322
323 };
324
325 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
326
327 my $new_object_callback = sub {
328   my( $cgi, $hashref, $fields, $opt ) = @_;
329
330   my $part_pkg = FS::part_pkg->new( $hashref );
331   $part_pkg->set($_ => '0')
332     foreach (qw( setup_fee recur_fee ));
333
334   $part_pkg;
335
336 };
337
338 my $edit_callback = sub {
339   my( $cgi, $object, $fields, $opt ) = @_;
340
341   $recur_disabled = $object->freq ? 0 : 1;
342
343   (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1});
344
345   my @report_option = ();
346   foreach ($object->options) {
347     /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
348     /^report_option_(\d+)$/ && (push @report_option, $1);
349   }
350   foreach ($object->part_pkg_taxoverride) {
351     $taxproductnums{$_->usage_class} = 1
352       if $_->usage_class;
353   }
354
355   $cgi->param('report_option', join(',', @report_option));
356   foreach my $field ( @$fields ) {
357     next unless ( 
358       ref($field) eq 'HASH' &&
359       $field->{field} &&
360       $field->{field} eq 'report_option'
361     );
362     #$field->{curr_value} = join(',', @report_option);
363     $field->{value} = join(',', @report_option);
364   }
365
366   %options = $object->options;
367
368   $object->set($_ => $object->option($_))
369     foreach (qw( setup_fee recur_fee ));
370
371 };
372
373 my $new_callback = sub {
374   my( $cgi, $object, $fields ) = @_;
375
376   my $conf = new FS::Conf; 
377   if ( $conf->exists('agent_defaultpkg') ) {
378     #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
379     @agent_type = map {$_->typenum} qsearch('agent_type',{});
380   }
381
382 };
383
384 my $clone_callback = sub {
385   my( $cgi, $object, $fields, $opt ) = @_;
386
387   if ( $cgi->param('pkgnum') ) {
388
389     my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
390     $object->agentnum( $cust_pkg->cust_main->agentnum );
391
392     $opt->{action} = 'Custom';
393
394     #my $part_pkg = $clone_part_pkg->clone;
395     #this is all clone does anyway
396     $object->custom('Y');
397
398     $object->disabled('Y');
399
400   }
401
402   %options = $object->options;
403
404   $object->set($_ => $options{$_})
405     foreach (qw( setup_fee recur_fee ));
406
407   $recur_disabled = $object->freq ? 0 : 1;
408 };
409
410 my $m2_error_callback_maker = sub {
411   my $link_type = shift; #yay closures
412   return sub {
413     my( $cgi, $object ) = @_;
414     my $num;
415     map {
416
417           if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
418                ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
419           {
420
421             my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
422                          || '';
423             new FS::part_pkg_link {
424               'link_type'   => $link_type,
425               'src_pkgpart' => $object->pkgpart,
426               'dst_pkgpart' => $dst,
427               'hidden'      => $hidden,
428             };
429           } else {
430             ();
431           }
432         }
433     $cgi->param;
434   };
435 };
436
437 my $javascript = <<'END';
438   <SCRIPT TYPE="text/javascript">
439
440     function freq_changed(what) {
441       var freq = what.options[what.selectedIndex].value;
442
443       if ( freq == '0' ) {
444         what.form.recur_fee.disabled = true;
445         what.form.recur_fee.style.backgroundColor = '#dddddd';
446       } else {
447         what.form.recur_fee.disabled = false;
448         what.form.recur_fee.style.backgroundColor = '#ffffff';
449       }
450
451     }
452
453     function agent_changed(what) {
454
455       var agentnum = what.options[what.selectedIndex].value;
456
457       if ( agentnum == 0 ) {
458         what.form.agent_type.disabled = false;
459         //what.form.agent_type.style.backgroundColor = '#ffffff';
460         what.form.agent_type.style.visibility = '';
461       } else {
462         what.form.agent_type.disabled = true;
463         //what.form.agent_type.style.backgroundColor = '#dddddd';
464         what.form.agent_type.style.visibility = 'hidden';
465       }
466
467     }
468
469   </SCRIPT>
470 END
471
472 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
473
474 tie my %plan_labels, 'Tie::IxHash',
475   map {  $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
476       keys %plans;
477
478 my $html_bottom = sub {
479   my( $object ) = @_;
480
481   #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
482
483   my $layer_callback = sub {
484   
485     my $layer = shift;
486     my $html = ntable("#cccccc",2);
487   
488     #$html .= '
489     #  <TR>
490     #    <TD ALIGN="right">Recurring fee frequency </TD>
491     #    <TD><SELECT NAME="freq">
492     #';
493     #
494     #my @freq = keys %freq;
495     #@freq = grep { /^\d+$/ } @freq
496   #XXX this bit#  #  if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
497     #foreach my $freq ( @freq ) {
498     #  $html .= qq(<OPTION VALUE="$freq");
499     #  $html .= ' SELECTED' if $freq eq $part_pkg->freq;
500     #  $html .= ">$freq{$freq}";
501     #}
502     #$html .= '</SELECT></TD></TR>';
503   
504     my $href = $plans{$layer}->{'fields'};
505     my @fields = exists($plans{$layer}->{'fieldorder'})
506                    ? @{$plans{$layer}->{'fieldorder'}}
507                    : keys %{ $href };
508   
509     foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
510   
511       $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
512   
513       my $format = sub { shift };
514       $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
515
516       #XXX these should use elements/ fields... (or this whole thing should
517       #just use layer_fields instead of layer_callback)
518   
519       if ( ! exists($href->{$field}{'type'}) ) {
520   
521         $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
522                  ( exists($options{$field})
523                      ? &$format($options{$field})
524                      : $href->{$field}{'default'} ).
525                  qq!">!;
526   
527       } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
528   
529         $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
530                  ( exists($options{$field}) && $options{$field}
531                    ? ' CHECKED'
532                    : ''
533                  ). '>';
534   
535       } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
536   
537         $html .= '<SELECT';
538         $html .= ' MULTIPLE'
539           if $href->{$field}{'type'} eq 'select_multiple';
540         $html .= qq! NAME="${layer}__$field">!;
541   
542         if ( $href->{$field}{'select_table'} ) {
543           foreach my $record (
544             qsearch( $href->{$field}{'select_table'},
545                      $href->{$field}{'select_hash'}   )
546           ) {
547             my $value = $record->getfield($href->{$field}{'select_key'});
548             $html .= qq!<OPTION VALUE="$value"!.
549                      (  $options{$field} =~ /(^|, *)$value *(,|$)/ #?
550                           ? ' SELECTED'
551                           : ''
552                      ).
553                      '>'. $record->getfield($href->{$field}{'select_label'});
554           }
555         } elsif ( $href->{$field}{'select_options'} ) {
556           foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
557             my $label = $href->{$field}{'select_options'}{$key};
558             $html .= qq!<OPTION VALUE="$key"!.
559                      ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
560                          ? ' SELECTED'
561                          : ''
562                      ).
563                      '>'. $label;
564           }
565   
566         } else {
567           $html .= '<font color="#ff0000">warning: '.
568                    "don't know how to retreive options for $field select field".
569                    '</font>';
570         }
571         $html .= '</SELECT>';
572   
573       } elsif ( $href->{$field}{'type'} eq 'radio' ) {
574   
575         my $radio =
576           qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
577   
578         foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
579           my $label = $href->{$field}{'options'}{$key};
580           $html .= qq!$radio VALUE="$key"!.
581                    ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
582                        ? ' CHECKED'
583                        : ''
584                    ).
585                    "> $label<BR>";
586         }
587   
588       }
589   
590       $html .= '</TD></TR>';
591     }
592     $html .= '</TABLE>';
593   
594     $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
595              join(',', keys %{ $href } ). '">';
596   
597     $html;
598   
599   };
600
601   my %selectlayers = (
602     field          => 'plan',
603     options        => [ keys %plan_labels ],
604     labels         => \%plan_labels,
605     curr_value     => $object->plan,
606     layer_callback => $layer_callback,
607   );
608
609   my $return =
610     include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
611     '<SCRIPT TYPE="text/javascript">'.
612       include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
613
614   $return .=
615     "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
616       if $taxproducts;
617
618   $return .= '</SCRIPT>';
619
620   $return;
621
622 };
623
624 my %usage_class = map { ($_->classnum => $_->classname) }
625                   qsearch('usage_class', {});
626 $usage_class{setup} = 'Setup';
627 $usage_class{recur} = 'Recurring';
628
629 my %taxproduct_fields = ();
630 my $end_callback = sub {
631   my( $cgi, $object, $fields, $opt ) = @_;
632
633   @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
634
635   if ( $object->pkgpart ) {
636     foreach my $usage_class ( '', @taxproductnums ) {
637       $tax_override{$usage_class} =
638         join (",", map $_->taxclassnum,
639                        qsearch( 'part_pkg_taxoverride', {
640                                   'pkgpart'     => $object->pkgpart,
641                                   'usage_class' => $usage_class,
642                               })
643              );
644     }
645   }
646
647   %taxproduct_fields =
648     map { $_ => [ "taxproductnum_$_", 
649                   { type  => 'select-taxproduct',
650                     #label => "$usage_class{$_} tax product",
651                   },
652                   "tax_override_$_", 
653                   { type  => 'select-taxoverride' }
654                 ]
655         }
656         @taxproductnums;
657
658   $taxproduct_fields{'(default)'} =
659     [ 'taxproductnum', { type => 'select-taxproduct',
660                          #label => 'Default tax product',
661                        },
662       'tax_override',  { type => 'select-taxoverride' },
663     ];
664 };
665
666 my $taxproduct_values = sub {
667   my ($cgi, $object, $flags) = @_;
668   my $routine =
669     sub { my $layer = shift;
670           my @fields = @{$taxproduct_fields{$layer}};
671           my @values = ();
672           while( @fields ) {
673             my $field = shift @fields;
674             shift @fields;
675             $field =~ /^taxproductnum_\w+$/ &&
676               push @values, ( $field => $options{"usage_$field"} );
677             $field =~ /^tax_override_(\w+)$/ &&
678               push @values, ( $field => $tax_override{$1} );
679             $field =~ /^taxproductnum$/ &&
680               push @values, ( $field => $object->taxproductnum );
681             $field =~ /^tax_override$/ &&
682               push @values, ( $field => $tax_override{''} );
683           }
684           { (@values) };
685         };
686   
687   my @result = 
688     map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
689   return({ @result });
690   
691 };
692
693 my $field_callback = sub {
694   my ($cgi, $object, $fieldref) = @_;
695
696   my $field = $fieldref->{field};
697   if ($field eq 'taxproductnums') {
698     $fieldref->{value} = join(',', @taxproductnums);
699   } elsif ($field eq 'taxproduct_select') {
700     $fieldref->{options} = [ '(default)', @taxproductnums ];
701     $fieldref->{labels}  = { ( '(default)' => '(default)' ),
702                              map {( $_ => ($usage_class{$_} || $_) )}
703                                @taxproductnums
704                            };
705     $fieldref->{layer_fields} = \%taxproduct_fields;
706     $fieldref->{layer_values_callback} = $taxproduct_values;
707   }
708 };
709
710 </%init>