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;
129 =item merge SOURCE_ORDER
131 Merges the DID order given by SOURCE_ORDER into THIS order.
133 The following fields from the source order are transferred, only if they aren't
140 DID order items are transferred into this order.
142 The source order is deleted.
144 The operation fails if:
145 -either order has a received time; or
146 -the DID vendors do not match between the orders
153 return "invalid source order" unless $src;
155 return "DIDs received for either order"
156 if $src->received || $self->received;
158 return "DID vendors do not match"
159 if $src->vendornum != $self->vendornum;
161 my @move_if_unset = qw( vendor_order_id submitted confirmed custnum );
162 foreach my $f ( @move_if_unset ) {
163 $self->$f($src->$f) if !$self->$f;
167 my @did_order_items = qsearch('did_order_item', { 'ordernum' => $src->ordernum });
168 foreach my $did_order_item ( @did_order_items ) {
169 $did_order_item->ordernum($self->ordernum);
170 $error = $did_order_item->replace;
171 return $error if $error;
174 $error = $src->delete;
175 return $error if !$error;
177 $error = $self->replace;
178 return $error if !$error;
183 =item replace OLD_RECORD
185 Replaces the OLD_RECORD with this one in the database. If there is an error,
186 returns the error, otherwise returns false.
190 # the replace method can be inherited from FS::Record
194 Checks all fields to make sure this is a valid bulk DID order. If there is
195 an error, returns the error, otherwise returns false. Called by the insert
200 # the check method should currently be supplied - FS::Record contains some
201 # data checking routines
207 $self->ut_numbern('ordernum')
208 || $self->ut_foreign_key('vendornum', 'did_vendor', 'vendornum' )
209 || $self->ut_textn('vendor_order_id')
210 || $self->ut_number('submitted')
211 || $self->ut_numbern('confirmed')
212 || $self->ut_numbern('received')
214 return $error if $error;
221 Returns the did_order_items (see L<FS::did_order_item>) associated with this bulk DID order.
227 qsearch( 'did_order_item', { 'ordernum' => $self->ordernum } );
232 Returns all cust_main (see L<FS::cust_main>), if any, associated with this
239 my @did_order_item = $self->did_order_item;
241 push @custnums, $self->custnum if $self->custnum;
242 foreach my $did_order_item ( @did_order_item ) {
243 push @custnums, $did_order_item->custnum if $did_order_item->custnum;
246 foreach my $custnum ( @custnums ) {
247 push @cust_main, qsearchs('cust_main', { 'custnum' => $custnum } );
255 Returns true if and only if the order has any stock order items.
261 my $items_with_custnum = 0;
262 my @did_order_item = $self->did_order_item;
263 foreach my $did_order_item ( @did_order_item ) {
264 $items_with_custnum++ if $did_order_item->custnum;
267 return 0 if ($items_with_custnum == scalar(@did_order_item)
268 && $items_with_custnum != 0 && !$self->custnum)
276 Returns the provisioned DIDs, if any, as phone_avail (see L<FS::phone_avail>) objects.
282 qsearch({ table => 'phone_avail',
283 hashref => { 'ordernum' => $self->ordernum, },
284 select => 'phone_avail.*',
285 extra_sql => ' and svcnum is not null ',
293 L<FS::Record>, schema.html from the base documentation.