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);
19 'begin_callback' => $begin_callback,
20 'end_callback' => $end_callback,
21 'new_hashref_callback' => $new_hashref_callback,
22 'new_object_callback' => $new_object_callback,
23 'new_callback' => $new_callback,
24 'clone_callback' => $clone_callback,
25 'edit_callback' => $edit_callback,
26 'error_callback' => $error_callback,
27 'field_callback' => $field_callback,
29 'onsubmit' => 'confirm_submit',
32 'pkgpart' => 'Package Definition',
35 'comment' => 'Comment (customer-hidden)',
36 'classnum' => 'Package class',
37 'addon_classnum' => 'Restrict additional orders to package class',
38 'promo_code' => 'Promotional code',
39 'freq' => 'Recurring fee frequency',
40 'setuptax' => 'Setup fee tax exempt',
41 'recurtax' => 'Recurring fee tax exempt',
42 'taxclass' => 'Tax class',
43 'taxproduct_select'=> 'Tax products',
44 'plan' => 'Price plan',
45 'disabled' => 'Disable new orders',
46 'disable_line_item_date_ranges' => 'Disable line item date ranges',
47 'setup_cost' => 'Setup cost',
48 'recur_cost' => 'Recur cost',
49 'pay_weight' => 'Payment weight',
50 'credit_weight' => 'Credit weight',
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 ( map { ( "setup_fee_$_" => "Setup fee $_",
57 "recur_fee_$_" => "Recurring fee $_",
60 $conf->config('currencies')
62 'discountnum' => 'Offer discounts for longer terms',
63 'bill_dst_pkgpart' => 'Include line item(s) from package',
64 'svc_dst_pkgpart' => 'Include services of package',
65 'supp_dst_pkgpart' => 'When ordering package, also order',
66 'report_option' => 'Report classes',
67 'fcc_ds0s' => 'Voice-grade equivalents',
68 'fcc_voip_class' => 'Category',
69 'delay_start' => 'Default delay (days)',
73 { field=>'clone', type=>'hidden',
74 curr_value_callback =>
75 sub { shift->param('clone') },
77 { field=>'pkgnum', type=>'hidden',
78 curr_value_callback =>
79 sub { shift->param('pkgnum') },
82 { field=>'custom', type=>'hidden' },
83 { field=>'family_pkgpart', type=>'hidden' },
84 { field=>'successor', type=>'hidden' },
86 { type => 'columnstart' },
94 {field=>'comment', type=>'text', size=>40 }, #32
95 { field => 'agentnum',
96 type => 'select-agent',
97 disable_empty => ! $acl_edit_global,
98 empty_label => '(global)',
99 onchange => 'agent_changed',
101 {field=>'classnum', type=>'select-pkg_class' },
102 ( $conf->exists('pkg-addon_classnum')
103 ? ( { field=>'addon_classnum',
104 type =>'select-pkg_class',
109 {field=>'disabled', type=>$disabled_type, value=>'Y'},
110 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
112 { type => 'tablebreak-tr-title',
113 value => 'Pricing', #better name?
116 type => 'selectlayers-select',
117 options => [ keys %plan_labels ],
118 labels => \%plan_labels,
119 onchange => 'aux_planchanged(what);',
121 { field => 'setup_fee',
123 onchange => 'setup_changed',
125 { field => 'setup_show_zero',
128 disabled => sub { $setup_show_zero_disabled },
130 ( map { +{ field => "setup_fee_$_",
132 prefix=> currency_symbol($_, SYM_HTML),
136 sort $conf->config('currencies')
139 type => 'part_pkg_freq',
140 onchange => 'freq_changed',
142 { field => 'recur_fee',
144 disabled => sub { $recur_disabled },
145 onchange => 'recur_changed',
147 { field => 'recur_show_zero',
150 disabled => sub { $recur_show_zero_disabled },
152 ( map { +{ field => "recur_fee_$_",
154 prefix=> currency_symbol($_, SYM_HTML),
158 sort $conf->config('currencies')
164 #recurring fee (auto-disable)
166 { type => 'columnnext' },
168 {type=>'justtitle', value=>'Taxation' },
169 {field=>'setuptax', type=>'checkbox', value=>'Y'},
170 {field=>'recurtax', type=>'checkbox', value=>'Y'},
171 {field=>'taxclass', type=>'select-taxclass' },
172 { field => 'taxproductnums',
174 value => join(',', @taxproductnums),
176 { field => 'taxproduct_select',
177 type => 'selectlayers',
178 options => [ '(default)', @taxproductnums ],
179 curr_value => '(default)',
180 labels => { ( '(default)' => '(default)' ),
181 map {($_=>$usage_class{$_})}
184 layer_fields => \%taxproduct_fields,
185 layer_values_callback => $taxproduct_values,
186 layers_only => !$taxproducts,
187 cell_style => ( !$taxproducts
193 { type => 'tablebreak-tr-title',
194 value => 'Promotions', #better name?
196 { field=>'promo_code', type=>'text', size=>15 },
198 { type => 'tablebreak-tr-title',
199 value => 'Cost tracking', #better name?
201 { field=>'setup_cost', type=>'money', },
202 { field=>'recur_cost', type=>'money', },
204 ( $conf->exists('part_pkg-delay_start')
205 ? ( { type => 'tablebreak-tr-title',
206 value => 'Delayed start',
208 { field => 'delay_start',
209 type => 'text', size => 6 },
214 { type => 'columnnext' },
216 { field => 'agent_type',
217 type => 'select-agent_types',
218 disabled => ! $acl_edit_global,
219 curr_value_callback => sub {
220 my($cgi, $object, $field) = @_;
221 #in the other callbacks..? hmm.
226 { type => 'tablebreak-tr-title',
227 value => 'Line-item revenue recogition', #better name?
229 { field=>'pay_weight', type=>'text', size=>6 },
230 { field=>'credit_weight', type=>'text', size=>6 },
232 ( $conf->exists('cust_pkg-show_fcc_voice_grade_equivalent')
234 { type => 'tablebreak-tr-title',
235 value => 'FCC Form 477 information',
237 { field=>'fcc_voip_class',
238 type=>'select-voip_class',
240 { field=>'fcc_ds0s', type=>'text', size=>6 },
246 { type => 'columnend' },
248 { 'type' => $report_option ? 'tablebreak-tr-title'
250 'value' => 'Optional report classes',
251 'field' => 'census_title',
253 { 'field' => 'report_option',
254 'type' => $report_option ? 'select-table'
256 'table' => 'part_pkg_report_option',
257 'name_col' => 'name',
258 'hashref' => { 'disabled' => '' },
262 { 'type' => 'tablebreak-tr-title',
263 'value' => 'Term discounts',
265 { 'field' => 'discountnum',
266 'type' => 'select-table',
267 'table' => 'discount',
268 'name_col' => 'name',
269 'hashref' => { %$discountnum_hashref },
270 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
271 'empty_label'=> 'Select discount',
272 'm2_label' => 'Offer discounts for longer terms',
273 'm2m_method' => 'part_pkg_discount',
274 'm2m_dstcol' => 'discountnum',
275 'm2_error_callback' => $discount_error_callback,
278 { 'type' => 'tablebreak-tr-title',
279 'value' => 'Pricing add-ons',
282 { 'field' => 'bill_dst_pkgpart',
283 'type' => 'select-part_pkg',
284 'extra_sql' => sub { $pkgpart
285 ? "AND pkgpart != $pkgpart"
288 'm2_label' => 'Include line item(s) from package',
289 'm2m_method' => 'bill_part_pkg_link',
290 'm2m_dstcol' => 'dst_pkgpart',
291 'm2_error_callback' =>
292 &{$m2_error_callback_maker}('bill'),
293 'm2_fields' => [ { 'field' => 'hidden',
294 'type' => 'checkbox',
302 { type => 'tablebreak-tr-title',
305 { type => 'pkg_svc', },
307 { 'field' => 'svc_dst_pkgpart',
308 'label' => 'Also include services from package: ',
309 'type' => 'select-part_pkg',
310 'extra_sql' => sub { $pkgpart
311 ? "AND pkgpart != $pkgpart"
314 'm2_label' => 'Include services of package: ',
315 'm2m_method' => 'svc_part_pkg_link',
316 'm2m_dstcol' => 'dst_pkgpart',
317 'm2_error_callback' =>
318 &{$m2_error_callback_maker}('svc'),
321 { 'type' => 'tablebreak-tr-title',
322 'value' => 'Supplemental packages',
324 'include_opt_callback' => sub {
325 'id' => 'show_supp_pkgs',
328 { 'field' => 'supp_dst_pkgpart',
329 'type' => 'select-part_pkg',
330 'm2_label' => 'When ordering package, also order',
331 'm2m_method' => 'supp_part_pkg_link',
332 'm2m_dstcol' => 'dst_pkgpart',
333 'm2_error_callback' =>
334 &{$m2_error_callback_maker}('supp'),
337 { type => 'tablebreak-tr-title',
338 value => 'Price plan options',
345 my $curuser = $FS::CurrentUser::CurrentUser;
347 my $edit_global = 'Edit global package definitions';
348 my $acl_edit = $curuser->access_right('Edit package definitions');
349 my $acl_edit_global = $curuser->access_right($edit_global);
351 my $acl_edit_either = $acl_edit || $acl_edit_global;
353 my $begin_callback = sub {
354 my( $cgi, $fields, $opt ) = @_;
356 unless $acl_edit_either
357 || ( $cgi->param('pkgnum')
358 && $curuser->access_right('Customize customer package')
362 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
364 #arg. access rights for cloning are Hard.
365 # on the one hand we don't really want cloning (customizing a package) to fail
366 # for want of finding the source package in normal usage
367 # on the other hand, we don't want people using the clone link to be able to
369 my $agent_clone_extra_sql =
370 ' ( '. FS::part_pkg->curuser_pkgs_sql.
371 " OR ( part_pkg.custom = 'Y' ) ".
374 my $conf = new FS::Conf;
375 my $taxproducts = $conf->exists('enable_taxproducts');
377 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
378 my %locale_labels = map {
379 ( $_ => 'Package -- '. FS::Locales->description($_) )
382 sort { $locale_labels{$a} cmp $locale_labels{$b} }
386 my %locale_field_labels = (
388 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
393 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
394 " WHERE disabled IS NULL OR disabled = '' ")
396 $sth->execute or die $sth->errstr;
397 my $report_option = $sth->fetchrow_arrayref->[0];
400 # - tr-part_pkg_freq: month_increments_only (from price plans)
402 # - test errors cloning
403 # - test custom pricing
404 # - move the selectlayer divs away from lame layer_callback
406 #my ($query) = $cgi->keywords;
411 my %tax_override = ();
413 my %taxproductnums = map { ($_->classnum => 1) }
414 qsearch('usage_class', { 'disabled' => '' });
415 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
418 my $recur_disabled = 1;
419 my $setup_show_zero_disabled = 0;
420 my $recur_show_zero_disabled = 1;
424 my $splice_locale_fields = sub {
425 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
428 my @locale_fields = (
430 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
431 my $pkg_value = $pkg_value_callback
432 ? $pkg_value_callback eq 'cgiparam'
433 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
434 : &$pkg_value_callback($_)
437 { field => 'pkgpartmsgnum'. $n,
439 value => $pkey_value,
441 { field => 'pkgpartmsgnum'. $n. '_locale',
445 { field => 'pkgpartmsgnum'. $n++. '_pkg',
456 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
460 my $error_callback = sub {
461 my($cgi, $object, $fields, $opt ) = @_;
463 (@agent_type) = $cgi->param('agent_type');
465 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
467 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
469 $recur_disabled = $cgi->param('freq') ? 0 : 1;
470 $recur_show_zero_disabled =
472 ? $cgi->param('recur_fee') > 0 ? 1 : 0
475 foreach ($cgi->param) {
476 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
478 $tax_override{''} = $cgi->param('tax_override');
479 $tax_override{$_} = $cgi->param('tax_override_$_')
480 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
482 #some false laziness w/process
483 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
485 my $options = $cgi->param($plan."__OPTIONS");
486 my @options = split(',', $options);
488 map { my $optionname = $_;
489 my $param = $plan."__$optionname";
490 my $value = join(', ', $cgi->param($param));
491 ( $optionname => $value );
495 $object->set($_ => scalar($cgi->param($_)) )
496 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
498 foreach my $currency ( $conf->config('currencies') ) {
499 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
500 foreach (qw( setup_fee recur_fee )) {
501 my $param = $_.'_'.$currency;
502 $object->set( $param, $cgi->param($param) );
506 $pkgpart = $object->pkgpart;
508 &$splice_locale_fields(
512 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
513 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
520 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
522 my $new_object_callback = sub {
523 my( $cgi, $hashref, $fields, $opt ) = @_;
525 my $part_pkg = FS::part_pkg->new( $hashref );
526 $part_pkg->set($_ => '0')
527 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
533 sub set_report_option {
534 my($cgi, $object, $fields ) = @_; #, $opt
536 my @report_option = ();
537 foreach ($object->options) {
538 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
539 /^report_option_(\d+)$/ && (push @report_option, $1);
541 foreach ($object->part_pkg_taxoverride) {
542 $taxproductnums{$_->usage_class} = 1
546 $cgi->param('report_option', join(',', @report_option));
547 foreach my $field ( @$fields ) {
549 ref($field) eq 'HASH' &&
551 $field->{field} eq 'report_option'
553 #$field->{curr_value} = join(',', @report_option);
554 $field->{value} = join(',', @report_option);
559 my $edit_callback = sub {
560 my( $cgi, $object, $fields, $opt ) = @_;
562 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
564 $recur_disabled = $object->freq ? 0 : 1;
566 $recur_show_zero_disabled =
568 ? $object->option('recur_fee') > 0 ? 1 : 0
572 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
574 set_report_option( $cgi, $object, $fields);
576 %options = $object->options;
578 $object->set($_ => $object->option($_, 1))
579 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
581 foreach my $currency ( $conf->config('currencies') ) {
582 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
583 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
584 foreach keys %part_pkg_currency;
587 $pkgpart = $object->pkgpart;
589 &$splice_locale_fields(
593 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
594 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
598 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
599 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
605 my $new_callback = sub {
606 my( $cgi, $object, $fields ) = @_;
608 my $conf = new FS::Conf;
610 if ( $conf->exists('agent_defaultpkg') ) {
611 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
612 @agent_type = map {$_->typenum} qsearch('agent_type',{});
615 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
617 &$splice_locale_fields($fields, '', '');
621 my $clone_callback = sub {
622 my( $cgi, $object, $fields, $opt ) = @_;
624 if ( $cgi->param('pkgnum') ) {
626 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
627 $object->agentnum( $cust_pkg->cust_main->agentnum );
629 $opt->{action} = 'Custom';
631 #my $part_pkg = $clone_part_pkg->clone;
632 #this is all clone does anyway
633 $object->custom('Y');
635 $object->disabled('Y');
637 } else { #when explicitly cloning, not customizing
640 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
644 set_report_option( $cgi, $object, $fields);
646 %options = $object->options;
648 $object->set($_ => $options{$_})
649 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
651 foreach my $currency ( $conf->config('currencies') ) {
652 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
653 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
654 foreach keys %part_pkg_currency;
657 $recur_disabled = $object->freq ? 0 : 1;
659 &$splice_locale_fields(
664 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
665 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
670 my $discount_error_callback = sub {
671 my( $cgi, $object ) = @_;
673 if ( /^discountnum(\d+)$/ &&
674 ( my $discountnum = $cgi->param("discountnum$1") ) )
676 new FS::part_pkg_discount {
677 'pkgpart' => $object->pkgpart,
678 'discountnum' => $discountnum,
687 my $m2_error_callback_maker = sub {
688 my $link_type = shift; #yay closures
690 my( $cgi, $object ) = @_;
693 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
694 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
697 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
699 new FS::part_pkg_link {
700 'link_type' => $link_type,
701 'src_pkgpart' => $object->pkgpart,
702 'dst_pkgpart' => $dst,
713 my $javascript = <<'END';
714 <SCRIPT TYPE="text/javascript">
716 function freq_changed(what) {
717 var freq = what.options[what.selectedIndex].value;
720 what.form.recur_fee.disabled = true;
721 what.form.recur_fee.style.backgroundColor = '#dddddd';
722 what.form.recur_show_zero.disabled = true;
723 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
725 what.form.recur_fee.disabled = false;
726 what.form.recur_fee.style.backgroundColor = '#ffffff';
727 recur_changed( what.form.recur_fee );
728 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
733 function setup_changed(what) {
734 var setup = what.value;
735 if ( parseFloat(setup) == 0 ) {
736 what.form.setup_show_zero.disabled = false;
738 what.form.setup_show_zero.disabled = true;
742 function recur_changed(what) {
743 var recur = what.value;
744 if ( parseFloat(recur) == 0 ) {
745 what.form.recur_show_zero.disabled = false;
747 what.form.recur_show_zero.disabled = true;
751 function agent_changed(what) {
754 if ( what.type == 'select-one' ) {
755 agentnum = what.options[what.selectedIndex].value;
757 agentnum = what.value;
760 if ( agentnum == 0 ) {
761 what.form.agent_type.disabled = false;
762 //what.form.agent_type.style.backgroundColor = '#ffffff';
763 what.form.agent_type.style.visibility = '';
765 what.form.agent_type.disabled = true;
766 //what.form.agent_type.style.backgroundColor = '#dddddd';
767 what.form.agent_type.style.visibility = 'hidden';
772 function aux_planchanged(what) { //?
774 var plan = what.options[what.selectedIndex].value;
776 var term_table = document.getElementById('TableNumber7') // XXX NOT ROBUST
777 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
778 //term_table.disabled = false;
779 term_table.style.visibility = '';
781 //term_table.disabled = true;
782 term_table.style.visibility = 'hidden';
785 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
788 for ( var i=0; i < form.length; i++ ) {
789 if ( currency_regex.test(form[i].name) ) {
790 if ( plan == 'currency_fixed' ) {
791 form[i].disabled = false;
793 form[i].disabled = true;
800 // some magic to make "supplemental packages" less obvious
801 var supp_pkg_rows = [];
802 function show_supp_pkgs_click() {
803 supp_pkg_rows[0].style.display = '';
805 this.style.backgroundColor = '';
806 this.style.border = '';
807 this.style.padding = '';
810 function hide_supp_pkgs() {
811 var all_selects = document.getElementsByTagName('select');
812 for (var i=0; i < all_selects.length; i++) {
813 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
814 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
817 if ( supp_pkg_rows.length == 1 ) {
818 // there are none configured, so hide the row to create a new one
819 supp_pkg_rows[0].style.display = 'none';
820 var button = document.getElementById('show_supp_pkgs');
821 button.onclick = show_supp_pkgs_click;
822 button.style.backgroundColor = '#cccccc';
823 button.style.border = '1px solid #7e0079';
824 button.style.padding = '1px';
831 'Changing the setup or recurring fee will create a new package definition. '.
834 $javascript .= "function confirm_submit(f) {";
835 if ( $conf->exists('part_pkg-lineage') ) {
838 var fields = Array('setup_fee','recur_fee');
839 for(var i=0; i < fields.length; i++) {
840 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
841 return confirm('$warning');
851 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
853 tie my %plan_labels, 'Tie::IxHash',
854 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
857 my $html_bottom = sub {
860 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
862 my $layer_callback = sub {
865 my $html = ntable("#cccccc",2);
869 # <TD ALIGN="right">Recurring fee frequency </TD>
870 # <TD><SELECT NAME="freq">
873 #my @freq = keys %freq;
874 #@freq = grep { /^\d+$/ } @freq
875 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
876 #foreach my $freq ( @freq ) {
877 # $html .= qq(<OPTION VALUE="$freq");
878 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
879 # $html .= ">$freq{$freq}";
882 #$html .= '</SELECT></TD></TR>';
884 my $href = $plans{$layer}->{'fields'};
885 my @fields = exists($plans{$layer}->{'fieldorder'})
886 ? @{$plans{$layer}->{'fieldorder'}}
889 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
891 if(!exists($href->{$field})) {
893 warn "nonexistent part_pkg option: '$field'\n";
897 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
899 my $format = sub { shift };
900 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
902 #XXX these should use elements/ fields... (or this whole thing should
903 #just use layer_fields instead of layer_callback)
905 if ( ! exists($href->{$field}{'type'}) ) {
907 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
908 ( exists($options{$field})
909 ? &$format($options{$field})
910 : $href->{$field}{'default'} ).
913 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
915 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
916 ( exists($options{$field}) && $options{$field}
921 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
925 if $href->{$field}{'type'} eq 'select_multiple';
926 $html .= qq! NAME="${layer}__$field">!;
928 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
929 if exists($href->{$field}{'disable_empty'})
930 && ! $href->{$field}{'disable_empty'};
932 if ( $href->{$field}{'select_table'} ) {
934 qsearch( $href->{$field}{'select_table'},
935 $href->{$field}{'select_hash'} )
937 my $value = $record->getfield($href->{$field}{'select_key'});
938 $html .= qq!<OPTION VALUE="$value"!.
939 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
943 '>'. $record->getfield($href->{$field}{'select_label'});
945 } elsif ( $href->{$field}{'select_options'} ) {
946 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
947 my $label = $href->{$field}{'select_options'}{$key};
948 $html .= qq!<OPTION VALUE="$key"!.
949 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
957 $html .= '<font color="#ff0000">warning: '.
958 "don't know how to retreive options for $field select field".
961 $html .= '</SELECT>';
963 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
966 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
968 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
969 my $label = $href->{$field}{'options'}{$key};
970 $html .= qq!$radio VALUE="$key"!.
971 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
980 $html .= '</TD></TR>';
984 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
985 join(',', keys %{ $href } ). '">';
993 options => [ keys %plan_labels ],
994 labels => \%plan_labels,
995 curr_value => $object->plan,
996 layer_callback => $layer_callback,
997 onchange => 'aux_planchanged(what);',
1001 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1002 '<SCRIPT TYPE="text/javascript">'.
1003 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
1006 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
1009 $return .= '</SCRIPT>';
1015 my %usage_class = map { ($_->classnum => $_->classname) }
1016 qsearch('usage_class', {});
1017 $usage_class{setup} = 'Setup';
1018 $usage_class{recur} = 'Recurring';
1020 my %taxproduct_fields = ();
1021 my $end_callback = sub {
1022 my( $cgi, $object, $fields, $opt ) = @_;
1024 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1026 if ( $object->pkgpart ) {
1027 foreach my $usage_class ( '', @taxproductnums ) {
1028 $tax_override{$usage_class} =
1029 join (",", map $_->taxclassnum,
1030 qsearch( 'part_pkg_taxoverride', {
1031 'pkgpart' => $object->pkgpart,
1032 'usage_class' => $usage_class,
1038 %taxproduct_fields =
1039 map { $_ => [ "taxproductnum_$_",
1040 { type => 'select-taxproduct',
1041 #label => "$usage_class{$_} tax product",
1044 { type => 'select-taxoverride' }
1049 $taxproduct_fields{'(default)'} =
1050 [ 'taxproductnum', { type => 'select-taxproduct',
1051 #label => 'Default tax product',
1053 'tax_override', { type => 'select-taxoverride' },
1057 my $taxproduct_values = sub {
1058 my ($cgi, $object, $flags) = @_;
1060 sub { my $layer = shift;
1061 my @fields = @{$taxproduct_fields{$layer}};
1064 my $field = shift @fields;
1066 $field =~ /^taxproductnum_\w+$/ &&
1067 push @values, ( $field => $options{"usage_$field"} );
1068 $field =~ /^tax_override_(\w+)$/ &&
1069 push @values, ( $field => $tax_override{$1} );
1070 $field =~ /^taxproductnum$/ &&
1071 push @values, ( $field => $object->taxproductnum );
1072 $field =~ /^tax_override$/ &&
1073 push @values, ( $field => $tax_override{''} );
1079 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1080 return({ @result });
1084 my $field_callback = sub {
1085 my ($cgi, $object, $fieldref) = @_;
1087 my $field = $fieldref->{field};
1088 if ($field eq 'taxproductnums') {
1089 $fieldref->{value} = join(',', @taxproductnums);
1090 } elsif ($field eq 'taxproduct_select') {
1091 $fieldref->{options} = [ '(default)', @taxproductnums ];
1092 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1093 map {( $_ => ($usage_class{$_} || $_) )}
1096 $fieldref->{layer_fields} = \%taxproduct_fields;
1097 $fieldref->{layer_values_callback} = $taxproduct_values;
1101 my $discountnum_hashref = {
1103 'months' => { 'op' => '>', 'value' => 1 },