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 { type => 'tablebreak-tr-title',
224 value => 'FCC Form 477 information',
226 { field => 'fcc_options_string',
227 type => 'input-fcc_options',
228 curr_value_callback => sub {
229 my ($cgi, $part_pkg, $fref) = @_;
230 if ( $cgi->param('fcc_options_string') ) {
232 return $cgi->param('fcc_options_string');
235 %hash = $part_pkg->fcc_options
236 if ($part_pkg->pkgpart);
237 return encode_json(\%hash);
242 { type => 'columnend' },
244 { 'type' => $report_option ? 'tablebreak-tr-title'
246 'value' => 'Optional report classes',
247 'field' => 'census_title',
249 { 'field' => 'report_option',
250 'type' => $report_option ? 'select-table'
252 'table' => 'part_pkg_report_option',
253 'name_col' => 'name',
254 'hashref' => { 'disabled' => '' },
258 { 'type' => 'tablebreak-tr-title',
259 'value' => 'Term discounts',
261 { 'field' => 'discountnum',
262 'type' => 'select-table',
263 'table' => 'discount',
264 'name_col' => 'name',
265 'hashref' => { %$discountnum_hashref },
266 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
267 'empty_label'=> 'Select discount',
268 'm2_label' => 'Offer discounts for longer terms',
269 'm2m_method' => 'part_pkg_discount',
270 'm2m_dstcol' => 'discountnum',
271 'm2_error_callback' => $discount_error_callback,
274 { 'type' => 'tablebreak-tr-title',
275 'value' => 'Pricing add-ons',
278 { 'field' => 'bill_dst_pkgpart',
279 'type' => 'select-part_pkg',
280 'extra_sql' => sub { $pkgpart
281 ? "AND pkgpart != $pkgpart"
284 + 'label_callback' => sub { shift->pkg_comment_only },
285 'm2_label' => 'Include line item(s) from package',
286 'm2m_method' => 'bill_part_pkg_link',
287 'm2m_dstcol' => 'dst_pkgpart',
288 'm2_error_callback' =>
289 &{$m2_error_callback_maker}('bill'),
290 'm2_fields' => [ { 'field' => 'hidden',
291 'type' => 'checkbox',
299 { type => 'tablebreak-tr-title',
302 { type => 'pkg_svc', },
304 { 'field' => 'svc_dst_pkgpart',
305 'label' => 'Also include services from package: ',
306 'type' => 'select-part_pkg',
307 'extra_sql' => sub { $pkgpart
308 ? "AND pkgpart != $pkgpart"
311 + 'label_callback' => sub { shift->pkg_comment_only },
312 'm2_label' => 'Include services of package: ',
313 'm2m_method' => 'svc_part_pkg_link',
314 'm2m_dstcol' => 'dst_pkgpart',
315 'm2_error_callback' =>
316 &{$m2_error_callback_maker}('svc'),
319 { 'type' => 'tablebreak-tr-title',
320 'value' => 'Supplemental packages',
322 'include_opt_callback' => sub {
323 'id' => 'show_supp_pkgs',
326 { 'field' => 'supp_dst_pkgpart',
327 'type' => 'select-part_pkg',
328 + 'label_callback' => sub { shift->pkg_comment_only },
329 'm2_label' => 'When ordering package, also order',
330 'm2m_method' => 'supp_part_pkg_link',
331 'm2m_dstcol' => 'dst_pkgpart',
332 'm2_error_callback' =>
333 &{$m2_error_callback_maker}('supp'),
336 { type => 'tablebreak-tr-title',
337 value => 'Price plan options',
346 my $curuser = $FS::CurrentUser::CurrentUser;
348 my $edit_global = 'Edit global package definitions';
349 my $acl_edit = $curuser->access_right('Edit package definitions');
350 my $acl_edit_global = $curuser->access_right($edit_global);
352 my $acl_edit_either = $acl_edit || $acl_edit_global;
354 my $begin_callback = sub {
355 my( $cgi, $fields, $opt ) = @_;
357 unless $acl_edit_either
358 || ( $cgi->param('pkgnum')
359 && $curuser->access_right('Customize customer package')
363 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
365 #arg. access rights for cloning are Hard.
366 # on the one hand we don't really want cloning (customizing a package) to fail
367 # for want of finding the source package in normal usage
368 # on the other hand, we don't want people using the clone link to be able to
370 my $agent_clone_extra_sql =
371 ' ( '. FS::part_pkg->curuser_pkgs_sql.
372 " OR ( part_pkg.custom = 'Y' ) ".
375 my $conf = new FS::Conf;
376 my $taxproducts = $conf->exists('enable_taxproducts');
378 my $fcc_opts = $conf->exists('part_pkg-show_fcc_options');
380 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
381 my %locale_labels = map {
382 ( $_ => 'Package -- '. FS::Locales->description($_) )
385 sort { $locale_labels{$a} cmp $locale_labels{$b} }
389 my %locale_field_labels = (
391 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
396 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
397 " WHERE disabled IS NULL OR disabled = '' ")
399 $sth->execute or die $sth->errstr;
400 my $report_option = $sth->fetchrow_arrayref->[0];
403 # - tr-part_pkg_freq: month_increments_only (from price plans)
405 # - test errors cloning
406 # - test custom pricing
407 # - move the selectlayer divs away from lame layer_callback
409 #my ($query) = $cgi->keywords;
414 my %tax_override = ();
416 my %taxproductnums = map { ($_->classnum => 1) }
417 qsearch('usage_class', { 'disabled' => '' });
418 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
421 my $recur_disabled = 1;
422 my $setup_show_zero_disabled = 0;
423 my $recur_show_zero_disabled = 1;
427 my $splice_locale_fields = sub {
428 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
431 my @locale_fields = (
433 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
434 my $pkg_value = $pkg_value_callback
435 ? $pkg_value_callback eq 'cgiparam'
436 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
437 : &$pkg_value_callback($_)
440 { field => 'pkgpartmsgnum'. $n,
442 value => $pkey_value,
444 { field => 'pkgpartmsgnum'. $n. '_locale',
448 { field => 'pkgpartmsgnum'. $n++. '_pkg',
459 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
463 my $error_callback = sub {
464 my($cgi, $object, $fields, $opt ) = @_;
466 (@agent_type) = $cgi->param('agent_type');
468 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
470 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
472 $recur_disabled = $cgi->param('freq') ? 0 : 1;
473 $recur_show_zero_disabled =
475 ? $cgi->param('recur_fee') > 0 ? 1 : 0
478 foreach ($cgi->param) {
479 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
481 $tax_override{''} = $cgi->param('tax_override');
482 $tax_override{$_} = $cgi->param('tax_override_$_')
483 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
485 #some false laziness w/process
486 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
488 my $options = $cgi->param($plan."__OPTIONS");
489 my @options = split(',', $options);
491 map { my $optionname = $_;
492 my $param = $plan."__$optionname";
493 my $value = join(', ', $cgi->param($param));
494 ( $optionname => $value );
498 $object->set($_ => scalar($cgi->param($_)) )
499 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
501 $pkgpart = $object->pkgpart;
503 &$splice_locale_fields(
507 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
508 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
515 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
517 my $new_object_callback = sub {
518 my( $cgi, $hashref, $fields, $opt ) = @_;
520 my $part_pkg = FS::part_pkg->new( $hashref );
521 $part_pkg->set($_ => '0')
522 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
528 sub set_report_option {
529 my($cgi, $object, $fields ) = @_; #, $opt
531 my @report_option = ();
532 foreach ($object->options) {
533 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
534 /^report_option_(\d+)$/ && (push @report_option, $1);
536 foreach ($object->part_pkg_taxoverride) {
537 $taxproductnums{$_->usage_class} = 1
541 $cgi->param('report_option', join(',', @report_option));
542 foreach my $field ( @$fields ) {
544 ref($field) eq 'HASH' &&
546 $field->{field} eq 'report_option'
548 #$field->{curr_value} = join(',', @report_option);
549 $field->{value} = join(',', @report_option);
554 my $edit_callback = sub {
555 my( $cgi, $object, $fields, $opt ) = @_;
557 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
559 $recur_disabled = $object->freq ? 0 : 1;
561 $recur_show_zero_disabled =
563 ? $object->option('recur_fee') > 0 ? 1 : 0
567 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
569 set_report_option( $cgi, $object, $fields);
571 %options = $object->options;
573 $object->set($_ => $object->option($_, 1))
574 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
576 $pkgpart = $object->pkgpart;
578 &$splice_locale_fields(
582 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
583 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
587 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
588 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
594 my $new_callback = sub {
595 my( $cgi, $object, $fields ) = @_;
597 my $conf = new FS::Conf;
599 if ( $conf->exists('agent_defaultpkg') ) {
600 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
601 @agent_type = map {$_->typenum} qsearch('agent_type',{});
604 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
606 &$splice_locale_fields($fields, '', '');
610 my $clone_callback = sub {
611 my( $cgi, $object, $fields, $opt ) = @_;
613 if ( $cgi->param('pkgnum') ) {
615 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
616 $object->agentnum( $cust_pkg->cust_main->agentnum );
618 $opt->{action} = 'Custom';
620 #my $part_pkg = $clone_part_pkg->clone;
621 #this is all clone does anyway
622 $object->custom('Y');
624 $object->disabled('Y');
626 } else { #when explicitly cloning, not customizing
629 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
633 set_report_option( $cgi, $object, $fields);
635 %options = $object->options;
637 $object->set($_ => $options{$_})
638 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
640 $recur_disabled = $object->freq ? 0 : 1;
642 &$splice_locale_fields(
647 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
648 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
653 my $discount_error_callback = sub {
654 my( $cgi, $object ) = @_;
656 if ( /^discountnum(\d+)$/ &&
657 ( my $discountnum = $cgi->param("discountnum$1") ) )
659 new FS::part_pkg_discount {
660 'pkgpart' => $object->pkgpart,
661 'discountnum' => $discountnum,
670 my $m2_error_callback_maker = sub {
671 my $link_type = shift; #yay closures
673 my( $cgi, $object ) = @_;
676 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
677 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
680 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
682 new FS::part_pkg_link {
683 'link_type' => $link_type,
684 'src_pkgpart' => $object->pkgpart,
685 'dst_pkgpart' => $dst,
696 my $javascript = <<'END';
697 <SCRIPT TYPE="text/javascript">
699 function freq_changed(what) {
700 var freq = what.options[what.selectedIndex].value;
703 what.form.recur_fee.disabled = true;
704 what.form.recur_fee.style.backgroundColor = '#dddddd';
705 what.form.recur_show_zero.disabled = true;
706 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
708 what.form.recur_fee.disabled = false;
709 what.form.recur_fee.style.backgroundColor = '#ffffff';
710 recur_changed( what.form.recur_fee );
711 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
716 function setup_changed(what) {
717 var setup = what.value;
718 if ( parseFloat(setup) == 0 ) {
719 what.form.setup_show_zero.disabled = false;
721 what.form.setup_show_zero.disabled = true;
725 function recur_changed(what) {
726 var recur = what.value;
727 if ( parseFloat(recur) == 0 ) {
728 what.form.recur_show_zero.disabled = false;
730 what.form.recur_show_zero.disabled = true;
734 function agent_changed(what) {
737 if ( what.type == 'select-one' ) {
738 agentnum = what.options[what.selectedIndex].value;
740 agentnum = what.value;
743 if ( agentnum == 0 ) {
744 what.form.agent_type.disabled = false;
745 //what.form.agent_type.style.backgroundColor = '#ffffff';
746 what.form.agent_type.style.visibility = '';
748 what.form.agent_type.disabled = true;
749 //what.form.agent_type.style.backgroundColor = '#dddddd';
750 what.form.agent_type.style.visibility = 'hidden';
755 function aux_planchanged(what) { //?
757 var plan = what.options[what.selectedIndex].value;
758 var table = document.getElementById('TableNumber6') // XXX NOT ROBUST
760 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
761 //table.disabled = false;
762 table.style.visibility = '';
764 //table.disabled = true;
765 table.style.visibility = 'hidden';
770 // some magic to make "supplemental packages" less obvious
771 var supp_pkg_rows = [];
772 function show_supp_pkgs_click() {
773 supp_pkg_rows[0].style.display = '';
775 this.style.backgroundColor = '';
776 this.style.border = '';
777 this.style.padding = '';
780 function hide_supp_pkgs() {
781 var all_selects = document.getElementsByTagName('select');
782 for (var i=0; i < all_selects.length; i++) {
783 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
784 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
787 if ( supp_pkg_rows.length == 1 ) {
788 // there are none configured, so hide the row to create a new one
789 supp_pkg_rows[0].style.display = 'none';
790 var button = document.getElementById('show_supp_pkgs');
791 button.onclick = show_supp_pkgs_click;
792 button.style.backgroundColor = '#cccccc';
793 button.style.border = '1px solid #7e0079';
794 button.style.padding = '1px';
801 'Changing the setup or recurring fee will create a new package definition. '.
804 $javascript .= "function confirm_submit(f) {";
805 if ( $conf->exists('part_pkg-lineage') ) {
808 var fields = Array('setup_fee','recur_fee');
809 for(var i=0; i < fields.length; i++) {
810 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
811 return confirm('$warning');
821 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
823 tie my %plan_labels, 'Tie::IxHash',
824 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
827 my $html_bottom = sub {
830 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
832 my $layer_callback = sub {
835 my $html = ntable("#cccccc",2);
839 # <TD ALIGN="right">Recurring fee frequency </TD>
840 # <TD><SELECT NAME="freq">
843 #my @freq = keys %freq;
844 #@freq = grep { /^\d+$/ } @freq
845 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
846 #foreach my $freq ( @freq ) {
847 # $html .= qq(<OPTION VALUE="$freq");
848 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
849 # $html .= ">$freq{$freq}";
852 #$html .= '</SELECT></TD></TR>';
854 my $href = $plans{$layer}->{'fields'};
855 my @fields = exists($plans{$layer}->{'fieldorder'})
856 ? @{$plans{$layer}->{'fieldorder'}}
859 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
861 if(!exists($href->{$field})) {
863 warn "nonexistent part_pkg option: '$field'\n";
866 if ( exists($href->{$field}->{display_if}) ) {
867 my %args = ( 'plan' => $layer ); # anything else?
868 my $display = &{ $href->{$field}->{display_if} }(%args);
872 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
874 my $format = sub { shift };
875 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
877 #XXX these should use elements/ fields... (or this whole thing should
878 #just use layer_fields instead of layer_callback)
880 if ( ! exists($href->{$field}{'type'}) ) {
882 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
883 ( exists($options{$field})
884 ? &$format($options{$field})
885 : $href->{$field}{'default'} ).
888 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
890 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
891 ( exists($options{$field}) && $options{$field}
896 } elsif ( $href->{$field}{'type'} eq 'select-rate' ) {
898 $html .= include('/elements/select-rate.html',
899 'field' => $layer.'__'.$field,
900 'curr_value' => $options{$field},
901 map { $_ => $href->{$field}{$_} }
902 grep { $_ !~ /^(name|type)$/ }
903 keys %{ $href->{$field} }
906 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
910 if $href->{$field}{'type'} eq 'select_multiple';
911 $html .= qq! NAME="${layer}__$field">!;
913 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
914 if exists($href->{$field}{'disable_empty'})
915 && ! $href->{$field}{'disable_empty'};
917 if ( $href->{$field}{'select_table'} ) {
919 qsearch( $href->{$field}{'select_table'},
920 $href->{$field}{'select_hash'} )
922 my $value = $record->getfield($href->{$field}{'select_key'});
923 $html .= qq!<OPTION VALUE="$value"!.
924 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
928 '>'. $record->getfield($href->{$field}{'select_label'});
930 } elsif ( $href->{$field}{'select_options'} ) {
931 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
932 my $label = $href->{$field}{'select_options'}{$key};
933 $html .= qq!<OPTION VALUE="$key"!.
934 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
942 $html .= '<font color="#ff0000">warning: '.
943 "don't know how to retreive options for $field select field".
946 $html .= '</SELECT>';
948 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
951 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
953 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
954 my $label = $href->{$field}{'options'}{$key};
955 $html .= qq!$radio VALUE="$key"!.
956 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
965 $html .= '</TD></TR>';
969 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
970 join(',', keys %{ $href } ). '">';
978 options => [ keys %plan_labels ],
979 labels => \%plan_labels,
980 curr_value => $object->plan,
981 layer_callback => $layer_callback,
982 onchange => 'aux_planchanged(what);',
986 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
987 '<SCRIPT TYPE="text/javascript">'.
988 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
991 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
994 $return .= '</SCRIPT>';
1000 my %usage_class = map { ($_->classnum => $_->classname) }
1001 qsearch('usage_class', {});
1002 $usage_class{setup} = 'Setup';
1003 $usage_class{recur} = 'Recurring';
1005 my %taxproduct_fields = ();
1006 my $end_callback = sub {
1007 my( $cgi, $object, $fields, $opt ) = @_;
1009 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1011 if ( $object->pkgpart ) {
1012 foreach my $usage_class ( '', @taxproductnums ) {
1013 $tax_override{$usage_class} =
1014 join (",", map $_->taxclassnum,
1015 qsearch( 'part_pkg_taxoverride', {
1016 'pkgpart' => $object->pkgpart,
1017 'usage_class' => $usage_class,
1023 %taxproduct_fields =
1024 map { $_ => [ "taxproductnum_$_",
1025 { type => 'select-taxproduct',
1026 #label => "$usage_class{$_} tax product",
1029 { type => 'select-taxoverride' }
1034 $taxproduct_fields{'(default)'} =
1035 [ 'taxproductnum', { type => 'select-taxproduct',
1036 #label => 'Default tax product',
1038 'tax_override', { type => 'select-taxoverride' },
1042 my $taxproduct_values = sub {
1043 my ($cgi, $object, $flags) = @_;
1045 sub { my $layer = shift;
1046 my @fields = @{$taxproduct_fields{$layer}};
1049 my $field = shift @fields;
1051 $field =~ /^taxproductnum_\w+$/ &&
1052 push @values, ( $field => $options{"usage_$field"} );
1053 $field =~ /^tax_override_(\w+)$/ &&
1054 push @values, ( $field => $tax_override{$1} );
1055 $field =~ /^taxproductnum$/ &&
1056 push @values, ( $field => $object->taxproductnum );
1057 $field =~ /^tax_override$/ &&
1058 push @values, ( $field => $tax_override{''} );
1064 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1065 return({ @result });
1069 my $field_callback = sub {
1070 my ($cgi, $object, $fieldref) = @_;
1072 my $field = $fieldref->{field};
1073 if ($field eq 'taxproductnums') {
1074 $fieldref->{value} = join(',', @taxproductnums);
1075 } elsif ($field eq 'taxproduct_select') {
1076 $fieldref->{options} = [ '(default)', @taxproductnums ];
1077 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1078 map {( $_ => ($usage_class{$_} || $_) )}
1081 $fieldref->{layer_fields} = \%taxproduct_fields;
1082 $fieldref->{layer_values_callback} = $taxproduct_values;
1086 my $discountnum_hashref = {
1088 'months' => { 'op' => '>', 'value' => 1 },