diff options
author | levinse <levinse> | 2011-04-15 03:04:13 +0000 |
---|---|---|
committer | levinse <levinse> | 2011-04-15 03:04:13 +0000 |
commit | 59be9ba7caf1009a97af97156bbd700bffb18fd4 (patch) | |
tree | c58f49cb73e529ec8ee77200918f2ca412f849ee /FS/FS | |
parent | f2cefba60adbf732299acda09d52024748665eef (diff) |
FS/FS/msa.pm
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/Schema.pm | 24 | ||||
-rw-r--r-- | FS/FS/did_order.pm | 40 | ||||
-rw-r--r-- | FS/FS/did_order_item.pm | 25 | ||||
-rw-r--r-- | FS/FS/rate_center.pm | 119 |
4 files changed, 184 insertions, 24 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index c9775fca8..37660f20b 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -3125,6 +3125,26 @@ sub tables_hashref { 'index' => [], }, + 'msa' => { + 'columns' => [ + 'msanum', 'int', '', '', '', '', + 'description', 'varchar', '', $char_d, '', '', + ], + 'primary_key' => 'msanum', + 'unique' => [], + 'index' => [], + }, + + 'rate_center' => { + 'columns' => [ + 'ratecenternum', 'serial', '', '', '', '', + 'description', 'varchar', '', $char_d, '', '', + ], + 'primary_key' => 'ratecenternum', + 'unique' => [], + 'index' => [], + }, + 'did_vendor' => { 'columns' => [ 'vendornum', 'serial', '', '', '', '', @@ -3139,10 +3159,10 @@ sub tables_hashref { 'columns' => [ 'orderitemnum', 'serial', '', '', '', '', 'ordernum', 'int', '', '', '', '', - 'msa', 'varchar', 'NULL', $char_d, '', '', + 'msanum', 'int', 'NULL', '', '', '', 'npa', 'int', 'NULL', '', '', '', 'latanum', 'int', 'NULL', '', '', '', - 'ratecenter', 'varchar', 'NULL', $char_d, '', '', + 'ratecenternum', 'int', 'NULL', '', '', '', 'state', 'char', 'NULL', 2, '', '', 'quantity', 'int', '', '', '', '', ], diff --git a/FS/FS/did_order.pm b/FS/FS/did_order.pm index adc965f91..b138192f8 100644 --- a/FS/FS/did_order.pm +++ b/FS/FS/did_order.pm @@ -2,7 +2,7 @@ package FS::did_order; use strict; use base qw( FS::o2m_Common FS::Record ); -use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( qsearch qsearchs dbh ); =head1 NAME @@ -89,7 +89,43 @@ Delete this record from the database. =cut -# the delete method can be inherited from FS::Record +sub delete { + my $self = shift; + + return "Can't delete a DID order which has DIDs received" + if qsearch( 'phone_avail', { 'ordernum' => $self->ordernum } ); + + 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; + + my @did_order_item = $self->did_order_item; + + foreach my $did_order_item ( @did_order_item ) { + my $error = $did_order_item->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "can't delete DID order item " + . $did_order_item->orderitemnum . ": $error"; + } + } + + my $error = $self->SUPER::delete(@_); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; +} + =item replace OLD_RECORD diff --git a/FS/FS/did_order_item.pm b/FS/FS/did_order_item.pm index 4408c50f5..c2d657ad8 100644 --- a/FS/FS/did_order_item.pm +++ b/FS/FS/did_order_item.pm @@ -37,33 +37,18 @@ primary key =item ordernum -ordernum - -=item msa - -msa +=item msanum - foreign key to msa table =item npa -npa - -=item latanum - -latanum +=item latanum - foreign key to lata table -=item rate_center - -rate_center +=item ratecenternum - foreign key to rate_center table =item state -state - =item quantity -quantity - - =back =head1 METHODS @@ -126,10 +111,10 @@ sub check { my $error = $self->ut_numbern('orderitemnum') || $self->ut_number('ordernum') - || $self->ut_textn('msa') + || $self->ut_foreign_keyn('msanum', 'msa', 'msanum') || $self->ut_numbern('npa') || $self->ut_foreign_keyn('latanum', 'lata', 'latanum') - || $self->ut_textn('rate_center') + || $self->ut_foreign_keyn('ratecenternum', 'rate_center', 'ratecenternum') || $self->ut_textn('state') || $self->ut_number('quantity') ; diff --git a/FS/FS/rate_center.pm b/FS/FS/rate_center.pm new file mode 100644 index 000000000..d566b63a4 --- /dev/null +++ b/FS/FS/rate_center.pm @@ -0,0 +1,119 @@ +package FS::rate_center; + +use strict; +use base qw( FS::Record ); +use FS::Record qw( qsearch qsearchs ); + +=head1 NAME + +FS::rate_center - Object methods for rate_center records + +=head1 SYNOPSIS + + use FS::rate_center; + + $record = new FS::rate_center \%hash; + $record = new FS::rate_center { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::rate_center object represents an rate center. FS::rate_center inherits from +FS::Record. The following fields are currently supported: + +=over 4 + +=item ratecenternum + +primary key + +=item description + +description + + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new rate center. To add the rate center 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 + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'rate_center'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +# the insert method can be inherited from FS::Record + +=item delete + +Delete this record from the database. + +=cut + +# the delete method can be inherited from FS::Record + +=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 + +# the replace method can be inherited from FS::Record + +=item check + +Checks all fields to make sure this is a valid rate center. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +# the check method should currently be supplied - FS::Record contains some +# data checking routines + +sub check { + my $self = shift; + + my $error = + $self->ut_numbern('ratecenternum') + || $self->ut_text('description') + ; + return $error if $error; + + $self->SUPER::check; +} + +=back + +=head1 SEE ALSO + +L<FS::Record>, schema.html from the base documentation. + +=cut + +1; + |