1 <% include( 'elements/edit.html',
2 'post_url' => popurl(1).'process/part_pkg.cgi',
3 'name' => "Package definition",
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').
13 'html_bottom' => $html_bottom,
15 'onLoad="agent_changed(document.edit_topform.agentnum);
18 'begin_callback' => $begin_callback,
19 'end_callback' => $end_callback,
20 'new_hashref_callback' => $new_hashref_callback,
21 'new_object_callback' => $new_object_callback,
22 'new_callback' => $new_callback,
23 'clone_callback' => $clone_callback,
24 'edit_callback' => $edit_callback,
25 'error_callback' => $error_callback,
26 'field_callback' => $field_callback,
28 'onsubmit' => 'confirm_submit',
31 'pkgpart' => 'Package Definition',
34 'comment' => 'Comment (customer-hidden)',
35 'classnum' => 'Package class',
36 'addon_classnum' => 'Restrict additional orders to package class',
37 'promo_code' => 'Promotional code',
38 'freq' => 'Recurring fee frequency',
39 'setuptax' => 'Setup fee tax exempt',
40 'recurtax' => 'Recurring fee tax exempt',
41 'taxclass' => 'Tax class',
42 'taxproduct_select'=> 'Tax products',
43 'plan' => 'Price plan',
44 'disabled' => 'Disable new orders',
45 'disable_line_item_date_ranges' => 'Disable line item date ranges',
46 'setup_cost' => 'Setup cost',
47 'recur_cost' => 'Recur cost',
48 'pay_weight' => 'Payment weight',
49 'credit_weight' => 'Credit weight',
50 'agentnum' => 'Agent',
51 'setup_fee' => 'Setup fee',
52 'setup_show_zero' => 'Show zero setup',
53 'recur_fee' => 'Recurring fee',
54 'recur_show_zero' => 'Show zero recurring',
55 'discountnum' => 'Offer discounts for longer terms',
56 'bill_dst_pkgpart' => 'Include line item(s) from package',
57 'svc_dst_pkgpart' => 'Include services of package',
58 'supp_dst_pkgpart' => 'When ordering package, also order',
59 'report_option' => 'Report classes',
60 'fcc_ds0s' => 'Voice-grade equivalents',
61 'fcc_voip_class' => 'Category',
62 'delay_start' => 'Default delay (days)',
66 { field=>'clone', type=>'hidden',
67 curr_value_callback =>
68 sub { shift->param('clone') },
70 { field=>'pkgnum', type=>'hidden',
71 curr_value_callback =>
72 sub { shift->param('pkgnum') },
75 { field=>'custom', type=>'hidden' },
76 { field=>'family_pkgpart', type=>'hidden' },
77 { field=>'successor', type=>'hidden' },
79 { type => 'columnstart' },
87 {field=>'comment', type=>'text', size=>40 }, #32
88 { field => 'agentnum',
89 type => 'select-agent',
90 disable_empty => ! $acl_edit_global,
91 empty_label => '(global)',
92 onchange => 'agent_changed',
94 {field=>'classnum', type=>'select-pkg_class' },
95 ( $conf->exists('pkg-addon_classnum')
96 ? ( { field=>'addon_classnum',
97 type =>'select-pkg_class',
102 {field=>'disabled', type=>$disabled_type, value=>'Y'},
103 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
105 { type => 'tablebreak-tr-title',
106 value => 'Pricing', #better name?
109 type => 'selectlayers-select',
110 options => [ keys %plan_labels ],
111 labels => \%plan_labels,
112 onchange => 'aux_planchanged(what);',
114 { field => 'setup_fee',
116 onchange => 'setup_changed',
118 { field => 'setup_show_zero',
121 disabled => sub { $setup_show_zero_disabled },
124 type => 'part_pkg_freq',
125 onchange => 'freq_changed',
127 { field => 'recur_fee',
129 disabled => sub { $recur_disabled },
130 onchange => 'recur_changed',
133 { field => 'recur_show_zero',
136 disabled => sub { $recur_show_zero_disabled },
142 #recurring fee (auto-disable)
144 { type => 'columnnext' },
146 {type=>'justtitle', value=>'Taxation' },
147 {field=>'setuptax', type=>'checkbox', value=>'Y'},
148 {field=>'recurtax', type=>'checkbox', value=>'Y'},
149 {field=>'taxclass', type=>'select-taxclass' },
150 { field => 'taxproductnums',
152 value => join(',', @taxproductnums),
154 { field => 'taxproduct_select',
155 type => 'selectlayers',
156 options => [ '(default)', @taxproductnums ],
157 curr_value => '(default)',
158 labels => { ( '(default)' => '(default)' ),
159 map {($_=>$usage_class{$_})}
162 layer_fields => \%taxproduct_fields,
163 layer_values_callback => $taxproduct_values,
164 layers_only => !$taxproducts,
165 cell_style => ( !$taxproducts
171 { type => 'tablebreak-tr-title',
172 value => 'Promotions', #better name?
174 { field=>'promo_code', type=>'text', size=>15 },
176 { type => 'tablebreak-tr-title',
177 value => 'Cost tracking', #better name?
179 { field=>'setup_cost', type=>'money', },
180 { field=>'recur_cost', type=>'money', },
182 ( $conf->exists('part_pkg-delay_start')
183 ? ( { type => 'tablebreak-tr-title',
184 value => 'Delayed start',
186 { field => 'delay_start',
187 type => 'text', size => 6 },
192 { type => 'columnnext' },
194 { field => 'agent_type',
195 type => 'select-agent_types',
196 disabled => ! $acl_edit_global,
197 curr_value_callback => sub {
198 my($cgi, $object, $field) = @_;
199 #in the other callbacks..? hmm.
204 { type => 'tablebreak-tr-title',
205 value => 'Line-item revenue recogition', #better name?
207 { field=>'pay_weight', type=>'text', size=>6 },
208 { field=>'credit_weight', type=>'text', size=>6 },
210 ( $conf->exists('cust_pkg-show_fcc_voice_grade_equivalent')
212 { type => 'tablebreak-tr-title',
213 value => 'FCC Form 477 information',
215 { field=>'fcc_voip_class',
216 type=>'select-voip_class',
218 { field=>'fcc_ds0s', type=>'text', size=>6 },
223 { type => 'columnend' },
225 { 'type' => $report_option ? 'tablebreak-tr-title'
227 'value' => 'Optional report classes',
228 'field' => 'census_title',
230 { 'field' => 'report_option',
231 'type' => $report_option ? 'select-table'
233 'table' => 'part_pkg_report_option',
234 'name_col' => 'name',
235 'hashref' => { 'disabled' => '' },
239 { 'type' => 'tablebreak-tr-title',
240 'value' => 'Term discounts',
242 { 'field' => 'discountnum',
243 'type' => 'select-table',
244 'table' => 'discount',
245 'name_col' => 'name',
246 'hashref' => { %$discountnum_hashref },
247 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
248 'empty_label'=> 'Select discount',
249 'm2_label' => 'Offer discounts for longer terms',
250 'm2m_method' => 'part_pkg_discount',
251 'm2m_dstcol' => 'discountnum',
252 'm2_error_callback' => $discount_error_callback,
255 { 'type' => 'tablebreak-tr-title',
256 'value' => 'Pricing add-ons',
259 { 'field' => 'bill_dst_pkgpart',
260 'type' => 'select-part_pkg',
261 'extra_sql' => sub { $pkgpart
262 ? "AND pkgpart != $pkgpart"
265 'm2_label' => 'Include line item(s) from package',
266 'm2m_method' => 'bill_part_pkg_link',
267 'm2m_dstcol' => 'dst_pkgpart',
268 'm2_error_callback' =>
269 &{$m2_error_callback_maker}('bill'),
270 'm2_fields' => [ { 'field' => 'hidden',
271 'type' => 'checkbox',
279 { type => 'tablebreak-tr-title',
282 { type => 'pkg_svc', },
284 { 'field' => 'svc_dst_pkgpart',
285 'label' => 'Also include services from package: ',
286 'type' => 'select-part_pkg',
287 'extra_sql' => sub { $pkgpart
288 ? "AND pkgpart != $pkgpart"
291 'm2_label' => 'Include services of package: ',
292 'm2m_method' => 'svc_part_pkg_link',
293 'm2m_dstcol' => 'dst_pkgpart',
294 'm2_error_callback' =>
295 &{$m2_error_callback_maker}('svc'),
298 { 'type' => 'tablebreak-tr-title',
299 'value' => 'Supplemental packages',
301 'include_opt_callback' => sub {
302 'id' => 'show_supp_pkgs',
305 { 'field' => 'supp_dst_pkgpart',
306 'type' => 'select-part_pkg',
307 'm2_label' => 'When ordering package, also order',
308 'm2m_method' => 'supp_part_pkg_link',
309 'm2m_dstcol' => 'dst_pkgpart',
310 'm2_error_callback' =>
311 &{$m2_error_callback_maker}('supp'),
314 { type => 'tablebreak-tr-title',
315 value => 'Price plan options',
324 my $curuser = $FS::CurrentUser::CurrentUser;
326 my $edit_global = 'Edit global package definitions';
327 my $acl_edit = $curuser->access_right('Edit package definitions');
328 my $acl_edit_global = $curuser->access_right($edit_global);
330 my $acl_edit_either = $acl_edit || $acl_edit_global;
332 my $begin_callback = sub {
333 my( $cgi, $fields, $opt ) = @_;
335 unless $acl_edit_either
336 || ( $cgi->param('pkgnum')
337 && $curuser->access_right('Customize customer package')
341 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
343 #arg. access rights for cloning are Hard.
344 # on the one hand we don't really want cloning (customizing a package) to fail
345 # for want of finding the source package in normal usage
346 # on the other hand, we don't want people using the clone link to be able to
348 my $agent_clone_extra_sql =
349 ' ( '. FS::part_pkg->curuser_pkgs_sql.
350 " OR ( part_pkg.custom = 'Y' ) ".
353 my $conf = new FS::Conf;
354 my $taxproducts = $conf->exists('enable_taxproducts');
356 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
357 my %locale_labels = map {
358 ( $_ => 'Package -- '. FS::Locales->description($_) )
361 sort { $locale_labels{$a} cmp $locale_labels{$b} }
365 my %locale_field_labels = (
367 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
372 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
373 " WHERE disabled IS NULL OR disabled = '' ")
375 $sth->execute or die $sth->errstr;
376 my $report_option = $sth->fetchrow_arrayref->[0];
379 # - tr-part_pkg_freq: month_increments_only (from price plans)
381 # - test errors cloning
382 # - test custom pricing
383 # - move the selectlayer divs away from lame layer_callback
385 #my ($query) = $cgi->keywords;
390 my %tax_override = ();
392 my %taxproductnums = map { ($_->classnum => 1) }
393 qsearch('usage_class', { 'disabled' => '' });
394 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
397 my $recur_disabled = 1;
398 my $setup_show_zero_disabled = 0;
399 my $recur_show_zero_disabled = 1;
403 my $splice_locale_fields = sub {
404 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
407 my @locale_fields = (
409 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
410 my $pkg_value = $pkg_value_callback
411 ? $pkg_value_callback eq 'cgiparam'
412 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
413 : &$pkg_value_callback($_)
416 { field => 'pkgpartmsgnum'. $n,
418 value => $pkey_value,
420 { field => 'pkgpartmsgnum'. $n. '_locale',
424 { field => 'pkgpartmsgnum'. $n++. '_pkg',
435 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
439 my $error_callback = sub {
440 my($cgi, $object, $fields, $opt ) = @_;
442 (@agent_type) = $cgi->param('agent_type');
444 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
446 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
448 $recur_disabled = $cgi->param('freq') ? 0 : 1;
449 $recur_show_zero_disabled =
451 ? $cgi->param('recur_fee') > 0 ? 1 : 0
454 foreach ($cgi->param) {
455 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
457 $tax_override{''} = $cgi->param('tax_override');
458 $tax_override{$_} = $cgi->param('tax_override_$_')
459 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
461 #some false laziness w/process
462 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
464 my $options = $cgi->param($plan."__OPTIONS");
465 my @options = split(',', $options);
467 map { my $optionname = $_;
468 my $param = $plan."__$optionname";
469 my $value = join(', ', $cgi->param($param));
470 ( $optionname => $value );
474 $object->set($_ => scalar($cgi->param($_)) )
475 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
477 $pkgpart = $object->pkgpart;
479 &$splice_locale_fields(
483 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
484 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
491 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
493 my $new_object_callback = sub {
494 my( $cgi, $hashref, $fields, $opt ) = @_;
496 my $part_pkg = FS::part_pkg->new( $hashref );
497 $part_pkg->set($_ => '0')
498 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
504 sub set_report_option {
505 my($cgi, $object, $fields ) = @_; #, $opt
507 my @report_option = ();
508 foreach ($object->options) {
509 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
510 /^report_option_(\d+)$/ && (push @report_option, $1);
512 foreach ($object->part_pkg_taxoverride) {
513 $taxproductnums{$_->usage_class} = 1
517 $cgi->param('report_option', join(',', @report_option));
518 foreach my $field ( @$fields ) {
520 ref($field) eq 'HASH' &&
522 $field->{field} eq 'report_option'
524 #$field->{curr_value} = join(',', @report_option);
525 $field->{value} = join(',', @report_option);
530 my $edit_callback = sub {
531 my( $cgi, $object, $fields, $opt ) = @_;
533 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
535 $recur_disabled = $object->freq ? 0 : 1;
537 $recur_show_zero_disabled =
539 ? $object->option('recur_fee') > 0 ? 1 : 0
543 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
545 set_report_option( $cgi, $object, $fields);
547 %options = $object->options;
549 $object->set($_ => $object->option($_, 1))
550 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
552 $pkgpart = $object->pkgpart;
554 &$splice_locale_fields(
558 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
559 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
563 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
564 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
570 my $new_callback = sub {
571 my( $cgi, $object, $fields ) = @_;
573 my $conf = new FS::Conf;
575 if ( $conf->exists('agent_defaultpkg') ) {
576 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
577 @agent_type = map {$_->typenum} qsearch('agent_type',{});
580 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
582 &$splice_locale_fields($fields, '', '');
586 my $clone_callback = sub {
587 my( $cgi, $object, $fields, $opt ) = @_;
589 if ( $cgi->param('pkgnum') ) {
591 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
592 $object->agentnum( $cust_pkg->cust_main->agentnum );
594 $opt->{action} = 'Custom';
596 #my $part_pkg = $clone_part_pkg->clone;
597 #this is all clone does anyway
598 $object->custom('Y');
600 $object->disabled('Y');
602 } else { #when explicitly cloning, not customizing
605 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
609 set_report_option( $cgi, $object, $fields);
611 %options = $object->options;
613 $object->set($_ => $options{$_})
614 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
616 $recur_disabled = $object->freq ? 0 : 1;
618 &$splice_locale_fields(
623 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
624 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
629 my $discount_error_callback = sub {
630 my( $cgi, $object ) = @_;
632 if ( /^discountnum(\d+)$/ &&
633 ( my $discountnum = $cgi->param("discountnum$1") ) )
635 new FS::part_pkg_discount {
636 'pkgpart' => $object->pkgpart,
637 'discountnum' => $discountnum,
646 my $m2_error_callback_maker = sub {
647 my $link_type = shift; #yay closures
649 my( $cgi, $object ) = @_;
652 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
653 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
656 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
658 new FS::part_pkg_link {
659 'link_type' => $link_type,
660 'src_pkgpart' => $object->pkgpart,
661 'dst_pkgpart' => $dst,
672 my $javascript = <<'END';
673 <SCRIPT TYPE="text/javascript">
675 function freq_changed(what) {
676 var freq = what.options[what.selectedIndex].value;
679 what.form.recur_fee.disabled = true;
680 what.form.recur_fee.style.backgroundColor = '#dddddd';
681 what.form.recur_show_zero.disabled = true;
682 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
684 what.form.recur_fee.disabled = false;
685 what.form.recur_fee.style.backgroundColor = '#ffffff';
686 recur_changed( what.form.recur_fee );
687 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
692 function setup_changed(what) {
693 var setup = what.value;
694 if ( parseFloat(setup) == 0 ) {
695 what.form.setup_show_zero.disabled = false;
697 what.form.setup_show_zero.disabled = true;
701 function recur_changed(what) {
702 var recur = what.value;
703 if ( parseFloat(recur) == 0 ) {
704 what.form.recur_show_zero.disabled = false;
706 what.form.recur_show_zero.disabled = true;
710 function agent_changed(what) {
713 if ( what.type == 'select-one' ) {
714 agentnum = what.options[what.selectedIndex].value;
716 agentnum = what.value;
719 if ( agentnum == 0 ) {
720 what.form.agent_type.disabled = false;
721 //what.form.agent_type.style.backgroundColor = '#ffffff';
722 what.form.agent_type.style.visibility = '';
724 what.form.agent_type.disabled = true;
725 //what.form.agent_type.style.backgroundColor = '#dddddd';
726 what.form.agent_type.style.visibility = 'hidden';
731 function aux_planchanged(what) { //?
733 var plan = what.options[what.selectedIndex].value;
734 var table = document.getElementById('TableNumber6') // XXX NOT ROBUST
736 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
737 //table.disabled = false;
738 table.style.visibility = '';
740 //table.disabled = true;
741 table.style.visibility = 'hidden';
746 // some magic to make "supplemental packages" less obvious
747 var supp_pkg_rows = [];
748 function show_supp_pkgs_click() {
749 supp_pkg_rows[0].style.display = '';
751 this.style.backgroundColor = '';
752 this.style.border = '';
753 this.style.padding = '';
756 function hide_supp_pkgs() {
757 var all_selects = document.getElementsByTagName('select');
758 for (var i=0; i < all_selects.length; i++) {
759 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
760 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
763 if ( supp_pkg_rows.length == 1 ) {
764 // there are none configured, so hide the row to create a new one
765 supp_pkg_rows[0].style.display = 'none';
766 var button = document.getElementById('show_supp_pkgs');
767 button.onclick = show_supp_pkgs_click;
768 button.style.backgroundColor = '#cccccc';
769 button.style.border = '1px solid #7e0079';
770 button.style.padding = '1px';
777 'Changing the setup or recurring fee will create a new package definition. '.
780 $javascript .= "function confirm_submit(f) {";
781 if ( $conf->exists('part_pkg-lineage') ) {
784 var fields = Array('setup_fee','recur_fee');
785 for(var i=0; i < fields.length; i++) {
786 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
787 return confirm('$warning');
797 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
799 tie my %plan_labels, 'Tie::IxHash',
800 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
803 my $html_bottom = sub {
806 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
808 my $layer_callback = sub {
811 my $html = ntable("#cccccc",2);
815 # <TD ALIGN="right">Recurring fee frequency </TD>
816 # <TD><SELECT NAME="freq">
819 #my @freq = keys %freq;
820 #@freq = grep { /^\d+$/ } @freq
821 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
822 #foreach my $freq ( @freq ) {
823 # $html .= qq(<OPTION VALUE="$freq");
824 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
825 # $html .= ">$freq{$freq}";
828 #$html .= '</SELECT></TD></TR>';
830 my $href = $plans{$layer}->{'fields'};
831 my @fields = exists($plans{$layer}->{'fieldorder'})
832 ? @{$plans{$layer}->{'fieldorder'}}
835 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
837 if(!exists($href->{$field})) {
839 warn "nonexistent part_pkg option: '$field'\n";
842 if ( exists($href->{$field}->{display_if}) ) {
843 my %args = ( 'plan' => $layer ); # anything else?
844 my $display = &{ $href->{$field}->{display_if} }(%args);
848 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
850 my $format = sub { shift };
851 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
853 #XXX these should use elements/ fields... (or this whole thing should
854 #just use layer_fields instead of layer_callback)
856 if ( ! exists($href->{$field}{'type'}) ) {
858 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
859 ( exists($options{$field})
860 ? &$format($options{$field})
861 : $href->{$field}{'default'} ).
864 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
866 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
867 ( exists($options{$field}) && $options{$field}
872 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
876 if $href->{$field}{'type'} eq 'select_multiple';
877 $html .= qq! NAME="${layer}__$field">!;
879 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
880 if exists($href->{$field}{'disable_empty'})
881 && ! $href->{$field}{'disable_empty'};
883 if ( $href->{$field}{'select_table'} ) {
885 qsearch( $href->{$field}{'select_table'},
886 $href->{$field}{'select_hash'} )
888 my $value = $record->getfield($href->{$field}{'select_key'});
889 $html .= qq!<OPTION VALUE="$value"!.
890 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
894 '>'. $record->getfield($href->{$field}{'select_label'});
896 } elsif ( $href->{$field}{'select_options'} ) {
897 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
898 my $label = $href->{$field}{'select_options'}{$key};
899 $html .= qq!<OPTION VALUE="$key"!.
900 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
908 $html .= '<font color="#ff0000">warning: '.
909 "don't know how to retreive options for $field select field".
912 $html .= '</SELECT>';
914 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
917 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
919 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
920 my $label = $href->{$field}{'options'}{$key};
921 $html .= qq!$radio VALUE="$key"!.
922 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
931 $html .= '</TD></TR>';
935 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
936 join(',', keys %{ $href } ). '">';
944 options => [ keys %plan_labels ],
945 labels => \%plan_labels,
946 curr_value => $object->plan,
947 layer_callback => $layer_callback,
948 onchange => 'aux_planchanged(what);',
952 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
953 '<SCRIPT TYPE="text/javascript">'.
954 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
957 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
960 $return .= '</SCRIPT>';
966 my %usage_class = map { ($_->classnum => $_->classname) }
967 qsearch('usage_class', {});
968 $usage_class{setup} = 'Setup';
969 $usage_class{recur} = 'Recurring';
971 my %taxproduct_fields = ();
972 my $end_callback = sub {
973 my( $cgi, $object, $fields, $opt ) = @_;
975 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
977 if ( $object->pkgpart ) {
978 foreach my $usage_class ( '', @taxproductnums ) {
979 $tax_override{$usage_class} =
980 join (",", map $_->taxclassnum,
981 qsearch( 'part_pkg_taxoverride', {
982 'pkgpart' => $object->pkgpart,
983 'usage_class' => $usage_class,
990 map { $_ => [ "taxproductnum_$_",
991 { type => 'select-taxproduct',
992 #label => "$usage_class{$_} tax product",
995 { type => 'select-taxoverride' }
1000 $taxproduct_fields{'(default)'} =
1001 [ 'taxproductnum', { type => 'select-taxproduct',
1002 #label => 'Default tax product',
1004 'tax_override', { type => 'select-taxoverride' },
1008 my $taxproduct_values = sub {
1009 my ($cgi, $object, $flags) = @_;
1011 sub { my $layer = shift;
1012 my @fields = @{$taxproduct_fields{$layer}};
1015 my $field = shift @fields;
1017 $field =~ /^taxproductnum_\w+$/ &&
1018 push @values, ( $field => $options{"usage_$field"} );
1019 $field =~ /^tax_override_(\w+)$/ &&
1020 push @values, ( $field => $tax_override{$1} );
1021 $field =~ /^taxproductnum$/ &&
1022 push @values, ( $field => $object->taxproductnum );
1023 $field =~ /^tax_override$/ &&
1024 push @values, ( $field => $tax_override{''} );
1030 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1031 return({ @result });
1035 my $field_callback = sub {
1036 my ($cgi, $object, $fieldref) = @_;
1038 my $field = $fieldref->{field};
1039 if ($field eq 'taxproductnums') {
1040 $fieldref->{value} = join(',', @taxproductnums);
1041 } elsif ($field eq 'taxproduct_select') {
1042 $fieldref->{options} = [ '(default)', @taxproductnums ];
1043 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1044 map {( $_ => ($usage_class{$_} || $_) )}
1047 $fieldref->{layer_fields} = \%taxproduct_fields;
1048 $fieldref->{layer_values_callback} = $taxproduct_values;
1052 my $discountnum_hashref = {
1054 'months' => { 'op' => '>', 'value' => 1 },