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);
16 aux_planchanged(document.edit_topform.plan)"',
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 ( map { ( "setup_fee_$_" => "Setup fee $_",
56 "recur_fee_$_" => "Recurring fee $_",
59 $conf->config('currencies')
61 'discountnum' => 'Offer discounts for longer terms',
62 'bill_dst_pkgpart' => 'Include line item(s) from package',
63 'svc_dst_pkgpart' => 'Include services of package',
64 'supp_dst_pkgpart' => 'Include complete package',
65 'report_option' => 'Report classes',
66 'fcc_ds0s' => 'Voice-grade equivalents',
67 'fcc_voip_class' => 'Category',
68 'delay_start' => 'Default delay (days)',
72 { field=>'clone', type=>'hidden',
73 curr_value_callback =>
74 sub { shift->param('clone') },
76 { field=>'pkgnum', type=>'hidden',
77 curr_value_callback =>
78 sub { shift->param('pkgnum') },
81 { field=>'custom', type=>'hidden' },
82 { field=>'family_pkgpart', type=>'hidden' },
83 { field=>'successor', type=>'hidden' },
85 { type => 'columnstart' },
93 {field=>'comment', type=>'text', size=>40 }, #32
94 { field => 'agentnum',
95 type => 'select-agent',
96 disable_empty => ! $acl_edit_global,
97 empty_label => '(global)',
98 onchange => 'agent_changed',
100 {field=>'classnum', type=>'select-pkg_class' },
101 ( $conf->exists('pkg-addon_classnum')
102 ? ( { field=>'addon_classnum',
103 type =>'select-pkg_class',
108 {field=>'disabled', type=>$disabled_type, value=>'Y'},
109 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
111 { type => 'tablebreak-tr-title',
112 value => 'Pricing', #better name?
115 type => 'selectlayers-select',
116 options => [ keys %plan_labels ],
117 labels => \%plan_labels,
118 onchange => 'aux_planchanged(what);',
120 { field => 'setup_fee',
122 onchange => 'setup_changed',
124 { field => 'setup_show_zero',
127 disabled => sub { $setup_show_zero_disabled },
129 ( map { +{ field => "setup_fee_$_",
131 prefix=> currency_symbol($_, SYM_HTML),
135 sort $conf->config('currencies')
138 type => 'part_pkg_freq',
139 onchange => 'freq_changed',
141 { field => 'recur_fee',
143 disabled => sub { $recur_disabled },
144 onchange => 'recur_changed',
146 { field => 'recur_show_zero',
149 disabled => sub { $recur_show_zero_disabled },
151 ( map { +{ field => "recur_fee_$_",
153 prefix=> currency_symbol($_, SYM_HTML),
157 sort $conf->config('currencies')
163 #recurring fee (auto-disable)
165 { type => 'columnnext' },
167 {type=>'justtitle', value=>'Taxation' },
168 {field=>'setuptax', type=>'checkbox', value=>'Y'},
169 {field=>'recurtax', type=>'checkbox', value=>'Y'},
170 {field=>'taxclass', type=>'select-taxclass' },
171 { field => 'taxproductnums',
173 value => join(',', @taxproductnums),
175 { field => 'taxproduct_select',
176 type => 'selectlayers',
177 options => [ '(default)', @taxproductnums ],
178 curr_value => '(default)',
179 labels => { ( '(default)' => '(default)' ),
180 map {($_=>$usage_class{$_})}
183 layer_fields => \%taxproduct_fields,
184 layer_values_callback => $taxproduct_values,
185 layers_only => !$taxproducts,
186 cell_style => ( !$taxproducts
192 { type => 'tablebreak-tr-title',
193 value => 'Promotions', #better name?
195 { field=>'promo_code', type=>'text', size=>15 },
197 { type => 'tablebreak-tr-title',
198 value => 'Cost tracking', #better name?
200 { field=>'setup_cost', type=>'money', },
201 { field=>'recur_cost', type=>'money', },
203 ( $conf->exists('part_pkg-delay_start')
204 ? ( { type => 'tablebreak-tr-title',
205 value => 'Delayed start',
207 { field => 'delay_start',
208 type => 'text', size => 6 },
213 { type => 'columnnext' },
215 { field => 'agent_type',
216 type => 'select-agent_types',
217 disabled => ! $acl_edit_global,
218 curr_value_callback => sub {
219 my($cgi, $object, $field) = @_;
220 #in the other callbacks..? hmm.
225 { type => 'tablebreak-tr-title',
226 value => 'Line-item revenue recogition', #better name?
228 { field=>'pay_weight', type=>'text', size=>6 },
229 { field=>'credit_weight', type=>'text', size=>6 },
231 ( $conf->exists('cust_pkg-show_fcc_voice_grade_equivalent')
233 { type => 'tablebreak-tr-title',
234 value => 'FCC Form 477 information',
236 { field=>'fcc_voip_class',
237 type=>'select-voip_class',
239 { field=>'fcc_ds0s', type=>'text', size=>6 },
245 { type => 'columnend' },
247 { 'type' => $report_option ? 'tablebreak-tr-title'
249 'value' => 'Optional report classes',
250 'field' => 'census_title',
252 { 'field' => 'report_option',
253 'type' => $report_option ? 'select-table'
255 'table' => 'part_pkg_report_option',
256 'name_col' => 'name',
257 'hashref' => { 'disabled' => '' },
261 { 'type' => 'tablebreak-tr-title',
262 'value' => 'Term discounts',
264 { 'field' => 'discountnum',
265 'type' => 'select-table',
266 'table' => 'discount',
267 'name_col' => 'name',
268 'hashref' => { %$discountnum_hashref },
269 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
270 'empty_label'=> 'Select discount',
271 'm2_label' => 'Offer discounts for longer terms',
272 'm2m_method' => 'part_pkg_discount',
273 'm2m_dstcol' => 'discountnum',
274 'm2_error_callback' => $discount_error_callback,
277 { 'type' => 'tablebreak-tr-title',
278 'value' => 'Supplemental packages',
281 { 'field' => 'supp_dst_pkgpart',
282 'type' => 'select-part_pkg',
283 'm2_label' => 'Include complete package',
284 'm2m_method' => 'supp_part_pkg_link',
285 'm2m_dstcol' => 'dst_pkgpart',
286 'm2_error_callback' =>
287 &{$m2_error_callback_maker}('supp'),
290 { 'type' => 'tablebreak-tr-title',
291 'value' => 'Pricing add-ons',
294 { 'field' => 'bill_dst_pkgpart',
295 'type' => 'select-part_pkg',
296 'extra_sql' => sub { $pkgpart
297 ? "AND pkgpart != $pkgpart"
300 'm2_label' => 'Include line item(s) from package',
301 'm2m_method' => 'bill_part_pkg_link',
302 'm2m_dstcol' => 'dst_pkgpart',
303 'm2_error_callback' =>
304 &{$m2_error_callback_maker}('bill'),
305 'm2_fields' => [ { 'field' => 'hidden',
306 'type' => 'checkbox',
314 { type => 'tablebreak-tr-title',
317 { type => 'pkg_svc', },
319 { 'field' => 'svc_dst_pkgpart',
320 'label' => 'Also include services from package: ',
321 'type' => 'select-part_pkg',
322 'extra_sql' => sub { $pkgpart
323 ? "AND pkgpart != $pkgpart"
326 'm2_label' => 'Include services of package: ',
327 'm2m_method' => 'svc_part_pkg_link',
328 'm2m_dstcol' => 'dst_pkgpart',
329 'm2_error_callback' =>
330 &{$m2_error_callback_maker}('svc'),
333 { type => 'tablebreak-tr-title',
334 value => 'Price plan options',
341 my $curuser = $FS::CurrentUser::CurrentUser;
343 my $edit_global = 'Edit global package definitions';
344 my $acl_edit = $curuser->access_right('Edit package definitions');
345 my $acl_edit_global = $curuser->access_right($edit_global);
347 my $acl_edit_either = $acl_edit || $acl_edit_global;
349 my $begin_callback = sub {
350 my( $cgi, $fields, $opt ) = @_;
352 unless $acl_edit_either
353 || ( $cgi->param('pkgnum')
354 && $curuser->access_right('Customize customer package')
358 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
360 #arg. access rights for cloning are Hard.
361 # on the one hand we don't really want cloning (customizing a package) to fail
362 # for want of finding the source package in normal usage
363 # on the other hand, we don't want people using the clone link to be able to
365 my $agent_clone_extra_sql =
366 ' ( '. FS::part_pkg->curuser_pkgs_sql.
367 " OR ( part_pkg.custom = 'Y' ) ".
370 my $conf = new FS::Conf;
371 my $taxproducts = $conf->exists('enable_taxproducts');
373 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
374 my %locale_labels = map {
375 ( $_ => 'Package -- '. FS::Locales->description($_) )
378 sort { $locale_labels{$a} cmp $locale_labels{$b} }
382 my %locale_field_labels = (
384 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
389 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
390 " WHERE disabled IS NULL OR disabled = '' ")
392 $sth->execute or die $sth->errstr;
393 my $report_option = $sth->fetchrow_arrayref->[0];
396 # - tr-part_pkg_freq: month_increments_only (from price plans)
398 # - test errors cloning
399 # - test custom pricing
400 # - move the selectlayer divs away from lame layer_callback
402 #my ($query) = $cgi->keywords;
407 my %tax_override = ();
409 my %taxproductnums = map { ($_->classnum => 1) }
410 qsearch('usage_class', { 'disabled' => '' });
411 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
414 my $recur_disabled = 1;
415 my $setup_show_zero_disabled = 0;
416 my $recur_show_zero_disabled = 1;
420 my $splice_locale_fields = sub {
421 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
424 my @locale_fields = (
426 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
427 my $pkg_value = $pkg_value_callback
428 ? $pkg_value_callback eq 'cgiparam'
429 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
430 : &$pkg_value_callback($_)
433 { field => 'pkgpartmsgnum'. $n,
435 value => $pkey_value,
437 { field => 'pkgpartmsgnum'. $n. '_locale',
441 { field => 'pkgpartmsgnum'. $n++. '_pkg',
452 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
456 my $error_callback = sub {
457 my($cgi, $object, $fields, $opt ) = @_;
459 (@agent_type) = $cgi->param('agent_type');
461 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
463 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
465 $recur_disabled = $cgi->param('freq') ? 0 : 1;
466 $recur_show_zero_disabled =
468 ? $cgi->param('recur_fee') > 0 ? 1 : 0
471 foreach ($cgi->param) {
472 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
474 $tax_override{''} = $cgi->param('tax_override');
475 $tax_override{$_} = $cgi->param('tax_override_$_')
476 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
478 #some false laziness w/process
479 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
481 my $options = $cgi->param($plan."__OPTIONS");
482 my @options = split(',', $options);
484 map { my $optionname = $_;
485 my $param = $plan."__$optionname";
486 my $value = join(', ', $cgi->param($param));
487 ( $optionname => $value );
491 $object->set($_ => scalar($cgi->param($_)) )
492 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
494 foreach my $currency ( $conf->config('currencies') ) {
495 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
496 foreach (qw( setup_fee recur_fee )) {
497 my $param = $_.'_'.$currency;
498 $object->set( $param, $cgi->param($param) );
502 $pkgpart = $object->pkgpart;
504 &$splice_locale_fields(
508 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
509 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
516 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
518 my $new_object_callback = sub {
519 my( $cgi, $hashref, $fields, $opt ) = @_;
521 my $part_pkg = FS::part_pkg->new( $hashref );
522 $part_pkg->set($_ => '0')
523 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
529 sub set_report_option {
530 my($cgi, $object, $fields ) = @_; #, $opt
532 my @report_option = ();
533 foreach ($object->options) {
534 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
535 /^report_option_(\d+)$/ && (push @report_option, $1);
537 foreach ($object->part_pkg_taxoverride) {
538 $taxproductnums{$_->usage_class} = 1
542 $cgi->param('report_option', join(',', @report_option));
543 foreach my $field ( @$fields ) {
545 ref($field) eq 'HASH' &&
547 $field->{field} eq 'report_option'
549 #$field->{curr_value} = join(',', @report_option);
550 $field->{value} = join(',', @report_option);
555 my $edit_callback = sub {
556 my( $cgi, $object, $fields, $opt ) = @_;
558 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
560 $recur_disabled = $object->freq ? 0 : 1;
562 $recur_show_zero_disabled =
564 ? $object->option('recur_fee') > 0 ? 1 : 0
568 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
570 set_report_option( $cgi, $object, $fields);
572 %options = $object->options;
574 $object->set($_ => $object->option($_, 1))
575 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
577 foreach my $currency ( $conf->config('currencies') ) {
578 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
579 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
580 foreach keys %part_pkg_currency;
583 $pkgpart = $object->pkgpart;
585 &$splice_locale_fields(
589 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
590 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
594 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
595 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
601 my $new_callback = sub {
602 my( $cgi, $object, $fields ) = @_;
604 my $conf = new FS::Conf;
606 if ( $conf->exists('agent_defaultpkg') ) {
607 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
608 @agent_type = map {$_->typenum} qsearch('agent_type',{});
611 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
613 &$splice_locale_fields($fields, '', '');
617 my $clone_callback = sub {
618 my( $cgi, $object, $fields, $opt ) = @_;
620 if ( $cgi->param('pkgnum') ) {
622 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
623 $object->agentnum( $cust_pkg->cust_main->agentnum );
625 $opt->{action} = 'Custom';
627 #my $part_pkg = $clone_part_pkg->clone;
628 #this is all clone does anyway
629 $object->custom('Y');
631 $object->disabled('Y');
633 } else { #when explicitly cloning, not customizing
636 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
640 set_report_option( $cgi, $object, $fields);
642 %options = $object->options;
644 $object->set($_ => $options{$_})
645 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
647 foreach my $currency ( $conf->config('currencies') ) {
648 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
649 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
650 foreach keys %part_pkg_currency;
653 $recur_disabled = $object->freq ? 0 : 1;
655 &$splice_locale_fields(
660 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
661 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
666 my $discount_error_callback = sub {
667 my( $cgi, $object ) = @_;
669 if ( /^discountnum(\d+)$/ &&
670 ( my $discountnum = $cgi->param("discountnum$1") ) )
672 new FS::part_pkg_discount {
673 'pkgpart' => $object->pkgpart,
674 'discountnum' => $discountnum,
683 my $m2_error_callback_maker = sub {
684 my $link_type = shift; #yay closures
686 my( $cgi, $object ) = @_;
689 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
690 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
693 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
695 new FS::part_pkg_link {
696 'link_type' => $link_type,
697 'src_pkgpart' => $object->pkgpart,
698 'dst_pkgpart' => $dst,
709 my $javascript = <<'END';
710 <SCRIPT TYPE="text/javascript">
712 function freq_changed(what) {
713 var freq = what.options[what.selectedIndex].value;
716 what.form.recur_fee.disabled = true;
717 what.form.recur_fee.style.backgroundColor = '#dddddd';
718 what.form.recur_show_zero.disabled = true;
719 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
721 what.form.recur_fee.disabled = false;
722 what.form.recur_fee.style.backgroundColor = '#ffffff';
723 recur_changed( what.form.recur_fee );
724 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
729 function setup_changed(what) {
730 var setup = what.value;
731 if ( parseFloat(setup) == 0 ) {
732 what.form.setup_show_zero.disabled = false;
734 what.form.setup_show_zero.disabled = true;
738 function recur_changed(what) {
739 var recur = what.value;
740 if ( parseFloat(recur) == 0 ) {
741 what.form.recur_show_zero.disabled = false;
743 what.form.recur_show_zero.disabled = true;
747 function agent_changed(what) {
750 if ( what.type == 'select-one' ) {
751 agentnum = what.options[what.selectedIndex].value;
753 agentnum = what.value;
756 if ( agentnum == 0 ) {
757 what.form.agent_type.disabled = false;
758 //what.form.agent_type.style.backgroundColor = '#ffffff';
759 what.form.agent_type.style.visibility = '';
761 what.form.agent_type.disabled = true;
762 //what.form.agent_type.style.backgroundColor = '#dddddd';
763 what.form.agent_type.style.visibility = 'hidden';
768 function aux_planchanged(what) { //?
770 var plan = what.options[what.selectedIndex].value;
772 var term_table = document.getElementById('TableNumber7') // XXX NOT ROBUST
773 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
774 //term_table.disabled = false;
775 term_table.style.visibility = '';
777 //term_table.disabled = true;
778 term_table.style.visibility = 'hidden';
781 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
784 for ( var i=0; i < form.length; i++ ) {
785 if ( currency_regex.test(form[i].name) ) {
786 if ( plan == 'currency_fixed' ) {
787 form[i].disabled = false;
789 form[i].disabled = true;
799 'Changing the setup or recurring fee will create a new package definition. '.
802 $javascript .= "function confirm_submit(f) {";
803 if ( $conf->exists('part_pkg-lineage') ) {
806 var fields = Array('setup_fee','recur_fee');
807 for(var i=0; i < fields.length; i++) {
808 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
809 return confirm('$warning');
819 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
821 tie my %plan_labels, 'Tie::IxHash',
822 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
825 my $html_bottom = sub {
828 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
830 my $layer_callback = sub {
833 my $html = ntable("#cccccc",2);
837 # <TD ALIGN="right">Recurring fee frequency </TD>
838 # <TD><SELECT NAME="freq">
841 #my @freq = keys %freq;
842 #@freq = grep { /^\d+$/ } @freq
843 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
844 #foreach my $freq ( @freq ) {
845 # $html .= qq(<OPTION VALUE="$freq");
846 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
847 # $html .= ">$freq{$freq}";
850 #$html .= '</SELECT></TD></TR>';
852 my $href = $plans{$layer}->{'fields'};
853 my @fields = exists($plans{$layer}->{'fieldorder'})
854 ? @{$plans{$layer}->{'fieldorder'}}
857 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
859 if(!exists($href->{$field})) {
861 warn "nonexistent part_pkg option: '$field'\n";
865 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
867 my $format = sub { shift };
868 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
870 #XXX these should use elements/ fields... (or this whole thing should
871 #just use layer_fields instead of layer_callback)
873 if ( ! exists($href->{$field}{'type'}) ) {
875 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
876 ( exists($options{$field})
877 ? &$format($options{$field})
878 : $href->{$field}{'default'} ).
881 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
883 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
884 ( exists($options{$field}) && $options{$field}
889 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
893 if $href->{$field}{'type'} eq 'select_multiple';
894 $html .= qq! NAME="${layer}__$field">!;
896 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
897 if exists($href->{$field}{'disable_empty'})
898 && ! $href->{$field}{'disable_empty'};
900 if ( $href->{$field}{'select_table'} ) {
902 qsearch( $href->{$field}{'select_table'},
903 $href->{$field}{'select_hash'} )
905 my $value = $record->getfield($href->{$field}{'select_key'});
906 $html .= qq!<OPTION VALUE="$value"!.
907 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
911 '>'. $record->getfield($href->{$field}{'select_label'});
913 } elsif ( $href->{$field}{'select_options'} ) {
914 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
915 my $label = $href->{$field}{'select_options'}{$key};
916 $html .= qq!<OPTION VALUE="$key"!.
917 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
925 $html .= '<font color="#ff0000">warning: '.
926 "don't know how to retreive options for $field select field".
929 $html .= '</SELECT>';
931 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
934 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
936 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
937 my $label = $href->{$field}{'options'}{$key};
938 $html .= qq!$radio VALUE="$key"!.
939 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
948 $html .= '</TD></TR>';
952 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
953 join(',', keys %{ $href } ). '">';
961 options => [ keys %plan_labels ],
962 labels => \%plan_labels,
963 curr_value => $object->plan,
964 layer_callback => $layer_callback,
965 onchange => 'aux_planchanged(what);',
969 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
970 '<SCRIPT TYPE="text/javascript">'.
971 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
974 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
977 $return .= '</SCRIPT>';
983 my %usage_class = map { ($_->classnum => $_->classname) }
984 qsearch('usage_class', {});
985 $usage_class{setup} = 'Setup';
986 $usage_class{recur} = 'Recurring';
988 my %taxproduct_fields = ();
989 my $end_callback = sub {
990 my( $cgi, $object, $fields, $opt ) = @_;
992 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
994 if ( $object->pkgpart ) {
995 foreach my $usage_class ( '', @taxproductnums ) {
996 $tax_override{$usage_class} =
997 join (",", map $_->taxclassnum,
998 qsearch( 'part_pkg_taxoverride', {
999 'pkgpart' => $object->pkgpart,
1000 'usage_class' => $usage_class,
1006 %taxproduct_fields =
1007 map { $_ => [ "taxproductnum_$_",
1008 { type => 'select-taxproduct',
1009 #label => "$usage_class{$_} tax product",
1012 { type => 'select-taxoverride' }
1017 $taxproduct_fields{'(default)'} =
1018 [ 'taxproductnum', { type => 'select-taxproduct',
1019 #label => 'Default tax product',
1021 'tax_override', { type => 'select-taxoverride' },
1025 my $taxproduct_values = sub {
1026 my ($cgi, $object, $flags) = @_;
1028 sub { my $layer = shift;
1029 my @fields = @{$taxproduct_fields{$layer}};
1032 my $field = shift @fields;
1034 $field =~ /^taxproductnum_\w+$/ &&
1035 push @values, ( $field => $options{"usage_$field"} );
1036 $field =~ /^tax_override_(\w+)$/ &&
1037 push @values, ( $field => $tax_override{$1} );
1038 $field =~ /^taxproductnum$/ &&
1039 push @values, ( $field => $object->taxproductnum );
1040 $field =~ /^tax_override$/ &&
1041 push @values, ( $field => $tax_override{''} );
1047 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1048 return({ @result });
1052 my $field_callback = sub {
1053 my ($cgi, $object, $fieldref) = @_;
1055 my $field = $fieldref->{field};
1056 if ($field eq 'taxproductnums') {
1057 $fieldref->{value} = join(',', @taxproductnums);
1058 } elsif ($field eq 'taxproduct_select') {
1059 $fieldref->{options} = [ '(default)', @taxproductnums ];
1060 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1061 map {( $_ => ($usage_class{$_} || $_) )}
1064 $fieldref->{layer_fields} = \%taxproduct_fields;
1065 $fieldref->{layer_values_callback} = $taxproduct_values;
1069 my $discountnum_hashref = {
1071 'months' => { 'op' => '>', 'value' => 1 },