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