}
+=item join_options_sql
+
+Returns an SQL fragment for JOINing the part_pkg_option records for this
+package's setup_fee and recur_fee (as setup_option and recur_option,
+respectively). Useful for optimization.
+
+=cut
+
+sub join_options_sql {
+ #my $class = shift;
+ "
+ LEFT JOIN part_pkg_option AS setup_option
+ ON ( part_pkg.pkgpart = setup_option.pkgpart
+ AND setup_option.optionname = 'setup_fee' )
+ LEFT JOIN part_pkg_option AS recur_option
+ ON ( part_pkg.pkgpart = recur_option.pkgpart
+ AND recur_option.optionname = 'recur_fee' )
+ ";
+}
+
=back
=head1 SUBROUTINES
die 'Use of toggle_disabled with classnum has not been implemented'
if exists $hash{'classnum'};
+$opt{'select'} = 'part_pkg.*, setup_option.optionvalue AS _setup_fee,
+ recur_option.optionvalue AS _recur_fee'
+ unless $opt{'select'};
+$opt{'addl_from'} .= FS::part_pkg->join_options_sql;
+
$opt{'extra_sql'} .= ( keys(%hash) ? ' AND ' : ' WHERE ' ).
FS::part_pkg->curuser_pkgs_sql;
unless $opt{'presorted'};
} else {
@records = qsearch( {
+ 'select' => $opt{'select'} || '*',
'table' => $opt{'table'},
'addl_from' => $opt{'addl_from'},
'hashref' => $hashref,
} #else -1, all classes, so don't set classnum
my @part_pkg = qsearch({
+ 'select' => 'part_pkg.*, setup_option.optionvalue AS _setup_fee,
+ recur_option.optionvalue AS _recur_fee',
'table' => 'part_pkg',
+ 'addl_from' => FS::part_pkg->join_options_sql,
'hashref' => \%hash,
'extra_sql' =>
' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( 'null'=>1 ).