summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Report/Table.pm42
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/cdr.pm8
3 files changed, 44 insertions, 7 deletions
diff --git a/FS/FS/Report/Table.pm b/FS/FS/Report/Table.pm
index eeb99bac5..5fb56404d 100644
--- a/FS/FS/Report/Table.pm
+++ b/FS/FS/Report/Table.pm
@@ -599,6 +599,10 @@ sub _cust_bill_pkg_recurring {
$self->in_time_period_and_agent($speriod, $eperiod, $agentnum, $_date);
}
+ if ( $opt{'custnum'} =~ /^(\d+)$/ ) {
+ push @where, "(cust_main.custnum = $1)";
+ }
+
return "
FROM $cust_bill_pkg
$cust_bill_pkg_join
@@ -606,6 +610,16 @@ sub _cust_bill_pkg_recurring {
}
+=item cust_bill_pkg_recur: the total recur charges
+
+Most arguments as for C<cust_bill_pkg>, plus:
+
+'custnum': limit to this customer
+
+'cost': if true, return total recur costs instead
+
+=cut
+
sub cust_bill_pkg_recur {
my $self = shift;
my ($speriod, $eperiod, $agentnum, %opt) = @_;
@@ -632,9 +646,11 @@ sub cust_bill_pkg_recur {
($cust_bill_pkg.edate - $cust_bill_pkg.sdate)";
}
- my $total_sql =
- "SELECT COALESCE(SUM(($cust_bill_pkg.recur - $item_usage) $recur_fraction),0)" .
- $self->_cust_bill_pkg_recurring(@_);
+ my $total_sql = $opt{'cost'}
+ ? "SELECT SUM(part_pkg.recur_cost)"
+ : "SELECT COALESCE(SUM(($cust_bill_pkg.recur - $item_usage) $recur_fraction),0)";
+
+ $total_sql .= $self->_cust_bill_pkg_recurring(@_);
$self->scalar_sql($total_sql);
}
@@ -650,10 +666,14 @@ sub cust_bill_pkg_count_pkgnum {
=item cust_bill_pkg_detail: the total usage charges in detail lines.
-Arguments as for C<cust_bill_pkg>, plus:
+Most arguments as for C<cust_bill_pkg>, plus:
'usageclass': limit to this usage class number.
+'custnum': limit to this customer
+
+'cost': if true, return total usage costs instead
+
=cut
sub cust_bill_pkg_detail {
@@ -686,7 +706,16 @@ sub cust_bill_pkg_detail {
);
}
+ if ( $opt{'custnum'} =~ /^(\d+)$/ ) {
+ push @where, "(cust_main.custnum = $1)";
+ }
+
my $total_sql = " SELECT SUM(cust_bill_pkg_detail.amount) ";
+ my $extra_join = '';
+ if ($opt{'cost'}) {
+ $extra_join = " JOIN cdr USING ( detailnum ) ";
+ $total_sql = " SELECT SUM(cdr.rated_cost) ";
+ }
$total_sql .=
" FROM cust_bill_pkg_detail
@@ -696,8 +725,9 @@ sub cust_bill_pkg_detail {
LEFT JOIN cust_pkg ON cust_bill_pkg.pkgnum = cust_pkg.pkgnum
LEFT JOIN part_pkg USING ( pkgpart )
LEFT JOIN part_pkg AS override ON pkgpart_override = override.pkgpart
- LEFT JOIN part_fee USING ( feepart )
- WHERE ".join( ' AND ', grep $_, @where );
+ LEFT JOIN part_fee USING ( feepart )
+ ".$extra_join.
+ " WHERE ".join( ' AND ', grep $_, @where );
$self->scalar_sql($total_sql);
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 3ecbea3da..029dbe10c 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -5492,6 +5492,7 @@ sub tables_hashref {
'rated_ratedetailnum', 'int', 'NULL', '', '', '',
'rated_classnum', 'int', 'NULL', '', '', '',
'rated_ratename', 'varchar', 'NULL', $char_d, '', '',
+ 'rated_cost', 'decimal', 'NULL', '10,4', '', '',
'carrierid', 'bigint', 'NULL', '', '', '',
diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm
index 775c79114..e40b0921a 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -216,6 +216,7 @@ sub table_info {
#'upstream_rateplanid' => '',
#'ratedetailnum' => '',
'rated_price' => 'Rated price',
+ 'rated_cost' => 'Rated cost',
#'distance' => '',
#'islocal' => '',
#'calltypenum' => '',
@@ -468,7 +469,9 @@ Sets the status and rated price.
Available options are: inbound, rated_pretty_dst, rated_regionname,
rated_seconds, rated_minutes, rated_granularity, rated_ratedetailnum,
-rated_classnum, rated_ratename.
+rated_classnum, rated_ratename, and set_rate_cost (if true, will set
+a recalculated L</rate_cost> in the rated_cost field after the other
+fields are set; does not work with inbound.)
If there is an error, returns the error, otherwise returns false.
@@ -506,6 +509,8 @@ sub set_status_and_rated_price {
qw( pretty_dst regionname seconds minutes granularity
ratedetailnum classnum ratename );
$self->svcnum($svcnum) if $svcnum;
+ $self->rated_cost($self->rate_cost) if $opt{'set_rate_cost'};
+
return $self->replace();
}
@@ -1005,6 +1010,7 @@ sub rate_prefix {
'rated_ratedetailnum' => $rate_detail->ratedetailnum,
'rated_classnum' => $rate_detail->classnum, #rated_ratedetailnum?
'rated_ratename' => $ratename, #not rate_detail - Intrastate/Interstate
+ 'set_rate_cost' => 1,
);
}