Rate CDRs immediately, RT#15839
[freeside.git] / httemplate / search / report_cdr.html
1 <% include('/elements/header.html', 'Call Detail Record Search' ) %>
2
3 <SCRIPT type="text/javascript">
4     function clearfield(which){
5         var f = document.getElementById(which);
6         if ( f == null) return;
7         f.value = '';
8     }
9 </SCRIPT>
10
11 <FORM ACTION="cdr.html" METHOD="GET">
12
13 <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
14
15   <TR>
16     <TH CLASS="background" COLSPAN=2 ALIGN="left">
17       <FONT SIZE="+1">Search options</FONT>
18     </TH>
19   </TR>
20
21   <TR>
22     <TD ALIGN="right">Status: </TD>
23     <TD>
24       <SELECT NAME="freesidestatus">
25         <OPTION VALUE="">(all)</OPTION>
26         <OPTION VALUE="NULL">unprocessed</OPTION>
27         <OPTION VALUE="rated">prerated
28         <OPTION VALUE="done">processed</OPTION>
29         <OPTION VALUE="failed">skipped</OPTION>
30       </SELECT>
31     </TD>
32   </TR>
33
34 % #if ( ) {  # disable for everyone not using termination billing...
35 %   foreach my $termpart ( 1..1 ) { #qsearch('part_termination
36
37     <TR>
38       <TD ALIGN="right">Termination Status: </TD>
39       <TD>
40         <SELECT NAME="termpart<%$termpart%>status">
41           <OPTION VALUE="">(all)
42           <OPTION VALUE="NULL">unprocessed
43           <OPTION VALUE="done">processed
44         </SELECT>
45       </TD>
46     </TR>
47
48 %   }
49 % #}
50
51   <% include('/elements/tr-select-table.html',
52             field   => 'cdrtypenum',
53             label   => 'CDR Type',
54             table   => 'cdr_type',
55             name_col    => 'cdrtypename',
56             disable_empty   => 1,
57             pre_options => [    '',     'all', 
58                                 'none', 'none' ] )
59   %>
60
61   <% include ( '/elements/tr-input-beginning_ending.html' ) %>
62
63   <TR>
64     <TD ALIGN="right">Source #: </TD>
65     <TD>
66       <INPUT TYPE="text" NAME="src">
67     </TD>
68   </TR>
69
70   <TR>
71     <TD ALIGN="right">Destination #: </TD>
72     <TD>
73       <INPUT TYPE="text" NAME="dst">
74     </TD>
75   </TR>
76
77   <TR>
78     <TD ALIGN="right">Destination Context: </TD>
79     <TD>
80       <INPUT TYPE="text" NAME="dcontext">
81     </TD>
82   </TR>
83
84
85   <TR>
86     <TD ALIGN="right">Charged Party #: </TD>
87     <TD>
88       <INPUT TYPE="text" NAME="charged_party" VALUE="<% join(',', @charged_party) |h %>">
89     </TD>
90   </TR>
91
92   <TR>
93     <TD ALIGN="right">Charged Party or Source #: </TD>
94     <TD>
95       <INPUT TYPE="text" NAME="charged_party_or_src" VALUE="<% join(',', @charged_party_or_src ) |h %>" >
96     </TD>
97   </TR>
98
99   <TR>
100     <TD ALIGN="right">Last Application: </TD>
101     <TD>
102       <INPUT TYPE="text" NAME="lastapp" VALUE="" >
103     </TD>
104   </TR>
105
106   <TR>
107     <TD ALIGN="right">Freeside service #: </TD>
108     <TD>
109       <INPUT TYPE="text" NAME="svcnum" VALUE="<% join(',', @svcnum ) %>" >
110     </TD>
111   </TR>
112
113   <% include( '/elements/tr-input-lessthan_greaterthan.html',
114                 'label' => 'Duration (sec)',
115                 'field' => 'duration',
116             )
117   %>
118
119   <% include( '/elements/tr-input-lessthan_greaterthan.html',
120                 'label' => 'Billable duration (sec)',
121                 'field' => 'billsec',
122             )
123   %>
124
125   <TR>
126     <TD ALIGN="right">Top</TD>
127     <TD><INPUT TYPE="TEXT" id="top_dst" NAME="top_dst" SIZE="7" onfocus="clearfield('top_src');"> destinations</TD>
128   </TR>
129   
130   <TR>
131     <TD ALIGN="right">Top</TD>
132     <TD><INPUT TYPE="TEXT" id="top_src" NAME="top_src" SIZE="7" onfocus="clearfield('top_dst');"> sources</TD>
133   </TR>
134   
135   <TR>
136     <TD ALIGN="right"></TD>
137     <TD><INPUT TYPE="TEXT" NAME="longest" SIZE="7"> longest calls</TD>
138   </TR>
139   
140   <% include( '/elements/tr-select-cdrbatch.html' ) %>
141
142   <TR>
143     <TD ALIGN="right">Acct ID (one per-line):</TD>
144     <TD><TEXTAREA NAME="acctid"></TEXTAREA></TD>
145   </TR>
146
147   <TR>
148     <TH CLASS="background" COLSPAN=2>&nbsp;</TH>
149   </TR>
150
151   <TR>
152     <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH>
153   </TR>
154
155   <INPUT TYPE="hidden" NAME="show" VALUE="1">
156
157   <TR>
158     <TD COLSPAN=2>
159       <% include('/elements/checkboxes.html',
160                    'names_list'          => $names_list,
161                    'element_name_prefix' => 'show_',
162                    'checked_callback'    => sub { $show_default{$_[1]} },
163                                                   # my($cgi, $name) = @_;
164                 )
165       %>
166     </TD>
167   </TR>
168
169 </TABLE>
170
171 <BR>
172 <INPUT TYPE="submit" VALUE="Search Call Detail Records">
173
174 </FORM>
175
176 <% include('/elements/footer.html') %>
177 <%init>
178
179 die "access denied"
180   unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
181
182 my @fields = fields('cdr');
183 my $labels = FS::cdr->table_info->{'fields'};
184
185 #XXX config
186 my @show_default = qw(
187   calldate clid src dst dcontext charged_party
188   startdate answerdate enddate duration billsec
189   disposition amaflags accountcode userfield
190   rated_price upstream_price carrierid 
191   svcnum freesidestatus freesiderewritestatus
192 );
193 my %show_default = map { $_=>1 } @show_default;
194
195 my $names_list = [ map {
196                          [ $_ => {
197                                    'label' => 'Show '. ( $labels->{$_} || $_ )
198                                  }
199                          ]
200                        } 
201                    @fields
202                  ];
203
204 my @charged_party = ();
205 my @charged_party_or_src = ();
206 my @svcnum = ();
207 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
208   my $custnum = $1;
209
210   my $cust_main = qsearchs( {
211     'table'     => 'cust_main',
212     'hashref'   => { 'custnum' => $custnum },
213     'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
214   });
215   die "Customer not found!" unless $cust_main;
216
217   #historical?
218   foreach my $cust_pkg ( $cust_main->ncancelled_pkgs ) {
219
220     my @voip_pkgs =
221       grep { $_->plan eq 'voip_cdr' } $cust_pkg->part_pkg->self_and_bill_linked;
222     if ( scalar(@voip_pkgs) > 1 ) { 
223       die "multiple voip_cdr packages bundled\n";
224     } elsif ( !@voip_pkgs ) {
225       next;
226     }
227     my $voip_pkg = @voip_pkgs[0];
228
229     my $cdr_svc_method = $voip_pkg->option('cdr_svc_method')
230                          || 'svc_phone.phonenum';
231
232     my @cust_svc = $cust_pkg->cust_svc; #historical?
233
234     if ( $cdr_svc_method eq 'svc_phone.phonenum' ) {
235
236       my @svc_phone = map $_->svc_x,
237                         grep { $_->part_svc->svcdb eq 'svc_phone' } @cust_svc;
238
239       my @numbers = map {
240                           my $number = $_->phonenum;
241                           $number = $_->countrycode. $number
242                             unless $_->countrycode eq '1';
243                           $number;
244                         }
245                       @svc_phone;
246
247       if ( $voip_pkg->option('disable_src') ) {
248         push @charged_party, @numbers;
249       } else {
250         push @charged_party_or_src, @numbers;
251       }
252
253     } elsif ( $cdr_svc_method eq 'svc_pbx.title' ) {
254       my @svc_pbx = map $_->svc_x,
255                       grep { $_->part_svc->svcdb eq 'svc_pbx' } @cust_svc;
256       push @charged_party, map $_->title, @svc_pbx;
257     } elsif ( $cdr_svc_method eq 'svc_pbx.svcnum' ) {
258       my @cust_svc_pbx = grep { $_->part_svc->svcdb eq 'svc_pbx' } @cust_svc;
259       push @svcnum, map $_->svcnum, @cust_svc_pbx;
260     }
261
262   }
263
264   die "No CDR packages for customer $custnum\n"
265     unless @charged_party || @charged_party_or_src || @svcnum;
266
267   #die "Multiple matching metods for customer $custnum\n"
268   #  if #there's more than one
269
270 }
271
272 </%init>