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 + 'label_callback' => sub { shift->pkg_comment_only },
279 'm2_label' => 'Include line item(s) from package',
280 'm2m_method' => 'bill_part_pkg_link',
281 'm2m_dstcol' => 'dst_pkgpart',
282 'm2_error_callback' =>
283 &{$m2_error_callback_maker}('bill'),
284 'm2_fields' => [ { 'field' => 'hidden',
285 'type' => 'checkbox',
293 { type => 'tablebreak-tr-title',
296 { type => 'pkg_svc', },
298 { 'field' => 'svc_dst_pkgpart',
299 'label' => 'Also include services from package: ',
300 'type' => 'select-part_pkg',
301 'extra_sql' => sub { $pkgpart
302 ? "AND pkgpart != $pkgpart"
305 + 'label_callback' => sub { shift->pkg_comment_only },
306 'm2_label' => 'Include services of package: ',
307 'm2m_method' => 'svc_part_pkg_link',
308 'm2m_dstcol' => 'dst_pkgpart',
309 'm2_error_callback' =>
310 &{$m2_error_callback_maker}('svc'),
313 { 'type' => 'tablebreak-tr-title',
314 'value' => 'Supplemental packages',
316 'include_opt_callback' => sub {
317 'id' => 'show_supp_pkgs',
320 { 'field' => 'supp_dst_pkgpart',
321 'type' => 'select-part_pkg',
322 + 'label_callback' => sub { shift->pkg_comment_only },
323 'm2_label' => 'When ordering package, also order',
324 'm2m_method' => 'supp_part_pkg_link',
325 'm2m_dstcol' => 'dst_pkgpart',
326 'm2_error_callback' =>
327 &{$m2_error_callback_maker}('supp'),
330 { type => 'tablebreak-tr-title',
331 value => 'Price plan options',
340 my $curuser = $FS::CurrentUser::CurrentUser;
342 my $edit_global = 'Edit global package definitions';
343 my $acl_edit = $curuser->access_right('Edit package definitions');
344 my $acl_edit_global = $curuser->access_right($edit_global);
346 my $acl_edit_either = $acl_edit || $acl_edit_global;
348 my $begin_callback = sub {
349 my( $cgi, $fields, $opt ) = @_;
351 unless $acl_edit_either
352 || ( $cgi->param('pkgnum')
353 && $curuser->access_right('Customize customer package')
357 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
359 #arg. access rights for cloning are Hard.
360 # on the one hand we don't really want cloning (customizing a package) to fail
361 # for want of finding the source package in normal usage
362 # on the other hand, we don't want people using the clone link to be able to
364 my $agent_clone_extra_sql =
365 ' ( '. FS::part_pkg->curuser_pkgs_sql.
366 " OR ( part_pkg.custom = 'Y' ) ".
369 my $conf = new FS::Conf;
370 my $taxproducts = $conf->exists('enable_taxproducts');
372 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
373 my %locale_labels = map {
374 ( $_ => 'Package -- '. FS::Locales->description($_) )
377 sort { $locale_labels{$a} cmp $locale_labels{$b} }
381 my %locale_field_labels = (
383 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
388 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
389 " WHERE disabled IS NULL OR disabled = '' ")
391 $sth->execute or die $sth->errstr;
392 my $report_option = $sth->fetchrow_arrayref->[0];
395 # - tr-part_pkg_freq: month_increments_only (from price plans)
397 # - test errors cloning
398 # - test custom pricing
399 # - move the selectlayer divs away from lame layer_callback
401 #my ($query) = $cgi->keywords;
406 my %tax_override = ();
408 my %taxproductnums = map { ($_->classnum => 1) }
409 qsearch('usage_class', { 'disabled' => '' });
410 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
413 my $recur_disabled = 1;
414 my $setup_show_zero_disabled = 0;
415 my $recur_show_zero_disabled = 1;
419 my $splice_locale_fields = sub {
420 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
423 my @locale_fields = (
425 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
426 my $pkg_value = $pkg_value_callback
427 ? $pkg_value_callback eq 'cgiparam'
428 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
429 : &$pkg_value_callback($_)
432 { field => 'pkgpartmsgnum'. $n,
434 value => $pkey_value,
436 { field => 'pkgpartmsgnum'. $n. '_locale',
440 { field => 'pkgpartmsgnum'. $n++. '_pkg',
451 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
455 my $error_callback = sub {
456 my($cgi, $object, $fields, $opt ) = @_;
458 (@agent_type) = $cgi->param('agent_type');
460 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
462 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
464 $recur_disabled = $cgi->param('freq') ? 0 : 1;
465 $recur_show_zero_disabled =
467 ? $cgi->param('recur_fee') > 0 ? 1 : 0
470 foreach ($cgi->param) {
471 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
473 $tax_override{''} = $cgi->param('tax_override');
474 $tax_override{$_} = $cgi->param('tax_override_$_')
475 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
477 #some false laziness w/process
478 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
480 my $options = $cgi->param($plan."__OPTIONS");
481 my @options = split(',', $options);
483 map { my $optionname = $_;
484 my $param = $plan."__$optionname";
485 my $value = join(', ', $cgi->param($param));
486 ( $optionname => $value );
490 $object->set($_ => scalar($cgi->param($_)) )
491 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
493 $pkgpart = $object->pkgpart;
495 &$splice_locale_fields(
499 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
500 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
507 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
509 my $new_object_callback = sub {
510 my( $cgi, $hashref, $fields, $opt ) = @_;
512 my $part_pkg = FS::part_pkg->new( $hashref );
513 $part_pkg->set($_ => '0')
514 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
520 sub set_report_option {
521 my($cgi, $object, $fields ) = @_; #, $opt
523 my @report_option = ();
524 foreach ($object->options) {
525 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
526 /^report_option_(\d+)$/ && (push @report_option, $1);
528 foreach ($object->part_pkg_taxoverride) {
529 $taxproductnums{$_->usage_class} = 1
533 $cgi->param('report_option', join(',', @report_option));
534 foreach my $field ( @$fields ) {
536 ref($field) eq 'HASH' &&
538 $field->{field} eq 'report_option'
540 #$field->{curr_value} = join(',', @report_option);
541 $field->{value} = join(',', @report_option);
546 my $edit_callback = sub {
547 my( $cgi, $object, $fields, $opt ) = @_;
549 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
551 $recur_disabled = $object->freq ? 0 : 1;
553 $recur_show_zero_disabled =
555 ? $object->option('recur_fee') > 0 ? 1 : 0
559 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
561 set_report_option( $cgi, $object, $fields);
563 %options = $object->options;
565 $object->set($_ => $object->option($_, 1))
566 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
568 $pkgpart = $object->pkgpart;
570 &$splice_locale_fields(
574 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
575 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
579 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
580 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
586 my $new_callback = sub {
587 my( $cgi, $object, $fields ) = @_;
589 my $conf = new FS::Conf;
591 if ( $conf->exists('agent_defaultpkg') ) {
592 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
593 @agent_type = map {$_->typenum} qsearch('agent_type',{});
596 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
598 &$splice_locale_fields($fields, '', '');
602 my $clone_callback = sub {
603 my( $cgi, $object, $fields, $opt ) = @_;
605 if ( $cgi->param('pkgnum') ) {
607 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
608 $object->agentnum( $cust_pkg->cust_main->agentnum );
610 $opt->{action} = 'Custom';
612 #my $part_pkg = $clone_part_pkg->clone;
613 #this is all clone does anyway
614 $object->custom('Y');
616 $object->disabled('Y');
618 } else { #when explicitly cloning, not customizing
621 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
625 set_report_option( $cgi, $object, $fields);
627 %options = $object->options;
629 $object->set($_ => $options{$_})
630 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
632 $recur_disabled = $object->freq ? 0 : 1;
634 &$splice_locale_fields(
639 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
640 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
645 my $discount_error_callback = sub {
646 my( $cgi, $object ) = @_;
648 if ( /^discountnum(\d+)$/ &&
649 ( my $discountnum = $cgi->param("discountnum$1") ) )
651 new FS::part_pkg_discount {
652 'pkgpart' => $object->pkgpart,
653 'discountnum' => $discountnum,
662 my $m2_error_callback_maker = sub {
663 my $link_type = shift; #yay closures
665 my( $cgi, $object ) = @_;
668 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
669 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
672 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
674 new FS::part_pkg_link {
675 'link_type' => $link_type,
676 'src_pkgpart' => $object->pkgpart,
677 'dst_pkgpart' => $dst,
688 my $javascript = <<'END';
689 <SCRIPT TYPE="text/javascript">
691 function freq_changed(what) {
692 var freq = what.options[what.selectedIndex].value;
695 what.form.recur_fee.disabled = true;
696 what.form.recur_fee.style.backgroundColor = '#dddddd';
697 what.form.recur_show_zero.disabled = true;
698 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
700 what.form.recur_fee.disabled = false;
701 what.form.recur_fee.style.backgroundColor = '#ffffff';
702 recur_changed( what.form.recur_fee );
703 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
708 function setup_changed(what) {
709 var setup = what.value;
710 if ( parseFloat(setup) == 0 ) {
711 what.form.setup_show_zero.disabled = false;
713 what.form.setup_show_zero.disabled = true;
717 function recur_changed(what) {
718 var recur = what.value;
719 if ( parseFloat(recur) == 0 ) {
720 what.form.recur_show_zero.disabled = false;
722 what.form.recur_show_zero.disabled = true;
726 function agent_changed(what) {
729 if ( what.type == 'select-one' ) {
730 agentnum = what.options[what.selectedIndex].value;
732 agentnum = what.value;
735 if ( agentnum == 0 ) {
736 what.form.agent_type.disabled = false;
737 //what.form.agent_type.style.backgroundColor = '#ffffff';
738 what.form.agent_type.style.visibility = '';
740 what.form.agent_type.disabled = true;
741 //what.form.agent_type.style.backgroundColor = '#dddddd';
742 what.form.agent_type.style.visibility = 'hidden';
747 function aux_planchanged(what) { //?
749 var plan = what.options[what.selectedIndex].value;
750 var table = document.getElementById('TableNumber6') // XXX NOT ROBUST
752 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
753 //table.disabled = false;
754 table.style.visibility = '';
756 //table.disabled = true;
757 table.style.visibility = 'hidden';
762 // some magic to make "supplemental packages" less obvious
763 var supp_pkg_rows = [];
764 function show_supp_pkgs_click() {
765 supp_pkg_rows[0].style.display = '';
767 this.style.backgroundColor = '';
768 this.style.border = '';
769 this.style.padding = '';
772 function hide_supp_pkgs() {
773 var all_selects = document.getElementsByTagName('select');
774 for (var i=0; i < all_selects.length; i++) {
775 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
776 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
779 if ( supp_pkg_rows.length == 1 ) {
780 // there are none configured, so hide the row to create a new one
781 supp_pkg_rows[0].style.display = 'none';
782 var button = document.getElementById('show_supp_pkgs');
783 button.onclick = show_supp_pkgs_click;
784 button.style.backgroundColor = '#cccccc';
785 button.style.border = '1px solid #7e0079';
786 button.style.padding = '1px';
793 'Changing the setup or recurring fee will create a new package definition. '.
796 $javascript .= "function confirm_submit(f) {";
797 if ( $conf->exists('part_pkg-lineage') ) {
800 var fields = Array('setup_fee','recur_fee');
801 for(var i=0; i < fields.length; i++) {
802 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
803 return confirm('$warning');
813 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
815 tie my %plan_labels, 'Tie::IxHash',
816 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
819 my $html_bottom = sub {
822 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
824 my $layer_callback = sub {
827 my $html = ntable("#cccccc",2);
831 # <TD ALIGN="right">Recurring fee frequency </TD>
832 # <TD><SELECT NAME="freq">
835 #my @freq = keys %freq;
836 #@freq = grep { /^\d+$/ } @freq
837 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
838 #foreach my $freq ( @freq ) {
839 # $html .= qq(<OPTION VALUE="$freq");
840 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
841 # $html .= ">$freq{$freq}";
844 #$html .= '</SELECT></TD></TR>';
846 my $href = $plans{$layer}->{'fields'};
847 my @fields = exists($plans{$layer}->{'fieldorder'})
848 ? @{$plans{$layer}->{'fieldorder'}}
851 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
853 if(!exists($href->{$field})) {
855 warn "nonexistent part_pkg option: '$field'\n";
858 if ( exists($href->{$field}->{display_if}) ) {
859 my %args = ( 'plan' => $layer ); # anything else?
860 my $display = &{ $href->{$field}->{display_if} }(%args);
864 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
866 my $format = sub { shift };
867 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
869 #XXX these should use elements/ fields... (or this whole thing should
870 #just use layer_fields instead of layer_callback)
872 if ( ! exists($href->{$field}{'type'}) ) {
874 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
875 ( exists($options{$field})
876 ? &$format($options{$field})
877 : $href->{$field}{'default'} ).
880 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
882 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
883 ( exists($options{$field}) && $options{$field}
888 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
892 if $href->{$field}{'type'} eq 'select_multiple';
893 $html .= qq! NAME="${layer}__$field">!;
895 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
896 if exists($href->{$field}{'disable_empty'})
897 && ! $href->{$field}{'disable_empty'};
899 if ( $href->{$field}{'select_table'} ) {
901 qsearch( $href->{$field}{'select_table'},
902 $href->{$field}{'select_hash'} )
904 my $value = $record->getfield($href->{$field}{'select_key'});
905 $html .= qq!<OPTION VALUE="$value"!.
906 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
910 '>'. $record->getfield($href->{$field}{'select_label'});
912 } elsif ( $href->{$field}{'select_options'} ) {
913 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
914 my $label = $href->{$field}{'select_options'}{$key};
915 $html .= qq!<OPTION VALUE="$key"!.
916 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
924 $html .= '<font color="#ff0000">warning: '.
925 "don't know how to retreive options for $field select field".
928 $html .= '</SELECT>';
930 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
933 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
935 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
936 my $label = $href->{$field}{'options'}{$key};
937 $html .= qq!$radio VALUE="$key"!.
938 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
947 $html .= '</TD></TR>';
951 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
952 join(',', keys %{ $href } ). '">';
960 options => [ keys %plan_labels ],
961 labels => \%plan_labels,
962 curr_value => $object->plan,
963 layer_callback => $layer_callback,
964 onchange => 'aux_planchanged(what);',
968 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
969 '<SCRIPT TYPE="text/javascript">'.
970 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
973 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
976 $return .= '</SCRIPT>';
982 my %usage_class = map { ($_->classnum => $_->classname) }
983 qsearch('usage_class', {});
984 $usage_class{setup} = 'Setup';
985 $usage_class{recur} = 'Recurring';
987 my %taxproduct_fields = ();
988 my $end_callback = sub {
989 my( $cgi, $object, $fields, $opt ) = @_;
991 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
993 if ( $object->pkgpart ) {
994 foreach my $usage_class ( '', @taxproductnums ) {
995 $tax_override{$usage_class} =
996 join (",", map $_->taxclassnum,
997 qsearch( 'part_pkg_taxoverride', {
998 'pkgpart' => $object->pkgpart,
999 'usage_class' => $usage_class,
1005 %taxproduct_fields =
1006 map { $_ => [ "taxproductnum_$_",
1007 { type => 'select-taxproduct',
1008 #label => "$usage_class{$_} tax product",
1011 { type => 'select-taxoverride' }
1016 $taxproduct_fields{'(default)'} =
1017 [ 'taxproductnum', { type => 'select-taxproduct',
1018 #label => 'Default tax product',
1020 'tax_override', { type => 'select-taxoverride' },
1024 my $taxproduct_values = sub {
1025 my ($cgi, $object, $flags) = @_;
1027 sub { my $layer = shift;
1028 my @fields = @{$taxproduct_fields{$layer}};
1031 my $field = shift @fields;
1033 $field =~ /^taxproductnum_\w+$/ &&
1034 push @values, ( $field => $options{"usage_$field"} );
1035 $field =~ /^tax_override_(\w+)$/ &&
1036 push @values, ( $field => $tax_override{$1} );
1037 $field =~ /^taxproductnum$/ &&
1038 push @values, ( $field => $object->taxproductnum );
1039 $field =~ /^tax_override$/ &&
1040 push @values, ( $field => $tax_override{''} );
1046 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1047 return({ @result });
1051 my $field_callback = sub {
1052 my ($cgi, $object, $fieldref) = @_;
1054 my $field = $fieldref->{field};
1055 if ($field eq 'taxproductnums') {
1056 $fieldref->{value} = join(',', @taxproductnums);
1057 } elsif ($field eq 'taxproduct_select') {
1058 $fieldref->{options} = [ '(default)', @taxproductnums ];
1059 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1060 map {( $_ => ($usage_class{$_} || $_) )}
1063 $fieldref->{layer_fields} = \%taxproduct_fields;
1064 $fieldref->{layer_values_callback} = $taxproduct_values;
1068 my $discountnum_hashref = {
1070 'months' => { 'op' => '>', 'value' => 1 },