-my %all_pkgs;
-if ( $conf->exists('hidecancelledpackages' ) ) {
- %all_pkgs = map { $_->custnum => [ $_->ncancelled_pkgs ] } @cust_main;
-} else {
- %all_pkgs = map { $_->custnum => [ $_->all_pkgs ] } @cust_main;
+my %all_pkgs = ();
+if ( scalar(@cust_main) > 1 || $cgi->param('referral_custnum') ) {
+
+ my $pkgs_method = $conf->exists('hidecancelledpackages')
+ ? 'ncancelled_pkgs'
+ : 'all_pkgs';
+
+ #false laziness w/httemplate/view/cust_main/packages.html
+ my $select = join(',',
+ 'cust_pkg.*',
+ 'part_pkg.*',
+ 'setup_option.optionvalue AS _opt_setup_fee',
+ 'recur_option.optionvalue AS _opt_recur_fee',
+ );
+
+ my $addl_from = ' LEFT JOIN part_pkg USING ( pkgpart ) '.
+ FS::part_pkg->join_options_sql;
+
+ local($FS::cust_pkg::cache_enabled) = 1; #for $cust_pkg->part_pkg
+ %all_pkgs = map { $_->custnum =>
+ [ $_->$pkgs_method({ select => $select,
+ addl_from => $addl_from,
+ })
+ ];
+ }
+ @cust_main;
+