summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2016-01-29 15:14:17 -0600
committerJonathan Prykop <jonathan@freeside.biz>2016-01-29 15:14:17 -0600
commit5773eb8d8b4168213482a7e61aa37e0dd05c69da (patch)
tree47a8856cbadc19eba89a59e8b10b299631112317
parent488d3c15c9aaea2a17826600ee332f0af9b0634d (diff)
RT#39638 [selective v3 backport of commit 7516e3da0f17eeecba27219ef96a8b5f46af2083, link cdr to cust_bill_pkg_detail]
-rw-r--r--FS/FS/Schema.pm3
-rw-r--r--FS/FS/cdr.pm13
-rw-r--r--FS/FS/cust_bill_pkg_detail.pm37
-rw-r--r--FS/FS/detail_format.pm2
-rw-r--r--FS/FS/detail_format/sum_count.pm4
-rw-r--r--FS/FS/detail_format/sum_duration.pm4
-rw-r--r--FS/FS/detail_format/sum_duration_prefix.pm4
7 files changed, 63 insertions, 4 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index cd05be36f..a71b90249 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -3844,6 +3844,9 @@ sub tables_hashref {
#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' => [],
diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm
index 5a1d8ea23..8ccf7af63 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -161,6 +161,8 @@ following fields are currently supported:
=item cdrbatch
+=item detailnum - Link to invoice detail (L<FS::cust_bill_pkg_detail>)
+
=back
=head1 METHODS
@@ -227,6 +229,7 @@ sub table_info {
'freesiderewritestatus' => 'Freeside rewrite status',
'cdrbatch' => 'Legacy batch',
'cdrbatchnum' => 'Batch',
+ 'detailnum' => 'Freeside invoice detail line',
},
};
@@ -338,8 +341,12 @@ sub check {
#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
#
@@ -352,8 +359,6 @@ sub check {
# # Telstra =1, Optus = 2, RSL COM = 3
# || $self->ut_foreign_keyn('carrierid', 'cdr_carrier', 'carrierid' )
- return $error if $error;
-
$self->SUPER::check;
}
diff --git a/FS/FS/cust_bill_pkg_detail.pm b/FS/FS/cust_bill_pkg_detail.pm
index d0cbdbec0..dd118c1b2 100644
--- a/FS/FS/cust_bill_pkg_detail.pm
+++ b/FS/FS/cust_bill_pkg_detail.pm
@@ -86,15 +86,52 @@ sub table { 'cust_bill_pkg_detail'; }
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
diff --git a/FS/FS/detail_format.pm b/FS/FS/detail_format.pm
index 8840a006d..be84680f9 100644
--- a/FS/FS/detail_format.pm
+++ b/FS/FS/detail_format.pm
@@ -178,6 +178,7 @@ Takes a single CDR and returns an invoice detail to describe it.
By default, this maps the following fields from the CDR:
+acctid => acctid
rated_price => amount
rated_classnum => classnum
rated_seconds => duration
@@ -208,6 +209,7 @@ sub single_detail {
$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,
diff --git a/FS/FS/detail_format/sum_count.pm b/FS/FS/detail_format/sum_count.pm
index c40fcb8fe..253956f0d 100644
--- a/FS/FS/detail_format/sum_count.pm
+++ b/FS/FS/detail_format/sum_count.pm
@@ -24,6 +24,7 @@ sub header_detail {
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.
@@ -33,6 +34,8 @@ sub append {
$subtotal->{count}++;
$subtotal->{amount} += $object->rated_price
if $object->freesidestatus ne 'no-charge';
+
+ push @$acctids, $cdr->acctid;
}
}
@@ -68,6 +71,7 @@ sub finish {
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
diff --git a/FS/FS/detail_format/sum_duration.pm b/FS/FS/detail_format/sum_duration.pm
index 1b967b407..c41bed385 100644
--- a/FS/FS/detail_format/sum_duration.pm
+++ b/FS/FS/detail_format/sum_duration.pm
@@ -24,6 +24,7 @@ sub header_detail {
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.
@@ -34,6 +35,8 @@ sub append {
$subtotal->{duration} += $object->rated_seconds;
$subtotal->{amount} += $object->rated_price
if $object->freesidestatus ne 'no-charge';
+
+ push @$acctids, $cdr->acctid;
}
}
@@ -70,6 +73,7 @@ sub finish {
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
diff --git a/FS/FS/detail_format/sum_duration_prefix.pm b/FS/FS/detail_format/sum_duration_prefix.pm
index cd7bbe3cc..3c33dc163 100644
--- a/FS/FS/detail_format/sum_duration_prefix.pm
+++ b/FS/FS/detail_format/sum_duration_prefix.pm
@@ -24,6 +24,7 @@ my $prefix_length = 6;
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' ),
@@ -52,6 +53,8 @@ sub append {
$subtotal->{duration} += $object->rated_seconds;
$subtotal->{amount} += $object->rated_price
if $object->freesidestatus ne 'no-charge';
+
+ push @$acctids, $cdr->acctid;
}
}
@@ -91,6 +94,7 @@ sub finish {
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
}