show package pricing details on customer view, RT11372
[freeside.git] / FS / FS / part_pkg / voip_cdr.pm
index 5dbd115..658df54 100644 (file)
@@ -278,6 +278,13 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
   'weight' => 40,
 );
 
+sub price_info {
+    my $self = shift;
+    my $str = $self->SUPER::price_info;
+    $str .= " plus usage" if $str;
+    $str;
+}
+
 sub calc_setup {
   my($self, $cust_pkg ) = @_;
   $self->option('setup_fee');
@@ -385,6 +392,8 @@ sub calc_usage {
       );  # $last_bill, $$sdate )
     $options{'by_svcnum'} = 1 if $svc_field eq 'svcnum';
 
+    my @invoice_details_sort;
+
     foreach my $cdr (
       $svc_x->get_cdrs( %options )
     ) {
@@ -471,7 +480,7 @@ sub calc_usage {
             }
 
           } else {
-            $countrycode = $domestic_prefix || '1';
+            $countrycode = length($domestic_prefix) ? $domestic_prefix : '1';
             $number =~ s/^$countrycode//;# if length($number) > 10;
           }
 
@@ -743,7 +752,7 @@ sub calc_usage {
           warn "  adding details on charge to invoice: [ ".
               join(', ', @{$call_details} ). " ]"
             if ( $DEBUG && ref($call_details) );
-          push @$details, $call_details; #\@call_details,
+          push @invoice_details_sort, [ $call_details, $cdr->calldate_unix ];
         }
 
         # if the customer flag is on, call "downstream_csv" or something
@@ -761,6 +770,11 @@ sub calc_usage {
       }
 
     } # $cdr
+    my @sorted_invoice_details = sort { @{$a}[1] <=> @{$b}[1] } @invoice_details_sort;
+    foreach my $sorted_call_detail ( @sorted_invoice_details ) {
+        push @$details, @{$sorted_call_detail}[0];
+    }
 
   } # $cust_svc