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]';
#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;
$custnum = $cust_main->custnum;
}
+ $hash{'contactnum'} = $opt->{'contactnum'} if $opt->{'contactnum'};
+
# Create the new package.
my $cust_pkg = new FS::cust_pkg {
custnum => $custnum,
</FONT>
% }
% if ( $show_detach_link ) {
+ <FONT SIZE=-1>
( <%pkg_detach_link($cust_pkg)%> )
</FONT>
% }
'actionlabel' => emt('Detach'),
'cust_pkg' => $cust_pkg,
'width' => 616,
- 'height' => 676,
+ 'height' => 684,
);
}
<& 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 &>
( $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 = (
|| $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') || '$' ),
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 = '';
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,