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)',
72 'adjourn_months' => 'Suspend the package after ',
73 'contract_end_months' => 'Contract ends after ',
74 'expire_months' => 'Cancel the package after ',
75 'change_to_pkgpart'=> 'and replace it with ',
79 { field=>'clone', type=>'hidden',
80 curr_value_callback =>
81 sub { shift->param('clone') },
83 { field=>'pkgnum', type=>'hidden',
84 curr_value_callback =>
85 sub { shift->param('pkgnum') },
88 { field=>'custom', type=>'hidden' },
89 { field=>'family_pkgpart', type=>'hidden' },
90 { field=>'successor', type=>'hidden' },
92 { type => 'columnstart' },
95 type => 'input-locale-text',
100 {field=>'comment', type=>'text', size=>40 }, #32
101 { field => 'agentnum',
102 type => 'select-agent',
103 disable_empty => ! $acl_edit_global,
104 empty_label => '(global)',
105 onchange => 'agent_changed',
107 {field=>'classnum', type=>'select-pkg_class' },
108 ( $conf->exists('pkg-addon_classnum')
109 ? ( { field=>'addon_classnum',
110 type =>'select-pkg_class',
115 {field=>'disabled', type=>$disabled_type, value=>'Y'},
116 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
117 { field => 'start_on_hold',
122 { type => 'tablebreak-tr-title',
123 value => 'Pricing', #better name?
126 type => 'selectlayers-select',
127 options => [ keys %plan_labels ],
128 labels => \%plan_labels,
129 onchange => 'aux_planchanged(what);',
131 { field => 'setup_fee',
133 onchange => 'setup_changed',
135 { field => 'setup_show_zero',
138 disabled => sub { $setup_show_zero_disabled },
140 ( map { +{ field => "setup_fee_$_",
142 prefix=> currency_symbol($_, SYM_HTML),
146 sort $conf->config('currencies')
149 type => 'part_pkg_freq',
150 onchange => 'freq_changed',
152 { field => 'recur_fee',
154 disabled => sub { $recur_disabled },
155 onchange => 'recur_changed',
157 { field => 'recur_show_zero',
160 disabled => sub { $recur_show_zero_disabled },
162 ( map { +{ field => "recur_fee_$_",
164 prefix=> currency_symbol($_, SYM_HTML),
168 sort $conf->config('currencies')
171 ( $conf->exists('part_pkg-delay_start')
172 ? ( { type => 'tablebreak-tr-title',
173 value => 'Delayed start',
175 { field => 'delay_start',
176 type => 'text', size => 6 },
181 { type => 'tablebreak-tr-title',
182 value => 'Limited duration',
184 { field => 'adjourn_months',
185 type => 'select-months',
187 { field => 'contract_end_months',
188 type => 'select-months',
190 { field => 'expire_months',
191 type => 'select-expire_months',
193 { field => 'change_to_pkgpart',
194 type => 'select-part_pkg',
195 extra_sql => sub { $pkgpart
196 ? "AND part_pkg.pkgpart != $pkgpart"
199 empty_label => 'no package',
205 #recurring fee (auto-disable)
207 { type => 'columnnext' },
209 {type=>'justtitle', value=>'Taxation' },
210 {field=>'setuptax', type=>'checkbox', value=>'Y'},
211 {field=>'recurtax', type=>'checkbox', value=>'Y'},
212 {field=>'taxclass', type=>'select-taxclass' },
213 { field => 'taxproductnums',
215 value => join(',', @taxproductnums),
217 #{ field => 'taxproduct_select',
218 # type => 'selectlayers',
219 # options => [ '(default)', @taxproductnums ],
220 # curr_value => '(default)',
221 # labels => { ( '(default)' => '(default)' ),
222 # map {($_=>$usage_class{$_})}
225 # layer_fields => \%taxproduct_fields,
226 # layer_values_callback => $taxproduct_values,
227 # layers_only => !$taxproducts,
228 # cell_style => ( !$taxproducts
233 { field => 'taxproductnum',
234 type => 'part_pkg-taxproducts',
235 include_opt_callback =>
236 sub { pkgpart => $_[0]->pkgpart },
239 { type => 'tablebreak-tr-title',
240 value => 'Promotions', #better name?
242 { field=>'promo_code', type=>'text', size=>15 },
244 { type => 'tablebreak-tr-title',
245 value => 'Cost tracking', #better name?
248 ( $curuser->access_right('Edit package definition costs')
249 ? ( { field=>'setup_cost', type=>'money', },
250 { field=>'recur_cost', type=>'money', },
252 : ( { field=>'setup_cost', type=>'fixed', },
253 { field=>'recur_cost', type=>'fixed', },
257 { type => 'columnnext' },
259 {type=>'justtitle', value=>'Agent (reseller) types' },
261 { field => 'agent_type',
262 type => 'select-agent_type',
263 disabled => ! $acl_edit_global,
264 element_etc => 'size="10"',
265 multiple => '1', #cause edit.html is dum
266 curr_value_callback => sub {
267 my($cgi, $object, $field) = @_;
268 #in the other callbacks..? hmm.
274 { type => 'tablebreak-tr-title',
275 value => 'FCC Form 477 information',
277 { field => 'fcc_options_string',
278 type => 'input-fcc_options',
279 curr_value_callback => sub {
280 my ($cgi, $part_pkg, $fref) = @_;
281 if ( $cgi->param('fcc_options_string') ) {
283 return $cgi->param('fcc_options_string');
286 %hash = $part_pkg->fcc_options
287 if ($part_pkg->pkgpart);
288 return encode_json(\%hash);
294 { type => 'tablebreak-tr-title',
295 value => 'External Links', #better name?
297 { field=>'agent_pkgpartid', type=>'text', size=>21 },
299 { type => 'tablebreak-tr-title',
300 value => 'Line-item revenue recognition', #better name?
302 { field=>'pay_weight', type=>'text', size=>6 },
303 { field=>'credit_weight', type=>'text', size=>6 },
305 { type => 'columnend' },
307 { type => 'tablebreak-tr-title',
308 value => 'Usage pricing add-ons', #better name? just 'Usage pricing' ? there's also CDR usage pricing, RADIUS usage pricing, etc :/
310 { 'field' => 'usagepricepart',
311 'type' => 'part_pkg_usageprice',
312 'o2m_table' => 'part_pkg_usageprice',
314 'm2_error_callback' => $usageprice_error_callback,
317 { 'type' => $report_option ? 'tablebreak-tr-title'
319 'value' => 'Optional report classes',
320 'field' => 'census_title',
322 { 'field' => 'report_option',
323 'type' => $report_option ? 'select-table'
325 'table' => 'part_pkg_report_option',
326 'name_col' => 'name',
327 'hashref' => { 'disabled' => '' },
329 'curr_value_callback' => $report_option_value_callback,
332 { 'type' => 'tablebreak-tr-title',
333 'value' => 'Term discounts',
335 { 'field' => 'discountnum',
336 'type' => 'select-table',
337 'table' => 'discount',
338 'name_col' => 'name',
339 'hashref' => { %$discountnum_hashref },
340 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
341 'empty_label'=> 'Select discount',
342 'm2_label' => 'Offer discounts for longer terms',
343 'm2m_method' => 'part_pkg_discount',
344 'm2m_dstcol' => 'discountnum',
345 'm2_error_callback' => $discount_error_callback,
348 { 'type' => 'tablebreak-tr-title',
349 'value' => 'Pricing add-ons',
352 { 'field' => 'bill_dst_pkgpart',
353 'type' => 'select-part_pkg',
354 'extra_sql' => sub { $pkgpart
355 ? "AND part_pkg.pkgpart != $pkgpart"
358 'label_callback' => sub { shift->pkg_comment_only },
359 'm2_label' => 'Include line item(s) from package',
360 'm2m_method' => 'bill_part_pkg_link',
361 'm2m_dstcol' => 'dst_pkgpart',
362 'm2_error_callback' =>
363 &{$m2_error_callback_maker}('bill'),
364 'm2_fields' => [ { 'field' => 'hidden',
365 'type' => 'checkbox',
373 { type => 'tablebreak-tr-title',
376 { type => 'pkg_svc', },
378 { 'field' => 'svc_dst_pkgpart',
379 'label' => 'Also include services from package: ',
380 'type' => 'select-part_pkg',
381 'extra_sql' => sub { $pkgpart
382 ? "AND part_pkg.pkgpart != $pkgpart"
385 'label_callback' => sub { shift->pkg_comment_only },
386 'm2_label' => 'Include services of package: ',
387 'm2m_method' => 'svc_part_pkg_link',
388 'm2m_dstcol' => 'dst_pkgpart',
389 'm2_error_callback' =>
390 &{$m2_error_callback_maker}('svc'),
393 { 'type' => 'tablebreak-tr-title',
394 'value' => 'Supplemental packages',
396 'include_opt_callback' => sub {
397 'id' => 'show_supp_pkgs',
400 { 'field' => 'supp_dst_pkgpart',
401 'type' => 'select-part_pkg',
402 'label_callback' => sub { shift->pkg_comment_only },
403 'm2_label' => 'When ordering package, also order',
404 'm2m_method' => 'supp_part_pkg_link',
405 'm2m_dstcol' => 'dst_pkgpart',
406 'm2_error_callback' =>
407 &{$m2_error_callback_maker}('supp'),
410 { type => 'tablebreak-tr-title',
411 value => 'Price plan options',
418 my $curuser = $FS::CurrentUser::CurrentUser;
420 my $edit_global = 'Edit global package definitions';
421 my $acl_edit = $curuser->access_right('Edit package definitions');
422 my $acl_edit_global = $curuser->access_right($edit_global);
424 my $acl_edit_either = $acl_edit || $acl_edit_global;
426 my $begin_callback = sub {
427 my( $cgi, $fields, $opt ) = @_;
429 unless $acl_edit_either
430 || ( $cgi->param('pkgnum')
431 && $curuser->access_right('Customize customer package')
435 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
437 #arg. access rights for cloning are Hard.
438 # on the one hand we don't really want cloning (customizing a package) to fail
439 # for want of finding the source package in normal usage
440 # on the other hand, we don't want people using the clone link to be able to
442 my $agent_clone_extra_sql =
443 ' ( '. FS::part_pkg->curuser_pkgs_sql.
444 " OR ( part_pkg.custom = 'Y' ) ".
447 my $conf = new FS::Conf;
448 my $taxproducts = $conf->config('tax_data_vendor') ne '';
450 my $fcc_opts = $conf->exists('part_pkg-show_fcc_options');
452 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
453 my %locale_labels = map {
454 ( $_ => 'Package -- '. FS::Locales->description($_) )
457 sort { $locale_labels{$a} cmp $locale_labels{$b} }
461 my %locale_field_labels = (
463 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
468 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
469 " WHERE disabled IS NULL OR disabled = '' ")
471 $sth->execute or die $sth->errstr;
472 my $report_option = $sth->fetchrow_arrayref->[0];
475 # - tr-part_pkg_freq: month_increments_only (from price plans)
477 # - test errors cloning
478 # - test custom pricing
479 # - move the selectlayer divs away from lame layer_callback
481 #my ($query) = $cgi->keywords;
486 my %tax_override = ();
488 my %taxproductnums = map { ($_->classnum => 1) }
489 qsearch('usage_class', { 'disabled' => '' });
490 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
493 my $recur_disabled = 1;
494 my $setup_show_zero_disabled = 0;
495 my $recur_show_zero_disabled = 1;
499 my $error_callback = sub {
500 my($cgi, $object, $fields, $opt ) = @_;
502 (@agent_type) = $cgi->param('agent_type');
504 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
506 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
508 $recur_disabled = $cgi->param('freq') ? 0 : 1;
509 $recur_show_zero_disabled =
511 ? $cgi->param('recur_fee') > 0 ? 1 : 0
514 foreach ($cgi->param) {
515 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
517 $tax_override{''} = $cgi->param('tax_override');
518 $tax_override{$_} = $cgi->param('tax_override_$_')
519 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
521 #some false laziness w/process
522 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
524 my $options = $cgi->param($plan."__OPTIONS");
525 my @options = split(',', $options);
527 map { my $optionname = $_;
528 my $param = $plan."__$optionname";
529 my $value = join(', ', $cgi->param($param));
530 ( $optionname => $value );
534 $object->set($_ => scalar($cgi->param($_)) )
535 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
537 foreach my $currency ( $conf->config('currencies') ) {
538 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
539 foreach (qw( setup_fee recur_fee )) {
540 my $param = $_.'_'.$currency;
541 $object->set( $param, $cgi->param($param) );
545 $pkgpart = $object->pkgpart;
547 if ( $cgi->param('error') =~ / is suggested with / ) {
548 #yeah, detection is a shitty kludge, but we don't have exception objects
549 $opt->{form_init} = '<INPUT TYPE="checkbox" NAME="part_pkg_restrict_soft_override" VALUE="Y"> Override suggestion<BR><BR>';
554 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
556 my $new_object_callback = sub {
557 my( $cgi, $hashref, $fields, $opt ) = @_;
559 my $part_pkg = FS::part_pkg->new( $hashref );
560 $part_pkg->set($_ => '0')
561 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
567 my $report_option_value_callback = sub {
568 my ($cgi, $object) = @_;
570 if ( defined $cgi->param('report_option') ) {
571 @report_option = $cgi->param('report_option');
573 foreach ($object->options) {
574 /^report_option_(\d+)$/ && (push @report_option, $1);
577 join(',', @report_option);
580 sub set_report_option {
581 my($cgi, $object, $fields ) = @_; #, $opt
583 my @report_option = ();
584 foreach ($object->options) {
585 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
586 # /^report_option_(\d+)$/ && (push @report_option, $1);
588 foreach ($object->part_pkg_taxoverride) {
589 $taxproductnums{$_->usage_class} = 1
593 # $cgi->param('report_option', join(',', @report_option));
594 # foreach my $field ( @$fields ) {
596 # ref($field) eq 'HASH' &&
598 # $field->{field} eq 'report_option'
600 # #$field->{curr_value} = join(',', @report_option);
601 # $field->{value} = join(',', @report_option);
606 my $edit_callback = sub {
607 my( $cgi, $object, $fields, $opt ) = @_;
609 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
611 $recur_disabled = $object->freq ? 0 : 1;
613 $recur_show_zero_disabled =
615 ? $object->option('recur_fee') > 0 ? 1 : 0
619 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
621 set_report_option( $cgi, $object, $fields);
623 %options = $object->options;
625 $object->set($_ => $object->option($_, 1))
626 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
628 foreach my $currency ( $conf->config('currencies') ) {
629 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
630 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
631 foreach keys %part_pkg_currency;
634 $pkgpart = $object->pkgpart;
638 my $new_callback = sub {
639 my( $cgi, $object, $fields ) = @_;
641 my $conf = new FS::Conf;
643 if ( $conf->exists('agent_defaultpkg') ) {
644 @agent_type = map {$_->typenum} qsearch('agent_type', { 'disabled'=>'' });
647 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
651 my $clone_callback = sub {
652 my( $cgi, $object, $fields, $opt ) = @_;
654 if ( $cgi->param('pkgnum') ) {
656 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => scalar($cgi->param('pkgnum')) } );
657 $object->agentnum( $cust_pkg->cust_main->agentnum );
659 $opt->{action} = 'Custom';
661 #my $part_pkg = $clone_part_pkg->clone;
662 #this is all clone does anyway
663 $object->custom('Y');
665 $object->disabled('Y');
667 } else { #when explicitly cloning, not customizing
670 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
674 set_report_option( $cgi, $object, $fields);
676 %options = $object->options;
678 $object->set($_ => $options{$_})
679 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
681 $recur_disabled = $object->freq ? 0 : 1;
682 $recur_show_zero_disabled =
684 ? $object->option('recur_fee') > 0 ? 1 : 0
687 foreach my $currency ( $conf->config('currencies') ) {
688 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
689 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
690 foreach keys %part_pkg_currency;
695 my $discount_error_callback = sub {
696 my( $cgi, $object ) = @_;
698 if ( /^discountnum(\d+)$/ &&
699 ( my $discountnum = $cgi->param("discountnum$1") ) )
701 new FS::part_pkg_discount {
702 'pkgpart' => $object->pkgpart,
703 'discountnum' => $discountnum,
712 my $usageprice_error_callback = sub {
713 my( $cgi, $object ) = @_;
715 if ( /^usagepricepart(\d+)_price$/
716 && $cgi->param("usagepricepart$1_price") )
718 new FS::part_pkg_usageprice {
719 'usagepricepart' => scalar($cgi->param("usagepricepart$1")),
720 'pkgpart' => $object->pkgpart,
721 'price' => scalar($cgi->param("usagepricepart$1_price")),
723 'action' => scalar($cgi->param("usagepricepart$1_action")),
724 'target' => scalar($cgi->param("usagepricepart$1_target")),
725 'amount' => scalar($cgi->param("usagepricepart$1_amount")),
734 my $m2_error_callback_maker = sub {
735 my $link_type = shift; #yay closures
737 my( $cgi, $object ) = @_;
740 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
741 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
744 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
746 new FS::part_pkg_link {
747 'link_type' => $link_type,
748 'src_pkgpart' => $object->pkgpart,
749 'dst_pkgpart' => $dst,
760 my $javascript = <<'END';
761 <SCRIPT TYPE="text/javascript">
763 function freq_changed(what) {
764 var freq = what.options[what.selectedIndex].value;
767 what.form.recur_fee.disabled = true;
768 what.form.recur_fee.style.backgroundColor = '#dddddd';
769 what.form.recur_show_zero.disabled = true;
770 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
772 what.form.recur_fee.disabled = false;
773 what.form.recur_fee.style.backgroundColor = '#ffffff';
774 recur_changed( what.form.recur_fee );
775 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
780 function setup_changed(what) {
781 var setup = what.value;
782 if ( parseFloat(setup) == 0 ) {
783 what.form.setup_show_zero.disabled = false;
785 what.form.setup_show_zero.disabled = true;
789 function recur_changed(what) {
790 var recur = what.value;
791 if ( parseFloat(recur) == 0 ) {
792 what.form.recur_show_zero.disabled = false;
794 what.form.recur_show_zero.disabled = true;
798 function agent_changed(what) {
801 if ( what.type == 'select-one' ) {
802 agentnum = what.options[what.selectedIndex].value;
804 agentnum = what.value;
807 if ( agentnum == 0 ) {
808 what.form.agent_type.disabled = false;
809 //what.form.agent_type.style.backgroundColor = '#ffffff';
810 what.form.agent_type.style.visibility = '';
812 what.form.agent_type.disabled = true;
813 //what.form.agent_type.style.backgroundColor = '#dddddd';
814 what.form.agent_type.style.visibility = 'hidden';
819 function aux_planchanged(what) { //?
821 var plan = what.options[what.selectedIndex].value;
823 var term_table = document.getElementById('TableNumber8') // XXX NOT ROBUST
824 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
825 //term_table.disabled = false;
826 //term_table.style.visibility = '';
827 term_table.style.display = '';
829 //term_table.disabled = true;
830 //term_table.style.visibility = 'hidden';
831 term_table.style.display = 'none';
834 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
837 for ( var i=0; i < form.length; i++ ) {
838 if ( currency_regex.test(form[i].name) ) {
839 if ( plan == 'currency_fixed' ) {
840 form[i].disabled = false;
842 form[i].disabled = true;
849 // some magic to make "supplemental packages" less obvious
850 var supp_pkg_rows = [];
851 function show_supp_pkgs_click() {
852 supp_pkg_rows[0].style.display = '';
854 this.style.backgroundColor = '';
855 this.style.border = '';
856 this.style.padding = '';
859 function hide_supp_pkgs() {
860 var all_selects = document.getElementsByTagName('select');
861 for (var i=0; i < all_selects.length; i++) {
862 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
863 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
866 if ( supp_pkg_rows.length == 1 ) {
867 // there are none configured, so hide the row to create a new one
868 supp_pkg_rows[0].style.display = 'none';
869 var button = document.getElementById('show_supp_pkgs');
870 button.onclick = show_supp_pkgs_click;
871 button.style.backgroundColor = '#cccccc';
872 button.style.border = '1px solid #7e0079';
873 button.style.padding = '1px';
877 function finish_edit_fcc(id) {
879 show_fcc_options(id); // refresh the display
885 'Changing the setup or recurring fee will create a new package definition. '.
888 $javascript .= "function confirm_submit(f) {";
889 if ( $conf->exists('part_pkg-lineage') ) {
892 var fields = Array('setup_fee','recur_fee');
893 for(var i=0; i < fields.length; i++) {
894 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
895 return confirm('$warning');
905 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
907 tie my %plan_labels, 'Tie::IxHash',
908 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
911 my $html_bottom = sub {
914 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
916 my $layer_callback = sub {
919 my $html = ntable("#cccccc",2);
923 # <TD ALIGN="right">Recurring fee frequency </TD>
924 # <TD><SELECT NAME="freq">
927 #my @freq = keys %freq;
928 #@freq = grep { /^\d+$/ } @freq
929 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
930 #foreach my $freq ( @freq ) {
931 # $html .= qq(<OPTION VALUE="$freq");
932 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
933 # $html .= ">$freq{$freq}";
936 #$html .= '</SELECT></TD></TR>';
938 my $href = $plans{$layer}->{'fields'};
940 if ( $plans{$layer}->{'fieldorder'} ) {
941 @fields = @{ $plans{$layer}->{'fieldorder'} };
943 warn "FS::part_pkg::$layer has no fieldorder.\n";
944 @fields = keys %$href;
947 # hash of dependencies for each of the Pricing Plan fields.
948 # make sure NOT to use double-quotes inside the 'msg' value.
950 'unused_credit_suspend' => {
951 'msg' => q|You must set the 'suspend_credit_type' option in Configuration->Settings to gain access to this option.|,
953 my $conf = new FS::conf;
954 my @conf_info = qsearch('conf', { 'name' => 'suspend_credit_type' } );
955 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
959 'unused_credit_cancel' => {
960 'msg' => q|You must set the 'cancel_credit_type' option in Configuration->Settings to gain access to this option.|,
962 my $conf = new FS::conf;
963 my @conf_info = qsearch('conf', { 'name' => 'cancel_credit_type' } );
964 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
970 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
972 if(!exists($href->{$field})) {
974 warn "nonexistent part_pkg option: '$field'\n";
977 if ( exists($href->{$field}->{display_if}) ) {
978 my %args = ( 'plan' => $layer ); # anything else?
979 my $display = &{ $href->{$field}->{display_if} }(%args);
983 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>
986 my $format = sub { shift };
987 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
989 #XXX these should use elements/ fields... (or this whole thing should
990 #just use layer_fields instead of layer_callback)
992 if (exists($dependencies->{$field}) && !$dependencies->{$field}{'are_met'}()) {
993 $html .= q!<span title="!.$dependencies->{$field}{'msg'}.q!">N/A</span>!;
995 } elsif ( ! exists($href->{$field}{'type'}) ) {
997 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
998 ( exists($options{$field})
999 ? &$format($options{$field})
1000 : $href->{$field}{'default'} ).
1003 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
1005 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
1006 ( exists($options{$field}) && $options{$field}
1011 } elsif ( $href->{$field}{'type'} =~ /^select-rt-/ ) {
1013 $html .= include('/elements/'.$href->{$field}{'type'}.'.html',
1014 'name' => $layer.'__'.$field,
1015 'curr_value' => $options{$field},
1016 map { $_ => $href->{$field}{$_} }
1017 grep { $_ !~ /^(name|type|parse)$/ }
1018 keys %{ $href->{$field} }
1021 } elsif ( $href->{$field}{'type'} eq 'select-rate' ) {
1023 $html .= include('/elements/select-rate.html',
1024 'field' => $layer.'__'.$field,
1025 'curr_value' => $options{$field},
1026 map { $_ => $href->{$field}{$_} }
1027 grep { $_ !~ /^(name|type)$/ }
1028 keys %{ $href->{$field} }
1031 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
1034 $html .= ' MULTIPLE'
1035 if $href->{$field}{'type'} eq 'select_multiple';
1036 $html .= qq! NAME="${layer}__$field">!;
1038 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
1039 if exists($href->{$field}{'disable_empty'})
1040 && ! $href->{$field}{'disable_empty'};
1042 if ( $href->{$field}{'select_table'} ) {
1043 foreach my $record (
1044 qsearch( $href->{$field}{'select_table'},
1045 $href->{$field}{'select_hash'} )
1047 my $value = $record->getfield($href->{$field}{'select_key'});
1048 $html .= qq!<OPTION VALUE="$value"!.
1049 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
1053 '>'. $record->getfield($href->{$field}{'select_label'});
1055 } elsif ( $href->{$field}{'select_options'} ) {
1056 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
1057 my $label = $href->{$field}{'select_options'}{$key};
1058 $html .= qq!<OPTION VALUE="$key"!.
1059 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1067 $html .= '<font color="#ff0000">warning: '.
1068 "don't know how to retreive options for $field select field".
1071 $html .= '</SELECT>';
1073 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
1076 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
1078 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
1079 my $label = $href->{$field}{'options'}{$key};
1080 $html .= qq!$radio VALUE="$key"!.
1081 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1090 $html .= '</TD></TR>';
1092 $html .= '</TABLE>';
1094 $html .= include('/elements/hidden.html',
1095 field => $layer.'__OPTIONS',
1096 value => join(',', @fields)
1103 my %selectlayers = (
1105 options => [ keys %plan_labels ],
1106 labels => \%plan_labels,
1107 curr_value => $object->plan,
1108 layer_callback => $layer_callback,
1109 onchange => 'aux_planchanged(what);',
1113 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1114 '<SCRIPT TYPE="text/javascript">'.
1115 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
1118 # "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
1121 $return .= '</SCRIPT>';
1127 my %usage_class = map { ($_->classnum => $_->classname) }
1128 qsearch('usage_class', {});
1129 $usage_class{setup} = 'Setup';
1130 $usage_class{recur} = 'Recurring';
1132 my %taxproduct_fields = ();
1133 my $end_callback = sub {
1134 my( $cgi, $object, $fields, $opt ) = @_;
1136 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1138 if ( $object->pkgpart ) {
1139 foreach my $usage_class ( '', @taxproductnums ) {
1140 $tax_override{$usage_class} =
1141 join (",", map $_->taxclassnum,
1142 qsearch( 'part_pkg_taxoverride', {
1143 'pkgpart' => $object->pkgpart,
1144 'usage_class' => $usage_class,
1150 %taxproduct_fields =
1151 map { $_ => [ "taxproductnum_$_",
1152 { type => 'select-taxproduct',
1153 #label => "$usage_class{$_} tax product",
1156 { type => 'select-taxoverride' }
1161 $taxproduct_fields{'(default)'} =
1162 [ 'taxproductnum', { type => 'select-taxproduct',
1163 #label => 'Default tax product',
1165 'tax_override', { type => 'select-taxoverride' },
1169 my $taxproduct_values = sub {
1170 my ($cgi, $object, $flags) = @_;
1172 sub { my $layer = shift;
1173 my @fields = @{$taxproduct_fields{$layer}};
1176 my $field = shift @fields;
1178 $field =~ /^taxproductnum_\w+$/ &&
1179 push @values, ( $field => $options{"usage_$field"} );
1180 $field =~ /^tax_override_(\w+)$/ &&
1181 push @values, ( $field => $tax_override{$1} );
1182 $field =~ /^taxproductnum$/ &&
1183 push @values, ( $field => $object->taxproductnum );
1184 $field =~ /^tax_override$/ &&
1185 push @values, ( $field => $tax_override{''} );
1191 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1192 return({ @result });
1196 my $field_callback = sub {
1197 my ($cgi, $object, $fieldref) = @_;
1199 my $field = $fieldref->{field};
1200 if ($field eq 'taxproductnums') {
1201 $fieldref->{value} = join(',', @taxproductnums);
1202 } elsif ($field eq 'taxproduct_select') {
1203 $fieldref->{options} = [ '(default)', @taxproductnums ];
1204 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1205 map {( $_ => ($usage_class{$_} || $_) )}
1208 $fieldref->{layer_fields} = \%taxproduct_fields;
1209 $fieldref->{layer_values_callback} = $taxproduct_values;
1210 } elsif ($field eq 'taxproductnum') { # part_pkg-taxproduct, new style
1211 if ( !$taxproducts ) {
1212 # then make the widget go away
1213 $fieldref->{type} = 'hidden';
1218 my $discountnum_hashref = {
1220 'months' => { 'op' => '>', 'value' => 1 },