escape cust_event.statustext so dumps coming back from failed transactions are viewab...
[freeside.git] / httemplate / search / cust_event.html
1 <& 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                                     'Trigger',
12                                     #'Inv #', 'Inv Date', 'Cust #',
13                                     #'Invoice',
14                                     
15                                     FS::UI::Web::cust_header(), #'cust_main_custnum',
16                                   ],
17                  'fields' => [
18                                'event',
19                                sub { time2str("%b %d %Y %T", $_[0]->_date) },
20                                $status_sub,
21                                $trigger_sub,
22                                #sub {
23                                #      #my $cust_event = shift;
24                                #      'Invoice #'. $_[0]->invnum.
25                                #      ' ('.
26                                #        time2str("%D", $_[0]->cust_bill_date).
27                                #      ')';
28                                #    },
29                                \&FS::UI::Web::cust_fields,
30                              ],
31                 'align' => 'lrll'.FS::UI::Web::cust_aligns(),
32                 'links' => [
33                               '',
34                               '',
35                               '',
36                               $trigger_link,
37                               #sub {
38                               #  my $part_event = shift;
39                               #  #XXX
40                               #  my $template = $part_event->templatename;
41                               #  $template .= '-' if $template;
42                               #  [ "${p}view/cust_bill.cgi?$template", 'invnum'];
43                               #},
44
45                               ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
46                                     FS::UI::Web::cust_header()
47                               ),
48                             ],
49                  'color' => [ 
50                               '',
51                               '',
52                               '',
53                               '',
54                               #'',
55                               FS::UI::Web::cust_colors(),
56                             ],
57                  'style' => [ 
58                               '',
59                               '',
60                               '',
61                               '',
62                               #'',
63                               FS::UI::Web::cust_styles(),
64                             ],
65 &>
66 <%once>
67
68 my $status_sub = sub { 
69   my $cust_event = shift;
70
71   my $status = $cust_event->status;
72   $status .= ': '. encode_entities($cust_event->statustext)
73     if $cust_event->statustext;
74
75   my $part_event = $cust_event->part_event;
76
77   if ( $part_event->eventtable eq 'cust_bill'
78        && ( $part_event->templatename || $part_event->option('notice_name') )
79      )
80   {
81     my $link = 'invnum='. $cust_event->tablenum;
82     $link .= ';template='. uri_escape($part_event->templatename)
83       if $part_event->templatename;
84     $link .= ';notice_name='. uri_escape($part_event->option('notice_name'))
85       if $part_event->option('notice_name');
86
87     my $conf = new FS::Conf;
88     my $cust_bill = $cust_event->cust_X;
89
90     $status .= qq{
91           ( <A HREF="${p}view/cust_bill.cgi?$link">view</A>
92           | <A HREF="${p}view/cust_bill-pdf.cgi?$link">view&nbsp;typeset</A>
93           | <A HREF="${p}misc/send-invoice.cgi?method=print;$link">re-print</A>
94     };
95
96     if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) { 
97       $status .= qq{
98             | <A HREF="${p}misc/send-invoice.cgi?method=email;$link">re-email</A>
99       };
100     } 
101    
102     if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { 
103       $status .= qq{
104             | <A HREF="${p}misc/send-invoice.cgi?method=fax;$link">re-fax</A>
105       }
106     } 
107
108     $status .= ' ) ';
109
110   }
111
112   $status;
113 };
114
115 my $trigger_sub = sub {
116   my $cust_event = shift;
117   my $eventtable = $cust_event->eventtable;
118   my $label = FS::part_event->eventtable_labels->{$eventtable};
119   #if ( $eventtable eq 'cust_pkg' || $eventtable eq 'cust_bill' ) {
120     "$label #". $cust_event->tablenum;
121   #} else {
122   #  $label;
123   #}
124 };
125
126 my $trigger_link = sub {
127   my $cust_event = shift;
128   my $eventtable = $cust_event->eventtable;
129   if ( $eventtable eq 'cust_pkg' ) {
130     my $custnum = $cust_event->cust_main_custnum;
131     my $show = $FS::CurrentUser::CurrentUser->default_customer_view =~ /^(jumbo|packages)$/
132                  ? ''
133                  : ';show=packages';
134     my $pkgnum = $cust_event->tablenum;
135     my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
136     [ "${p}view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#cust_pkg", 'tablenum' ];
137   } else {
138     [ "${p}view/$eventtable.cgi?", 'tablenum' ];
139   }
140 };
141
142 </%once>
143 <%init>
144
145 my $curuser = $FS::CurrentUser::CurrentUser;
146
147 die "access denied"
148   unless $curuser->access_right('Billing event reports')
149       or $curuser->access_right('View customer billing events')
150          && (    $cgi->param('custnum') =~ /^(\d+)$/
151               || $cgi->param('invnum')  =~ /^(\d+)$/
152               || $cgi->param('pkgnum')  =~ /^(\d+)$/
153             );
154
155 my $title = $cgi->param('failed') ? 'Failed billing events' : 'Billing events';
156
157 my %search = ();
158
159 my @scalars = qw( agentnum status custnum invnum pkgnum failed );
160 for my $param (@scalars) {
161   $search{$param} = scalar( $cgi->param($param) )
162     if $cgi->param($param);
163 }
164
165 #lists
166 my @lists = qw( payby eventpart );
167 foreach my $param (@lists) {
168   $search{$param} = [ $cgi->param($param) ];
169 }
170
171 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
172 $search{'beginning'} = $beginning;
173 $search{'ending'}    = $ending;
174
175 my $where = ' WHERE '. FS::cust_event->search_sql_where( \%search );
176
177 my $join = FS::cust_event->join_sql();
178
179 my $sql_query = {
180   'table'     => 'cust_event',
181   'select'    => join(', ',
182                     'cust_event.*',
183                     'part_event.*',
184                     #'cust_bill.custnum',
185                     #'cust_bill._date AS cust_bill_date',
186                     'cust_main.custnum AS cust_main_custnum',
187                     FS::UI::Web::cust_sql_fields(),
188                   ),
189   'hashref'   => {}, 
190   'extra_sql' => $where,
191   'order_by'  => 'ORDER BY _date ASC',
192   'addl_from' => $join,
193 };
194
195 my $count_sql = "SELECT COUNT(*) FROM cust_event $join $where";
196
197 my $conf = new FS::Conf;
198
199 my @params = ( @scalars, qw( beginning ending ) );
200
201 my $html_init = join("\n", map {
202   ( my $action = $_ ) =~ s/_$//;
203   include('/elements/progress-init.html',
204             $_.'form',
205             [ 'action', @params ],
206             "../misc/${_}events.cgi",
207             { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
208             $_, #key
209          ),
210   qq!<FORM NAME="${_}form">!,
211   qq!<INPUT TYPE="hidden" NAME="action" VALUE="$_">!, #not used though
212   ( map { my $value = encode_entities( $search{$_} );
213           qq(<INPUT TYPE="hidden" NAME="$_" VALUE="$value">);
214         }
215         @params #keys %search
216   ),
217   ( map { my $value = encode_entities( join(',', @{ $search{$_} } ) );
218           qq(<INPUT TYPE="hidden" NAME="$_" VALUE="$value">);
219         }
220         @lists
221   ),
222   qq!</FORM>!
223 } qw( print_ email_ fax_ ) ).
224
225 '<SCRIPT TYPE="text/javascript">
226
227 function confirm_print_process() {
228   if ( ! confirm("Are you sure you want to reprint these invoices?") ) {
229     return;
230   }
231   print_process();
232 }
233 function confirm_email_process() {
234   if ( ! confirm("Are you sure you want to re-email these invoices?") ) {
235     return;
236   }
237   email_process();
238 }
239 function confirm_fax_process() {
240   if ( ! confirm("Are you sure you want to re-fax these invoices?") ) {
241     return;
242   }
243   fax_process();
244 }
245
246 </SCRIPT>';
247
248 my $menubar = [];
249
250 if ( $curuser->access_right('Resend invoices') ) {
251
252   push @$menubar, 'Re-print these events' =>
253                     "javascript:confirm_print_process()",
254                   'Re-email these events' =>
255                     "javascript:confirm_email_process()",
256                 ;
257
258   push @$menubar, 'Re-fax these events' =>
259                     "javascript:confirm_fax_process()"
260     if $conf->exists('hylafax');
261
262 }
263
264 my $link_cust = sub {
265   my $cust_event = shift;
266   $cust_event->cust_main_custnum
267     ? [ "${p}view/cust_main.cgi?", 'cust_main_custnum' ]
268     : '';
269 };
270
271 </%init>