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 'agent_pkgpartid' => 'External ID',
51 'agentnum' => 'Agent',
52 'setup_fee' => 'Setup fee',
53 'setup_show_zero' => 'Show zero setup',
54 'recur_fee' => 'Recurring fee',
55 'recur_show_zero' => 'Show zero recurring',
56 'discountnum' => 'Offer discounts for longer terms',
57 'bill_dst_pkgpart' => 'Include line item(s) from package',
58 'svc_dst_pkgpart' => 'Include services of package',
59 'supp_dst_pkgpart' => 'When ordering package, also order',
60 'report_option' => 'Report classes',
61 'fcc_ds0s' => 'Voice-grade equivalents',
62 'fcc_voip_class' => 'Category',
63 'delay_start' => 'Default delay (days)',
67 { field=>'clone', type=>'hidden',
68 curr_value_callback =>
69 sub { shift->param('clone') },
71 { field=>'pkgnum', type=>'hidden',
72 curr_value_callback =>
73 sub { shift->param('pkgnum') },
76 { field=>'custom', type=>'hidden' },
77 { field=>'family_pkgpart', type=>'hidden' },
78 { field=>'successor', type=>'hidden' },
80 { type => 'columnstart' },
88 {field=>'comment', type=>'text', size=>40 }, #32
89 { field => 'agentnum',
90 type => 'select-agent',
91 disable_empty => ! $acl_edit_global,
92 empty_label => '(global)',
93 onchange => 'agent_changed',
95 {field=>'classnum', type=>'select-pkg_class' },
96 ( $conf->exists('pkg-addon_classnum')
97 ? ( { field=>'addon_classnum',
98 type =>'select-pkg_class',
103 {field=>'disabled', type=>$disabled_type, value=>'Y'},
104 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
106 { type => 'tablebreak-tr-title',
107 value => 'Pricing', #better name?
110 type => 'selectlayers-select',
111 options => [ keys %plan_labels ],
112 labels => \%plan_labels,
113 onchange => 'aux_planchanged(what);',
115 { field => 'setup_fee',
117 onchange => 'setup_changed',
119 { field => 'setup_show_zero',
122 disabled => sub { $setup_show_zero_disabled },
125 type => 'part_pkg_freq',
126 onchange => 'freq_changed',
128 { field => 'recur_fee',
130 disabled => sub { $recur_disabled },
131 onchange => 'recur_changed',
134 { field => 'recur_show_zero',
137 disabled => sub { $recur_show_zero_disabled },
143 #recurring fee (auto-disable)
145 { type => 'columnnext' },
147 {type=>'justtitle', value=>'Taxation' },
148 {field=>'setuptax', type=>'checkbox', value=>'Y'},
149 {field=>'recurtax', type=>'checkbox', value=>'Y'},
150 {field=>'taxclass', type=>'select-taxclass' },
151 { field => 'taxproductnums',
153 value => join(',', @taxproductnums),
155 { field => 'taxproduct_select',
156 type => 'selectlayers',
157 options => [ '(default)', @taxproductnums ],
158 curr_value => '(default)',
159 labels => { ( '(default)' => '(default)' ),
160 map {($_=>$usage_class{$_})}
163 layer_fields => \%taxproduct_fields,
164 layer_values_callback => $taxproduct_values,
165 layers_only => !$taxproducts,
166 cell_style => ( !$taxproducts
172 { type => 'tablebreak-tr-title',
173 value => 'Promotions', #better name?
175 { field=>'promo_code', type=>'text', size=>15 },
177 { type => 'tablebreak-tr-title',
178 value => 'Cost tracking', #better name?
181 ( $curuser->access_right('Edit package definition costs')
182 ? ( { field=>'setup_cost', type=>'money', },
183 { field=>'recur_cost', type=>'money', },
185 : ( { field=>'setup_cost', type=>'fixed', },
186 { field=>'recur_cost', type=>'fixed', },
190 ( $conf->exists('part_pkg-delay_start')
191 ? ( { type => 'tablebreak-tr-title',
192 value => 'Delayed start',
194 { field => 'delay_start',
195 type => 'text', size => 6 },
200 { type => 'columnnext' },
202 { field => 'agent_type',
203 type => 'select-agent_types',
204 disabled => ! $acl_edit_global,
205 curr_value_callback => sub {
206 my($cgi, $object, $field) = @_;
207 #in the other callbacks..? hmm.
212 { type => 'tablebreak-tr-title',
213 value => 'External Links', #better name?
215 { field=>'agent_pkgpartid', type=>'text', size=>21 },
217 { type => 'tablebreak-tr-title',
218 value => 'Line-item revenue recogition', #better name?
220 { field=>'pay_weight', type=>'text', size=>6 },
221 { field=>'credit_weight', type=>'text', size=>6 },
223 ( $conf->exists('cust_pkg-show_fcc_voice_grade_equivalent')
225 { type => 'tablebreak-tr-title',
226 value => 'FCC Form 477 information',
228 { field=>'fcc_voip_class',
229 type=>'select-voip_class',
231 { field=>'fcc_ds0s', type=>'text', size=>6 },
236 { type => 'columnend' },
238 { 'type' => $report_option ? 'tablebreak-tr-title'
240 'value' => 'Optional report classes',
241 'field' => 'census_title',
243 { 'field' => 'report_option',
244 'type' => $report_option ? 'select-table'
246 'table' => 'part_pkg_report_option',
247 'name_col' => 'name',
248 'hashref' => { 'disabled' => '' },
252 { 'type' => 'tablebreak-tr-title',
253 'value' => 'Term discounts',
255 { 'field' => 'discountnum',
256 'type' => 'select-table',
257 'table' => 'discount',
258 'name_col' => 'name',
259 'hashref' => { %$discountnum_hashref },
260 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
261 'empty_label'=> 'Select discount',
262 'm2_label' => 'Offer discounts for longer terms',
263 'm2m_method' => 'part_pkg_discount',
264 'm2m_dstcol' => 'discountnum',
265 'm2_error_callback' => $discount_error_callback,
268 { 'type' => 'tablebreak-tr-title',
269 'value' => 'Pricing add-ons',
272 { 'field' => 'bill_dst_pkgpart',
273 'type' => 'select-part_pkg',
274 'extra_sql' => sub { $pkgpart
275 ? "AND pkgpart != $pkgpart"
278 'm2_label' => 'Include line item(s) from package',
279 'm2m_method' => 'bill_part_pkg_link',
280 'm2m_dstcol' => 'dst_pkgpart',
281 'm2_error_callback' =>
282 &{$m2_error_callback_maker}('bill'),
283 'm2_fields' => [ { 'field' => 'hidden',
284 'type' => 'checkbox',
292 { type => 'tablebreak-tr-title',
295 { type => 'pkg_svc', },
297 { 'field' => 'svc_dst_pkgpart',
298 'label' => 'Also include services from package: ',
299 'type' => 'select-part_pkg',
300 'extra_sql' => sub { $pkgpart
301 ? "AND pkgpart != $pkgpart"
304 'm2_label' => 'Include services of package: ',
305 'm2m_method' => 'svc_part_pkg_link',
306 'm2m_dstcol' => 'dst_pkgpart',
307 'm2_error_callback' =>
308 &{$m2_error_callback_maker}('svc'),
311 { 'type' => 'tablebreak-tr-title',
312 'value' => 'Supplemental packages',
314 'include_opt_callback' => sub {
315 'id' => 'show_supp_pkgs',
318 { 'field' => 'supp_dst_pkgpart',
319 'type' => 'select-part_pkg',
320 'm2_label' => 'When ordering package, also order',
321 'm2m_method' => 'supp_part_pkg_link',
322 'm2m_dstcol' => 'dst_pkgpart',
323 'm2_error_callback' =>
324 &{$m2_error_callback_maker}('supp'),
327 { type => 'tablebreak-tr-title',
328 value => 'Price plan options',
337 my $curuser = $FS::CurrentUser::CurrentUser;
339 my $edit_global = 'Edit global package definitions';
340 my $acl_edit = $curuser->access_right('Edit package definitions');
341 my $acl_edit_global = $curuser->access_right($edit_global);
343 my $acl_edit_either = $acl_edit || $acl_edit_global;
345 my $begin_callback = sub {
346 my( $cgi, $fields, $opt ) = @_;
348 unless $acl_edit_either
349 || ( $cgi->param('pkgnum')
350 && $curuser->access_right('Customize customer package')
354 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
356 #arg. access rights for cloning are Hard.
357 # on the one hand we don't really want cloning (customizing a package) to fail
358 # for want of finding the source package in normal usage
359 # on the other hand, we don't want people using the clone link to be able to
361 my $agent_clone_extra_sql =
362 ' ( '. FS::part_pkg->curuser_pkgs_sql.
363 " OR ( part_pkg.custom = 'Y' ) ".
366 my $conf = new FS::Conf;
367 my $taxproducts = $conf->exists('enable_taxproducts');
369 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
370 my %locale_labels = map {
371 ( $_ => 'Package -- '. FS::Locales->description($_) )
374 sort { $locale_labels{$a} cmp $locale_labels{$b} }
378 my %locale_field_labels = (
380 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
385 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
386 " WHERE disabled IS NULL OR disabled = '' ")
388 $sth->execute or die $sth->errstr;
389 my $report_option = $sth->fetchrow_arrayref->[0];
392 # - tr-part_pkg_freq: month_increments_only (from price plans)
394 # - test errors cloning
395 # - test custom pricing
396 # - move the selectlayer divs away from lame layer_callback
398 #my ($query) = $cgi->keywords;
403 my %tax_override = ();
405 my %taxproductnums = map { ($_->classnum => 1) }
406 qsearch('usage_class', { 'disabled' => '' });
407 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
410 my $recur_disabled = 1;
411 my $setup_show_zero_disabled = 0;
412 my $recur_show_zero_disabled = 1;
416 my $splice_locale_fields = sub {
417 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
420 my @locale_fields = (
422 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
423 my $pkg_value = $pkg_value_callback
424 ? $pkg_value_callback eq 'cgiparam'
425 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
426 : &$pkg_value_callback($_)
429 { field => 'pkgpartmsgnum'. $n,
431 value => $pkey_value,
433 { field => 'pkgpartmsgnum'. $n. '_locale',
437 { field => 'pkgpartmsgnum'. $n++. '_pkg',
448 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
452 my $error_callback = sub {
453 my($cgi, $object, $fields, $opt ) = @_;
455 (@agent_type) = $cgi->param('agent_type');
457 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
459 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
461 $recur_disabled = $cgi->param('freq') ? 0 : 1;
462 $recur_show_zero_disabled =
464 ? $cgi->param('recur_fee') > 0 ? 1 : 0
467 foreach ($cgi->param) {
468 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
470 $tax_override{''} = $cgi->param('tax_override');
471 $tax_override{$_} = $cgi->param('tax_override_$_')
472 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
474 #some false laziness w/process
475 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
477 my $options = $cgi->param($plan."__OPTIONS");
478 my @options = split(',', $options);
480 map { my $optionname = $_;
481 my $param = $plan."__$optionname";
482 my $value = join(', ', $cgi->param($param));
483 ( $optionname => $value );
487 $object->set($_ => scalar($cgi->param($_)) )
488 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
490 $pkgpart = $object->pkgpart;
492 &$splice_locale_fields(
496 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
497 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
504 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
506 my $new_object_callback = sub {
507 my( $cgi, $hashref, $fields, $opt ) = @_;
509 my $part_pkg = FS::part_pkg->new( $hashref );
510 $part_pkg->set($_ => '0')
511 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
517 sub set_report_option {
518 my($cgi, $object, $fields ) = @_; #, $opt
520 my @report_option = ();
521 foreach ($object->options) {
522 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
523 /^report_option_(\d+)$/ && (push @report_option, $1);
525 foreach ($object->part_pkg_taxoverride) {
526 $taxproductnums{$_->usage_class} = 1
530 $cgi->param('report_option', join(',', @report_option));
531 foreach my $field ( @$fields ) {
533 ref($field) eq 'HASH' &&
535 $field->{field} eq 'report_option'
537 #$field->{curr_value} = join(',', @report_option);
538 $field->{value} = join(',', @report_option);
543 my $edit_callback = sub {
544 my( $cgi, $object, $fields, $opt ) = @_;
546 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
548 $recur_disabled = $object->freq ? 0 : 1;
550 $recur_show_zero_disabled =
552 ? $object->option('recur_fee') > 0 ? 1 : 0
556 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
558 set_report_option( $cgi, $object, $fields);
560 %options = $object->options;
562 $object->set($_ => $object->option($_, 1))
563 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
565 $pkgpart = $object->pkgpart;
567 &$splice_locale_fields(
571 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
572 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
576 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
577 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
583 my $new_callback = sub {
584 my( $cgi, $object, $fields ) = @_;
586 my $conf = new FS::Conf;
588 if ( $conf->exists('agent_defaultpkg') ) {
589 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
590 @agent_type = map {$_->typenum} qsearch('agent_type',{});
593 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
595 &$splice_locale_fields($fields, '', '');
599 my $clone_callback = sub {
600 my( $cgi, $object, $fields, $opt ) = @_;
602 if ( $cgi->param('pkgnum') ) {
604 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
605 $object->agentnum( $cust_pkg->cust_main->agentnum );
607 $opt->{action} = 'Custom';
609 #my $part_pkg = $clone_part_pkg->clone;
610 #this is all clone does anyway
611 $object->custom('Y');
613 $object->disabled('Y');
615 } else { #when explicitly cloning, not customizing
618 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
622 set_report_option( $cgi, $object, $fields);
624 %options = $object->options;
626 $object->set($_ => $options{$_})
627 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
629 $recur_disabled = $object->freq ? 0 : 1;
631 &$splice_locale_fields(
636 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
637 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
642 my $discount_error_callback = sub {
643 my( $cgi, $object ) = @_;
645 if ( /^discountnum(\d+)$/ &&
646 ( my $discountnum = $cgi->param("discountnum$1") ) )
648 new FS::part_pkg_discount {
649 'pkgpart' => $object->pkgpart,
650 'discountnum' => $discountnum,
659 my $m2_error_callback_maker = sub {
660 my $link_type = shift; #yay closures
662 my( $cgi, $object ) = @_;
665 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
666 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
669 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
671 new FS::part_pkg_link {
672 'link_type' => $link_type,
673 'src_pkgpart' => $object->pkgpart,
674 'dst_pkgpart' => $dst,
685 my $javascript = <<'END';
686 <SCRIPT TYPE="text/javascript">
688 function freq_changed(what) {
689 var freq = what.options[what.selectedIndex].value;
692 what.form.recur_fee.disabled = true;
693 what.form.recur_fee.style.backgroundColor = '#dddddd';
694 what.form.recur_show_zero.disabled = true;
695 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
697 what.form.recur_fee.disabled = false;
698 what.form.recur_fee.style.backgroundColor = '#ffffff';
699 recur_changed( what.form.recur_fee );
700 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
705 function setup_changed(what) {
706 var setup = what.value;
707 if ( parseFloat(setup) == 0 ) {
708 what.form.setup_show_zero.disabled = false;
710 what.form.setup_show_zero.disabled = true;
714 function recur_changed(what) {
715 var recur = what.value;
716 if ( parseFloat(recur) == 0 ) {
717 what.form.recur_show_zero.disabled = false;
719 what.form.recur_show_zero.disabled = true;
723 function agent_changed(what) {
726 if ( what.type == 'select-one' ) {
727 agentnum = what.options[what.selectedIndex].value;
729 agentnum = what.value;
732 if ( agentnum == 0 ) {
733 what.form.agent_type.disabled = false;
734 //what.form.agent_type.style.backgroundColor = '#ffffff';
735 what.form.agent_type.style.visibility = '';
737 what.form.agent_type.disabled = true;
738 //what.form.agent_type.style.backgroundColor = '#dddddd';
739 what.form.agent_type.style.visibility = 'hidden';
744 function aux_planchanged(what) { //?
746 var plan = what.options[what.selectedIndex].value;
747 var table = document.getElementById('TableNumber6') // XXX NOT ROBUST
749 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
750 //table.disabled = false;
751 table.style.visibility = '';
753 //table.disabled = true;
754 table.style.visibility = 'hidden';
759 // some magic to make "supplemental packages" less obvious
760 var supp_pkg_rows = [];
761 function show_supp_pkgs_click() {
762 supp_pkg_rows[0].style.display = '';
764 this.style.backgroundColor = '';
765 this.style.border = '';
766 this.style.padding = '';
769 function hide_supp_pkgs() {
770 var all_selects = document.getElementsByTagName('select');
771 for (var i=0; i < all_selects.length; i++) {
772 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
773 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
776 if ( supp_pkg_rows.length == 1 ) {
777 // there are none configured, so hide the row to create a new one
778 supp_pkg_rows[0].style.display = 'none';
779 var button = document.getElementById('show_supp_pkgs');
780 button.onclick = show_supp_pkgs_click;
781 button.style.backgroundColor = '#cccccc';
782 button.style.border = '1px solid #7e0079';
783 button.style.padding = '1px';
790 'Changing the setup or recurring fee will create a new package definition. '.
793 $javascript .= "function confirm_submit(f) {";
794 if ( $conf->exists('part_pkg-lineage') ) {
797 var fields = Array('setup_fee','recur_fee');
798 for(var i=0; i < fields.length; i++) {
799 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
800 return confirm('$warning');
810 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
812 tie my %plan_labels, 'Tie::IxHash',
813 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
816 my $html_bottom = sub {
819 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
821 my $layer_callback = sub {
824 my $html = ntable("#cccccc",2);
828 # <TD ALIGN="right">Recurring fee frequency </TD>
829 # <TD><SELECT NAME="freq">
832 #my @freq = keys %freq;
833 #@freq = grep { /^\d+$/ } @freq
834 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
835 #foreach my $freq ( @freq ) {
836 # $html .= qq(<OPTION VALUE="$freq");
837 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
838 # $html .= ">$freq{$freq}";
841 #$html .= '</SELECT></TD></TR>';
843 my $href = $plans{$layer}->{'fields'};
844 my @fields = exists($plans{$layer}->{'fieldorder'})
845 ? @{$plans{$layer}->{'fieldorder'}}
848 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
850 if(!exists($href->{$field})) {
852 warn "nonexistent part_pkg option: '$field'\n";
855 if ( exists($href->{$field}->{display_if}) ) {
856 my %args = ( 'plan' => $layer ); # anything else?
857 my $display = &{ $href->{$field}->{display_if} }(%args);
861 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
863 my $format = sub { shift };
864 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
866 #XXX these should use elements/ fields... (or this whole thing should
867 #just use layer_fields instead of layer_callback)
869 if ( ! exists($href->{$field}{'type'}) ) {
871 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
872 ( exists($options{$field})
873 ? &$format($options{$field})
874 : $href->{$field}{'default'} ).
877 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
879 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
880 ( exists($options{$field}) && $options{$field}
885 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
889 if $href->{$field}{'type'} eq 'select_multiple';
890 $html .= qq! NAME="${layer}__$field">!;
892 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
893 if exists($href->{$field}{'disable_empty'})
894 && ! $href->{$field}{'disable_empty'};
896 if ( $href->{$field}{'select_table'} ) {
898 qsearch( $href->{$field}{'select_table'},
899 $href->{$field}{'select_hash'} )
901 my $value = $record->getfield($href->{$field}{'select_key'});
902 $html .= qq!<OPTION VALUE="$value"!.
903 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
907 '>'. $record->getfield($href->{$field}{'select_label'});
909 } elsif ( $href->{$field}{'select_options'} ) {
910 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
911 my $label = $href->{$field}{'select_options'}{$key};
912 $html .= qq!<OPTION VALUE="$key"!.
913 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
921 $html .= '<font color="#ff0000">warning: '.
922 "don't know how to retreive options for $field select field".
925 $html .= '</SELECT>';
927 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
930 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
932 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
933 my $label = $href->{$field}{'options'}{$key};
934 $html .= qq!$radio VALUE="$key"!.
935 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
944 $html .= '</TD></TR>';
948 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
949 join(',', keys %{ $href } ). '">';
957 options => [ keys %plan_labels ],
958 labels => \%plan_labels,
959 curr_value => $object->plan,
960 layer_callback => $layer_callback,
961 onchange => 'aux_planchanged(what);',
965 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
966 '<SCRIPT TYPE="text/javascript">'.
967 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
970 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
973 $return .= '</SCRIPT>';
979 my %usage_class = map { ($_->classnum => $_->classname) }
980 qsearch('usage_class', {});
981 $usage_class{setup} = 'Setup';
982 $usage_class{recur} = 'Recurring';
984 my %taxproduct_fields = ();
985 my $end_callback = sub {
986 my( $cgi, $object, $fields, $opt ) = @_;
988 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
990 if ( $object->pkgpart ) {
991 foreach my $usage_class ( '', @taxproductnums ) {
992 $tax_override{$usage_class} =
993 join (",", map $_->taxclassnum,
994 qsearch( 'part_pkg_taxoverride', {
995 'pkgpart' => $object->pkgpart,
996 'usage_class' => $usage_class,
1002 %taxproduct_fields =
1003 map { $_ => [ "taxproductnum_$_",
1004 { type => 'select-taxproduct',
1005 #label => "$usage_class{$_} tax product",
1008 { type => 'select-taxoverride' }
1013 $taxproduct_fields{'(default)'} =
1014 [ 'taxproductnum', { type => 'select-taxproduct',
1015 #label => 'Default tax product',
1017 'tax_override', { type => 'select-taxoverride' },
1021 my $taxproduct_values = sub {
1022 my ($cgi, $object, $flags) = @_;
1024 sub { my $layer = shift;
1025 my @fields = @{$taxproduct_fields{$layer}};
1028 my $field = shift @fields;
1030 $field =~ /^taxproductnum_\w+$/ &&
1031 push @values, ( $field => $options{"usage_$field"} );
1032 $field =~ /^tax_override_(\w+)$/ &&
1033 push @values, ( $field => $tax_override{$1} );
1034 $field =~ /^taxproductnum$/ &&
1035 push @values, ( $field => $object->taxproductnum );
1036 $field =~ /^tax_override$/ &&
1037 push @values, ( $field => $tax_override{''} );
1043 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1044 return({ @result });
1048 my $field_callback = sub {
1049 my ($cgi, $object, $fieldref) = @_;
1051 my $field = $fieldref->{field};
1052 if ($field eq 'taxproductnums') {
1053 $fieldref->{value} = join(',', @taxproductnums);
1054 } elsif ($field eq 'taxproduct_select') {
1055 $fieldref->{options} = [ '(default)', @taxproductnums ];
1056 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1057 map {( $_ => ($usage_class{$_} || $_) )}
1060 $fieldref->{layer_fields} = \%taxproduct_fields;
1061 $fieldref->{layer_values_callback} = $taxproduct_values;
1065 my $discountnum_hashref = {
1067 'months' => { 'op' => '>', 'value' => 1 },