summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorivan <ivan>2011-08-15 20:59:06 +0000
committerivan <ivan>2011-08-15 20:59:06 +0000
commit6011535409e784cde658c0042b2f665c83975a91 (patch)
treef91d43becb3391dfc7181cf9681a42f41162f3fc /httemplate
parentfee2489219be414439be6cffac38b834005a41e6 (diff)
consolate cust_bill-(ps|pdf).cgi into elements/cust_bill-typeset
Diffstat (limited to 'httemplate')
-rwxr-xr-xhttemplate/view/cust_bill-pdf.cgi45
-rwxr-xr-xhttemplate/view/cust_bill-ps.cgi44
-rw-r--r--httemplate/view/elements/cust_bill-typeset52
3 files changed, 54 insertions, 87 deletions
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' );
-
-</%init>
+<& 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' );
-
-</%init>
+<& 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' );
+
+</%init>