- # find all packages that have the old location as their service address,
- # and aren't canceled,
- # and aren't supplemental to another package.
- my @pkgs = qsearch('cust_pkg', {
- 'locationnum' => $old->locationnum,
- 'cancel' => '',
- 'main_pkgnum' => '',
- });
- foreach my $cust_pkg (@pkgs) {
- # don't move one-time charges that have already been charged
- next if $cust_pkg->part_pkg->freq eq '0'
- and ($cust_pkg->setup || 0) > 0;
+ my @pkgs;
+ if ($opt{'move_pkgs'}) {
+ @pkgs = @{$opt{'move_pkgs'}};
+ my $pkgerr;
+ foreach my $pkg (@pkgs) {
+ my $pkgnum = $pkg->pkgnum;
+ $pkgerr = "cust_pkg $pkgnum has already been charged"
+ if $pkg->part_pkg->freq eq '0'
+ and ($pkg->setup || 0) > 0;
+ $pkgerr = "cust_pkg $pkgnum is supplemental"
+ if $pkg->main_pkgnum;
+ $pkgerr = "cust_pkg $pkgnum already cancelled"
+ if $pkg->cancel;
+ $pkgerr = "cust_pkg $pkgnum does not use this location"
+ unless $pkg->locationnum eq $old->locationnum;
+ last if $pkgerr;
+ }
+ if ($pkgerr) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Cannot update package location: $pkgerr";
+ }
+ } else {
+ @pkgs = $old->move_pkgs;
+ }