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 | |
parent | c647fbae23dc64cdecb1c6fa6fee671cca7e8e7a (diff) |
DID inventory/import / bulk DID orders - phase 2, RT12754
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/Schema.pm | 1 | ||||
-rw-r--r-- | FS/FS/did_order.pm | 91 | ||||
-rw-r--r-- | FS/FS/did_order_item.pm | 5 | ||||
-rw-r--r-- | FS/FS/phone_avail.pm | 16 |
4 files changed, 101 insertions, 12 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 9d03ce3..eebcfec 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -3184,6 +3184,7 @@ sub tables_hashref { 'ratecenternum', 'int', 'NULL', '', '', '', 'state', 'char', 'NULL', 2, '', '', 'quantity', 'int', '', '', '', '', + 'custnum', 'int', 'NULL', '', '', '', ], 'primary_key' => 'orderitemnum', 'unique' => [], 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. diff --git a/FS/FS/did_order_item.pm b/FS/FS/did_order_item.pm index c2d657a..235e00e 100644 --- a/FS/FS/did_order_item.pm +++ b/FS/FS/did_order_item.pm @@ -49,6 +49,8 @@ primary key =item quantity +=item custnum - foreign key to cust_main table, optional + =back =head1 METHODS @@ -117,6 +119,7 @@ sub check { || $self->ut_foreign_keyn('ratecenternum', 'rate_center', 'ratecenternum') || $self->ut_textn('state') || $self->ut_number('quantity') + || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum') ; return $error if $error; @@ -127,7 +130,7 @@ sub check { =head1 SEE ALSO -L<FS::Record>, schema.html from the base documentation. +L<FS::did_order>, <FS::Record>, schema.html from the base documentation. =cut diff --git a/FS/FS/phone_avail.pm b/FS/FS/phone_avail.pm index b726d34..44421ff 100644 --- a/FS/FS/phone_avail.pm +++ b/FS/FS/phone_avail.pm @@ -226,14 +226,14 @@ sub process_batch_import { 'postinsert_callback' => sub { my $record = shift; if($record->ordernum) { - my $did_order = qsearchs('did_order', - { 'ordernum' => $record->ordernum } ); - if($did_order && !$did_order->received) { - $did_order->received(time); - $did_order->confirmed(parse_datetime($record->confirmed)); - $did_order->vendor_order_id($record->vendor_order_id); - $did_order->replace; - } + my $did_order = qsearchs('did_order', + { 'ordernum' => $record->ordernum } ); + if($did_order && !$did_order->received) { + $did_order->received(time); + $did_order->confirmed(parse_datetime($record->confirmed)); + $did_order->vendor_order_id($record->vendor_order_id); + $did_order->replace; + } } }, }; |