1 <% include( 'elements/edit.html',
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);
18 'begin_callback' => $begin_callback,
19 'end_callback' => $end_callback,
20 'new_hashref_callback' => $new_hashref_callback,
21 'new_object_callback' => $new_object_callback,
22 'new_callback' => $new_callback,
23 'clone_callback' => $clone_callback,
24 'edit_callback' => $edit_callback,
25 'error_callback' => $error_callback,
26 'field_callback' => $field_callback,
28 'onsubmit' => 'confirm_submit',
31 'pkgpart' => 'Package Definition',
34 'comment' => 'Comment (customer-hidden)',
35 'classnum' => 'Package class',
36 'addon_classnum' => 'Restrict additional orders to package class',
37 'promo_code' => 'Promotional code',
38 'freq' => 'Recurring fee frequency',
39 'setuptax' => 'Setup fee tax exempt',
40 'recurtax' => 'Recurring fee tax exempt',
41 'taxclass' => 'Tax class',
42 'taxproduct_select'=> 'Tax products',
43 'plan' => 'Price plan',
44 'disabled' => 'Disable new orders',
45 'disable_line_item_date_ranges' => 'Disable line item date ranges',
46 'start_on_hold' => 'Start on hold',
47 'setup_cost' => 'Setup cost',
48 'recur_cost' => 'Recur cost',
49 'pay_weight' => 'Payment weight',
50 'credit_weight' => 'Credit weight',
51 'agent_pkgpartid' => 'External ID',
52 'agentnum' => 'Agent',
53 'agent_type' => ' ', #just its title headingn is fine
54 'setup_fee' => 'Setup fee',
55 'setup_show_zero' => 'Show zero setup',
56 'recur_fee' => 'Recurring fee',
57 'recur_show_zero' => 'Show zero recurring',
58 'discountnum' => 'Offer discounts for longer terms',
59 'bill_dst_pkgpart' => 'Include line item(s) from package',
60 'svc_dst_pkgpart' => 'Include services of package',
61 'supp_dst_pkgpart' => 'When ordering package, also order',
62 'report_option' => 'Report classes',
63 'fcc_ds0s' => 'Voice-grade equivalents',
64 'fcc_voip_class' => 'Category',
65 'delay_start' => 'Default delay (days)',
69 { field=>'clone', type=>'hidden',
70 curr_value_callback =>
71 sub { shift->param('clone') },
73 { field=>'pkgnum', type=>'hidden',
74 curr_value_callback =>
75 sub { shift->param('pkgnum') },
78 { field=>'custom', type=>'hidden' },
79 { field=>'family_pkgpart', type=>'hidden' },
80 { field=>'successor', type=>'hidden' },
82 { type => 'columnstart' },
90 {field=>'comment', type=>'text', size=>40 }, #32
91 { field => 'agentnum',
92 type => 'select-agent',
93 disable_empty => ! $acl_edit_global,
94 empty_label => '(global)',
95 onchange => 'agent_changed',
97 {field=>'classnum', type=>'select-pkg_class' },
98 ( $conf->exists('pkg-addon_classnum')
99 ? ( { field=>'addon_classnum',
100 type =>'select-pkg_class',
105 {field=>'disabled', type=>$disabled_type, value=>'Y'},
106 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
107 { field => 'start_on_hold',
112 { type => 'tablebreak-tr-title',
113 value => 'Pricing', #better name?
116 type => 'selectlayers-select',
117 options => [ keys %plan_labels ],
118 labels => \%plan_labels,
119 onchange => 'aux_planchanged(what);',
121 { field => 'setup_fee',
123 onchange => 'setup_changed',
125 { field => 'setup_show_zero',
128 disabled => sub { $setup_show_zero_disabled },
131 type => 'part_pkg_freq',
132 onchange => 'freq_changed',
134 { field => 'recur_fee',
136 disabled => sub { $recur_disabled },
137 onchange => 'recur_changed',
140 { field => 'recur_show_zero',
143 disabled => sub { $recur_show_zero_disabled },
149 #recurring fee (auto-disable)
151 { type => 'columnnext' },
153 {type=>'justtitle', value=>'Taxation' },
154 {field=>'setuptax', type=>'checkbox', value=>'Y'},
155 {field=>'recurtax', type=>'checkbox', value=>'Y'},
156 {field=>'taxclass', type=>'select-taxclass' },
157 { field => 'taxproductnums',
159 value => join(',', @taxproductnums),
161 { field => 'taxproduct_select',
162 type => 'selectlayers',
163 options => [ '(default)', @taxproductnums ],
164 curr_value => '(default)',
165 labels => { ( '(default)' => '(default)' ),
166 map {($_=>$usage_class{$_})}
169 layer_fields => \%taxproduct_fields,
170 layer_values_callback => $taxproduct_values,
171 layers_only => !$taxproducts,
172 cell_style => ( !$taxproducts
178 { type => 'tablebreak-tr-title',
179 value => 'Promotions', #better name?
181 { field=>'promo_code', type=>'text', size=>15 },
183 { type => 'tablebreak-tr-title',
184 value => 'Cost tracking', #better name?
187 ( $curuser->access_right('Edit package definition costs')
188 ? ( { field=>'setup_cost', type=>'money', },
189 { field=>'recur_cost', type=>'money', },
191 : ( { field=>'setup_cost', type=>'fixed', },
192 { field=>'recur_cost', type=>'fixed', },
196 ( $conf->exists('part_pkg-delay_start')
197 ? ( { type => 'tablebreak-tr-title',
198 value => 'Delayed start',
200 { field => 'delay_start',
201 type => 'text', size => 6 },
206 { type => 'columnnext' },
208 {type=>'justtitle', value=>'Agent (reseller) types' },
210 { field => 'agent_type',
211 type => 'select-agent_type',
212 disabled => ! $acl_edit_global,
213 element_etc => 'size="10"',
214 multiple => '1', #cause edit.html is dum
215 curr_value_callback => sub {
216 my($cgi, $object, $field) = @_;
217 #in the other callbacks..? hmm.
222 { type => 'tablebreak-tr-title',
223 value => 'External Links', #better name?
225 { field=>'agent_pkgpartid', type=>'text', size=>21 },
227 { type => 'tablebreak-tr-title',
228 value => 'Line-item revenue recogition', #better name?
230 { field=>'pay_weight', type=>'text', size=>6 },
231 { field=>'credit_weight', type=>'text', size=>6 },
233 { type => 'tablebreak-tr-title',
234 value => 'FCC Form 477 information',
236 { field => 'fcc_options_string',
237 type => 'input-fcc_options',
238 curr_value_callback => sub {
239 my ($cgi, $part_pkg, $fref) = @_;
240 if ( $cgi->param('fcc_options_string') ) {
242 return $cgi->param('fcc_options_string');
245 %hash = $part_pkg->fcc_options
246 if ($part_pkg->pkgpart);
247 return encode_json(\%hash);
252 { type => 'columnend' },
254 { 'type' => $report_option ? 'tablebreak-tr-title'
256 'value' => 'Optional report classes',
257 'field' => 'census_title',
259 { 'field' => 'report_option',
260 'type' => $report_option ? 'select-table'
262 'table' => 'part_pkg_report_option',
263 'name_col' => 'name',
264 'hashref' => { 'disabled' => '' },
268 { 'type' => 'tablebreak-tr-title',
269 'value' => 'Term discounts',
271 { 'field' => 'discountnum',
272 'type' => 'select-table',
273 'table' => 'discount',
274 'name_col' => 'name',
275 'hashref' => { %$discountnum_hashref },
276 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
277 'empty_label'=> 'Select discount',
278 'm2_label' => 'Offer discounts for longer terms',
279 'm2m_method' => 'part_pkg_discount',
280 'm2m_dstcol' => 'discountnum',
281 'm2_error_callback' => $discount_error_callback,
284 { 'type' => 'tablebreak-tr-title',
285 'value' => 'Pricing add-ons',
288 { 'field' => 'bill_dst_pkgpart',
289 'type' => 'select-part_pkg',
290 'extra_sql' => sub { $pkgpart
291 ? "AND pkgpart != $pkgpart"
294 + 'label_callback' => sub { shift->pkg_comment_only },
295 'm2_label' => 'Include line item(s) from package',
296 'm2m_method' => 'bill_part_pkg_link',
297 'm2m_dstcol' => 'dst_pkgpart',
298 'm2_error_callback' =>
299 &{$m2_error_callback_maker}('bill'),
300 'm2_fields' => [ { 'field' => 'hidden',
301 'type' => 'checkbox',
309 { type => 'tablebreak-tr-title',
312 { type => 'pkg_svc', },
314 { 'field' => 'svc_dst_pkgpart',
315 'label' => 'Also include services from package: ',
316 'type' => 'select-part_pkg',
317 'extra_sql' => sub { $pkgpart
318 ? "AND pkgpart != $pkgpart"
321 + 'label_callback' => sub { shift->pkg_comment_only },
322 'm2_label' => 'Include services of package: ',
323 'm2m_method' => 'svc_part_pkg_link',
324 'm2m_dstcol' => 'dst_pkgpart',
325 'm2_error_callback' =>
326 &{$m2_error_callback_maker}('svc'),
329 { 'type' => 'tablebreak-tr-title',
330 'value' => 'Supplemental packages',
332 'include_opt_callback' => sub {
333 'id' => 'show_supp_pkgs',
336 { 'field' => 'supp_dst_pkgpart',
337 'type' => 'select-part_pkg',
338 + 'label_callback' => sub { shift->pkg_comment_only },
339 'm2_label' => 'When ordering package, also order',
340 'm2m_method' => 'supp_part_pkg_link',
341 'm2m_dstcol' => 'dst_pkgpart',
342 'm2_error_callback' =>
343 &{$m2_error_callback_maker}('supp'),
346 { type => 'tablebreak-tr-title',
347 value => 'Price plan options',
356 my $curuser = $FS::CurrentUser::CurrentUser;
358 my $edit_global = 'Edit global package definitions';
359 my $acl_edit = $curuser->access_right('Edit package definitions');
360 my $acl_edit_global = $curuser->access_right($edit_global);
362 my $acl_edit_either = $acl_edit || $acl_edit_global;
364 my $begin_callback = sub {
365 my( $cgi, $fields, $opt ) = @_;
367 unless $acl_edit_either
368 || ( $cgi->param('pkgnum')
369 && $curuser->access_right('Customize customer package')
373 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
375 #arg. access rights for cloning are Hard.
376 # on the one hand we don't really want cloning (customizing a package) to fail
377 # for want of finding the source package in normal usage
378 # on the other hand, we don't want people using the clone link to be able to
380 my $agent_clone_extra_sql =
381 ' ( '. FS::part_pkg->curuser_pkgs_sql.
382 " OR ( part_pkg.custom = 'Y' ) ".
385 my $conf = new FS::Conf;
386 my $taxproducts = $conf->exists('enable_taxproducts');
388 my $fcc_opts = $conf->exists('part_pkg-show_fcc_options');
390 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
391 my %locale_labels = map {
392 ( $_ => 'Package -- '. FS::Locales->description($_) )
395 sort { $locale_labels{$a} cmp $locale_labels{$b} }
399 my %locale_field_labels = (
401 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
406 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
407 " WHERE disabled IS NULL OR disabled = '' ")
409 $sth->execute or die $sth->errstr;
410 my $report_option = $sth->fetchrow_arrayref->[0];
413 # - tr-part_pkg_freq: month_increments_only (from price plans)
415 # - test errors cloning
416 # - test custom pricing
417 # - move the selectlayer divs away from lame layer_callback
419 #my ($query) = $cgi->keywords;
424 my %tax_override = ();
426 my %taxproductnums = map { ($_->classnum => 1) }
427 qsearch('usage_class', { 'disabled' => '' });
428 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
431 my $recur_disabled = 1;
432 my $setup_show_zero_disabled = 0;
433 my $recur_show_zero_disabled = 1;
437 my $splice_locale_fields = sub {
438 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
441 my @locale_fields = (
443 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
444 my $pkg_value = $pkg_value_callback
445 ? $pkg_value_callback eq 'cgiparam'
446 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
447 : &$pkg_value_callback($_)
450 { field => 'pkgpartmsgnum'. $n,
452 value => $pkey_value,
454 { field => 'pkgpartmsgnum'. $n. '_locale',
458 { field => 'pkgpartmsgnum'. $n++. '_pkg',
469 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
473 my $error_callback = sub {
474 my($cgi, $object, $fields, $opt ) = @_;
476 (@agent_type) = $cgi->param('agent_type');
478 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
480 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
482 $recur_disabled = $cgi->param('freq') ? 0 : 1;
483 $recur_show_zero_disabled =
485 ? $cgi->param('recur_fee') > 0 ? 1 : 0
488 foreach ($cgi->param) {
489 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
491 $tax_override{''} = $cgi->param('tax_override');
492 $tax_override{$_} = $cgi->param('tax_override_$_')
493 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
495 #some false laziness w/process
496 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
498 my $options = $cgi->param($plan."__OPTIONS");
499 my @options = split(',', $options);
501 map { my $optionname = $_;
502 my $param = $plan."__$optionname";
503 my $value = join(', ', $cgi->param($param));
504 ( $optionname => $value );
508 $object->set($_ => scalar($cgi->param($_)) )
509 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
511 $pkgpart = $object->pkgpart;
513 &$splice_locale_fields(
517 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
518 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
525 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
527 my $new_object_callback = sub {
528 my( $cgi, $hashref, $fields, $opt ) = @_;
530 my $part_pkg = FS::part_pkg->new( $hashref );
531 $part_pkg->set($_ => '0')
532 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
538 sub set_report_option {
539 my($cgi, $object, $fields ) = @_; #, $opt
541 my @report_option = ();
542 foreach ($object->options) {
543 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
544 /^report_option_(\d+)$/ && (push @report_option, $1);
546 foreach ($object->part_pkg_taxoverride) {
547 $taxproductnums{$_->usage_class} = 1
551 $cgi->param('report_option', join(',', @report_option));
552 foreach my $field ( @$fields ) {
554 ref($field) eq 'HASH' &&
556 $field->{field} eq 'report_option'
558 #$field->{curr_value} = join(',', @report_option);
559 $field->{value} = join(',', @report_option);
564 my $edit_callback = sub {
565 my( $cgi, $object, $fields, $opt ) = @_;
567 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
569 $recur_disabled = $object->freq ? 0 : 1;
571 $recur_show_zero_disabled =
573 ? $object->option('recur_fee') > 0 ? 1 : 0
577 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
579 set_report_option( $cgi, $object, $fields);
581 %options = $object->options;
583 $object->set($_ => $object->option($_, 1))
584 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
586 $pkgpart = $object->pkgpart;
588 &$splice_locale_fields(
592 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
593 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
597 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
598 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
604 my $new_callback = sub {
605 my( $cgi, $object, $fields ) = @_;
607 my $conf = new FS::Conf;
609 if ( $conf->exists('agent_defaultpkg') ) {
610 @agent_type = map {$_->typenum} qsearch('agent_type', { 'disabled'=>'' });
613 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
615 &$splice_locale_fields($fields, '', '');
619 my $clone_callback = sub {
620 my( $cgi, $object, $fields, $opt ) = @_;
622 if ( $cgi->param('pkgnum') ) {
624 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
625 $object->agentnum( $cust_pkg->cust_main->agentnum );
627 $opt->{action} = 'Custom';
629 #my $part_pkg = $clone_part_pkg->clone;
630 #this is all clone does anyway
631 $object->custom('Y');
633 $object->disabled('Y');
635 } else { #when explicitly cloning, not customizing
638 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
642 set_report_option( $cgi, $object, $fields);
644 %options = $object->options;
646 $object->set($_ => $options{$_})
647 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
649 $recur_disabled = $object->freq ? 0 : 1;
651 &$splice_locale_fields(
656 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
657 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
662 my $discount_error_callback = sub {
663 my( $cgi, $object ) = @_;
665 if ( /^discountnum(\d+)$/ &&
666 ( my $discountnum = $cgi->param("discountnum$1") ) )
668 new FS::part_pkg_discount {
669 'pkgpart' => $object->pkgpart,
670 'discountnum' => $discountnum,
679 my $m2_error_callback_maker = sub {
680 my $link_type = shift; #yay closures
682 my( $cgi, $object ) = @_;
685 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
686 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
689 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
691 new FS::part_pkg_link {
692 'link_type' => $link_type,
693 'src_pkgpart' => $object->pkgpart,
694 'dst_pkgpart' => $dst,
705 my $javascript = <<'END';
706 <SCRIPT TYPE="text/javascript">
708 function freq_changed(what) {
709 var freq = what.options[what.selectedIndex].value;
712 what.form.recur_fee.disabled = true;
713 what.form.recur_fee.style.backgroundColor = '#dddddd';
714 what.form.recur_show_zero.disabled = true;
715 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
717 what.form.recur_fee.disabled = false;
718 what.form.recur_fee.style.backgroundColor = '#ffffff';
719 recur_changed( what.form.recur_fee );
720 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
725 function setup_changed(what) {
726 var setup = what.value;
727 if ( parseFloat(setup) == 0 ) {
728 what.form.setup_show_zero.disabled = false;
730 what.form.setup_show_zero.disabled = true;
734 function recur_changed(what) {
735 var recur = what.value;
736 if ( parseFloat(recur) == 0 ) {
737 what.form.recur_show_zero.disabled = false;
739 what.form.recur_show_zero.disabled = true;
743 function agent_changed(what) {
746 if ( what.type == 'select-one' ) {
747 agentnum = what.options[what.selectedIndex].value;
749 agentnum = what.value;
752 if ( agentnum == 0 ) {
753 what.form.agent_type.disabled = false;
754 //what.form.agent_type.style.backgroundColor = '#ffffff';
755 what.form.agent_type.style.visibility = '';
757 what.form.agent_type.disabled = true;
758 //what.form.agent_type.style.backgroundColor = '#dddddd';
759 what.form.agent_type.style.visibility = 'hidden';
764 function aux_planchanged(what) { //?
766 var plan = what.options[what.selectedIndex].value;
767 var table = document.getElementById('TableNumber6') // XXX NOT ROBUST
769 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
770 //table.disabled = false;
771 table.style.visibility = '';
773 //table.disabled = true;
774 table.style.visibility = 'hidden';
779 // some magic to make "supplemental packages" less obvious
780 var supp_pkg_rows = [];
781 function show_supp_pkgs_click() {
782 supp_pkg_rows[0].style.display = '';
784 this.style.backgroundColor = '';
785 this.style.border = '';
786 this.style.padding = '';
789 function hide_supp_pkgs() {
790 var all_selects = document.getElementsByTagName('select');
791 for (var i=0; i < all_selects.length; i++) {
792 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
793 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
796 if ( supp_pkg_rows.length == 1 ) {
797 // there are none configured, so hide the row to create a new one
798 supp_pkg_rows[0].style.display = 'none';
799 var button = document.getElementById('show_supp_pkgs');
800 button.onclick = show_supp_pkgs_click;
801 button.style.backgroundColor = '#cccccc';
802 button.style.border = '1px solid #7e0079';
803 button.style.padding = '1px';
807 function finish_edit_fcc(id) {
809 show_fcc_options(id); // refresh the display
815 'Changing the setup or recurring fee will create a new package definition. '.
818 $javascript .= "function confirm_submit(f) {";
819 if ( $conf->exists('part_pkg-lineage') ) {
822 var fields = Array('setup_fee','recur_fee');
823 for(var i=0; i < fields.length; i++) {
824 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
825 return confirm('$warning');
835 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
837 tie my %plan_labels, 'Tie::IxHash',
838 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
841 my $html_bottom = sub {
844 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
846 my $layer_callback = sub {
849 my $html = ntable("#cccccc",2);
853 # <TD ALIGN="right">Recurring fee frequency </TD>
854 # <TD><SELECT NAME="freq">
857 #my @freq = keys %freq;
858 #@freq = grep { /^\d+$/ } @freq
859 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
860 #foreach my $freq ( @freq ) {
861 # $html .= qq(<OPTION VALUE="$freq");
862 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
863 # $html .= ">$freq{$freq}";
866 #$html .= '</SELECT></TD></TR>';
868 my $href = $plans{$layer}->{'fields'};
869 my @fields = exists($plans{$layer}->{'fieldorder'})
870 ? @{$plans{$layer}->{'fieldorder'}}
873 # hash of dependencies for each of the Pricing Plan fields.
874 # make sure NOT to use double-quotes inside the 'msg' value.
876 'unused_credit_suspend' => {
877 'msg' => q|You must set the 'suspend_credit_type' option in Configuration->Settings to gain access to this option.|,
879 my $conf = new FS::conf;
880 my @conf_info = qsearch('conf', { 'name' => 'suspend_credit_type' } );
881 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
885 'unused_credit_cancel' => {
886 'msg' => q|You must set the 'cancel_credit_type' option in Configuration->Settings to gain access to this option.|,
888 my $conf = new FS::conf;
889 my @conf_info = qsearch('conf', { 'name' => 'cancel_credit_type' } );
890 return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
896 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
898 if(!exists($href->{$field})) {
900 warn "nonexistent part_pkg option: '$field'\n";
903 if ( exists($href->{$field}->{display_if}) ) {
904 my %args = ( 'plan' => $layer ); # anything else?
905 my $display = &{ $href->{$field}->{display_if} }(%args);
909 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
911 my $format = sub { shift };
912 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
914 #XXX these should use elements/ fields... (or this whole thing should
915 #just use layer_fields instead of layer_callback)
917 if (exists($dependencies->{$field}) && !$dependencies->{$field}{'are_met'}()) {
918 $html .= q!<span title="!.$dependencies->{$field}{'msg'}.q!">N/A</span>!;
920 } elsif ( ! exists($href->{$field}{'type'}) ) {
922 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
923 ( exists($options{$field})
924 ? &$format($options{$field})
925 : $href->{$field}{'default'} ).
928 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
930 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
931 ( exists($options{$field}) && $options{$field}
936 } elsif ( $href->{$field}{'type'} eq 'select-rate' ) {
938 $html .= include('/elements/select-rate.html',
939 'field' => $layer.'__'.$field,
940 'curr_value' => $options{$field},
941 map { $_ => $href->{$field}{$_} }
942 grep { $_ !~ /^(name|type)$/ }
943 keys %{ $href->{$field} }
946 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
950 if $href->{$field}{'type'} eq 'select_multiple';
951 $html .= qq! NAME="${layer}__$field">!;
953 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
954 if exists($href->{$field}{'disable_empty'})
955 && ! $href->{$field}{'disable_empty'};
957 if ( $href->{$field}{'select_table'} ) {
959 qsearch( $href->{$field}{'select_table'},
960 $href->{$field}{'select_hash'} )
962 my $value = $record->getfield($href->{$field}{'select_key'});
963 $html .= qq!<OPTION VALUE="$value"!.
964 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
968 '>'. $record->getfield($href->{$field}{'select_label'});
970 } elsif ( $href->{$field}{'select_options'} ) {
971 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
972 my $label = $href->{$field}{'select_options'}{$key};
973 $html .= qq!<OPTION VALUE="$key"!.
974 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
982 $html .= '<font color="#ff0000">warning: '.
983 "don't know how to retreive options for $field select field".
986 $html .= '</SELECT>';
988 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
991 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
993 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
994 my $label = $href->{$field}{'options'}{$key};
995 $html .= qq!$radio VALUE="$key"!.
996 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1005 $html .= '</TD></TR>';
1007 $html .= '</TABLE>';
1009 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
1010 join(',', keys %{ $href } ). '">';
1016 my %selectlayers = (
1018 options => [ keys %plan_labels ],
1019 labels => \%plan_labels,
1020 curr_value => $object->plan,
1021 layer_callback => $layer_callback,
1022 onchange => 'aux_planchanged(what);',
1026 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1027 '<SCRIPT TYPE="text/javascript">'.
1028 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
1031 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
1034 $return .= '</SCRIPT>';
1040 my %usage_class = map { ($_->classnum => $_->classname) }
1041 qsearch('usage_class', {});
1042 $usage_class{setup} = 'Setup';
1043 $usage_class{recur} = 'Recurring';
1045 my %taxproduct_fields = ();
1046 my $end_callback = sub {
1047 my( $cgi, $object, $fields, $opt ) = @_;
1049 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1051 if ( $object->pkgpart ) {
1052 foreach my $usage_class ( '', @taxproductnums ) {
1053 $tax_override{$usage_class} =
1054 join (",", map $_->taxclassnum,
1055 qsearch( 'part_pkg_taxoverride', {
1056 'pkgpart' => $object->pkgpart,
1057 'usage_class' => $usage_class,
1063 %taxproduct_fields =
1064 map { $_ => [ "taxproductnum_$_",
1065 { type => 'select-taxproduct',
1066 #label => "$usage_class{$_} tax product",
1069 { type => 'select-taxoverride' }
1074 $taxproduct_fields{'(default)'} =
1075 [ 'taxproductnum', { type => 'select-taxproduct',
1076 #label => 'Default tax product',
1078 'tax_override', { type => 'select-taxoverride' },
1082 my $taxproduct_values = sub {
1083 my ($cgi, $object, $flags) = @_;
1085 sub { my $layer = shift;
1086 my @fields = @{$taxproduct_fields{$layer}};
1089 my $field = shift @fields;
1091 $field =~ /^taxproductnum_\w+$/ &&
1092 push @values, ( $field => $options{"usage_$field"} );
1093 $field =~ /^tax_override_(\w+)$/ &&
1094 push @values, ( $field => $tax_override{$1} );
1095 $field =~ /^taxproductnum$/ &&
1096 push @values, ( $field => $object->taxproductnum );
1097 $field =~ /^tax_override$/ &&
1098 push @values, ( $field => $tax_override{''} );
1104 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1105 return({ @result });
1109 my $field_callback = sub {
1110 my ($cgi, $object, $fieldref) = @_;
1112 my $field = $fieldref->{field};
1113 if ($field eq 'taxproductnums') {
1114 $fieldref->{value} = join(',', @taxproductnums);
1115 } elsif ($field eq 'taxproduct_select') {
1116 $fieldref->{options} = [ '(default)', @taxproductnums ];
1117 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1118 map {( $_ => ($usage_class{$_} || $_) )}
1121 $fieldref->{layer_fields} = \%taxproduct_fields;
1122 $fieldref->{layer_values_callback} = $taxproduct_values;
1126 my $discountnum_hashref = {
1128 'months' => { 'op' => '>', 'value' => 1 },