X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fdid_order.pm;h=c1b34c345ace12ee435e122875058a3a52bed7d0;hb=2705b64bb669ba94492a185410e8d67f6ea82edd;hp=f46d72bf8c29e754ed27c5f23c001c4ad46d41fe;hpb=31f2e890b5b3e1b0ad29a877ff67bc641ea1fc40;p=freeside.git diff --git a/FS/FS/did_order.pm b/FS/FS/did_order.pm index f46d72bf8..c1b34c345 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 @@ -138,6 +174,32 @@ sub did_order_item { qsearch( 'did_order_item', { 'ordernum' => $self->ordernum } ); } +=item cust_main + +Returns the cust_main (see L), if any, associated with this bulk DID order. + +=cut + +sub cust_main { + my $self = shift; + return '' unless $self->custnum; + qsearchs('cust_main', { 'custnum' => $self->custnum } ); +} + +=item provisioned + +Returns the provisioned DIDs, if any, as phone_avail (see L) objects. + +=cut + +sub provisioned { + my $self = shift; + qsearch({ table => 'phone_avail', + hashref => { 'ordernum' => $self->ordernum, }, + select => 'phone_avail.*', + extra_sql => ' and svcnum is not null ', + }); +} =back