[freeside-commits] branch FREESIDE_4_BRANCH updated. e4aff0c0af3139118b4ae02e814ba7d0d8f46774
Ivan Kohler
ivan at freeside.biz
Sun Feb 4 17:48:01 PST 2018
The branch, FREESIDE_4_BRANCH has been updated
via e4aff0c0af3139118b4ae02e814ba7d0d8f46774 (commit)
from 889eafade02f1b7463cc47202020ddb8c5d8394f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit e4aff0c0af3139118b4ae02e814ba7d0d8f46774
Author: Ivan Kohler <ivan at freeside.biz>
Date: Sun Feb 4 17:47:57 2018 -0800
option to reprocess CDRs when voiding an invoice, RT#79001
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index d6d2d971c..ef7c6ffa4 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -214,7 +214,7 @@ sub insert {
}
-=item void [ REASON ]
+=item void [ REASON [ , REPROCESS_CDRS ] ]
Voids this invoice: deletes the invoice and adds a record of the voided invoice
to the FS::cust_bill_void table (and related tables starting from
@@ -225,6 +225,7 @@ FS::cust_bill_pkg_void).
sub void {
my $self = shift;
my $reason = scalar(@_) ? shift : '';
+ my $reprocess_cdrs = scalar(@_) ? shift : '';
unless (ref($reason) || !$reason) {
$reason = FS::reason->new_or_existing(
@@ -256,7 +257,7 @@ sub void {
}
foreach my $cust_bill_pkg ( $self->cust_bill_pkg ) {
- my $error = $cust_bill_pkg->void($reason);
+ my $error = $cust_bill_pkg->void($reason, $reprocess_cdrs);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
@@ -2912,6 +2913,23 @@ sub _items_total {
+=item has_call_details
+
+Returns true if this invoice has call details.
+
+=cut
+
+sub has_call_details {
+ my $self = shift;
+ $self->scalar_sql("
+ SELECT 1 FROM cust_bill_pkg_detail
+ LEFT JOIN cust_bill_pkg USING (billpkgnum)
+ WHERE cust_bill_pkg_detail.format = 'C'
+ AND cust_bill_pkg.invnum = ?
+ LIMIT 1
+ ", $self->invnum);
+}
+
=item call_details [ OPTION => VALUE ... ]
Returns an array of CSV strings representing the call details for this invoice
diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm
index 9567278aa..77dce2476 100644
--- a/FS/FS/cust_bill_pkg.pm
+++ b/FS/FS/cust_bill_pkg.pm
@@ -324,7 +324,7 @@ sub insert {
}
-=item void [ REASON ]
+=item void [ REASON [ , REPROCESS_CDRS ] ]
Voids this line item: deletes the line item and adds a record of the voided
line item to the FS::cust_bill_pkg_void table (and related tables).
@@ -334,6 +334,7 @@ line item to the FS::cust_bill_pkg_void table (and related tables).
sub void {
my $self = shift;
my $reason = scalar(@_) ? shift : '';
+ my $reprocess_cdrs = scalar(@_) ? shift : '';
unless (ref($reason) || !$reason) {
$reason = FS::reason->new_or_existing(
@@ -373,6 +374,9 @@ sub void {
cust_tax_exempt_pkg
cust_bill_pkg_fee
)) {
+ my %delete_args = ();
+ $delete_args{'reprocess_cdrs'} = $reprocess_cdrs
+ if $table eq 'cust_bill_pkg_detail';
foreach my $linked ( qsearch($table, { billpkgnum=>$self->billpkgnum }) ) {
@@ -380,7 +384,7 @@ sub void {
my $void = $vclass->new( {
map { $_ => $linked->get($_) } $linked->fields
});
- my $error = $void->insert || $linked->delete;
+ my $error = $void->insert || $linked->delete(%delete_args);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
diff --git a/FS/FS/cust_bill_pkg_detail.pm b/FS/FS/cust_bill_pkg_detail.pm
index dd118c1b2..19b15f7dd 100644
--- a/FS/FS/cust_bill_pkg_detail.pm
+++ b/FS/FS/cust_bill_pkg_detail.pm
@@ -106,21 +106,37 @@ sub insert {
'';
}
-=item delete
+=item delete [ ARG => VALUE ... ]
Delete this record from the database.
+If the "reprocess_cdrs" argument is set to true, resets the status of any
+related CDRs (and deletes their associated cdr_termination records, if any).
+
=cut
sub delete {
- my $self = shift;
+ my( $self, %args ) = @_;
+
my $error = $self->SUPER::delete;
return $error if $error;
+
foreach my $cdr (qsearch('cdr', { detailnum => $self->detailnum })) {
+
$cdr->set('detailnum', '');
+ $cdr->set('freesidestatus', '') if $args{'reprocess_cdrs'};
$error = $cdr->replace;
return "error unlinking CDR #" . $cdr->acctid . ": $error" if $error;
+
+ #well, technically this could have been on other invoices / termination
+ # partners... separate flag?
+ $self->scalar_sql( 'DELETE FROM cdr_termination WHERE acctid = ?',
+ $cdr->acctid )
+ if $args{'reprocess_cdrs'};
+
}
+
+ '';
}
=item replace OLD_RECORD
diff --git a/httemplate/misc/process/void-cust_bill.html b/httemplate/misc/process/void-cust_bill.html
index 32a2fc591..49dda185e 100755
--- a/httemplate/misc/process/void-cust_bill.html
+++ b/httemplate/misc/process/void-cust_bill.html
@@ -19,8 +19,8 @@ my $invnum = $1;
my $cust_bill = qsearchs('cust_bill',{'invnum'=>$invnum});
-my $custnum = $cust_bill->custnum;
-
-my $error = $cust_bill->void( scalar($cgi->param('reason')) );
+my $error = $cust_bill->void( scalar($cgi->param('reason')),
+ scalar($cgi->param('reprocess_cdrs')),
+ );
</%init>
diff --git a/httemplate/misc/void-cust_bill.html b/httemplate/misc/void-cust_bill.html
index e4e4705d7..e5fbdc6d5 100755
--- a/httemplate/misc/void-cust_bill.html
+++ b/httemplate/misc/void-cust_bill.html
@@ -18,6 +18,14 @@
'cgi' => $cgi
&>
+% if ( $cust_bill->has_call_details ) {
+ <& /elements/tr-checkbox.html,
+ label => 'Reprocess CDRs',
+ field => 'reprocess_cdrs',
+ value => '1',
+ &>
+% }
+
</TABLE>
<BR>
-----------------------------------------------------------------------
Summary of changes:
FS/FS/cust_bill.pm | 22 ++++++++++++++++++++--
FS/FS/cust_bill_pkg.pm | 8 ++++++--
FS/FS/cust_bill_pkg_detail.pm | 20 ++++++++++++++++++--
httemplate/misc/process/void-cust_bill.html | 6 +++---
httemplate/misc/void-cust_bill.html | 8 ++++++++
5 files changed, 55 insertions(+), 9 deletions(-)
More information about the freeside-commits
mailing list