better error page when re-emailing bad addresses or other SMTP errorsm, RT#25834
[freeside.git] / httemplate / misc / send-invoice.cgi
1 % if ( $error ) {
2 %   errorpage($error);
3 % } else {
4 <% $cgi->redirect("${p}view/cust_main.cgi?$custnum") %>
5 % }
6 <%once>
7
8 my %method = ( map { $_=>1 } qw( email print fax_invoice ) );
9
10 </%once>
11 <%init>
12
13 die "access denied"
14   unless $FS::CurrentUser::CurrentUser->access_right('Resend invoices');
15
16 my $invnum      = $cgi->param('invnum');
17 my $template    = $cgi->param('template');
18 my $notice_name = $cgi->param('notice_name') if $cgi->param('notice_name');
19 my $method      = $cgi->param('method');
20 my $mode;
21 if ( $cgi->param('mode') =~ /^(\d+)$/ ) {
22   $mode = $1;
23 }
24
25 $method .= '_invoice' if $method eq 'fax'; #!
26
27 die "unknown method $method" unless $method{$method};
28
29 my $cust_bill = qsearchs('cust_bill',{'invnum'=>$invnum});
30 die "Can't find invoice!\n" unless $cust_bill;
31
32 $cust_bill->set('mode' => $mode) if $mode;
33
34 #these methods die instead of return errors, so, handle that without a backtrace
35 eval { $cust_bill->$method({ 'template'    => $template,
36                              'notice_name' => $notice_name,
37                           }); 
38      };
39 my $error = $@;
40
41 my $custnum = $cust_bill->getfield('custnum');
42
43 </%init>