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 'delay_start' => 'Default delay (days)',
75 { field=>'clone', type=>'hidden',
76 curr_value_callback =>
77 sub { shift->param('clone') },
79 { field=>'pkgnum', type=>'hidden',
80 curr_value_callback =>
81 sub { shift->param('pkgnum') },
84 { field=>'custom', type=>'hidden' },
85 { field=>'family_pkgpart', type=>'hidden' },
86 { field=>'successor', type=>'hidden' },
88 { type => 'columnstart' },
96 {field=>'comment', type=>'text', size=>40 }, #32
97 { field => 'agentnum',
98 type => 'select-agent',
99 disable_empty => ! $acl_edit_global,
100 empty_label => '(global)',
101 onchange => 'agent_changed',
103 {field=>'classnum', type=>'select-pkg_class' },
104 ( $conf->exists('pkg-addon_classnum')
105 ? ( { field=>'addon_classnum',
106 type =>'select-pkg_class',
111 {field=>'disabled', type=>$disabled_type, value=>'Y'},
112 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
113 { field => 'start_on_hold',
118 { type => 'tablebreak-tr-title',
119 value => 'Pricing', #better name?
122 type => 'selectlayers-select',
123 options => [ keys %plan_labels ],
124 labels => \%plan_labels,
125 onchange => 'aux_planchanged(what);',
127 { field => 'setup_fee',
129 onchange => 'setup_changed',
131 { field => 'setup_show_zero',
134 disabled => sub { $setup_show_zero_disabled },
136 ( map { +{ field => "setup_fee_$_",
138 prefix=> currency_symbol($_, SYM_HTML),
142 sort $conf->config('currencies')
145 type => 'part_pkg_freq',
146 onchange => 'freq_changed',
148 { field => 'recur_fee',
150 disabled => sub { $recur_disabled },
151 onchange => 'recur_changed',
153 { field => 'recur_show_zero',
156 disabled => sub { $recur_show_zero_disabled },
158 ( map { +{ field => "recur_fee_$_",
160 prefix=> currency_symbol($_, SYM_HTML),
164 sort $conf->config('currencies')
170 #recurring fee (auto-disable)
172 { type => 'columnnext' },
174 {type=>'justtitle', value=>'Taxation' },
175 {field=>'setuptax', type=>'checkbox', value=>'Y'},
176 {field=>'recurtax', type=>'checkbox', value=>'Y'},
177 {field=>'taxclass', type=>'select-taxclass' },
178 { field => 'taxproductnums',
180 value => join(',', @taxproductnums),
182 #{ field => 'taxproduct_select',
183 # type => 'selectlayers',
184 # options => [ '(default)', @taxproductnums ],
185 # curr_value => '(default)',
186 # labels => { ( '(default)' => '(default)' ),
187 # map {($_=>$usage_class{$_})}
190 # layer_fields => \%taxproduct_fields,
191 # layer_values_callback => $taxproduct_values,
192 # layers_only => !$taxproducts,
193 # cell_style => ( !$taxproducts
198 { field => 'taxproductnum',
199 type => 'part_pkg-taxproducts',
200 include_opt_callback =>
201 sub { pkgpart => $_[0]->pkgpart },
204 { type => 'tablebreak-tr-title',
205 value => 'Promotions', #better name?
207 { field=>'promo_code', type=>'text', size=>15 },
209 { type => 'tablebreak-tr-title',
210 value => 'Cost tracking', #better name?
213 ( $curuser->access_right('Edit package definition costs')
214 ? ( { field=>'setup_cost', type=>'money', },
215 { field=>'recur_cost', type=>'money', },
217 : ( { field=>'setup_cost', type=>'fixed', },
218 { field=>'recur_cost', type=>'fixed', },
222 ( $conf->exists('part_pkg-delay_start')
223 ? ( { type => 'tablebreak-tr-title',
224 value => 'Delayed start',
226 { field => 'delay_start',
227 type => 'text', size => 6 },
232 { type => 'columnnext' },
234 {type=>'justtitle', value=>'Agent (reseller) types' },
236 { field => 'agent_type',
237 type => 'select-agent_type',
238 disabled => ! $acl_edit_global,
239 element_etc => 'size="10"',
240 multiple => '1', #cause edit.html is dum
241 curr_value_callback => sub {
242 my($cgi, $object, $field) = @_;
243 #in the other callbacks..? hmm.
249 { type => 'tablebreak-tr-title',
250 value => 'FCC Form 477 information',
252 { field => 'fcc_options_string',
253 type => 'input-fcc_options',
254 curr_value_callback => sub {
255 my ($cgi, $part_pkg, $fref) = @_;
256 if ( $cgi->param('fcc_options_string') ) {
258 return $cgi->param('fcc_options_string');
261 %hash = $part_pkg->fcc_options
262 if ($part_pkg->pkgpart);
263 return encode_json(\%hash);
269 { type => 'tablebreak-tr-title',
270 value => 'External Links', #better name?
272 { field=>'agent_pkgpartid', type=>'text', size=>21 },
274 { type => 'tablebreak-tr-title',
275 value => 'Line-item revenue recogition', #better name?
277 { field=>'pay_weight', type=>'text', size=>6 },
278 { field=>'credit_weight', type=>'text', size=>6 },
280 { type => 'columnend' },
282 { type => 'tablebreak-tr-title',
283 value => 'Usage pricing add-ons', #better name? just 'Usage pricing' ? there's also CDR usage pricing, RADIUS usage pricing, etc :/
285 { 'field' => 'usagepricepart',
286 'type' => 'part_pkg_usageprice',
287 'o2m_table' => 'part_pkg_usageprice',
289 'm2_error_callback' => $usageprice_error_callback,
292 { 'type' => $report_option ? 'tablebreak-tr-title'
294 'value' => 'Optional report classes',
295 'field' => 'census_title',
297 { 'field' => 'report_option',
298 'type' => $report_option ? 'select-table'
300 'table' => 'part_pkg_report_option',
301 'name_col' => 'name',
302 'hashref' => { 'disabled' => '' },
306 { 'type' => 'tablebreak-tr-title',
307 'value' => 'Term discounts',
309 { 'field' => 'discountnum',
310 'type' => 'select-table',
311 'table' => 'discount',
312 'name_col' => 'name',
313 'hashref' => { %$discountnum_hashref },
314 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
315 'empty_label'=> 'Select discount',
316 'm2_label' => 'Offer discounts for longer terms',
317 'm2m_method' => 'part_pkg_discount',
318 'm2m_dstcol' => 'discountnum',
319 'm2_error_callback' => $discount_error_callback,
322 { 'type' => 'tablebreak-tr-title',
323 'value' => 'Pricing add-ons',
326 { 'field' => 'bill_dst_pkgpart',
327 'type' => 'select-part_pkg',
328 'extra_sql' => sub { $pkgpart
329 ? "AND pkgpart != $pkgpart"
332 'label_callback' => sub { shift->pkg_comment_only },
333 'm2_label' => 'Include line item(s) from package',
334 'm2m_method' => 'bill_part_pkg_link',
335 'm2m_dstcol' => 'dst_pkgpart',
336 'm2_error_callback' =>
337 &{$m2_error_callback_maker}('bill'),
338 'm2_fields' => [ { 'field' => 'hidden',
339 'type' => 'checkbox',
347 { type => 'tablebreak-tr-title',
350 { type => 'pkg_svc', },
352 { 'field' => 'svc_dst_pkgpart',
353 'label' => 'Also include services from package: ',
354 'type' => 'select-part_pkg',
355 'extra_sql' => sub { $pkgpart
356 ? "AND pkgpart != $pkgpart"
359 'label_callback' => sub { shift->pkg_comment_only },
360 'm2_label' => 'Include services of package: ',
361 'm2m_method' => 'svc_part_pkg_link',
362 'm2m_dstcol' => 'dst_pkgpart',
363 'm2_error_callback' =>
364 &{$m2_error_callback_maker}('svc'),
367 { 'type' => 'tablebreak-tr-title',
368 'value' => 'Supplemental packages',
370 'include_opt_callback' => sub {
371 'id' => 'show_supp_pkgs',
374 { 'field' => 'supp_dst_pkgpart',
375 'type' => 'select-part_pkg',
376 'label_callback' => sub { shift->pkg_comment_only },
377 'm2_label' => 'When ordering package, also order',
378 'm2m_method' => 'supp_part_pkg_link',
379 'm2m_dstcol' => 'dst_pkgpart',
380 'm2_error_callback' =>
381 &{$m2_error_callback_maker}('supp'),
384 { type => 'tablebreak-tr-title',
385 value => 'Price plan options',
392 my $curuser = $FS::CurrentUser::CurrentUser;
394 my $edit_global = 'Edit global package definitions';
395 my $acl_edit = $curuser->access_right('Edit package definitions');
396 my $acl_edit_global = $curuser->access_right($edit_global);
398 my $acl_edit_either = $acl_edit || $acl_edit_global;
400 my $begin_callback = sub {
401 my( $cgi, $fields, $opt ) = @_;
403 unless $acl_edit_either
404 || ( $cgi->param('pkgnum')
405 && $curuser->access_right('Customize customer package')
409 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
411 #arg. access rights for cloning are Hard.
412 # on the one hand we don't really want cloning (customizing a package) to fail
413 # for want of finding the source package in normal usage
414 # on the other hand, we don't want people using the clone link to be able to
416 my $agent_clone_extra_sql =
417 ' ( '. FS::part_pkg->curuser_pkgs_sql.
418 " OR ( part_pkg.custom = 'Y' ) ".
421 my $conf = new FS::Conf;
422 my $taxproducts = $conf->config('tax_data_vendor') ne '';
424 my $fcc_opts = $conf->exists('part_pkg-show_fcc_options');
426 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
427 my %locale_labels = map {
428 ( $_ => 'Package -- '. FS::Locales->description($_) )
431 sort { $locale_labels{$a} cmp $locale_labels{$b} }
435 my %locale_field_labels = (
437 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
442 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
443 " WHERE disabled IS NULL OR disabled = '' ")
445 $sth->execute or die $sth->errstr;
446 my $report_option = $sth->fetchrow_arrayref->[0];
449 # - tr-part_pkg_freq: month_increments_only (from price plans)
451 # - test errors cloning
452 # - test custom pricing
453 # - move the selectlayer divs away from lame layer_callback
455 #my ($query) = $cgi->keywords;
460 my %tax_override = ();
462 my %taxproductnums = map { ($_->classnum => 1) }
463 qsearch('usage_class', { 'disabled' => '' });
464 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
467 my $recur_disabled = 1;
468 my $setup_show_zero_disabled = 0;
469 my $recur_show_zero_disabled = 1;
473 my $splice_locale_fields = sub {
474 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
477 my @locale_fields = (
479 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
480 my $pkg_value = $pkg_value_callback
481 ? $pkg_value_callback eq 'cgiparam'
482 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
483 : &$pkg_value_callback($_)
486 { field => 'pkgpartmsgnum'. $n,
488 value => $pkey_value,
490 { field => 'pkgpartmsgnum'. $n. '_locale',
494 { field => 'pkgpartmsgnum'. $n++. '_pkg',
505 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
509 my $error_callback = sub {
510 my($cgi, $object, $fields, $opt ) = @_;
512 (@agent_type) = $cgi->param('agent_type');
514 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
516 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
518 $recur_disabled = $cgi->param('freq') ? 0 : 1;
519 $recur_show_zero_disabled =
521 ? $cgi->param('recur_fee') > 0 ? 1 : 0
524 foreach ($cgi->param) {
525 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
527 $tax_override{''} = $cgi->param('tax_override');
528 $tax_override{$_} = $cgi->param('tax_override_$_')
529 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
531 #some false laziness w/process
532 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
534 my $options = $cgi->param($plan."__OPTIONS");
535 my @options = split(',', $options);
537 map { my $optionname = $_;
538 my $param = $plan."__$optionname";
539 my $value = join(', ', $cgi->param($param));
540 ( $optionname => $value );
544 $object->set($_ => scalar($cgi->param($_)) )
545 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
547 foreach my $currency ( $conf->config('currencies') ) {
548 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
549 foreach (qw( setup_fee recur_fee )) {
550 my $param = $_.'_'.$currency;
551 $object->set( $param, $cgi->param($param) );
555 $pkgpart = $object->pkgpart;
557 &$splice_locale_fields(
561 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
562 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
567 if ( $cgi->param('error') =~ / is suggested with / ) {
568 #yeah, detection is a shitty kludge, but we don't have exception objects
569 $opt->{form_init} = '<INPUT TYPE="checkbox" NAME="part_pkg_restrict_soft_override" VALUE="Y"> Override suggestion<BR><BR>';
574 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
576 my $new_object_callback = sub {
577 my( $cgi, $hashref, $fields, $opt ) = @_;
579 my $part_pkg = FS::part_pkg->new( $hashref );
580 $part_pkg->set($_ => '0')
581 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
587 sub set_report_option {
588 my($cgi, $object, $fields ) = @_; #, $opt
590 my @report_option = ();
591 foreach ($object->options) {
592 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
593 /^report_option_(\d+)$/ && (push @report_option, $1);
595 foreach ($object->part_pkg_taxoverride) {
596 $taxproductnums{$_->usage_class} = 1
600 $cgi->param('report_option', join(',', @report_option));
601 foreach my $field ( @$fields ) {
603 ref($field) eq 'HASH' &&
605 $field->{field} eq 'report_option'
607 #$field->{curr_value} = join(',', @report_option);
608 $field->{value} = join(',', @report_option);
613 my $edit_callback = sub {
614 my( $cgi, $object, $fields, $opt ) = @_;
616 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
618 $recur_disabled = $object->freq ? 0 : 1;
620 $recur_show_zero_disabled =
622 ? $object->option('recur_fee') > 0 ? 1 : 0
626 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
628 set_report_option( $cgi, $object, $fields);
630 %options = $object->options;
632 $object->set($_ => $object->option($_, 1))
633 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
635 foreach my $currency ( $conf->config('currencies') ) {
636 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
637 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
638 foreach keys %part_pkg_currency;
641 $pkgpart = $object->pkgpart;
643 &$splice_locale_fields(
647 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
648 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
652 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
653 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
659 my $new_callback = sub {
660 my( $cgi, $object, $fields ) = @_;
662 my $conf = new FS::Conf;
664 if ( $conf->exists('agent_defaultpkg') ) {
665 @agent_type = map {$_->typenum} qsearch('agent_type', { 'disabled'=>'' });
668 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
670 &$splice_locale_fields($fields, '', '');
674 my $clone_callback = sub {
675 my( $cgi, $object, $fields, $opt ) = @_;
677 if ( $cgi->param('pkgnum') ) {
679 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
680 $object->agentnum( $cust_pkg->cust_main->agentnum );
682 $opt->{action} = 'Custom';
684 #my $part_pkg = $clone_part_pkg->clone;
685 #this is all clone does anyway
686 $object->custom('Y');
688 $object->disabled('Y');
690 } else { #when explicitly cloning, not customizing
693 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
697 set_report_option( $cgi, $object, $fields);
699 %options = $object->options;
701 $object->set($_ => $options{$_})
702 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
704 foreach my $currency ( $conf->config('currencies') ) {
705 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
706 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
707 foreach keys %part_pkg_currency;
710 $recur_disabled = $object->freq ? 0 : 1;
712 &$splice_locale_fields(
717 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
718 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
723 my $discount_error_callback = sub {
724 my( $cgi, $object ) = @_;
726 if ( /^discountnum(\d+)$/ &&
727 ( my $discountnum = $cgi->param("discountnum$1") ) )
729 new FS::part_pkg_discount {
730 'pkgpart' => $object->pkgpart,
731 'discountnum' => $discountnum,
740 my $usageprice_error_callback = sub {
741 my( $cgi, $object ) = @_;
743 if ( /^usagepricepart(\d+)_price$/
744 && $cgi->param("usagepricepart$1_price") )
746 new FS::part_pkg_usageprice {
747 'usagepricepart' => $cgi->param("usagepricepart$1"),
748 'pkgpart' => $object->pkgpart,
749 'price' => scalar($cgi->param("usagepricepart$1_price")),
751 'action' => scalar($cgi->param("usagepricepart$1_action")),
752 'target' => scalar($cgi->param("usagepricepart$1_target")),
753 'amount' => scalar($cgi->param("usagepricepart$1_amount")),
762 my $m2_error_callback_maker = sub {
763 my $link_type = shift; #yay closures
765 my( $cgi, $object ) = @_;
768 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
769 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
772 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
774 new FS::part_pkg_link {
775 'link_type' => $link_type,
776 'src_pkgpart' => $object->pkgpart,
777 'dst_pkgpart' => $dst,
788 my $javascript = <<'END';
789 <SCRIPT TYPE="text/javascript">
791 function freq_changed(what) {
792 var freq = what.options[what.selectedIndex].value;
795 what.form.recur_fee.disabled = true;
796 what.form.recur_fee.style.backgroundColor = '#dddddd';
797 what.form.recur_show_zero.disabled = true;
798 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
800 what.form.recur_fee.disabled = false;
801 what.form.recur_fee.style.backgroundColor = '#ffffff';
802 recur_changed( what.form.recur_fee );
803 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
808 function setup_changed(what) {
809 var setup = what.value;
810 if ( parseFloat(setup) == 0 ) {
811 what.form.setup_show_zero.disabled = false;
813 what.form.setup_show_zero.disabled = true;
817 function recur_changed(what) {
818 var recur = what.value;
819 if ( parseFloat(recur) == 0 ) {
820 what.form.recur_show_zero.disabled = false;
822 what.form.recur_show_zero.disabled = true;
826 function agent_changed(what) {
829 if ( what.type == 'select-one' ) {
830 agentnum = what.options[what.selectedIndex].value;
832 agentnum = what.value;
835 if ( agentnum == 0 ) {
836 what.form.agent_type.disabled = false;
837 //what.form.agent_type.style.backgroundColor = '#ffffff';
838 what.form.agent_type.style.visibility = '';
840 what.form.agent_type.disabled = true;
841 //what.form.agent_type.style.backgroundColor = '#dddddd';
842 what.form.agent_type.style.visibility = 'hidden';
847 function aux_planchanged(what) { //?
849 var plan = what.options[what.selectedIndex].value;
851 var term_table = document.getElementById('TableNumber8') // XXX NOT ROBUST
852 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
853 //term_table.disabled = false;
854 //term_table.style.visibility = '';
855 term_table.style.display = '';
857 //term_table.disabled = true;
858 //term_table.style.visibility = 'hidden';
859 term_table.style.display = 'none';
862 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
865 for ( var i=0; i < form.length; i++ ) {
866 if ( currency_regex.test(form[i].name) ) {
867 if ( plan == 'currency_fixed' ) {
868 form[i].disabled = false;
870 form[i].disabled = true;
877 // some magic to make "supplemental packages" less obvious
878 var supp_pkg_rows = [];
879 function show_supp_pkgs_click() {
880 supp_pkg_rows[0].style.display = '';
882 this.style.backgroundColor = '';
883 this.style.border = '';
884 this.style.padding = '';
887 function hide_supp_pkgs() {
888 var all_selects = document.getElementsByTagName('select');
889 for (var i=0; i < all_selects.length; i++) {
890 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
891 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
894 if ( supp_pkg_rows.length == 1 ) {
895 // there are none configured, so hide the row to create a new one
896 supp_pkg_rows[0].style.display = 'none';
897 var button = document.getElementById('show_supp_pkgs');
898 button.onclick = show_supp_pkgs_click;
899 button.style.backgroundColor = '#cccccc';
900 button.style.border = '1px solid #7e0079';
901 button.style.padding = '1px';
905 function finish_edit_fcc(id) {
907 show_fcc_options(id); // refresh the display
913 'Changing the setup or recurring fee will create a new package definition. '.
916 $javascript .= "function confirm_submit(f) {";
917 if ( $conf->exists('part_pkg-lineage') ) {
920 var fields = Array('setup_fee','recur_fee');
921 for(var i=0; i < fields.length; i++) {
922 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
923 return confirm('$warning');
933 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
935 tie my %plan_labels, 'Tie::IxHash',
936 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
939 my $html_bottom = sub {
942 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
944 my $layer_callback = sub {
947 my $html = ntable("#cccccc",2);
951 # <TD ALIGN="right">Recurring fee frequency </TD>
952 # <TD><SELECT NAME="freq">
955 #my @freq = keys %freq;
956 #@freq = grep { /^\d+$/ } @freq
957 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
958 #foreach my $freq ( @freq ) {
959 # $html .= qq(<OPTION VALUE="$freq");
960 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
961 # $html .= ">$freq{$freq}";
964 #$html .= '</SELECT></TD></TR>';
966 my $href = $plans{$layer}->{'fields'};
967 my @fields = exists($plans{$layer}->{'fieldorder'})
968 ? @{$plans{$layer}->{'fieldorder'}}
971 # hash of dependencies for each of the Pricing Plan fields.
972 # make sure NOT to use double-quotes inside the 'msg' value.
974 'unused_credit_suspend' => {
975 'msg' => q|You must set the 'suspend_credit_type' option in Configuration->Settings to gain access to this option.|,
977 my $conf = new FS::conf;
978 my @conf_info = qsearch('conf', { 'name' => 'suspend_credit_type' } );
979 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
983 'unused_credit_cancel' => {
984 'msg' => q|You must set the 'cancel_credit_type' option in Configuration->Settings to gain access to this option.|,
986 my $conf = new FS::conf;
987 my @conf_info = qsearch('conf', { 'name' => 'cancel_credit_type' } );
988 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
994 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
996 if(!exists($href->{$field})) {
998 warn "nonexistent part_pkg option: '$field'\n";
1001 if ( exists($href->{$field}->{display_if}) ) {
1002 my %args = ( 'plan' => $layer ); # anything else?
1003 my $display = &{ $href->{$field}->{display_if} }(%args);
1007 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
1009 my $format = sub { shift };
1010 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
1012 #XXX these should use elements/ fields... (or this whole thing should
1013 #just use layer_fields instead of layer_callback)
1015 if (exists($dependencies->{$field}) && !$dependencies->{$field}{'are_met'}()) {
1016 $html .= q!<span title="!.$dependencies->{$field}{'msg'}.q!">N/A</span>!;
1018 } elsif ( ! exists($href->{$field}{'type'}) ) {
1020 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
1021 ( exists($options{$field})
1022 ? &$format($options{$field})
1023 : $href->{$field}{'default'} ).
1026 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
1028 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
1029 ( exists($options{$field}) && $options{$field}
1034 } elsif ( $href->{$field}{'type'} eq 'select-rate' ) {
1036 $html .= include('/elements/select-rate.html',
1037 'field' => $layer.'__'.$field,
1038 'curr_value' => $options{$field},
1039 map { $_ => $href->{$field}{$_} }
1040 grep { $_ !~ /^(name|type)$/ }
1041 keys %{ $href->{$field} }
1044 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
1047 $html .= ' MULTIPLE'
1048 if $href->{$field}{'type'} eq 'select_multiple';
1049 $html .= qq! NAME="${layer}__$field">!;
1051 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
1052 if exists($href->{$field}{'disable_empty'})
1053 && ! $href->{$field}{'disable_empty'};
1055 if ( $href->{$field}{'select_table'} ) {
1056 foreach my $record (
1057 qsearch( $href->{$field}{'select_table'},
1058 $href->{$field}{'select_hash'} )
1060 my $value = $record->getfield($href->{$field}{'select_key'});
1061 $html .= qq!<OPTION VALUE="$value"!.
1062 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
1066 '>'. $record->getfield($href->{$field}{'select_label'});
1068 } elsif ( $href->{$field}{'select_options'} ) {
1069 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
1070 my $label = $href->{$field}{'select_options'}{$key};
1071 $html .= qq!<OPTION VALUE="$key"!.
1072 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1080 $html .= '<font color="#ff0000">warning: '.
1081 "don't know how to retreive options for $field select field".
1084 $html .= '</SELECT>';
1086 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
1089 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
1091 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
1092 my $label = $href->{$field}{'options'}{$key};
1093 $html .= qq!$radio VALUE="$key"!.
1094 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1103 $html .= '</TD></TR>';
1105 $html .= '</TABLE>';
1107 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
1108 join(',', keys %{ $href } ). '">';
1114 my %selectlayers = (
1116 options => [ keys %plan_labels ],
1117 labels => \%plan_labels,
1118 curr_value => $object->plan,
1119 layer_callback => $layer_callback,
1120 onchange => 'aux_planchanged(what);',
1124 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1125 '<SCRIPT TYPE="text/javascript">'.
1126 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
1129 # "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
1132 $return .= '</SCRIPT>';
1138 my %usage_class = map { ($_->classnum => $_->classname) }
1139 qsearch('usage_class', {});
1140 $usage_class{setup} = 'Setup';
1141 $usage_class{recur} = 'Recurring';
1143 my %taxproduct_fields = ();
1144 my $end_callback = sub {
1145 my( $cgi, $object, $fields, $opt ) = @_;
1147 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1149 if ( $object->pkgpart ) {
1150 foreach my $usage_class ( '', @taxproductnums ) {
1151 $tax_override{$usage_class} =
1152 join (",", map $_->taxclassnum,
1153 qsearch( 'part_pkg_taxoverride', {
1154 'pkgpart' => $object->pkgpart,
1155 'usage_class' => $usage_class,
1161 %taxproduct_fields =
1162 map { $_ => [ "taxproductnum_$_",
1163 { type => 'select-taxproduct',
1164 #label => "$usage_class{$_} tax product",
1167 { type => 'select-taxoverride' }
1172 $taxproduct_fields{'(default)'} =
1173 [ 'taxproductnum', { type => 'select-taxproduct',
1174 #label => 'Default tax product',
1176 'tax_override', { type => 'select-taxoverride' },
1180 my $taxproduct_values = sub {
1181 my ($cgi, $object, $flags) = @_;
1183 sub { my $layer = shift;
1184 my @fields = @{$taxproduct_fields{$layer}};
1187 my $field = shift @fields;
1189 $field =~ /^taxproductnum_\w+$/ &&
1190 push @values, ( $field => $options{"usage_$field"} );
1191 $field =~ /^tax_override_(\w+)$/ &&
1192 push @values, ( $field => $tax_override{$1} );
1193 $field =~ /^taxproductnum$/ &&
1194 push @values, ( $field => $object->taxproductnum );
1195 $field =~ /^tax_override$/ &&
1196 push @values, ( $field => $tax_override{''} );
1202 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1203 return({ @result });
1207 my $field_callback = sub {
1208 my ($cgi, $object, $fieldref) = @_;
1210 my $field = $fieldref->{field};
1211 if ($field eq 'taxproductnums') {
1212 $fieldref->{value} = join(',', @taxproductnums);
1213 } elsif ($field eq 'taxproduct_select') {
1214 $fieldref->{options} = [ '(default)', @taxproductnums ];
1215 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1216 map {( $_ => ($usage_class{$_} || $_) )}
1219 $fieldref->{layer_fields} = \%taxproduct_fields;
1220 $fieldref->{layer_values_callback} = $taxproduct_values;
1221 } elsif ($field eq 'taxproductnum') { # part_pkg-taxproduct, new style
1222 if ( !$taxproducts ) {
1223 # then make the widget go away
1224 $fieldref->{type} = 'hidden';
1229 my $discountnum_hashref = {
1231 'months' => { 'op' => '>', 'value' => 1 },