4 use base qw( FS::o2m_Common FS::Record );
5 use FS::Record qw( qsearch qsearchs dbh );
9 FS::did_order - Object methods for did_order records
15 $record = new FS::did_order \%hash;
16 $record = new FS::did_order { 'column' => 'value' };
18 $error = $record->insert;
20 $error = $new_record->replace($old_record);
22 $error = $record->delete;
24 $error = $record->check;
28 An FS::did_order object represents a bulk DID order. FS::did_order inherits from
29 FS::Record. The following fields are currently supported:
66 Creates a new bulk DID order. To add it to the database, see L<"insert">.
68 Note that this stores the hash reference, not a distinct copy of the hash it
69 points to. You can ask the object for a copy with the I<hash> method.
73 # the new method can be inherited from FS::Record, if a table method is defined
75 sub table { 'did_order'; }
79 Adds this record to the database. If there is an error, returns the error,
80 otherwise returns false.
84 # the insert method can be inherited from FS::Record
88 Delete this record from the database.
95 return "Can't delete a DID order which has DIDs received"
96 if qsearch( 'phone_avail', { 'ordernum' => $self->ordernum } );
98 local $SIG{HUP} = 'IGNORE';
99 local $SIG{INT} = 'IGNORE';
100 local $SIG{QUIT} = 'IGNORE';
101 local $SIG{TERM} = 'IGNORE';
102 local $SIG{TSTP} = 'IGNORE';
103 local $SIG{PIPE} = 'IGNORE';
105 my $oldAutoCommit = $FS::UID::AutoCommit;
106 local $FS::UID::AutoCommit = 0;
109 my @did_order_item = $self->did_order_item;
111 foreach my $did_order_item ( @did_order_item ) {
112 my $error = $did_order_item->delete;
114 $dbh->rollback if $oldAutoCommit;
115 return "can't delete DID order item "
116 . $did_order_item->orderitemnum . ": $error";
120 my $error = $self->SUPER::delete(@_);
122 $dbh->rollback if $oldAutoCommit;
126 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
130 =item replace OLD_RECORD
132 Replaces the OLD_RECORD with this one in the database. If there is an error,
133 returns the error, otherwise returns false.
137 # the replace method can be inherited from FS::Record
141 Checks all fields to make sure this is a valid bulk DID order. If there is
142 an error, returns the error, otherwise returns false. Called by the insert
147 # the check method should currently be supplied - FS::Record contains some
148 # data checking routines
154 $self->ut_numbern('ordernum')
155 || $self->ut_foreign_key('vendornum', 'did_vendor', 'vendornum' )
156 || $self->ut_textn('vendor_order_id')
157 || $self->ut_number('submitted')
158 || $self->ut_numbern('confirmed')
159 || $self->ut_numbern('received')
161 return $error if $error;
168 Returns the did_order_items (see L<FS::did_order_item>) associated with this bulk DID order.
174 qsearch( 'did_order_item', { 'ordernum' => $self->ordernum } );
179 Returns the cust_main (see L<FS::cust_main>), if any, associated with this bulk DID order.
185 return '' unless $self->custnum;
186 qsearchs('cust_main', { 'custnum' => $self->custnum } );
191 Returns the provisioned DIDs, if any, as phone_avail (see L<FS::phone_avail>) objects.
197 qsearch({ table => 'phone_avail',
198 hashref => { 'ordernum' => $self->ordernum, },
199 select => 'phone_avail.*',
200 extra_sql => ' and svcnum is not null ',
208 L<FS::Record>, schema.html from the base documentation.