clean up various other RT initialization inconsistancy, RT#18719
[freeside.git] / httemplate / search / cust_bill_event.cgi
1 <% include( 'elements/search.html',
2                  'title'       => $title,
3                  'html_init'   => $html_init,
4                  'menubar'     => $menubar,
5                  'name'        => 'billing events',
6                  'query'       => $sql_query,
7                  'count_query' => $count_sql,
8                  'header'      => [ 'Event',
9                                     'Date',
10                                     'Status',
11                                     #'Inv #', 'Inv Date', 'Cust #',
12                                     'Invoice',
13                                     FS::UI::Web::cust_header(),
14                                   ],
15                  'fields' => [
16                                'event',
17                                sub { time2str("%b %d %Y %T", $_[0]->_date) },
18                                sub { 
19                                      #my $cust_bill_event = shift;
20                                      my $status = $_[0]->status;
21                                      $status .= ': '.$_[0]->statustext
22                                        if $_[0]->statustext;
23                                      $status;
24                                    },
25                                sub {
26                                      #my $cust_bill_event = shift;
27                                      'Invoice #'. $_[0]->invnum.
28                                      ' ('.
29                                        time2str("%D", $_[0]->cust_bill_date).
30                                      ')';
31                                    },
32                                \&FS::UI::Web::cust_fields,
33                              ],
34                 'align' => 'lrlr'.FS::UI::Web::cust_aligns(),
35                 'links' => [
36                               '',
37                               '',
38                               '',
39                               sub {
40                                 my $part_bill_event = shift;
41                                 my $template = $part_bill_event->templatename;
42                                 $template .= '-' if $template;
43                                 [ "${p}view/cust_bill.cgi?$template", 'invnum'];
44                               },
45                               ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
46                                     FS::UI::Web::cust_header()
47                               ),
48                             ],
49                  'color' => [ 
50                               '',
51                               '',
52                               '',
53                               '',
54                               FS::UI::Web::cust_colors(),
55                             ],
56                  'style' => [ 
57                               '',
58                               '',
59                               '',
60                               '',
61                               FS::UI::Web::cust_styles(),
62                             ],
63              )
64 %>
65 <%init>
66
67 my $curuser = $FS::CurrentUser::CurrentUser;
68
69 die "access denied"
70   unless $curuser->access_right('Billing event reports')
71       or $curuser->access_right('View customer billing events')
72          && $cgi->param('invnum') =~ /^(\d+)$/;
73
74 my $title = $cgi->param('failed')
75               ? 'Failed invoice events'
76               : 'Invoice events';
77
78 my %search = ();
79
80 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
81   $search{agentnum} = $1;
82 }
83
84 ($search{beginning}, $search{ending})
85   = FS::UI::Web::parse_beginning_ending($cgi);
86
87 if ( $cgi->param('failed') ) {
88   $search{failed} = '1';
89 }
90
91 if ( $cgi->param('part_bill_event.payby') =~ /^(\w+)$/ ) {
92   $search{payby} = $1;
93 }
94
95 if ( $cgi->param('invnum') =~ /^(\d+)$/ ) {
96   $search{invnum} = $1;
97 }
98
99 my $where = 'WHERE '. FS::cust_bill_event->search_sql_where( \%search );
100
101 my $join = 'LEFT JOIN part_bill_event USING ( eventpart ) '.
102            'LEFT JOIN cust_bill       USING ( invnum    ) '.
103            'LEFT JOIN cust_main       USING ( custnum   ) ';
104
105 my $sql_query = {
106   'table'     => 'cust_bill_event',
107   'select'    => join(', ',
108                     'cust_bill_event.*',
109                     'part_bill_event.event',
110                     'cust_bill.custnum',
111                     'cust_bill._date AS cust_bill_date',
112                     'cust_main.custnum AS cust_main_custnum',
113                     FS::UI::Web::cust_sql_fields(),
114                   ),
115   'hashref'   => {}, 
116   'extra_sql' => $where,
117   'order_by'  => 'ORDER BY _date ASC',
118   'addl_from' => $join,
119 };
120
121 my $count_sql = "SELECT COUNT(*) FROM cust_bill_event $join $where";
122
123 my $conf = new FS::Conf;
124
125 my $html_init = '
126     <FONT SIZE="+1">Invoice events are the deprecated, old-style actions taken o
127 n open invoices.  See Reports-&gt;Billing events-&gt;Billing events for current event reports.</FONT><BR><BR>';
128
129 $html_init .= join("\n", map {
130   ( my $action = $_ ) =~ s/_$//;
131   include('/elements/progress-init.html',
132             $_.'form',
133             [ keys(%search) ],
134             "../misc/${_}invoice_events.cgi",
135             { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
136             $_, #key
137          ),
138   qq!<FORM NAME="${_}form">!,
139   qq!<INPUT TYPE="hidden" NAME="action" VALUE="$_">!, #not used though
140   (map {qq!<INPUT TYPE="hidden" NAME="$_" VALUE="$search{$_}">!} keys(%search)),
141   qq!</FORM>!
142 } qw( print_ email_ fax_ ) );
143
144 my $menubar = [];
145
146 if ( $curuser->access_right('Resend invoices') ) {
147
148   push @$menubar, 'Re-print these events' =>
149                     "javascript:print_process()",
150                   'Re-email these events' =>
151                     "javascript:email_process()",
152                 ;
153
154   push @$menubar, 'Re-fax these events' =>
155                     "javascript:fax_process()"
156     if $conf->exists('hylafax');
157
158 }
159
160 my $link_cust = sub {
161   my $cust_bill_event = shift;
162   $cust_bill_event->cust_main_custnum
163     ? [ "${p}view/cust_main.cgi?", 'custnum' ]
164     : '';
165 };
166
167 </%init>