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 'fcc_ds0s' => 'Voice-grade equivalents',
72 'fcc_voip_class' => 'Category',
73 'delay_start' => 'Default delay (days)',
77 { field=>'clone', type=>'hidden',
78 curr_value_callback =>
79 sub { shift->param('clone') },
81 { field=>'pkgnum', type=>'hidden',
82 curr_value_callback =>
83 sub { shift->param('pkgnum') },
86 { field=>'custom', type=>'hidden' },
87 { field=>'family_pkgpart', type=>'hidden' },
88 { field=>'successor', type=>'hidden' },
90 { type => 'columnstart' },
98 {field=>'comment', type=>'text', size=>40 }, #32
99 { field => 'agentnum',
100 type => 'select-agent',
101 disable_empty => ! $acl_edit_global,
102 empty_label => '(global)',
103 onchange => 'agent_changed',
105 {field=>'classnum', type=>'select-pkg_class' },
106 ( $conf->exists('pkg-addon_classnum')
107 ? ( { field=>'addon_classnum',
108 type =>'select-pkg_class',
113 {field=>'disabled', type=>$disabled_type, value=>'Y'},
114 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
115 { field => 'start_on_hold',
120 { type => 'tablebreak-tr-title',
121 value => 'Pricing', #better name?
124 type => 'selectlayers-select',
125 options => [ keys %plan_labels ],
126 labels => \%plan_labels,
127 onchange => 'aux_planchanged(what);',
129 { field => 'setup_fee',
131 onchange => 'setup_changed',
133 { field => 'setup_show_zero',
136 disabled => sub { $setup_show_zero_disabled },
138 ( map { +{ field => "setup_fee_$_",
140 prefix=> currency_symbol($_, SYM_HTML),
144 sort $conf->config('currencies')
147 type => 'part_pkg_freq',
148 onchange => 'freq_changed',
150 { field => 'recur_fee',
152 disabled => sub { $recur_disabled },
153 onchange => 'recur_changed',
155 { field => 'recur_show_zero',
158 disabled => sub { $recur_show_zero_disabled },
160 ( map { +{ field => "recur_fee_$_",
162 prefix=> currency_symbol($_, SYM_HTML),
166 sort $conf->config('currencies')
172 #recurring fee (auto-disable)
174 { type => 'columnnext' },
176 {type=>'justtitle', value=>'Taxation' },
177 {field=>'setuptax', type=>'checkbox', value=>'Y'},
178 {field=>'recurtax', type=>'checkbox', value=>'Y'},
179 {field=>'taxclass', type=>'select-taxclass' },
180 { field => 'taxproductnums',
182 value => join(',', @taxproductnums),
184 { field => 'taxproduct_select',
185 type => 'selectlayers',
186 options => [ '(default)', @taxproductnums ],
187 curr_value => '(default)',
188 labels => { ( '(default)' => '(default)' ),
189 map {($_=>$usage_class{$_})}
192 layer_fields => \%taxproduct_fields,
193 layer_values_callback => $taxproduct_values,
194 layers_only => !$taxproducts,
195 cell_style => ( !$taxproducts
201 { type => 'tablebreak-tr-title',
202 value => 'Promotions', #better name?
204 { field=>'promo_code', type=>'text', size=>15 },
206 { type => 'tablebreak-tr-title',
207 value => 'Cost tracking', #better name?
210 ( $curuser->access_right('Edit package definition costs')
211 ? ( { field=>'setup_cost', type=>'money', },
212 { field=>'recur_cost', type=>'money', },
214 : ( { field=>'setup_cost', type=>'fixed', },
215 { field=>'recur_cost', type=>'fixed', },
219 ( $conf->exists('part_pkg-delay_start')
220 ? ( { type => 'tablebreak-tr-title',
221 value => 'Delayed start',
223 { field => 'delay_start',
224 type => 'text', size => 6 },
229 { type => 'columnnext' },
231 {type=>'justtitle', value=>'Agent (reseller) types' },
233 { field => 'agent_type',
234 type => 'select-agent_type',
235 disabled => ! $acl_edit_global,
236 element_etc => 'size="10"',
237 multiple => '1', #cause edit.html is dum
238 curr_value_callback => sub {
239 my($cgi, $object, $field) = @_;
240 #in the other callbacks..? hmm.
246 { type => 'tablebreak-tr-title',
247 value => 'FCC Form 477 information',
249 { field => 'fcc_options_string',
250 type => 'input-fcc_options',
251 curr_value_callback => sub {
252 my ($cgi, $part_pkg, $fref) = @_;
253 if ( $cgi->param('fcc_options_string') ) {
255 return $cgi->param('fcc_options_string');
258 %hash = $part_pkg->fcc_options
259 if ($part_pkg->pkgpart);
260 return encode_json(\%hash);
266 { type => 'tablebreak-tr-title',
267 value => 'External Links', #better name?
269 { field=>'agent_pkgpartid', type=>'text', size=>21 },
271 { type => 'tablebreak-tr-title',
272 value => 'Line-item revenue recogition', #better name?
274 { field=>'pay_weight', type=>'text', size=>6 },
275 { field=>'credit_weight', type=>'text', size=>6 },
277 { type => 'columnend' },
279 { type => 'tablebreak-tr-title',
280 value => 'Usage pricing add-ons', #better name? just 'Usage pricing' ? there's also CDR usage pricing, RADIUS usage pricing, etc :/
282 { 'field' => 'usagepricepart',
283 'type' => 'part_pkg_usageprice',
284 'o2m_table' => 'part_pkg_usageprice',
286 'm2_error_callback' => $usageprice_error_callback,
289 { 'type' => $report_option ? 'tablebreak-tr-title'
291 'value' => 'Optional report classes',
292 'field' => 'census_title',
294 { 'field' => 'report_option',
295 'type' => $report_option ? 'select-table'
297 'table' => 'part_pkg_report_option',
298 'name_col' => 'name',
299 'hashref' => { 'disabled' => '' },
303 { 'type' => 'tablebreak-tr-title',
304 'value' => 'Term discounts',
306 { 'field' => 'discountnum',
307 'type' => 'select-table',
308 'table' => 'discount',
309 'name_col' => 'name',
310 'hashref' => { %$discountnum_hashref },
311 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
312 'empty_label'=> 'Select discount',
313 'm2_label' => 'Offer discounts for longer terms',
314 'm2m_method' => 'part_pkg_discount',
315 'm2m_dstcol' => 'discountnum',
316 'm2_error_callback' => $discount_error_callback,
319 { 'type' => 'tablebreak-tr-title',
320 'value' => 'Pricing add-ons',
323 { 'field' => 'bill_dst_pkgpart',
324 'type' => 'select-part_pkg',
325 'extra_sql' => sub { $pkgpart
326 ? "AND pkgpart != $pkgpart"
329 'label_callback' => sub { shift->pkg_comment_only },
330 'm2_label' => 'Include line item(s) from package',
331 'm2m_method' => 'bill_part_pkg_link',
332 'm2m_dstcol' => 'dst_pkgpart',
333 'm2_error_callback' =>
334 &{$m2_error_callback_maker}('bill'),
335 'm2_fields' => [ { 'field' => 'hidden',
336 'type' => 'checkbox',
344 { type => 'tablebreak-tr-title',
347 { type => 'pkg_svc', },
349 { 'field' => 'svc_dst_pkgpart',
350 'label' => 'Also include services from package: ',
351 'type' => 'select-part_pkg',
352 'extra_sql' => sub { $pkgpart
353 ? "AND pkgpart != $pkgpart"
356 'label_callback' => sub { shift->pkg_comment_only },
357 'm2_label' => 'Include services of package: ',
358 'm2m_method' => 'svc_part_pkg_link',
359 'm2m_dstcol' => 'dst_pkgpart',
360 'm2_error_callback' =>
361 &{$m2_error_callback_maker}('svc'),
364 { 'type' => 'tablebreak-tr-title',
365 'value' => 'Supplemental packages',
367 'include_opt_callback' => sub {
368 'id' => 'show_supp_pkgs',
371 { 'field' => 'supp_dst_pkgpart',
372 'type' => 'select-part_pkg',
373 'label_callback' => sub { shift->pkg_comment_only },
374 'm2_label' => 'When ordering package, also order',
375 'm2m_method' => 'supp_part_pkg_link',
376 'm2m_dstcol' => 'dst_pkgpart',
377 'm2_error_callback' =>
378 &{$m2_error_callback_maker}('supp'),
381 { type => 'tablebreak-tr-title',
382 value => 'Price plan options',
389 my $curuser = $FS::CurrentUser::CurrentUser;
391 my $edit_global = 'Edit global package definitions';
392 my $acl_edit = $curuser->access_right('Edit package definitions');
393 my $acl_edit_global = $curuser->access_right($edit_global);
395 my $acl_edit_either = $acl_edit || $acl_edit_global;
397 my $begin_callback = sub {
398 my( $cgi, $fields, $opt ) = @_;
400 unless $acl_edit_either
401 || ( $cgi->param('pkgnum')
402 && $curuser->access_right('Customize customer package')
406 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
408 #arg. access rights for cloning are Hard.
409 # on the one hand we don't really want cloning (customizing a package) to fail
410 # for want of finding the source package in normal usage
411 # on the other hand, we don't want people using the clone link to be able to
413 my $agent_clone_extra_sql =
414 ' ( '. FS::part_pkg->curuser_pkgs_sql.
415 " OR ( part_pkg.custom = 'Y' ) ".
418 my $conf = new FS::Conf;
419 my $taxproducts = $conf->exists('enable_taxproducts');
421 my $fcc_opts = $conf->exists('part_pkg-show_fcc_options');
423 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
424 my %locale_labels = map {
425 ( $_ => 'Package -- '. FS::Locales->description($_) )
428 sort { $locale_labels{$a} cmp $locale_labels{$b} }
432 my %locale_field_labels = (
434 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
439 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
440 " WHERE disabled IS NULL OR disabled = '' ")
442 $sth->execute or die $sth->errstr;
443 my $report_option = $sth->fetchrow_arrayref->[0];
446 # - tr-part_pkg_freq: month_increments_only (from price plans)
448 # - test errors cloning
449 # - test custom pricing
450 # - move the selectlayer divs away from lame layer_callback
452 #my ($query) = $cgi->keywords;
457 my %tax_override = ();
459 my %taxproductnums = map { ($_->classnum => 1) }
460 qsearch('usage_class', { 'disabled' => '' });
461 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
464 my $recur_disabled = 1;
465 my $setup_show_zero_disabled = 0;
466 my $recur_show_zero_disabled = 1;
470 my $splice_locale_fields = sub {
471 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
474 my @locale_fields = (
476 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
477 my $pkg_value = $pkg_value_callback
478 ? $pkg_value_callback eq 'cgiparam'
479 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
480 : &$pkg_value_callback($_)
483 { field => 'pkgpartmsgnum'. $n,
485 value => $pkey_value,
487 { field => 'pkgpartmsgnum'. $n. '_locale',
491 { field => 'pkgpartmsgnum'. $n++. '_pkg',
502 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
506 my $error_callback = sub {
507 my($cgi, $object, $fields, $opt ) = @_;
509 (@agent_type) = $cgi->param('agent_type');
511 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
513 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
515 $recur_disabled = $cgi->param('freq') ? 0 : 1;
516 $recur_show_zero_disabled =
518 ? $cgi->param('recur_fee') > 0 ? 1 : 0
521 foreach ($cgi->param) {
522 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
524 $tax_override{''} = $cgi->param('tax_override');
525 $tax_override{$_} = $cgi->param('tax_override_$_')
526 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
528 #some false laziness w/process
529 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
531 my $options = $cgi->param($plan."__OPTIONS");
532 my @options = split(',', $options);
534 map { my $optionname = $_;
535 my $param = $plan."__$optionname";
536 my $value = join(', ', $cgi->param($param));
537 ( $optionname => $value );
541 $object->set($_ => scalar($cgi->param($_)) )
542 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
544 foreach my $currency ( $conf->config('currencies') ) {
545 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
546 foreach (qw( setup_fee recur_fee )) {
547 my $param = $_.'_'.$currency;
548 $object->set( $param, $cgi->param($param) );
552 $pkgpart = $object->pkgpart;
554 &$splice_locale_fields(
558 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
559 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
566 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
568 my $new_object_callback = sub {
569 my( $cgi, $hashref, $fields, $opt ) = @_;
571 my $part_pkg = FS::part_pkg->new( $hashref );
572 $part_pkg->set($_ => '0')
573 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
579 sub set_report_option {
580 my($cgi, $object, $fields ) = @_; #, $opt
582 my @report_option = ();
583 foreach ($object->options) {
584 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
585 /^report_option_(\d+)$/ && (push @report_option, $1);
587 foreach ($object->part_pkg_taxoverride) {
588 $taxproductnums{$_->usage_class} = 1
592 $cgi->param('report_option', join(',', @report_option));
593 foreach my $field ( @$fields ) {
595 ref($field) eq 'HASH' &&
597 $field->{field} eq 'report_option'
599 #$field->{curr_value} = join(',', @report_option);
600 $field->{value} = join(',', @report_option);
605 my $edit_callback = sub {
606 my( $cgi, $object, $fields, $opt ) = @_;
608 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
610 $recur_disabled = $object->freq ? 0 : 1;
612 $recur_show_zero_disabled =
614 ? $object->option('recur_fee') > 0 ? 1 : 0
618 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
620 set_report_option( $cgi, $object, $fields);
622 %options = $object->options;
624 $object->set($_ => $object->option($_, 1))
625 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
627 foreach my $currency ( $conf->config('currencies') ) {
628 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
629 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
630 foreach keys %part_pkg_currency;
633 $pkgpart = $object->pkgpart;
635 &$splice_locale_fields(
639 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
640 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
644 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
645 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
651 my $new_callback = sub {
652 my( $cgi, $object, $fields ) = @_;
654 my $conf = new FS::Conf;
656 if ( $conf->exists('agent_defaultpkg') ) {
657 @agent_type = map {$_->typenum} qsearch('agent_type', { 'disabled'=>'' });
660 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
662 &$splice_locale_fields($fields, '', '');
666 my $clone_callback = sub {
667 my( $cgi, $object, $fields, $opt ) = @_;
669 if ( $cgi->param('pkgnum') ) {
671 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
672 $object->agentnum( $cust_pkg->cust_main->agentnum );
674 $opt->{action} = 'Custom';
676 #my $part_pkg = $clone_part_pkg->clone;
677 #this is all clone does anyway
678 $object->custom('Y');
680 $object->disabled('Y');
682 } else { #when explicitly cloning, not customizing
685 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
689 set_report_option( $cgi, $object, $fields);
691 %options = $object->options;
693 $object->set($_ => $options{$_})
694 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
696 foreach my $currency ( $conf->config('currencies') ) {
697 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
698 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
699 foreach keys %part_pkg_currency;
702 $recur_disabled = $object->freq ? 0 : 1;
704 &$splice_locale_fields(
709 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
710 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
715 my $discount_error_callback = sub {
716 my( $cgi, $object ) = @_;
718 if ( /^discountnum(\d+)$/ &&
719 ( my $discountnum = $cgi->param("discountnum$1") ) )
721 new FS::part_pkg_discount {
722 'pkgpart' => $object->pkgpart,
723 'discountnum' => $discountnum,
732 my $usageprice_error_callback = sub {
733 my( $cgi, $object ) = @_;
735 if ( /^usagepricepart(\d+)_price$/
736 && $cgi->param("usagepricepart$1_price") )
738 new FS::part_pkg_usageprice {
739 'usagepricepart' => $cgi->param("usagepricepart$1"),
740 'pkgpart' => $object->pkgpart,
741 'price' => scalar($cgi->param("usagepricepart$1_price")),
743 'action' => scalar($cgi->param("usagepricepart$1_action")),
744 'target' => scalar($cgi->param("usagepricepart$1_target")),
745 'amount' => scalar($cgi->param("usagepricepart$1_amount")),
754 my $m2_error_callback_maker = sub {
755 my $link_type = shift; #yay closures
757 my( $cgi, $object ) = @_;
760 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
761 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
764 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
766 new FS::part_pkg_link {
767 'link_type' => $link_type,
768 'src_pkgpart' => $object->pkgpart,
769 'dst_pkgpart' => $dst,
780 my $javascript = <<'END';
781 <SCRIPT TYPE="text/javascript">
783 function freq_changed(what) {
784 var freq = what.options[what.selectedIndex].value;
787 what.form.recur_fee.disabled = true;
788 what.form.recur_fee.style.backgroundColor = '#dddddd';
789 what.form.recur_show_zero.disabled = true;
790 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
792 what.form.recur_fee.disabled = false;
793 what.form.recur_fee.style.backgroundColor = '#ffffff';
794 recur_changed( what.form.recur_fee );
795 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
800 function setup_changed(what) {
801 var setup = what.value;
802 if ( parseFloat(setup) == 0 ) {
803 what.form.setup_show_zero.disabled = false;
805 what.form.setup_show_zero.disabled = true;
809 function recur_changed(what) {
810 var recur = what.value;
811 if ( parseFloat(recur) == 0 ) {
812 what.form.recur_show_zero.disabled = false;
814 what.form.recur_show_zero.disabled = true;
818 function agent_changed(what) {
821 if ( what.type == 'select-one' ) {
822 agentnum = what.options[what.selectedIndex].value;
824 agentnum = what.value;
827 if ( agentnum == 0 ) {
828 what.form.agent_type.disabled = false;
829 //what.form.agent_type.style.backgroundColor = '#ffffff';
830 what.form.agent_type.style.visibility = '';
832 what.form.agent_type.disabled = true;
833 //what.form.agent_type.style.backgroundColor = '#dddddd';
834 what.form.agent_type.style.visibility = 'hidden';
839 function aux_planchanged(what) { //?
841 var plan = what.options[what.selectedIndex].value;
843 var term_table = document.getElementById('TableNumber8') // XXX NOT ROBUST
844 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
845 //term_table.disabled = false;
846 //term_table.style.visibility = '';
847 term_table.style.display = '';
849 //term_table.disabled = true;
850 //term_table.style.visibility = 'hidden';
851 term_table.style.display = 'none';
854 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
857 for ( var i=0; i < form.length; i++ ) {
858 if ( currency_regex.test(form[i].name) ) {
859 if ( plan == 'currency_fixed' ) {
860 form[i].disabled = false;
862 form[i].disabled = true;
869 // some magic to make "supplemental packages" less obvious
870 var supp_pkg_rows = [];
871 function show_supp_pkgs_click() {
872 supp_pkg_rows[0].style.display = '';
874 this.style.backgroundColor = '';
875 this.style.border = '';
876 this.style.padding = '';
879 function hide_supp_pkgs() {
880 var all_selects = document.getElementsByTagName('select');
881 for (var i=0; i < all_selects.length; i++) {
882 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
883 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
886 if ( supp_pkg_rows.length == 1 ) {
887 // there are none configured, so hide the row to create a new one
888 supp_pkg_rows[0].style.display = 'none';
889 var button = document.getElementById('show_supp_pkgs');
890 button.onclick = show_supp_pkgs_click;
891 button.style.backgroundColor = '#cccccc';
892 button.style.border = '1px solid #7e0079';
893 button.style.padding = '1px';
897 function finish_edit_fcc(id) {
899 show_fcc_options(id); // refresh the display
905 'Changing the setup or recurring fee will create a new package definition. '.
908 $javascript .= "function confirm_submit(f) {";
909 if ( $conf->exists('part_pkg-lineage') ) {
912 var fields = Array('setup_fee','recur_fee');
913 for(var i=0; i < fields.length; i++) {
914 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
915 return confirm('$warning');
925 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
927 tie my %plan_labels, 'Tie::IxHash',
928 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
931 my $html_bottom = sub {
934 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
936 my $layer_callback = sub {
939 my $html = ntable("#cccccc",2);
943 # <TD ALIGN="right">Recurring fee frequency </TD>
944 # <TD><SELECT NAME="freq">
947 #my @freq = keys %freq;
948 #@freq = grep { /^\d+$/ } @freq
949 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
950 #foreach my $freq ( @freq ) {
951 # $html .= qq(<OPTION VALUE="$freq");
952 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
953 # $html .= ">$freq{$freq}";
956 #$html .= '</SELECT></TD></TR>';
958 my $href = $plans{$layer}->{'fields'};
959 my @fields = exists($plans{$layer}->{'fieldorder'})
960 ? @{$plans{$layer}->{'fieldorder'}}
963 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
965 if(!exists($href->{$field})) {
967 warn "nonexistent part_pkg option: '$field'\n";
970 if ( exists($href->{$field}->{display_if}) ) {
971 my %args = ( 'plan' => $layer ); # anything else?
972 my $display = &{ $href->{$field}->{display_if} }(%args);
976 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
978 my $format = sub { shift };
979 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
981 #XXX these should use elements/ fields... (or this whole thing should
982 #just use layer_fields instead of layer_callback)
984 if ( ! exists($href->{$field}{'type'}) ) {
986 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
987 ( exists($options{$field})
988 ? &$format($options{$field})
989 : $href->{$field}{'default'} ).
992 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
994 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
995 ( exists($options{$field}) && $options{$field}
1000 } elsif ( $href->{$field}{'type'} eq 'select-rate' ) {
1002 $html .= include('/elements/select-rate.html',
1003 'field' => $layer.'__'.$field,
1004 'curr_value' => $options{$field},
1005 map { $_ => $href->{$field}{$_} }
1006 grep { $_ !~ /^(name|type)$/ }
1007 keys %{ $href->{$field} }
1010 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
1013 $html .= ' MULTIPLE'
1014 if $href->{$field}{'type'} eq 'select_multiple';
1015 $html .= qq! NAME="${layer}__$field">!;
1017 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
1018 if exists($href->{$field}{'disable_empty'})
1019 && ! $href->{$field}{'disable_empty'};
1021 if ( $href->{$field}{'select_table'} ) {
1022 foreach my $record (
1023 qsearch( $href->{$field}{'select_table'},
1024 $href->{$field}{'select_hash'} )
1026 my $value = $record->getfield($href->{$field}{'select_key'});
1027 $html .= qq!<OPTION VALUE="$value"!.
1028 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
1032 '>'. $record->getfield($href->{$field}{'select_label'});
1034 } elsif ( $href->{$field}{'select_options'} ) {
1035 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
1036 my $label = $href->{$field}{'select_options'}{$key};
1037 $html .= qq!<OPTION VALUE="$key"!.
1038 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1046 $html .= '<font color="#ff0000">warning: '.
1047 "don't know how to retreive options for $field select field".
1050 $html .= '</SELECT>';
1052 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
1055 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
1057 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
1058 my $label = $href->{$field}{'options'}{$key};
1059 $html .= qq!$radio VALUE="$key"!.
1060 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1069 $html .= '</TD></TR>';
1071 $html .= '</TABLE>';
1073 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
1074 join(',', keys %{ $href } ). '">';
1080 my %selectlayers = (
1082 options => [ keys %plan_labels ],
1083 labels => \%plan_labels,
1084 curr_value => $object->plan,
1085 layer_callback => $layer_callback,
1086 onchange => 'aux_planchanged(what);',
1090 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1091 '<SCRIPT TYPE="text/javascript">'.
1092 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
1095 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
1098 $return .= '</SCRIPT>';
1104 my %usage_class = map { ($_->classnum => $_->classname) }
1105 qsearch('usage_class', {});
1106 $usage_class{setup} = 'Setup';
1107 $usage_class{recur} = 'Recurring';
1109 my %taxproduct_fields = ();
1110 my $end_callback = sub {
1111 my( $cgi, $object, $fields, $opt ) = @_;
1113 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1115 if ( $object->pkgpart ) {
1116 foreach my $usage_class ( '', @taxproductnums ) {
1117 $tax_override{$usage_class} =
1118 join (",", map $_->taxclassnum,
1119 qsearch( 'part_pkg_taxoverride', {
1120 'pkgpart' => $object->pkgpart,
1121 'usage_class' => $usage_class,
1127 %taxproduct_fields =
1128 map { $_ => [ "taxproductnum_$_",
1129 { type => 'select-taxproduct',
1130 #label => "$usage_class{$_} tax product",
1133 { type => 'select-taxoverride' }
1138 $taxproduct_fields{'(default)'} =
1139 [ 'taxproductnum', { type => 'select-taxproduct',
1140 #label => 'Default tax product',
1142 'tax_override', { type => 'select-taxoverride' },
1146 my $taxproduct_values = sub {
1147 my ($cgi, $object, $flags) = @_;
1149 sub { my $layer = shift;
1150 my @fields = @{$taxproduct_fields{$layer}};
1153 my $field = shift @fields;
1155 $field =~ /^taxproductnum_\w+$/ &&
1156 push @values, ( $field => $options{"usage_$field"} );
1157 $field =~ /^tax_override_(\w+)$/ &&
1158 push @values, ( $field => $tax_override{$1} );
1159 $field =~ /^taxproductnum$/ &&
1160 push @values, ( $field => $object->taxproductnum );
1161 $field =~ /^tax_override$/ &&
1162 push @values, ( $field => $tax_override{''} );
1168 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1169 return({ @result });
1173 my $field_callback = sub {
1174 my ($cgi, $object, $fieldref) = @_;
1176 my $field = $fieldref->{field};
1177 if ($field eq 'taxproductnums') {
1178 $fieldref->{value} = join(',', @taxproductnums);
1179 } elsif ($field eq 'taxproduct_select') {
1180 $fieldref->{options} = [ '(default)', @taxproductnums ];
1181 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1182 map {( $_ => ($usage_class{$_} || $_) )}
1185 $fieldref->{layer_fields} = \%taxproduct_fields;
1186 $fieldref->{layer_values_callback} = $taxproduct_values;
1190 my $discountnum_hashref = {
1192 'months' => { 'op' => '>', 'value' => 1 },