1 package FS::detail_format::sum_duration;
5 use base qw(FS::detail_format);
6 use FS::Record qw(qsearchs);
8 use FS::svc_Common; # for label
12 sub name { 'Summary, one line per service' };
16 if ( $self->{inbound} ) {
17 'Destination,Calls,Duration,Price'
20 'Source,Calls,Duration,Price'
26 my $svcnums = ($self->{svcnums} ||= {});
27 foreach my $cdr (@_) {
28 my $object = $self->{inbound} ? $cdr->cdr_termination(1) : $cdr;
29 my $svcnum = $object->svcnum; # yes, $object->svcnum.
31 my $subtotal = ($svcnums->{$svcnum} ||=
32 { count => 0, duration => 0, amount => 0 });
34 $subtotal->{duration} += $object->rated_seconds;
35 $subtotal->{amount} += $object->rated_price;
41 my $svcnums = $self->{svcnums};
42 my $buffer = $self->{buffer};
43 foreach my $svcnum (keys %$svcnums) {
45 my $subtotal = $svcnums->{$svcnum};
46 next if $subtotal->{amount} < 0.01;
48 my $cust_svc = qsearchs('cust_svc', { svcnum => $svcnum })
49 or die "svcnum #$svcnum not found";
50 my $phonenum = $cust_svc->svc_x->label;
51 warn "processing $phonenum\n" if $DEBUG;
56 int($subtotal->{duration}/60) . ' min',
57 $self->money_char . sprintf('%.02f',$subtotal->{amount}),
60 warn "adding detail: ".$self->csv->string."\n" if $DEBUG;
62 push @$buffer, FS::cust_bill_pkg_detail->new({
63 amount => $subtotal->{amount},
65 classnum => '', #ignored in this format
66 duration => $subtotal->{duration},
67 phonenum => $phonenum,
68 accountcode => '', #ignored in this format
69 startdate => '', #could use the earliest startdate in the bunch?
70 regionname => '', #no, we're using prefix instead
71 detail => $self->csv->string,
75 # supposedly the compiler is smart enough to do this in place
76 @$buffer = sort { $a->{Hash}->{phonenum} cmp $b->{Hash}->{phonenum} }