diff options
author | jeff <jeff> | 2008-08-23 21:59:46 +0000 |
---|---|---|
committer | jeff <jeff> | 2008-08-23 21:59:46 +0000 |
commit | ef0d8db38d1ee28a65a7ecdc6e11c7a82c0a741b (patch) | |
tree | 78518afc3aa8623211251caedf78459167cd0877 /FS | |
parent | 8381e7232f90ac22b3f655cdccd0d39e2bde1d63 (diff) |
add usage classes to rate details
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS.pm | 2 | ||||
-rw-r--r-- | FS/FS/Mason.pm | 2 | ||||
-rw-r--r-- | FS/FS/Schema.pm | 12 | ||||
-rw-r--r-- | FS/FS/Setup.pm | 4 | ||||
-rw-r--r-- | FS/FS/Upgrade.pm | 3 | ||||
-rw-r--r-- | FS/FS/rate_detail.pm | 17 | ||||
-rw-r--r-- | FS/FS/usage_class.pm | 143 | ||||
-rw-r--r-- | FS/MANIFEST | 2 | ||||
-rw-r--r-- | FS/t/usage_class.t | 5 |
9 files changed, 190 insertions, 0 deletions
@@ -190,6 +190,8 @@ L<FS::rate_prefix> - Rate region prefixes for call billing L<FS::rate_detail> - Rate plan detail for call billing +L<FS::usage_class> - Usage class class + L<FS::agent> - Agent (reseller) class L<FS::agent_type> - Agent type class diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index 77ff668..cfb12e4 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -145,6 +145,8 @@ Initializes the Mason environment, loads all Freeside and RT libraries, etc. 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; diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 86cf4a3..530f632 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1671,6 +1671,7 @@ sub tables_hashref { '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 @@ sub tables_hashref { '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', '', '', '', '', diff --git a/FS/FS/Setup.pm b/FS/FS/Setup.pm index d265d93..2b392e5 100644 --- a/FS/FS/Setup.pm +++ b/FS/FS/Setup.pm @@ -341,6 +341,10 @@ sub initial_data { #not yet.... #) + + #usage classes + 'usage_class' => [], + ; \%hash; diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index b4c79ea..fd62f64 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -106,6 +106,9 @@ sub upgrade_data { #replace invnum and pkgnum with billpkgnum 'cust_bill_pkg_detail' => [], + #usage_classes if we have none + 'usage_class' => [], + ; \%hash; diff --git a/FS/FS/rate_detail.pm b/FS/FS/rate_detail.pm index 533fb1e..a78ea82 100644 --- a/FS/FS/rate_detail.pm +++ b/FS/FS/rate_detail.pm @@ -49,6 +49,8 @@ inherits from FS::Record. The following fields are currently supported: =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 @@ sub check { || $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 @@ sub dest_prefixes_short { $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 diff --git a/FS/FS/usage_class.pm b/FS/FS/usage_class.pm new file mode 100644 index 0000000..053d398 --- /dev/null +++ b/FS/FS/usage_class.pm @@ -0,0 +1,143 @@ +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; + diff --git a/FS/MANIFEST b/FS/MANIFEST index 5dcd696..a6fe219 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -420,3 +420,5 @@ t/phone_avail.t FS/Yori.pm FS/cust_svc_option.pm t/cust_svc_option.t +FS/usage_class.pm +t/usage_class.t diff --git a/FS/t/usage_class.t b/FS/t/usage_class.t new file mode 100644 index 0000000..64fe98e --- /dev/null +++ b/FS/t/usage_class.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::usage_class; +$loaded=1; +print "ok 1\n"; |