1 package FS::detail_format::sum_duration_accountcode;
5 use base qw(FS::detail_format);
9 my $me = '[sum_duration_accountcode]';
11 sub name { 'Summary, one line per accountcode' };
14 'Account code,Calls,Duration,Price';
19 my $codes = ($self->{codes} ||= {});
20 my $acctids = ($self->{acctids} ||= []);
21 foreach my $cdr (@_) {
22 my $accountcode = $cdr->accountcode || 'other';
24 my $object = $self->{inbound} ? $cdr->cdr_termination(1) : $cdr;
25 my $subtotal = $codes->{$accountcode}
26 ||= { count => 0, duration => 0, amount => 0.0 };
28 $subtotal->{duration} += $object->rated_seconds;
29 $subtotal->{amount} += $object->rated_price
30 if $object->freesidestatus ne 'no-charge';
32 push @$acctids, $cdr->acctid;
38 my $codes = $self->{codes};
39 foreach my $accountcode (sort { $a cmp $b } keys %$codes) {
41 warn "processing $accountcode\n" if $DEBUG;
43 my $subtotal = $codes->{$accountcode};
48 sprintf('%.01f min', $subtotal->{duration}/60),
49 $self->money_char . sprintf('%.02f', $subtotal->{amount})
52 warn "adding detail: ".$self->csv->string."\n" if $DEBUG;
54 push @{ $self->{buffer} }, FS::cust_bill_pkg_detail->new({
55 amount => $subtotal->{amount},
57 classnum => '', #ignored in this format
58 duration => $subtotal->{duration},
59 phonenum => '', # not divided up per service
60 accountcode => $accountcode,
63 detail => $self->csv->string,
64 acctid => $self->{acctids},
66 } #foreach $accountcode