From ffc79778a0c4fee45af3a441abe8fa3a034460b0 Mon Sep 17 00:00:00 2001 From: Henning Leutz <leutz@pcsg.de> Date: Tue, 24 Sep 2019 08:25:42 +0200 Subject: [PATCH] refactor: fix: quiqqer/template-cologne#39 --- ajax/backend/update.php | 4 + bin/backend/controls/Payment.js | 85 +++++++++++++++---- locale.xml | 5 ++ .../Payments/Api/AbstractPayment.php | 11 --- .../Methods/AdvancePayment/Payment.php | 2 +- .../Payments/Methods/Invoice/Payment.php | 2 +- .../ERP/Accounting/Payments/Types/Factory.php | 5 ++ .../ERP/Accounting/Payments/Types/Payment.php | 63 ++++++++++++++ 8 files changed, 149 insertions(+), 28 deletions(-) diff --git a/ajax/backend/update.php b/ajax/backend/update.php index b6f952e..e19c779 100644 --- a/ajax/backend/update.php +++ b/ajax/backend/update.php @@ -33,6 +33,10 @@ function ($paymentId, $data) { $Payment->setDescription($data['description']); } + if (isset($data['orderInformation'])) { + $Payment->setOrderInformation($data['orderInformation']); + } + if (isset($data['paymentFeeTitle'])) { $Payment->setPaymentFeeTitle($data['paymentFeeTitle']); } diff --git a/bin/backend/controls/Payment.js b/bin/backend/controls/Payment.js index 6b6825f..62c9051 100644 --- a/bin/backend/controls/Payment.js +++ b/bin/backend/controls/Payment.js @@ -33,6 +33,7 @@ define('package/quiqqer/payments/bin/backend/controls/Payment', [ 'showInformation', 'showDescription', 'openDeleteDialog', + 'showOrderInformation', 'toggleStatus', 'save', '$onCreate', @@ -59,11 +60,11 @@ define('package/quiqqer/payments/bin/backend/controls/Payment', [ this.$Container = null; this.$IconField = null; - this.$DataTitle = null; - this.$DataWorkingTitle = null; - this.$DataDescription = null; - this.$PaymentFeeTitle = null; - + this.$DataTitle = null; + this.$DataWorkingTitle = null; + this.$DataDescription = null; + this.$DataOrderInformation = null; + this.$PaymentFeeTitle = null; this.addEvents({ onCreate : this.$onCreate, @@ -133,6 +134,15 @@ define('package/quiqqer/payments/bin/backend/controls/Payment', [ } }); + this.addCategory({ + name : 'orderInformation', + text : QUILocale.get(lg, 'panel.payment.order.information'), + icon : 'fa fa-file-text-o', + events: { + onClick: this.showOrderInformation + } + }); + this.$Container = new Element('div', { styles: { height : '100%', @@ -435,7 +445,7 @@ define('package/quiqqer/payments/bin/backend/controls/Payment', [ }, /** - * SHow the description + * Show the description */ showDescription: function () { var self = this; @@ -467,6 +477,39 @@ define('package/quiqqer/payments/bin/backend/controls/Payment', [ }); }, + /** + * Show the order information + */ + showOrderInformation: function () { + var self = this; + + Promise.all([ + this.$hideContainer(), + this.$getTranslationData('orderInformation') + ]).then(function (result) { + var Container = result[0], + description = result[1]; + + return new Promise(function (resolve) { + require(['controls/lang/ContentMultiLang'], function (ContentMultiLang) { + self.$DataOrderInformation = new ContentMultiLang({ + styles: { + height: '100%' + }, + events: { + onLoad: function () { + self.$DataOrderInformation.setData(description); + resolve(); + } + } + }).inject(Container); + }); + }); + }).then(function () { + return self.$showContainer(); + }); + }, + /** * Opens the delete dialog */ @@ -566,6 +609,11 @@ define('package/quiqqer/payments/bin/backend/controls/Payment', [ this.$DataDescription = null; } + if (this.$DataOrderInformation) { + this.$DataOrderInformation.destroy(); + this.$DataOrderInformation = null; + } + if (this.$DataTitle) { this.$DataTitle.destroy(); this.$DataTitle = null; @@ -598,6 +646,10 @@ define('package/quiqqer/payments/bin/backend/controls/Payment', [ this.$setData('description', this.$DataDescription.getData()); } + if (this.$DataOrderInformation) { + this.$setData('orderInformation', this.$DataOrderInformation.getData()); + } + if (this.$DataTitle) { this.$setData('title', this.$DataTitle.getData()); } @@ -687,10 +739,11 @@ define('package/quiqqer/payments/bin/backend/controls/Payment', [ $getTranslationData: function (name) { var paymentId = this.getAttribute('paymentId'); - var title = 'payment.' + paymentId + '.title'; - var description = 'payment.' + paymentId + '.description'; - var workingTitle = 'payment.' + paymentId + '.workingTitle'; - var paymentFeeTitle = 'payment.' + paymentId + '.paymentFeeTitle'; + var title = 'payment.' + paymentId + '.title'; + var description = 'payment.' + paymentId + '.description'; + var workingTitle = 'payment.' + paymentId + '.workingTitle'; + var paymentFeeTitle = 'payment.' + paymentId + '.paymentFeeTitle'; + var orderInformation = 'payment.' + paymentId + '.orderInformation'; if (typeof this.$__running === 'undefined') { this.$__storageData = {}; @@ -718,13 +771,15 @@ define('package/quiqqer/payments/bin/backend/controls/Payment', [ Translator.get(lg, description, lg), Translator.get(lg, workingTitle, lg), Translator.get(lg, paymentFeeTitle, lg), + Translator.get(lg, orderInformation, lg), Translator.getAvailableLanguages() ]).then(function (promiseResult) { - this.$__storageData.title = promiseResult[0]; - this.$__storageData.description = promiseResult[1]; - this.$__storageData.workingTitle = promiseResult[2]; - this.$__storageData.paymentFeeTitle = promiseResult[3]; - this.$__storageData.languages = promiseResult[4]; + this.$__storageData.title = promiseResult[0]; + this.$__storageData.description = promiseResult[1]; + this.$__storageData.workingTitle = promiseResult[2]; + this.$__storageData.paymentFeeTitle = promiseResult[3]; + this.$__storageData.orderInformation = promiseResult[4]; + this.$__storageData.languages = promiseResult[5]; this.$__running = false; resolve(); diff --git a/locale.xml b/locale.xml index a2cf08e..88c9b08 100644 --- a/locale.xml +++ b/locale.xml @@ -351,6 +351,11 @@ Beispiel: Nachnahmegebühr: 10,00 € <de><![CDATA[Zahlungsart: [paymentType]]]></de> <en><![CDATA[Payment type: [paymentType]]]></en> </locale> + + <locale name="panel.payment.order.information"> + <de><![CDATA[Bestellinformationstext]]></de> + <en><![CDATA[Order information text]]></en> + </locale> </groups> </locales> \ No newline at end of file diff --git a/src/QUI/ERP/Accounting/Payments/Api/AbstractPayment.php b/src/QUI/ERP/Accounting/Payments/Api/AbstractPayment.php index bd07515..4369d39 100644 --- a/src/QUI/ERP/Accounting/Payments/Api/AbstractPayment.php +++ b/src/QUI/ERP/Accounting/Payments/Api/AbstractPayment.php @@ -253,16 +253,5 @@ public function getInvoiceInformationText($Invoice) return ''; } - /** - * Return the extra text for the invoice - * - * @param QUI\ERP\Order\OrderInterface $Order - * @return string - */ - public function getOrderInformationText($Order) - { - return ''; - } - //endregion } diff --git a/src/QUI/ERP/Accounting/Payments/Methods/AdvancePayment/Payment.php b/src/QUI/ERP/Accounting/Payments/Methods/AdvancePayment/Payment.php index b281111..97aeb01 100644 --- a/src/QUI/ERP/Accounting/Payments/Methods/AdvancePayment/Payment.php +++ b/src/QUI/ERP/Accounting/Payments/Methods/AdvancePayment/Payment.php @@ -45,7 +45,7 @@ public function getDescription() */ public function isSuccessful($hash) { - return false; + return true; } /** diff --git a/src/QUI/ERP/Accounting/Payments/Methods/Invoice/Payment.php b/src/QUI/ERP/Accounting/Payments/Methods/Invoice/Payment.php index 5a842a4..80dbe9d 100644 --- a/src/QUI/ERP/Accounting/Payments/Methods/Invoice/Payment.php +++ b/src/QUI/ERP/Accounting/Payments/Methods/Invoice/Payment.php @@ -100,7 +100,7 @@ public function getInvoiceInformationText($Invoice) } /** - * Create a Scubscription from a (temporary) Order + * Create a Subscription from a (temporary) Order * * @param AbstractOrder $Order * @return void diff --git a/src/QUI/ERP/Accounting/Payments/Types/Factory.php b/src/QUI/ERP/Accounting/Payments/Types/Factory.php index 6f68dcc..6e972e5 100644 --- a/src/QUI/ERP/Accounting/Payments/Types/Factory.php +++ b/src/QUI/ERP/Accounting/Payments/Types/Factory.php @@ -118,6 +118,11 @@ public function createChild($data = []) ' ' ); + $this->createPaymentLocale( + 'payment.'.$NewChild->getId().'.orderInformation', + ' ' + ); + try { QUI\Translator::publish('quiqqer/payments'); } catch (QUI\Exception $Exception) { diff --git a/src/QUI/ERP/Accounting/Payments/Types/Payment.php b/src/QUI/ERP/Accounting/Payments/Types/Payment.php index ef26def..a42697d 100644 --- a/src/QUI/ERP/Accounting/Payments/Types/Payment.php +++ b/src/QUI/ERP/Accounting/Payments/Types/Payment.php @@ -84,6 +84,12 @@ public function toArray() $lg, 'payment.'.$id.'.workingTitle' ); + + $attributes['orderInformation'][$language] = $Locale->getByLang( + $language, + $lg, + 'payment.'.$id.'.orderInformation' + ); } // payment type @@ -362,6 +368,50 @@ public function getWorkingTitle($Locale = null) ); } + /** + * Return the extra text for the invoice + * + * @param QUI\ERP\Order\OrderInterface $Order + * @return string + */ + public function getOrderInformationText(QUI\ERP\Order\OrderInterface $Order) + { + $Shipping = $Order->getShipping(); + $Locale = QUI::getLocale(); + $Currency = $Order->getCurrency(); + + $id = $this->getId(); + + $shipping = ''; + $paidDate = ''; + $paid = ''; + $toPay = ''; + + try { + $paidStatus = $Order->getPaidStatusInformation(); + + $paidDate = $paidStatus['paidDate']; + $paid = $paidStatus['paid']; + $toPay = $paidStatus['toPay']; + } catch (QUI\Exception $Exception) { + QUI\System\Log::addWarning($Exception->getMessage()); + } + + if ($Shipping) { + $shipping = $Shipping->getTitle(); + } + + // @todo bestellnr + + return $Locale->get('quiqqer/payments', 'payment.'.$id.'.orderInformation', [ + 'orderId' => $Order->getId(), + 'shipping' => $shipping, + 'paidDate' => $paidDate, + 'paid' => $Currency->format($paid), + 'toPay' => $Currency->format($toPay) + ]); + } + /** * Return the icon for the Payment * @@ -417,6 +467,19 @@ public function setDescription(array $descriptions) ); } + /** + * Set the order information text + * + * @param array $orderInformation + */ + public function setOrderInformation(array $orderInformation) + { + $this->setPaymentLocale( + 'payment.'.$this->getId().'.orderInformation', + $orderInformation + ); + } + /** * Set the working title * -- GitLab