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