fix quotation package locations reverting to customer default location on order,...
[freeside.git] / FS / FS / cust_main / Packages.pm
index e913402..3f4792e 100644 (file)
@@ -155,7 +155,7 @@ sub order_pkg {
     }
     $cust_pkg->locationnum($opt->{'cust_location'}->locationnum);
 
-  } else {
+  } elsif ( ! $cust_pkg->locationnum ) {
 
     $cust_pkg->locationnum($self->ship_locationnum);
 
@@ -701,6 +701,13 @@ sub num_cancelled_pkgs {
   $self->num_pkgs($opt);
 }
 
+=item num_ncancelled_pkgs
+
+Returns the number of packages that have not been cancelled (see L<FS::cust_pkg>) for this
+customer.
+
+=cut
+
 sub num_ncancelled_pkgs {
   my $self = shift;
   my $opt = shift || {};
@@ -709,6 +716,23 @@ sub num_ncancelled_pkgs {
   $self->num_pkgs($opt);
 }
 
+=item num_billing_pkgs
+
+Returns the number of packages that have not been cancelled 
+and have a non-zero billing frequency (see L<FS::cust_pkg>)
+for this customer.
+
+=cut
+
+sub num_billing_pkgs {
+  my $self = shift;
+  my $opt = shift || {};
+  $opt->{addl_from} .= ' LEFT JOIN part_pkg USING (pkgpart)';
+  $opt->{extra_sql} .= ' AND ' if $opt->{extra_sql};
+  $opt->{extra_sql} .= "freq IS NOT NULL AND freq != '0'";
+  $self->num_ncancelled_pkgs($opt);
+}
+
 sub num_suspended_pkgs {
   my $self = shift;
   my $opt = shift || {};