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