diff options
author | levinse <levinse> | 2011-06-08 05:38:55 +0000 |
---|---|---|
committer | levinse <levinse> | 2011-06-08 05:38:55 +0000 |
commit | 9a59cc9d51350d7eefb25697cd0d99188f686ea5 (patch) | |
tree | 76323a99701f5bd702663b228813c7b1b6a79c3b /FS/FS/did_order.pm | |
parent | c647fbae23dc64cdecb1c6fa6fee671cca7e8e7a (diff) |
DID inventory/import / bulk DID orders - phase 2, RT12754
Diffstat (limited to 'FS/FS/did_order.pm')
-rw-r--r-- | FS/FS/did_order.pm | 91 |
1 files changed, 88 insertions, 3 deletions
diff --git a/FS/FS/did_order.pm b/FS/FS/did_order.pm index c1b34c3..2404ad8 100644 --- a/FS/FS/did_order.pm +++ b/FS/FS/did_order.pm @@ -126,6 +126,59 @@ sub delete { $dbh->commit or die $dbh->errstr if $oldAutoCommit; } +=item merge SOURCE_ORDER + +Merges the DID order given by SOURCE_ORDER into THIS order. + +The following fields from the source order are transferred, only if they aren't +set in this order: +-vendor order # +-submitted +-confirmed +-customer + +DID order items are transferred into this order. + +The source order is deleted. + +The operation fails if: +-either order has a received time; or +-the DID vendors do not match between the orders + +=cut + +sub merge { + my $self = shift; + my $src = shift; + return "invalid source order" unless $src; + + return "DIDs received for either order" + if $src->received || $self->received; + + return "DID vendors do not match" + if $src->vendornum != $self->vendornum; + + my @move_if_unset = qw( vendor_order_id submitted confirmed custnum ); + foreach my $f ( @move_if_unset ) { + $self->$f($src->$f) if !$self->$f; + } + + my $error = ''; + my @did_order_items = qsearch('did_order_item', { 'ordernum' => $src->ordernum }); + foreach my $did_order_item ( @did_order_items ) { + $did_order_item->ordernum($self->ordernum); + $error = $did_order_item->replace; + return $error if $error; + } + + $error = $src->delete; + return $error if !$error; + + $error = $self->replace; + return $error if !$error; + + ''; +} =item replace OLD_RECORD @@ -176,16 +229,48 @@ sub did_order_item { =item cust_main -Returns the cust_main (see L<FS::cust_main>), if any, associated with this bulk DID order. +Returns all cust_main (see L<FS::cust_main>), 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 } ); + my @did_order_item = $self->did_order_item; + my @custnums; + push @custnums, $self->custnum if $self->custnum; + foreach my $did_order_item ( @did_order_item ) { + push @custnums, $did_order_item->custnum if $did_order_item->custnum; + } + my @cust_main; + foreach my $custnum ( @custnums ) { + push @cust_main, qsearchs('cust_main', { 'custnum' => $custnum } ); + } + @cust_main; +} + + +=item has_stock + +Returns true if and only if the order has any stock order items. + +=cut + +sub has_stock { + my $self = shift; + my $items_with_custnum = 0; + my @did_order_item = $self->did_order_item; + foreach my $did_order_item ( @did_order_item ) { + $items_with_custnum++ if $did_order_item->custnum; + } + + return 0 if ($items_with_custnum == scalar(@did_order_item) + && $items_with_custnum != 0 && !$self->custnum) + || $self->custnum; + 1; } + =item provisioned Returns the provisioned DIDs, if any, as phone_avail (see L<FS::phone_avail>) objects. |