From 33e8e39412f8704f87a133fafc9b5c1529aa4102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= <p.mueller@pcsg.de> Date: Wed, 19 May 2021 11:43:43 +0200 Subject: [PATCH] feat: output button in draft panel --- ajax/invoices/getHistory.php | 6 ++- .../controls/panels/TemporaryInvoice.js | 50 +++++++++++++++++-- .../ERP/Accounting/Invoice/InvoiceView.php | 11 +++- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/ajax/invoices/getHistory.php b/ajax/invoices/getHistory.php index 788f65d..f7e3800 100644 --- a/ajax/invoices/getHistory.php +++ b/ajax/invoices/getHistory.php @@ -19,7 +19,11 @@ function ($invoiceId) { try { $Invoice = $Invoices->get($invoiceId); } catch (QUI\Exception $Exception) { - $Invoice = $Invoices->getInvoiceByHash($invoiceId); + try { + $Invoice = $Invoices->getInvoiceByHash($invoiceId); + } catch (QUI\Exception $Exception) { + $Invoice = $Invoices->getTemporaryInvoiceByHash($invoiceId); + } } /* @var $Invoice \QUI\ERP\Accounting\Invoice\Invoice */ diff --git a/bin/backend/controls/panels/TemporaryInvoice.js b/bin/backend/controls/panels/TemporaryInvoice.js index 8fa5079..c93ebb3 100644 --- a/bin/backend/controls/panels/TemporaryInvoice.js +++ b/bin/backend/controls/panels/TemporaryInvoice.js @@ -63,7 +63,8 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ '$onArticleReplaceClick', '$clickDelete', 'toggleSort', - '$showLockMessage' + '$showLockMessage', + 'print' ], options: { @@ -1330,7 +1331,6 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ this.getButtons('lock').hide(); - this.addButton({ name : 'delete', icon : 'fa fa-trash', @@ -1343,6 +1343,18 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ } }); + this.addButton({ + name : 'output', + textimage: 'fa fa-print', + text : QUILocale.get(lg, 'journal.btn.pdf'), + styles : { + 'float': 'right' + }, + events : { + onClick: this.print + } + }); + // categories this.addCategory({ name : 'data', @@ -1757,6 +1769,38 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ var value = (address.salutation + ' ' + address.firstname + ' ' + address.lastname).trim(); PersonInput.set('value', value); - } + }, + + /** + * Opens the print dialog + * + * @return {Promise} + */ + print: function () { + var self = this, + type = self.getAttribute('type'), + entityType; + + switch (parseInt(type)) { + case 3: + entityType = 'CreditNote'; + break; + + case 4: + entityType = 'Canceled'; + break; + + default: + entityType = 'Invoice'; + } + + return new Promise(function (resolve) { + require([ + 'package/quiqqer/invoice/bin/backend/utils/Dialogs' + ], function (Dialogs) { + Dialogs.openPrintDialog(self.getAttribute('id'), entityType).then(resolve); + }); + }); + }, }); }); diff --git a/src/QUI/ERP/Accounting/Invoice/InvoiceView.php b/src/QUI/ERP/Accounting/Invoice/InvoiceView.php index cf49d09..f6244a1 100644 --- a/src/QUI/ERP/Accounting/Invoice/InvoiceView.php +++ b/src/QUI/ERP/Accounting/Invoice/InvoiceView.php @@ -168,7 +168,8 @@ public function isPaid() public function previewHTML(): string { try { - $previewHtml = ERPOutput::getDocumentHtml($this->Invoice->getCleanId(), $this->getOutputType(), null, null, null, true); + $previewHtml = ERPOutput::getDocumentHtml($this->Invoice->getCleanId(), $this->getOutputType(), null, null, + null, true); } catch (QUI\Exception $Exception) { QUI\System\Log::writeException($Exception); $previewHtml = ''; @@ -336,4 +337,12 @@ protected function getOutputType(): string return 'Invoice'; } } + + /** + * @return bool + */ + public function isDraft(): bool + { + return $this->Invoice instanceof InvoiceTemporary; + } } -- GitLab