don't show 'N/A' statustext as a failed billing event
[freeside.git] / httemplate / search / cust_bill_event.cgi
1 <%
2
3 my $title = $cgi->param('failed') ? 'Failed invoice events' : 'Invoice events';
4
5 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
6
7 ##tie my %hash, 'Tie::DxHash', 
8 #my %hash = (
9 #      _date => { op=> '>=', value=>$beginning },
10 ## i wish...
11 ##      _date => { op=> '<=', value=>$ending },
12 #);
13 #$hash{'statustext'} = { op=> '!=', value=>'' }
14 #  if $cgi->param('failed');
15
16 my $where = " WHERE cust_bill_event._date >= $beginning".
17             "   AND cust_bill_event._date <= $ending";
18 $where .= " AND statustext != '' ".
19           " AND statustext IS NOT NULL ".
20           " AND statustext != 'N/A' "
21   if $cgi->param('failed');
22
23 my $sql_query = {
24   'table'     => 'cust_bill_event',
25   #'hashref'   => \%hash,
26   'hashref'   => {}, 
27   'select'    => join(', ',
28                    'cust_bill_event.*',
29                    'part_bill_event.event',
30                    'cust_bill.custnum',
31                    'cust_bill._date AS cust_bill_date',
32                    'cust_main.custnum AS cust_main_custnum',
33                    FS::UI::Web::cust_sql_fields(),
34                  ),
35   'extra_sql' => "$where ORDER BY _date ASC",
36   'addl_from' => 'LEFT JOIN part_bill_event USING ( eventpart ) '.
37                  'LEFT JOIN cust_bill       USING ( invnum    ) '.
38                  'LEFT JOIN cust_main       USING ( custnum   ) ',
39 };
40
41 my $count_sql = "select count(*) from cust_bill_event $where";
42
43 my $conf = new FS::Conf;
44
45 my $failed = $cgi->param('failed');
46
47 my $html_init = join("\n", map {
48   ( my $action = $_ ) =~ s/_$//;
49   include('/elements/progress-init.html',
50             $_.'form',
51             [ 'action', 'beginning', 'ending', 'failed' ],
52             "../misc/${_}invoice_events.cgi",
53             { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
54             $_, #key
55          ),
56   qq!<FORM NAME="${_}form">!,
57   qq!<INPUT TYPE="hidden" NAME="action" VALUE="$_">!, #not used though
58   qq!<INPUT TYPE="hidden" NAME="beginning" VALUE="$beginning">!,
59   qq!<INPUT TYPE="hidden" NAME="ending"    VALUE="$ending">!,
60   qq!<INPUT TYPE="hidden" NAME="failed"    VALUE="$failed">!,
61   qq!</FORM>!
62 } qw( print_ email_ fax_ ) );
63
64 my $menubar =  [
65                  'Main menu' => $p,
66                  'Re-print these events' =>
67                    "javascript:print_process()",
68                  'Re-email these events' =>
69                    "javascript:email_process()",
70                ];
71
72 push @$menubar, 'Re-fax these events' =>
73                   "javascript:fax_process()"
74   if $conf->exists('hylafax');
75
76 my $link_cust = sub {
77   my $cust_bill_event = shift;
78   $cust_bill_event->cust_main_custnum
79     ? [ "${p}view/cust_main.cgi?", 'custnum' ]
80     : '';
81 };
82
83 %><%= include( 'elements/search.html',
84                  'title'       => $title,
85                  'html_init'   => $html_init,
86                  'menubar'     => $menubar,
87                  'name'        => 'billing events',
88                  'query'       => $sql_query,
89                  'count_query' => $count_sql,
90                  'header'      => [ 'Event',
91                                     'Date',
92                                     'Status',
93                                     #'Inv #', 'Inv Date', 'Cust #',
94                                     'Invoice',
95                                     FS::UI::Web::cust_header(),
96                                   ],
97                  'fields' => [
98                                'event',
99                                sub { time2str("%b %d %Y %T", $_[0]->_date) },
100                                sub { 
101                                      #my $cust_bill_event = shift;
102                                      my $status = $_[0]->status;
103                                      $status .= ': '.$_[0]->statustext
104                                        if $_[0]->statustext;
105                                      $status;
106                                    },
107                                sub {
108                                      #my $cust_bill_event = shift;
109                                      'Invoice #'. $_[0]->invnum.
110                                      ' ('.
111                                        time2str("%D", $_[0]->cust_bill_date).
112                                      ')';
113                                    },
114                                \&FS::UI::Web::cust_fields,
115                              ],
116                  'links' => [
117                               '',
118                               '',
119                               '',
120                               sub {
121                                 my $part_bill_event = shift;
122                                 my $template = $part_bill_event->templatename;
123                                 $template .= '-' if $template;
124                                 [ "${p}view/cust_bill.cgi?$template", 'invnum'];
125                               },
126                               ( map { $link_cust } FS::UI::Web::cust_header() ),
127                             ],
128              )
129 %>