From 6011535409e784cde658c0042b2f665c83975a91 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 15 Aug 2011 20:59:06 +0000 Subject: [PATCH] consolate cust_bill-(ps|pdf).cgi into elements/cust_bill-typeset --- httemplate/view/cust_bill-pdf.cgi | 45 +------------------------- httemplate/view/cust_bill-ps.cgi | 44 +------------------------ httemplate/view/elements/cust_bill-typeset | 52 ++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 87 deletions(-) create mode 100644 httemplate/view/elements/cust_bill-typeset diff --git a/httemplate/view/cust_bill-pdf.cgi b/httemplate/view/cust_bill-pdf.cgi index 2ac0d0a3a..23d059dad 100755 --- a/httemplate/view/cust_bill-pdf.cgi +++ b/httemplate/view/cust_bill-pdf.cgi @@ -1,44 +1 @@ -<% $pdf %> -<%init> - -die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('View invoices'); - -my( $invnum, $template, $notice_name ); -my($query) = $cgi->keywords; -if ( $query =~ /^((.+)-)?(\d+)(.pdf)?$/ ) { #probably not necessary anymore? - $template = $2; - $invnum = $3; - $notice_name = 'Invoice'; -} else { - $invnum = $cgi->param('invnum'); - $invnum =~ s/\.pdf//i; #probably not necessary anymore - $template = $cgi->param('template'); - $notice_name = ( $cgi->param('notice_name') || 'Invoice' ); -} - -my $conf = new FS::Conf; - -my %opt = ( - 'unsquelch_cdr' => $conf->exists('voip-cdr_email'), - 'template' => $template, - 'notice_name' => $notice_name, -); - -my $cust_bill = qsearchs({ - 'select' => 'cust_bill.*', - 'table' => 'cust_bill', - 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )', - 'hashref' => { 'invnum' => $invnum }, - 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, -}); -die "Invoice #$invnum not found!" unless $cust_bill; - -my $pdf = $cust_bill->print_pdf(\%opt); - -http_header('Content-Type' => 'application/pdf' ); -http_header('Content-Disposition' => "filename=$invnum.pdf" ); -http_header('Content-Length' => length($pdf) ); -http_header('Cache-control' => 'max-age=60' ); - - +<& elements/cust_bill-typeset, 'pdf' &>\ diff --git a/httemplate/view/cust_bill-ps.cgi b/httemplate/view/cust_bill-ps.cgi index cc8020a3e..093bfd62a 100755 --- a/httemplate/view/cust_bill-ps.cgi +++ b/httemplate/view/cust_bill-ps.cgi @@ -1,43 +1 @@ -<% $ps %> -<%init> - -die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('View invoices'); - -my( $invnum, $template, $notice_name ); -my($query) = $cgi->keywords; -if ( $query =~ /^((.+)-)?(\d+)(.pdf)?$/ ) { #probably not necessary anymore? - $template = $2; - $invnum = $3; - $notice_name = 'Invoice'; -} else { - $invnum = $cgi->param('invnum'); - $template = $cgi->param('template'); - $notice_name = ( $cgi->param('notice_name') || 'Invoice' ); -} - -my $conf = new FS::Conf; - -my %opt = ( - 'unsquelch_cdr' => $conf->exists('voip-cdr_email'), - 'template' => $template, - 'notice_name' => $notice_name, -); - -my $cust_bill = qsearchs({ - 'select' => 'cust_bill.*', - 'table' => 'cust_bill', - 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )', - 'hashref' => { 'invnum' => $invnum }, - 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, -}); -die "Invoice #$invnum not found!" unless $cust_bill; - -my $ps = $cust_bill->print_ps(\%opt); - -http_header('Content-Type' => 'application/postscript' ); -http_header('Content-Disposition' => "filename=$invnum.ps" ); -http_header('Content-Length' => length($ps) ); -http_header('Cache-control' => 'max-age=60' ); - - +<& elements/cust_bill-typeset 'ps' &>\ diff --git a/httemplate/view/elements/cust_bill-typeset b/httemplate/view/elements/cust_bill-typeset new file mode 100644 index 000000000..00f503fbb --- /dev/null +++ b/httemplate/view/elements/cust_bill-typeset @@ -0,0 +1,52 @@ +<% $content %>\ +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('View invoices'); + +my $type = shift; + +my( $invnum, $template, $notice_name ); +my($query) = $cgi->keywords; +if ( $query =~ /^((.+)-)?(\d+)(.pdf)?$/ ) { #probably not necessary anymore? + $template = $2; + $invnum = $3; + $notice_name = 'Invoice'; +} else { + $invnum = $cgi->param('invnum'); + $invnum =~ s/\.pdf//i; #probably not necessary anymore + $template = $cgi->param('template'); + $notice_name = ( $cgi->param('notice_name') || 'Invoice' ); +} + +my $conf = new FS::Conf; + +my %opt = ( + 'unsquelch_cdr' => $conf->exists('voip-cdr_email'), + 'template' => $template, + 'notice_name' => $notice_name, +); + +my $cust_bill = qsearchs({ + 'select' => 'cust_bill.*', + 'table' => 'cust_bill', + 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )', + 'hashref' => { 'invnum' => $invnum }, + 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, +}); +die "Invoice #$invnum not found!" unless $cust_bill; + +my $method = "print_$type"; + +my $content = $cust_bill->$method(\%opt); + +my %mime = ( 'pdf' => 'application/pdf', + 'ps' => 'application/postscript', + ); + +http_header('Content-Type' => $mime{$type} ); +http_header('Content-Disposition' => "filename=$invnum.$type" ); +http_header('Content-Length' => length($content) ); +http_header('Cache-control' => 'max-age=60' ); + + -- 2.11.0