From 71c6403be78e91e34d4124da35c9d0d284ad197d Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Sat, 4 May 2013 00:19:30 -0700 Subject: [PATCH] merging is now attaching, RT#22185 --- FS/FS/cust_main/Packages.pm | 34 +++++++++++++++++++++++-- FS/FS/cust_pkg.pm | 2 ++ httemplate/view/cust_main/packages/contact.html | 3 ++- httemplate/view/cust_main/packages/section.html | 12 ++++++++- httemplate/view/cust_main/packages/status.html | 7 +++-- 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm index e904cfd1f..41ef22894 100644 --- a/FS/FS/cust_main/Packages.pm +++ b/FS/FS/cust_main/Packages.pm @@ -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; diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index df5a4dc01..4464aa5a2 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -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, diff --git a/httemplate/view/cust_main/packages/contact.html b/httemplate/view/cust_main/packages/contact.html index 0c81eb39d..fe8b71534 100644 --- a/httemplate/view/cust_main/packages/contact.html +++ b/httemplate/view/cust_main/packages/contact.html @@ -6,6 +6,7 @@ % } % if ( $show_detach_link ) { + ( <%pkg_detach_link($cust_pkg)%> ) % } @@ -70,7 +71,7 @@ sub pkg_detach_link { 'actionlabel' => emt('Detach'), 'cust_pkg' => $cust_pkg, 'width' => 616, - 'height' => 676, + 'height' => 684, ); } diff --git a/httemplate/view/cust_main/packages/section.html b/httemplate/view/cust_main/packages/section.html index 5f54c0a36..391a13b5f 100755 --- a/httemplate/view/cust_main/packages/section.html +++ b/httemplate/view/cust_main/packages/section.html @@ -28,7 +28,7 @@ <& package.html, %iopt &> <& status.html, %iopt &> - <& contact.html, %iopt &> + <& contact.html, %iopt &>
<& location.html, %iopt &> <& 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') || '$' ), diff --git a/httemplate/view/cust_main/packages/status.html b/httemplate/view/cust_main/packages/status.html index 24a4dfcd0..c0213e90b 100644 --- a/httemplate/view/cust_main/packages/status.html +++ b/httemplate/view/cust_main/packages/status.html @@ -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 ). ''; + 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, -- 2.11.0