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'
79 && ( $part_event->templatename || $part_event->option('notice_name') )
82 my $link = 'invnum='. $cust_event->tablenum;
83 $link .= ';template='. uri_escape($part_event->templatename)
84 if $part_event->templatename;
85 $link .= ';notice_name='. uri_escape($part_event->option('notice_name'))
86 if $part_event->option('notice_name');
88 my $conf = new FS::Conf;
89 my $cust_bill = $cust_event->cust_X;
92 ( <A HREF="${p}view/cust_bill.cgi?$link">view</A>
93 | <A HREF="${p}view/cust_bill-pdf.cgi?$link">view typeset</A>
94 | <A HREF="${p}misc/send-invoice.cgi?method=print;$link">re-print</A>
97 if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) {
99 | <A HREF="${p}misc/send-invoice.cgi?method=email;$link">re-email</A>
103 if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) {
105 | <A HREF="${p}misc/send-invoice.cgi?method=fax;$link">re-fax</A>
116 my $trigger_sub = sub {
117 my $cust_event = shift;
118 my $eventtable = $cust_event->eventtable;
119 my $label = FS::part_event->eventtable_labels->{$eventtable};
120 #if ( $eventtable eq 'cust_pkg' || $eventtable eq 'cust_bill' ) {
121 "$label #". $cust_event->tablenum;
127 my $trigger_link = sub {
128 my $cust_event = shift;
129 my $eventtable = $cust_event->eventtable;
130 if ( $eventtable eq 'cust_pkg' ) {
131 my $custnum = $cust_event->cust_main_custnum;
132 my $show = $FS::CurrentUser::CurrentUser->default_customer_view =~ /^(jumbo|packages)$/
135 my $pkgnum = $cust_event->tablenum;
136 my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
137 [ "${p}view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#cust_pkg", 'tablenum' ];
139 [ "${p}view/$eventtable.cgi?", 'tablenum' ];
146 my $curuser = $FS::CurrentUser::CurrentUser;
149 unless $curuser->access_right('Billing event reports')
150 or $curuser->access_right('View customer billing events')
151 && ( $cgi->param('custnum') =~ /^(\d+)$/
152 || $cgi->param('invnum') =~ /^(\d+)$/
153 || $cgi->param('pkgnum') =~ /^(\d+)$/
156 my $title = $cgi->param('failed') ? 'Failed billing events' : 'Billing events';
160 my @scalars = qw( agentnum status custnum invnum pkgnum failed );
161 for my $param (@scalars) {
162 $search{$param} = scalar( $cgi->param($param) )
163 if $cgi->param($param);
167 my @lists = qw( payby eventpart );
168 foreach my $param (@lists) {
169 $search{$param} = [ $cgi->param($param) ];
172 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
173 $search{'beginning'} = $beginning;
174 $search{'ending'} = $ending;
176 my $where = ' WHERE '. FS::cust_event->search_sql_where( \%search );
178 my $join = FS::cust_event->join_sql();
181 'table' => 'cust_event',
182 'select' => join(', ',
185 #'cust_bill.custnum',
186 #'cust_bill._date AS cust_bill_date',
187 'cust_main.custnum AS cust_main_custnum',
188 FS::UI::Web::cust_sql_fields(),
191 'extra_sql' => $where,
192 'order_by' => 'ORDER BY _date ASC',
193 'addl_from' => $join,
197 my $count_sql = "SELECT COUNT(*) FROM cust_event $join $where";
199 my $conf = new FS::Conf;
201 my @params = ( @scalars, qw( beginning ending ) );
203 my $html_init = join("\n", map {
204 ( my $action = $_ ) =~ s/_$//;
205 include('/elements/progress-init.html',
207 [ 'action', @params ],
208 "../misc/${_}events.cgi",
209 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
212 qq!<FORM NAME="${_}form">!,
213 qq!<INPUT TYPE="hidden" NAME="action" VALUE="$_">!, #not used though
214 ( map { my $value = encode_entities( $search{$_} );
215 qq(<INPUT TYPE="hidden" NAME="$_" VALUE="$value">);
217 @params #keys %search
219 ( map { my $value = encode_entities( join(',', @{ $search{$_} } ) );
220 qq(<INPUT TYPE="hidden" NAME="$_" VALUE="$value">);
225 } qw( print_ email_ fax_ ) ).
227 '<SCRIPT TYPE="text/javascript">
229 function confirm_print_process() {
230 if ( ! confirm("Are you sure you want to reprint these invoices?") ) {
235 function confirm_email_process() {
236 if ( ! confirm("Are you sure you want to re-email these invoices?") ) {
241 function confirm_fax_process() {
242 if ( ! confirm("Are you sure you want to re-fax these invoices?") ) {
252 if ( $curuser->access_right('Resend invoices') ) {
254 push @$menubar, 'Re-print these events' =>
255 "javascript:confirm_print_process()",
256 'Re-email these events' =>
257 "javascript:confirm_email_process()",
260 push @$menubar, 'Re-fax these events' =>
261 "javascript:confirm_fax_process()"
262 if $conf->exists('hylafax');
266 my $link_cust = sub {
267 my $cust_event = shift;
268 $cust_event->cust_main_custnum
269 ? [ "${p}view/cust_main.cgi?", 'cust_main_custnum' ]