[freeside-commits] freeside/FS/FS phone_avail.pm, 1.4.8.10, 1.4.8.11 did_order_item.pm, 1.1.2.3, 1.1.2.4 did_order.pm, 1.1.2.6, 1.1.2.7 Schema.pm, 1.239.2.43, 1.239.2.44

Erik Levinson levinse at wavetail.420.am
Tue Jun 7 22:37:42 PDT 2011


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv9785/FS/FS

Modified Files:
      Tag: FREESIDE_2_1_BRANCH
	phone_avail.pm did_order_item.pm did_order.pm Schema.pm 
Log Message:
DID inventory/import / bulk DID orders - phase 2, RT12754

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.239.2.43
retrieving revision 1.239.2.44
diff -u -w -d -r1.239.2.43 -r1.239.2.44
--- Schema.pm	6 Jun 2011 23:43:50 -0000	1.239.2.43
+++ Schema.pm	8 Jun 2011 05:37:39 -0000	1.239.2.44
@@ -2927,6 +2927,7 @@
         'ratecenternum',      'int',     'NULL',      '', '', '',
         'state',       'char',    'NULL',       2, '', '', 
         'quantity',      'int',     '',      '', '', '',
+        'custnum',   'int', 'NULL', '', '', '',
       ],
       'primary_key' => 'orderitemnum',
       'unique' => [],

Index: did_order_item.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/did_order_item.pm,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -w -d -r1.1.2.3 -r1.1.2.4
--- did_order_item.pm	15 Apr 2011 03:09:50 -0000	1.1.2.3
+++ did_order_item.pm	8 Jun 2011 05:37:39 -0000	1.1.2.4
@@ -49,6 +49,8 @@
 
 =item quantity
 
+=item custnum - foreign key to cust_main table, optional
+
 =back
 
 =head1 METHODS
@@ -117,6 +119,7 @@
     || $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 @@
 
 =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
 

Index: did_order.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/did_order.pm,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -w -d -r1.1.2.6 -r1.1.2.7
--- did_order.pm	17 Apr 2011 03:28:12 -0000	1.1.2.6
+++ did_order.pm	8 Jun 2011 05:37:39 -0000	1.1.2.7
@@ -126,6 +126,59 @@
   $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 @@
 
 =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.

Index: phone_avail.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/phone_avail.pm,v
retrieving revision 1.4.8.10
retrieving revision 1.4.8.11
diff -u -w -d -r1.4.8.10 -r1.4.8.11



More information about the freeside-commits mailing list