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