/**
  * Generates and saves the invoice to the uploads folder.
  * @param $dest
  * @return string
  */
 protected function save($dest, $html_templates)
 {
     $this->number = $this->get_next_invoice_number();
     $this->formatted_number = $this->get_formatted_number();
     $this->filename = $this->formatted_number . '.pdf';
     $this->year = date_i18n('Y', current_time('timestamp'));
     $this->full_path = BEWPI_INVOICES_DIR . (string) $this->year . '/' . $this->filename;
     // check if invoice doesn't already exists in invoice dir
     if ($this->exists()) {
         if ($this->counter_reset) {
             // user used invoice number reset, but invoice already exists with this invoice number
             wp_die(sprintf(__('Could not create invoice. In order to reset invoice number with %d, delete all invoices with invoice number %s and greater.', 'woocommerce-pdf-invoices'), (int) $this->template_options['bewpi_next_invoice_number'], $this->formatted_number), '', array('response' => 200, 'back_link' => true));
         } else {
             wp_die(sprintf(__('Could not create invoice. Invoice with invoice number %s already exists. First delete invoice and try again.', 'woocommerce-pdf-invoices'), $this->formatted_number), '', array('response' => 200, 'back_link' => true));
         }
     }
     // update invoice data in db
     update_post_meta($this->order->id, '_bewpi_formatted_invoice_number', $this->formatted_number);
     update_post_meta($this->order->id, '_bewpi_invoice_number', $this->number);
     update_post_meta($this->order->id, '_bewpi_invoice_year', $this->year);
     $this->date = $this->get_formatted_invoice_date();
     update_post_meta($this->order->id, '_bewpi_invoice_date', $this->date);
     $this->colspan = $this->get_colspan();
     $html_sections = $this->output_template_files_to_buffer($html_templates);
     $paid = $this->is_paid();
     do_action('bewpi_before_document_generation', array('type' => $this->type, 'order_id' => $this->order->id));
     parent::generate($html_sections, $dest, $paid);
     return $this->full_path;
 }
Ejemplo n.º 2
0
 /**
  * Generates and saves the invoice to the uploads folder.
  * @param $dest
  * @return string
  */
 protected function save($dest, $html_templates)
 {
     $this->general_options = get_option('bewpi_general_settings');
     $this->template_options = get_option('bewpi_template_settings');
     do_action("bewpi_before_invoice_content", $this->order->id);
     if ($this->exists()) {
         // delete postmeta and PDF
         $this->delete();
     }
     $this->number = $this->get_next_invoice_number();
     $this->formatted_number = $this->get_formatted_number();
     $this->filename = $this->formatted_number . '.pdf';
     $this->year = date_i18n('Y', current_time('timestamp'));
     $this->full_path = BEWPI_INVOICES_DIR . (string) $this->year . '/' . $this->filename;
     // update invoice data in db
     update_post_meta($this->order->id, '_bewpi_formatted_invoice_number', $this->formatted_number);
     update_post_meta($this->order->id, '_bewpi_invoice_number', $this->number);
     update_post_meta($this->order->id, '_bewpi_invoice_year', $this->year);
     $this->date = $this->get_formatted_invoice_date();
     update_post_meta($this->order->id, '_bewpi_invoice_date', $this->date);
     $this->colspan = $this->get_colspan();
     $html_sections = $this->output_template_files_to_buffer($html_templates);
     $paid = $this->is_paid();
     do_action('bewpi_before_document_generation', array('type' => $this->type, 'order_id' => $this->order->id));
     parent::generate($html_sections, $dest, $paid);
     do_action("bewpi_after_invoice_content", $this->order->id);
     return $this->full_path;
 }