summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-08-16 20:56:07 -0700
committerMark Wells <mark@freeside.biz>2016-08-16 20:56:13 -0700
commit13f66d3743bbb7be4fb87854636598aae0934815 (patch)
treedb6c90194afd5a74dca8695a0122ea8539a59535
parentf10cc704ae52f6d1982e50a4b9a00385a40fa19f (diff)
respect granularity settings for display of inbound call duration, #71715
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/cdr.pm5
-rw-r--r--FS/FS/cdr_termination.pm9
-rw-r--r--FS/FS/detail_format.pm17
-rw-r--r--FS/FS/part_pkg/voip_inbound.pm9
5 files changed, 26 insertions, 15 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index b09266b..8a04106 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -5619,6 +5619,7 @@ sub tables_hashref {
'rated_price', 'decimal', 'NULL', '10,4', '', '',
'rated_seconds', 'int', 'NULL', '', '', '',
'rated_minutes', 'double precision', 'NULL', '', '', '',
+ 'rated_granularity','int', 'NULL', '', '', '',
'status', 'varchar', 'NULL', 32, '', '',
'svcnum', 'int', 'NULL', '', '', '',
],
diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm
index d3d62e0..155090d 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -507,8 +507,9 @@ sub set_status_and_rated_price {
rated_price => $rated_price,
status => $status,
});
- $term->rated_seconds($opt{rated_seconds}) if exists($opt{rated_seconds});
- $term->rated_minutes($opt{rated_minutes}) if exists($opt{rated_minutes});
+ foreach (qw(rated_seconds rated_minutes rated_granularity)) {
+ $term->set($_, $opt{$_}) if exists($opt{$_});
+ }
$term->svcnum($svcnum) if $svcnum;
return $term->insert;
diff --git a/FS/FS/cdr_termination.pm b/FS/FS/cdr_termination.pm
index 0209f0d..3c1f453 100644
--- a/FS/FS/cdr_termination.pm
+++ b/FS/FS/cdr_termination.pm
@@ -47,6 +47,12 @@ termpart
rated_price
+=item rated_seconds
+
+=item rated_minutes
+
+=item rated_granularity
+
=item status
status
@@ -120,6 +126,9 @@ sub check {
#|| $self->ut_foreign_key('termpart', 'part_termination', 'termpart')
|| $self->ut_number('termpart')
|| $self->ut_floatn('rated_price')
+ || $self->ut_numbern('rated_seconds')
+ || $self->ut_floatn('rated_minutes')
+ || $self->ut_numbern('rated_granularity')
|| $self->ut_enum('status', [ '', 'processing-tiered', 'done' ] ) # , 'skipped' ] )
;
return $error if $error;
diff --git a/FS/FS/detail_format.pm b/FS/FS/detail_format.pm
index d032100..78517dd 100644
--- a/FS/FS/detail_format.pm
+++ b/FS/FS/detail_format.pm
@@ -186,6 +186,11 @@ rated_regionname => regionname
accountcode => accountcode
startdate => startdate
+If the formatter is in inbound mode, it will look up a C<cdr_termination>
+record and use rated_price and rated_seconds from that, and acctid will be
+set to null to avoid linking the CDR to the detail record for the inbound
+leg of the call.
+
'phonenum' is set to the internal C<phonenum> value set on the formatter
object.
@@ -209,10 +214,10 @@ sub single_detail {
$price = 0 if $cdr->freesidestatus eq 'no-charge';
FS::cust_bill_pkg_detail->new( {
- 'acctid' => $cdr->acctid,
+ 'acctid' => ($self->{inbound} ? '' : $cdr->acctid),
'amount' => $price,
'classnum' => $cdr->rated_classnum,
- 'duration' => $cdr->rated_seconds,
+ 'duration' => $object->rated_seconds,
'regionname' => $cdr->rated_regionname,
'accountcode' => $cdr->accountcode,
'startdate' => $cdr->startdate,
@@ -280,13 +285,11 @@ sub duration {
my $object = $self->{inbound} ? $cdr->cdr_termination(1) : $cdr;
my $sec = $object->rated_seconds if $object;
$sec ||= 0;
- # XXX termination objects don't have rated_granularity so this may
- # result in inbound CDRs being displayed as min/sec when they shouldn't.
- # Should probably fix this.
- if ( $cdr->rated_granularity eq '0' ) {
+ # termination objects now have rated_granularity.
+ if ( $object->rated_granularity eq '0' ) {
'1 call';
}
- elsif ( $cdr->rated_granularity eq '60' ) {
+ elsif ( $object->rated_granularity eq '60' ) {
sprintf('%dm', ($sec + 59)/60);
}
else {
diff --git a/FS/FS/part_pkg/voip_inbound.pm b/FS/FS/part_pkg/voip_inbound.pm
index 81f2765..e911439 100644
--- a/FS/FS/part_pkg/voip_inbound.pm
+++ b/FS/FS/part_pkg/voip_inbound.pm
@@ -292,10 +292,7 @@ sub calc_usage {
my @call_details = (
$cdr->downstream_csv( 'format' => $output_format,
'charge' => $charge,
- 'seconds' => ($use_duration
- ? $cdr->duration
- : $cdr->billsec
- ),
+ 'seconds' => $seconds,
'granularity' => $granularity,
)
);
@@ -317,10 +314,10 @@ sub calc_usage {
'done',
$charge,
$cust_svc->svcnum,
- 'rated_seconds' => $use_duration ? $cdr->duration : $cdr->billsec,
+ 'rated_seconds' => $seconds,
'rated_granularity' => $granularity,
'rated_classnum' => $cdr->calltypenum,
- 'inbound' => 1,
+ 'inbound' => 1, # to update cdr_termination, not cdr
);
die $error if $error;
$formatter->append($cdr);