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 my $show = $FS::CurrentUser::CurrentUser->default_customer_view =~ /^(jumbo|packages)$/
130 my $pkgnum = $cust_event->tablenum;
131 my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
132 [ "${p}view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#cust_pkg", 'tablenum' ];
134 [ "${p}view/$eventtable.cgi?", 'tablenum' ];
141 my $curuser = $FS::CurrentUser::CurrentUser;
144 unless $curuser->access_right('Billing event reports')
145 or $curuser->access_right('View customer billing events')
146 && ( $cgi->param('custnum') =~ /^(\d+)$/
147 || $cgi->param('invnum') =~ /^(\d+)$/
148 || $cgi->param('pkgnum') =~ /^(\d+)$/
152 my $title = $cgi->param('failed')
153 ? 'Failed billing events'
158 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
159 push @search, "cust_main.agentnum = $1";
160 #my $agent = qsearchs('agent', { 'agentnum' => $1 } );
161 #die "unknown agentnum $1" unless $agent;
164 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
165 push @search, "cust_event._date >= $beginning",
166 "cust_event._date <= $ending";
168 if ( $cgi->param('failed') ) {
169 push @search, "statustext != ''",
170 "statustext IS NOT NULL",
171 "statustext != 'N/A'";
174 #if ( $cgi->param('part_event.payby') =~ /^(\w+)$/ ) {
175 # push @search, "part_event.payby = '$1'";
178 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
179 push @search, "cust_main.custnum = '$1'";
181 if ( $cgi->param('invnum') =~ /^(\d+)$/ ) {
182 push @search, "part_event.eventtable = 'cust_bill'",
185 if ( $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
186 push @search, "part_event.eventtable = 'cust_pkg'",
190 #here is the agent virtualization
191 push @search, $curuser->agentnums_sql( 'table' => 'cust_main' );
193 my $where = 'WHERE '. join(' AND ', @search );
196 JOIN part_event USING ( eventpart )
197 LEFT JOIN cust_bill ON ( eventtable = 'cust_bill' AND tablenum = invnum )
198 LEFT JOIN cust_pkg ON ( eventtable = 'cust_pkg' AND tablenum = pkgnum )
199 LEFT JOIN cust_main ON ( ( eventtable = 'cust_main' AND tablenum = cust_main.custnum )
200 OR ( eventtable = 'cust_bill' AND cust_bill.custnum = cust_main.custnum )
201 OR ( eventtable = 'cust_pkg' AND cust_pkg.custnum = cust_main.custnum )
204 #'LEFT JOIN cust_main USING ( custnum ) ';
207 'table' => 'cust_event',
208 'select' => join(', ',
211 #'cust_bill.custnum',
212 #'cust_bill._date AS cust_bill_date',
213 'cust_main.custnum AS cust_main_custnum',
214 FS::UI::Web::cust_sql_fields(),
217 'extra_sql' => "$where ORDER BY _date ASC",
218 'addl_from' => $join,
221 my $count_sql = "SELECT COUNT(*) FROM cust_event $join $where";
223 my $conf = new FS::Conf;
225 my $failed = $cgi->param('failed');
227 my $html_init = join("\n", map {
228 ( my $action = $_ ) =~ s/_$//;
229 include('/elements/progress-init.html',
231 [ 'action', 'beginning', 'ending', 'failed' ],
232 "../misc/${_}events.cgi",
233 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
236 qq!<FORM NAME="${_}form">!,
237 qq!<INPUT TYPE="hidden" NAME="action" VALUE="$_">!, #not used though
238 qq!<INPUT TYPE="hidden" NAME="beginning" VALUE="$beginning">!,
239 qq!<INPUT TYPE="hidden" NAME="ending" VALUE="$ending">!,
240 qq!<INPUT TYPE="hidden" NAME="failed" VALUE="$failed">!,
242 } qw( print_ email_ fax_ ) ).
244 '<SCRIPT TYPE="text/javascript">
246 function confirm_print_process() {
247 if ( ! confirm("Are you sure you want to reprint these invoices?") ) {
252 function confirm_email_process() {
253 if ( ! confirm("Are you sure you want to re-email these invoices?") ) {
258 function confirm_fax_process() {
259 if ( ! confirm("Are you sure you want to re-fax these invoices?") ) {
269 if ( $curuser->access_right('Resend invoices') ) {
271 push @$menubar, 'Re-print these events' =>
272 "javascript:confirm_print_process()",
273 'Re-email these events' =>
274 "javascript:confirm_email_process()",
277 push @$menubar, 'Re-fax these events' =>
278 "javascript:confirm_fax_process()"
279 if $conf->exists('hylafax');
283 my $link_cust = sub {
284 my $cust_event = shift;
285 $cust_event->cust_main_custnum
286 ? [ "${p}view/cust_main.cgi?", 'cust_main_custnum' ]