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 my $acctids = ($self->{acctids} ||= []);
28 foreach my $cdr (@_) {
29 my $object = $self->{inbound} ? $cdr->cdr_termination(1) : $cdr;
30 my $svcnum = $object->svcnum; # yes, $object->svcnum.
32 my $subtotal = ($svcnums->{$svcnum} ||=
33 { count => 0, duration => 0, amount => 0 });
35 $subtotal->{duration} += $object->rated_seconds;
36 $subtotal->{amount} += $object->rated_price
37 if $object->freesidestatus ne 'no-charge';
39 push @$acctids, $cdr->acctid;
45 my $svcnums = $self->{svcnums};
46 my $buffer = $self->{buffer};
47 foreach my $svcnum (keys %$svcnums) {
49 my $subtotal = $svcnums->{$svcnum};
50 next if $subtotal->{amount} < 0.01;
52 my $cust_svc = qsearchs('cust_svc', { svcnum => $svcnum })
53 or die "svcnum #$svcnum not found";
54 my $phonenum = $cust_svc->svc_x->label;
55 warn "processing $phonenum\n" if $DEBUG;
60 int($subtotal->{duration}/60) . ' min',
61 $self->money_char . sprintf('%.02f',$subtotal->{amount}),
64 warn "adding detail: ".$self->csv->string."\n" if $DEBUG;
66 push @$buffer, FS::cust_bill_pkg_detail->new({
67 amount => $subtotal->{amount},
69 classnum => '', #ignored in this format
70 duration => $subtotal->{duration},
71 phonenum => $phonenum,
72 accountcode => '', #ignored in this format
73 startdate => '', #could use the earliest startdate in the bunch?
74 regionname => '', #no, we're using prefix instead
75 detail => $self->csv->string,
76 acctid => $self->{acctids},
80 # supposedly the compiler is smart enough to do this in place
81 @$buffer = sort { $a->{Hash}->{phonenum} cmp $b->{Hash}->{phonenum} }