search voided invoices, #28684
[freeside.git] / FS / FS / cust_bill_pkg.pm
index 066ddf1..212c4b6 100644 (file)
@@ -970,7 +970,13 @@ sub tax_locationnum {
 
 sub tax_location {
   my $self = shift;
-  FS::cust_location->by_key($self->tax_locationnum);
+  if ( $self->pkgnum ) { # normal sales
+    return $self->cust_pkg->tax_location;
+  } elsif ( $self->feepart ) { # fees
+    return $self->cust_bill->cust_main->ship_location;
+  } else { # taxes
+    return;
+  }
 }
 
 =item part_X
@@ -982,8 +988,8 @@ charge.  If called on a tax line, returns nothing.
 
 sub part_X {
   my $self = shift;
-  if ( $self->override_pkgpart ) {
-    return FS::part_pkg->by_key($self->override_pkgpart);
+  if ( $self->pkgpart_override ) {
+    return FS::part_pkg->by_key($self->pkgpart_override);
   } elsif ( $self->pkgnum ) {
     return $self->cust_pkg->part_pkg;
   } elsif ( $self->feepart ) {
@@ -1455,7 +1461,9 @@ sub upgrade_tax_location {
       my $i = 0;
       my $nlinks = scalar(@tax_links);
       if ( $nlinks ) {
-        while (int($cents_remaining) > 0) {
+        # ensure that it really is an integer
+        $cents_remaining = sprintf('%.0f', $cents_remaining);
+        while ($cents_remaining > 0) {
           $tax_links[$i % $nlinks]->{cents} += 1;
           $cents_remaining--;
           $i++;
@@ -1576,6 +1584,14 @@ sub _upgrade_data {
   });
   # call it kind of like a class method, not that it matters much
   $job->insert($class, 's' => str2time('2012-01-01'));
+  # if there's a customer location upgrade queued also, wait for it to 
+  # finish
+  my $location_job = qsearchs('queue', {
+      job => 'FS::cust_main::Location::process_upgrade_location'
+    });
+  if ( $location_job ) {
+    $job->depend_insert($location_job->jobnum);
+  }
   # Then mark the upgrade as done, so that we don't queue the job twice
   # and somehow run two of them concurrently.
   FS::upgrade_journal->set_done($upgrade);