consolate cust_bill-(ps|pdf).cgi into elements/cust_bill-typeset
authorivan <ivan>
Mon, 15 Aug 2011 20:59:06 +0000 (20:59 +0000)
committerivan <ivan>
Mon, 15 Aug 2011 20:59:06 +0000 (20:59 +0000)
httemplate/view/cust_bill-pdf.cgi
httemplate/view/cust_bill-ps.cgi
httemplate/view/elements/cust_bill-typeset [new file with mode: 0644]

index 2ac0d0a..23d059d 100755 (executable)
@@ -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' &>\
index cc8020a..093bfd6 100755 (executable)
@@ -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 (file)
index 0000000..00f503f
--- /dev/null
@@ -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>