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