pass cust_bill_pkg_detail as hash, not a long ordered list. duh.
authorivan <ivan>
Thu, 22 Sep 2011 22:03:15 +0000 (22:03 +0000)
committerivan <ivan>
Thu, 22 Sep 2011 22:03:15 +0000 (22:03 +0000)
FS/FS/cust_bill_pkg.pm
FS/FS/part_pkg/voip_cdr.pm
FS/FS/part_pkg/voip_inbound.pm

index c9b0a4d..ab9d350 100644 (file)
@@ -146,18 +146,29 @@ sub insert {
 
   if ( $self->get('details') ) {
     foreach my $detail ( @{$self->get('details')} ) {
-      my $cust_bill_pkg_detail = new FS::cust_bill_pkg_detail {
-        'billpkgnum' => $self->billpkgnum,
-        'format'     => (ref($detail) ? $detail->[0] : '' ),
-        'detail'     => (ref($detail) ? $detail->[1] : $detail ),
-        'amount'     => (ref($detail) ? $detail->[2] : '' ),
-        'classnum'   => (ref($detail) ? $detail->[3] : '' ),
-        'phonenum'   => (ref($detail) ? $detail->[4] : '' ),
-        'accountcode' => (ref($detail) ? $detail->[5] : '' ),
-        'startdate'  => (ref($detail) ? $detail->[6] : '' ),
-        'duration'   => (ref($detail) ? $detail->[7] : '' ),
-        'regionname' => (ref($detail) ? $detail->[8] : '' ),
-      };
+      my %hash = ();
+      if ( ref($detail) ) {
+        if ( ref($detail) eq 'ARRAY' ) {
+          #carp "this way sucks, use a hash"; #but more useful/friendly
+          $hash{'format'}      = $detail->[0];
+          $hash{'detail'}      = $detail->[1];
+          $hash{'amount'}      = $detail->[2];
+          $hash{'classnum'}    = $detail->[3];
+          $hash{'phonenum'}    = $detail->[4];
+          $hash{'accountcode'} = $detail->[5];
+          $hash{'startdate'}   = $detail->[6];
+          $hash{'duration'}    = $detail->[7];
+          $hash{'regionname'}  = $detail->[8];
+        } elsif ( ref($detail) eq 'HASH' ) {
+          %hash = %$detail;
+        } else {
+          die "unknow detail type ". ref($detail);
+        }
+      } else {
+        $hash{'detail'} = $detail;
+      }
+      $hash{'billpkgnum'} = $self->billpkgnum;
+      my $cust_bill_pkg_detail = new FS::cust_bill_pkg_detail \%hash;
       $error = $cust_bill_pkg_detail->insert;
       if ( $error ) {
         $dbh->rollback if $oldAutoCommit;
index 81de0bd..ada91c6 100644 (file)
@@ -768,33 +768,33 @@ sub calc_usage {
 
           if ( scalar(@call_details) == 1 ) {
             $call_details =
-              [ 'C',
-                $call_details[0],
-                $charge,
-                $classnum,
-                $phonenum,
-                $cdr->accountcode,
-                $cdr->startdate,
-                $seconds,
-                $regionname,
-              ];
+              { format      => 'C',
+                detail      => $call_details[0],
+                amount      => $charge,
+                classnum    => $classnum,
+                phonenum    => $phonenum,
+                accountcode => $cdr->accountcode,
+                startdate   => $cdr->startdate,
+                duration    => $seconds,
+                regionname  => $regionname,
+              };
           } else { #only used for $rating_method eq 'upstream' now
             $csv->combine(@call_details);
             $call_details =
-              [ 'C',
-                $csv->string,
-                $charge,
-                $classnum,
-                $phonenum,
-                $cdr->accountcode,
-                $cdr->startdate,
-                $seconds,
-                $regionname,
-              ];
+              { format      => 'C',
+                detail      => $csv->string,
+                amount      => $charge,
+                classnum    => $classnum,
+                phonenum    => $phonenum,
+                accountcode => $cdr->accountcode,
+                startdate   => $cdr->startdate,
+                duration    => $seconds,
+                regionname  => $regionname,
+              };
           }
-          warn "  adding details on charge to invoice: [ ".
-              join(', ', @{$call_details} ). " ]"
-            if ( $DEBUG && ref($call_details) );
+          #warn "  adding details on charge to invoice: [ ".
+          #    join(', ', @{$call_details} ). " ]"
+          #  if ( $DEBUG && ref($call_details) );
           push @invoice_details_sort, [ $call_details, $cdr->calldate_unix ];
         }
 
@@ -821,14 +821,9 @@ sub calc_usage {
 
   } # $cust_svc
 
-  unshift @$details, [ 'C',
-                       FS::cdr::invoice_header($output_format),
-                       '',
-                       '',
-                       '',
-                       '',
-                       '',
-                     ]
+  unshift @$details, { format => 'C',
+                       detail => FS::cdr::invoice_header($output_format),
+                     }
     if @$details && $rating_method ne 'upstream';
 
 #  if ( $spool_cdr && length($downstream_cdr) ) {
index 9b048c2..da4ce87 100644 (file)
@@ -279,16 +279,16 @@ sub calc_usage {
                                           )
                                 );
         push @$details,
-            [ 'C',
-              $call_details[0],
-              $charge,
-              $cdr->calltypenum, #classnum
-              $self->phonenum,
-              $cdr->accountcode,
-              $cdr->startdate,
-              $seconds,
-              '', #regionname, not set for inbound calls
-            ];
+          { format      => 'C',
+            detail      => $call_details[0],
+            amount      => $charge,
+            classnum    => $cdr->calltypenum, #classnum
+            phonenum    => $self->phonenum,
+            accountcode => $cdr->accountcode,
+            startdate   => $cdr->startdate,
+            duration    => $seconds,
+            # regionname?? => '', #regionname, not set for inbound calls
+          };
      }
 
      my $error = $cdr->set_status_and_rated_price( 'done',
@@ -299,14 +299,9 @@ sub calc_usage {
 
     } #$cdr
   } # $cust_svc
-  unshift @$details, [ 'C',
-                       FS::cdr::invoice_header($output_format),
-                       '',
-                       '',
-                       '',
-                       '',
-                       '',
-                     ]
+  unshift @$details, { format => 'C',
+                       detail => FS::cdr::invoice_header($output_format),
+                     }
     if @$details;
 
   $charges;