X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_bill_pkg_detail.pm;h=19b15f7dddee20cb5b97b579c5c2677411095e04;hp=d0cbdbec001fc57658234cccde95785e08128405;hb=908b5627cc5899b00d3b9e83602403eb956dd038;hpb=c2f7d8ba623194ad1fae37b231b2e29b33d05674 diff --git a/FS/FS/cust_bill_pkg_detail.pm b/FS/FS/cust_bill_pkg_detail.pm index d0cbdbec0..19b15f7dd 100644 --- a/FS/FS/cust_bill_pkg_detail.pm +++ b/FS/FS/cust_bill_pkg_detail.pm @@ -86,15 +86,68 @@ sub table { 'cust_bill_pkg_detail'; } Adds this record to the database. If there is an error, returns the error, otherwise returns false. -=item delete +=cut + +sub insert { + my $self = shift; + my $error = $self->SUPER::insert(@_); + return $error if $error; + + # link CDRs + my $acctids = $self->get('acctid') or return ''; + $acctids = [ $acctids ] unless ref $acctids; + foreach my $acctid ( @$acctids ) { + my $cdr = FS::cdr->by_key($acctid); + $cdr->set('detailnum', $self->detailnum); + $error = $cdr->replace; + # this should never happen + return "error linking CDR #$acctid: $error" if $error; + } + ''; +} + +=item delete [ ARG => VALUE ... ] Delete this record from the database. +If the "reprocess_cdrs" argument is set to true, resets the status of any +related CDRs (and deletes their associated cdr_termination records, if any). + +=cut + +sub delete { + my( $self, %args ) = @_; + + my $error = $self->SUPER::delete; + return $error if $error; + + foreach my $cdr (qsearch('cdr', { detailnum => $self->detailnum })) { + + $cdr->set('detailnum', ''); + $cdr->set('freesidestatus', '') if $args{'reprocess_cdrs'}; + $error = $cdr->replace; + return "error unlinking CDR #" . $cdr->acctid . ": $error" if $error; + + #well, technically this could have been on other invoices / termination + # partners... separate flag? + $self->scalar_sql( 'DELETE FROM cdr_termination WHERE acctid = ?', + $cdr->acctid ) + if $args{'reprocess_cdrs'}; + + } + + ''; +} + =item replace OLD_RECORD Replaces the OLD_RECORD with this one in the database. If there is an error, returns the error, otherwise returns false. +=cut + +# the replace method can be inherited from FS::Record (doesn't touch CDRs) + =item check Checks all fields to make sure this is a valid line item detail. If there is