summaryrefslogtreecommitdiff
path: root/httemplate/search/report_cdr.html
blob: 4c16f74c01b10fe4dc44d33df09e44f7cc7ef1b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<% include('/elements/header.html', 'Call Detail Record Search' ) %>

<SCRIPT type="text/javascript">
    function clearfield(which){
        var f = document.getElementById(which);
        if ( f == null) return;
        f.value = '';
    }
</SCRIPT>

<FORM ACTION="cdr.html" METHOD="GET">

<TABLE BGCOLOR="#cccccc" CELLSPACING=0>

  <TR>
    <TH CLASS="background" COLSPAN=2 ALIGN="left">
      <FONT SIZE="+1">Search options</FONT>
    </TH>
  </TR>

  <TR>
    <TD ALIGN="right">Status: </TD>
    <TD>
      <SELECT NAME="freesidestatus">
        <OPTION VALUE="">(all)</OPTION>
        <OPTION VALUE="NULL">unprocessed</OPTION>
%# <OPTION VALUE="processing-tiered">processing</OPTION>
        <OPTION VALUE="rated">prerated
        <OPTION VALUE="no-charge">processed (included)</OPTION>
        <OPTION VALUE="done">processed (billed)</OPTION>
        <OPTION VALUE="skipped">skipped</OPTION>
        <OPTION VALUE="failed">failed</OPTION>
      </SELECT>
    </TD>
  </TR>

% #if ( ) {  # disable for everyone not using termination billing...
%   foreach my $termpart ( 1..1 ) { #qsearch('part_termination

    <TR>
      <TD ALIGN="right">Termination Status: </TD>
      <TD>
        <SELECT NAME="termpart<%$termpart%>status">
          <OPTION VALUE="">(all)
          <OPTION VALUE="NULL">unprocessed
          <OPTION VALUE="done">processed
        </SELECT>
      </TD>
    </TR>

%   }
% #}

  <% include('/elements/tr-select-table.html',
            field   => 'cdrtypenum',
            label   => 'CDR Type',
            table   => 'cdr_type',
            name_col    => 'cdrtypename',
            disable_empty   => 1,
            pre_options => [    '',     'all', 
                                'none', 'none' ] )
  %>

  <% include ( '/elements/tr-input-beginning_ending.html' ) %>

  <TR>
    <TD ALIGN="right">Source #: </TD>
    <TD>
      <INPUT TYPE="text" NAME="src">
    </TD>
  </TR>

  <TR>
    <TD ALIGN="right">Destination #: </TD>
    <TD>
      <INPUT TYPE="text" NAME="dst">
    </TD>
  </TR>

  <TR>
    <TD ALIGN="right">Destination Context: </TD>
    <TD>
      <INPUT TYPE="text" NAME="dcontext">
    </TD>
  </TR>


  <TR>
    <TD ALIGN="right">Charged Party #: </TD>
    <TD>
      <INPUT TYPE="text" NAME="charged_party" VALUE="<% join(',', @charged_party) |h %>">
    </TD>
  </TR>

  <TR>
    <TD ALIGN="right">Charged Party or Source #: </TD>
    <TD>
      <INPUT TYPE="text" NAME="charged_party_or_src" VALUE="<% join(',', @charged_party_or_src ) |h %>" >
    </TD>
  </TR>

  <TR>
    <TD ALIGN="right">Last Application: </TD>
    <TD>
      <INPUT TYPE="text" NAME="lastapp" VALUE="" >
    </TD>
  </TR>

  <TR>
    <TD ALIGN="right">Freeside service #: </TD>
    <TD>
      <INPUT TYPE="text" NAME="svcnum" VALUE="<% join(',', @svcnum ) %>" >
    </TD>
  </TR>

  <% include( '/elements/tr-input-lessthan_greaterthan.html',
                'label' => 'Duration (sec)',
                'field' => 'duration',
            )
  %>

  <% include( '/elements/tr-input-lessthan_greaterthan.html',
                'label' => 'Billable duration (sec)',
                'field' => 'billsec',
            )
  %>

  <TR>
    <TD ALIGN="right">Top</TD>
    <TD><INPUT TYPE="TEXT" id="top_dst" NAME="top_dst" SIZE="7" onfocus="clearfield('top_src');"> destinations</TD>
  </TR>
  
  <TR>
    <TD ALIGN="right">Top</TD>
    <TD><INPUT TYPE="TEXT" id="top_src" NAME="top_src" SIZE="7" onfocus="clearfield('top_dst');"> sources</TD>
  </TR>
  
  <TR>
    <TD ALIGN="right"></TD>
    <TD><INPUT TYPE="TEXT" NAME="longest" SIZE="7"> longest calls</TD>
  </TR>
  
  <% include( '/elements/tr-select-cdrbatch.html' ) %>

  <TR>
    <TD ALIGN="right">Acct ID (one per-line):</TD>
    <TD><TEXTAREA NAME="acctid"></TEXTAREA></TD>
  </TR>

  <TR>
    <TD ALIGN="right">Acct Code (one per-line):</TD>
    <TD><TEXTAREA NAME="accountcode"></TEXTAREA></TD>
  </TR>

  <TR>
    <TH CLASS="background" COLSPAN=2>&nbsp;</TH>
  </TR>

  <TR>
    <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH>
  </TR>

  <INPUT TYPE="hidden" NAME="show" VALUE="1">

  <TR>
    <TD COLSPAN=2>
      <% include('/elements/checkboxes.html',
                   'names_list'          => $names_list,
                   'element_name_prefix' => 'show_',
                   'checked_callback'    => sub { $show_default{$_[1]} },
                                                  # my($cgi, $name) = @_;
                )
      %>
    </TD>
  </TR>

</TABLE>

<BR>
<INPUT TYPE="submit" VALUE="Search Call Detail Records">

</FORM>

<% include('/elements/footer.html') %>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('List rating data');

my @fields = fields('cdr');
push @fields, 'ratename';
push @fields, map "cdr_termination.$_", qw( rated_price rated_seconds rated_minutes rated_granularity status svcnum );

my $labels = FS::cdr->table_info->{'fields'};
$labels->{ratename} = 'Rate plan';
$labels->{'cdr_termination.rated_price'} = 'Termination rated price';
$labels->{'cdr_termination.rated_seconds'} = 'Termination rated seconds';
$labels->{'cdr_termination.rated_minutes'} = 'Termination rated minutes';
$labels->{'cdr_termination.rated_granularity'} = 'Termination rated granularity';
$labels->{'cdr_termination.status'} = 'Termination status';
$labels->{'cdr_termination.svcnum'} = 'Termination service';

my $conf = new FS::Conf;
my $default_phone_countrycode =
  $conf->config('default_phone_countrycode') || '1';

#XXX config
my @show_default = qw(
  calldate clid src dst dcontext charged_party
  startdate answerdate enddate duration billsec
  disposition amaflags accountcode userfield
  rated_price upstream_price carrierid 
  svcnum freesidestatus freesiderewritestatus
);
my %show_default = map { $_=>1 } @show_default;

my $names_list = [ map {
                         [ $_ => {
                                   'label' => 'Show '. ( $labels->{$_} || $_ )
                                 }
                         ]
                       } 
                   @fields
                 ];

my @charged_party = ();
my @charged_party_or_src = ();
my @svcnum = ();
if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
  my $custnum = $1;

  my $cust_main = qsearchs( {
    'table'     => 'cust_main',
    'hashref'   => { 'custnum' => $custnum },
    'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
  });
  die "Customer not found!" unless $cust_main;

  #historical packages?  It would help, it was still usage, it happened
  foreach my $cust_pkg ( $cust_main->ncancelled_pkgs ) {

    my @voip_pkgs =
      grep { $_->plan eq 'voip_cdr' } $cust_pkg->part_pkg->self_and_bill_linked;
    if ( scalar(@voip_pkgs) > 1 ) { 
      die "multiple voip_cdr packages bundled\n";
    } elsif ( !@voip_pkgs ) {
      next;
    }
    my $voip_pkg = @voip_pkgs[0];

    my $cdr_svc_method = $voip_pkg->option('cdr_svc_method')
                         || 'svc_phone.phonenum';

    my @cust_svc = $cust_pkg->cust_svc; #historical?

    if ( $cdr_svc_method eq 'svc_phone.phonenum' ) {

      my @svc_phone = map $_->svc_x,
                        grep { $_->part_svc->svcdb eq 'svc_phone' } @cust_svc;

      my @numbers = map {
                          my $number = $_->phonenum;
                          $number = $_->countrycode. $number
                           unless $_->countrycode eq $default_phone_countrycode;
                          $number;
                        }
                      @svc_phone;

      if ( $voip_pkg->option('disable_src') ) {
        push @charged_party, @numbers;
      } else {
        push @charged_party_or_src, @numbers;
      }

    } elsif ( $cdr_svc_method eq 'svc_pbx.title' ) {
      my @svc_pbx = map $_->svc_x,
                      grep { $_->part_svc->svcdb eq 'svc_pbx' } @cust_svc;
      push @charged_party, map $_->title, @svc_pbx;
    } elsif ( $cdr_svc_method eq 'svc_pbx.svcnum' ) {
      my @cust_svc_pbx = grep { $_->part_svc->svcdb eq 'svc_pbx' } @cust_svc;
      push @svcnum, map $_->svcnum, @cust_svc_pbx;
    }

  }

  die "No CDR packages for customer $custnum\n"
    unless @charged_party || @charged_party_or_src || @svcnum;

  #die "Multiple matching metods for customer $custnum\n"
  #  if #there's more than one

}

</%init>