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