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