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