1 <& elements/search.html,
3 'html_init' => include('.init'),
5 'name' => 'billing events',
7 'count_query' => $count_sql,
12 #'Inv #', 'Inv Date', 'Cust #',
15 FS::UI::Web::cust_header(), #'cust_main_custnum',
19 sub { time2str("%b %d %Y %T", $_[0]->_date) },
23 # #my $cust_event = shift;
24 # 'Invoice #'. $_[0]->invnum.
26 # time2str("%D", $_[0]->cust_bill_date).
29 \&FS::UI::Web::cust_fields,
31 'align' => 'lrll'.FS::UI::Web::cust_aligns(),
38 # my $part_event = shift;
40 # my $template = $part_event->templatename;
41 # $template .= '-' if $template;
42 # [ "${p}view/cust_bill.cgi?$template", 'invnum'];
45 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
46 FS::UI::Web::cust_header()
55 FS::UI::Web::cust_colors(),
63 FS::UI::Web::cust_styles(),
68 my $status_sub = sub {
69 my $cust_event = shift;
71 my $status = $cust_event->status;
72 $status .= ': '. encode_entities($cust_event->statustext)
73 if $cust_event->statustext;
75 my $part_event = $cust_event->part_event;
77 if ( $part_event->eventtable eq 'cust_bill'
78 && ( $part_event->templatename || $part_event->option('notice_name') )
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');
87 my $conf = new FS::Conf;
88 my $cust_bill = $cust_event->cust_X;
91 ( <A HREF="${p}view/cust_bill.cgi?$link">view</A>
92 | <A HREF="${p}view/cust_bill-pdf.cgi?$link">view typeset</A>
93 | <A HREF="${p}misc/send-invoice.cgi?method=print;$link">re-print</A>
96 if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) {
98 | <A HREF="${p}misc/send-invoice.cgi?method=email;$link">re-email</A>
102 if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) {
104 | <A HREF="${p}misc/send-invoice.cgi?method=fax;$link">re-fax</A>
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;
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)$/
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 } elsif ( $eventtable eq 'cust_pay' ) {
138 [ "${p}view/$eventtable.html?paynum=", 'tablenum' ];
139 } elsif ( $eventtable eq 'cust_statement' ) {
140 [ "${p}view/$eventtable.html?", 'tablenum' ];
141 } elsif ( $eventtable eq 'cust_pay_batch' ) {
142 [ "${p}search/cust_pay_batch.cgi?batchnum=", 'cust_pay_batch_batchnum' ];
144 [ "${p}view/$eventtable.cgi?", 'tablenum' ];
150 my @scalars = qw( agentnum status custnum invnum pkgnum failed );
151 my @lists = qw( eventpart event_status );
156 my $curuser = $FS::CurrentUser::CurrentUser;
159 unless $curuser->access_right('Billing event reports')
160 or $curuser->access_right('View customer billing events')
161 && ( $cgi->param('custnum') =~ /^(\d+)$/
162 || $cgi->param('invnum') =~ /^(\d+)$/
163 || $cgi->param('pkgnum') =~ /^(\d+)$/
166 my @statuses = $cgi->param('event_status');
167 my $title = 'Billing events';
168 if ( $statuses[0] eq 'failed' and !defined($statuses[1]) ) {
169 # tweak the title if we're showing only failed events
170 $title = 'Failed billing events';
173 for my $param (@scalars) {
174 $search{$param} = scalar( $cgi->param($param) )
175 if $cgi->param($param);
179 foreach my $param (@lists) {
180 $search{$param} = [ $cgi->param($param) ];
183 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
184 $search{'beginning'} = $beginning;
185 $search{'ending'} = $ending;
187 my $where = ' WHERE '. FS::cust_event->search_sql_where( \%search );
189 my $join = FS::cust_event->join_sql() .
190 # warning: does not show the true service address for package events.
191 # the query to do that would be painfully slow.
192 'LEFT JOIN cust_location bill_location '.
193 'ON (cust_main.bill_locationnum = bill_location.locationnum) '.
194 'LEFT JOIN cust_location ship_location '.
195 'ON (cust_main.ship_locationnum = ship_location.locationnum)'.
196 # include link to referral in case it's in cust-fields
197 # (maybe we should be using FS::UI::Web::join_cust_main instead?)
198 'LEFT JOIN (select refnum, referral from part_referral) AS part_referral_x '.
199 'ON (cust_main.refnum = part_referral_x.refnum) ';
202 'table' => 'cust_event',
203 'select' => join(', ',
206 #'cust_bill.custnum',
207 #'cust_bill._date AS cust_bill_date',
208 'cust_pay_batch.batchnum AS cust_pay_batch_batchnum',
209 'cust_main.custnum AS cust_main_custnum',
210 FS::UI::Web::cust_sql_fields(),
213 'extra_sql' => $where,
214 'order_by' => 'ORDER BY _date ASC',
215 'addl_from' => $join,
219 my $count_sql = "SELECT COUNT(*) FROM cust_event $join $where";
221 my $conf = new FS::Conf;
225 if ( $curuser->access_right('Resend invoices') ) {
227 push @$menubar, 'Re-print these events' =>
228 "javascript:confirm_print_process()",
229 'Re-email these events' =>
230 "javascript:confirm_email_process()",
233 push @$menubar, 'Re-fax these events' =>
234 "javascript:confirm_fax_process()"
235 if $conf->exists('hylafax');
239 my $link_cust = sub {
240 my $cust_event = shift;
241 $cust_event->cust_main_custnum
242 ? [ "${p}view/cust_main.cgi?", 'cust_main_custnum' ]
248 % # action is part of the target URL, don't need to pass it as a param
249 % foreach my $action (qw(print email fax)) {
250 <& /elements/progress-init.html,
252 [ @scalars, @lists, 'beginning', 'ending' ],
253 "../misc/${action}_events.cgi",
254 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
257 <FORM NAME="<% $action %>_form">
258 % foreach my $param (@scalars, 'beginning', 'ending') {
259 <INPUT TYPE="hidden" NAME="<% $param %>" VALUE="<% $search{$param} |h %>">
261 % foreach my $param (@lists) {
262 % foreach my $value (@{ $search{$param} }) {
263 <INPUT TYPE="hidden" NAME="<% $param %>" VALUE="<% $value |h %>">
267 % } # foreach $action
268 <SCRIPT TYPE="text/javascript">
270 function confirm_print_process() {
271 if ( ! confirm("Are you sure you want to reprint these invoices?") ) {
276 function confirm_email_process() {
277 if ( ! confirm("Are you sure you want to re-email these invoices?") ) {
282 function confirm_fax_process() {
283 if ( ! confirm("Are you sure you want to re-fax these invoices?") ) {