1 <% include( 'elements/search.html',
3 'html_init' => $html_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(),
69 my $status_sub = sub {
70 my $cust_event = shift;
72 my $status = $cust_event->status;
73 $status .= ': '.$cust_event->statustext
74 if $cust_event->statustext;
76 my $part_event = $cust_event->part_event;
78 if ( $part_event->eventtable eq 'cust_bill' && $part_event->templatename ) {
79 my $alt_templatename = $part_event->templatename;
80 my $alt_link = "$alt_templatename-". $cust_event->tablenum;
82 my $conf = new FS::Conf;
83 my $cust_bill = $cust_event->cust_X;
86 ( <A HREF="${p}view/cust_bill.cgi?$alt_link">view</A>
87 | <A HREF="${p}view/cust_bill-pdf.cgi?$alt_link.pdf">view
89 | <A HREF="${p}misc/print-invoice.cgi?$alt_link">re-print</A>
92 if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) {
94 | <A HREF="${p}misc/email-invoice.cgi?$alt_link">re-email</A>
98 if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) {
100 | <A HREF="${p}misc/fax-invoice.cgi?$alt_link">re-fax</A>
111 my $trigger_sub = sub {
112 my $cust_event = shift;
113 my $eventtable = $cust_event->eventtable;
114 my $label = FS::part_event->eventtable_labels->{$eventtable};
115 #if ( $eventtable eq 'cust_pkg' || $eventtable eq 'cust_bill' ) {
116 "$label #". $cust_event->tablenum;
122 my $trigger_link = sub {
123 my $cust_event = shift;
124 my $eventtable = $cust_event->eventtable;
125 if ( $eventtable eq 'cust_pkg' ) {
126 my $custnum = $cust_event->cust_main_custnum;
127 [ "${p}view/cust_main.cgi?$custnum#cust_pkg", 'tablenum' ];
129 [ "${p}view/$eventtable.cgi?", 'tablenum' ];
136 my $curuser = $FS::CurrentUser::CurrentUser;
139 unless $curuser->access_right('Billing event reports')
140 or $curuser->access_right('View customer billing events')
141 && ( $cgi->param('custnum') =~ /^(\d+)$/
142 || $cgi->param('invnum') =~ /^(\d+)$/
143 || $cgi->param('pkgnum') =~ /^(\d+)$/
147 my $title = $cgi->param('failed')
148 ? 'Failed billing events'
153 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
154 push @search, "cust_main.agentnum = $1";
155 #my $agent = qsearchs('agent', { 'agentnum' => $1 } );
156 #die "unknown agentnum $1" unless $agent;
159 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
160 push @search, "cust_event._date >= $beginning",
161 "cust_event._date <= $ending";
163 if ( $cgi->param('failed') ) {
164 push @search, "statustext != ''",
165 "statustext IS NOT NULL",
166 "statustext != 'N/A'";
169 #if ( $cgi->param('part_event.payby') =~ /^(\w+)$/ ) {
170 # push @search, "part_event.payby = '$1'";
173 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
174 push @search, "cust_main.custnum = '$1'";
176 if ( $cgi->param('invnum') =~ /^(\d+)$/ ) {
177 push @search, "part_event.eventtable = 'cust_bill'",
180 if ( $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
181 push @search, "part_event.eventtable = 'cust_pkg'",
185 #here is the agent virtualization
186 push @search, $curuser->agentnums_sql( 'table' => 'cust_main' );
188 my $where = 'WHERE '. join(' AND ', @search );
191 JOIN part_event USING ( eventpart )
192 LEFT JOIN cust_bill ON ( eventtable = 'cust_bill' AND tablenum = invnum )
193 LEFT JOIN cust_pkg ON ( eventtable = 'cust_pkg' AND tablenum = pkgnum )
194 LEFT JOIN cust_main ON ( ( eventtable = 'cust_main' AND tablenum = cust_main.custnum )
195 OR ( eventtable = 'cust_bill' AND cust_bill.custnum = cust_main.custnum )
196 OR ( eventtable = 'cust_pkg' AND cust_pkg.custnum = cust_main.custnum )
199 #'LEFT JOIN cust_main USING ( custnum ) ';
202 'table' => 'cust_event',
203 'select' => join(', ',
206 #'cust_bill.custnum',
207 #'cust_bill._date AS cust_bill_date',
208 'cust_main.custnum AS cust_main_custnum',
209 FS::UI::Web::cust_sql_fields(),
212 'extra_sql' => "$where ORDER BY _date ASC",
213 'addl_from' => $join,
216 my $count_sql = "SELECT COUNT(*) FROM cust_event $join $where";
218 my $conf = new FS::Conf;
220 my $failed = $cgi->param('failed');
222 my $html_init = join("\n", map {
223 ( my $action = $_ ) =~ s/_$//;
224 include('/elements/progress-init.html',
226 [ 'action', 'beginning', 'ending', 'failed' ],
227 "../misc/${_}events.cgi",
228 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
231 qq!<FORM NAME="${_}form">!,
232 qq!<INPUT TYPE="hidden" NAME="action" VALUE="$_">!, #not used though
233 qq!<INPUT TYPE="hidden" NAME="beginning" VALUE="$beginning">!,
234 qq!<INPUT TYPE="hidden" NAME="ending" VALUE="$ending">!,
235 qq!<INPUT TYPE="hidden" NAME="failed" VALUE="$failed">!,
237 } qw( print_ email_ fax_ ) ).
239 '<SCRIPT TYPE="text/javascript">
241 function confirm_print_process() {
242 if ( ! confirm("Are you sure you want to reprint these invoices?") ) {
247 function confirm_email_process() {
248 if ( ! confirm("Are you sure you want to re-email these invoices?") ) {
253 function confirm_fax_process() {
254 if ( ! confirm("Are you sure you want to re-fax these invoices?") ) {
263 'Re-print these events' =>
264 "javascript:confirm_print_process()",
265 'Re-email these events' =>
266 "javascript:confirm_email_process()",
269 push @$menubar, 'Re-fax these events' =>
270 "javascript:confirm_fax_process()"
271 if $conf->exists('hylafax');
273 my $link_cust = sub {
274 my $cust_event = shift;
275 $cust_event->cust_main_custnum
276 ? [ "${p}view/cust_main.cgi?", 'cust_main_custnum' ]