[freeside-commits] freeside/FS/FS Schema.pm, 1.213, 1.214 cdr.pm, 1.55, 1.56 cdr_termination.pm, 1.2, 1.3 cust_svc.pm, 1.82, 1.83 svc_phone.pm, 1.26, 1.27
Mark Wells
mark at wavetail.420.am
Mon Apr 26 22:38:30 PDT 2010
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv21528/FS/FS
Modified Files:
Schema.pm cdr.pm cdr_termination.pm cust_svc.pm svc_phone.pm
Log Message:
RT#7046: inbound rate for rate plan billing
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.213
retrieving revision 1.214
diff -u -w -d -r1.213 -r1.214
--- Schema.pm 23 Apr 2010 06:46:24 -0000 1.213
+++ Schema.pm 27 Apr 2010 05:38:27 -0000 1.214
@@ -2524,6 +2524,7 @@
'termpart', 'int', '', '', '', '',#future use see below
'rated_price', 'decimal', 'NULL', '10,4', '', '',
'status', 'varchar', 'NULL', 32, '', '',
+ 'svcnum', 'int', 'NULL', '', '', '',
],
'primary_key' => 'cdrtermnum',
'unique' => [ [ 'acctid', 'termpart' ] ],
Index: svc_phone.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_phone.pm,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -w -d -r1.26 -r1.27
--- svc_phone.pm 12 Mar 2010 21:56:32 -0000 1.26
+++ svc_phone.pm 27 Apr 2010 05:38:27 -0000 1.27
@@ -525,6 +525,99 @@
$cust_pkg ? $cust_pkg->cust_location_or_main : '';
}
+=item get_cdrs
+
+Returns a set of Call Detail Records (see L<FS::cdr>) associated with this
+service. By default, "associated with" means that either the "src" or the
+"charged_party" field of the CDR matches the "phonenum" field of the service.
+
+=over 2
+
+Accepts the following options:
+
+=item for_update => 1: SELECT the CDRs "FOR UPDATE".
+
+=item status => "" (or "done"): Return only CDRs with that processing status.
+
+=item inbound => 1: Return CDRs for inbound calls. With "status", will filter
+on inbound processing status.
+
+=item default_prefix => "XXX": Also accept the phone number of the service prepended
+with the chosen prefix.
+
+=item disable_src => 1: Only match on "charged_party", not "src".
+
+=back
+
+=cut
+
+sub get_cdrs {
+ my($self, %options) = @_;
+ my @fields;
+ my %hash;
+ my @where;
+
+ if ( $options{'inbound'} ) {
+ @fields = ( 'dst' );
+ if ( exists($options{'status'}) ) {
+ # must be 'done' or ''
+ my $sq = 'EXISTS ( SELECT 1 FROM cdr_termination '.
+ 'WHERE cdr.acctid = cdr_termination.acctid '.
+ 'AND cdr_termination.status = \'done\' '.
+ 'AND cdr_termination.termpart = 1 )';
+ if ( $options{'status'} eq 'done' ) {
+ push @where, $sq;
+ }
+ elsif ($options{'status'} eq '' ) {
+ push @where, "NOT $sq";
+ }
+ else {
+ warn "invalid status: $options{'status'} (ignored)\n";
+ }
+ }
+ }
+ else {
+ @fields = ( 'charged_party' );
+ push @fields, 'src' if !$options{'disable_src'};
+ $hash{'freesidestatus'} = $options{'status'}
+ if exists($options{'status'});
+ }
+
+ my $for_update = $options{'for_update'} ? 'FOR UPDATE' : '';
+
+ my $number = $self->phonenum;
+
+ my $prefix = $options{'default_prefix'};
+
+ my @orwhere = map " $_ = '$number' ", @fields;
+ push @orwhere, map " $_ = '$prefix$number' ", @fields
+ if length($prefix);
+ if ( $prefix =~ /^\+(\d+)$/ ) {
+ push @orwhere, map " $_ = '$1$number' ", @fields
+ }
+
+ push @where, ' ( '. join(' OR ', @orwhere ). ' ) ';
+
+ if ( $options{'begin'} ) {
+ push @where, 'startdate >= '. $options{'begin'};
+ }
+ if ( $options{'end'} ) {
+ push @where, 'startdate < '. $options{'end'};
+ }
+
+ my $extra_sql = ( keys(%hash) ? ' AND ' : ' WHERE ' ). join(' AND ', @where );
+
+ my @cdrs =
+ qsearch( {
+ 'table' => 'cdr',
+ 'hashref' => \%hash,
+ 'extra_sql' => $extra_sql,
+ 'order_by' => "ORDER BY startdate $for_update",
+ } );
+
+ @cdrs;
+}
+
=back
=head1 BUGS
Index: cdr.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cdr.pm,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -w -d -r1.55 -r1.56
--- cdr.pm 19 Nov 2009 09:47:02 -0000 1.55
+++ cdr.pm 27 Apr 2010 05:38:27 -0000 1.56
@@ -14,6 +14,7 @@
use FS::cdr_calltype;
use FS::cdr_carrier;
use FS::cdr_batch;
+use FS::cdr_termination;
@ISA = qw(FS::Record);
@EXPORT_OK = qw( _cdr_date_parser_maker _cdr_min_parser_maker );
@@ -386,11 +387,33 @@
=cut
sub set_status_and_rated_price {
- my($self, $status, $rated_price, $svcnum) = @_;
+ my($self, $status, $rated_price, $svcnum, %opt) = @_;
+ if($opt{'inbound'}) {
+ my $term = qsearchs('cdr_termination', {
+ acctid => $self->acctid,
+ termpart => 1 # inbound
+ });
+ my $error;
+ if($term) {
+ warn "replacing existing cdr status (".$self->acctid.")\n" if $term;
+ $error = $term->delete;
+ return $error if $error;
+ }
+ $term = FS::cdr_termination->new({
+ acctid => $self->acctid,
+ termpart => 1,
+ rated_price => $rated_price,
+ status => $status,
+ svcnum => $svcnum,
+ });
+ return $term->insert;
+ }
+ else {
$self->freesidestatus($status);
$self->rated_price($rated_price);
$self->svcnum($svcnum) if $svcnum;
- $self->replace();
+ return $self->replace();
+ }
}
=item calldate_unix
Index: cust_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_svc.pm,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -w -d -r1.82 -r1.83
--- cust_svc.pm 17 Feb 2010 08:32:53 -0000 1.82
+++ cust_svc.pm 27 Apr 2010 05:38:27 -0000 1.83
@@ -709,72 +709,6 @@
}
-=item get_cdrs_for_update
-
-Returns (and SELECTs "FOR UPDATE") all unprocessed (freesidestatus NULL) CDR
-objects (see L<FS::cdr>) associated with this service.
-
-CDRs are associated with svc_phone services via svc_phone.phonenum
-
-=cut
-
-sub get_cdrs_for_update {
- my $self = shift;
- $self->get_cdrs( 'freesidestatus' => '',
- 'for_update' => 1,
- @_,
- );
-}
-
-sub get_cdrs {
- my($self, %options) = @_;
-
- my @fields = ( 'charged_party' );
- push @fields, 'src' unless $options{'disable_src'};
-
- my $for_update = $options{'for_update'} ? 'FOR UPDATE' : '';
-
- my %hash = ();
- $hash{'freesidestatus'} = $options{'freesidestatus'}
- if exists($options{'freesidestatus'});
-
- #CDRs are associated with svc_phone services via svc_phone.phonenum
-
- #return () unless $self->svc_x->isa('FS::svc_phone');
- return () unless $self->part_svc->svcdb eq 'svc_phone';
- my $number = $self->svc_x->phonenum;
-
- my $prefix = $options{'default_prefix'};
-
- my @orwhere = map " $_ = '$number' ", @fields;
- push @orwhere, map " $_ = '$prefix$number' ", @fields
- if length($prefix);
- if ( $prefix =~ /^\+(\d+)$/ ) {
- push @orwhere, map " $_ = '$1$number' ", @fields
- }
-
- my @where = ( ' ( '. join(' OR ', @orwhere ). ' ) ' );
-
- if ( $options{'begin'} ) {
- push @where, 'startdate >= '. $options{'begin'};
- }
- if ( $options{'end'} ) {
- push @where, 'startdate < '. $options{'end'};
- }
-
- my $extra_sql = ( keys(%hash) ? ' AND ' : ' WHERE ' ). join(' AND ', @where );
-
- my @cdrs =
- qsearch( {
- 'table' => 'cdr',
- 'hashref' => \%hash,
- 'extra_sql' => $extra_sql,
- 'order_by' => "ORDER BY startdate $for_update",
- } );
-
- @cdrs;
-}
-
=back
=head1 BUGS
Index: cdr_termination.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cdr_termination.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -d -r1.2 -r1.3
--- cdr_termination.pm 2 Jul 2009 11:22:48 -0000 1.2
+++ cdr_termination.pm 27 Apr 2010 05:38:27 -0000 1.3
@@ -51,6 +51,9 @@
status
+=item svcnum
+
+svc_phone record associated with this transaction, if there is one.
=back
More information about the freeside-commits
mailing list