use strict;
use vars qw(@ISA $disable_agentcheck $DEBUG);
+use List::Util qw(max);
use Tie::IxHash;
use FS::UID qw( getotaker dbh );
use FS::Misc qw( send_email );
# for sending cancel emails in sub cancel
use FS::Conf;
-@ISA = qw( FS::cust_main_Mixin FS::Record );
+@ISA = qw( FS::cust_main_Mixin FS::option_Common FS::Record );
$DEBUG = 0;
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
- my $error = $self->SUPER::insert;
+ my $error = $self->SUPER::insert($options{options} ? %{$options{options}} : ());
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
- my $error = $new->SUPER::replace($old);
+ my $error = $new->SUPER::replace($old,
+ $options{options} ? ${options{options}} : ()
+ );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
my %hash = $self->hash;
$hash{'cancel'} = time;
my $new = new FS::cust_pkg ( \%hash );
- $error = $new->replace($self);
+ $error = $new->replace( $self, options => { $self->options } );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
my %hash = $self->hash;
$hash{'susp'} = time;
my $new = new FS::cust_pkg ( \%hash );
- $error = $new->replace($self);
+ $error = $new->replace( $self, options => { $self->options } );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
$hash{'susp'} = '';
my $new = new FS::cust_pkg ( \%hash );
- $error = $new->replace($self);
+ $error = $new->replace( $self, options => { $self->options } );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
my $cust_pkg_reason = qsearchs( {
'table' => 'cust_pkg_reason',
'hashref' => { 'pkgnum' => $self->pkgnum, },
- 'extra_sql'=> 'ORDER BY date DESC',
+ 'extra_sql'=> 'ORDER BY date DESC LIMIT 1',
} );
qsearchs ( 'reason', { 'reasonnum' => $cust_pkg_reason->reasonnum } )
if $cust_pkg_reason;
}
+=item overlimit [ SVCPART ]
+
+Returns the services for this package which have exceeded their
+usage limit as FS::cust_svc objects (see L<FS::cust_svc>). If a svcpart
+is specified, return only the matching services.
+
+=cut
+
+sub overlimit {
+ my $self = shift;
+ grep { $_->overlimit } $self->cust_svc;
+}
+
=item h_cust_svc END_TIMESTAMP [ START_TIMESTAMP ]
Returns historical services for this package created before END TIMESTAMP and
my $part_svc = $pkg_svc->part_svc;
my $num_cust_svc = $self->num_cust_svc($part_svc->svcpart);
$part_svc->{'Hash'}{'num_cust_svc'} = $num_cust_svc; #more evil
- $part_svc->{'Hash'}{'num_avail'} = $pkg_svc->quantity - $num_cust_svc;
+ $part_svc->{'Hash'}{'num_avail'} =
+ max( 0, $pkg_svc->quantity - $num_cust_svc );
$part_svc->{'Hash'}{'cust_pkg_svc'} = [ $self->cust_svc($part_svc->svcpart) ];
$part_svc;
} $self->part_pkg->pkg_svc;
foreach my $cust_svc ($self->cust_svc) {
if($target{$cust_svc->svcpart} > 0) {
$target{$cust_svc->svcpart}--;
- my $new = new FS::cust_svc {
- svcnum => $cust_svc->svcnum,
- svcpart => $cust_svc->svcpart,
- pkgnum => $dest_pkgnum,
- };
+ my $new = new FS::cust_svc { $cust_svc->hash };
+ $new->pkgnum($dest_pkgnum);
my $error = $new->replace($cust_svc);
return $error if $error;
} elsif ( exists $opt{'change_svcpart'} && $opt{'change_svcpart'} ) {
warn "alternate(s) found\n" if $DEBUG;
my $change_svcpart = $alternate[0];
$target{$change_svcpart}--;
- my $new = new FS::cust_svc {
- svcnum => $cust_svc->svcnum,
- svcpart => $change_svcpart,
- pkgnum => $dest_pkgnum,
- };
+ my $new = new FS::cust_svc { $cust_svc->hash };
+ $new->svcpart($change_svcpart);
+ $new->pkgnum($dest_pkgnum);
my $error = $new->replace($cust_svc);
return $error if $error;
} else {
sub insert_reason {
my ($self, %options) = @_;
- my $otaker = $FS::CurrentUser::CurrentUser->name;
- $otaker = $FS::CurrentUser::CurrentUser->username
- if (($otaker) eq "User, Legacy");
+ my $otaker = $FS::CurrentUser::CurrentUser->username;
my $cust_pkg_reason =
new FS::cust_pkg_reason({ 'pkgnum' => $self->pkgnum,