summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjeff <jeff>2007-04-11 04:28:22 +0000
committerjeff <jeff>2007-04-11 04:28:22 +0000
commit5a322e9cf2be599b4c6bcf3959178506dd5992be (patch)
tree3c268765b5b416abc0f3095cd426e8a157e2c3a0
parent8ac30110a4643b9083cc1fb91f672d7297161852 (diff)
usage suspend vs admin suspend -- avoid actual cust_pkg::suspend except legacy cases
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/cust_pkg.pm13
-rw-r--r--FS/FS/cust_svc.pm53
-rw-r--r--FS/FS/svc_Common.pm11
-rw-r--r--FS/FS/svc_acct.pm22
-rwxr-xr-xhttemplate/view/cust_main/packages.html16
6 files changed, 110 insertions, 6 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 591793b6e..c71bb01b4 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -725,6 +725,7 @@ sub tables_hashref {
'svcnum', 'serial', '', '', '', '',
'pkgnum', 'int', 'NULL', '', '', '',
'svcpart', 'int', '', '', '', '',
+ 'overlimit', @date_type, '', '',
],
'primary_key' => 'svcnum',
'unique' => [],
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 3e36ae242..616a48084 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -799,6 +799,19 @@ sub cust_svc {
}
+=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
diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm
index cdb34cd71..81d7b178e 100644
--- a/FS/FS/cust_svc.pm
+++ b/FS/FS/cust_svc.pm
@@ -68,6 +68,8 @@ The following fields are currently supported:
=item svcpart - Service definition (see L<FS::part_svc>)
+=item overlimit - date the service exceeded its usage limit
+
=back
=head1 METHODS
@@ -154,6 +156,54 @@ sub cancel {
}
+=item overlimit [ ACTION ]
+
+Retrieves or sets the overlimit date. If ACTION is absent, return
+the present value of overlimit. If ACTION is present, it can
+have the value 'suspend' or 'unsuspend'. In the case of 'suspend' overlimit
+is set to the current time if it is not already set. The 'unsuspend' value
+causes the time to be cleared.
+
+If there is an error on setting, returns the error, otherwise returns false.
+
+=cut
+
+sub overlimit {
+ my $self = shift;
+ my $action = shift or return $self->getfield('overlimit');
+
+ local $SIG{HUP} = 'IGNORE';
+ local $SIG{INT} = 'IGNORE';
+ local $SIG{QUIT} = 'IGNORE';
+ local $SIG{TERM} = 'IGNORE';
+ local $SIG{TSTP} = 'IGNORE';
+ local $SIG{PIPE} = 'IGNORE';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ if ( $action eq 'suspend' ) {
+ $self->setfield('overlimit', time) unless $self->getfield('overlimit');
+ }elsif ( $action eq 'unsuspend' ) {
+ $self->setfield('overlimit', '');
+ }else{
+ die "unexpected action value: $action";
+ }
+
+ local $ignore_quantity = 1;
+ my $error = $self->replace;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error setting overlimit: $error";
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+ ''; #no errors
+
+}
+
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
@@ -175,6 +225,8 @@ sub replace {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+ $old = $new->replace_old unless defined($old);
+
if ( $new->svcpart != $old->svcpart ) {
my $svc_x = $new->svc_x;
my $new_svc_x = ref($svc_x)->new({$svc_x->hash, svcpart=>$new->svcpart });
@@ -212,6 +264,7 @@ sub check {
$self->ut_numbern('svcnum')
|| $self->ut_numbern('pkgnum')
|| $self->ut_number('svcpart')
+ || $self->ut_numbern('overlimit')
;
return $error if $error;
diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm
index f60a7d945..52226d20b 100644
--- a/FS/FS/svc_Common.pm
+++ b/FS/FS/svc_Common.pm
@@ -735,6 +735,17 @@ sub export {
}
+=item overlimit
+
+Sets or retrieves overlimit date.
+
+=cut
+
+sub overlimit {
+ my $self = shift;
+ $self->cust_svc->overlimit(@_);
+}
+
=item cancel
Stub - returns false (no error) so derived classes don't need to define this
diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm
index cb3f38bf2..1ef211946 100644
--- a/FS/FS/svc_acct.pm
+++ b/FS/FS/svc_acct.pm
@@ -1590,7 +1590,7 @@ sub _op_usage {
if ( &{$op2condition{$op}}($self, $column, $amount) ) {
foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
- if ($part_export->option('overlimit_groups')) {
+ if ($part_export->option('overlimit_groups'), 1) {
my ($new,$old);
my $other = new FS::svc_acct $self->hashref;
my $groups = &{ $self->_fieldhandlers->{'usergroup'} }
@@ -1602,6 +1602,7 @@ sub _op_usage {
$new = $self; $old = $other;
}
my $error = $part_export->export_replace($new, $old);
+ $error ||= $self->overlimit($action);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "Error replacing radius groups in export, ${op}: $error";
@@ -1614,6 +1615,7 @@ sub _op_usage {
&& &{$op2condition{$op}}($self, $column, $amount) ) {
#my $error = $self->$action();
my $error = $self->cust_svc->cust_pkg->$action();
+ $error ||= $self->overlimit($action);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "Error ${action}ing: $error";
@@ -1707,8 +1709,22 @@ sub set_usage {
if $rv == 0;
}
- if ( $conf->exists("svc_acct-usage_unsuspend") && $reset ) {
- my $error = $self->cust_svc->cust_pkg->unsuspend;
+ if ( $reset ) {
+ my $error = $self->overlimit('unsuspend');
+
+ foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
+ if ($part_export->option('overlimit_groups'), 1) {
+ my $old = new FS::svc_acct $self->hashref;
+ my $groups = &{ $self->_fieldhandlers->{'usergroup'} }
+ ($self, $part_export->option('overlimit_groups'));
+ $old->usergroup( $groups );
+ $error ||= $part_export->export_replace($self, $old);
+ }
+ }
+
+ if ( $conf->exists("svc_acct-usage_unsuspend")) {
+ $error ||= $self->cust_svc->cust_pkg->unsuspend;
+ }
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "Error unsuspending: $error";
diff --git a/httemplate/view/cust_main/packages.html b/httemplate/view/cust_main/packages.html
index b54208b79..c56904690 100755
--- a/httemplate/view/cust_main/packages.html
+++ b/httemplate/view/cust_main/packages.html
@@ -270,12 +270,15 @@ Current packages
<% pkg_datestr($cust_pkg, 'setup', $conf) %>
</TR>
% } else {
-
-
+% if (scalar($cust_pkg->overlimit)) {
+ <TR>
+ <TD COLSPAN=<%$colspan%>><FONT COLOR="#FFD000"><B>Overlimit</B></FONT>,&nbsp;<% $billed_or_prepaid %>&nbsp;<% myfreq($part_pkg) %></TD>
+ </TR>
+%}else{
<TR>
<TD COLSPAN=<%$colspan%>><FONT COLOR="#00CC00"><B>Active</B></FONT>,&nbsp;<% $billed_or_prepaid %>&nbsp;<% myfreq($part_pkg) %></TD>
</TR>
-
+% }
<TR>
<TD WIDTH="<%$width%>" ALIGN="right">Setup&nbsp;</TD>
<% pkg_datestr($cust_pkg, 'setup', $conf) %>
@@ -347,6 +350,13 @@ Current packages
</TR>
<TR>
+ <TD ALIGN="right" COLSPAN="2" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
+
+ <% $cust_svc->overlimit ? "Overlimit: ". time2str('%b %o %Y' . ($conf->exists('cust_pkg-display_times') ? ' %l:%M %P' : ''), $cust_svc->overlimit) : '' %>
+ </FONT></TD>
+ </TR>
+
+ <TR>
<TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
% if ( $curuser->access_right('Recharge customer service')