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 'start_on_hold' => 'Start on hold',
48 'setup_cost' => 'Setup cost',
49 'recur_cost' => 'Recur cost',
50 'pay_weight' => 'Payment weight',
51 'credit_weight' => 'Credit weight',
52 'agent_pkgpartid' => 'External ID',
53 'agentnum' => 'Agent',
54 'agent_type' => ' ', #just its title headingn is fine
55 'setup_fee' => 'Setup fee',
56 'setup_show_zero' => 'Show zero setup',
57 'recur_fee' => 'Recurring fee',
58 'recur_show_zero' => 'Show zero recurring',
59 ( map { ( "setup_fee_$_" => "Setup fee $_",
60 "recur_fee_$_" => "Recurring fee $_",
63 $conf->config('currencies')
65 'usagepricepart' => ' ',
66 'discountnum' => 'Offer discounts for longer terms',
67 'bill_dst_pkgpart' => 'Include line item(s) from package',
68 'svc_dst_pkgpart' => 'Include services of package',
69 'supp_dst_pkgpart' => 'When ordering package, also order',
70 'report_option' => 'Report classes',
71 'fcc_ds0s' => 'Voice-grade equivalents',
72 'fcc_voip_class' => 'Category',
73 'delay_start' => 'Default delay (days)',
77 { field=>'clone', type=>'hidden',
78 curr_value_callback =>
79 sub { shift->param('clone') },
81 { field=>'pkgnum', type=>'hidden',
82 curr_value_callback =>
83 sub { shift->param('pkgnum') },
86 { field=>'custom', type=>'hidden' },
87 { field=>'family_pkgpart', type=>'hidden' },
88 { field=>'successor', type=>'hidden' },
90 { type => 'columnstart' },
98 {field=>'comment', type=>'text', size=>40 }, #32
99 { field => 'agentnum',
100 type => 'select-agent',
101 disable_empty => ! $acl_edit_global,
102 empty_label => '(global)',
103 onchange => 'agent_changed',
105 {field=>'classnum', type=>'select-pkg_class' },
106 ( $conf->exists('pkg-addon_classnum')
107 ? ( { field=>'addon_classnum',
108 type =>'select-pkg_class',
113 {field=>'disabled', type=>$disabled_type, value=>'Y'},
114 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
115 { field => 'start_on_hold',
120 { type => 'tablebreak-tr-title',
121 value => 'Pricing', #better name?
124 type => 'selectlayers-select',
125 options => [ keys %plan_labels ],
126 labels => \%plan_labels,
127 onchange => 'aux_planchanged(what);',
129 { field => 'setup_fee',
131 onchange => 'setup_changed',
133 { field => 'setup_show_zero',
136 disabled => sub { $setup_show_zero_disabled },
138 ( map { +{ field => "setup_fee_$_",
140 prefix=> currency_symbol($_, SYM_HTML),
144 sort $conf->config('currencies')
147 type => 'part_pkg_freq',
148 onchange => 'freq_changed',
150 { field => 'recur_fee',
152 disabled => sub { $recur_disabled },
153 onchange => 'recur_changed',
155 { field => 'recur_show_zero',
158 disabled => sub { $recur_show_zero_disabled },
160 ( map { +{ field => "recur_fee_$_",
162 prefix=> currency_symbol($_, SYM_HTML),
166 sort $conf->config('currencies')
172 #recurring fee (auto-disable)
174 { type => 'columnnext' },
176 {type=>'justtitle', value=>'Taxation' },
177 {field=>'setuptax', type=>'checkbox', value=>'Y'},
178 {field=>'recurtax', type=>'checkbox', value=>'Y'},
179 {field=>'taxclass', type=>'select-taxclass' },
180 { field => 'taxproductnums',
182 value => join(',', @taxproductnums),
184 { field => 'taxproduct_select',
185 type => 'selectlayers',
186 options => [ '(default)', @taxproductnums ],
187 curr_value => '(default)',
188 labels => { ( '(default)' => '(default)' ),
189 map {($_=>$usage_class{$_})}
192 layer_fields => \%taxproduct_fields,
193 layer_values_callback => $taxproduct_values,
194 layers_only => !$taxproducts,
195 cell_style => ( !$taxproducts
201 { type => 'tablebreak-tr-title',
202 value => 'Promotions', #better name?
204 { field=>'promo_code', type=>'text', size=>15 },
206 { type => 'tablebreak-tr-title',
207 value => 'Cost tracking', #better name?
210 ( $curuser->access_right('Edit package definition costs')
211 ? ( { field=>'setup_cost', type=>'money', },
212 { field=>'recur_cost', type=>'money', },
214 : ( { field=>'setup_cost', type=>'fixed', },
215 { field=>'recur_cost', type=>'fixed', },
219 ( $conf->exists('part_pkg-delay_start')
220 ? ( { type => 'tablebreak-tr-title',
221 value => 'Delayed start',
223 { field => 'delay_start',
224 type => 'text', size => 6 },
229 { type => 'columnnext' },
231 {type=>'justtitle', value=>'Agent (reseller) types' },
233 { field => 'agent_type',
234 type => 'select-agent_type',
235 disabled => ! $acl_edit_global,
236 element_etc => 'size="10"',
237 multiple => '1', #cause edit.html is dum
238 curr_value_callback => sub {
239 my($cgi, $object, $field) = @_;
240 #in the other callbacks..? hmm.
246 { type => 'tablebreak-tr-title',
247 value => 'FCC Form 477 information',
249 { field => 'fcc_options_string',
250 type => 'input-fcc_options',
251 curr_value_callback => sub {
252 my ($cgi, $part_pkg, $fref) = @_;
253 if ( $cgi->param('fcc_options_string') ) {
255 return $cgi->param('fcc_options_string');
258 %hash = $part_pkg->fcc_options
259 if ($part_pkg->pkgpart);
260 return encode_json(\%hash);
266 { type => 'tablebreak-tr-title',
267 value => 'External Links', #better name?
269 { field=>'agent_pkgpartid', type=>'text', size=>21 },
271 { type => 'tablebreak-tr-title',
272 value => 'Line-item revenue recogition', #better name?
274 { field=>'pay_weight', type=>'text', size=>6 },
275 { field=>'credit_weight', type=>'text', size=>6 },
277 { type => 'columnend' },
279 { type => 'tablebreak-tr-title',
280 value => 'Usage pricing add-ons', #better name? just 'Usage pricing' ? there's also CDR usage pricing, RADIUS usage pricing, etc :/
282 { 'field' => 'usagepricepart',
283 'type' => 'part_pkg_usageprice',
284 'o2m_table' => 'part_pkg_usageprice',
286 'm2_error_callback' => $usageprice_error_callback,
289 { 'type' => $report_option ? 'tablebreak-tr-title'
291 'value' => 'Optional report classes',
292 'field' => 'census_title',
294 { 'field' => 'report_option',
295 'type' => $report_option ? 'select-table'
297 'table' => 'part_pkg_report_option',
298 'name_col' => 'name',
299 'hashref' => { 'disabled' => '' },
303 { 'type' => 'tablebreak-tr-title',
304 'value' => 'Term discounts',
306 { 'field' => 'discountnum',
307 'type' => 'select-table',
308 'table' => 'discount',
309 'name_col' => 'name',
310 'hashref' => { %$discountnum_hashref },
311 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
312 'empty_label'=> 'Select discount',
313 'm2_label' => 'Offer discounts for longer terms',
314 'm2m_method' => 'part_pkg_discount',
315 'm2m_dstcol' => 'discountnum',
316 'm2_error_callback' => $discount_error_callback,
319 { 'type' => 'tablebreak-tr-title',
320 'value' => 'Pricing add-ons',
323 { 'field' => 'bill_dst_pkgpart',
324 'type' => 'select-part_pkg',
325 'extra_sql' => sub { $pkgpart
326 ? "AND pkgpart != $pkgpart"
329 'label_callback' => sub { shift->pkg_comment_only },
330 'm2_label' => 'Include line item(s) from package',
331 'm2m_method' => 'bill_part_pkg_link',
332 'm2m_dstcol' => 'dst_pkgpart',
333 'm2_error_callback' =>
334 &{$m2_error_callback_maker}('bill'),
335 'm2_fields' => [ { 'field' => 'hidden',
336 'type' => 'checkbox',
344 { type => 'tablebreak-tr-title',
347 { type => 'pkg_svc', },
349 { 'field' => 'svc_dst_pkgpart',
350 'label' => 'Also include services from package: ',
351 'type' => 'select-part_pkg',
352 'extra_sql' => sub { $pkgpart
353 ? "AND pkgpart != $pkgpart"
356 'label_callback' => sub { shift->pkg_comment_only },
357 'm2_label' => 'Include services of package: ',
358 'm2m_method' => 'svc_part_pkg_link',
359 'm2m_dstcol' => 'dst_pkgpart',
360 'm2_error_callback' =>
361 &{$m2_error_callback_maker}('svc'),
364 { 'type' => 'tablebreak-tr-title',
365 'value' => 'Supplemental packages',
367 'include_opt_callback' => sub {
368 'id' => 'show_supp_pkgs',
371 { 'field' => 'supp_dst_pkgpart',
372 'type' => 'select-part_pkg',
373 'label_callback' => sub { shift->pkg_comment_only },
374 'm2_label' => 'When ordering package, also order',
375 'm2m_method' => 'supp_part_pkg_link',
376 'm2m_dstcol' => 'dst_pkgpart',
377 'm2_error_callback' =>
378 &{$m2_error_callback_maker}('supp'),
381 { type => 'tablebreak-tr-title',
382 value => 'Price plan options',
389 my $curuser = $FS::CurrentUser::CurrentUser;
391 my $edit_global = 'Edit global package definitions';
392 my $acl_edit = $curuser->access_right('Edit package definitions');
393 my $acl_edit_global = $curuser->access_right($edit_global);
395 my $acl_edit_either = $acl_edit || $acl_edit_global;
397 my $begin_callback = sub {
398 my( $cgi, $fields, $opt ) = @_;
400 unless $acl_edit_either
401 || ( $cgi->param('pkgnum')
402 && $curuser->access_right('Customize customer package')
406 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
408 #arg. access rights for cloning are Hard.
409 # on the one hand we don't really want cloning (customizing a package) to fail
410 # for want of finding the source package in normal usage
411 # on the other hand, we don't want people using the clone link to be able to
413 my $agent_clone_extra_sql =
414 ' ( '. FS::part_pkg->curuser_pkgs_sql.
415 " OR ( part_pkg.custom = 'Y' ) ".
418 my $conf = new FS::Conf;
419 my $taxproducts = $conf->exists('enable_taxproducts');
421 my $fcc_opts = $conf->exists('part_pkg-show_fcc_options');
423 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
424 my %locale_labels = map {
425 ( $_ => 'Package -- '. FS::Locales->description($_) )
428 sort { $locale_labels{$a} cmp $locale_labels{$b} }
432 my %locale_field_labels = (
434 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
439 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
440 " WHERE disabled IS NULL OR disabled = '' ")
442 $sth->execute or die $sth->errstr;
443 my $report_option = $sth->fetchrow_arrayref->[0];
446 # - tr-part_pkg_freq: month_increments_only (from price plans)
448 # - test errors cloning
449 # - test custom pricing
450 # - move the selectlayer divs away from lame layer_callback
452 #my ($query) = $cgi->keywords;
457 my %tax_override = ();
459 my %taxproductnums = map { ($_->classnum => 1) }
460 qsearch('usage_class', { 'disabled' => '' });
461 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
464 my $recur_disabled = 1;
465 my $setup_show_zero_disabled = 0;
466 my $recur_show_zero_disabled = 1;
470 my $splice_locale_fields = sub {
471 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
474 my @locale_fields = (
476 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
477 my $pkg_value = $pkg_value_callback
478 ? $pkg_value_callback eq 'cgiparam'
479 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
480 : &$pkg_value_callback($_)
483 { field => 'pkgpartmsgnum'. $n,
485 value => $pkey_value,
487 { field => 'pkgpartmsgnum'. $n. '_locale',
491 { field => 'pkgpartmsgnum'. $n++. '_pkg',
502 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
506 my $error_callback = sub {
507 my($cgi, $object, $fields, $opt ) = @_;
509 (@agent_type) = $cgi->param('agent_type');
511 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
513 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
515 $recur_disabled = $cgi->param('freq') ? 0 : 1;
516 $recur_show_zero_disabled =
518 ? $cgi->param('recur_fee') > 0 ? 1 : 0
521 foreach ($cgi->param) {
522 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
524 $tax_override{''} = $cgi->param('tax_override');
525 $tax_override{$_} = $cgi->param('tax_override_$_')
526 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
528 #some false laziness w/process
529 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
531 my $options = $cgi->param($plan."__OPTIONS");
532 my @options = split(',', $options);
534 map { my $optionname = $_;
535 my $param = $plan."__$optionname";
536 my $value = join(', ', $cgi->param($param));
537 ( $optionname => $value );
541 $object->set($_ => scalar($cgi->param($_)) )
542 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
544 foreach my $currency ( $conf->config('currencies') ) {
545 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
546 foreach (qw( setup_fee recur_fee )) {
547 my $param = $_.'_'.$currency;
548 $object->set( $param, $cgi->param($param) );
552 $pkgpart = $object->pkgpart;
554 &$splice_locale_fields(
558 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
559 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
566 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
568 my $new_object_callback = sub {
569 my( $cgi, $hashref, $fields, $opt ) = @_;
571 my $part_pkg = FS::part_pkg->new( $hashref );
572 $part_pkg->set($_ => '0')
573 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
579 sub set_report_option {
580 my($cgi, $object, $fields ) = @_; #, $opt
582 my @report_option = ();
583 foreach ($object->options) {
584 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
585 /^report_option_(\d+)$/ && (push @report_option, $1);
587 foreach ($object->part_pkg_taxoverride) {
588 $taxproductnums{$_->usage_class} = 1
592 $cgi->param('report_option', join(',', @report_option));
593 foreach my $field ( @$fields ) {
595 ref($field) eq 'HASH' &&
597 $field->{field} eq 'report_option'
599 #$field->{curr_value} = join(',', @report_option);
600 $field->{value} = join(',', @report_option);
605 my $edit_callback = sub {
606 my( $cgi, $object, $fields, $opt ) = @_;
608 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
610 $recur_disabled = $object->freq ? 0 : 1;
612 $recur_show_zero_disabled =
614 ? $object->option('recur_fee') > 0 ? 1 : 0
618 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
620 set_report_option( $cgi, $object, $fields);
622 %options = $object->options;
624 $object->set($_ => $object->option($_, 1))
625 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
627 foreach my $currency ( $conf->config('currencies') ) {
628 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
629 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
630 foreach keys %part_pkg_currency;
633 $pkgpart = $object->pkgpart;
635 &$splice_locale_fields(
639 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
640 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
644 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
645 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
651 my $new_callback = sub {
652 my( $cgi, $object, $fields ) = @_;
654 my $conf = new FS::Conf;
656 if ( $conf->exists('agent_defaultpkg') ) {
657 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
658 @agent_type = map {$_->typenum} qsearch('agent_type',{});
661 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
663 &$splice_locale_fields($fields, '', '');
667 my $clone_callback = sub {
668 my( $cgi, $object, $fields, $opt ) = @_;
670 if ( $cgi->param('pkgnum') ) {
672 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
673 $object->agentnum( $cust_pkg->cust_main->agentnum );
675 $opt->{action} = 'Custom';
677 #my $part_pkg = $clone_part_pkg->clone;
678 #this is all clone does anyway
679 $object->custom('Y');
681 $object->disabled('Y');
683 } else { #when explicitly cloning, not customizing
686 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
690 set_report_option( $cgi, $object, $fields);
692 %options = $object->options;
694 $object->set($_ => $options{$_})
695 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
697 foreach my $currency ( $conf->config('currencies') ) {
698 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
699 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
700 foreach keys %part_pkg_currency;
703 $recur_disabled = $object->freq ? 0 : 1;
705 &$splice_locale_fields(
710 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
711 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
716 my $discount_error_callback = sub {
717 my( $cgi, $object ) = @_;
719 if ( /^discountnum(\d+)$/ &&
720 ( my $discountnum = $cgi->param("discountnum$1") ) )
722 new FS::part_pkg_discount {
723 'pkgpart' => $object->pkgpart,
724 'discountnum' => $discountnum,
733 my $usageprice_error_callback = sub {
734 my( $cgi, $object ) = @_;
736 if ( /^usagepricepart(\d+)_price$/
737 && $cgi->param("usagepricepart$1_price") )
739 new FS::part_pkg_usageprice {
740 'usagepricepart' => $cgi->param("usagepricepart$1"),
741 'pkgpart' => $object->pkgpart,
742 'price' => scalar($cgi->param("usagepricepart$1_price")),
744 'action' => scalar($cgi->param("usagepricepart$1_action")),
745 'target' => scalar($cgi->param("usagepricepart$1_target")),
746 'amount' => scalar($cgi->param("usagepricepart$1_amount")),
755 my $m2_error_callback_maker = sub {
756 my $link_type = shift; #yay closures
758 my( $cgi, $object ) = @_;
761 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
762 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
765 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
767 new FS::part_pkg_link {
768 'link_type' => $link_type,
769 'src_pkgpart' => $object->pkgpart,
770 'dst_pkgpart' => $dst,
781 my $javascript = <<'END';
782 <SCRIPT TYPE="text/javascript">
784 function freq_changed(what) {
785 var freq = what.options[what.selectedIndex].value;
788 what.form.recur_fee.disabled = true;
789 what.form.recur_fee.style.backgroundColor = '#dddddd';
790 what.form.recur_show_zero.disabled = true;
791 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
793 what.form.recur_fee.disabled = false;
794 what.form.recur_fee.style.backgroundColor = '#ffffff';
795 recur_changed( what.form.recur_fee );
796 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
801 function setup_changed(what) {
802 var setup = what.value;
803 if ( parseFloat(setup) == 0 ) {
804 what.form.setup_show_zero.disabled = false;
806 what.form.setup_show_zero.disabled = true;
810 function recur_changed(what) {
811 var recur = what.value;
812 if ( parseFloat(recur) == 0 ) {
813 what.form.recur_show_zero.disabled = false;
815 what.form.recur_show_zero.disabled = true;
819 function agent_changed(what) {
822 if ( what.type == 'select-one' ) {
823 agentnum = what.options[what.selectedIndex].value;
825 agentnum = what.value;
828 if ( agentnum == 0 ) {
829 what.form.agent_type.disabled = false;
830 //what.form.agent_type.style.backgroundColor = '#ffffff';
831 what.form.agent_type.style.visibility = '';
833 what.form.agent_type.disabled = true;
834 //what.form.agent_type.style.backgroundColor = '#dddddd';
835 what.form.agent_type.style.visibility = 'hidden';
840 function aux_planchanged(what) { //?
842 var plan = what.options[what.selectedIndex].value;
844 var term_table = document.getElementById('TableNumber8') // XXX NOT ROBUST
845 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
846 //term_table.disabled = false;
847 //term_table.style.visibility = '';
848 term_table.style.display = '';
850 //term_table.disabled = true;
851 //term_table.style.visibility = 'hidden';
852 term_table.style.display = 'none';
855 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
858 for ( var i=0; i < form.length; i++ ) {
859 if ( currency_regex.test(form[i].name) ) {
860 if ( plan == 'currency_fixed' ) {
861 form[i].disabled = false;
863 form[i].disabled = true;
870 // some magic to make "supplemental packages" less obvious
871 var supp_pkg_rows = [];
872 function show_supp_pkgs_click() {
873 supp_pkg_rows[0].style.display = '';
875 this.style.backgroundColor = '';
876 this.style.border = '';
877 this.style.padding = '';
880 function hide_supp_pkgs() {
881 var all_selects = document.getElementsByTagName('select');
882 for (var i=0; i < all_selects.length; i++) {
883 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
884 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
887 if ( supp_pkg_rows.length == 1 ) {
888 // there are none configured, so hide the row to create a new one
889 supp_pkg_rows[0].style.display = 'none';
890 var button = document.getElementById('show_supp_pkgs');
891 button.onclick = show_supp_pkgs_click;
892 button.style.backgroundColor = '#cccccc';
893 button.style.border = '1px solid #7e0079';
894 button.style.padding = '1px';
901 'Changing the setup or recurring fee will create a new package definition. '.
904 $javascript .= "function confirm_submit(f) {";
905 if ( $conf->exists('part_pkg-lineage') ) {
908 var fields = Array('setup_fee','recur_fee');
909 for(var i=0; i < fields.length; i++) {
910 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
911 return confirm('$warning');
921 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
923 tie my %plan_labels, 'Tie::IxHash',
924 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
927 my $html_bottom = sub {
930 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
932 my $layer_callback = sub {
935 my $html = ntable("#cccccc",2);
939 # <TD ALIGN="right">Recurring fee frequency </TD>
940 # <TD><SELECT NAME="freq">
943 #my @freq = keys %freq;
944 #@freq = grep { /^\d+$/ } @freq
945 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
946 #foreach my $freq ( @freq ) {
947 # $html .= qq(<OPTION VALUE="$freq");
948 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
949 # $html .= ">$freq{$freq}";
952 #$html .= '</SELECT></TD></TR>';
954 my $href = $plans{$layer}->{'fields'};
955 my @fields = exists($plans{$layer}->{'fieldorder'})
956 ? @{$plans{$layer}->{'fieldorder'}}
959 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
961 if(!exists($href->{$field})) {
963 warn "nonexistent part_pkg option: '$field'\n";
966 if ( exists($href->{$field}->{display_if}) ) {
967 my %args = ( 'plan' => $layer ); # anything else?
968 my $display = &{ $href->{$field}->{display_if} }(%args);
972 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
974 my $format = sub { shift };
975 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
977 #XXX these should use elements/ fields... (or this whole thing should
978 #just use layer_fields instead of layer_callback)
980 if ( ! exists($href->{$field}{'type'}) ) {
982 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
983 ( exists($options{$field})
984 ? &$format($options{$field})
985 : $href->{$field}{'default'} ).
988 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
990 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
991 ( exists($options{$field}) && $options{$field}
996 } elsif ( $href->{$field}{'type'} eq 'select-rate' ) {
998 $html .= include('/elements/select-rate.html',
999 'field' => $layer.'__'.$field,
1000 'curr_value' => $options{$field},
1001 map { $_ => $href->{$field}{$_} }
1002 grep { $_ !~ /^(name|type)$/ }
1003 keys %{ $href->{$field} }
1006 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
1009 $html .= ' MULTIPLE'
1010 if $href->{$field}{'type'} eq 'select_multiple';
1011 $html .= qq! NAME="${layer}__$field">!;
1013 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
1014 if exists($href->{$field}{'disable_empty'})
1015 && ! $href->{$field}{'disable_empty'};
1017 if ( $href->{$field}{'select_table'} ) {
1018 foreach my $record (
1019 qsearch( $href->{$field}{'select_table'},
1020 $href->{$field}{'select_hash'} )
1022 my $value = $record->getfield($href->{$field}{'select_key'});
1023 $html .= qq!<OPTION VALUE="$value"!.
1024 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
1028 '>'. $record->getfield($href->{$field}{'select_label'});
1030 } elsif ( $href->{$field}{'select_options'} ) {
1031 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
1032 my $label = $href->{$field}{'select_options'}{$key};
1033 $html .= qq!<OPTION VALUE="$key"!.
1034 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1042 $html .= '<font color="#ff0000">warning: '.
1043 "don't know how to retreive options for $field select field".
1046 $html .= '</SELECT>';
1048 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
1051 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
1053 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
1054 my $label = $href->{$field}{'options'}{$key};
1055 $html .= qq!$radio VALUE="$key"!.
1056 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1065 $html .= '</TD></TR>';
1067 $html .= '</TABLE>';
1069 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
1070 join(',', keys %{ $href } ). '">';
1076 my %selectlayers = (
1078 options => [ keys %plan_labels ],
1079 labels => \%plan_labels,
1080 curr_value => $object->plan,
1081 layer_callback => $layer_callback,
1082 onchange => 'aux_planchanged(what);',
1086 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1087 '<SCRIPT TYPE="text/javascript">'.
1088 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
1091 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
1094 $return .= '</SCRIPT>';
1100 my %usage_class = map { ($_->classnum => $_->classname) }
1101 qsearch('usage_class', {});
1102 $usage_class{setup} = 'Setup';
1103 $usage_class{recur} = 'Recurring';
1105 my %taxproduct_fields = ();
1106 my $end_callback = sub {
1107 my( $cgi, $object, $fields, $opt ) = @_;
1109 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1111 if ( $object->pkgpart ) {
1112 foreach my $usage_class ( '', @taxproductnums ) {
1113 $tax_override{$usage_class} =
1114 join (",", map $_->taxclassnum,
1115 qsearch( 'part_pkg_taxoverride', {
1116 'pkgpart' => $object->pkgpart,
1117 'usage_class' => $usage_class,
1123 %taxproduct_fields =
1124 map { $_ => [ "taxproductnum_$_",
1125 { type => 'select-taxproduct',
1126 #label => "$usage_class{$_} tax product",
1129 { type => 'select-taxoverride' }
1134 $taxproduct_fields{'(default)'} =
1135 [ 'taxproductnum', { type => 'select-taxproduct',
1136 #label => 'Default tax product',
1138 'tax_override', { type => 'select-taxoverride' },
1142 my $taxproduct_values = sub {
1143 my ($cgi, $object, $flags) = @_;
1145 sub { my $layer = shift;
1146 my @fields = @{$taxproduct_fields{$layer}};
1149 my $field = shift @fields;
1151 $field =~ /^taxproductnum_\w+$/ &&
1152 push @values, ( $field => $options{"usage_$field"} );
1153 $field =~ /^tax_override_(\w+)$/ &&
1154 push @values, ( $field => $tax_override{$1} );
1155 $field =~ /^taxproductnum$/ &&
1156 push @values, ( $field => $object->taxproductnum );
1157 $field =~ /^tax_override$/ &&
1158 push @values, ( $field => $tax_override{''} );
1164 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1165 return({ @result });
1169 my $field_callback = sub {
1170 my ($cgi, $object, $fieldref) = @_;
1172 my $field = $fieldref->{field};
1173 if ($field eq 'taxproductnums') {
1174 $fieldref->{value} = join(',', @taxproductnums);
1175 } elsif ($field eq 'taxproduct_select') {
1176 $fieldref->{options} = [ '(default)', @taxproductnums ];
1177 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1178 map {( $_ => ($usage_class{$_} || $_) )}
1181 $fieldref->{layer_fields} = \%taxproduct_fields;
1182 $fieldref->{layer_values_callback} = $taxproduct_values;
1186 my $discountnum_hashref = {
1188 'months' => { 'op' => '>', 'value' => 1 },