move batch customer import to its own file; add svc_external_svc_phone export format...
[freeside.git] / FS / FS / part_pkg.pm
index 3eb3bc1..cab6436 100644 (file)
@@ -599,15 +599,29 @@ sub svcpart {
   my $svcdb = scalar(@_) ? shift : '';
   my @svcdb_pkg_svc =
     grep { ( $svcdb eq $_->part_svc->svcdb || !$svcdb ) } $self->pkg_svc;
-  my @pkg_svc = ();
-  @pkg_svc = grep { $_->primary_svc =~ /^Y/i } @svcdb_pkg_svc
-    if dbdef->table('pkg_svc')->column('primary_svc');
+  my @pkg_svc = grep { $_->primary_svc =~ /^Y/i } @svcdb_pkg_svc;
   @pkg_svc = grep {$_->quantity == 1 } @svcdb_pkg_svc
     unless @pkg_svc;
   return '' if scalar(@pkg_svc) != 1;
   $pkg_svc[0]->svcpart;
 }
 
+=item svcpart_unique_svcdb SVCDB
+
+Returns the svcpart of the a service definition (see L<FS::part_svc>) matching
+SVCDB associated with this package definition (see L<FS::pkg_svc>).  Returns
+false if there not a primary service definition for SVCDB or there are multiple
+service definitions for SVCDB.
+
+=cut
+
+sub svcpart_unique_svcdb {
+  my( $self, $svcdb ) = @_;
+  my @svcdb_pkg_svc = grep { ( $svcdb eq $_->part_svc->svcdb ) } $self->pkg_svc;
+  return '' if scalar(@svcdb_pkg_svc) != 1;
+  $svcdb_pkg_svc[0]->svcpart;
+}
+
 =item payby
 
 Returns a list of the acceptable payment types for this package.  Eventually
@@ -929,6 +943,7 @@ sub _expand_cch_taxproductnum {
                          ? ( split ':', $part_pkg_taxproduct->taxproduct )
                          : ()
                      );
+  $a = '' unless $a; $b = '' unless $b; $c = '' unless $c; $d = '' unless $d;
   my $extra_sql = "AND ( taxproduct = '$a:$b:$c:$d'
                       OR taxproduct = '$a:$b:$c:'
                       OR taxproduct = '$a:$b:".":$d'
@@ -955,11 +970,11 @@ sub part_pkg_taxrate {
         ).
     ')';
   # much more CCH oddness in m2m -- this is kludgy
+  my @tpnums = $self->_expand_cch_taxproductnum($class);
   $extra_sql .= ' AND ('.
-    join(' OR ', map{ "taxproductnum = $_" }
-                 $self->_expand_cch_taxproductnum($class)
-        ).
-    ')';
+                          join(' OR ', map{ "taxproductnum = $_" } @tpnums ).
+                     ')'
+     if @tpnums;
 
   my $addl_from = 'LEFT JOIN part_pkg_taxproduct USING ( taxproductnum )';
   my $order_by = 'ORDER BY taxclassnum, length(geocode) desc, length(taxproduct) desc';