X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FReport%2FTable.pm;h=4b22b60b85bb801369bf80397e27af930267b77e;hp=4b1ad05d64a3df262b6fc8020bd9deae70ce34df;hb=e0e76b55a2f83c19e4114eefe4dabcab092808b4;hpb=6163b943f45e083a87cc03344eb775a9edd553ce diff --git a/FS/FS/Report/Table.pm b/FS/FS/Report/Table.pm index 4b1ad05d6..4b22b60b8 100644 --- a/FS/FS/Report/Table.pm +++ b/FS/FS/Report/Table.pm @@ -753,6 +753,33 @@ sub cust_bill_pkg_taxes { $self->scalar_sql($total_sql); } +#all credits applied to matching pkg line items (ie not taxes or fees) + +sub cust_bill_pkg_credits { + my $self = shift; + my ($speriod, $eperiod, $agentnum, %opt) = @_; + + $agentnum ||= $opt{'agentnum'}; + + my @where = ( + '(cust_bill_pkg.pkgnum != 0 OR feepart IS NOT NULL)', + $self->with_classnum($opt{'classnum'}, $opt{'use_override'}), + $self->with_report_option(%opt), + $self->in_time_period_and_agent($speriod, $eperiod, $agentnum), + $self->with_refnum(%opt), + $self->with_cust_classnum(%opt) + ); + + my $total_sql = "SELECT COALESCE(SUM(cust_credit_bill_pkg.amount),0) + FROM cust_bill_pkg + $cust_bill_pkg_join + LEFT JOIN cust_credit_bill_pkg + USING ( billpkgnum ) + WHERE " . join(' AND ', grep $_, @where); + + $self->scalar_sql($total_sql); +} + ##### package churn report ##### =item active_pkg: The number of packages that were active at the start of