[freeside-commits] freeside/FS/FS usage_class.pm, NONE, 1.1 Mason.pm, 1.2, 1.3 Schema.pm, 1.99, 1.100 Setup.pm, 1.13, 1.14 Upgrade.pm, 1.18, 1.19 rate_detail.pm, 1.8, 1.9

Jeff Finucane,420,, jeff at wavetail.420.am
Sat Aug 23 14:59:46 PDT 2008


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv1980/FS/FS

Modified Files:
	Mason.pm Schema.pm Setup.pm Upgrade.pm rate_detail.pm 
Added Files:
	usage_class.pm 
Log Message:
add usage classes to rate details

Index: Upgrade.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Upgrade.pm,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- Upgrade.pm	2 Aug 2008 04:10:00 -0000	1.18
+++ Upgrade.pm	23 Aug 2008 21:59:43 -0000	1.19
@@ -106,6 +106,9 @@
     #replace invnum and pkgnum with billpkgnum
     'cust_bill_pkg_detail' => [],
 
+    #usage_classes if we have none
+    'usage_class' => [],
+
   ;
 
   \%hash;

Index: rate_detail.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/rate_detail.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rate_detail.pm	26 Mar 2008 15:43:05 -0000	1.8
+++ rate_detail.pm	23 Aug 2008 21:59:44 -0000	1.9
@@ -49,6 +49,8 @@
 
 =item sec_granularity - granularity in seconds, i.e. 6 or 60; 0 for per-call
 
+=item classnum - usage class (see L<FS::usage_class) if any for this rate
+
 =back
 
 =head1 METHODS
@@ -121,6 +123,8 @@
     || $self->ut_float('min_charge')
 
     || $self->ut_number('sec_granularity')
+
+    || $self->ut_foreign_keyn('classnum', 'usage_class', 'classnum' )
   ;
   return $error if $error;
 
@@ -187,6 +191,19 @@
   $self->dest_region->prefixes_short;
 }
 
+=item classname
+
+Returns the name of the usage class (see L<FS::usage_class>) associated with
+this call plan rate.
+
+=cut
+
+sub classname {
+  my $self = shift;
+  my $usage_class = qsearchs('usage_class', { classnum => $self->classnum });
+  $usage_class ? $usage_class->classname : '';
+}
+
 
 =back
 

--- NEW FILE: usage_class.pm ---
package FS::usage_class;

use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs );

@ISA = qw(FS::Record);

=head1 NAME

FS::usage_class - Object methods for usage_class records

=head1 SYNOPSIS

  use FS::usage_class;

  $record = new FS::usage_class \%hash;
  $record = new FS::usage_class { 'column' => 'value' };

  $error = $record->insert;

  $error = $new_record->replace($old_record);

  $error = $record->delete;

  $error = $record->check;

=head1 DESCRIPTION

An FS::usage_class object represents a usage class.  Every rate detail
(see L<FS::rate_detail) has, optionally, a usage class.  FS::usage_class
inherits from FS::Record.  The following fields are currently supported:

=over 4

=item classnum

Primary key (assigned automatically for new usage classes)

=item classname

Text name of this usage class

=item disabled

Disabled flag, empty or 'Y'


=back

=head1 METHODS

=over 4

=item new HASHREF

Creates a new usage class.  To add the usage class to the database,
see L<"insert">.

Note that this stores the hash reference, not a distinct copy of the hash it
points to.  You can ask the object for a copy with the I<hash> method.

=cut

sub table { 'usage_class'; }

=item insert

Adds this record to the database.  If there is an error, returns the error,
otherwise returns false.

=cut

=item delete

Delete this record from the database.

=cut

=item replace OLD_RECORD

Replaces the OLD_RECORD with this one in the database.  If there is an error,
returns the error, otherwise returns false.

=cut

=item check

Checks all fields to make sure this is a valid usage class.  If there is
an error, returns the error, otherwise returns false.  Called by the insert
and replace methods.

=cut

sub check {
  my $self = shift;

  my $error = 
    $self->ut_numbern('classnum')
    || $self->ut_text('classname')
    || $self->ut_enum('disabled', [ '', 'Y' ])
  ;
  return $error if $error;

  $self->SUPER::check;
}

sub _populate_initial_data {
  my ($class, %opts) = @_;

  foreach ("Intrastate", "Interstate", "International") {
    my $object = $class->new( { 'classname' => $_ } );
    my $error = $object->insert;
    die "error inserting $class into database: $error\n"
      if $error;
  }

  '';

}

sub _upgrade_data {
  my $class = shift;

  return $class->_populate_initial_data(@_)
    unless scalar( qsearch( 'usage_class', {} ) );

  '';

}

=back

=head1 BUGS

=head1 SEE ALSO

L<FS::Record>, schema.html from the base documentation.

=cut

1;


Index: Setup.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Setup.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- Setup.pm	12 Dec 2007 05:58:41 -0000	1.13
+++ Setup.pm	23 Aug 2008 21:59:43 -0000	1.14
@@ -341,6 +341,10 @@
     #not yet....
 
   #)
+
+    #usage classes
+    'usage_class' => [],
+
   ;
 
   \%hash;

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -d -r1.99 -r1.100
--- Schema.pm	22 Aug 2008 03:01:05 -0000	1.99
+++ Schema.pm	23 Aug 2008 21:59:42 -0000	1.100
@@ -1671,6 +1671,7 @@
         'min_charge',      'decimal', '', '10,5', '', '', 
         'sec_granularity', 'int',     '', '', '', '', 
         #time period (link to table of periods)?
+        'classnum',        'int',     'NULL', '', '', '', 
       ],
       'primary_key' => 'ratedetailnum',
       'unique'      => [ [ 'ratenum', 'orig_regionnum', 'dest_regionnum' ] ],
@@ -1700,6 +1701,17 @@
       'index'       => [ [ 'countrycode' ], [ 'regionnum' ] ],
     },
 
+    'usage_class' => {
+      'columns' => [
+        'classnum',    'serial',   '',      '', '', '', 
+        'classname',   'varchar',  '', $char_d, '', '', 
+        'disabled',    'char', 'NULL',       1, '', '', 
+      ],
+      'primary_key' => 'classnum',
+      'unique' => [],
+      'index' => [ ['disabled'] ],
+    },
+
     'reg_code' => {
       'columns' => [
         'codenum',   'serial',    '', '', '', '', 

Index: Mason.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Mason.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Mason.pm	22 Aug 2008 03:01:04 -0000	1.2
+++ Mason.pm	23 Aug 2008 21:59:42 -0000	1.3
@@ -145,6 +145,8 @@
   use FS::rate;
   use FS::rate_region;
   use FS::rate_prefix;
+  use FS::rate_detail;
+  use FS::usage_class;
   use FS::payment_gateway;
   use FS::agent_payment_gateway;
   use FS::XMLRPC;



More information about the freeside-commits mailing list