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 '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 'setup_fee' => 'Setup fee',
54 'setup_show_zero' => 'Show zero setup',
55 'recur_fee' => 'Recurring fee',
56 'recur_show_zero' => 'Show zero recurring',
57 ( map { ( "setup_fee_$_" => "Setup fee $_",
58 "recur_fee_$_" => "Recurring fee $_",
61 $conf->config('currencies')
63 'usagepricepart' => ' ',
64 'discountnum' => 'Offer discounts for longer terms',
65 'bill_dst_pkgpart' => 'Include line item(s) from package',
66 'svc_dst_pkgpart' => 'Include services of package',
67 'supp_dst_pkgpart' => 'When ordering package, also order',
68 'report_option' => 'Report classes',
69 'fcc_ds0s' => 'Voice-grade equivalents',
70 'fcc_voip_class' => 'Category',
71 'delay_start' => 'Default delay (days)',
75 { field=>'clone', type=>'hidden',
76 curr_value_callback =>
77 sub { shift->param('clone') },
79 { field=>'pkgnum', type=>'hidden',
80 curr_value_callback =>
81 sub { shift->param('pkgnum') },
84 { field=>'custom', type=>'hidden' },
85 { field=>'family_pkgpart', type=>'hidden' },
86 { field=>'successor', type=>'hidden' },
88 { type => 'columnstart' },
96 {field=>'comment', type=>'text', size=>40 }, #32
97 { field => 'agentnum',
98 type => 'select-agent',
99 disable_empty => ! $acl_edit_global,
100 empty_label => '(global)',
101 onchange => 'agent_changed',
103 {field=>'classnum', type=>'select-pkg_class' },
104 ( $conf->exists('pkg-addon_classnum')
105 ? ( { field=>'addon_classnum',
106 type =>'select-pkg_class',
111 {field=>'disabled', type=>$disabled_type, value=>'Y'},
112 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
114 { type => 'tablebreak-tr-title',
115 value => 'Pricing', #better name?
118 type => 'selectlayers-select',
119 options => [ keys %plan_labels ],
120 labels => \%plan_labels,
121 onchange => 'aux_planchanged(what);',
123 { field => 'setup_fee',
125 onchange => 'setup_changed',
127 { field => 'setup_show_zero',
130 disabled => sub { $setup_show_zero_disabled },
132 ( map { +{ field => "setup_fee_$_",
134 prefix=> currency_symbol($_, SYM_HTML),
138 sort $conf->config('currencies')
141 type => 'part_pkg_freq',
142 onchange => 'freq_changed',
144 { field => 'recur_fee',
146 disabled => sub { $recur_disabled },
147 onchange => 'recur_changed',
149 { field => 'recur_show_zero',
152 disabled => sub { $recur_show_zero_disabled },
154 ( map { +{ field => "recur_fee_$_",
156 prefix=> currency_symbol($_, SYM_HTML),
160 sort $conf->config('currencies')
166 #recurring fee (auto-disable)
168 { type => 'columnnext' },
170 {type=>'justtitle', value=>'Taxation' },
171 {field=>'setuptax', type=>'checkbox', value=>'Y'},
172 {field=>'recurtax', type=>'checkbox', value=>'Y'},
173 {field=>'taxclass', type=>'select-taxclass' },
174 { field => 'taxproductnums',
176 value => join(',', @taxproductnums),
178 { field => 'taxproduct_select',
179 type => 'selectlayers',
180 options => [ '(default)', @taxproductnums ],
181 curr_value => '(default)',
182 labels => { ( '(default)' => '(default)' ),
183 map {($_=>$usage_class{$_})}
186 layer_fields => \%taxproduct_fields,
187 layer_values_callback => $taxproduct_values,
188 layers_only => !$taxproducts,
189 cell_style => ( !$taxproducts
195 { type => 'tablebreak-tr-title',
196 value => 'Promotions', #better name?
198 { field=>'promo_code', type=>'text', size=>15 },
200 { type => 'tablebreak-tr-title',
201 value => 'Cost tracking', #better name?
204 ( $curuser->access_right('Edit package definition costs')
205 ? ( { field=>'setup_cost', type=>'money', },
206 { field=>'recur_cost', type=>'money', },
208 : ( { field=>'setup_cost', type=>'fixed', },
209 { field=>'recur_cost', type=>'fixed', },
213 ( $conf->exists('part_pkg-delay_start')
214 ? ( { type => 'tablebreak-tr-title',
215 value => 'Delayed start',
217 { field => 'delay_start',
218 type => 'text', size => 6 },
223 { type => 'columnnext' },
225 { field => 'agent_type',
226 type => 'select-agent_types',
227 disabled => ! $acl_edit_global,
228 curr_value_callback => sub {
229 my($cgi, $object, $field) = @_;
230 #in the other callbacks..? hmm.
236 { type => 'tablebreak-tr-title',
237 value => 'FCC Form 477 information',
239 { field => 'fcc_options_string',
240 type => 'input-fcc_options',
241 curr_value_callback => sub {
242 my ($cgi, $part_pkg, $fref) = @_;
243 if ( $cgi->param('fcc_options_string') ) {
245 return $cgi->param('fcc_options_string');
248 %hash = $part_pkg->fcc_options
249 if ($part_pkg->pkgpart);
250 return encode_json(\%hash);
256 { type => 'tablebreak-tr-title',
257 value => 'External Links', #better name?
259 { field=>'agent_pkgpartid', type=>'text', size=>21 },
261 { type => 'tablebreak-tr-title',
262 value => 'Line-item revenue recogition', #better name?
264 { field=>'pay_weight', type=>'text', size=>6 },
265 { field=>'credit_weight', type=>'text', size=>6 },
267 { type => 'columnend' },
269 { type => 'tablebreak-tr-title',
270 value => 'Usage pricing add-ons', #better name? just 'Usage pricing' ? there's also CDR usage pricing, RADIUS usage pricing, etc :/
272 { 'field' => 'usagepricepart',
273 'type' => 'part_pkg_usageprice',
274 'o2m_table' => 'part_pkg_usageprice',
276 'm2_error_callback' => $usageprice_error_callback,
279 { 'type' => $report_option ? 'tablebreak-tr-title'
281 'value' => 'Optional report classes',
282 'field' => 'census_title',
284 { 'field' => 'report_option',
285 'type' => $report_option ? 'select-table'
287 'table' => 'part_pkg_report_option',
288 'name_col' => 'name',
289 'hashref' => { 'disabled' => '' },
293 { 'type' => 'tablebreak-tr-title',
294 'value' => 'Term discounts',
296 { 'field' => 'discountnum',
297 'type' => 'select-table',
298 'table' => 'discount',
299 'name_col' => 'name',
300 'hashref' => { %$discountnum_hashref },
301 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
302 'empty_label'=> 'Select discount',
303 'm2_label' => 'Offer discounts for longer terms',
304 'm2m_method' => 'part_pkg_discount',
305 'm2m_dstcol' => 'discountnum',
306 'm2_error_callback' => $discount_error_callback,
309 { 'type' => 'tablebreak-tr-title',
310 'value' => 'Pricing add-ons',
313 { 'field' => 'bill_dst_pkgpart',
314 'type' => 'select-part_pkg',
315 'extra_sql' => sub { $pkgpart
316 ? "AND pkgpart != $pkgpart"
319 'label_callback' => sub { shift->pkg_comment_only },
320 'm2_label' => 'Include line item(s) from package',
321 'm2m_method' => 'bill_part_pkg_link',
322 'm2m_dstcol' => 'dst_pkgpart',
323 'm2_error_callback' =>
324 &{$m2_error_callback_maker}('bill'),
325 'm2_fields' => [ { 'field' => 'hidden',
326 'type' => 'checkbox',
334 { type => 'tablebreak-tr-title',
337 { type => 'pkg_svc', },
339 { 'field' => 'svc_dst_pkgpart',
340 'label' => 'Also include services from package: ',
341 'type' => 'select-part_pkg',
342 'extra_sql' => sub { $pkgpart
343 ? "AND pkgpart != $pkgpart"
346 'label_callback' => sub { shift->pkg_comment_only },
347 'm2_label' => 'Include services of package: ',
348 'm2m_method' => 'svc_part_pkg_link',
349 'm2m_dstcol' => 'dst_pkgpart',
350 'm2_error_callback' =>
351 &{$m2_error_callback_maker}('svc'),
354 { 'type' => 'tablebreak-tr-title',
355 'value' => 'Supplemental packages',
357 'include_opt_callback' => sub {
358 'id' => 'show_supp_pkgs',
361 { 'field' => 'supp_dst_pkgpart',
362 'type' => 'select-part_pkg',
363 'label_callback' => sub { shift->pkg_comment_only },
364 'm2_label' => 'When ordering package, also order',
365 'm2m_method' => 'supp_part_pkg_link',
366 'm2m_dstcol' => 'dst_pkgpart',
367 'm2_error_callback' =>
368 &{$m2_error_callback_maker}('supp'),
371 { type => 'tablebreak-tr-title',
372 value => 'Price plan options',
379 my $curuser = $FS::CurrentUser::CurrentUser;
381 my $edit_global = 'Edit global package definitions';
382 my $acl_edit = $curuser->access_right('Edit package definitions');
383 my $acl_edit_global = $curuser->access_right($edit_global);
385 my $acl_edit_either = $acl_edit || $acl_edit_global;
387 my $begin_callback = sub {
388 my( $cgi, $fields, $opt ) = @_;
390 unless $acl_edit_either
391 || ( $cgi->param('pkgnum')
392 && $curuser->access_right('Customize customer package')
396 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
398 #arg. access rights for cloning are Hard.
399 # on the one hand we don't really want cloning (customizing a package) to fail
400 # for want of finding the source package in normal usage
401 # on the other hand, we don't want people using the clone link to be able to
403 my $agent_clone_extra_sql =
404 ' ( '. FS::part_pkg->curuser_pkgs_sql.
405 " OR ( part_pkg.custom = 'Y' ) ".
408 my $conf = new FS::Conf;
409 my $taxproducts = $conf->exists('enable_taxproducts');
411 my $fcc_opts = $conf->exists('part_pkg-show_fcc_options');
413 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
414 my %locale_labels = map {
415 ( $_ => 'Package -- '. FS::Locales->description($_) )
418 sort { $locale_labels{$a} cmp $locale_labels{$b} }
422 my %locale_field_labels = (
424 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
429 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
430 " WHERE disabled IS NULL OR disabled = '' ")
432 $sth->execute or die $sth->errstr;
433 my $report_option = $sth->fetchrow_arrayref->[0];
436 # - tr-part_pkg_freq: month_increments_only (from price plans)
438 # - test errors cloning
439 # - test custom pricing
440 # - move the selectlayer divs away from lame layer_callback
442 #my ($query) = $cgi->keywords;
447 my %tax_override = ();
449 my %taxproductnums = map { ($_->classnum => 1) }
450 qsearch('usage_class', { 'disabled' => '' });
451 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
454 my $recur_disabled = 1;
455 my $setup_show_zero_disabled = 0;
456 my $recur_show_zero_disabled = 1;
460 my $splice_locale_fields = sub {
461 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
464 my @locale_fields = (
466 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
467 my $pkg_value = $pkg_value_callback
468 ? $pkg_value_callback eq 'cgiparam'
469 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
470 : &$pkg_value_callback($_)
473 { field => 'pkgpartmsgnum'. $n,
475 value => $pkey_value,
477 { field => 'pkgpartmsgnum'. $n. '_locale',
481 { field => 'pkgpartmsgnum'. $n++. '_pkg',
492 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
496 my $error_callback = sub {
497 my($cgi, $object, $fields, $opt ) = @_;
499 (@agent_type) = $cgi->param('agent_type');
501 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
503 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
505 $recur_disabled = $cgi->param('freq') ? 0 : 1;
506 $recur_show_zero_disabled =
508 ? $cgi->param('recur_fee') > 0 ? 1 : 0
511 foreach ($cgi->param) {
512 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
514 $tax_override{''} = $cgi->param('tax_override');
515 $tax_override{$_} = $cgi->param('tax_override_$_')
516 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
518 #some false laziness w/process
519 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
521 my $options = $cgi->param($plan."__OPTIONS");
522 my @options = split(',', $options);
524 map { my $optionname = $_;
525 my $param = $plan."__$optionname";
526 my $value = join(', ', $cgi->param($param));
527 ( $optionname => $value );
531 $object->set($_ => scalar($cgi->param($_)) )
532 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
534 foreach my $currency ( $conf->config('currencies') ) {
535 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
536 foreach (qw( setup_fee recur_fee )) {
537 my $param = $_.'_'.$currency;
538 $object->set( $param, $cgi->param($param) );
542 $pkgpart = $object->pkgpart;
544 &$splice_locale_fields(
548 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
549 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
556 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
558 my $new_object_callback = sub {
559 my( $cgi, $hashref, $fields, $opt ) = @_;
561 my $part_pkg = FS::part_pkg->new( $hashref );
562 $part_pkg->set($_ => '0')
563 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
569 sub set_report_option {
570 my($cgi, $object, $fields ) = @_; #, $opt
572 my @report_option = ();
573 foreach ($object->options) {
574 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
575 /^report_option_(\d+)$/ && (push @report_option, $1);
577 foreach ($object->part_pkg_taxoverride) {
578 $taxproductnums{$_->usage_class} = 1
582 $cgi->param('report_option', join(',', @report_option));
583 foreach my $field ( @$fields ) {
585 ref($field) eq 'HASH' &&
587 $field->{field} eq 'report_option'
589 #$field->{curr_value} = join(',', @report_option);
590 $field->{value} = join(',', @report_option);
595 my $edit_callback = sub {
596 my( $cgi, $object, $fields, $opt ) = @_;
598 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
600 $recur_disabled = $object->freq ? 0 : 1;
602 $recur_show_zero_disabled =
604 ? $object->option('recur_fee') > 0 ? 1 : 0
608 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
610 set_report_option( $cgi, $object, $fields);
612 %options = $object->options;
614 $object->set($_ => $object->option($_, 1))
615 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
617 foreach my $currency ( $conf->config('currencies') ) {
618 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
619 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
620 foreach keys %part_pkg_currency;
623 $pkgpart = $object->pkgpart;
625 &$splice_locale_fields(
629 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
630 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
634 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
635 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
641 my $new_callback = sub {
642 my( $cgi, $object, $fields ) = @_;
644 my $conf = new FS::Conf;
646 if ( $conf->exists('agent_defaultpkg') ) {
647 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
648 @agent_type = map {$_->typenum} qsearch('agent_type',{});
651 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
653 &$splice_locale_fields($fields, '', '');
657 my $clone_callback = sub {
658 my( $cgi, $object, $fields, $opt ) = @_;
660 if ( $cgi->param('pkgnum') ) {
662 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
663 $object->agentnum( $cust_pkg->cust_main->agentnum );
665 $opt->{action} = 'Custom';
667 #my $part_pkg = $clone_part_pkg->clone;
668 #this is all clone does anyway
669 $object->custom('Y');
671 $object->disabled('Y');
673 } else { #when explicitly cloning, not customizing
676 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
680 set_report_option( $cgi, $object, $fields);
682 %options = $object->options;
684 $object->set($_ => $options{$_})
685 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
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;
693 $recur_disabled = $object->freq ? 0 : 1;
695 &$splice_locale_fields(
700 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
701 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
706 my $discount_error_callback = sub {
707 my( $cgi, $object ) = @_;
709 if ( /^discountnum(\d+)$/ &&
710 ( my $discountnum = $cgi->param("discountnum$1") ) )
712 new FS::part_pkg_discount {
713 'pkgpart' => $object->pkgpart,
714 'discountnum' => $discountnum,
723 my $usageprice_error_callback = sub {
724 my( $cgi, $object ) = @_;
726 if ( /^usagepricepart(\d+)_price$/
727 && $cgi->param("usagepricepart$1_price") )
729 new FS::part_pkg_usageprice {
730 'usagepricepart' => $cgi->param("usagepricepart$1"),
731 'pkgpart' => $object->pkgpart,
732 'price' => scalar($cgi->param("usagepricepart$1_price")),
734 'action' => scalar($cgi->param("usagepricepart$1_action")),
735 'target' => scalar($cgi->param("usagepricepart$1_target")),
736 'amount' => scalar($cgi->param("usagepricepart$1_amount")),
745 my $m2_error_callback_maker = sub {
746 my $link_type = shift; #yay closures
748 my( $cgi, $object ) = @_;
751 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
752 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
755 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
757 new FS::part_pkg_link {
758 'link_type' => $link_type,
759 'src_pkgpart' => $object->pkgpart,
760 'dst_pkgpart' => $dst,
771 my $javascript = <<'END';
772 <SCRIPT TYPE="text/javascript">
774 function freq_changed(what) {
775 var freq = what.options[what.selectedIndex].value;
778 what.form.recur_fee.disabled = true;
779 what.form.recur_fee.style.backgroundColor = '#dddddd';
780 what.form.recur_show_zero.disabled = true;
781 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
783 what.form.recur_fee.disabled = false;
784 what.form.recur_fee.style.backgroundColor = '#ffffff';
785 recur_changed( what.form.recur_fee );
786 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
791 function setup_changed(what) {
792 var setup = what.value;
793 if ( parseFloat(setup) == 0 ) {
794 what.form.setup_show_zero.disabled = false;
796 what.form.setup_show_zero.disabled = true;
800 function recur_changed(what) {
801 var recur = what.value;
802 if ( parseFloat(recur) == 0 ) {
803 what.form.recur_show_zero.disabled = false;
805 what.form.recur_show_zero.disabled = true;
809 function agent_changed(what) {
812 if ( what.type == 'select-one' ) {
813 agentnum = what.options[what.selectedIndex].value;
815 agentnum = what.value;
818 if ( agentnum == 0 ) {
819 what.form.agent_type.disabled = false;
820 //what.form.agent_type.style.backgroundColor = '#ffffff';
821 what.form.agent_type.style.visibility = '';
823 what.form.agent_type.disabled = true;
824 //what.form.agent_type.style.backgroundColor = '#dddddd';
825 what.form.agent_type.style.visibility = 'hidden';
830 function aux_planchanged(what) { //?
832 var plan = what.options[what.selectedIndex].value;
834 var term_table = document.getElementById('TableNumber8') // XXX NOT ROBUST
835 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
836 //term_table.disabled = false;
837 //term_table.style.visibility = '';
838 term_table.style.display = '';
840 //term_table.disabled = true;
841 //term_table.style.visibility = 'hidden';
842 term_table.style.display = 'none';
845 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
848 for ( var i=0; i < form.length; i++ ) {
849 if ( currency_regex.test(form[i].name) ) {
850 if ( plan == 'currency_fixed' ) {
851 form[i].disabled = false;
853 form[i].disabled = true;
860 // some magic to make "supplemental packages" less obvious
861 var supp_pkg_rows = [];
862 function show_supp_pkgs_click() {
863 supp_pkg_rows[0].style.display = '';
865 this.style.backgroundColor = '';
866 this.style.border = '';
867 this.style.padding = '';
870 function hide_supp_pkgs() {
871 var all_selects = document.getElementsByTagName('select');
872 for (var i=0; i < all_selects.length; i++) {
873 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
874 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
877 if ( supp_pkg_rows.length == 1 ) {
878 // there are none configured, so hide the row to create a new one
879 supp_pkg_rows[0].style.display = 'none';
880 var button = document.getElementById('show_supp_pkgs');
881 button.onclick = show_supp_pkgs_click;
882 button.style.backgroundColor = '#cccccc';
883 button.style.border = '1px solid #7e0079';
884 button.style.padding = '1px';
891 'Changing the setup or recurring fee will create a new package definition. '.
894 $javascript .= "function confirm_submit(f) {";
895 if ( $conf->exists('part_pkg-lineage') ) {
898 var fields = Array('setup_fee','recur_fee');
899 for(var i=0; i < fields.length; i++) {
900 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
901 return confirm('$warning');
911 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
913 tie my %plan_labels, 'Tie::IxHash',
914 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
917 my $html_bottom = sub {
920 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
922 my $layer_callback = sub {
925 my $html = ntable("#cccccc",2);
929 # <TD ALIGN="right">Recurring fee frequency </TD>
930 # <TD><SELECT NAME="freq">
933 #my @freq = keys %freq;
934 #@freq = grep { /^\d+$/ } @freq
935 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
936 #foreach my $freq ( @freq ) {
937 # $html .= qq(<OPTION VALUE="$freq");
938 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
939 # $html .= ">$freq{$freq}";
942 #$html .= '</SELECT></TD></TR>';
944 my $href = $plans{$layer}->{'fields'};
945 my @fields = exists($plans{$layer}->{'fieldorder'})
946 ? @{$plans{$layer}->{'fieldorder'}}
949 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
951 if(!exists($href->{$field})) {
953 warn "nonexistent part_pkg option: '$field'\n";
956 if ( exists($href->{$field}->{display_if}) ) {
957 my %args = ( 'plan' => $layer ); # anything else?
958 my $display = &{ $href->{$field}->{display_if} }(%args);
962 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
964 my $format = sub { shift };
965 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
967 #XXX these should use elements/ fields... (or this whole thing should
968 #just use layer_fields instead of layer_callback)
970 if ( ! exists($href->{$field}{'type'}) ) {
972 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
973 ( exists($options{$field})
974 ? &$format($options{$field})
975 : $href->{$field}{'default'} ).
978 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
980 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
981 ( exists($options{$field}) && $options{$field}
986 } elsif ( $href->{$field}{'type'} eq 'select-rate' ) {
988 $html .= include('/elements/select-rate.html',
989 'field' => $layer.'__'.$field,
990 'curr_value' => $options{$field},
991 map { $_ => $href->{$field}{$_} }
992 grep { $_ !~ /^(name|type)$/ }
993 keys %{ $href->{$field} }
996 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
1000 if $href->{$field}{'type'} eq 'select_multiple';
1001 $html .= qq! NAME="${layer}__$field">!;
1003 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
1004 if exists($href->{$field}{'disable_empty'})
1005 && ! $href->{$field}{'disable_empty'};
1007 if ( $href->{$field}{'select_table'} ) {
1008 foreach my $record (
1009 qsearch( $href->{$field}{'select_table'},
1010 $href->{$field}{'select_hash'} )
1012 my $value = $record->getfield($href->{$field}{'select_key'});
1013 $html .= qq!<OPTION VALUE="$value"!.
1014 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
1018 '>'. $record->getfield($href->{$field}{'select_label'});
1020 } elsif ( $href->{$field}{'select_options'} ) {
1021 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
1022 my $label = $href->{$field}{'select_options'}{$key};
1023 $html .= qq!<OPTION VALUE="$key"!.
1024 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1032 $html .= '<font color="#ff0000">warning: '.
1033 "don't know how to retreive options for $field select field".
1036 $html .= '</SELECT>';
1038 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
1041 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
1043 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
1044 my $label = $href->{$field}{'options'}{$key};
1045 $html .= qq!$radio VALUE="$key"!.
1046 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1055 $html .= '</TD></TR>';
1057 $html .= '</TABLE>';
1059 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
1060 join(',', keys %{ $href } ). '">';
1066 my %selectlayers = (
1068 options => [ keys %plan_labels ],
1069 labels => \%plan_labels,
1070 curr_value => $object->plan,
1071 layer_callback => $layer_callback,
1072 onchange => 'aux_planchanged(what);',
1076 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1077 '<SCRIPT TYPE="text/javascript">'.
1078 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
1081 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
1084 $return .= '</SCRIPT>';
1090 my %usage_class = map { ($_->classnum => $_->classname) }
1091 qsearch('usage_class', {});
1092 $usage_class{setup} = 'Setup';
1093 $usage_class{recur} = 'Recurring';
1095 my %taxproduct_fields = ();
1096 my $end_callback = sub {
1097 my( $cgi, $object, $fields, $opt ) = @_;
1099 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1101 if ( $object->pkgpart ) {
1102 foreach my $usage_class ( '', @taxproductnums ) {
1103 $tax_override{$usage_class} =
1104 join (",", map $_->taxclassnum,
1105 qsearch( 'part_pkg_taxoverride', {
1106 'pkgpart' => $object->pkgpart,
1107 'usage_class' => $usage_class,
1113 %taxproduct_fields =
1114 map { $_ => [ "taxproductnum_$_",
1115 { type => 'select-taxproduct',
1116 #label => "$usage_class{$_} tax product",
1119 { type => 'select-taxoverride' }
1124 $taxproduct_fields{'(default)'} =
1125 [ 'taxproductnum', { type => 'select-taxproduct',
1126 #label => 'Default tax product',
1128 'tax_override', { type => 'select-taxoverride' },
1132 my $taxproduct_values = sub {
1133 my ($cgi, $object, $flags) = @_;
1135 sub { my $layer = shift;
1136 my @fields = @{$taxproduct_fields{$layer}};
1139 my $field = shift @fields;
1141 $field =~ /^taxproductnum_\w+$/ &&
1142 push @values, ( $field => $options{"usage_$field"} );
1143 $field =~ /^tax_override_(\w+)$/ &&
1144 push @values, ( $field => $tax_override{$1} );
1145 $field =~ /^taxproductnum$/ &&
1146 push @values, ( $field => $object->taxproductnum );
1147 $field =~ /^tax_override$/ &&
1148 push @values, ( $field => $tax_override{''} );
1154 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1155 return({ @result });
1159 my $field_callback = sub {
1160 my ($cgi, $object, $fieldref) = @_;
1162 my $field = $fieldref->{field};
1163 if ($field eq 'taxproductnums') {
1164 $fieldref->{value} = join(',', @taxproductnums);
1165 } elsif ($field eq 'taxproduct_select') {
1166 $fieldref->{options} = [ '(default)', @taxproductnums ];
1167 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1168 map {( $_ => ($usage_class{$_} || $_) )}
1171 $fieldref->{layer_fields} = \%taxproduct_fields;
1172 $fieldref->{layer_values_callback} = $taxproduct_values;
1176 my $discountnum_hashref = {
1178 'months' => { 'op' => '>', 'value' => 1 },