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