voxlinesystems CDRs and quantity bs
[freeside.git] / httemplate / search / cdr.html
1 <% include( 'elements/search.html',
2                'title' => $title,
3                'name'  => 'call detail records',
4                'query' => { 'table'     => 'cdr',
5                             'hashref'   => $hashref,
6                             'extra_sql' => $qsearch,
7                             'order_by'  => 'ORDER BY calldate',
8                           },
9                'count_query' => $count_query,
10                'header' => [ fields('cdr') ], #XXX fill in some nice names
11                'fields' => [ fields('cdr') ], #XXX fill in some pretty-print
12                                               # processing, etc.
13              )
14 %>
15 <%init>
16
17 die "access denied"
18   unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
19
20 my $title = 'Call Detail Records';
21 my $hashref = {};
22
23 #process params for CDR search, populate $hashref...
24 # and fixup $count_query
25
26 my @search = ();
27
28 ###
29 # freesidestatus
30 ###
31
32 if ( $cgi->param('freesidestatus') eq 'NULL' ) {
33
34   my $title = "Unprocessed $title";
35   $hashref->{'freesidestatus'} = ''; # Record.pm will take care of it
36   push @search, "( freesidestatus IS NULL OR freesidestatus = '' )";
37
38 } elsif ( $cgi->param('freesidestatus') =~ /^([\w ]+)$/ ) {
39
40   my $title = "Processed $title";
41   $hashref->{'freesidestatus'} = $1;
42   push @search, "freesidestatus = '$1'";
43
44 }
45
46 ###
47 # dates
48 ###
49
50 my $str2time_sql = str2time_sql;
51
52 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
53 push @search, "$str2time_sql calldate) >= $beginning ",
54               "$str2time_sql calldate) <= $ending";
55
56 ###
57 # duration / billsec
58 ###
59
60 push @search, FS::UI::Web::parse_lt_gt($cgi, 'duration');
61 push @search, FS::UI::Web::parse_lt_gt($cgi, 'billsec');
62
63 ###
64 # src/dest/charged_party
65 ###
66
67 my @qsearch = @search;
68
69 if ( $cgi->param('src') =~ /^\s*([\d\-\+\ ]+)\s*$/ ) {
70   ( my $src = $1 ) =~ s/\D//g;
71   $hashref->{'src'} = $src;
72   push @search, "src = '$src'";
73 }
74
75 if ( $cgi->param('dst') =~ /^\s*([\d\-\+ ]+)\s*$/ ) {
76   ( my $dst = $1 ) =~ s/\D//g;
77   $hashref->{'dst'} = $dst;
78   push @search, "dst = '$dst'";
79 }
80
81 if ( $cgi->param('charged_party') =~ /^\s*([\d\-\+\ ]+)\s*$/ ) {
82   ( my $charged_party = $1 ) =~ s/\D//g;
83   #$hashref->{'charged_party'} = $charged_party;
84   #push @search, "charged_party = '$charged_party'";
85   #XXX countrycode
86   push @search,  " (    charged_party = '$charged_party'
87                      OR charged_party = '1$charged_party' ) ";
88   push @qsearch, " (    charged_party = '$charged_party'
89                     OR charged_party = '1$charged_party' ) ";
90 }
91
92
93 ###
94 # finish it up
95 ###
96
97 my $search = join(' AND ', @search);
98 $search = "WHERE $search" if $search;
99
100 my $count_query = "SELECT COUNT(*) FROM cdr $search";
101
102 my $qsearch = join(' AND ', @qsearch);
103 $qsearch = ( scalar(keys %$hashref) ? ' AND ' : ' WHERE ' ) . $qsearch
104   if $qsearch;
105
106 </%init>