#new
'cdrbatchnum', 'int', 'NULL', '', '', '',
+ # FK to cust_bill_pkg_detail; having a value here absolutely means
+ # that the CDR appears on an invoice
+ 'detailnum', 'bigint', 'NULL', '', '', '',
],
'primary_key' => 'acctid',
'unique' => [],
=item cdrbatch
+=item detailnum - Link to invoice detail (L<FS::cust_bill_pkg_detail>)
+
=back
=head1 METHODS
'freesiderewritestatus' => 'Freeside rewrite status',
'cdrbatch' => 'Legacy batch',
'cdrbatchnum' => 'Batch',
+ 'detailnum' => 'Freeside invoice detail line',
},
};
#check the foreign keys even?
#do we want to outright *reject* the CDR?
- my $error =
- $self->ut_numbern('acctid');
+ my $error = $self->ut_numbern('acctid');
+ return $error if $error;
+
+ if ( $self->freesidestatus ne 'done' ) {
+ $self->set('detailnum', ''); # can't have this on an unbilled call
+ }
#add a config option to turn these back on if someone needs 'em
#
# # Telstra =1, Optus = 2, RSL COM = 3
# || $self->ut_foreign_keyn('carrierid', 'cdr_carrier', 'carrierid' )
- return $error if $error;
-
$self->SUPER::check;
}
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
+=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
Delete this record from the database.
+=cut
+
+sub delete {
+ my $self = shift;
+ my $error = $self->SUPER::delete;
+ return $error if $error;
+ foreach my $cdr (qsearch('cdr', { detailnum => $self->detailnum })) {
+ $cdr->set('detailnum', '');
+ $error = $cdr->replace;
+ return "error unlinking CDR #" . $cdr->acctid . ": $error" if $error;
+ }
+}
+
=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
By default, this maps the following fields from the CDR:
+acctid => acctid
rated_price => amount
rated_classnum => classnum
rated_seconds => duration
$price = 0 if $cdr->freesidestatus eq 'no-charge';
FS::cust_bill_pkg_detail->new( {
+ 'acctid' => $cdr->acctid,
'amount' => $price,
'classnum' => $cdr->rated_classnum,
'duration' => $cdr->rated_seconds,
sub append {
my $self = shift;
my $svcnums = ($self->{svcnums} ||= {});
+ my $acctids = $self->{acctids} ||= [];
foreach my $cdr (@_) {
my $object = $self->{inbound} ? $cdr->cdr_termination(1) : $cdr;
my $svcnum = $object->svcnum; # yes, $object->svcnum.
$subtotal->{count}++;
$subtotal->{amount} += $object->rated_price
if $object->freesidestatus ne 'no-charge';
+
+ push @$acctids, $cdr->acctid;
}
}
startdate => '', #could use the earliest startdate in the bunch?
regionname => '', #no, we're using prefix instead
detail => $self->csv->string,
+ acctid => $self->{acctids},
});
} #foreach $svcnum
sub append {
my $self = shift;
my $svcnums = ($self->{svcnums} ||= {});
+ my $acctids = ($self->{acctids} ||= []);
foreach my $cdr (@_) {
my $object = $self->{inbound} ? $cdr->cdr_termination(1) : $cdr;
my $svcnum = $object->svcnum; # yes, $object->svcnum.
$subtotal->{duration} += $object->rated_seconds;
$subtotal->{amount} += $object->rated_price
if $object->freesidestatus ne 'no-charge';
+
+ push @$acctids, $cdr->acctid;
}
}
startdate => '', #could use the earliest startdate in the bunch?
regionname => '', #no, we're using prefix instead
detail => $self->csv->string,
+ acctid => $self->{acctids},
});
} #foreach $svcnum
sub append {
my $self = shift;
my $prefixes = ($self->{prefixes} ||= {});
+ my $acctids = ($self->{acctids} ||= []);
foreach my $cdr (@_) {
my (undef, $phonenum) = $cdr->parse_number(
column => ( $self->{inbound} ? 'src' : 'dst' ),
$subtotal->{duration} += $object->rated_seconds;
$subtotal->{amount} += $object->rated_price
if $object->freesidestatus ne 'no-charge';
+
+ push @$acctids, $cdr->acctid;
}
}
startdate => '', #could use the earliest startdate in the bunch?
regionname => '', #no, we're using prefix instead
detail => $self->csv->string,
+ acctid => $self->{acctids},
});
} #foreach $prefix
}