/**
* Generates and saves the invoice to the uploads folder.
* @param $dest
* @return string
*/
public function save($dest)
{
if ($this->exists()) {
die('Invoice already exists. First delete invoice.');
}
// If the invoice is manually deleted from dir, delete data from database.
$this->delete();
if ($this->template_options['bewpi_invoice_number_type'] === "sequential_number") {
if (!$this->reset_counter() && !$this->new_year_reset()) {
$this->number = $this->template_options['bewpi_last_invoice_number'] + 1;
}
} else {
$this->number = $this->order->get_order_number();
}
$this->number_of_columns = $this->get_number_of_columns();
$this->colspan = $this->get_colspan();
$this->formatted_number = $this->get_formatted_number(true);
$this->year = date('Y');
$this->filename = BEWPI_INVOICES_DIR . (string) $this->year . '/' . $this->formatted_number . '.pdf';
// Template
$this->css = $this->get_css();
$this->header = $this->get_header_html();
$this->body = $this->get_body_html();
$this->footer = $this->get_footer_html();
add_post_meta($this->order->id, '_bewpi_invoice_number', $this->number);
add_post_meta($this->order->id, '_bewpi_invoice_year', $this->year);
$this->template_options['bewpi_last_invoice_number'] = $this->number;
$this->template_options['bewpi_last_invoiced_year'] = $this->year;
delete_option('bewpi_template_settings');
add_option('bewpi_template_settings', $this->template_options);
parent::generate($dest, $this);
return $this->filename;
}