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,
16 'onLoad="agent_changed(document.edit_topform.agentnum);
17 aux_planchanged(document.edit_topform.plan);
20 'begin_callback' => $begin_callback,
21 'end_callback' => $end_callback,
22 'new_hashref_callback' => $new_hashref_callback,
23 'new_object_callback' => $new_object_callback,
24 'new_callback' => $new_callback,
25 'clone_callback' => $clone_callback,
26 'edit_callback' => $edit_callback,
27 'error_callback' => $error_callback,
28 'field_callback' => $field_callback,
30 'onsubmit' => 'confirm_submit',
33 'pkgpart' => 'Package Definition',
36 'comment' => 'Comment (customer-hidden)',
37 'classnum' => 'Package class',
38 'addon_classnum' => 'Restrict additional orders to package class',
39 'promo_code' => 'Promotional code',
40 'freq' => 'Recurring fee frequency',
41 'setuptax' => 'Setup fee tax exempt',
42 'recurtax' => 'Recurring fee tax exempt',
43 'taxclass' => 'Tax class',
44 'taxproduct_select'=> 'Tax products',
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 ',
80 { field=>'clone', type=>'hidden',
81 curr_value_callback =>
82 sub { shift->param('clone') },
84 { field=>'pkgnum', type=>'hidden',
85 curr_value_callback =>
86 sub { shift->param('pkgnum') },
89 { field=>'custom', type=>'hidden' },
90 { field=>'family_pkgpart', type=>'hidden' },
91 { field=>'successor', type=>'hidden' },
93 { type => 'columnstart' },
96 type => 'input-locale-text',
101 {field=>'comment', type=>'text', size=>40 }, #32
102 { field => 'agentnum',
103 type => 'select-agent',
104 disable_empty => ! $acl_edit_global,
105 empty_label => '(global)',
106 onchange => 'agent_changed',
108 {field=>'classnum', type=>'select-pkg_class' },
109 ( $conf->exists('pkg-addon_classnum')
110 ? ( { field=>'addon_classnum',
111 type =>'select-pkg_class',
116 {field=>'disabled', type=>$disabled_type, value=>'Y'},
117 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
118 { field => 'start_on_hold',
123 { type => 'tablebreak-tr-title',
124 value => 'Pricing', #better name?
127 type => 'selectlayers-select',
128 options => [ keys %plan_labels ],
129 labels => \%plan_labels,
130 onchange => 'aux_planchanged(what);',
132 { field => 'setup_fee',
134 onchange => 'setup_changed',
136 { field => 'setup_show_zero',
139 disabled => sub { $setup_show_zero_disabled },
141 ( map { +{ field => "setup_fee_$_",
143 prefix=> currency_symbol($_, SYM_HTML),
147 sort $conf->config('currencies')
150 type => 'part_pkg_freq',
151 onchange => 'freq_changed',
153 { field => 'recur_fee',
155 disabled => sub { $recur_disabled },
156 onchange => 'recur_changed',
158 { field => 'recur_show_zero',
161 disabled => sub { $recur_show_zero_disabled },
163 ( map { +{ field => "recur_fee_$_",
165 prefix=> currency_symbol($_, SYM_HTML),
169 sort $conf->config('currencies')
172 ( $conf->exists('part_pkg-delay_start')
173 ? ( { type => 'tablebreak-tr-title',
174 value => 'Delayed start',
176 { field => 'delay_start',
177 type => 'text', size => 6 },
182 { type => 'tablebreak-tr-title',
183 value => 'Limited duration',
185 { field => 'adjourn_months',
186 type => 'select-months',
188 { field => 'contract_end_months',
189 type => 'select-months',
191 { field => 'expire_months',
192 type => 'select-expire_months',
194 { field => 'change_to_pkgpart',
195 type => 'select-part_pkg',
196 extra_sql => sub { $pkgpart
197 ? "AND part_pkg.pkgpart != $pkgpart"
200 empty_label => 'no package',
206 #recurring fee (auto-disable)
208 { type => 'columnnext' },
210 {type=>'justtitle', value=>'Taxation' },
211 {field=>'setuptax', type=>'checkbox', value=>'Y'},
212 {field=>'recurtax', type=>'checkbox', value=>'Y'},
213 {field=>'taxclass', type=>'select-taxclass' },
214 { field => 'taxproductnums',
216 value => join(',', @taxproductnums),
218 #{ field => 'taxproduct_select',
219 # type => 'selectlayers',
220 # options => [ '(default)', @taxproductnums ],
221 # curr_value => '(default)',
222 # labels => { ( '(default)' => '(default)' ),
223 # map {($_=>$usage_class{$_})}
226 # layer_fields => \%taxproduct_fields,
227 # layer_values_callback => $taxproduct_values,
228 # layers_only => !$taxproducts,
229 # cell_style => ( !$taxproducts
234 { field => 'taxproductnum',
235 type => 'part_pkg-taxproducts',
236 include_opt_callback =>
237 sub { pkgpart => $_[0]->pkgpart },
240 { type => 'tablebreak-tr-title',
241 value => 'Promotions', #better name?
243 { field=>'promo_code', type=>'text', size=>15 },
245 { type => 'tablebreak-tr-title',
246 value => 'Cost tracking', #better name?
249 ( $curuser->access_right('Edit package definition costs')
250 ? ( { field=>'setup_cost', type=>'money', },
251 { field=>'recur_cost', type=>'money', },
253 : ( { field=>'setup_cost', type=>'fixed', },
254 { field=>'recur_cost', type=>'fixed', },
258 { type => 'columnnext' },
260 {type=>'justtitle', value=>'Agent (reseller) types' },
262 { field => 'agent_type',
263 type => 'select-agent_type',
264 disabled => ! $acl_edit_global,
265 element_etc => 'size="10"',
266 multiple => '1', #cause edit.html is dum
267 curr_value_callback => sub {
268 my($cgi, $object, $field) = @_;
269 #in the other callbacks..? hmm.
275 { type => 'tablebreak-tr-title',
276 value => 'FCC Form 477 information',
278 { field => 'fcc_options_string',
279 type => 'input-fcc_options',
280 curr_value_callback => sub {
281 my ($cgi, $part_pkg, $fref) = @_;
282 if ( $cgi->param('fcc_options_string') ) {
284 return $cgi->param('fcc_options_string');
287 %hash = $part_pkg->fcc_options
288 if ($part_pkg->pkgpart);
289 return encode_json(\%hash);
295 { type => 'tablebreak-tr-title',
296 value => 'External Links', #better name?
298 { field=>'agent_pkgpartid', type=>'text', size=>21 },
300 { type => 'tablebreak-tr-title',
301 value => 'Line-item revenue recognition', #better name?
303 { field=>'pay_weight', type=>'text', size=>6 },
304 { field=>'credit_weight', type=>'text', size=>6 },
306 { type => 'columnend' },
308 { type => 'tablebreak-tr-title',
309 value => 'Usage pricing add-ons', #better name? just 'Usage pricing' ? there's also CDR usage pricing, RADIUS usage pricing, etc :/
311 { 'field' => 'usagepricepart',
312 'type' => 'part_pkg_usageprice',
313 'o2m_table' => 'part_pkg_usageprice',
315 'm2_error_callback' => $usageprice_error_callback,
318 { 'type' => $report_option ? 'tablebreak-tr-title'
320 'value' => 'Optional report classes',
321 'field' => 'census_title',
323 { 'field' => 'report_option',
324 'type' => $report_option ? 'select-table'
326 'table' => 'part_pkg_report_option',
327 'name_col' => 'name',
328 'hashref' => { 'disabled' => '' },
330 'curr_value_callback' => $report_option_value_callback,
333 { 'type' => 'tablebreak-tr-title',
334 'value' => 'Term discounts',
336 { 'field' => 'discountnum',
337 'type' => 'select-table',
338 'table' => 'discount',
339 'name_col' => 'name',
340 'hashref' => { %$discountnum_hashref },
341 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
342 'empty_label'=> 'Select discount',
343 'm2_label' => 'Offer discounts for longer terms',
344 'm2m_method' => 'part_pkg_discount',
345 'm2m_dstcol' => 'discountnum',
346 'm2_error_callback' => $discount_error_callback,
349 { 'type' => 'tablebreak-tr-title',
350 'value' => 'Pricing add-ons',
353 { 'field' => 'bill_dst_pkgpart',
354 'type' => 'select-part_pkg',
355 'extra_sql' => sub { $pkgpart
356 ? "AND part_pkg.pkgpart != $pkgpart"
359 'label_callback' => sub { shift->pkg_comment_only },
360 'm2_label' => 'Include line item(s) from package',
361 'm2m_method' => 'bill_part_pkg_link',
362 'm2m_dstcol' => 'dst_pkgpart',
363 'm2_error_callback' =>
364 &{$m2_error_callback_maker}('bill'),
365 'm2_fields' => [ { 'field' => 'hidden',
366 'type' => 'checkbox',
374 { type => 'tablebreak-tr-title',
377 { type => 'pkg_svc', },
379 { 'field' => 'svc_dst_pkgpart',
380 'label' => 'Also include services from package: ',
381 'type' => 'select-part_pkg',
382 'extra_sql' => sub { $pkgpart
383 ? "AND part_pkg.pkgpart != $pkgpart"
386 'label_callback' => sub { shift->pkg_comment_only },
387 'm2_label' => 'Include services of package: ',
388 'm2m_method' => 'svc_part_pkg_link',
389 'm2m_dstcol' => 'dst_pkgpart',
390 'm2_error_callback' =>
391 &{$m2_error_callback_maker}('svc'),
394 { 'type' => 'tablebreak-tr-title',
395 'value' => 'Supplemental packages',
397 'include_opt_callback' => sub {
398 'id' => 'show_supp_pkgs',
401 { 'field' => 'supp_dst_pkgpart',
402 'type' => 'select-part_pkg',
403 'label_callback' => sub { shift->pkg_comment_only },
404 'm2_label' => 'When ordering package, also order',
405 'm2m_method' => 'supp_part_pkg_link',
406 'm2m_dstcol' => 'dst_pkgpart',
407 'm2_error_callback' =>
408 &{$m2_error_callback_maker}('supp'),
411 { type => 'tablebreak-tr-title',
412 value => 'Price plan options',
419 my $curuser = $FS::CurrentUser::CurrentUser;
421 my $edit_global = 'Edit global package definitions';
422 my $acl_edit = $curuser->access_right('Edit package definitions');
423 my $acl_edit_global = $curuser->access_right($edit_global);
425 my $acl_edit_either = $acl_edit || $acl_edit_global;
427 my $begin_callback = sub {
428 my( $cgi, $fields, $opt ) = @_;
430 unless $acl_edit_either
431 || ( $cgi->param('pkgnum')
432 && $curuser->access_right('Customize customer package')
436 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
438 #arg. access rights for cloning are Hard.
439 # on the one hand we don't really want cloning (customizing a package) to fail
440 # for want of finding the source package in normal usage
441 # on the other hand, we don't want people using the clone link to be able to
443 my $agent_clone_extra_sql =
444 ' ( '. FS::part_pkg->curuser_pkgs_sql.
445 " OR ( part_pkg.custom = 'Y' ) ".
448 my $conf = new FS::Conf;
449 my $taxproducts = $conf->config('tax_data_vendor') ne '';
451 my $fcc_opts = $conf->exists('part_pkg-show_fcc_options');
453 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
454 my %locale_labels = map {
455 ( $_ => 'Package -- '. FS::Locales->description($_) )
458 sort { $locale_labels{$a} cmp $locale_labels{$b} }
462 my %locale_field_labels = (
464 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
469 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
470 " WHERE disabled IS NULL OR disabled = '' ")
472 $sth->execute or die $sth->errstr;
473 my $report_option = $sth->fetchrow_arrayref->[0];
476 # - tr-part_pkg_freq: month_increments_only (from price plans)
478 # - test errors cloning
479 # - test custom pricing
480 # - move the selectlayer divs away from lame layer_callback
482 #my ($query) = $cgi->keywords;
487 my %tax_override = ();
489 my %taxproductnums = map { ($_->classnum => 1) }
490 qsearch('usage_class', { 'disabled' => '' });
491 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
494 my $recur_disabled = 1;
495 my $setup_show_zero_disabled = 0;
496 my $recur_show_zero_disabled = 1;
500 my $error_callback = sub {
501 my($cgi, $object, $fields, $opt ) = @_;
503 (@agent_type) = $cgi->param('agent_type');
505 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
507 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
509 $recur_disabled = $cgi->param('freq') ? 0 : 1;
510 $recur_show_zero_disabled =
512 ? $cgi->param('recur_fee') > 0 ? 1 : 0
515 foreach ($cgi->param) {
516 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
518 $tax_override{''} = $cgi->param('tax_override');
519 $tax_override{$_} = $cgi->param('tax_override_$_')
520 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
522 #some false laziness w/process
523 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
525 my $options = $cgi->param($plan."__OPTIONS");
526 my @options = split(',', $options);
528 map { my $optionname = $_;
529 my $param = $plan."__$optionname";
530 my $value = join(', ', $cgi->param($param));
531 ( $optionname => $value );
535 $object->set($_ => scalar($cgi->param($_)) )
536 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
538 foreach my $currency ( $conf->config('currencies') ) {
539 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
540 foreach (qw( setup_fee recur_fee )) {
541 my $param = $_.'_'.$currency;
542 $object->set( $param, $cgi->param($param) );
546 $pkgpart = $object->pkgpart;
548 if ( $cgi->param('error') =~ / is suggested with / ) {
549 #yeah, detection is a shitty kludge, but we don't have exception objects
550 $opt->{form_init} = '<INPUT TYPE="checkbox" NAME="part_pkg_restrict_soft_override" VALUE="Y"> Override suggestion<BR><BR>';
555 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
557 my $new_object_callback = sub {
558 my( $cgi, $hashref, $fields, $opt ) = @_;
560 my $part_pkg = FS::part_pkg->new( $hashref );
561 $part_pkg->set($_ => '0')
562 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
568 my $report_option_value_callback = sub {
569 my ($cgi, $object) = @_;
571 if ( defined $cgi->param('report_option') ) {
572 @report_option = $cgi->param('report_option');
574 foreach ($object->options) {
575 /^report_option_(\d+)$/ && (push @report_option, $1);
578 join(',', @report_option);
581 sub set_report_option {
582 my($cgi, $object, $fields ) = @_; #, $opt
584 my @report_option = ();
585 foreach ($object->options) {
586 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
587 # /^report_option_(\d+)$/ && (push @report_option, $1);
589 foreach ($object->part_pkg_taxoverride) {
590 $taxproductnums{$_->usage_class} = 1
594 # $cgi->param('report_option', join(',', @report_option));
595 # foreach my $field ( @$fields ) {
597 # ref($field) eq 'HASH' &&
599 # $field->{field} eq 'report_option'
601 # #$field->{curr_value} = join(',', @report_option);
602 # $field->{value} = join(',', @report_option);
607 my $edit_callback = sub {
608 my( $cgi, $object, $fields, $opt ) = @_;
610 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
612 $recur_disabled = $object->freq ? 0 : 1;
614 $recur_show_zero_disabled =
616 ? $object->option('recur_fee') > 0 ? 1 : 0
620 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
622 set_report_option( $cgi, $object, $fields);
624 %options = $object->options;
626 $object->set($_ => $object->option($_, 1))
627 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
629 foreach my $currency ( $conf->config('currencies') ) {
630 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
631 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
632 foreach keys %part_pkg_currency;
635 $pkgpart = $object->pkgpart;
639 my $new_callback = sub {
640 my( $cgi, $object, $fields ) = @_;
642 my $conf = new FS::Conf;
644 if ( $conf->exists('agent_defaultpkg') ) {
645 @agent_type = map {$_->typenum} qsearch('agent_type', { 'disabled'=>'' });
648 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
652 my $clone_callback = sub {
653 my( $cgi, $object, $fields, $opt ) = @_;
655 if ( $cgi->param('pkgnum') ) {
657 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => scalar($cgi->param('pkgnum')) } );
658 $object->agentnum( $cust_pkg->cust_main->agentnum );
660 $opt->{action} = 'Custom';
662 #my $part_pkg = $clone_part_pkg->clone;
663 #this is all clone does anyway
664 $object->custom('Y');
666 $object->disabled('Y');
668 } else { #when explicitly cloning, not customizing
671 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
675 set_report_option( $cgi, $object, $fields);
677 %options = $object->options;
679 $object->set($_ => $options{$_})
680 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
682 $recur_disabled = $object->freq ? 0 : 1;
683 $recur_show_zero_disabled =
685 ? $object->option('recur_fee') > 0 ? 1 : 0
688 foreach my $currency ( $conf->config('currencies') ) {
689 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
690 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
691 foreach keys %part_pkg_currency;
696 my $discount_error_callback = sub {
697 my( $cgi, $object ) = @_;
699 if ( /^discountnum(\d+)$/ &&
700 ( my $discountnum = $cgi->param("discountnum$1") ) )
702 new FS::part_pkg_discount {
703 'pkgpart' => $object->pkgpart,
704 'discountnum' => $discountnum,
713 my $usageprice_error_callback = sub {
714 my( $cgi, $object ) = @_;
716 if ( /^usagepricepart(\d+)_price$/
717 && $cgi->param("usagepricepart$1_price") )
719 new FS::part_pkg_usageprice {
720 'usagepricepart' => scalar($cgi->param("usagepricepart$1")),
721 'pkgpart' => $object->pkgpart,
722 'price' => scalar($cgi->param("usagepricepart$1_price")),
724 'action' => scalar($cgi->param("usagepricepart$1_action")),
725 'target' => scalar($cgi->param("usagepricepart$1_target")),
726 'amount' => scalar($cgi->param("usagepricepart$1_amount")),
735 my $m2_error_callback_maker = sub {
736 my $link_type = shift; #yay closures
738 my( $cgi, $object ) = @_;
741 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
742 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
745 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
747 new FS::part_pkg_link {
748 'link_type' => $link_type,
749 'src_pkgpart' => $object->pkgpart,
750 'dst_pkgpart' => $dst,
761 my $javascript = <<'END';
762 <SCRIPT TYPE="text/javascript">
764 function freq_changed(what) {
765 var freq = what.options[what.selectedIndex].value;
768 what.form.recur_fee.disabled = true;
769 what.form.recur_fee.style.backgroundColor = '#dddddd';
770 what.form.recur_show_zero.disabled = true;
771 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
773 what.form.recur_fee.disabled = false;
774 what.form.recur_fee.style.backgroundColor = '#ffffff';
775 recur_changed( what.form.recur_fee );
776 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
781 function setup_changed(what) {
782 var setup = what.value;
783 if ( parseFloat(setup) == 0 ) {
784 what.form.setup_show_zero.disabled = false;
786 what.form.setup_show_zero.disabled = true;
790 function recur_changed(what) {
791 var recur = what.value;
792 if ( parseFloat(recur) == 0 ) {
793 what.form.recur_show_zero.disabled = false;
795 what.form.recur_show_zero.disabled = true;
799 function agent_changed(what) {
802 if ( what.type == 'select-one' ) {
803 agentnum = what.options[what.selectedIndex].value;
805 agentnum = what.value;
808 if ( agentnum == 0 ) {
809 what.form.agent_type.disabled = false;
810 //what.form.agent_type.style.backgroundColor = '#ffffff';
811 what.form.agent_type.style.visibility = '';
813 what.form.agent_type.disabled = true;
814 //what.form.agent_type.style.backgroundColor = '#dddddd';
815 what.form.agent_type.style.visibility = 'hidden';
820 function aux_planchanged(what) { //?
822 var plan = what.options[what.selectedIndex].value;
824 var term_table = document.getElementById('TableNumber8') // XXX NOT ROBUST
825 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
826 //term_table.disabled = false;
827 //term_table.style.visibility = '';
828 term_table.style.display = '';
830 //term_table.disabled = true;
831 //term_table.style.visibility = 'hidden';
832 term_table.style.display = 'none';
835 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
838 for ( var i=0; i < form.length; i++ ) {
839 if ( currency_regex.test(form[i].name) ) {
840 if ( plan == 'currency_fixed' ) {
841 form[i].disabled = false;
843 form[i].disabled = true;
850 // some magic to make "supplemental packages" less obvious
851 var supp_pkg_rows = [];
852 function show_supp_pkgs_click() {
853 supp_pkg_rows[0].style.display = '';
855 this.style.backgroundColor = '';
856 this.style.border = '';
857 this.style.padding = '';
860 function hide_supp_pkgs() {
861 var all_selects = document.getElementsByTagName('select');
862 for (var i=0; i < all_selects.length; i++) {
863 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
864 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
867 if ( supp_pkg_rows.length == 1 ) {
868 // there are none configured, so hide the row to create a new one
869 supp_pkg_rows[0].style.display = 'none';
870 var button = document.getElementById('show_supp_pkgs');
871 button.onclick = show_supp_pkgs_click;
872 button.style.backgroundColor = '#cccccc';
873 button.style.border = '1px solid #7e0079';
874 button.style.padding = '1px';
878 function finish_edit_fcc(id) {
880 show_fcc_options(id); // refresh the display
886 'Changing the setup or recurring fee will create a new package definition. '.
889 $javascript .= "function confirm_submit(f) {";
890 if ( $conf->exists('part_pkg-lineage') ) {
893 var fields = Array('setup_fee','recur_fee');
894 for(var i=0; i < fields.length; i++) {
895 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
896 return confirm('$warning');
906 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
908 tie my %plan_labels, 'Tie::IxHash',
909 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
912 my $html_bottom = sub {
915 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
917 my $layer_callback = sub {
920 my $html = ntable("#cccccc",2);
924 # <TD ALIGN="right">Recurring fee frequency </TD>
925 # <TD><SELECT NAME="freq">
928 #my @freq = keys %freq;
929 #@freq = grep { /^\d+$/ } @freq
930 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
931 #foreach my $freq ( @freq ) {
932 # $html .= qq(<OPTION VALUE="$freq");
933 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
934 # $html .= ">$freq{$freq}";
937 #$html .= '</SELECT></TD></TR>';
939 my $href = $plans{$layer}->{'fields'};
941 if ( $plans{$layer}->{'fieldorder'} ) {
942 @fields = @{ $plans{$layer}->{'fieldorder'} };
944 warn "FS::part_pkg::$layer has no fieldorder.\n";
945 @fields = keys %$href;
948 # hash of dependencies for each of the Pricing Plan fields.
949 # make sure NOT to use double-quotes inside the 'msg' value.
951 'unused_credit_suspend' => {
952 'msg' => q|You must set the 'suspend_credit_type' option in Configuration->Settings to gain access to this option.|,
954 my $conf = new FS::conf;
955 my @conf_info = qsearch('conf', { 'name' => 'suspend_credit_type' } );
956 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
960 'unused_credit_cancel' => {
961 'msg' => q|You must set the 'cancel_credit_type' option in Configuration->Settings to gain access to this option.|,
963 my $conf = new FS::conf;
964 my @conf_info = qsearch('conf', { 'name' => 'cancel_credit_type' } );
965 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
971 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
973 if(!exists($href->{$field})) {
975 warn "nonexistent part_pkg option: '$field'\n";
978 if ( exists($href->{$field}->{display_if}) ) {
979 my %args = ( 'plan' => $layer ); # anything else?
980 my $display = &{ $href->{$field}->{display_if} }(%args);
984 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>
987 my $format = sub { shift };
988 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
990 #XXX these should use elements/ fields... (or this whole thing should
991 #just use layer_fields instead of layer_callback)
993 if (exists($dependencies->{$field}) && !$dependencies->{$field}{'are_met'}()) {
994 $html .= q!<span title="!.$dependencies->{$field}{'msg'}.q!">N/A</span>!;
996 } elsif ( ! exists($href->{$field}{'type'}) ) {
998 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
999 ( exists($options{$field})
1000 ? &$format($options{$field})
1001 : $href->{$field}{'default'} ).
1004 } elsif ( $href->{$field}{'type'} eq 'textarea' ) {
1006 $html .= qq!<TEXTAREA NAME="${layer}__$field">!.
1007 ( exists($options{$field})
1008 ? &$format($options{$field})
1009 : $href->{$field}{'default'} ).
1012 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
1014 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
1015 ( exists($options{$field}) && $options{$field}
1020 } elsif ( $href->{$field}{'type'} eq 'date' ) {
1022 $html .= include('/elements/input-date-field.html', {
1023 'name' => $layer.'__'.$field,
1024 'value' => $options{$field},
1027 } elsif ( $href->{$field}{'type'} =~ /^select-rt-/ ) {
1029 $html .= include('/elements/'.$href->{$field}{'type'}.'.html',
1030 'name' => $layer.'__'.$field,
1031 'curr_value' => $options{$field},
1032 map { $_ => $href->{$field}{$_} }
1033 grep { $_ !~ /^(name|type|parse)$/ }
1034 keys %{ $href->{$field} }
1037 } elsif ( $href->{$field}{'type'} eq 'select-rate' ) {
1039 $html .= include('/elements/select-rate.html',
1040 'field' => $layer.'__'.$field,
1041 'curr_value' => $options{$field},
1042 map { $_ => $href->{$field}{$_} }
1043 grep { $_ !~ /^(name|type)$/ }
1044 keys %{ $href->{$field} }
1047 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
1050 $html .= ' MULTIPLE'
1051 if $href->{$field}{'type'} eq 'select_multiple';
1052 $html .= qq! NAME="${layer}__$field">!;
1054 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
1055 if exists($href->{$field}{'disable_empty'})
1056 && ! $href->{$field}{'disable_empty'};
1058 if ( $href->{$field}{'select_table'} ) {
1059 foreach my $record (
1060 qsearch( $href->{$field}{'select_table'},
1061 $href->{$field}{'select_hash'} )
1063 my $value = $record->getfield($href->{$field}{'select_key'});
1064 $html .= qq!<OPTION VALUE="$value"!.
1065 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
1069 '>'. $record->getfield($href->{$field}{'select_label'});
1071 } elsif ( $href->{$field}{'select_options'} ) {
1072 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
1073 my $label = $href->{$field}{'select_options'}{$key};
1074 $html .= qq!<OPTION VALUE="$key"!.
1075 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1083 $html .= '<font color="#ff0000">warning: '.
1084 "don't know how to retreive options for $field select field".
1087 $html .= '</SELECT>';
1089 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
1092 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
1094 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
1095 my $label = $href->{$field}{'options'}{$key};
1096 $html .= qq!$radio VALUE="$key"!.
1097 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1106 $html .= '</TD></TR>';
1108 $html .= '</TABLE>';
1110 $html .= include('/elements/hidden.html',
1111 field => $layer.'__OPTIONS',
1112 value => join(',', @fields)
1119 my %selectlayers = (
1121 options => [ keys %plan_labels ],
1122 labels => \%plan_labels,
1123 curr_value => $object->plan,
1124 layer_callback => $layer_callback,
1125 onchange => 'aux_planchanged(what);',
1129 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1130 '<SCRIPT TYPE="text/javascript">'.
1131 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
1134 # "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
1137 $return .= '</SCRIPT>';
1143 my %usage_class = map { ($_->classnum => $_->classname) }
1144 qsearch('usage_class', {});
1145 $usage_class{setup} = 'Setup';
1146 $usage_class{recur} = 'Recurring';
1148 my %taxproduct_fields = ();
1149 my $end_callback = sub {
1150 my( $cgi, $object, $fields, $opt ) = @_;
1152 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1154 if ( $object->pkgpart ) {
1155 foreach my $usage_class ( '', @taxproductnums ) {
1156 $tax_override{$usage_class} =
1157 join (",", map $_->taxclassnum,
1158 qsearch( 'part_pkg_taxoverride', {
1159 'pkgpart' => $object->pkgpart,
1160 'usage_class' => $usage_class,
1166 %taxproduct_fields =
1167 map { $_ => [ "taxproductnum_$_",
1168 { type => 'select-taxproduct',
1169 #label => "$usage_class{$_} tax product",
1172 { type => 'select-taxoverride' }
1177 $taxproduct_fields{'(default)'} =
1178 [ 'taxproductnum', { type => 'select-taxproduct',
1179 #label => 'Default tax product',
1181 'tax_override', { type => 'select-taxoverride' },
1185 my $taxproduct_values = sub {
1186 my ($cgi, $object, $flags) = @_;
1188 sub { my $layer = shift;
1189 my @fields = @{$taxproduct_fields{$layer}};
1192 my $field = shift @fields;
1194 $field =~ /^taxproductnum_\w+$/ &&
1195 push @values, ( $field => $options{"usage_$field"} );
1196 $field =~ /^tax_override_(\w+)$/ &&
1197 push @values, ( $field => $tax_override{$1} );
1198 $field =~ /^taxproductnum$/ &&
1199 push @values, ( $field => $object->taxproductnum );
1200 $field =~ /^tax_override$/ &&
1201 push @values, ( $field => $tax_override{''} );
1207 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1208 return({ @result });
1212 my $field_callback = sub {
1213 my ($cgi, $object, $fieldref) = @_;
1215 my $field = $fieldref->{field};
1216 if ($field eq 'taxproductnums') {
1217 $fieldref->{value} = join(',', @taxproductnums);
1218 } elsif ($field eq 'taxproduct_select') {
1219 $fieldref->{options} = [ '(default)', @taxproductnums ];
1220 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1221 map {( $_ => ($usage_class{$_} || $_) )}
1224 $fieldref->{layer_fields} = \%taxproduct_fields;
1225 $fieldref->{layer_values_callback} = $taxproduct_values;
1226 } elsif ($field eq 'taxproductnum') { # part_pkg-taxproduct, new style
1227 if ( !$taxproducts ) {
1228 # then make the widget go away
1229 $fieldref->{type} = 'hidden';
1234 my $discountnum_hashref = {
1236 'months' => { 'op' => '>', 'value' => 1 },