doc
[freeside.git] / FS / FS / part_pkg.pm
index 0562a6d..3ee9e7f 100644 (file)
@@ -369,7 +369,7 @@ sub replace {
   foreach my $part_svc ( qsearch('part_svc', {} ) ) {
     my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
     my $primary_svc =
-      ( defined($options->{'primary_svc'})
+      ( defined($options->{'primary_svc'}) && $options->{'primary_svc'}
         && $options->{'primary_svc'} == $part_svc->svcpart
       )
         ? 'Y'
@@ -917,10 +917,12 @@ sub svc_part_pkg_link {
 
 sub _part_pkg_link {
   my( $self, $type ) = @_;
-  qsearch('part_pkg_link', { 'src_pkgpart' => $self->pkgpart,
-                             'link_type'   => $type,
-                           }
-         );
+  qsearch({ table    => 'part_pkg_link',
+            hashref  => { 'src_pkgpart' => $self->pkgpart,
+                          'link_type'   => $type,
+                        },
+            order_by => "ORDER BY hidden",
+         });
 }
 
 sub self_and_bill_linked {
@@ -928,12 +930,18 @@ sub self_and_bill_linked {
 }
 
 sub _self_and_linked {
-  my( $self, $type ) = @_;
+  my( $self, $type, $hidden ) = @_;
+  $hidden ||= '';
+
+  my @result = ();
+  foreach ( ( $self, map { $_->dst_pkg->_self_and_linked($type, $_->hidden) }
+                     $self->_part_pkg_link($type) ) )
+  {
+    $_->hidden($hidden) if $hidden;
+    push @result, $_;
+  }
 
-  ( $self,
-    map { $_->dst_pkg->_self_and_linked($type) }
-        $self->_part_pkg_link($type)
-  );
+  (@result);
 }
 
 =item part_pkg_taxoverride [ CLASS ]
@@ -1225,27 +1233,29 @@ sub _upgrade_data { # class method
   foreach my $part_pkg (@part_pkg) {
 
     unless ( $part_pkg->plan ) {
-
       $part_pkg->plan('flat');
+    }
 
-      if ( $part_pkg->setup =~ /^\s*([\d\.]+)\s*$/ ) {
+    if ( length($part_pkg->option('setup_fee')) == 0 
+         && $part_pkg->setup =~ /^\s*([\d\.]+)\s*$/ ) {
 
-        my $opt = new FS::part_pkg_option {
-          'pkgpart'     => $part_pkg->pkgpart,
-          'optionname'  => 'setup_fee',
-          'optionvalue' => $1,
-        };
-        my $error = $opt->insert;
-        die $error if $error;
+      my $opt = new FS::part_pkg_option {
+        'pkgpart'     => $part_pkg->pkgpart,
+        'optionname'  => 'setup_fee',
+        'optionvalue' => $1,
+      };
+      my $error = $opt->insert;
+      die $error if $error;
 
-        $part_pkg->setup('');
 
-      } else {
-        die "Can't parse part_pkg.setup for fee; convert pkgnum ".
-            $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
-      }
+      #} else {
+      #  die "Can't parse part_pkg.setup for fee; convert pkgnum ".
+      #      $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
+    }
+    $part_pkg->setup('');
 
-      if ( $part_pkg->recur =~ /^\s*([\d\.]+)\s*$/ ) {
+    if ( length($part_pkg->option('recur_fee')) == 0
+         && $part_pkg->recur =~ /^\s*([\d\.]+)\s*$/ ) {
 
         my $opt = new FS::part_pkg_option {
           'pkgpart'     => $part_pkg->pkgpart,
@@ -1255,14 +1265,12 @@ sub _upgrade_data { # class method
         my $error = $opt->insert;
         die $error if $error;
 
-        $part_pkg->recur('');
-
-      } else {
-        die "Can't parse part_pkg.setup for fee; convert pkgnum ".
-            $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
-      }
 
+      #} else {
+      #  die "Can't parse part_pkg.setup for fee; convert pkgnum ".
+      #      $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
     }
+    $part_pkg->recur('');
 
     $part_pkg->replace; #this should take care of plandata, right?
 
@@ -1281,6 +1289,7 @@ sub _upgrade_data { # class method
     $new->custom('Y');
     my $comment = $part_pkg->comment;
     $comment =~ s/^\(CUSTOM\) //;
+    $comment = '(none)' unless $comment =~ /\S/;
     $new->comment($comment);
 
     my $pkg_svc = { map { $_->svcpart => $_->quantity } $part_pkg->pkg_svc };