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' => $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 foreach my $currency ( $conf->config('currencies') ) {
682 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
683 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
684 foreach keys %part_pkg_currency;
689 my $discount_error_callback = sub {
690 my( $cgi, $object ) = @_;
692 if ( /^discountnum(\d+)$/ &&
693 ( my $discountnum = $cgi->param("discountnum$1") ) )
695 new FS::part_pkg_discount {
696 'pkgpart' => $object->pkgpart,
697 'discountnum' => $discountnum,
706 my $usageprice_error_callback = sub {
707 my( $cgi, $object ) = @_;
709 if ( /^usagepricepart(\d+)_price$/
710 && $cgi->param("usagepricepart$1_price") )
712 new FS::part_pkg_usageprice {
713 'usagepricepart' => $cgi->param("usagepricepart$1"),
714 'pkgpart' => $object->pkgpart,
715 'price' => scalar($cgi->param("usagepricepart$1_price")),
717 'action' => scalar($cgi->param("usagepricepart$1_action")),
718 'target' => scalar($cgi->param("usagepricepart$1_target")),
719 'amount' => scalar($cgi->param("usagepricepart$1_amount")),
728 my $m2_error_callback_maker = sub {
729 my $link_type = shift; #yay closures
731 my( $cgi, $object ) = @_;
734 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
735 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
738 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
740 new FS::part_pkg_link {
741 'link_type' => $link_type,
742 'src_pkgpart' => $object->pkgpart,
743 'dst_pkgpart' => $dst,
754 my $javascript = <<'END';
755 <SCRIPT TYPE="text/javascript">
757 function freq_changed(what) {
758 var freq = what.options[what.selectedIndex].value;
761 what.form.recur_fee.disabled = true;
762 what.form.recur_fee.style.backgroundColor = '#dddddd';
763 what.form.recur_show_zero.disabled = true;
764 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
766 what.form.recur_fee.disabled = false;
767 what.form.recur_fee.style.backgroundColor = '#ffffff';
768 recur_changed( what.form.recur_fee );
769 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
774 function setup_changed(what) {
775 var setup = what.value;
776 if ( parseFloat(setup) == 0 ) {
777 what.form.setup_show_zero.disabled = false;
779 what.form.setup_show_zero.disabled = true;
783 function recur_changed(what) {
784 var recur = what.value;
785 if ( parseFloat(recur) == 0 ) {
786 what.form.recur_show_zero.disabled = false;
788 what.form.recur_show_zero.disabled = true;
792 function agent_changed(what) {
795 if ( what.type == 'select-one' ) {
796 agentnum = what.options[what.selectedIndex].value;
798 agentnum = what.value;
801 if ( agentnum == 0 ) {
802 what.form.agent_type.disabled = false;
803 //what.form.agent_type.style.backgroundColor = '#ffffff';
804 what.form.agent_type.style.visibility = '';
806 what.form.agent_type.disabled = true;
807 //what.form.agent_type.style.backgroundColor = '#dddddd';
808 what.form.agent_type.style.visibility = 'hidden';
813 function aux_planchanged(what) { //?
815 var plan = what.options[what.selectedIndex].value;
817 var term_table = document.getElementById('TableNumber8') // XXX NOT ROBUST
818 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
819 //term_table.disabled = false;
820 //term_table.style.visibility = '';
821 term_table.style.display = '';
823 //term_table.disabled = true;
824 //term_table.style.visibility = 'hidden';
825 term_table.style.display = 'none';
828 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
831 for ( var i=0; i < form.length; i++ ) {
832 if ( currency_regex.test(form[i].name) ) {
833 if ( plan == 'currency_fixed' ) {
834 form[i].disabled = false;
836 form[i].disabled = true;
843 // some magic to make "supplemental packages" less obvious
844 var supp_pkg_rows = [];
845 function show_supp_pkgs_click() {
846 supp_pkg_rows[0].style.display = '';
848 this.style.backgroundColor = '';
849 this.style.border = '';
850 this.style.padding = '';
853 function hide_supp_pkgs() {
854 var all_selects = document.getElementsByTagName('select');
855 for (var i=0; i < all_selects.length; i++) {
856 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
857 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
860 if ( supp_pkg_rows.length == 1 ) {
861 // there are none configured, so hide the row to create a new one
862 supp_pkg_rows[0].style.display = 'none';
863 var button = document.getElementById('show_supp_pkgs');
864 button.onclick = show_supp_pkgs_click;
865 button.style.backgroundColor = '#cccccc';
866 button.style.border = '1px solid #7e0079';
867 button.style.padding = '1px';
871 function finish_edit_fcc(id) {
873 show_fcc_options(id); // refresh the display
879 'Changing the setup or recurring fee will create a new package definition. '.
882 $javascript .= "function confirm_submit(f) {";
883 if ( $conf->exists('part_pkg-lineage') ) {
886 var fields = Array('setup_fee','recur_fee');
887 for(var i=0; i < fields.length; i++) {
888 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
889 return confirm('$warning');
899 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
901 tie my %plan_labels, 'Tie::IxHash',
902 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
905 my $html_bottom = sub {
908 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
910 my $layer_callback = sub {
913 my $html = ntable("#cccccc",2);
917 # <TD ALIGN="right">Recurring fee frequency </TD>
918 # <TD><SELECT NAME="freq">
921 #my @freq = keys %freq;
922 #@freq = grep { /^\d+$/ } @freq
923 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
924 #foreach my $freq ( @freq ) {
925 # $html .= qq(<OPTION VALUE="$freq");
926 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
927 # $html .= ">$freq{$freq}";
930 #$html .= '</SELECT></TD></TR>';
932 my $href = $plans{$layer}->{'fields'};
934 if ( $plans{$layer}->{'fieldorder'} ) {
935 @fields = @{ $plans{$layer}->{'fieldorder'} };
937 warn "FS::part_pkg::$layer has no fieldorder.\n";
938 @fields = keys %$href;
941 # hash of dependencies for each of the Pricing Plan fields.
942 # make sure NOT to use double-quotes inside the 'msg' value.
944 'unused_credit_suspend' => {
945 'msg' => q|You must set the 'suspend_credit_type' option in Configuration->Settings to gain access to this option.|,
947 my $conf = new FS::conf;
948 my @conf_info = qsearch('conf', { 'name' => 'suspend_credit_type' } );
949 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
953 'unused_credit_cancel' => {
954 'msg' => q|You must set the 'cancel_credit_type' option in Configuration->Settings to gain access to this option.|,
956 my $conf = new FS::conf;
957 my @conf_info = qsearch('conf', { 'name' => 'cancel_credit_type' } );
958 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
964 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
966 if(!exists($href->{$field})) {
968 warn "nonexistent part_pkg option: '$field'\n";
971 if ( exists($href->{$field}->{display_if}) ) {
972 my %args = ( 'plan' => $layer ); # anything else?
973 my $display = &{ $href->{$field}->{display_if} }(%args);
977 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>
980 my $format = sub { shift };
981 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
983 #XXX these should use elements/ fields... (or this whole thing should
984 #just use layer_fields instead of layer_callback)
986 if (exists($dependencies->{$field}) && !$dependencies->{$field}{'are_met'}()) {
987 $html .= q!<span title="!.$dependencies->{$field}{'msg'}.q!">N/A</span>!;
989 } elsif ( ! exists($href->{$field}{'type'}) ) {
991 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
992 ( exists($options{$field})
993 ? &$format($options{$field})
994 : $href->{$field}{'default'} ).
997 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
999 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
1000 ( exists($options{$field}) && $options{$field}
1005 } elsif ( $href->{$field}{'type'} =~ /^select-rt-/ ) {
1007 $html .= include('/elements/'.$href->{$field}{'type'}.'.html',
1008 'name' => $layer.'__'.$field,
1009 'curr_value' => $options{$field},
1010 map { $_ => $href->{$field}{$_} }
1011 grep { $_ !~ /^(name|type|parse)$/ }
1012 keys %{ $href->{$field} }
1015 } elsif ( $href->{$field}{'type'} eq 'select-rate' ) {
1017 $html .= include('/elements/select-rate.html',
1018 'field' => $layer.'__'.$field,
1019 'curr_value' => $options{$field},
1020 map { $_ => $href->{$field}{$_} }
1021 grep { $_ !~ /^(name|type)$/ }
1022 keys %{ $href->{$field} }
1025 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
1028 $html .= ' MULTIPLE'
1029 if $href->{$field}{'type'} eq 'select_multiple';
1030 $html .= qq! NAME="${layer}__$field">!;
1032 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
1033 if exists($href->{$field}{'disable_empty'})
1034 && ! $href->{$field}{'disable_empty'};
1036 if ( $href->{$field}{'select_table'} ) {
1037 foreach my $record (
1038 qsearch( $href->{$field}{'select_table'},
1039 $href->{$field}{'select_hash'} )
1041 my $value = $record->getfield($href->{$field}{'select_key'});
1042 $html .= qq!<OPTION VALUE="$value"!.
1043 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
1047 '>'. $record->getfield($href->{$field}{'select_label'});
1049 } elsif ( $href->{$field}{'select_options'} ) {
1050 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
1051 my $label = $href->{$field}{'select_options'}{$key};
1052 $html .= qq!<OPTION VALUE="$key"!.
1053 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1061 $html .= '<font color="#ff0000">warning: '.
1062 "don't know how to retreive options for $field select field".
1065 $html .= '</SELECT>';
1067 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
1070 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
1072 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
1073 my $label = $href->{$field}{'options'}{$key};
1074 $html .= qq!$radio VALUE="$key"!.
1075 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1084 $html .= '</TD></TR>';
1086 $html .= '</TABLE>';
1088 $html .= include('/elements/hidden.html',
1089 field => $layer.'__OPTIONS',
1090 value => join(',', @fields)
1097 my %selectlayers = (
1099 options => [ keys %plan_labels ],
1100 labels => \%plan_labels,
1101 curr_value => $object->plan,
1102 layer_callback => $layer_callback,
1103 onchange => 'aux_planchanged(what);',
1107 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1108 '<SCRIPT TYPE="text/javascript">'.
1109 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
1112 # "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
1115 $return .= '</SCRIPT>';
1121 my %usage_class = map { ($_->classnum => $_->classname) }
1122 qsearch('usage_class', {});
1123 $usage_class{setup} = 'Setup';
1124 $usage_class{recur} = 'Recurring';
1126 my %taxproduct_fields = ();
1127 my $end_callback = sub {
1128 my( $cgi, $object, $fields, $opt ) = @_;
1130 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1132 if ( $object->pkgpart ) {
1133 foreach my $usage_class ( '', @taxproductnums ) {
1134 $tax_override{$usage_class} =
1135 join (",", map $_->taxclassnum,
1136 qsearch( 'part_pkg_taxoverride', {
1137 'pkgpart' => $object->pkgpart,
1138 'usage_class' => $usage_class,
1144 %taxproduct_fields =
1145 map { $_ => [ "taxproductnum_$_",
1146 { type => 'select-taxproduct',
1147 #label => "$usage_class{$_} tax product",
1150 { type => 'select-taxoverride' }
1155 $taxproduct_fields{'(default)'} =
1156 [ 'taxproductnum', { type => 'select-taxproduct',
1157 #label => 'Default tax product',
1159 'tax_override', { type => 'select-taxoverride' },
1163 my $taxproduct_values = sub {
1164 my ($cgi, $object, $flags) = @_;
1166 sub { my $layer = shift;
1167 my @fields = @{$taxproduct_fields{$layer}};
1170 my $field = shift @fields;
1172 $field =~ /^taxproductnum_\w+$/ &&
1173 push @values, ( $field => $options{"usage_$field"} );
1174 $field =~ /^tax_override_(\w+)$/ &&
1175 push @values, ( $field => $tax_override{$1} );
1176 $field =~ /^taxproductnum$/ &&
1177 push @values, ( $field => $object->taxproductnum );
1178 $field =~ /^tax_override$/ &&
1179 push @values, ( $field => $tax_override{''} );
1185 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1186 return({ @result });
1190 my $field_callback = sub {
1191 my ($cgi, $object, $fieldref) = @_;
1193 my $field = $fieldref->{field};
1194 if ($field eq 'taxproductnums') {
1195 $fieldref->{value} = join(',', @taxproductnums);
1196 } elsif ($field eq 'taxproduct_select') {
1197 $fieldref->{options} = [ '(default)', @taxproductnums ];
1198 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1199 map {( $_ => ($usage_class{$_} || $_) )}
1202 $fieldref->{layer_fields} = \%taxproduct_fields;
1203 $fieldref->{layer_values_callback} = $taxproduct_values;
1204 } elsif ($field eq 'taxproductnum') { # part_pkg-taxproduct, new style
1205 if ( !$taxproducts ) {
1206 # then make the widget go away
1207 $fieldref->{type} = 'hidden';
1212 my $discountnum_hashref = {
1214 'months' => { 'op' => '>', 'value' => 1 },