From 5fe9793b4350ba0fe67feb9b1cb4cce1ffeb7583 Mon Sep 17 00:00:00 2001 From: Henning Leutz <leutz@pcsg.de> Date: Wed, 22 Feb 2017 11:41:58 +0100 Subject: [PATCH] refactor: development --- ajax/invoices/create.php | 6 +-- .../panels/TemporaryInvoice.UserData.js | 4 ++ database.xml | 2 +- src/QUI/ERP/Accounting/Invoice/Factory.php | 43 +++++++------------ src/QUI/ERP/Accounting/Invoice/Handler.php | 26 ----------- .../Accounting/Invoice/TemporaryInvoice.php | 4 +- 6 files changed, 25 insertions(+), 60 deletions(-) diff --git a/ajax/invoices/create.php b/ajax/invoices/create.php index a6efab9..5a889dc 100644 --- a/ajax/invoices/create.php +++ b/ajax/invoices/create.php @@ -12,11 +12,11 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_invoice_ajax_invoices_create', function () { - $Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); - $Invoice = $Invoices->create(); + $Factory = QUI\ERP\Accounting\Invoice\Factory::getInstance(); + $Invoice = $Factory->createInvoice(); return $Invoice->getId(); }, - array(), + false, 'Permission::checkAdminUser' ); diff --git a/bin/backend/controls/panels/TemporaryInvoice.UserData.js b/bin/backend/controls/panels/TemporaryInvoice.UserData.js index 0f07354..45e9787 100644 --- a/bin/backend/controls/panels/TemporaryInvoice.UserData.js +++ b/bin/backend/controls/panels/TemporaryInvoice.UserData.js @@ -157,6 +157,10 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use } return this.$getUser().then(function (User) { + if (!User) { + return []; + } + return User.getAddressList(); }).then(function (addresses) { diff --git a/database.xml b/database.xml index 40e2ae3..119fe26 100644 --- a/database.xml +++ b/database.xml @@ -58,7 +58,7 @@ <field type="INT NOT NULL">customer_id</field> <field type="INT NOT NULL">address_id</field> <field type="INT NULL">order_id</field> - <field type="VARCHAR(250) NOT NULL">hash</field> + <field type="VARCHAR(40) NOT NULL">hash</field> <field type="VARCHAR(200) NOT NULL">payment_method</field> <field type="TEXT NULL">payment_data</field> <!-- muss verschlüsselt sein --> diff --git a/src/QUI/ERP/Accounting/Invoice/Factory.php b/src/QUI/ERP/Accounting/Invoice/Factory.php index 818043d..ae384fb 100644 --- a/src/QUI/ERP/Accounting/Invoice/Factory.php +++ b/src/QUI/ERP/Accounting/Invoice/Factory.php @@ -11,45 +11,32 @@ * * @package QUI\ERP\Accounting\Invoice */ -class Factory +class Factory extends QUI\Utils\Singleton { /** - * @var null - */ - protected static $Instance = null; - - /** - * @return null|Factory - */ - public static function getInstance() - { - if (self::$Instance === null) { - self::$Instance = new self(); - } - - return self::$Instance; - } - - /** - * Create a non posted invoice + * Creates a new temporary invoice * + * @param QUI\Interfaces\Users\User|null $User * @return TemporaryInvoice */ - public function createInvoice() + public function createInvoice($User = null) { - $Handler = Handler::getInstance(); - $Database = QUI::getDataBase(); - $Hash = Uuid::uuid1(); + if ($User === null) { + $User = QUI::getUserBySession(); + } + + QUI\Permissions\Permission::checkPermission('quiqqer.invoice.create', $User); - $Database->insert( - $Handler->temporaryInvoiceTable(), + QUI::getDataBase()->insert( + Handler::getInstance()->temporaryInvoiceTable(), array( - 'hash' => $Hash->toString() + 'c_user' => $User->getId(), + 'hash' => Uuid::uuid1()->toString() ) ); - $newId = $Database->getPDO()->lastInsertId(); + $newId = QUI::getDataBase()->getPDO()->lastInsertId(); - return $Handler->getTemporaryInvoice($newId); + return Handler::getInstance()->getTemporaryInvoice($newId); } } diff --git a/src/QUI/ERP/Accounting/Invoice/Handler.php b/src/QUI/ERP/Accounting/Invoice/Handler.php index 29571ee..13e8a6f 100644 --- a/src/QUI/ERP/Accounting/Invoice/Handler.php +++ b/src/QUI/ERP/Accounting/Invoice/Handler.php @@ -52,32 +52,6 @@ public function temporaryInvoiceTable() return QUI::getDBTableName(self::TABLE_TEMPORARY_INVOICE); } - /** - * Creates a new temporary invoice - * - * @param QUI\Interfaces\Users\User|null $User - * @return TemporaryInvoice - */ - public function create($User = null) - { - if ($User === null) { - $User = QUI::getUserBySession(); - } - - QUI\Permissions\Permission::checkPermission('quiqqer.invoice.create', $User); - - QUI::getDataBase()->insert( - $this->temporaryInvoiceTable(), - array( - 'c_user' => $User->getId() - ) - ); - - $newId = QUI::getDataBase()->getPDO()->lastInsertId(); - - return $this->getTemporaryInvoice($newId); - } - /** * Delete a temporary invoice * diff --git a/src/QUI/ERP/Accounting/Invoice/TemporaryInvoice.php b/src/QUI/ERP/Accounting/Invoice/TemporaryInvoice.php index 160cb99..b9ff1c2 100644 --- a/src/QUI/ERP/Accounting/Invoice/TemporaryInvoice.php +++ b/src/QUI/ERP/Accounting/Invoice/TemporaryInvoice.php @@ -123,7 +123,6 @@ public function save($User = null) 'sum' => '', 'vat_data' => '', 'processing_status' => '' - ), array( 'id' => $this->getCleanId() @@ -159,7 +158,8 @@ public function delete($User = null) public function copy($User = null) { $Handler = Handler::getInstance(); - $New = $Handler->create($User); + $Factory = Factory::getInstance(); + $New = $Factory->createInvoice($User); $currentData = QUI::getDataBase()->fetch(array( 'from' => $Handler->temporaryInvoiceTable(), -- GitLab