fix quotations, RT#21103
authorIvan Kohler <ivan@freeside.biz>
Mon, 11 Mar 2013 09:17:13 +0000 (02:17 -0700)
committerIvan Kohler <ivan@freeside.biz>
Mon, 11 Mar 2013 09:17:13 +0000 (02:17 -0700)
FS/FS/Template_Mixin.pm
httemplate/view/quotation-pdf.cgi [new file with mode: 0755]

index 2a32534..7d8135d 100644 (file)
@@ -122,7 +122,9 @@ sub print_latex {
     UNLINK   => 0,
   ) or die "can't open temp file: $!\n";
 
-  my $agentnum = $self->cust_main->agentnum;
+  my $cust_main = $self->cust_main;
+  my $prospect_main = $self->prospect_main;
+  my $agentnum = $cust_main ? $cust_main->agentnum : $prospect_main->agentnum;
 
   if ( $template && $conf->exists("logo_${template}.eps", $agentnum) ) {
     print $lh $conf->config_binary("logo_${template}.eps", $agentnum)
diff --git a/httemplate/view/quotation-pdf.cgi b/httemplate/view/quotation-pdf.cgi
new file mode 100755 (executable)
index 0000000..7f62ce1
--- /dev/null
@@ -0,0 +1,29 @@
+<% $content %>\
+<%init>
+
+#false laziness w/elements/cust_bill-typeset
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Generate quotation'); #View quotations ?
+
+my $quotationnum = $cgi->param('quotationnum');
+
+my $conf = new FS::Conf;
+
+my $quotation = qsearchs({
+  'select'    => 'quotation.*',
+  'table'     => 'quotation',
+  #'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
+  'hashref'   => { 'quotationnum' => $quotationnum },
+  #'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+});
+die "Quotation #$quotationnum not found!" unless $quotation;
+
+my $content = $quotation->print_pdf(); #\%opt);
+
+http_header('Content-Type' => 'application/pdf');
+http_header('Content-Disposition' => "filename=$quotationnum.pdf" );
+http_header('Content-Length' => length($content) );
+http_header('Cache-control' => 'max-age=60' );
+
+</%init>