merging is now attaching, RT#22185
authorIvan Kohler <ivan@freeside.biz>
Sat, 4 May 2013 07:19:30 +0000 (00:19 -0700)
committerIvan Kohler <ivan@freeside.biz>
Sat, 4 May 2013 07:19:30 +0000 (00:19 -0700)
FS/FS/cust_main/Packages.pm
FS/FS/cust_pkg.pm
httemplate/view/cust_main/packages/contact.html
httemplate/view/cust_main/packages/section.html
httemplate/view/cust_main/packages/status.html

index e904cfd..41ef228 100644 (file)
@@ -7,6 +7,8 @@ use FS::UID qw( dbh );
 use FS::Record qw( qsearch qsearchs );
 use FS::cust_pkg;
 use FS::cust_svc;
+use FS::contact;       # for attach_pkgs
+use FS::cust_location; #
 
 $DEBUG = 0;
 $me = '[FS::cust_main::Packages]';
@@ -344,11 +346,39 @@ sub attach_pkgs {
 
   #end of false laziness
 
+  #pull in contact
+
+  my %contact_hash = ( 'first'    => $self->first,
+                       'last'     => $self->get('last'),
+                       'custnum'  => $new_custnum,
+                       'disabled' => '',
+                     );
+
+  my $contact = qsearchs(  'contact', \%contact_hash)
+                 || new FS::contact   \%contact_hash;
+  unless ( $contact->contactnum ) {
+    my $error = $contact->insert;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
   foreach my $cust_pkg ( $self->ncancelled_pkgs ) {
 
+    my $cust_location = $cust_pkg->cust_location || $self->ship_location;
+    my %loc_hash = $cust_location->hash;
+    $loc_hash{'locationnum'} = '';
+    $loc_hash{'custnum'}     = $new_custnum;
+    $loc_hash{'disabled'}    = '';
+    my $new_cust_location = qsearchs(  'cust_location', \%loc_hash)
+                             || new FS::cust_location   \%loc_hash;
+
     my $pkg_or_error = $cust_pkg->change( {
-      'keep_dates' => 1,
-      'cust_main'  => $new_cust_main,
+      'keep_dates'    => 1,
+      'cust_main'     => $new_cust_main,
+      'contactnum'    => $contact->contactnum,
+      'cust_location' => $new_cust_location,
     } );
 
     my $error = ref($pkg_or_error) ? '' : $pkg_or_error;
index df5a4dc..4464aa5 100644 (file)
@@ -1837,6 +1837,8 @@ sub change {
     $custnum = $cust_main->custnum;
   }
 
+  $hash{'contactnum'} = $opt->{'contactnum'} if $opt->{'contactnum'};
+
   # Create the new package.
   my $cust_pkg = new FS::cust_pkg {
     custnum        => $custnum,
index 0c81eb3..fe8b715 100644 (file)
@@ -6,6 +6,7 @@
         </FONT>
 % }
 % if ( $show_detach_link ) {
+        <FONT SIZE=-1>
           (&nbsp;<%pkg_detach_link($cust_pkg)%>&nbsp;)
         </FONT>
 %    }
@@ -70,7 +71,7 @@ sub pkg_detach_link {
     'actionlabel' => emt('Detach'),
     'cust_pkg'    => $cust_pkg,
     'width'       => 616,
-    'height'      => 676,
+    'height'      => 684,
   );
 }
 
index 5f54c0a..391a13b 100755 (executable)
@@ -28,7 +28,7 @@
     <& package.html, %iopt &>
     <& status.html,  %iopt &>
     <TD CLASS="inv" BGCOLOR="<% $iopt{bgcolor} %>" WIDTH="20%" VALIGN="top">
-      <& contact.html, %iopt &>
+      <& contact.html, %iopt &><BR>
       <& location.html, %iopt &>
     </TD>
     <& services.html, %iopt &>
@@ -59,6 +59,15 @@ my $packages = $opt{'packages'};
   ( $a->getfield('pkgnum') <=> $b->getfield('pkgnum') )
 } @$packages;
 
+my %change_custnum = map { $_->change_custnum => 1 }
+                       grep { $_->change_custnum }
+                         grep { $_->getfield('cancel') }
+                           @$packages;
+
+my $pkg_attached = ( scalar(keys %change_custnum) == 1
+                       && ! grep { ! $_->getfield('cancel') } @$packages
+                   );
+
 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';  
 
 my %conf_opt = (
@@ -67,6 +76,7 @@ my %conf_opt = (
                                  || $curuser->option('cust_pkg-display_times')),
   #for status.html
   'cust_pkg-show_autosuspend' => $conf->exists('cust_pkg-show_autosuspend'),
+  'pkg_attached'              => $pkg_attached,
   #for status.html pkg-balances
   'pkg-balances'              => $conf->exists('pkg-balances'),
   'money_char'                => ( $conf->config('money_char') || '$' ),
index 24a4dfc..c0213e9 100644 (file)
@@ -365,9 +365,6 @@ sub pkg_status_row_changed {
 sub pkg_status_row_detached {
   my( $cust_pkg, %opt ) = @_;
 
-warn $cust_pkg->pkgnum;
-warn $cust_pkg->change_custnum;
-
   return '' unless $cust_pkg->change_custnum;
 
   my $html = '';
@@ -379,8 +376,10 @@ warn $cust_pkg->change_custnum;
                       encode_entities( $cust_main->name ).
                     '</A>';
 
+    my $what = $opt{'pkg_attached'} ? 'Attached' : 'Detached';
+
     $html .= pkg_status_row_colspan( $cust_pkg, 
-                                     emt("Detached to customer #[_1]: ",
+                                     emt("$what to customer #[_1]: ",
                                             $cust_pkg->change_custnum
                                         ).
                                        $cust_link,