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.
235 ( $conf->exists('cust_pkg-show_fcc_voice_grade_equivalent')
237 { type => 'tablebreak-tr-title',
238 value => 'FCC Form 477 information',
240 { field=>'fcc_voip_class',
241 type=>'select-voip_class',
243 { field=>'fcc_ds0s', type=>'text', size=>6 },
248 { type => 'tablebreak-tr-title',
249 value => 'External Links', #better name?
251 { field=>'agent_pkgpartid', type=>'text', size=>21 },
253 { type => 'tablebreak-tr-title',
254 value => 'Line-item revenue recogition', #better name?
256 { field=>'pay_weight', type=>'text', size=>6 },
257 { field=>'credit_weight', type=>'text', size=>6 },
259 { type => 'columnend' },
261 { type => 'tablebreak-tr-title',
262 value => 'Usage pricing add-ons', #better name? just 'Usage pricing' ? there's also CDR usage pricing, RADIUS usage pricing, etc :/
264 { 'field' => 'usagepricepart',
265 'type' => 'part_pkg_usageprice',
266 'o2m_table' => 'part_pkg_usageprice',
268 'm2_error_callback' => $usageprice_error_callback,
271 { 'type' => $report_option ? 'tablebreak-tr-title'
273 'value' => 'Optional report classes',
274 'field' => 'census_title',
276 { 'field' => 'report_option',
277 'type' => $report_option ? 'select-table'
279 'table' => 'part_pkg_report_option',
280 'name_col' => 'name',
281 'hashref' => { 'disabled' => '' },
285 { 'type' => 'tablebreak-tr-title',
286 'value' => 'Term discounts',
288 { 'field' => 'discountnum',
289 'type' => 'select-table',
290 'table' => 'discount',
291 'name_col' => 'name',
292 'hashref' => { %$discountnum_hashref },
293 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
294 'empty_label'=> 'Select discount',
295 'm2_label' => 'Offer discounts for longer terms',
296 'm2m_method' => 'part_pkg_discount',
297 'm2m_dstcol' => 'discountnum',
298 'm2_error_callback' => $discount_error_callback,
301 { 'type' => 'tablebreak-tr-title',
302 'value' => 'Pricing add-ons',
305 { 'field' => 'bill_dst_pkgpart',
306 'type' => 'select-part_pkg',
307 'extra_sql' => sub { $pkgpart
308 ? "AND pkgpart != $pkgpart"
311 'label_callback' => sub { shift->pkg_comment_only },
312 'm2_label' => 'Include line item(s) from package',
313 'm2m_method' => 'bill_part_pkg_link',
314 'm2m_dstcol' => 'dst_pkgpart',
315 'm2_error_callback' =>
316 &{$m2_error_callback_maker}('bill'),
317 'm2_fields' => [ { 'field' => 'hidden',
318 'type' => 'checkbox',
326 { type => 'tablebreak-tr-title',
329 { type => 'pkg_svc', },
331 { 'field' => 'svc_dst_pkgpart',
332 'label' => 'Also include services from package: ',
333 'type' => 'select-part_pkg',
334 'extra_sql' => sub { $pkgpart
335 ? "AND pkgpart != $pkgpart"
338 'label_callback' => sub { shift->pkg_comment_only },
339 'm2_label' => 'Include services of package: ',
340 'm2m_method' => 'svc_part_pkg_link',
341 'm2m_dstcol' => 'dst_pkgpart',
342 'm2_error_callback' =>
343 &{$m2_error_callback_maker}('svc'),
346 { 'type' => 'tablebreak-tr-title',
347 'value' => 'Supplemental packages',
349 'include_opt_callback' => sub {
350 'id' => 'show_supp_pkgs',
353 { 'field' => 'supp_dst_pkgpart',
354 'type' => 'select-part_pkg',
355 'label_callback' => sub { shift->pkg_comment_only },
356 'm2_label' => 'When ordering package, also order',
357 'm2m_method' => 'supp_part_pkg_link',
358 'm2m_dstcol' => 'dst_pkgpart',
359 'm2_error_callback' =>
360 &{$m2_error_callback_maker}('supp'),
363 { type => 'tablebreak-tr-title',
364 value => 'Price plan options',
371 my $curuser = $FS::CurrentUser::CurrentUser;
373 my $edit_global = 'Edit global package definitions';
374 my $acl_edit = $curuser->access_right('Edit package definitions');
375 my $acl_edit_global = $curuser->access_right($edit_global);
377 my $acl_edit_either = $acl_edit || $acl_edit_global;
379 my $begin_callback = sub {
380 my( $cgi, $fields, $opt ) = @_;
382 unless $acl_edit_either
383 || ( $cgi->param('pkgnum')
384 && $curuser->access_right('Customize customer package')
388 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
390 #arg. access rights for cloning are Hard.
391 # on the one hand we don't really want cloning (customizing a package) to fail
392 # for want of finding the source package in normal usage
393 # on the other hand, we don't want people using the clone link to be able to
395 my $agent_clone_extra_sql =
396 ' ( '. FS::part_pkg->curuser_pkgs_sql.
397 " OR ( part_pkg.custom = 'Y' ) ".
400 my $conf = new FS::Conf;
401 my $taxproducts = $conf->exists('enable_taxproducts');
403 my @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
404 my %locale_labels = map {
405 ( $_ => 'Package -- '. FS::Locales->description($_) )
408 sort { $locale_labels{$a} cmp $locale_labels{$b} }
412 my %locale_field_labels = (
414 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
419 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
420 " WHERE disabled IS NULL OR disabled = '' ")
422 $sth->execute or die $sth->errstr;
423 my $report_option = $sth->fetchrow_arrayref->[0];
426 # - tr-part_pkg_freq: month_increments_only (from price plans)
428 # - test errors cloning
429 # - test custom pricing
430 # - move the selectlayer divs away from lame layer_callback
432 #my ($query) = $cgi->keywords;
437 my %tax_override = ();
439 my %taxproductnums = map { ($_->classnum => 1) }
440 qsearch('usage_class', { 'disabled' => '' });
441 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
444 my $recur_disabled = 1;
445 my $setup_show_zero_disabled = 0;
446 my $recur_show_zero_disabled = 1;
450 my $splice_locale_fields = sub {
451 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
454 my @locale_fields = (
456 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
457 my $pkg_value = $pkg_value_callback
458 ? $pkg_value_callback eq 'cgiparam'
459 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
460 : &$pkg_value_callback($_)
463 { field => 'pkgpartmsgnum'. $n,
465 value => $pkey_value,
467 { field => 'pkgpartmsgnum'. $n. '_locale',
471 { field => 'pkgpartmsgnum'. $n++. '_pkg',
482 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
486 my $error_callback = sub {
487 my($cgi, $object, $fields, $opt ) = @_;
489 (@agent_type) = $cgi->param('agent_type');
491 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
493 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
495 $recur_disabled = $cgi->param('freq') ? 0 : 1;
496 $recur_show_zero_disabled =
498 ? $cgi->param('recur_fee') > 0 ? 1 : 0
501 foreach ($cgi->param) {
502 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
504 $tax_override{''} = $cgi->param('tax_override');
505 $tax_override{$_} = $cgi->param('tax_override_$_')
506 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
508 #some false laziness w/process
509 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
511 my $options = $cgi->param($plan."__OPTIONS");
512 my @options = split(',', $options);
514 map { my $optionname = $_;
515 my $param = $plan."__$optionname";
516 my $value = join(', ', $cgi->param($param));
517 ( $optionname => $value );
521 $object->set($_ => scalar($cgi->param($_)) )
522 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
524 foreach my $currency ( $conf->config('currencies') ) {
525 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
526 foreach (qw( setup_fee recur_fee )) {
527 my $param = $_.'_'.$currency;
528 $object->set( $param, $cgi->param($param) );
532 $pkgpart = $object->pkgpart;
534 &$splice_locale_fields(
538 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
539 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
546 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
548 my $new_object_callback = sub {
549 my( $cgi, $hashref, $fields, $opt ) = @_;
551 my $part_pkg = FS::part_pkg->new( $hashref );
552 $part_pkg->set($_ => '0')
553 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
559 sub set_report_option {
560 my($cgi, $object, $fields ) = @_; #, $opt
562 my @report_option = ();
563 foreach ($object->options) {
564 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
565 /^report_option_(\d+)$/ && (push @report_option, $1);
567 foreach ($object->part_pkg_taxoverride) {
568 $taxproductnums{$_->usage_class} = 1
572 $cgi->param('report_option', join(',', @report_option));
573 foreach my $field ( @$fields ) {
575 ref($field) eq 'HASH' &&
577 $field->{field} eq 'report_option'
579 #$field->{curr_value} = join(',', @report_option);
580 $field->{value} = join(',', @report_option);
585 my $edit_callback = sub {
586 my( $cgi, $object, $fields, $opt ) = @_;
588 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
590 $recur_disabled = $object->freq ? 0 : 1;
592 $recur_show_zero_disabled =
594 ? $object->option('recur_fee') > 0 ? 1 : 0
598 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
600 set_report_option( $cgi, $object, $fields);
602 %options = $object->options;
604 $object->set($_ => $object->option($_, 1))
605 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
607 foreach my $currency ( $conf->config('currencies') ) {
608 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
609 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
610 foreach keys %part_pkg_currency;
613 $pkgpart = $object->pkgpart;
615 &$splice_locale_fields(
619 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
620 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
624 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
625 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
631 my $new_callback = sub {
632 my( $cgi, $object, $fields ) = @_;
634 my $conf = new FS::Conf;
636 if ( $conf->exists('agent_defaultpkg') ) {
637 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
638 @agent_type = map {$_->typenum} qsearch('agent_type',{});
641 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
643 &$splice_locale_fields($fields, '', '');
647 my $clone_callback = sub {
648 my( $cgi, $object, $fields, $opt ) = @_;
650 if ( $cgi->param('pkgnum') ) {
652 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
653 $object->agentnum( $cust_pkg->cust_main->agentnum );
655 $opt->{action} = 'Custom';
657 #my $part_pkg = $clone_part_pkg->clone;
658 #this is all clone does anyway
659 $object->custom('Y');
661 $object->disabled('Y');
663 } else { #when explicitly cloning, not customizing
666 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
670 set_report_option( $cgi, $object, $fields);
672 %options = $object->options;
674 $object->set($_ => $options{$_})
675 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
677 foreach my $currency ( $conf->config('currencies') ) {
678 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
679 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
680 foreach keys %part_pkg_currency;
683 $recur_disabled = $object->freq ? 0 : 1;
685 &$splice_locale_fields(
690 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
691 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
696 my $discount_error_callback = sub {
697 my( $cgi, $object ) = @_;
699 if ( /^discountnum(\d+)$/ &&
700 ( my $discountnum = $cgi->param("discountnum$1") ) )
702 new FS::part_pkg_discount {
703 'pkgpart' => $object->pkgpart,
704 'discountnum' => $discountnum,
713 my $usageprice_error_callback = sub {
714 my( $cgi, $object ) = @_;
716 if ( /^usagepricepart(\d+)_price$/
717 && $cgi->param("usagepricepart$1_price") )
719 new FS::part_pkg_usageprice {
720 'usagepricepart' => $cgi->param("usagepricepart$1"),
721 'pkgpart' => $object->pkgpart,
722 'price' => scalar($cgi->param("usagepricepart$1_price")),
724 'action' => scalar($cgi->param("usagepricepart$1_action")),
725 'target' => scalar($cgi->param("usagepricepart$1_target")),
726 'amount' => scalar($cgi->param("usagepricepart$1_amount")),
735 my $m2_error_callback_maker = sub {
736 my $link_type = shift; #yay closures
738 my( $cgi, $object ) = @_;
741 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
742 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
745 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
747 new FS::part_pkg_link {
748 'link_type' => $link_type,
749 'src_pkgpart' => $object->pkgpart,
750 'dst_pkgpart' => $dst,
761 my $javascript = <<'END';
762 <SCRIPT TYPE="text/javascript">
764 function freq_changed(what) {
765 var freq = what.options[what.selectedIndex].value;
768 what.form.recur_fee.disabled = true;
769 what.form.recur_fee.style.backgroundColor = '#dddddd';
770 what.form.recur_show_zero.disabled = true;
771 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
773 what.form.recur_fee.disabled = false;
774 what.form.recur_fee.style.backgroundColor = '#ffffff';
775 recur_changed( what.form.recur_fee );
776 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
781 function setup_changed(what) {
782 var setup = what.value;
783 if ( parseFloat(setup) == 0 ) {
784 what.form.setup_show_zero.disabled = false;
786 what.form.setup_show_zero.disabled = true;
790 function recur_changed(what) {
791 var recur = what.value;
792 if ( parseFloat(recur) == 0 ) {
793 what.form.recur_show_zero.disabled = false;
795 what.form.recur_show_zero.disabled = true;
799 function agent_changed(what) {
802 if ( what.type == 'select-one' ) {
803 agentnum = what.options[what.selectedIndex].value;
805 agentnum = what.value;
808 if ( agentnum == 0 ) {
809 what.form.agent_type.disabled = false;
810 //what.form.agent_type.style.backgroundColor = '#ffffff';
811 what.form.agent_type.style.visibility = '';
813 what.form.agent_type.disabled = true;
814 //what.form.agent_type.style.backgroundColor = '#dddddd';
815 what.form.agent_type.style.visibility = 'hidden';
820 function aux_planchanged(what) { //?
822 var plan = what.options[what.selectedIndex].value;
824 var term_table = document.getElementById('TableNumber8') // XXX NOT ROBUST
825 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
826 //term_table.disabled = false;
827 //term_table.style.visibility = '';
828 term_table.style.display = '';
830 //term_table.disabled = true;
831 //term_table.style.visibility = 'hidden';
832 term_table.style.display = 'none';
835 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
838 for ( var i=0; i < form.length; i++ ) {
839 if ( currency_regex.test(form[i].name) ) {
840 if ( plan == 'currency_fixed' ) {
841 form[i].disabled = false;
843 form[i].disabled = true;
850 // some magic to make "supplemental packages" less obvious
851 var supp_pkg_rows = [];
852 function show_supp_pkgs_click() {
853 supp_pkg_rows[0].style.display = '';
855 this.style.backgroundColor = '';
856 this.style.border = '';
857 this.style.padding = '';
860 function hide_supp_pkgs() {
861 var all_selects = document.getElementsByTagName('select');
862 for (var i=0; i < all_selects.length; i++) {
863 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
864 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
867 if ( supp_pkg_rows.length == 1 ) {
868 // there are none configured, so hide the row to create a new one
869 supp_pkg_rows[0].style.display = 'none';
870 var button = document.getElementById('show_supp_pkgs');
871 button.onclick = show_supp_pkgs_click;
872 button.style.backgroundColor = '#cccccc';
873 button.style.border = '1px solid #7e0079';
874 button.style.padding = '1px';
881 'Changing the setup or recurring fee will create a new package definition. '.
884 $javascript .= "function confirm_submit(f) {";
885 if ( $conf->exists('part_pkg-lineage') ) {
888 var fields = Array('setup_fee','recur_fee');
889 for(var i=0; i < fields.length; i++) {
890 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
891 return confirm('$warning');
901 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
903 tie my %plan_labels, 'Tie::IxHash',
904 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
907 my $html_bottom = sub {
910 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
912 my $layer_callback = sub {
915 my $html = ntable("#cccccc",2);
919 # <TD ALIGN="right">Recurring fee frequency </TD>
920 # <TD><SELECT NAME="freq">
923 #my @freq = keys %freq;
924 #@freq = grep { /^\d+$/ } @freq
925 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
926 #foreach my $freq ( @freq ) {
927 # $html .= qq(<OPTION VALUE="$freq");
928 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
929 # $html .= ">$freq{$freq}";
932 #$html .= '</SELECT></TD></TR>';
934 my $href = $plans{$layer}->{'fields'};
935 my @fields = exists($plans{$layer}->{'fieldorder'})
936 ? @{$plans{$layer}->{'fieldorder'}}
939 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
941 if(!exists($href->{$field})) {
943 warn "nonexistent part_pkg option: '$field'\n";
946 if ( exists($href->{$field}->{display_if}) ) {
947 my %args = ( 'plan' => $layer ); # anything else?
948 my $display = &{ $href->{$field}->{display_if} }(%args);
952 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
954 my $format = sub { shift };
955 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
957 #XXX these should use elements/ fields... (or this whole thing should
958 #just use layer_fields instead of layer_callback)
960 if ( ! exists($href->{$field}{'type'}) ) {
962 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
963 ( exists($options{$field})
964 ? &$format($options{$field})
965 : $href->{$field}{'default'} ).
968 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
970 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
971 ( exists($options{$field}) && $options{$field}
976 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
980 if $href->{$field}{'type'} eq 'select_multiple';
981 $html .= qq! NAME="${layer}__$field">!;
983 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
984 if exists($href->{$field}{'disable_empty'})
985 && ! $href->{$field}{'disable_empty'};
987 if ( $href->{$field}{'select_table'} ) {
989 qsearch( $href->{$field}{'select_table'},
990 $href->{$field}{'select_hash'} )
992 my $value = $record->getfield($href->{$field}{'select_key'});
993 $html .= qq!<OPTION VALUE="$value"!.
994 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
998 '>'. $record->getfield($href->{$field}{'select_label'});
1000 } elsif ( $href->{$field}{'select_options'} ) {
1001 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
1002 my $label = $href->{$field}{'select_options'}{$key};
1003 $html .= qq!<OPTION VALUE="$key"!.
1004 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1012 $html .= '<font color="#ff0000">warning: '.
1013 "don't know how to retreive options for $field select field".
1016 $html .= '</SELECT>';
1018 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
1021 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
1023 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
1024 my $label = $href->{$field}{'options'}{$key};
1025 $html .= qq!$radio VALUE="$key"!.
1026 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1035 $html .= '</TD></TR>';
1037 $html .= '</TABLE>';
1039 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
1040 join(',', keys %{ $href } ). '">';
1046 my %selectlayers = (
1048 options => [ keys %plan_labels ],
1049 labels => \%plan_labels,
1050 curr_value => $object->plan,
1051 layer_callback => $layer_callback,
1052 onchange => 'aux_planchanged(what);',
1056 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1057 '<SCRIPT TYPE="text/javascript">'.
1058 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
1061 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
1064 $return .= '</SCRIPT>';
1070 my %usage_class = map { ($_->classnum => $_->classname) }
1071 qsearch('usage_class', {});
1072 $usage_class{setup} = 'Setup';
1073 $usage_class{recur} = 'Recurring';
1075 my %taxproduct_fields = ();
1076 my $end_callback = sub {
1077 my( $cgi, $object, $fields, $opt ) = @_;
1079 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1081 if ( $object->pkgpart ) {
1082 foreach my $usage_class ( '', @taxproductnums ) {
1083 $tax_override{$usage_class} =
1084 join (",", map $_->taxclassnum,
1085 qsearch( 'part_pkg_taxoverride', {
1086 'pkgpart' => $object->pkgpart,
1087 'usage_class' => $usage_class,
1093 %taxproduct_fields =
1094 map { $_ => [ "taxproductnum_$_",
1095 { type => 'select-taxproduct',
1096 #label => "$usage_class{$_} tax product",
1099 { type => 'select-taxoverride' }
1104 $taxproduct_fields{'(default)'} =
1105 [ 'taxproductnum', { type => 'select-taxproduct',
1106 #label => 'Default tax product',
1108 'tax_override', { type => 'select-taxoverride' },
1112 my $taxproduct_values = sub {
1113 my ($cgi, $object, $flags) = @_;
1115 sub { my $layer = shift;
1116 my @fields = @{$taxproduct_fields{$layer}};
1119 my $field = shift @fields;
1121 $field =~ /^taxproductnum_\w+$/ &&
1122 push @values, ( $field => $options{"usage_$field"} );
1123 $field =~ /^tax_override_(\w+)$/ &&
1124 push @values, ( $field => $tax_override{$1} );
1125 $field =~ /^taxproductnum$/ &&
1126 push @values, ( $field => $object->taxproductnum );
1127 $field =~ /^tax_override$/ &&
1128 push @values, ( $field => $tax_override{''} );
1134 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1135 return({ @result });
1139 my $field_callback = sub {
1140 my ($cgi, $object, $fieldref) = @_;
1142 my $field = $fieldref->{field};
1143 if ($field eq 'taxproductnums') {
1144 $fieldref->{value} = join(',', @taxproductnums);
1145 } elsif ($field eq 'taxproduct_select') {
1146 $fieldref->{options} = [ '(default)', @taxproductnums ];
1147 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1148 map {( $_ => ($usage_class{$_} || $_) )}
1151 $fieldref->{layer_fields} = \%taxproduct_fields;
1152 $fieldref->{layer_values_callback} = $taxproduct_values;
1156 my $discountnum_hashref = {
1158 'months' => { 'op' => '>', 'value' => 1 },