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 'agentnum' => 'Agent',
52 'setup_fee' => 'Setup fee',
53 'setup_show_zero' => 'Show zero setup',
54 'recur_fee' => 'Recurring fee',
55 'recur_show_zero' => 'Show zero recurring',
56 ( map { ( "setup_fee_$_" => "Setup fee $_",
57 "recur_fee_$_" => "Recurring fee $_",
60 $conf->config('currencies')
62 'usagepricepart' => ' ',
63 'discountnum' => 'Offer discounts for longer terms',
64 'bill_dst_pkgpart' => 'Include line item(s) from package',
65 'svc_dst_pkgpart' => 'Include services of package',
66 'supp_dst_pkgpart' => 'When ordering package, also order',
67 'report_option' => 'Report classes',
68 'fcc_ds0s' => 'Voice-grade equivalents',
69 'fcc_voip_class' => 'Category',
70 'delay_start' => 'Default delay (days)',
74 { field=>'clone', type=>'hidden',
75 curr_value_callback =>
76 sub { shift->param('clone') },
78 { field=>'pkgnum', type=>'hidden',
79 curr_value_callback =>
80 sub { shift->param('pkgnum') },
83 { field=>'custom', type=>'hidden' },
84 { field=>'family_pkgpart', type=>'hidden' },
85 { field=>'successor', type=>'hidden' },
87 { type => 'columnstart' },
95 {field=>'comment', type=>'text', size=>40 }, #32
96 { field => 'agentnum',
97 type => 'select-agent',
98 disable_empty => ! $acl_edit_global,
99 empty_label => '(global)',
100 onchange => 'agent_changed',
102 {field=>'classnum', type=>'select-pkg_class' },
103 ( $conf->exists('pkg-addon_classnum')
104 ? ( { field=>'addon_classnum',
105 type =>'select-pkg_class',
110 {field=>'disabled', type=>$disabled_type, value=>'Y'},
111 {field=>'disable_line_item_date_ranges', type=>$disabled_type, value=>'Y'},
113 { type => 'tablebreak-tr-title',
114 value => 'Pricing', #better name?
117 type => 'selectlayers-select',
118 options => [ keys %plan_labels ],
119 labels => \%plan_labels,
120 onchange => 'aux_planchanged(what);',
122 { field => 'setup_fee',
124 onchange => 'setup_changed',
126 { field => 'setup_show_zero',
129 disabled => sub { $setup_show_zero_disabled },
131 ( map { +{ field => "setup_fee_$_",
133 prefix=> currency_symbol($_, SYM_HTML),
137 sort $conf->config('currencies')
140 type => 'part_pkg_freq',
141 onchange => 'freq_changed',
143 { field => 'recur_fee',
145 disabled => sub { $recur_disabled },
146 onchange => 'recur_changed',
148 { field => 'recur_show_zero',
151 disabled => sub { $recur_show_zero_disabled },
153 ( map { +{ field => "recur_fee_$_",
155 prefix=> currency_symbol($_, SYM_HTML),
159 sort $conf->config('currencies')
165 #recurring fee (auto-disable)
167 { type => 'columnnext' },
169 {type=>'justtitle', value=>'Taxation' },
170 {field=>'setuptax', type=>'checkbox', value=>'Y'},
171 {field=>'recurtax', type=>'checkbox', value=>'Y'},
172 {field=>'taxclass', type=>'select-taxclass' },
173 { field => 'taxproductnums',
175 value => join(',', @taxproductnums),
177 { field => 'taxproduct_select',
178 type => 'selectlayers',
179 options => [ '(default)', @taxproductnums ],
180 curr_value => '(default)',
181 labels => { ( '(default)' => '(default)' ),
182 map {($_=>$usage_class{$_})}
185 layer_fields => \%taxproduct_fields,
186 layer_values_callback => $taxproduct_values,
187 layers_only => !$taxproducts,
188 cell_style => ( !$taxproducts
194 { type => 'tablebreak-tr-title',
195 value => 'Promotions', #better name?
197 { field=>'promo_code', type=>'text', size=>15 },
199 { type => 'tablebreak-tr-title',
200 value => 'Cost tracking', #better name?
202 { field=>'setup_cost', type=>'money', },
203 { field=>'recur_cost', type=>'money', },
205 ( $conf->exists('part_pkg-delay_start')
206 ? ( { type => 'tablebreak-tr-title',
207 value => 'Delayed start',
209 { field => 'delay_start',
210 type => 'text', size => 6 },
215 { type => 'columnnext' },
217 { field => 'agent_type',
218 type => 'select-agent_types',
219 disabled => ! $acl_edit_global,
220 curr_value_callback => sub {
221 my($cgi, $object, $field) = @_;
222 #in the other callbacks..? hmm.
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 ( $conf->exists('cust_pkg-show_fcc_voice_grade_equivalent')
235 { type => 'tablebreak-tr-title',
236 value => 'FCC Form 477 information',
238 { field=>'fcc_voip_class',
239 type=>'select-voip_class',
241 { field=>'fcc_ds0s', type=>'text', size=>6 },
247 { type => 'columnend' },
249 { type => 'tablebreak-tr-title',
250 value => 'Usage pricing add-ons', #better name? just 'Usage pricing' ? there's also CDR usage pricing, RADIUS usage pricing, etc :/
252 { 'field' => 'usagepricepart',
253 'type' => 'part_pkg_usageprice',
254 'o2m_table' => 'part_pkg_usageprice',
256 'm2_error_callback' => $usageprice_error_callback,
259 { 'type' => $report_option ? 'tablebreak-tr-title'
261 'value' => 'Optional report classes',
262 'field' => 'census_title',
264 { 'field' => 'report_option',
265 'type' => $report_option ? 'select-table'
267 'table' => 'part_pkg_report_option',
268 'name_col' => 'name',
269 'hashref' => { 'disabled' => '' },
273 { 'type' => 'tablebreak-tr-title',
274 'value' => 'Term discounts',
276 { 'field' => 'discountnum',
277 'type' => 'select-table',
278 'table' => 'discount',
279 'name_col' => 'name',
280 'hashref' => { %$discountnum_hashref },
281 #'extra_sql' => 'AND (months IS NOT NULL OR months != 0)',
282 'empty_label'=> 'Select discount',
283 'm2_label' => 'Offer discounts for longer terms',
284 'm2m_method' => 'part_pkg_discount',
285 'm2m_dstcol' => 'discountnum',
286 'm2_error_callback' => $discount_error_callback,
289 { 'type' => 'tablebreak-tr-title',
290 'value' => 'Pricing add-ons',
293 { 'field' => 'bill_dst_pkgpart',
294 'type' => 'select-part_pkg',
295 'extra_sql' => sub { $pkgpart
296 ? "AND pkgpart != $pkgpart"
299 'm2_label' => 'Include line item(s) from package',
300 'm2m_method' => 'bill_part_pkg_link',
301 'm2m_dstcol' => 'dst_pkgpart',
302 'm2_error_callback' =>
303 &{$m2_error_callback_maker}('bill'),
304 'm2_fields' => [ { 'field' => 'hidden',
305 'type' => 'checkbox',
313 { type => 'tablebreak-tr-title',
316 { type => 'pkg_svc', },
318 { 'field' => 'svc_dst_pkgpart',
319 'label' => 'Also include services from package: ',
320 'type' => 'select-part_pkg',
321 'extra_sql' => sub { $pkgpart
322 ? "AND pkgpart != $pkgpart"
325 'm2_label' => 'Include services of package: ',
326 'm2m_method' => 'svc_part_pkg_link',
327 'm2m_dstcol' => 'dst_pkgpart',
328 'm2_error_callback' =>
329 &{$m2_error_callback_maker}('svc'),
332 { 'type' => 'tablebreak-tr-title',
333 'value' => 'Supplemental packages',
335 'include_opt_callback' => sub {
336 'id' => 'show_supp_pkgs',
339 { 'field' => 'supp_dst_pkgpart',
340 'type' => 'select-part_pkg',
341 'm2_label' => 'When ordering package, also order',
342 'm2m_method' => 'supp_part_pkg_link',
343 'm2m_dstcol' => 'dst_pkgpart',
344 'm2_error_callback' =>
345 &{$m2_error_callback_maker}('supp'),
348 { type => 'tablebreak-tr-title',
349 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 @locales = grep { ! /^en_/i } $conf->config('available-locales'); #should filter from the default locale lang instead of en_
389 my %locale_labels = map {
390 ( $_ => 'Package -- '. FS::Locales->description($_) )
393 sort { $locale_labels{$a} cmp $locale_labels{$b} }
397 my %locale_field_labels = (
399 ( 'pkgpartmsgnum'. $n++. '_pkg' => $locale_labels{$_} );
404 my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
405 " WHERE disabled IS NULL OR disabled = '' ")
407 $sth->execute or die $sth->errstr;
408 my $report_option = $sth->fetchrow_arrayref->[0];
411 # - tr-part_pkg_freq: month_increments_only (from price plans)
413 # - test errors cloning
414 # - test custom pricing
415 # - move the selectlayer divs away from lame layer_callback
417 #my ($query) = $cgi->keywords;
422 my %tax_override = ();
424 my %taxproductnums = map { ($_->classnum => 1) }
425 qsearch('usage_class', { 'disabled' => '' });
426 my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
429 my $recur_disabled = 1;
430 my $setup_show_zero_disabled = 0;
431 my $recur_show_zero_disabled = 1;
435 my $splice_locale_fields = sub {
436 my( $fields, $pkey_value_callback, $pkg_value_callback ) = @_;
439 my @locale_fields = (
441 my $pkey_value= $pkey_value_callback ? &$pkey_value_callback($_) : '';
442 my $pkg_value = $pkg_value_callback
443 ? $pkg_value_callback eq 'cgiparam'
444 ? $cgi->param('pkgpartmsgnum'. $n. '_pkg')
445 : &$pkg_value_callback($_)
448 { field => 'pkgpartmsgnum'. $n,
450 value => $pkey_value,
452 { field => 'pkgpartmsgnum'. $n. '_locale',
456 { field => 'pkgpartmsgnum'. $n++. '_pkg',
467 splice(@$fields, 7, 0, @locale_fields); #XXX 7 is arbitrary above
471 my $error_callback = sub {
472 my($cgi, $object, $fields, $opt ) = @_;
474 (@agent_type) = $cgi->param('agent_type');
476 $opt->{action} = 'Custom' if $cgi->param('pkgnum');
478 $setup_show_zero_disabled = ($cgi->param('setup_fee') > 0) ? 1 : 0;
480 $recur_disabled = $cgi->param('freq') ? 0 : 1;
481 $recur_show_zero_disabled =
483 ? $cgi->param('recur_fee') > 0 ? 1 : 0
486 foreach ($cgi->param) {
487 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
489 $tax_override{''} = $cgi->param('tax_override');
490 $tax_override{$_} = $cgi->param('tax_override_$_')
491 foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
493 #some false laziness w/process
494 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
496 my $options = $cgi->param($plan."__OPTIONS");
497 my @options = split(',', $options);
499 map { my $optionname = $_;
500 my $param = $plan."__$optionname";
501 my $value = join(', ', $cgi->param($param));
502 ( $optionname => $value );
506 $object->set($_ => scalar($cgi->param($_)) )
507 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
509 foreach my $currency ( $conf->config('currencies') ) {
510 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
511 foreach (qw( setup_fee recur_fee )) {
512 my $param = $_.'_'.$currency;
513 $object->set( $param, $cgi->param($param) );
517 $pkgpart = $object->pkgpart;
519 &$splice_locale_fields(
523 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
524 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
531 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
533 my $new_object_callback = sub {
534 my( $cgi, $hashref, $fields, $opt ) = @_;
536 my $part_pkg = FS::part_pkg->new( $hashref );
537 $part_pkg->set($_ => '0')
538 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
544 sub set_report_option {
545 my($cgi, $object, $fields ) = @_; #, $opt
547 my @report_option = ();
548 foreach ($object->options) {
549 /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
550 /^report_option_(\d+)$/ && (push @report_option, $1);
552 foreach ($object->part_pkg_taxoverride) {
553 $taxproductnums{$_->usage_class} = 1
557 $cgi->param('report_option', join(',', @report_option));
558 foreach my $field ( @$fields ) {
560 ref($field) eq 'HASH' &&
562 $field->{field} eq 'report_option'
564 #$field->{curr_value} = join(',', @report_option);
565 $field->{value} = join(',', @report_option);
570 my $edit_callback = sub {
571 my( $cgi, $object, $fields, $opt ) = @_;
573 $setup_show_zero_disabled = ($object->option('setup_fee') > 0) ? 1 : 0;
575 $recur_disabled = $object->freq ? 0 : 1;
577 $recur_show_zero_disabled =
579 ? $object->option('recur_fee') > 0 ? 1 : 0
583 map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
585 set_report_option( $cgi, $object, $fields);
587 %options = $object->options;
589 $object->set($_ => $object->option($_, 1))
590 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
592 foreach my $currency ( $conf->config('currencies') ) {
593 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
594 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
595 foreach keys %part_pkg_currency;
598 $pkgpart = $object->pkgpart;
600 &$splice_locale_fields(
604 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
605 $part_pkg_msgcat ? $part_pkg_msgcat->pkgpartmsgnum : '';
609 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
610 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
616 my $new_callback = sub {
617 my( $cgi, $object, $fields ) = @_;
619 my $conf = new FS::Conf;
621 if ( $conf->exists('agent_defaultpkg') ) {
622 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
623 @agent_type = map {$_->typenum} qsearch('agent_type',{});
626 $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill');
628 &$splice_locale_fields($fields, '', '');
632 my $clone_callback = sub {
633 my( $cgi, $object, $fields, $opt ) = @_;
635 if ( $cgi->param('pkgnum') ) {
637 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
638 $object->agentnum( $cust_pkg->cust_main->agentnum );
640 $opt->{action} = 'Custom';
642 #my $part_pkg = $clone_part_pkg->clone;
643 #this is all clone does anyway
644 $object->custom('Y');
646 $object->disabled('Y');
648 } else { #when explicitly cloning, not customizing
651 map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
655 set_report_option( $cgi, $object, $fields);
657 %options = $object->options;
659 $object->set($_ => $options{$_})
660 foreach (qw( setup_fee recur_fee disable_line_item_date_ranges ));
662 foreach my $currency ( $conf->config('currencies') ) {
663 my %part_pkg_currency = $object->part_pkg_currency_options($currency);
664 $object->set( $_.'_'.$currency, $part_pkg_currency{$_} )
665 foreach keys %part_pkg_currency;
668 $recur_disabled = $object->freq ? 0 : 1;
670 &$splice_locale_fields(
675 my $part_pkg_msgcat = $object->part_pkg_msgcat($locale);
676 $part_pkg_msgcat ? $part_pkg_msgcat->pkg : '';
681 my $discount_error_callback = sub {
682 my( $cgi, $object ) = @_;
684 if ( /^discountnum(\d+)$/ &&
685 ( my $discountnum = $cgi->param("discountnum$1") ) )
687 new FS::part_pkg_discount {
688 'pkgpart' => $object->pkgpart,
689 'discountnum' => $discountnum,
698 my $usageprice_error_callback = sub {
699 my( $cgi, $object ) = @_;
701 if ( /^usagepricepart(\d+)_price$/
702 && $cgi->param("usagepricepart$1_price") )
704 new FS::part_pkg_usageprice {
705 'usagepricepart' => $cgi->param("usagepricepart$1"),
706 'pkgpart' => $object->pkgpart,
707 'price' => scalar($cgi->param("usagepricepart$1_price")),
709 'action' => scalar($cgi->param("usagepricepart$1_action")),
710 'target' => scalar($cgi->param("usagepricepart$1_target")),
711 'amount' => scalar($cgi->param("usagepricepart$1_amount")),
720 my $m2_error_callback_maker = sub {
721 my $link_type = shift; #yay closures
723 my( $cgi, $object ) = @_;
726 if ( /^${link_type}_dst_pkgpart(\d+)$/ &&
727 ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) )
730 my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1")
732 new FS::part_pkg_link {
733 'link_type' => $link_type,
734 'src_pkgpart' => $object->pkgpart,
735 'dst_pkgpart' => $dst,
746 my $javascript = <<'END';
747 <SCRIPT TYPE="text/javascript">
749 function freq_changed(what) {
750 var freq = what.options[what.selectedIndex].value;
753 what.form.recur_fee.disabled = true;
754 what.form.recur_fee.style.backgroundColor = '#dddddd';
755 what.form.recur_show_zero.disabled = true;
756 //what.form.recur_show_zero.style.backgroundColor= '#dddddd';
758 what.form.recur_fee.disabled = false;
759 what.form.recur_fee.style.backgroundColor = '#ffffff';
760 recur_changed( what.form.recur_fee );
761 //what.form.recur_show_zero.style.backgroundColor= '#ffffff';
766 function setup_changed(what) {
767 var setup = what.value;
768 if ( parseFloat(setup) == 0 ) {
769 what.form.setup_show_zero.disabled = false;
771 what.form.setup_show_zero.disabled = true;
775 function recur_changed(what) {
776 var recur = what.value;
777 if ( parseFloat(recur) == 0 ) {
778 what.form.recur_show_zero.disabled = false;
780 what.form.recur_show_zero.disabled = true;
784 function agent_changed(what) {
787 if ( what.type == 'select-one' ) {
788 agentnum = what.options[what.selectedIndex].value;
790 agentnum = what.value;
793 if ( agentnum == 0 ) {
794 what.form.agent_type.disabled = false;
795 //what.form.agent_type.style.backgroundColor = '#ffffff';
796 what.form.agent_type.style.visibility = '';
798 what.form.agent_type.disabled = true;
799 //what.form.agent_type.style.backgroundColor = '#dddddd';
800 what.form.agent_type.style.visibility = 'hidden';
805 function aux_planchanged(what) { //?
807 var plan = what.options[what.selectedIndex].value;
809 var term_table = document.getElementById('TableNumber8') // XXX NOT ROBUST
810 if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) {
811 //term_table.disabled = false;
812 //term_table.style.visibility = '';
813 term_table.style.display = '';
815 //term_table.disabled = true;
816 //term_table.style.visibility = 'hidden';
817 term_table.style.display = 'none';
820 var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/;
823 for ( var i=0; i < form.length; i++ ) {
824 if ( currency_regex.test(form[i].name) ) {
825 if ( plan == 'currency_fixed' ) {
826 form[i].disabled = false;
828 form[i].disabled = true;
835 // some magic to make "supplemental packages" less obvious
836 var supp_pkg_rows = [];
837 function show_supp_pkgs_click() {
838 supp_pkg_rows[0].style.display = '';
840 this.style.backgroundColor = '';
841 this.style.border = '';
842 this.style.padding = '';
845 function hide_supp_pkgs() {
846 var all_selects = document.getElementsByTagName('select');
847 for (var i=0; i < all_selects.length; i++) {
848 if ( all_selects[i].id.match(/^supp_dst_pkgpart/) ) {
849 supp_pkg_rows.push( all_selects[i].parentNode.parentNode );
852 if ( supp_pkg_rows.length == 1 ) {
853 // there are none configured, so hide the row to create a new one
854 supp_pkg_rows[0].style.display = 'none';
855 var button = document.getElementById('show_supp_pkgs');
856 button.onclick = show_supp_pkgs_click;
857 button.style.backgroundColor = '#cccccc';
858 button.style.border = '1px solid #7e0079';
859 button.style.padding = '1px';
866 'Changing the setup or recurring fee will create a new package definition. '.
869 $javascript .= "function confirm_submit(f) {";
870 if ( $conf->exists('part_pkg-lineage') ) {
873 var fields = Array('setup_fee','recur_fee');
874 for(var i=0; i < fields.length; i++) {
875 if ( f[fields[i]].value != f[fields[i]].defaultValue ) {
876 return confirm('$warning');
886 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
888 tie my %plan_labels, 'Tie::IxHash',
889 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
892 my $html_bottom = sub {
895 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
897 my $layer_callback = sub {
900 my $html = ntable("#cccccc",2);
904 # <TD ALIGN="right">Recurring fee frequency </TD>
905 # <TD><SELECT NAME="freq">
908 #my @freq = keys %freq;
909 #@freq = grep { /^\d+$/ } @freq
910 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
911 #foreach my $freq ( @freq ) {
912 # $html .= qq(<OPTION VALUE="$freq");
913 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
914 # $html .= ">$freq{$freq}";
917 #$html .= '</SELECT></TD></TR>';
919 my $href = $plans{$layer}->{'fields'};
920 my @fields = exists($plans{$layer}->{'fieldorder'})
921 ? @{$plans{$layer}->{'fieldorder'}}
924 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
926 if(!exists($href->{$field})) {
928 warn "nonexistent part_pkg option: '$field'\n";
931 if ( exists($href->{$field}->{display_if}) ) {
932 my %args = ( 'plan' => $layer ); # anything else?
933 my $display = &{ $href->{$field}->{display_if} }(%args);
937 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
939 my $format = sub { shift };
940 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
942 #XXX these should use elements/ fields... (or this whole thing should
943 #just use layer_fields instead of layer_callback)
945 if ( ! exists($href->{$field}{'type'}) ) {
947 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
948 ( exists($options{$field})
949 ? &$format($options{$field})
950 : $href->{$field}{'default'} ).
953 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
955 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
956 ( exists($options{$field}) && $options{$field}
961 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
965 if $href->{$field}{'type'} eq 'select_multiple';
966 $html .= qq! NAME="${layer}__$field">!;
968 $html .= '<OPTION VALUE="">'. $href->{$field}{'empty_label'}
969 if exists($href->{$field}{'disable_empty'})
970 && ! $href->{$field}{'disable_empty'};
972 if ( $href->{$field}{'select_table'} ) {
974 qsearch( $href->{$field}{'select_table'},
975 $href->{$field}{'select_hash'} )
977 my $value = $record->getfield($href->{$field}{'select_key'});
978 $html .= qq!<OPTION VALUE="$value"!.
979 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #?
983 '>'. $record->getfield($href->{$field}{'select_label'});
985 } elsif ( $href->{$field}{'select_options'} ) {
986 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
987 my $label = $href->{$field}{'select_options'}{$key};
988 $html .= qq!<OPTION VALUE="$key"!.
989 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
997 $html .= '<font color="#ff0000">warning: '.
998 "don't know how to retreive options for $field select field".
1001 $html .= '</SELECT>';
1003 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
1006 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
1008 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
1009 my $label = $href->{$field}{'options'}{$key};
1010 $html .= qq!$radio VALUE="$key"!.
1011 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #?
1020 $html .= '</TD></TR>';
1022 $html .= '</TABLE>';
1024 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
1025 join(',', keys %{ $href } ). '">';
1031 my %selectlayers = (
1033 options => [ keys %plan_labels ],
1034 labels => \%plan_labels,
1035 curr_value => $object->plan,
1036 layer_callback => $layer_callback,
1037 onchange => 'aux_planchanged(what);',
1041 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
1042 '<SCRIPT TYPE="text/javascript">'.
1043 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
1046 "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
1049 $return .= '</SCRIPT>';
1055 my %usage_class = map { ($_->classnum => $_->classname) }
1056 qsearch('usage_class', {});
1057 $usage_class{setup} = 'Setup';
1058 $usage_class{recur} = 'Recurring';
1060 my %taxproduct_fields = ();
1061 my $end_callback = sub {
1062 my( $cgi, $object, $fields, $opt ) = @_;
1064 @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
1066 if ( $object->pkgpart ) {
1067 foreach my $usage_class ( '', @taxproductnums ) {
1068 $tax_override{$usage_class} =
1069 join (",", map $_->taxclassnum,
1070 qsearch( 'part_pkg_taxoverride', {
1071 'pkgpart' => $object->pkgpart,
1072 'usage_class' => $usage_class,
1078 %taxproduct_fields =
1079 map { $_ => [ "taxproductnum_$_",
1080 { type => 'select-taxproduct',
1081 #label => "$usage_class{$_} tax product",
1084 { type => 'select-taxoverride' }
1089 $taxproduct_fields{'(default)'} =
1090 [ 'taxproductnum', { type => 'select-taxproduct',
1091 #label => 'Default tax product',
1093 'tax_override', { type => 'select-taxoverride' },
1097 my $taxproduct_values = sub {
1098 my ($cgi, $object, $flags) = @_;
1100 sub { my $layer = shift;
1101 my @fields = @{$taxproduct_fields{$layer}};
1104 my $field = shift @fields;
1106 $field =~ /^taxproductnum_\w+$/ &&
1107 push @values, ( $field => $options{"usage_$field"} );
1108 $field =~ /^tax_override_(\w+)$/ &&
1109 push @values, ( $field => $tax_override{$1} );
1110 $field =~ /^taxproductnum$/ &&
1111 push @values, ( $field => $object->taxproductnum );
1112 $field =~ /^tax_override$/ &&
1113 push @values, ( $field => $tax_override{''} );
1119 map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
1120 return({ @result });
1124 my $field_callback = sub {
1125 my ($cgi, $object, $fieldref) = @_;
1127 my $field = $fieldref->{field};
1128 if ($field eq 'taxproductnums') {
1129 $fieldref->{value} = join(',', @taxproductnums);
1130 } elsif ($field eq 'taxproduct_select') {
1131 $fieldref->{options} = [ '(default)', @taxproductnums ];
1132 $fieldref->{labels} = { ( '(default)' => '(default)' ),
1133 map {( $_ => ($usage_class{$_} || $_) )}
1136 $fieldref->{layer_fields} = \%taxproduct_fields;
1137 $fieldref->{layer_values_callback} = $taxproduct_values;
1141 my $discountnum_hashref = {
1143 'months' => { 'op' => '>', 'value' => 1 },