input and output on data volume fields specified with k,m,g,or t
[freeside.git] / FS / FS / cust_pkg.pm
index ea959ab..616a480 100644 (file)
@@ -693,7 +693,7 @@ sub last_reason {
   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;
@@ -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
@@ -1529,9 +1542,7 @@ sub order {
 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,