X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg_link.pm;h=5fe6f2f01411bece7dd229aee21265b134f694a6;hp=aee0131d233b429201dcfe850ba98e690dd2804e;hb=8d0e8149e7b19ad8543ac6c8c663be63dbc34762;hpb=67cef14ba963b2dab906d5e67095c8d1d3de43b5 diff --git a/FS/FS/part_pkg_link.pm b/FS/FS/part_pkg_link.pm index aee0131d2..5fe6f2f01 100644 --- a/FS/FS/part_pkg_link.pm +++ b/FS/FS/part_pkg_link.pm @@ -130,6 +130,7 @@ sub insert { return $error if $error; } + $dbh->commit if $oldAutoCommit; return; } @@ -166,10 +167,18 @@ sub delete { $dbh->rollback if $oldAutoCommit; return $error; } - $dbh->commit; + $dbh->commit if $oldAutoCommit; return; } +=item remove_linked + +Removes any supplemental packages that were created by this link, by canceling +them and setting their pkglinknum to null. This should be done in preparation +for removing the link itself. + +=cut + sub remove_linked { my $self = shift; my $pkglinknum = $self->pkglinknum; @@ -180,23 +189,11 @@ sub remove_linked { warn "expiring ".scalar(@pkgs). " linked packages from part_pkg_link #$pkglinknum\n"; - my $reason = qsearchs('reason', { reason => $cancel_reason_text }); - if (!$reason) { - # upgrade/FS::Setup created this one automatically - my $reason_type = qsearchs('reason_type', - { type => $cancel_reason_type } - ) or die "default cancel reason type does not exist"; - - $reason = FS::reason->new({ - reason_type => $reason_type->typenum, - reason => $cancel_reason_text, - disabled => 'Y', - }); - $error = $reason->insert; - if ( $error ) { - return "$error (creating package cancel reason)"; - } - } + my $reason = FS::reason->new_or_existing( + class => 'C', + type => $cancel_reason_type, + reason => $cancel_reason_text + ); foreach my $pkg (@pkgs) { $pkg->set('pkglinknum' => ''); @@ -253,12 +250,10 @@ sub check { my $dst_pkg = $self->dst_pkg; if ( $src_pkg->freq eq '0' and $dst_pkg->freq ne '0' ) { return "One-time charges can't have supplemental packages." - } elsif ( $dst_pkg->freq ne '0' ) { - my $ratio = $dst_pkg->freq / $src_pkg->freq; - if ($ratio != int($ratio)) { - return "Supplemental package period (pkgpart ".$dst_pkg->pkgpart. - ") must be an integer multiple of main package period."; - } + } elsif ( $dst_pkg->freq == 0 ) { + return "The billing period of a supplemental package must be a whole number of months."; + } elsif ( $src_pkg->freq == 0 ) { + return "To have supplemental packages, the billing period of a package must be a whole number of months."; } }