[freeside-commits] freeside/FS/FS Conf.pm, 1.412, 1.413 cust_bill.pm, 1.301, 1.302

Erik Levinson levinse at wavetail.420.am
Mon Dec 27 21:23:53 PST 2010


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

Modified Files:
	Conf.pm cust_bill.pm 
Log Message:
invoice customization for DIDs, RT10886

Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.412
retrieving revision 1.413
diff -u -w -d -r1.412 -r1.413
--- Conf.pm	26 Dec 2010 04:09:24 -0000	1.412
+++ Conf.pm	28 Dec 2010 05:23:51 -0000	1.413
@@ -4187,6 +4187,13 @@
     'type'        => 'textarea',
   },
 
+  {
+    'key'         => 'svc_phone-did-summary',
+    'section'     => 'invoicing',
+    'description' => 'Enable DID activity summary for past 30 days on invoices, showing # DIDs activated/deactivated/ported-in/ported-out and total minutes usage',
+    'type'        => 'checkbox',
+  },
+
   { key => "apacheroot", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
   { key => "apachemachine", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
   { key => "apachemachines", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },

Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.301
retrieving revision 1.302
diff -u -w -d -r1.301 -r1.302
--- cust_bill.pm	14 Nov 2010 09:10:21 -0000	1.301
+++ cust_bill.pm	28 Dec 2010 05:23:51 -0000	1.302
@@ -2661,6 +2661,16 @@
     push @buf, ['',''];
   }
 
+  if ( $conf->exists('svc_phone-did-summary') ) {
+      my ($didsummary,$minutes) = $self->_did_summary;
+      my $didsummary_desc = 'DID Activity Summary (Past 30 days)';
+      push @detail_items, 
+	{ 'description' => $didsummary_desc,
+	    'ext_description' => [ $didsummary, $minutes ],
+	}
+	if !$multisection;
+  }
+
   foreach my $section (@sections, @$late_sections) {
 
     # begin some normalization
@@ -3795,6 +3805,72 @@
 
 }
 
+sub _did_summary {
+    my $self = shift;
+    my $end = $self->_date;
+    my $start = $end - 2592000; # 30 days
+    my $cust_main = $self->cust_main;
+    my @pkgs = $cust_main->all_pkgs;
+    my($num_activated,$num_deactivated,$num_portedin,$num_portedout,$minutes)
+	= (0,0,0,0,0);
+    my @seen = ();
+    foreach my $pkg ( @pkgs ) {
+	my @h_cust_svc = $pkg->h_cust_svc($end);
+	foreach my $h_cust_svc ( @h_cust_svc ) {
+	    next if grep {$_ eq $h_cust_svc->svcnum} @seen;
+	    next unless $h_cust_svc->part_svc->svcdb eq 'svc_phone';
+
+	    my $inserted = $h_cust_svc->date_inserted;
+	    my $deleted = $h_cust_svc->date_deleted;
+	    my $phone_inserted = $h_cust_svc->h_svc_x($inserted);
+	    my $phone_deleted;
+	    $phone_deleted =  $h_cust_svc->h_svc_x($deleted) if $deleted;
+	    
+# DID either activated or ported in; cannot be both for same DID simultaneously
+	    if ($inserted >= $start && $inserted <= $end && $phone_inserted
+		&& (!$phone_inserted->lnp_status 
+		    || $phone_inserted->lnp_status eq ''
+		    || $phone_inserted->lnp_status eq 'native')) {
+		$num_activated++;
+	    }
+	    else { # this one not so clean, should probably move to (h_)svc_phone
+		 my $phone_portedin = qsearchs( 'h_svc_phone',
+		      { 'svcnum' => $h_cust_svc->svcnum, 
+			'lnp_status' => 'portedin' },  
+		      FS::h_svc_phone->sql_h_searchs($end),  
+		    );
+		 $num_portedin++ if $phone_portedin;
+	    }
+
+# DID either deactivated or ported out;	cannot be both for same DID simultaneously
+	    if($deleted >= $start && $deleted <= $end && $phone_deleted
+		&& (!$phone_deleted->lnp_status 
+		    || $phone_deleted->lnp_status ne 'portingout')) {
+		$num_deactivated++;
+	    } 
+	    elsif($deleted >= $start && $deleted <= $end && $phone_deleted 
+		&& $phone_deleted->lnp_status 
+		&& $phone_deleted->lnp_status eq 'portingout') {
+		$num_portedout++;
+	    }
+
+	    # increment usage minutes
+	    my @cdrs = $phone_inserted->get_cdrs('begin'=>$start,'end'=>$end);
+	    foreach my $cdr ( @cdrs ) {
+		$minutes += $cdr->billsec/60;
+	    }
+
+	    # don't look at this service again
+	    push @seen, $h_cust_svc->svcnum;
+	}
+    }
+
+    $minutes = sprintf("%d", $minutes);
+    ("Activated: $num_activated  Ported-In: $num_portedin  Deactivated: "
+	. "$num_deactivated  Ported-Out: $num_portedout ",
+	    "Total Minutes: $minutes");
+}
+
 sub _items_svc_phone_sections {
   my $self = shift;
   my $escape = shift;



More information about the freeside-commits mailing list