[eluser]KaBaDaBrA[/eluser]
Hi there,
I've been using domPDF with the Code Igniter plugin provided by Derek Allard...really works great! What I have done is created a model that has the plugin and pdf creation.
The application that I am developing sends mutiple invoices with one click. When it loops through the clients it sends an invoiceID to the model and creates the necessary PDF documents. After the creation of the PDF documents it sends all the emails with the associated PDF attached. The emailing part works great!
The problem is that the header image only displays on the first invoice selected and the rest of the invoices header images are blank?! Is there any way to unset a variable or clear memory or something when a PDF document is created that will perhaps solve this problem?
Here's my code...
MODEL:
Code:
class Invoices_model extends Model {
function Invoices_model()
{
// Call the Model constructor
parent::Model();
$this->load->plugin('to_pdf');
}
function create_invoice($invoiceID, $invoiceQuery, $file_name)
{
//GET INVOICE SETTINGS AND LAYOUT
$sql = $this->db->query("SELECT * FROM settings");
foreach($sql->result() as $row):
$data['invoice_header'] = $row->invoice_header;
$data['invoice_terms'] = $row->invoice_terms;
$data['invoice_picture'] = $row->invoice_picture;
endforeach;
$sql->free_result();
//GET QUERY
$data['query'] = $invoiceQuery;
//DO PDF CREATION
$html = $this->load->view('invoices/generate_pdf', $data, true);
pdf_create($html, $file_name, false);
}
}
INVOICE LOOPING
Code:
//EMAIL MULTIPLE INVOICES WITH PDF ATTACHED
if($handler_options == '4') {
$file_name = "";
$emailTo = "";
$emailAddress = "";
$invoiceData = "";
$checkPayment = "";
//LOAD EMAIL LIBRARY
$this->load->library('email');
//LOAD INVOICES MODEL
$this->load->model('Invoices_model');
//LOOP THROUGH EACH PASSED CHECKBOX VALUE AND CREATE THE PDF
foreach($list as $invoiceID) :
$startDate = $this->uri->segment(4);
$endDate = $this->uri->segment(5);
$section = $this->uri->segment(6);
$this->email->clear(TRUE);
$query = $this->db->query('SELECT * FROM invoices, clients WHERE clients.id = invoices.clientID AND invoices.id = '.$invoiceID);
//GET CLIENT INFORMATION
foreach($query->result() as $row):
$showPersonal = "";
if($row->company == "") {
$showPersonal = $row->firstname.' '.$row->lastname;
} else {
$showPersonal = $row->company;
}
$file_name = 'Invoice '.$this->session->userdata('logged_invoice_prefix').$row->invoiceID.' - '.$showPersonal;
$emailAddress = $row->email;
$emailTo = $row->firstname.' '.$row->lastname;
$invoiceData = $this->session->userdata('logged_invoice_prefix').$row->invoiceID;
$checkPayment = $row->payment_option;
endforeach;
//USE INVOICES MODEL AND CREATE INVOICE
$this->Invoices_model->create_invoice($invoiceID, $query, $file_name);
$query->free_result();
$config['protocol'] = 'mail';
$config['charset'] = 'iso-8859-1';
$config['mailtype'] = 'html';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from($this->session->userdata('logged_invoice_email'), $this->session->userdata('logged_businessname').' - Accounts Department');
$this->email->to($emailAddress);
$this->email->subject($file_name);
$style = "<style>";
$style .= "body {";
$style .= "font-family: Calibri, Arial";
$style .= "}";
$style .= "</style>";
if ($checkPayment == "debit") {
$this->email->message("test debit");
} else {
$this->email->message("test cash / eft");
}
$this->email->attach('./tmp/'.$file_name.'.pdf');
if ($this->email->send())
{
unlink("./tmp/".$file_name.".pdf");
$sql = array('emailed' => '1');
$this->db->where('id', $invoiceID);
$this->db->update('invoices', $sql);
$this->session->set_flashdata('success','<p align="center" class="error"><strong>Multiple invoices have been <span class="red_header">successfully</span> emailed! Memory Used: '.$this->benchmark->memory_usage().'</strong></p><p> </p>');
} else {
unlink("./tmp/".$file_name.".pdf");
$sql = array('emailed' => '2');
$this->db->where('id', $invoiceID);
$this->db->update('invoices', $sql);
$this->session->set_flashdata('success','<p align="center" class="error"><strong>Multiple invoices have <span class="red_header">failed</span> to send!</strong></p><p> </p>');
}
$query->free_result();
endforeach;
redirect('invoices/index/'.$startDate.'/'.$endDate.'/payInvoiceMethod/'.$section);
}