diff --git a/ajax/invoices/getHistory.php b/ajax/invoices/getHistory.php index 788f65d93ea68f3c8829b4fc2bf7887e34a9e211..f7e3800e79cea316d7d093d2528d10a748071642 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 8fa5079c970efca6e6a0084c5dd2e11650ca2329..c93ebb3c85826781af6f336ad3e1c854e3bd2a4d 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 cf49d09228995be7220dcb594ef569bb3abc60e0..f6244a1f6b50c2066fbb00efb22048da1cf775d5 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; + } }