use FS::part_svc;
use FS::cust_pkg_reason;
use FS::reason;
+use FS::cust_pkg_usageprice;
use FS::cust_pkg_discount;
use FS::discount;
use FS::UI::Web;
our ($disable_agentcheck, $DEBUG, $me, $import) = (0, 0, '[FS::cust_pkg]', 0);
+our $upgrade = 0; #go away after setup+start dates cleaned up for old customers
+
sub _cache {
my $self = shift;
my ( $hashref, $cache ) = @_;
refnums as keys. If no I<refnum> is defined, a default FS::pkg_referral
record will be created corresponding to cust_main.refnum.
+If the additional field I<cust_pkg_usageprice> is defined, it will be treated
+as an arrayref of FS::cust_pkg_usageprice objects, which will be inserted.
+(Note that this field cannot be set with a usual ->cust_pkg_usageprice method.
+It can be set as part of the hash when creating the object, or with the B<set>
+method.)
+
The following options are available:
=over 4
'params' => $self->refnum,
);
+ if ( $self->hashref->{cust_pkg_usageprice} ) {
+ for my $cust_pkg_usageprice ( @{ $self->hashref->{cust_pkg_usageprice} } ) {
+ $cust_pkg_usageprice->pkgnum( $self->pkgnum );
+ my $error = $cust_pkg_usageprice->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+ }
+
if ( $self->discountnum ) {
my $error = $self->insert_discount();
if ( $error ) {
return $error if $error;
return "A package with both start date (future start) and setup date (already started) will never bill"
- if $self->start_date && $self->setup;
+ if $self->start_date && $self->setup && ! $upgrade;
return "A future unsuspend date can only be set for a package with a suspend date"
if $self->resume and !$self->susp and !$self->adjourn;
if ( $opt->{cust_main} ) {
my $cust_main = $opt->{cust_main};
unless ( $cust_main->custnum ) {
- my $error = $cust_main->insert;
+ my $error = $cust_main->insert( @{ $opt->{cust_main_insert_args}||[] } );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "inserting cust_main (transaction rolled back): $error";
}
}
+ # transfer usage pricing add-ons, if we're not changing pkgpart
+ if ( $same_pkgpart ) {
+ foreach my $old_cust_pkg_usageprice ($self->cust_pkg_usageprice) {
+ my $new_cust_pkg_usageprice = new FS::cust_pkg_usageprice {
+ 'pkgnum' => $cust_pkg->pkgnum,
+ 'usagepricepart' => $old_cust_pkg_usageprice->usagepricepart,
+ 'quantity' => $old_cust_pkg_usageprice->quantity,
+ };
+ $error = $new_cust_pkg_usageprice->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error transferring usage pricing add-on: $error";
+ }
+ }
+ }
+
# transfer discounts, if we're not changing pkgpart
if ( $same_pkgpart ) {
foreach my $old_discount ($self->cust_pkg_discount_active) {
sub cust_svc {
my $self = shift;
cluck "cust_pkg->cust_svc called" if $DEBUG > 2;
- $self->_sort_cust_svc( $self->cust_svc_unsorted_arrayref );
+ $self->_sort_cust_svc( $self->cust_svc_unsorted_arrayref(@_) );
}
sub cust_svc_unsorted {
my $self = shift;
- @{ $self->cust_svc_unsorted_arrayref };
+ @{ $self->cust_svc_unsorted_arrayref(@_) };
}
sub cust_svc_unsorted_arrayref {
Returns the parent customer object (see L<FS::cust_main>).
-=cut
-
-sub cust_main {
- my $self = shift;
- qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
-}
-
=item balance
Returns the balance for this specific package, when using
foreach my $cust_svc (
grep {
my $part_svc = $_->part_svc;
- $part_svc->svcdb eq 'svc_acct'
- && scalar($part_svc->part_export_usage);
+ scalar($part_svc->part_export_usage);
} $self->cust_svc
) {
$sum += $cust_svc->attribute_since_sqlradacct($start, $end, $attrib);
=item cust_pkg_discount
-=cut
-
-sub cust_pkg_discount {
- my $self = shift;
- qsearch('cust_pkg_discount', { 'pkgnum' => $self->pkgnum } );
-}
-
=item cust_pkg_discount_active
=cut
Returns a list of all voice usage counters attached to this package.
-=cut
-
-sub cust_pkg_usage {
- my $self = shift;
- qsearch('cust_pkg_usage', { pkgnum => $self->pkgnum });
-}
-
=item apply_usage OPTIONS
Takes the following options:
Limit to packages with a service location in the specified state and country.
For FCC 477 reporting, mostly.
+=item location_cust
+
+Limit to packages whose service locations are the same as the customer's
+default service location.
+
+=item location_nocust
+
+Limit to packages whose service locations are not the customer's default
+service location.
+
+=item location_census
+
+Limit to packages whose service locations have census tracts.
+
+=item location_nocensus
+
+Limit to packages whose service locations do not have a census tract.
+
+=item location_geocode
+
+Limit to packages whose locations have geocodes.
+
+=item location_geocode
+
+Limit to packages whose locations do not have geocodes.
+
=back
=cut
}
}
+ ###
+ # location_* flags
+ ###
+ if ( $params->{location_cust} xor $params->{location_nocust} ) {
+ my $op = $params->{location_cust} ? '=' : '!=';
+ push @where, "cust_location.locationnum $op cust_main.ship_locationnum";
+ }
+ if ( $params->{location_census} xor $params->{location_nocensus} ) {
+ my $op = $params->{location_census} ? "IS NOT NULL" : "IS NULL";
+ push @where, "cust_location.censustract $op";
+ }
+ if ( $params->{location_geocode} xor $params->{location_nogeocode} ) {
+ my $op = $params->{location_geocode} ? "IS NOT NULL" : "IS NULL";
+ push @where, "cust_location.geocode $op";
+ }
+
###
# parse part_pkg
###