use FS::cust_svc;
use FS::part_pkg;
use FS::cust_main;
+use FS::cust_location;
use FS::type_pkgs;
use FS::pkg_svc;
use FS::cust_bill_pkg;
=item pkgnum
-primary key (assigned automatically for new billing items)
+Primary key (assigned automatically for new billing items)
=item custnum
Billing item definition (see L<FS::part_pkg>)
+=item locationnum
+
+Optional link to package location (see L<FS::location>)
+
=item setup
date
$self->ut_numbern('pkgnum')
|| $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
|| $self->ut_numbern('pkgpart')
+ || $self->ut_foreign_keyn('locationnum', 'location', 'locationnum')
|| $self->ut_numbern('setup')
|| $self->ut_numbern('bill')
|| $self->ut_numbern('susp')
if ( $options{'reason'} ) {
$error = $self->insert_reason( 'reason' => $options{'reason'},
'action' => $date ? 'expire' : 'cancel',
+ 'date' => $date ? $date : $cancel_time,
'reason_otaker' => $options{'reason_otaker'},
);
if ( $error ) {
return "Package $pkgnum expires before it would be suspended.";
}
+ my $suspend_time = $options{'time'} || time;
+
if ( $options{'reason'} ) {
$error = $self->insert_reason( 'reason' => $options{'reason'},
'action' => $date ? 'adjourn' : 'suspend',
+ 'date' => $date ? $date : $suspend_time,
'reason_otaker' => $options{'reason_otaker'},
);
if ( $error ) {
if ( $date ) {
$hash{'adjourn'} = $date;
} else {
- $hash{'susp'} = time;
+ $hash{'susp'} = $suspend_time;
}
my $new = new FS::cust_pkg ( \%hash );
$error = $new->replace( $self, options => { $self->options } );
qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
}
+=item cust_location
+
+Returns the location object, if any (see L<FS::cust_location>).
+
+=cut
+
+sub cust_location {
+ my $self = shift;
+ return '' unless $self->locationnum;
+ qsearchs( 'cust_main', { 'locationnum' => $self->locationnum } );
+}
+
+=item cust_location_or_main
+
+If this package is associated with a location, returns the locaiton (see
+L<FS::cust_location>), otherwise returns the customer (see L<FS::cust_main>).
+
+=cut
+
+sub cust_location_or_main {
+ my $self = shift;
+ $self->cust_location || $self->cust_main;
+}
+
=item seconds_since TIMESTAMP
Returns the number of seconds all accounts (see L<FS::svc_acct>) in this