diff --git a/lib/midcom/admin/folder/locale/default.de.txt b/lib/midcom/admin/folder/locale/default.de.txt index 31748dab57..f2897b039f 100644 --- a/lib/midcom/admin/folder/locale/default.de.txt +++ b/lib/midcom/admin/folder/locale/default.de.txt @@ -220,4 +220,4 @@ Stilvorlage ---STRING objects with no navigation entry are still accessible on-site if the url is known Objekte ohne Navigationseintrag sind weiterhin verfügbar, insofern die URL bekannt ist ----STRINGEND +---STRINGEND \ No newline at end of file diff --git a/lib/midcom/admin/folder/locale/default.en.txt b/lib/midcom/admin/folder/locale/default.en.txt index f5407f7dc2..b332e8fe2b 100644 --- a/lib/midcom/admin/folder/locale/default.en.txt +++ b/lib/midcom/admin/folder/locale/default.en.txt @@ -220,4 +220,4 @@ Style template ---STRING objects with no navigation entry are still accessible on-site if the url is known Objects that are hidden from navigation are still accessible on-site if the URL is known ----STRINGEND +---STRINGEND \ No newline at end of file diff --git a/lib/org/openpsa/invoices/config/config.inc b/lib/org/openpsa/invoices/config/config.inc index ed5286f806..89280cd79d 100644 --- a/lib/org/openpsa/invoices/config/config.inc +++ b/lib/org/openpsa/invoices/config/config.inc @@ -7,6 +7,7 @@ 'invoice_number_format' => '#%06d', //contains the class file to create the pdf for the invoice, if set to false pdf-creation is disabled 'invoice_pdfbuilder_class' => false, //implements org_openpsa_invoices_interfaces_pdfbuilder +'invoice_pdfbuilder_reminder_class' => false, 'invoice_mail_bcc' => false, 'invoice_mail_from_address' => 'foo@example.org', diff --git a/lib/org/openpsa/invoices/config/routes.yml b/lib/org/openpsa/invoices/config/routes.yml index 06ca04e720..19874075a1 100644 --- a/lib/org/openpsa/invoices/config/routes.yml +++ b/lib/org/openpsa/invoices/config/routes.yml @@ -58,6 +58,10 @@ create_pdf: path: /invoice/action/create_pdf/ defaults: { _controller: 'org_openpsa_invoices_handler_invoice_action::create_pdf' } +create_reminder: + path: /invoice/action/create_reminder/ + defaults: { _controller: 'org_openpsa_invoices_handler_invoice_action::create_pdf_reminder' } + recalc_invoice: path: /invoice/recalculation/{guid}/ defaults: { _controller: 'org_openpsa_invoices_handler_invoice_items::recalculation' } diff --git a/lib/org/openpsa/invoices/config/schemadb_default.inc b/lib/org/openpsa/invoices/config/schemadb_default.inc index 8f62760a4b..6b24a39f95 100644 --- a/lib/org/openpsa/invoices/config/schemadb_default.inc +++ b/lib/org/openpsa/invoices/config/schemadb_default.inc @@ -163,6 +163,17 @@ 'index_method' => 'attachment', 'hidden' => true, ], + 'pdf_file_reminder' => [ + 'title' => 'reminder', + 'type' => 'blobs', + 'widget' => 'downloads', + 'type_config' => [ + 'sortable' => false, + 'max_count' => 1, + ], + 'index_method' => 'attachment', + 'hidden' => true, + ], 'files' => [ 'title' => 'Files', 'type' => 'blobs', diff --git a/lib/org/openpsa/invoices/handler/invoice/action.php b/lib/org/openpsa/invoices/handler/invoice/action.php index 3de3382a88..c7c975ae4f 100644 --- a/lib/org/openpsa/invoices/handler/invoice/action.php +++ b/lib/org/openpsa/invoices/handler/invoice/action.php @@ -130,6 +130,17 @@ public function _handler_create_pdf() } } + public function _handler_create_pdf_reminder() + { + $pdf_helper = new org_openpsa_invoices_invoice_pdf($this->invoice); + try { + $pdf_helper->render_and_attach('reminder'); + return $this->reply(true, $this->_l10n->get('reminder pdf created')); + } catch (midcom_error $e) { + return $this->reply(false, $this->_l10n->get('reminder pdf creation failed') . ': ' . $e->getMessage()); + } + } + public function _handler_send_by_mail() { $customerCard = org_openpsa_widgets_contact::get($this->invoice->customerContact); diff --git a/lib/org/openpsa/invoices/handler/invoice/view.php b/lib/org/openpsa/invoices/handler/invoice/view.php index 7ad34e7b8c..226caa8d40 100644 --- a/lib/org/openpsa/invoices/handler/invoice/view.php +++ b/lib/org/openpsa/invoices/handler/invoice/view.php @@ -98,6 +98,13 @@ private function populate_toolbar() } } + if ($this->_config->get('invoice_pdfbuilder_reminder_class') && $this->invoice->get_status() == 'overdue') { + $button = $this->build_button('create_reminder', 'file-pdf-o'); + $pdf_helper = new org_openpsa_invoices_invoice_pdf($this->invoice); + $button[MIDCOM_TOOLBAR_OPTIONS] = $pdf_helper->get_button_options('reminder'); + $buttons[] = $button; + } + if ($this->invoice->is_cancelable()) { $buttons[] = $this->build_button('create_cancelation', 'ban'); } diff --git a/lib/org/openpsa/invoices/invoice/pdf.php b/lib/org/openpsa/invoices/invoice/pdf.php index 8b0d9309a5..9e7923e7e3 100644 --- a/lib/org/openpsa/invoices/invoice/pdf.php +++ b/lib/org/openpsa/invoices/invoice/pdf.php @@ -21,9 +21,13 @@ public function __construct(org_openpsa_invoices_invoice_dba $invoice) $this->invoice = $invoice; } - public function get_attachment(bool $autocreate = false) : ?midcom_db_attachment + public function get_attachment(bool $autocreate = false, string $kind = null) : ?midcom_db_attachment { - $pdf_files = blobs::get_attachments($this->invoice, "pdf_file"); + if ($kind == 'reminder') { + $pdf_files = blobs::get_attachments($this->invoice, "pdf_file_reminder"); + } else { + $pdf_files = blobs::get_attachments($this->invoice, "pdf_file"); + } if (!empty($pdf_files)) { return reset($pdf_files); } @@ -33,10 +37,10 @@ public function get_attachment(bool $autocreate = false) : ?midcom_db_attachment return $this->render_and_attach(); } - public function get_button_options() : array + public function get_button_options(string $kind = 'invoice') : array { if ($attachment = $this->get_attachment()) { - if ($this->invoice->sent) { + if ($this->invoice->sent && $kind != 'reminder') { $message = 'invoice has already been sent. should it be replaced?'; } // check if auto generated parameter is same as md5 in current-file @@ -63,9 +67,14 @@ public function get_button_options() : array ]; } - public function render_and_attach() : midcom_db_attachment + public function render_and_attach(string $kind = null) : midcom_db_attachment { - $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class'); + if ($kind == null) { + $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class'); + } else { + $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_' . $kind . '_class'); + } + if (!class_exists($client_class)) { throw new midcom_error('Could not find PDF renderer ' . $client_class); } @@ -78,15 +87,21 @@ public function render_and_attach() : midcom_db_attachment } // renders the pdf and attaches it to the invoice $pdf_builder = new $client_class($this->invoice); - $filename = midcom_helper_misc::urlize($this->invoice->get_label()) . '.pdf'; + $l10n = midcom::get()->i18n->get_l10n('org.openpsa.invoices'); + if ($kind == 'reminder') { + $name = "guids_pdf_file_reminder"; + $filename = midcom_helper_misc::urlize($this->invoice->get_label()) . '_' . lcfirst($l10n->get('reminder')) . '.pdf'; + } else { + $name = "guids_pdf_file"; + $filename = midcom_helper_misc::urlize($this->invoice->get_label()) . '.pdf'; + } // tmp filename $tmp_file = midcom::get()->config->get('midcom_tempdir') . "/" . $filename; // render pdf to tmp filename $pdf_builder->render($tmp_file); - - $attachment = $this->get_attachment(); + $attachment = $this->get_attachment(false, $kind); if ($attachment) { $attachment->name = $filename; $attachment->title = $this->invoice->get_label(); @@ -95,7 +110,7 @@ public function render_and_attach() : midcom_db_attachment } else { $attachment = $this->invoice->create_attachment($filename, $this->invoice->get_label(), "application/pdf"); if ( !$attachment - || !$this->invoice->set_parameter("midcom.helper.datamanager2.type.blobs", "guids_pdf_file", $attachment->guid . ":" . $attachment->guid)) { + || !$this->invoice->set_parameter("midcom.helper.datamanager2.type.blobs", $name, $attachment->guid . ":" . $attachment->guid)) { throw new midcom_error("Failed to create invoice attachment for pdf: " . midcom_connection::get_error_string()); } } diff --git a/lib/org/openpsa/invoices/locale/default.de.txt b/lib/org/openpsa/invoices/locale/default.de.txt index ab8b723f76..1d00a69640 100644 --- a/lib/org/openpsa/invoices/locale/default.de.txt +++ b/lib/org/openpsa/invoices/locale/default.de.txt @@ -414,14 +414,30 @@ Die derzeitige PDF-Datei wurde manuell hochgeladen. Soll diese Datei wirklich er PDF erzeugen ---STRINGEND +---STRING reminder +Mahnung +---STRINGEND + +---STRING create_reminder +Mahnung erzeugen +---STRINGEND + ---STRING pdf created PDF-Datei wurde erfolgreich erzeugt ---STRINGEND +---STRING reminder pdf created +Mahnungs PDF-Datei wurde erfolgreich erzeugt +---STRINGEND + ---STRING pdf creation failed PDF-Datei konnte nicht erzeugt werden ---STRINGEND +---STRING reminder pdf creation failed +Mahnungs PDF-Datei konnte nicht erzeugt werden +---STRINGEND + ---STRING position Position ---STRINGEND diff --git a/lib/org/openpsa/invoices/locale/default.en.txt b/lib/org/openpsa/invoices/locale/default.en.txt index 83251258d6..8ba2c853e5 100644 --- a/lib/org/openpsa/invoices/locale/default.en.txt +++ b/lib/org/openpsa/invoices/locale/default.en.txt @@ -425,3 +425,7 @@ Could not create PDF ---STRING position Position ---STRINGEND + +---STRING create_reminder +create reminder +---STRINGEND diff --git a/lib/org/openpsa/invoices/style/admin-read.php b/lib/org/openpsa/invoices/style/admin-read.php index e21f15ab81..5a3295d26a 100644 --- a/lib/org/openpsa/invoices/style/admin-read.php +++ b/lib/org/openpsa/invoices/style/admin-read.php @@ -124,6 +124,10 @@
get('pdf file'); ?>
+get('reminder'); ?>
+ auth->drop_sudo(); } + public function testHandler_create_reminder() + { + midcom::get()->auth->request_sudo('org.openpsa.invoices'); + + $topic = $this->create_object(midcom_db_topic::class, ['component' => 'org.openpsa.invoices']); + $topic->set_parameter('org.openpsa.invoices', 'invoice_pdfbuilder_reminder_class', 'nonexistent'); + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST = [ + 'id' => self::$_invoice->id, + 'relocate' => true + ]; + $url = $this->run_relocate_handler($topic, ['invoice', 'action', 'create_reminder']); + $this->assertEquals('invoice/' . self::$_invoice->guid . '/', $url); + + midcom::get()->auth->drop_sudo(); + } + public function testHandler_mark_sent() { midcom::get()->auth->request_sudo('org.openpsa.invoices');