[freeside-commits] freeside/FS/FS cust_svc.pm,1.79,1.80

Ivan,,, ivan at wavetail.420.am
Mon May 18 02:55:31 PDT 2009


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv24826/FS/FS

Modified Files:
	cust_svc.pm 
Log Message:
basic CDR viewing from self-service, RT#4018

Index: cust_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_svc.pm,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- cust_svc.pm	24 Mar 2009 02:36:31 -0000	1.79
+++ cust_svc.pm	18 May 2009 09:55:29 -0000	1.80
@@ -692,32 +692,56 @@
 =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'};
 
-  #CDRs are now associated with svc_phone services via svc_phone.phonenum
+  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 @where =  map " $_ = '$number'        ", @fields;
-  push @where, map " $_ = '$prefix$number' ", @fields
+  my @orwhere =  map " $_ = '$number'        ", @fields;
+  push @orwhere, map " $_ = '$prefix$number' ", @fields
     if length($prefix);
   if ( $prefix =~ /^\+(\d+)$/ ) {
-    push @where, map " $_ = '$1$number' ", @fields
+    push @orwhere, map " $_ = '$1$number' ", @fields
   }
 
-  my $extra_sql = ' AND ( '. join(' OR ', @where ). ' ) ';
+  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'    => { 'freesidestatus' => '', },
-      'extra_sql'  => "$extra_sql FOR UPDATE",
+      'hashref'    => \%hash,
+      'extra_sql'  => "$extra_sql $for_update",
     } );
 
   @cdrs;



More information about the freeside-commits mailing list