3 my $title = $cgi->param('failed')
4 ? 'Failed invoice events'
9 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
10 push @search, "agentnum = $1";
11 #my $agent = qsearchs('agent', { 'agentnum' => $1 } );
12 #die "unknown agentnum $1" unless $agent;
15 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
16 push @search, "cust_bill_event._date >= $beginning",
17 "cust_bill_event._date <= $ending";
19 if ( $cgi->param('failed') ) {
20 push @search, "statustext != ''",
21 "statustext IS NOT NULL",
22 "statustext != 'N/A'";
25 if ( $cgi->param('part_bill_event.payby') =~ /^(\w+)$/ ) {
26 push @search, "part_bill_event.payby = '$1'";
29 #here is the agent virtualization
30 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
32 my $where = 'WHERE '. join(' AND ', @search );
34 my $join = 'LEFT JOIN part_bill_event USING ( eventpart ) '.
35 'LEFT JOIN cust_bill USING ( invnum ) '.
36 'LEFT JOIN cust_main USING ( custnum ) ';
39 'table' => 'cust_bill_event',
40 'select' => join(', ',
42 'part_bill_event.event',
44 'cust_bill._date AS cust_bill_date',
45 'cust_main.custnum AS cust_main_custnum',
46 FS::UI::Web::cust_sql_fields(),
49 'extra_sql' => "$where ORDER BY _date ASC",
53 my $count_sql = "SELECT COUNT(*) FROM cust_bill_event $join $where";
55 my $conf = new FS::Conf;
57 my $failed = $cgi->param('failed');
59 my $html_init = join("\n", map {
60 ( my $action = $_ ) =~ s/_$//;
61 include('/elements/progress-init.html',
63 [ 'action', 'beginning', 'ending', 'failed' ],
64 "../misc/${_}invoice_events.cgi",
65 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
68 qq!<FORM NAME="${_}form">!,
69 qq!<INPUT TYPE="hidden" NAME="action" VALUE="$_">!, #not used though
70 qq!<INPUT TYPE="hidden" NAME="beginning" VALUE="$beginning">!,
71 qq!<INPUT TYPE="hidden" NAME="ending" VALUE="$ending">!,
72 qq!<INPUT TYPE="hidden" NAME="failed" VALUE="$failed">!,
74 } qw( print_ email_ fax_ ) );
77 'Re-print these events' =>
78 "javascript:print_process()",
79 'Re-email these events' =>
80 "javascript:email_process()",
83 push @$menubar, 'Re-fax these events' =>
84 "javascript:fax_process()"
85 if $conf->exists('hylafax');
88 my $cust_bill_event = shift;
89 $cust_bill_event->cust_main_custnum
90 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
95 <% include( 'elements/search.html',
97 'html_init' => $html_init,
98 'menubar' => $menubar,
99 'name' => 'billing events',
100 'query' => $sql_query,
101 'count_query' => $count_sql,
102 'header' => [ 'Event',
105 #'Inv #', 'Inv Date', 'Cust #',
107 FS::UI::Web::cust_header(),
111 sub { time2str("%b %d %Y %T", $_[0]->_date) },
113 #my $cust_bill_event = shift;
114 my $status = $_[0]->status;
115 $status .= ': '.$_[0]->statustext
116 if $_[0]->statustext;
120 #my $cust_bill_event = shift;
121 'Invoice #'. $_[0]->invnum.
123 time2str("%D", $_[0]->cust_bill_date).
126 \&FS::UI::Web::cust_fields,
133 my $part_bill_event = shift;
134 my $template = $part_bill_event->templatename;
135 $template .= '-' if $template;
136 [ "${p}view/cust_bill.cgi?$template", 'invnum'];
138 ( map { $link_cust } FS::UI::Web::cust_header() ),