Small refactoring of pdf invoice

This commit is contained in:
FrancescoUK
2016-10-01 14:25:21 +01:00
parent 974744858f
commit a9963dcfd0
2 changed files with 14 additions and 10 deletions

View File

@@ -423,11 +423,11 @@ class Sales extends Secure_Controller
$html = $this->load->view('sales/invoice_email', $sale_data, TRUE);
// load pdf helper
$this->load->helper(array('dompdf', 'file'));
$file_content = pdf_create($html, '', FALSE);
$filename = sys_get_temp_dir() . '/' . $this->lang->line('sales_invoice') . '-' . str_replace('/', '-' , $sale_data['invoice_number']) . '.pdf';
write_file($filename, $file_content);
$result = $this->email_lib->sendEmail($to, $subject, $text, $filename);
if(file_put_contents($filename, pdf_create($html)) !== FALSE)
{
$result = $this->email_lib->sendEmail($to, $subject, $text, $filename);
}
$message = $this->lang->line($result ? 'sales_invoice_sent' : 'sales_invoice_unsent') . ' ' . $to;
}

View File

@@ -1,23 +1,27 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename = '', $stream = TRUE)
function pdf_create($html, $filename = '')
{
// need to enable magic quotes for the
$magic_quotes_enabled = get_magic_quotes_runtime();
if(!$magic_quotes_enabled)
{
ini_set("magic_quotes_runtime", true);
ini_set('magic_quotes_runtime', TRUE);
}
$dompdf = new Dompdf\Dompdf();
$dompdf->loadHtml($html);
$dompdf->render();
ini_set("magic_quotes_runtime", $magic_quotes_enabled);
if ($stream)
if(!$magic_quotes_enabled)
{
$dompdf->stream($filename.".pdf");
ini_set('magic_quotes_runtime', $magic_quotes_enabled);
}
if($filename != '')
{
$dompdf->stream($filename . '.pdf');
}
else
{