From 21bc85666207f893e898a24fd82bb6b8b75adbb7 Mon Sep 17 00:00:00 2001 From: Henning Leutz <leutz@pcsg.de> Date: Fri, 14 Aug 2020 08:58:36 +0200 Subject: [PATCH] fix: consider older invoice prefixed ids --- ajax/invoices/temporary/copy.php | 6 ++---- ajax/invoices/temporary/getArticleHtml.php | 10 +++------ ajax/invoices/temporary/html.php | 5 ++--- ajax/invoices/temporary/missing.php | 3 +-- ajax/invoices/temporary/post.php | 3 +-- ajax/invoices/temporary/previewhtml.php | 5 ++--- ajax/invoices/temporary/save.php | 7 ++++--- ajax/invoices/temporary/unlock.php | 4 ++-- bin/backend/classes/Invoices.js | 4 ++-- bin/backend/controls/panels/Invoice.js | 2 +- bin/backend/controls/panels/Journal.js | 8 +++---- .../controls/panels/TemporaryInvoice.js | 8 ++++--- .../controls/panels/TemporaryInvoices.js | 16 +++++++------- src/QUI/ERP/Accounting/Invoice/Handler.php | 3 ++- .../ERP/Accounting/Invoice/Utils/Invoice.php | 21 +++++++++++++++++++ 15 files changed, 60 insertions(+), 45 deletions(-) diff --git a/ajax/invoices/temporary/copy.php b/ajax/invoices/temporary/copy.php index d151841..210e537 100644 --- a/ajax/invoices/temporary/copy.php +++ b/ajax/invoices/temporary/copy.php @@ -12,11 +12,9 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_invoice_ajax_invoices_temporary_copy', function ($invoiceId) { - $Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); + $Invoice = QUI\ERP\Accounting\Invoice\Utils\Invoice::getTemporaryInvoiceByString($invoiceId); - return $Invoices->getTemporaryInvoice($invoiceId) - ->copy() - ->getId(); + return $Invoice->copy()->getId(); }, ['invoiceId'], 'Permission::checkAdminUser' diff --git a/ajax/invoices/temporary/getArticleHtml.php b/ajax/invoices/temporary/getArticleHtml.php index 9b16f4e..4a5b115 100644 --- a/ajax/invoices/temporary/getArticleHtml.php +++ b/ajax/invoices/temporary/getArticleHtml.php @@ -4,6 +4,8 @@ * This file contains package_quiqqer_invoice_ajax_invoices_temporary_getArticleHtml */ +use QUI\ERP\Accounting\Invoice\Utils\Invoice as InvoiceUtils; + /** * Returns the temporary invoice articles as html * @@ -14,13 +16,7 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_invoice_ajax_invoices_temporary_getArticleHtml', function ($invoiceId) { - $Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); - - try { - $Invoice = $Invoices->getTemporaryInvoice($invoiceId); - } catch (QUI\Exception $Exception) { - $Invoice = $Invoices->getInvoiceByHash($invoiceId); - } + $Invoice = InvoiceUtils::getTemporaryInvoiceByString($invoiceId); return $Invoice->getView()->getArticles()->render(); }, diff --git a/ajax/invoices/temporary/html.php b/ajax/invoices/temporary/html.php index aeb883a..520301a 100644 --- a/ajax/invoices/temporary/html.php +++ b/ajax/invoices/temporary/html.php @@ -12,9 +12,8 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_invoice_ajax_invoices_temporary_html', function ($invoiceId, $data) { - $Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); - $Invoice = $Invoices->getTemporaryInvoice($invoiceId); - $data = \json_decode($data, true); + $Invoice = QUI\ERP\Accounting\Invoice\Utils\Invoice::getTemporaryInvoiceByString($invoiceId); + $data = \json_decode($data, true); $Invoice->clearArticles(); diff --git a/ajax/invoices/temporary/missing.php b/ajax/invoices/temporary/missing.php index 08e3558..327231b 100644 --- a/ajax/invoices/temporary/missing.php +++ b/ajax/invoices/temporary/missing.php @@ -15,8 +15,7 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_invoice_ajax_invoices_temporary_missing', function ($invoiceId) { - $Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); - $Invoice = $Invoices->getTemporaryInvoice($invoiceId); + $Invoice = QUI\ERP\Accounting\Invoice\Utils\Invoice::getTemporaryInvoiceByString($invoiceId); $missed = $Invoice->getMissingAttributes(); $result = []; diff --git a/ajax/invoices/temporary/post.php b/ajax/invoices/temporary/post.php index 0714862..5dd1202 100644 --- a/ajax/invoices/temporary/post.php +++ b/ajax/invoices/temporary/post.php @@ -14,8 +14,7 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_invoice_ajax_invoices_temporary_post', function ($invoiceId) { - $Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); - $Temporary = $Invoices->getTemporaryInvoice($invoiceId); + $Temporary = QUI\ERP\Accounting\Invoice\Utils\Invoice::getTemporaryInvoiceByString($invoiceId); $Invoice = $Temporary->post(); return $Invoice->getHash(); diff --git a/ajax/invoices/temporary/previewhtml.php b/ajax/invoices/temporary/previewhtml.php index 1085a1b..13c8f3a 100644 --- a/ajax/invoices/temporary/previewhtml.php +++ b/ajax/invoices/temporary/previewhtml.php @@ -12,9 +12,8 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_invoice_ajax_invoices_temporary_previewhtml', function ($invoiceId, $data) { - $Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); - $Invoice = $Invoices->getTemporaryInvoice($invoiceId); - $data = \json_decode($data, true); + $Invoice = QUI\ERP\Accounting\Invoice\Utils\Invoice::getTemporaryInvoiceByString($invoiceId); + $data = \json_decode($data, true); $Invoice->clearArticles(); diff --git a/ajax/invoices/temporary/save.php b/ajax/invoices/temporary/save.php index 578d753..a0e5edc 100644 --- a/ajax/invoices/temporary/save.php +++ b/ajax/invoices/temporary/save.php @@ -16,9 +16,8 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_invoice_ajax_invoices_temporary_save', function ($invoiceId, $data) { - $Invoices = InvoiceHandler::getInstance(); - $Invoice = $Invoices->getTemporaryInvoice($invoiceId); - $data = \json_decode($data, true); + $Invoice = QUI\ERP\Accounting\Invoice\Utils\Invoice::getTemporaryInvoiceByString($invoiceId); + $data = \json_decode($data, true); if (empty($data['customer_id'])) { $data['invoice_address_id'] = ''; @@ -49,6 +48,8 @@ function ($invoiceId, $data) { $Invoice->setAttribute('invoice_address', false); // needed because of address reset $Invoice->setAttributes($data); $Invoice->save(); + + return $Invoice->toArray(); }, ['invoiceId', 'data'], 'Permission::checkAdminUser' diff --git a/ajax/invoices/temporary/unlock.php b/ajax/invoices/temporary/unlock.php index 9102626..614f69c 100644 --- a/ajax/invoices/temporary/unlock.php +++ b/ajax/invoices/temporary/unlock.php @@ -12,8 +12,8 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_invoice_ajax_invoices_temporary_unlock', function ($invoiceId) { - $Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); - $Invoice = $Invoices->getTemporaryInvoice($invoiceId); + $Invoice = QUI\ERP\Accounting\Invoice\Utils\Invoice::getTemporaryInvoiceByString($invoiceId); + $Invoice->unlock(); }, ['invoiceId'], 'Permission::checkAdminUser' diff --git a/bin/backend/classes/Invoices.js b/bin/backend/classes/Invoices.js index e80fc90..063b35b 100644 --- a/bin/backend/classes/Invoices.js +++ b/bin/backend/classes/Invoices.js @@ -359,9 +359,9 @@ define('package/quiqqer/invoice/bin/backend/classes/Invoices', [ var self = this; return new Promise(function (resolve, reject) { - QUIAjax.post('package_quiqqer_invoice_ajax_invoices_temporary_save', function () { + QUIAjax.post('package_quiqqer_invoice_ajax_invoices_temporary_save', function (result) { self.fireEvent('saveInvoice', [self, invoiceId, data]); - resolve(); + resolve(result); }, { 'package': 'quiqqer/invoice', invoiceId: invoiceId, diff --git a/bin/backend/controls/panels/Invoice.js b/bin/backend/controls/panels/Invoice.js index 2a288ab..768b7cc 100644 --- a/bin/backend/controls/panels/Invoice.js +++ b/bin/backend/controls/panels/Invoice.js @@ -404,7 +404,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/Invoice', [ require([ 'package/quiqqer/invoice/bin/backend/utils/Dialogs' ], function (Dialogs) { - Dialogs.openPrintDialog(Data.id_prefix + Data.id, entityType).then(resolve); + Dialogs.openPrintDialog(Data.id, entityType).then(resolve); }); }); }, diff --git a/bin/backend/controls/panels/Journal.js b/bin/backend/controls/panels/Journal.js index bf1a700..4ac6d04 100644 --- a/bin/backend/controls/panels/Journal.js +++ b/bin/backend/controls/panels/Journal.js @@ -767,7 +767,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/Journal', [ 'package/quiqqer/erp/bin/backend/controls/OutputDialog' ], function (OutputDialog) { new OutputDialog({ - entityId : Entry.id, + entityId : Entry.hash, entityType: entityType }).open(); @@ -859,7 +859,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/Journal', [ ParentNode.setStyle('padding', 10); ParentNode.set('html', '<div class="fa fa-spinner fa-spin"></div>'); - Invoices.getArticleHtml(this.$Grid.getDataByRow(row).id).then(function (result) { + Invoices.getArticleHtml(this.$Grid.getDataByRow(row).hash).then(function (result) { ParentNode.set('html', ''); new Element('div', { @@ -943,7 +943,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/Journal', [ return Promise.resolve(); } - return this.openInvoice(selected[0].id); + return this.openInvoice(selected[0].hash); }, /** @@ -959,7 +959,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/Journal', [ } var self = this, - invoiceId = selected[0].id; + invoiceId = selected[0].hash; return new Promise(function (resolve) { require([ diff --git a/bin/backend/controls/panels/TemporaryInvoice.js b/bin/backend/controls/panels/TemporaryInvoice.js index a44a4cc..378507f 100644 --- a/bin/backend/controls/panels/TemporaryInvoice.js +++ b/bin/backend/controls/panels/TemporaryInvoice.js @@ -211,14 +211,16 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ return Invoices.saveInvoice( this.getAttribute('invoiceId'), this.getCurrentData() - ).then(function () { + ).then(function (Data) { return Promise.all([ Invoices.postInvoice(self.getAttribute('invoiceId')), - Invoices.getSetting('temporaryInvoice', 'openPrintDialogAfterPost') + Invoices.getSetting('temporaryInvoice', 'openPrintDialogAfterPost'), + Data ]); }).then(function (result) { var newInvoiceHash = result[0], - openPrintDialogAfterPost = result[1]; + openPrintDialogAfterPost = result[1], + Data = result[2]; if (!openPrintDialogAfterPost) { self.destroy(); diff --git a/bin/backend/controls/panels/TemporaryInvoices.js b/bin/backend/controls/panels/TemporaryInvoices.js index df02a22..c3c0dde 100644 --- a/bin/backend/controls/panels/TemporaryInvoices.js +++ b/bin/backend/controls/panels/TemporaryInvoices.js @@ -551,7 +551,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', text : QUILocale.get(lg, 'journal.contextMenu.open.invoice'), events: { onClick: function () { - self.openInvoice(rowData.id); + self.openInvoice(rowData.hash); } } }) @@ -587,7 +587,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', } self.openInvoice( - self.$Grid.getSelectedData()[0].id + self.$Grid.getSelectedData()[0].hash ); } }); @@ -772,7 +772,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', var posts = []; for (var i = 0, len = selected.length; i < len; i++) { - posts.push(Invoices.postInvoice(selected[i].id)); + posts.push(Invoices.postInvoice(selected[i].hash)); } Promise.all(posts).then(function () { @@ -799,7 +799,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', } // open print dialog - Dialogs.openPrintDialog(selected[0].id, entityType).then(function () { + Dialogs.openPrintDialog(selected[0].hash, entityType).then(function () { Win.close(); }); }).catch(function (Err) { @@ -853,7 +853,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', var posts = []; for (var i = 0, len = selected.length; i < len; i++) { - posts.push(Invoices.deleteInvoice(selected[i].id)); + posts.push(Invoices.deleteInvoice(selected[i].hash)); } Promise.all(posts).then(function () { @@ -907,7 +907,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', onSubmit: function (Win) { Win.Loader.show(); - Invoices.copyTemporaryInvoice(selected[0].id).then(function (newId) { + Invoices.copyTemporaryInvoice(selected[0].hash).then(function (newId) { Win.close(); return self.openInvoice(newId); }).then(function () { @@ -963,7 +963,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', } new OutputDialog({ - entityId : selected.id, + entityId : selected.hash, entityType: entityType }).open(); @@ -991,7 +991,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', ParentNode.setStyle('padding', 10); ParentNode.set('html', '<div class="fa fa-spinner fa-spin"></div>'); - Invoices.getArticleHtmlFromTemporary(this.$Grid.getDataByRow(row).id).then(function (result) { + Invoices.getArticleHtmlFromTemporary(this.$Grid.getDataByRow(row).hash).then(function (result) { ParentNode.set('html', ''); if (result.indexOf('<table') === -1) { diff --git a/src/QUI/ERP/Accounting/Invoice/Handler.php b/src/QUI/ERP/Accounting/Invoice/Handler.php index 45967b6..7b2a421 100644 --- a/src/QUI/ERP/Accounting/Invoice/Handler.php +++ b/src/QUI/ERP/Accounting/Invoice/Handler.php @@ -134,7 +134,8 @@ public function getInvoicesByUser(QUI\Users\User $User) */ public function delete($invoiceId, $User = null) { - $this->getTemporaryInvoice($invoiceId)->delete($User); + $Invoice = QUI\ERP\Accounting\Invoice\Utils\Invoice::getInvoiceByString($invoiceId); + $Invoice->delete($User); } /** diff --git a/src/QUI/ERP/Accounting/Invoice/Utils/Invoice.php b/src/QUI/ERP/Accounting/Invoice/Utils/Invoice.php index 1a61631..708ba54 100644 --- a/src/QUI/ERP/Accounting/Invoice/Utils/Invoice.php +++ b/src/QUI/ERP/Accounting/Invoice/Utils/Invoice.php @@ -49,6 +49,27 @@ public static function getInvoiceByString($str) QUI\System\Log::writeDebugException($Exception); } + try { + return self::getTemporaryInvoiceByString($str); + } catch (QUI\Exception $Exception) { + QUI\System\Log::writeDebugException($Exception); + } + + throw $Exception; + } + + /** + * @param $str + * + * @return InvoiceTemporary + * + * @throws Exception + * @throws QUI\Exception + */ + public static function getTemporaryInvoiceByString($str) + { + $Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); + try { return $Invoices->getTemporaryInvoiceByHash($str); } catch (QUI\Exception $Exception) { -- GitLab