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').
12 include('/elements/init_calendar.html').
14 'html_bottom' => $html_bottom,
15 'extra_fields_validate' => $validate_priceplan_fields,
17 'onLoad="agent_changed(document.edit_topform.agentnum);
18 aux_planchanged(document.edit_topform.plan);
21 'begin_callback' => $begin_callback,
22 'end_callback' => $end_callback,
23 'new_hashref_callback' => $new_hashref_callback,
24 'new_object_callback' => $new_object_callback,
25 'new_callback' => $new_callback,
26 'clone_callback' => $clone_callback,
27 'edit_callback' => $edit_callback,
28 'error_callback' => $error_callback,
29 'field_callback' => $field_callback,
31 'onsubmit' => 'confirm_submit',
34 'pkgpart' => 'Package Definition',
37 'comment' => 'Comment (customer-hidden)',
38 'classnum' => 'Package class',
39 'addon_classnum' => 'Restrict additional orders to package class',
40 'promo_code' => 'Promotional code',
41 'freq' => 'Recurring fee frequency',
42 'setuptax' => 'Setup fee tax exempt',
43 'recurtax' => 'Recurring fee tax exempt',
44 'taxclass' => 'Tax class',
45 'plan' => 'Price plan',
46 'disabled' => 'Disable new orders',
47 'disable_line_item_date_ranges' => 'Disable line item date ranges',
48 'start_on_hold' => 'Start on hold',
49 'setup_cost' => 'Setup cost',
50 'recur_cost' => 'Recur cost',
51 'pay_weight' => 'Payment weight',
52 'credit_weight' => 'Credit weight',
53 'agent_pkgpartid' => 'External ID',
54 'agentnum' => 'Agent',
55 'agent_type' => ' ', #just its title headingn is fine
56 'setup_fee' => 'Setup fee',
57 'setup_show_zero' => 'Show zero setup',
58 'recur_fee' => 'Recurring fee',
59 'recur_show_zero' => 'Show zero recurring',
60 ( map { ( "setup_fee_$_" => "Setup fee $_",
61 "recur_fee_$_" => "Recurring fee $_",
64 $conf->config('currencies')
66 'usagepricepart' => ' ',
67 'discountnum' => 'Offer discounts for longer terms',
68 'bill_dst_pkgpart' => 'Include line item(s) from package',
69 'svc_dst_pkgpart' => 'Include services of package',
70 'supp_dst_pkgpart' => 'When ordering package, also order',
71 'report_option' => 'Report classes',
72 'delay_start' => 'Default delay (days)',
73 'adjourn_months' => 'Suspend the package after ',
74 'contract_end_months' => 'Contract ends after ',
75 'expire_months' => 'Cancel the package after ',
76 'change_to_pkgpart'=> 'and replace it with ',
77 'units_taxproductnum' => 'Per-line tax product',
81 { field=>'clone', type=>'hidden',
82 curr_value_callback =>
83 sub { shift->param('clone') },
85 { field=>'pkgnum', type=>'hidden',
86 curr_value_callback =>
87 sub { shift->param('pkgnum') },
90 { field=>'custom', type=>'hidden' },
91 { field=>'family_pkgpart', type=>'hidden' },
92 { field=>'successor', type=>'hidden' },
94 { type => 'columnstart' },
97 type => 'input-locale-text',
102 {field=>'comment', type=>'text', size=>40 }, #32
103 { field => 'agentnum',
104 type => 'select-agent',
105 disable_empty => ! $acl_edit_global,
106 empty_label => '(global)',
107 onchange => 'agent_changed',
109 {field=>'classnum', type=>'select-pkg_class' },
110 ( $conf->exists('pkg-addon_classnum')
111 ? ( { field=>'addon_classnum',
112 type =>'select-pkg_class',
117 {field=>'disabled', type=>$disabled_type, value=>'Y'},
118 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
119 { field => 'start_on_hold',
124 { type => 'tablebreak-tr-title',
125 value => 'Pricing', #better name?
128 type => 'selectlayers-select',
129 options => [ keys %plan_labels ],
130 labels => \%plan_labels,
131 onchange => 'aux_planchanged(what);',
133 { field => 'setup_fee',
135 onchange => 'setup_changed',
137 { field => 'setup_show_zero',
140 disabled => sub { $setup_show_zero_disabled },
142 ( map { +{ field => "setup_fee_$_",
144 prefix=> currency_symbol($_, SYM_HTML),
148 sort $conf->config('currencies')
151 type => 'part_pkg_freq',
152 onchange => 'freq_changed',
154 { field => 'recur_fee',
156 disabled => sub { $recur_disabled },
157 onchange => 'recur_changed',
159 { field => 'recur_show_zero',
162 disabled => sub { $recur_show_zero_disabled },
164 ( map { +{ field => "recur_fee_$_",
166 prefix=> currency_symbol($_, SYM_HTML),
170 sort $conf->config('currencies')
173 ( $conf->exists('part_pkg-delay_start')
174 ? ( { type => 'tablebreak-tr-title',
175 value => 'Delayed start',
177 { field => 'delay_start',
178 type => 'text', size => 6 },
183 { type => 'tablebreak-tr-title',
184 value => 'Limited duration',
186 { field => 'adjourn_months',
187 type => 'select-months',
189 { field => 'contract_end_months',
190 type => 'select-months',
192 { field => 'expire_months',
193 type => 'select-expire_months',
195 { field => 'change_to_pkgpart',
196 type => 'select-part_pkg',
197 extra_sql => sub { $pkgpart
198 ? "AND part_pkg.pkgpart != $pkgpart"
201 empty_label => 'no package',
207 #recurring fee (auto-disable)
209 { type => 'columnnext' },
211 {type=>'justtitle', value=>'Taxation' },
212 {field=>'setuptax', type=>'checkbox', value=>'Y'},
213 {field=>'recurtax', type=>'checkbox', value=>'Y'},
214 {field=>'taxclass', type=>'select-taxclass' },
215 { field => 'taxproductnums',
217 value => join(',', @taxproductnums),
219 { field => 'taxproductnum',
220 type => 'part_pkg-taxproducts',
221 include_opt_callback =>
222 sub { pkgpart => $_[0]->pkgpart },
224 { field => 'units_taxproductnum',
225 type => ($tax_data_vendor ?
226 'select-taxproduct' : 'hidden'),
228 { type => 'tablebreak-tr-title',
229 value => 'Promotions', #better name?
231 { field=>'promo_code', type=>'text', size=>15 },
233 { type => 'tablebreak-tr-title',
234 value => 'Cost tracking', #better name?
237 ( $curuser->access_right('Edit package definition costs')
238 ? ( { field=>'setup_cost', type=>'money', },
239 { field=>'recur_cost', type=>'money', },
241 : ( { field=>'setup_cost', type=>'fixed', },
242 { field=>'recur_cost', type=>'fixed', },
246 { type => 'columnnext' },
248 {type=>'justtitle', value=>'Agent (reseller) types' },
250 { field => 'agent_type',
251 type => 'select-agent_type',
252 disabled => ! $acl_edit_global,
253 element_etc => 'size="10"',
254 multiple => '1', #cause edit.html is dum
255 curr_value_callback => sub {
256 my($cgi, $object, $field) = @_;
257 #in the other callbacks..? hmm.
263 { type => 'tablebreak-tr-title',
264 value => 'FCC Form 477 information',
266 { field => 'fcc_options_string',
267 type => 'input-fcc_options',
268 curr_value_callback => sub {
269 my ($cgi, $part_pkg, $fref) = @_;
270 if ( $cgi->param('fcc_options_string') ) {
272 return $cgi->param('fcc_options_string');
275 %hash = $part_pkg->fcc_options
276 if ($part_pkg->pkgpart);
277 return encode_json(\%hash);
283 { type => 'tablebreak-tr-title',
284 value => 'External Links', #better name?
286 { field=>'agent_pkgpartid', type=>'text', size=>21 },
288 { type => 'tablebreak-tr-title',
289 value => 'Line-item revenue recognition', #better name?
291 { field=>'pay_weight', type=>'text', size=>6 },
292 { field=>'credit_weight', type=>'text', size=>6 },
294 { type => 'columnend' },
296 { type => 'tablebreak-tr-title',
297 value => 'Usage pricing add-ons', #better name? just 'Usage pricing' ? there's also CDR usage pricing, RADIUS usage pricing, etc :/
299 { 'field' => 'usagepricepart',
300 'type' => 'part_pkg_usageprice',
301 'o2m_table' => 'part_pkg_usageprice',
303 'm2_error_callback' => $usageprice_error_callback,
306 { 'type' => $report_option ? 'tablebreak-tr-title'
308 'value' => 'Optional report classes',
309 'field' => 'census_title',
311 { 'field' => 'report_option',
312 'type' => $report_option ? 'select-table'
314 'table' => 'part_pkg_report_option',
315 'name_col' => 'name',
316 'hashref' => { 'disabled' => '' },
318 'curr_value_callback' => $report_option_value_callback,
321 { 'type' => 'tablebreak-tr-title',
322 'value' => 'Term discounts',
324 { 'field' => 'discountnum',
325 'type' => 'select-table',
326 'table' => 'discount',
327 'name_col' => 'name',
328 'hashref' => { %$discountnum_hashref },
329 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
330 'empty_label'=> 'Select discount',
331 'm2_label' => 'Offer discounts for longer terms',
332 'm2m_method' => 'part_pkg_discount',
333 'm2m_dstcol' => 'discountnum',
334 'm2_error_callback' => $discount_error_callback,
337 { 'type' => 'tablebreak-tr-title',
338 'value' => 'Pricing add-ons',
341 { 'field' => 'bill_dst_pkgpart',
342 'type' => 'select-part_pkg',
343 'extra_sql' => sub { $pkgpart
344 ? "AND part_pkg.pkgpart != $pkgpart"
347 'label_callback' => sub { shift->pkg_comment_only },
348 'm2_label' => 'Include line item(s) from package',
349 'm2m_method' => 'bill_part_pkg_link',
350 'm2m_dstcol' => 'dst_pkgpart',
351 'm2_error_callback' =>
352 &{$m2_error_callback_maker}('bill'),
353 'm2_fields' => [ { 'field' => 'hidden',
354 'type' => 'checkbox',
362 { type => 'tablebreak-tr-title',
365 { type => 'pkg_svc', },
367 { 'field' => 'svc_dst_pkgpart',
368 'label' => 'Also include services from package: ',
369 'type' => 'select-part_pkg',
370 'extra_sql' => sub { $pkgpart
371 ? "AND part_pkg.pkgpart != $pkgpart"
374 'label_callback' => sub { shift->pkg_comment_only },
375 'm2_label' => 'Include services of package: ',
376 'm2m_method' => 'svc_part_pkg_link',
377 'm2m_dstcol' => 'dst_pkgpart',
378 'm2_error_callback' =>
379 &{$m2_error_callback_maker}('svc'),
382 { 'type' => 'tablebreak-tr-title',
383 'value' => 'Supplemental packages',
385 'include_opt_callback' => sub {
386 'id' => 'show_supp_pkgs',
389 { 'field' => 'supp_dst_pkgpart',
390 'type' => 'select-part_pkg',
391 'label_callback' => sub { shift->pkg_comment_only },
392 'm2_label' => 'When ordering package, also order',
393 'm2m_method' => 'supp_part_pkg_link',
394 'm2m_dstcol' => 'dst_pkgpart',
395 'm2_error_callback' =>
396 &{$m2_error_callback_maker}('supp'),
399 { type => 'tablebreak-tr-title',
400 value => 'Price plan options',
407 my $curuser = $FS::CurrentUser::CurrentUser;
409 my $edit_global = 'Edit global package definitions';
410 my $acl_edit = $curuser->access_right('Edit package definitions');
411 my $acl_edit_global = $curuser->access_right($edit_global);
413 my $acl_edit_either = $acl_edit || $acl_edit_global;
415 my $begin_callback = sub {
416 my( $cgi, $fields, $opt ) = @_;
418 unless $acl_edit_either
419 || ( $cgi->param('pkgnum')
420 && $curuser->access_right('Customize customer package')
424 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
426 #arg. access rights for cloning are Hard.
427 # on the one hand we don't really want cloning (customizing a package) to fail
428 # for want of finding the source package in normal usage
429 # on the other hand, we don't want people using the clone link to be able to
431 my $agent_clone_extra_sql =
432 ' ( '. FS::part_pkg->curuser_pkgs_sql.
433 " OR ( part_pkg.custom = 'Y' ) ".
436 my $conf = new FS::Conf;
437 my $tax_data_vendor = $conf->config('tax_data_vendor');
439 my $fcc_opts = $conf->exists('part_pkg-show_fcc_options');
441 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
442 my %locale_labels = map {
443 ( $_ => 'Package -- '. FS::Locales->description($_) )
446 sort { $locale_labels{$a} cmp $locale_labels{$b} }
450 my %locale_field_labels = (
452 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
457 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
458 " WHERE disabled IS NULL OR disabled = '' ")
460 $sth->execute or die $sth->errstr;
461 my $report_option = $sth->fetchrow_arrayref->[0];
464 # - tr-part_pkg_freq: month_increments_only (from price plans)
466 # - test errors cloning
467 # - test custom pricing
468 # - move the selectlayer divs away from lame layer_callback
470 #my ($query) = $cgi->keywords;
475 my %tax_override = ();
477 my %taxproductnums = map { ($_->classnum => 1) }
478 qsearch('usage_class', { 'disabled' => '' });
479 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
482 my $recur_disabled = 1;
483 my $setup_show_zero_disabled = 0;
484 my $recur_show_zero_disabled = 1;
488 my $error_callback = sub {
489 my($cgi, $object, $fields, $opt ) = @_;
491 (@agent_type) = $cgi->param('agent_type');
493 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
495 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
497 $recur_disabled = $cgi->param('freq') ? 0 : 1;
498 $recur_show_zero_disabled =
500 ? $cgi->param('recur_fee') > 0 ? 1 : 0
503 foreach ($cgi->param) {
504 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
506 $tax_override{''} = $cgi->param('tax_override');
507 $tax_override{$_} = $cgi->param('tax_override_$_')
508 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
510 #some false laziness w/process
511 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
513 my $options = $cgi->param($plan."__OPTIONS");
514 my @options = split(',', $options);
516 map { my $optionname = $_;
517 my $param = $plan."__$optionname";
518 my $value = join(', ', $cgi->param($param));
519 ( $optionname => $value );
523 $object->set($_ => scalar($cgi->param($_)) )
524 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
526 foreach my $currency ( $conf->config('currencies') ) {
527 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
528 foreach (qw( setup_fee recur_fee )) {
529 my $param = $_.'_'.$currency;
530 $object->set( $param, $cgi->param($param) );
534 $pkgpart = $object->pkgpart;
536 if ( $cgi->param('error') =~ / is suggested with / ) {
537 #yeah, detection is a shitty kludge, but we don't have exception objects
538 $opt->{form_init} = '<INPUT TYPE="checkbox" NAME="part_pkg_restrict_soft_override" VALUE="Y"> Override suggestion<BR><BR>';
543 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
545 my $new_object_callback = sub {
546 my( $cgi, $hashref, $fields, $opt ) = @_;
548 my $part_pkg = FS::part_pkg->new( $hashref );
549 $part_pkg->set($_ => '0')
550 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
556 my $report_option_value_callback = sub {
557 my ($cgi, $object) = @_;
559 if ( defined $cgi->param('report_option') ) {
560 @report_option = $cgi->param('report_option');
562 foreach ($object->options) {
563 /^report_option_(\d+)$/ && (push @report_option, $1);
566 join(',', @report_option);
569 sub set_report_option {
570 my($cgi, $object, $fields ) = @_; #, $opt
572 my @report_option = ();
573 foreach ($object->options) {
574 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
575 # /^report_option_(\d+)$/ && (push @report_option, $1);
577 foreach ($object->part_pkg_taxoverride) {
578 $taxproductnums{$_->usage_class} = 1
582 # $cgi->param('report_option', join(',', @report_option));
583 # foreach my $field ( @$fields ) {
585 # ref($field) eq 'HASH' &&
587 # $field->{field} eq 'report_option'
589 # #$field->{curr_value} = join(',', @report_option);
590 # $field->{value} = join(',', @report_option);
595 my $edit_callback = sub {
596 my( $cgi, $object, $fields, $opt ) = @_;
598 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
600 $recur_disabled = $object->freq ? 0 : 1;
602 $recur_show_zero_disabled =
604 ? $object->option('recur_fee') > 0 ? 1 : 0
608 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
610 set_report_option( $cgi, $object, $fields);
612 %options = $object->options;
614 $object->set($_ => $object->option($_, 1))
615 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
617 foreach my $currency ( $conf->config('currencies') ) {
618 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
619 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
620 foreach keys %part_pkg_currency;
623 $pkgpart = $object->pkgpart;
627 my $new_callback = sub {
628 my( $cgi, $object, $fields ) = @_;
630 my $conf = new FS::Conf;
632 if ( $conf->exists('agent_defaultpkg') ) {
633 @agent_type = map {$_->typenum} qsearch('agent_type', { 'disabled'=>'' });
636 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
640 my $clone_callback = sub {
641 my( $cgi, $object, $fields, $opt ) = @_;
643 if ( $cgi->param('pkgnum') ) {
645 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => scalar($cgi->param('pkgnum')) } );
646 $object->agentnum( $cust_pkg->cust_main->agentnum );
648 $opt->{action} = 'Custom';
650 #my $part_pkg = $clone_part_pkg->clone;
651 #this is all clone does anyway
652 $object->custom('Y');
654 $object->disabled('Y');
656 } else { #when explicitly cloning, not customizing
659 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
663 set_report_option( $cgi, $object, $fields);
665 %options = $object->options;
667 $object->set($_ => $options{$_})
668 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
670 $recur_disabled = $object->freq ? 0 : 1;
671 $recur_show_zero_disabled =
673 ? $object->option('recur_fee') > 0 ? 1 : 0
676 foreach my $currency ( $conf->config('currencies') ) {
677 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
678 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
679 foreach keys %part_pkg_currency;
684 my $discount_error_callback = sub {
685 my( $cgi, $object ) = @_;
687 if ( /^discountnum(\d+)$/ &&
688 ( my $discountnum = $cgi->param("discountnum$1") ) )
690 new FS::part_pkg_discount {
691 'pkgpart' => $object->pkgpart,
692 'discountnum' => $discountnum,
701 my $usageprice_error_callback = sub {
702 my( $cgi, $object ) = @_;
704 if ( /^usagepricepart(\d+)_price$/
705 && $cgi->param("usagepricepart$1_price") )
707 new FS::part_pkg_usageprice {
708 'usagepricepart' => scalar($cgi->param("usagepricepart$1")),
709 'pkgpart' => $object->pkgpart,
710 'price' => scalar($cgi->param("usagepricepart$1_price")),
712 'action' => scalar($cgi->param("usagepricepart$1_action")),
713 'target' => scalar($cgi->param("usagepricepart$1_target")),
714 'amount' => scalar($cgi->param("usagepricepart$1_amount")),
723 my $m2_error_callback_maker = sub {
724 my $link_type = shift; #yay closures
726 my( $cgi, $object ) = @_;
729 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
730 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
733 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
735 new FS::part_pkg_link {
736 'link_type' => $link_type,
737 'src_pkgpart' => $object->pkgpart,
738 'dst_pkgpart' => $dst,
749 my $javascript = <<'END';
750 <SCRIPT TYPE="text/javascript">
752 function freq_changed(what) {
753 var freq = what.options[what.selectedIndex].value;
756 what.form.recur_fee.disabled = true;
757 what.form.recur_fee.style.backgroundColor = '#dddddd';
758 what.form.recur_show_zero.disabled = true;
759 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
761 what.form.recur_fee.disabled = false;
762 what.form.recur_fee.style.backgroundColor = '#ffffff';
763 recur_changed( what.form.recur_fee );
764 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
769 function setup_changed(what) {
770 var setup = what.value;
771 if ( parseFloat(setup) == 0 ) {
772 what.form.setup_show_zero.disabled = false;
774 what.form.setup_show_zero.disabled = true;
778 function recur_changed(what) {
779 var recur = what.value;
780 if ( parseFloat(recur) == 0 ) {
781 what.form.recur_show_zero.disabled = false;
783 what.form.recur_show_zero.disabled = true;
787 function agent_changed(what) {
790 if ( what.type == 'select-one' ) {
791 agentnum = what.options[what.selectedIndex].value;
793 agentnum = what.value;
796 if ( agentnum == 0 ) {
797 what.form.agent_type.disabled = false;
798 //what.form.agent_type.style.backgroundColor = '#ffffff';
799 what.form.agent_type.style.visibility = '';
801 what.form.agent_type.disabled = true;
802 //what.form.agent_type.style.backgroundColor = '#dddddd';
803 what.form.agent_type.style.visibility = 'hidden';
808 function aux_planchanged(what) { //?
810 var plan = what.options[what.selectedIndex].value;
812 var term_table = document.getElementById('TableNumber8') // XXX NOT ROBUST
813 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
814 //term_table.disabled = false;
815 //term_table.style.visibility = '';
816 term_table.style.display = '';
818 //term_table.disabled = true;
819 //term_table.style.visibility = 'hidden';
820 term_table.style.display = 'none';
823 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
826 for ( var i=0; i < form.length; i++ ) {
827 if ( currency_regex.test(form[i].name) ) {
828 if ( plan == 'currency_fixed' ) {
829 form[i].disabled = false;
831 form[i].disabled = true;
838 // some magic to make "supplemental packages" less obvious
839 var supp_pkg_rows = [];
840 function show_supp_pkgs_click() {
841 supp_pkg_rows[0].style.display = '';
843 this.style.backgroundColor = '';
844 this.style.border = '';
845 this.style.padding = '';
848 function hide_supp_pkgs() {
849 var all_selects = document.getElementsByTagName('select');
850 for (var i=0; i < all_selects.length; i++) {
851 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
852 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
855 if ( supp_pkg_rows.length == 1 ) {
856 // there are none configured, so hide the row to create a new one
857 supp_pkg_rows[0].style.display = 'none';
858 var button = document.getElementById('show_supp_pkgs');
859 button.onclick = show_supp_pkgs_click;
860 button.style.backgroundColor = '#cccccc';
861 button.style.border = '1px solid #7e0079';
862 button.style.padding = '1px';
866 function finish_edit_fcc(id) {
868 show_fcc_options(id); // refresh the display
874 'Changing the setup or recurring fee will create a new package definition. '.
877 $javascript .= "function confirm_submit(f) {";
878 if ( $conf->exists('part_pkg-lineage') ) {
881 var fields = Array('setup_fee','recur_fee');
882 for(var i=0; i < fields.length; i++) {
883 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
884 return confirm('$warning');
894 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
896 tie my %plan_labels, 'Tie::IxHash',
897 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
900 my $validate_priceplan_fields = {};
901 foreach my $priceplan (keys %plans) {
902 my $plan_fields = $plans{$priceplan}->{fields};
903 foreach my $price_plan_field (keys %$plan_fields) {
904 $validate_priceplan_fields->{$priceplan."__".$price_plan_field} = $plan_fields->{$price_plan_field}->{"js_validate"}
905 if exists $plan_fields->{$price_plan_field}->{"js_validate"};
909 my $html_bottom = sub {
912 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
914 my $layer_callback = sub {
917 my $html = ntable("#cccccc",2);
921 # <TD ALIGN="right">Recurring fee frequency </TD>
922 # <TD><SELECT NAME="freq">
925 #my @freq = keys %freq;
926 #@freq = grep { /^\d+$/ } @freq
927 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
928 #foreach my $freq ( @freq ) {
929 # $html .= qq(<OPTION VALUE="$freq");
930 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
931 # $html .= ">$freq{$freq}";
934 #$html .= '</SELECT></TD></TR>';
936 my $href = $plans{$layer}->{'fields'};
938 if ( $plans{$layer}->{'fieldorder'} ) {
939 @fields = @{ $plans{$layer}->{'fieldorder'} };
941 warn "FS::part_pkg::$layer has no fieldorder.\n";
942 @fields = keys %$href;
945 # hash of dependencies for each of the Pricing Plan fields.
946 # make sure NOT to use double-quotes inside the 'msg' value.
948 'unused_credit_suspend' => {
949 'msg' => q|You must set the 'suspend_credit_type' option in Configuration->Settings to gain access to this option.|,
951 my $conf = new FS::conf;
952 my @conf_info = qsearch('conf', { 'name' => 'suspend_credit_type' } );
953 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
957 'unused_credit_cancel' => {
958 'msg' => q|You must set the 'cancel_credit_type' option in Configuration->Settings to gain access to this option.|,
960 my $conf = new FS::conf;
961 my @conf_info = qsearch('conf', { 'name' => 'cancel_credit_type' } );
962 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
968 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
970 if(!exists($href->{$field})) {
972 warn "nonexistent part_pkg option: '$field'\n";
975 if ( exists($href->{$field}->{display_if}) ) {
976 my %args = ( 'plan' => $layer ); # anything else?
977 my $display = &{ $href->{$field}->{display_if} }(%args);
981 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>
984 my $format = sub { shift };
985 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
987 #XXX these should use elements/ fields... (or this whole thing should
988 #just use layer_fields instead of layer_callback)
990 if (exists($dependencies->{$field}) && !$dependencies->{$field}{'are_met'}()) {
991 $html .= q!<span title="!.$dependencies->{$field}{'msg'}.q!">N/A</span>!;
993 } elsif ( ! exists($href->{$field}{'type'}) ) {
995 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
996 ( exists($options{$field})
997 ? &$format($options{$field})
998 : $href->{$field}{'default'} ).
1001 } elsif ( $href->{$field}{'type'} eq 'textarea' ) {
1003 $html .= qq!<TEXTAREA NAME="${layer}__$field">!.
1004 ( exists($options{$field})
1005 ? &$format($options{$field})
1006 : $href->{$field}{'default'} ).
1009 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
1011 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
1012 ( exists($options{$field}) && $options{$field}
1017 } elsif ( $href->{$field}{'type'} eq 'date' ) {
1019 $html .= include('/elements/input-date-field.html', {
1020 'name' => $layer.'__'.$field,
1021 'value' => $options{$field},
1024 } elsif ( $href->{$field}{'type'} =~ /^select-rt-/ ) {
1026 $html .= include('/elements/'.$href->{$field}{'type'}.'.html',
1027 'name' => $layer.'__'.$field,
1028 'curr_value' => $options{$field},
1029 map { $_ => $href->{$field}{$_} }
1030 grep { $_ !~ /^(name|type|parse)$/ }
1031 keys %{ $href->{$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 .= include('/elements/hidden.html',
1108 field => $layer.'__OPTIONS',
1109 value => join(',', @fields)
1116 my %selectlayers = (
1118 options => [ keys %plan_labels ],
1119 labels => \%plan_labels,
1120 curr_value => $object->plan,
1121 layer_callback => $layer_callback,
1122 onchange => 'aux_planchanged(what);',
1126 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1127 '<SCRIPT TYPE="text/javascript">'.
1128 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 ) .
1135 my %usage_class = map { ($_->classnum => $_->classname) }
1136 qsearch('usage_class', {});
1137 $usage_class{setup} = 'Setup';
1138 $usage_class{recur} = 'Recurring';
1140 my %taxproduct_fields = ();
1141 my $end_callback = sub {
1142 my( $cgi, $object, $fields, $opt ) = @_;
1144 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1146 if ( $object->pkgpart ) {
1147 foreach my $usage_class ( '', @taxproductnums ) {
1148 $tax_override{$usage_class} =
1149 join (",", map $_->taxclassnum,
1150 qsearch( 'part_pkg_taxoverride', {
1151 'pkgpart' => $object->pkgpart,
1152 'usage_class' => $usage_class,
1158 %taxproduct_fields =
1159 map { $_ => [ "taxproductnum_$_",
1160 { type => 'select-taxproduct',
1161 #label => "$usage_class{$_} tax product",
1164 { type => 'select-taxoverride' }
1169 $taxproduct_fields{'(default)'} =
1170 [ 'taxproductnum', { type => 'select-taxproduct',
1171 #label => 'Default tax product',
1173 'tax_override', { type => 'select-taxoverride' },
1177 my $taxproduct_values = sub {
1178 my ($cgi, $object, $flags) = @_;
1180 sub { my $layer = shift;
1181 my @fields = @{$taxproduct_fields{$layer}};
1184 my $field = shift @fields;
1186 $field =~ /^taxproductnum_\w+$/ &&
1187 push @values, ( $field => $options{"usage_$field"} );
1188 $field =~ /^tax_override_(\w+)$/ &&
1189 push @values, ( $field => $tax_override{$1} );
1190 $field =~ /^taxproductnum$/ &&
1191 push @values, ( $field => $object->taxproductnum );
1192 $field =~ /^tax_override$/ &&
1193 push @values, ( $field => $tax_override{''} );
1199 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1200 return({ @result });
1204 my $field_callback = sub {
1205 my ($cgi, $object, $fieldref) = @_;
1207 my $field = $fieldref->{field};
1208 if ($field eq 'taxproductnums') {
1209 $fieldref->{value} = join(',', @taxproductnums);
1210 } elsif ($field eq 'taxproductnum') { # part_pkg-taxproduct, new style
1211 if ( !$tax_data_vendor ) {
1212 # then make the widget go away
1213 $fieldref->{type} = 'hidden';
1218 my $discountnum_hashref = {
1220 'months' => { 'op' => '>', 'value' => 1 },