-my $cust_main = $opt{'cust_main'}
- or die "cust_main not specified";
-
-$opt{'records'} = delete $opt{'part_pkg'}
- if $opt{'part_pkg'};
-
-my $extra_sql = $opt{'extra_sql'}.
- ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
- ' WHERE typenum = '. $cust_main->agent->typenum.
- ' AND type_pkgs.pkgpart = part_pkg.pkgpart )';
-
-$opt{'records'} ||= [ qsearch({
- 'table' => 'part_pkg',
- 'hashref' => { 'disabled' => '', },
- 'extra_sql' => "$extra_sql ORDER BY pkg",
- #'extra_sql' => $extra_sql,
- #'order_by' => 'ORDER BY pkg',
- })
- ];
+my $cust_or_prospect_main = $opt{'cust_main'} || $opt{'prospect_main'}
+ or die "neither cust_main nor prospect_main specified";
+
+$opt{'extra_sql'} .= ' AND '. FS::part_pkg->agent_pkgs_sql( $cust_or_prospect_main->agent );