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