diff --git a/ajax/invoices/temporary/list.php b/ajax/invoices/temporary/list.php index ae76949df448517b7b79bc3ec83e32afe3604dc7..140af95e2096e3684d944607b1495a886abc243d 100644 --- a/ajax/invoices/temporary/list.php +++ b/ajax/invoices/temporary/list.php @@ -5,6 +5,7 @@ */ use QUI\ERP\Accounting\Invoice\TemporaryInvoice; +use QUI\ERP\Accounting\Invoice\Handler; /** * Returns temporary invoices list for a grid @@ -16,7 +17,7 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_invoice_ajax_invoices_temporary_list', function ($params) { - $Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); + $Invoices = Handler::getInstance(); $Grid = new QUI\Utils\Grid(); $data = $Invoices->searchTemporaryInvoices( @@ -30,6 +31,7 @@ function ($params) { 'customer_name', 'date', 'c_user', + 'c_username', 'paidstatus', 'display_nettosum', 'display_vatsum', @@ -51,7 +53,7 @@ function ($params) { $fillFields = function (&$data) use ($needleFields) { foreach ($needleFields as $field) { if (!isset($data[$field])) { - $data[$field] = ''; + $data[$field] = Handler::EMPTY_VALUE; } } }; @@ -60,6 +62,29 @@ function ($params) { $fillFields($data[$key]); $data[$key]['id'] = TemporaryInvoice::ID_PREFIX . $data[$key]['id']; + + // customer data + if (!empty($entry['customer_id'])) { + try { + $Customer = QUI::getUsers()->get($entry['customer_id']); + + $data[$key]['customer_name'] = $Customer->getName(); + } catch (QUI\Exception $Exception) { + $data[$key]['customer_id'] = Handler::EMPTY_VALUE; + $data[$key]['customer_name'] = Handler::EMPTY_VALUE; + } + } + + if (!empty($entry['c_user'])) { + try { + $CUser = QUI::getUsers()->get($entry['c_user']); + + $data[$key]['c_username'] = $CUser->getName(); + } catch (QUI\Exception $Exception) { + $data[$key]['c_user'] = Handler::EMPTY_VALUE; + $data[$key]['c_username'] = Handler::EMPTY_VALUE; + } + } } return $Grid->parseResult($data, $Invoices->countTemporaryInvoices()); diff --git a/ajax/invoices/temporary/save.php b/ajax/invoices/temporary/save.php new file mode 100644 index 0000000000000000000000000000000000000000..83034d28a992b6329a5535f1338354110549076e --- /dev/null +++ b/ajax/invoices/temporary/save.php @@ -0,0 +1,29 @@ +<?php + +/** + * This file contains package_quiqqer_invoice_ajax_invoices_temporary_save + */ + +/** + * Saves the temporary invoice + * + * @param integer|string $invoiceId + * @param string $data - JSON data + */ +QUI::$Ajax->registerFunction( + 'package_quiqqer_invoice_ajax_invoices_temporary_save', + function ($invoiceId, $data) { + $Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); + $Invoice = $Invoices->getTemporaryInvoice($invoiceId); + $data = json_decode($data, true); + + $Invoice->setAttributes($data); + $Invoice->save(); + + QUI::getMessagesHandler()->addSuccess( + QUI::getLocale()->get('quiqqer/invoice', 'message.invoice.save.successfully') + ); + }, + array('invoiceId', 'data'), + 'Permission::checkAdminUser' +); diff --git a/bin/backend/classes/Invoices.js b/bin/backend/classes/Invoices.js index f96cb3ed45a22482ec6133b07aee5d7fb89d2830..b9968a35749394aa85ee6488c29dd18e56b47bef 100644 --- a/bin/backend/classes/Invoices.js +++ b/bin/backend/classes/Invoices.js @@ -21,7 +21,7 @@ define('package/quiqqer/invoice/bin/backend/classes/Invoices', [ return new Class({ Extends: QUIDOM, - Type: 'package/quiqqer/invoice/bin/backend/classes/Invoices', + Type : 'package/quiqqer/invoice/bin/backend/classes/Invoices', initialize: function (options) { this.parent(options); @@ -38,7 +38,7 @@ define('package/quiqqer/invoice/bin/backend/classes/Invoices', [ QUIAjax.get('package_quiqqer_invoice_ajax_invoices_get', resolve, { 'package': 'quiqqer/invoice', invoiceId: invoiceId, - onError: reject, + onError : reject, showError: false }); }); @@ -54,8 +54,8 @@ define('package/quiqqer/invoice/bin/backend/classes/Invoices', [ return new Promise(function (resolve, reject) { QUIAjax.get('package_quiqqer_invoice_ajax_invoices_list', resolve, { 'package': 'quiqqer/invoice', - params: JSON.encode(params), - onError: reject, + params : JSON.encode(params), + onError : reject, showError: false }); }); @@ -72,7 +72,7 @@ define('package/quiqqer/invoice/bin/backend/classes/Invoices', [ QUIAjax.get('package_quiqqer_invoice_ajax_invoices_temporary_get', resolve, { 'package': 'quiqqer/invoice', invoiceId: invoiceId, - onError: reject, + onError : reject, showError: false }); }); @@ -90,8 +90,8 @@ define('package/quiqqer/invoice/bin/backend/classes/Invoices', [ return new Promise(function (resolve, reject) { QUIAjax.get('package_quiqqer_invoice_ajax_invoices_temporary_list', resolve, { 'package': 'quiqqer/invoice', - params: JSON.encode(params), - onError: reject, + params : JSON.encode(params), + onError : reject, showError: false }); }); @@ -110,7 +110,7 @@ define('package/quiqqer/invoice/bin/backend/classes/Invoices', [ resolve(newId); }, { 'package': 'quiqqer/invoice', - onError: reject, + onError : reject, showError: false }); }); @@ -131,7 +131,31 @@ define('package/quiqqer/invoice/bin/backend/classes/Invoices', [ }, { 'package': 'quiqqer/invoice', invoiceId: invoiceId, - onError: reject, + onError : reject, + showError: false + }); + }); + }, + + /** + * Delete a temporary invoice + * + * @param {String} invoiceId + * @param {Object} data + * @returns {Promise} + */ + saveInvoice: function (invoiceId, data) { + var self = this; + + return new Promise(function (resolve, reject) { + QUIAjax.post('package_quiqqer_invoice_ajax_invoices_temporary_save', function () { + self.fireEvent('saveInvoice', [self, invoiceId, data]); + resolve(); + }, { + 'package': 'quiqqer/invoice', + invoiceId: invoiceId, + data : JSON.encode(data), + onError : reject, showError: false }); }); @@ -152,7 +176,7 @@ define('package/quiqqer/invoice/bin/backend/classes/Invoices', [ }, { 'package': 'quiqqer/invoice', invoiceId: invoiceId, - onError: reject, + onError : reject, showError: false }); }); diff --git a/bin/backend/controls/panels/TemporaryInvoice.UserData.html b/bin/backend/controls/panels/TemporaryInvoice.UserData.html index a99cc27c65c6b68b3f110311f7ddd2526460876b..9a66f50a18a868e57a12f557aa8a0657969a851d 100644 --- a/bin/backend/controls/panels/TemporaryInvoice.UserData.html +++ b/bin/backend/controls/panels/TemporaryInvoice.UserData.html @@ -1,7 +1,7 @@ <table class="data-table data-table-flexbox invoice-data-customer"> <thead> <tr> - <th>Kundendaten</th> + <th>{{textTitle}}</th> </tr> </thead> @@ -9,8 +9,8 @@ <tr> <td> <label class="field-container"> - <span class="field-container-item" title="Kunde"> - Kunde + <span class="field-container-item" title="{{textCustomer}}"> + {{textCustomer}} </span> <span class="field-container-field field-container-field-no-padding"> <input type="hidden" @@ -26,8 +26,8 @@ <tr class="address-row" style="display: none;"> <td> <label class="field-container"> - <span class="field-container-item" title="Adresse"> - Adresse + <span class="field-container-item" title="{{textAddress}}"> + {{textAddress}} </span> <select class="field-container-field" name="address"> </select> @@ -37,8 +37,8 @@ <tr class="closable" style="display: none;"> <td> <label class="field-container"> - <span class="field-container-item" title="Firma"> - Firme + <span class="field-container-item" title="{{textCompany}}"> + {{textCompany}} </span> <input type="text" class="field-container-field" name="company" disabled/> </label> @@ -47,8 +47,8 @@ <tr class="closable" style="display: none;"> <td> <label class="field-container"> - <span class="field-container-item" title="Straße"> - Straße + <span class="field-container-item" title="{{textStreet}}"> + {{textStreet}} </span> <input type="text" class="field-container-field" name="street" disabled/> </label> @@ -57,8 +57,8 @@ <tr class="closable" style="display: none;"> <td> <label class="field-container"> - <span class="field-container-item" title="PLZ"> - PLZ + <span class="field-container-item" title="{{textZip}}"> + {{textZip}} </span> <input type="text" class="field-container-field" name="zip" disabled/> </label> @@ -67,8 +67,8 @@ <tr class="closable" style="display: none;"> <td> <label class="field-container"> - <span class="field-container-item" title="Ort"> - Ort + <span class="field-container-item" title="{{textCity}}"> + {{textCity}} </span> <input type="text" class="field-container-field" name="city" disabled/> </label> @@ -80,7 +80,7 @@ <div class="quiqqer-invoice-backend-temporaryInvoice-data-address-opener" data-open="0" > - <span class="fa fa-chevron-right"></span> Erweiterte Ansicht öffnen + <span class="fa fa-chevron-right"></span> {{textExtra}} </div> </td> </tr> diff --git a/bin/backend/controls/panels/TemporaryInvoice.UserData.js b/bin/backend/controls/panels/TemporaryInvoice.UserData.js index 0f12c0b3ce8371d190809a9af4a3e3eff07dd955..0f07354195c32f5b7337a4d6c404c86b86ad6ac8 100644 --- a/bin/backend/controls/panels/TemporaryInvoice.UserData.js +++ b/bin/backend/controls/panels/TemporaryInvoice.UserData.js @@ -1,7 +1,16 @@ /** * @module package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.UserData * - * + * @require qui/QUI + * @require qui/controls/Control + * @require qui/controls/buttons/Button + * @require controls/users/address/Display + * @require controls/users/search/Window + * @require Users + * @require Locale + * @require Ajax + * @require Mustache + * @require text!package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.UserData.html */ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.UserData', [ @@ -21,10 +30,12 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use Mustache, template) { "use strict"; + var lg = 'quiqqer/invoice'; + return new Class({ Extends: QUIControl, - Type: 'package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.UserData', + Type : 'package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.UserData', Binds: [ 'toggleExtras', @@ -32,7 +43,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use ], options: { - userId: false, + userId : false, addressId: false }, @@ -45,16 +56,16 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use this.$CustomerSelect = null; - this.$Extras = null; - this.$Company = null; - this.$Street = null; - this.$Zip = null; - this.$City = null; - this.$Table = null; - this.$AddressRow = null; + this.$Extras = null; + this.$Company = null; + this.$Street = null; + this.$Zip = null; + this.$City = null; + this.$Table = null; + this.$AddressRow = null; this.$AddressSelect = null; - this.$rows = []; + this.$rows = []; this.$extrasAreOpen = false; }, @@ -67,20 +78,29 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use var self = this; this.$Elm = new Element('div', { - html: Mustache.render(template) + html: Mustache.render(template, { + textTitle : QUILocale.get(lg, 'cutomerData'), + textCustomer: QUILocale.get(lg, 'customer'), + textAddress : QUILocale.get(lg, 'address'), + textCompany : QUILocale.get(lg, 'company'), + textStreet : QUILocale.get(lg, 'street'), + textZip : QUILocale.get(lg, 'zip'), + textCity : QUILocale.get(lg, 'city'), + textExtra : QUILocale.get(lg, 'invoice.temporary.extend.view.open') + }) }); this.$Extras = this.$Elm.getElement('.quiqqer-invoice-backend-temporaryInvoice-data-address-opener'); this.$Extras.addEvent('click', this.toggleExtras); this.$Company = this.$Elm.getElement('[name="company"]'); - this.$Street = this.$Elm.getElement('[name="street"]'); - this.$Zip = this.$Elm.getElement('[name="zip"]'); - this.$City = this.$Elm.getElement('[name="city"]'); + this.$Street = this.$Elm.getElement('[name="street"]'); + this.$Zip = this.$Elm.getElement('[name="zip"]'); + this.$City = this.$Elm.getElement('[name="city"]'); - this.$Table = this.$Elm.getElement('.invoice-data-customer'); - this.$rows = this.$Table.getElements('.closable'); - this.$AddressRow = this.$Table.getElement('.address-row'); + this.$Table = this.$Elm.getElement('.invoice-data-customer'); + this.$rows = this.$Table.getElements('.closable'); + this.$AddressRow = this.$Table.getElement('.address-row'); this.$AddressSelect = this.$Table.getElement('[name="address"]'); this.$AddressSelect.addEvent('change', function () { @@ -91,46 +111,95 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use }, /** - * Set the user id + * Return the data value * - * @param userId + * @returns {{userId: *, addressId: *}} */ - setUserId: function (userId) { + getValue: function () { + return { + userId : this.getAttribute('userId'), + addressId: this.getAttribute('addressId') + }; + }, + + /** + * Set the complete data values + * + * @param {String|Number} userId + * @param {String|Number} addressId + */ + setValue: function (userId, addressId) { this.setAttribute('userId', userId); + this.setAttribute('addressId', addressId); + return this.refresh(); + }, + + /** + * Refresh the display + */ + refresh: function () { if (!this.$Elm) { - return; + return Promise.resolve(); } - if (userId === '' || !userId) { + var userId = this.getAttribute('userId'); + + if (!userId || userId === '') { this.$Company.set('value', ''); this.$Street.set('value', ''); this.$Zip.set('value', ''); this.$City.set('value', ''); - return; - } - var User = Users.get(userId); + this.$AddressRow.setStyle('display', 'none'); - User.load().then(function (User) { + return Promise.resolve(); + } + + return this.$getUser().then(function (User) { return User.getAddressList(); + }).then(function (addresses) { + this.$AddressSelect.set('html', ''); + if (!addresses.length) { this.$AddressRow.setStyle('display', 'none'); return; } - // @todo rechnungsadresse auswählen + // @todo rechnungsadresse auswählen wenn keine value gesetzt ist + this.$AddressRow.setStyle('display', null); for (var i = 0, len = addresses.length; i < len; i++) { new Element('option', { value: addresses[i].id, - html: addresses[i].text + html : addresses[i].text }).inject(this.$AddressSelect); } - this.$AddressSelect.value = addresses[0].id; + var addressId = this.getAttribute('addressId'); + + this.$AddressSelect.value = addressId || addresses[0].id; + }.bind(this)); + }, + + /** + * Set the user id + * + * @param userId + * @return {Promise} + */ + setUserId: function (userId) { + this.setAttribute('userId', userId); + + if (!this.$Elm) { + return Promise.resolve(); + } + + this.fireEvent('change', [this]); + + return this.refresh().then(function () { this.$AddressSelect.fireEvent('change'); }.bind(this)); }, @@ -139,6 +208,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use * Set a address to the user data * * @param {String|Number} addressId + * @return {Promise} */ setAddressId: function (addressId) { var self = this; @@ -151,6 +221,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use self.$City.set('value', address.city); self.setAttribute('addressId', addressId); + self.fireEvent('change', [self]); resolve(address); }, { @@ -160,6 +231,27 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use }); }, + /** + * Return the loaded user object + * + * @returns {Promise} + */ + $getUser: function () { + var userId = this.getAttribute('userId'); + + if (!userId || userId === '') { + return Promise.reject(); + } + + var User = Users.get(userId); + + if (!User.isLoaded()) { + return Promise.resolve(User); + } + + return User.load(); + }, + /** * Events */ @@ -182,7 +274,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use }); if (this.getAttribute('userId')) { - this.$CustomerSelect.setValue(this.getAttribute('userId')); + this.$CustomerSelect.addItem(this.getAttribute('userId')); } }.bind(this)); }, @@ -214,8 +306,8 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use return new Promise(function (resolve) { self.$rows.setStyles({ - height: 0, - opacity: 0, + height : 0, + opacity : 0, overflow: 'hidden', position: 'relative' }); @@ -230,8 +322,8 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use duration: 250, callback: function () { self.$rows.setStyles({ - display: null, - height: null, + display : null, + height : null, overflow: null, position: null }); @@ -242,7 +334,8 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use duration: 250, callback: function () { self.$Extras.set({ - html: '<span class="fa fa-chevron-up"></span> Erweiterte Ansicht schließen' + html: '<span class="fa fa-chevron-up"></span> ' + + QUILocale.get(lg, 'invoice.temporary.extend.view.close') }); self.$extrasAreOpen = true; @@ -272,7 +365,8 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Use self.$extrasAreOpen = false; self.$Extras.set({ - html: '<span class="fa fa-chevron-right"></span> Erweiterte Ansicht öffnen' + html: '<span class="fa fa-chevron-right"></span> ' + + QUILocale.get(lg, 'invoice.temporary.extend.view.open') }); resolve(); diff --git a/bin/backend/controls/panels/TemporaryInvoice.js b/bin/backend/controls/panels/TemporaryInvoice.js index 579e8204ec067dccf9137ab90bc97419288f6ef4..e536bce702183bab95211878a3a181600113cef5 100644 --- a/bin/backend/controls/panels/TemporaryInvoice.js +++ b/bin/backend/controls/panels/TemporaryInvoice.js @@ -5,6 +5,17 @@ * * @require qui/QUI * @require qui/controls/desktop/Panel + * @require qui/controls/buttons/Button + * @require qui/controls/buttons/ButtonMultiple + * @require qui/controls/buttons/Seperator + * @require qui/controls/windows/Confirm + * @require controls/users/address/Select + * @require package/quiqqer/invoice/bin/Invoices + * @require Locale + * @require Mustache + * @require Users + * @require text!package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.Data.html', + * @require css!package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.css' */ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ @@ -32,9 +43,10 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ return new Class({ Extends: QUIPanel, - Type: 'package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', + Type : 'package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', Binds: [ + 'save', 'openData', 'openProducts', 'openVerification', @@ -48,7 +60,10 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ ], options: { - invoiceId: false + invoiceId : false, + data : {}, + customer_id: false, + address_id : false }, initialize: function (options) { @@ -63,8 +78,8 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ this.$AddSeparator = null; this.addEvents({ - onCreate: this.$onCreate, - onInject: this.$onInject, + onCreate : this.$onCreate, + onInject : this.$onInject, onDestroy: this.$onDestroy }); @@ -74,16 +89,22 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ }, /** - * Set the customer to the invoice + * Saves the current data * - * @param {String|Integer} userId - ID of the user + * @return {Promise} */ - setCustomer: function (userId) { - return new Promise(function (resolve) { - + save: function () { + this.Loader.show(); - resolve(); - }); + return Invoices.saveInvoice(this.getAttribute('invoiceId'), { + customer_id: this.getAttribute('customer_id'), + address_id : this.getAttribute('address_id') + }).then(function () { + this.Loader.hide(); + }.bind(this)).catch(function (err) { + console.error(err); + this.Loader.hide(); + }.bind(this)); }, /** @@ -109,64 +130,22 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ return QUI.parse(Container); }).then(function () { - var Container = self.getContent().getElement('.customer'); - - //require([ - // 'package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.UserSelect' - //], function (UserSelect) { - // new UserSelect({ - // userId: false, - // addressId: false - // }).inject(Container); - //}); - - // - //// customer setting - //var Customer = QUI.Controls.getById( - // Content.getElement('[name="customer"]').get('data-quiid') - //); - // - //// address fields - //var Company = Content.getElement('[name="company"]'), - // Street = Content.getElement('[name="street"]'), - // Zip = Content.getElement('[name="zip"]'), - // City = Content.getElement('[name="city"]'); - // - // - //Customer.addEvent('change', function (Control) { - // var userId = Control.getValue(); - // - // if (userId === '' || !userId) { - // Company.set('value', ''); - // Street.set('value', ''); - // Zip.set('value', ''); - // City.set('value', ''); - // return; - // } - // - // var User = Users.get(userId); - // - // User.load().then(function (User) { - // return User.getAddressList(); - // }).then(function (addresses) { - // if (!addresses.length) { - // return; - // } - // - // if (addresses.length == 1) { - // console.log(addresses[0]); - // - // Company.set('value', addresses[0].company); - // Street.set('value', addresses[0].street_no); - // Zip.set('value', addresses[0].zip); - // City.set('value', addresses[0].city); - // return; - // } - // - // // address Auswahl - // }); - //}); + var quiId = self.getContent().getElement( + '[data-qui="package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice.UserData"]' + ).get('data-quiid'); + + var Data = QUI.Controls.getById(quiId); + Data.addEvent('onChange', function () { + self.setAttribute('customer_id', Data.getValue().userId); + self.setAttribute('address_id', Data.getValue().addressId); + }); + + return Data.setValue( + self.getAttribute('customer_id'), + self.getAttribute('address_id') + ); + }).then(function () { self.Loader.hide(); return self.$openCategory(); }); @@ -192,6 +171,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ this.$AddProduct.show(); this.$AddSeparator.show(); this.Loader.hide(); + resolve(); }.bind(this)); }.bind(this)); @@ -263,17 +243,17 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ if (!Container) { Container = new Element('div', { 'class': 'container', - styles: { - opacity: 0, + styles : { + opacity : 0, position: 'relative', - top: -50 + top : -50 } }).inject(this.getContent()); } moofx(Container).animate({ opacity: 0, - top: -50 + top : -50 }, { duration: 200, callback: function () { @@ -308,7 +288,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ moofx(Container).animate({ opacity: 1, - top: 0 + top : 0 }, { duration: 200, callback: resolve @@ -328,8 +308,8 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ this.$AddProduct = new QUIButtonMultiple({ textimage: 'fa fa-plus', - text: 'Artikel hinzufügen', - events: { + text : 'Artikel hinzufügen', + events : { onClick: function () { if (self.$ProductList) { self.openProductSearch(); @@ -341,7 +321,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ this.$AddProduct.hide(); this.$AddProduct.appendChild({ - text: 'Freier Artikel', + text : 'Freier Artikel', events: { onClick: function () { if (self.$ProductList) { @@ -352,7 +332,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ }); this.$AddProduct.appendChild({ - text: 'Text', + text : 'Text', events: { onClick: function () { if (self.$ProductList) { @@ -366,11 +346,10 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ // buttons this.addButton({ - text: QUILocale.get('quiqqer/system', 'save'), + text : QUILocale.get('quiqqer/system', 'save'), textimage: 'fa fa-save', - events: { - onClick: function () { - } + events : { + onClick: this.save } }); @@ -378,7 +357,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ this.addButton(this.$AddProduct); this.addButton({ - icon: 'fa fa-trash', + icon : 'fa fa-trash', styles: { 'float': 'right' }, @@ -389,24 +368,24 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ // categories this.addCategory({ - icon: 'fa fa-info', - text: 'Rechnungsdaten', + icon : 'fa fa-info', + text : 'Rechnungsdaten', events: { onClick: this.openData } }); this.addCategory({ - icon: 'fa fa-list', - text: 'Positionen (Artikel)', + icon : 'fa fa-list', + text : 'Positionen (Artikel)', events: { onClick: this.openProducts } }); this.addCategory({ - icon: 'fa fa-check', - text: 'Überprüfung', + icon : 'fa fa-check', + text : 'Überprüfung', events: { onClick: this.openVerification } @@ -426,6 +405,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ Invoices.getTemporaryInvoice(this.getAttribute('invoiceId')).then(function (data) { this.setAttribute('title', data.id); + this.setAttributes(data); this.refresh(); this.getCategoryBar().firstChild().click(); @@ -457,21 +437,21 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ var self = this; new QUIConfirm({ - title: QUILocale.get(lg, 'dialog.ti.delete.title'), - text: QUILocale.get(lg, 'dialog.ti.delete.text'), + title : QUILocale.get(lg, 'dialog.ti.delete.title'), + text : QUILocale.get(lg, 'dialog.ti.delete.text'), information: QUILocale.get(lg, 'dialog.ti.delete.information', { id: this.getAttribute('invoiceId') }), - icon: 'fa fa-trash', - texticon: 'fa fa-trash', - maxHeight: 400, - maxWidth: 600, - autoclose: false, - ok_button: { - text: QUILocale.get('quiqqer/system', 'delete'), + icon : 'fa fa-trash', + texticon : 'fa fa-trash', + maxHeight : 400, + maxWidth : 600, + autoclose : false, + ok_button : { + text : QUILocale.get('quiqqer/system', 'delete'), textimage: 'fa fa-trash' }, - events: { + events : { onSubmit: function (Win) { Win.Loader.show(); diff --git a/bin/backend/controls/panels/TemporaryInvoices.js b/bin/backend/controls/panels/TemporaryInvoices.js index e9a1debc8b52a717ac7f2d5c8ce1990d3c0022dc..6bb24c81bebae12119cef5810579c604ee5d4ec6 100644 --- a/bin/backend/controls/panels/TemporaryInvoices.js +++ b/bin/backend/controls/panels/TemporaryInvoices.js @@ -1,6 +1,8 @@ /** * @module package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices * + * Zeigt alle Rechnungsentwürfe an + * * @require qui/QUI * @require qui/controls/desktop/Panel * @require qui/controls/windows/Confirm @@ -25,7 +27,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', return new Class({ Extends: QUIPanel, - Type: 'package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', + Type : 'package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', Binds: [ 'refresh', @@ -41,7 +43,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', initialize: function (options) { this.setAttributes({ - icon: 'fa fa-money', + icon : 'fa fa-money', title: QUILocale.get(lg, 'erp.panel.temporary.invoice.title') }); @@ -50,16 +52,16 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', this.$Grid = null; this.addEvents({ - onCreate: this.$onCreate, - onResize: this.$onResize, - onInject: this.$onInject, + onCreate : this.$onCreate, + onResize : this.$onResize, + onInject : this.$onInject, onDestroy: this.$onDestroy }); Invoices.addEvents({ onDeleteInvoice: this.$onInvoicesChange, onCreateInvoice: this.$onInvoicesChange, - onCopyInvoice: this.$onInvoicesChange + onCopyInvoice : this.$onInvoicesChange }); }, @@ -126,7 +128,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', // Buttons this.addButton({ - text: 'Summe anzeigen', + text : 'Summe anzeigen', textimage: 'fa fa-calculator' }); @@ -140,12 +142,12 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', ); this.$Grid = new Grid(Container, { - pagination: true, - buttons: [{ - name: 'create', - text: QUILocale.get(lg, 'temporary.btn.createInvoice'), + pagination : true, + buttons : [{ + name : 'create', + text : QUILocale.get(lg, 'temporary.btn.createInvoice'), textimage: 'fa fa-plus', - events: { + events : { onClick: function (Btn) { Btn.setAttribute('textimage', 'fa fa-spinner fa-spin'); @@ -155,148 +157,153 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', } } }, { - name: 'copy', - disabled: true, - text: QUILocale.get(lg, 'journal.btn.copyInvoice'), + name : 'copy', + disabled : true, + text : QUILocale.get(lg, 'journal.btn.copyInvoice'), textimage: 'fa fa-copy', - events: { + events : { onClick: this.$clickCopyInvoice } }, { - name: 'delete', - disabled: true, - text: QUILocale.get(lg, 'temporary.btn.deleteInvoice'), + name : 'delete', + disabled : true, + text : QUILocale.get(lg, 'temporary.btn.deleteInvoice'), textimage: 'fa fa-trash', - events: { + events : { onClick: this.$clickDeleteInvoice } }, { type: 'seperator' }, { - name: 'pdf', - disabled: true, - text: QUILocale.get(lg, 'journal.btn.pdf'), + name : 'pdf', + disabled : true, + text : QUILocale.get(lg, 'journal.btn.pdf'), textimage: 'fa fa-file-pdf-o', - events: { + events : { onClick: function () { } } }], columnModel: [{ - header: QUILocale.get(lg, 'journal.grid.invoiceNo'), + header : QUILocale.get(lg, 'journal.grid.invoiceNo'), dataIndex: 'id', - dataType: 'integer', - width: 100 + dataType : 'integer', + width : 100 }, { - header: QUILocale.get(lg, 'journal.grid.orderNo'), + header : QUILocale.get(lg, 'journal.grid.orderNo'), dataIndex: 'order_id', - dataType: 'integer', - width: 80 + dataType : 'integer', + width : 80 }, { - header: QUILocale.get(lg, 'journal.grid.customerNo'), + header : QUILocale.get(lg, 'journal.grid.customerNo'), dataIndex: 'customer_id', - dataType: 'integer', - width: 100 + dataType : 'integer', + width : 100 }, { - header: QUILocale.get('quiqqer/system', 'name'), + header : QUILocale.get('quiqqer/system', 'name'), dataIndex: 'customer_name', - dataType: 'string', - width: 130 + dataType : 'string', + width : 130 }, { - header: QUILocale.get('quiqqer/system', 'date'), + header : QUILocale.get('quiqqer/system', 'date'), dataIndex: 'date', - dataType: 'date', - width: 150 + dataType : 'date', + width : 150 }, { - header: QUILocale.get('quiqqer/system', 'username'), + header : QUILocale.get('quiqqer/system', 'c_user'), dataIndex: 'c_user', - dataType: 'integer', - width: 130 + dataType : 'integer', + width : 100 + }, { + header : QUILocale.get('quiqqer/system', 'c_user'), + dataIndex: 'c_username', + dataType : 'integer', + width : 130 }, { - header: QUILocale.get(lg, 'journal.grid.status'), + header : QUILocale.get(lg, 'journal.grid.status'), dataIndex: 'paidstatus', - dataType: 'string', - width: 120 + dataType : 'string', + width : 120 }, { - header: QUILocale.get(lg, 'journal.grid.netto'), + header : QUILocale.get(lg, 'journal.grid.netto'), dataIndex: 'display_nettosum', - dataType: 'currency', - width: 80 + dataType : 'currency', + width : 80 }, { - header: QUILocale.get(lg, 'journal.grid.vat'), + header : QUILocale.get(lg, 'journal.grid.vat'), dataIndex: 'display_vatsum', - dataType: 'currency', - width: 80 + dataType : 'currency', + width : 80 }, { - header: QUILocale.get(lg, 'journal.grid.sum'), + header : QUILocale.get(lg, 'journal.grid.sum'), dataIndex: 'display_sum', - dataType: 'currency', - width: 80 + dataType : 'currency', + width : 80 }, { - header: QUILocale.get(lg, 'journal.grid.paymentMethod'), + header : QUILocale.get(lg, 'journal.grid.paymentMethod'), dataIndex: 'payment_method', - dataType: 'string', - width: 120 + dataType : 'string', + width : 120 }, { - header: QUILocale.get(lg, 'journal.grid.paymentTerm'), + header : QUILocale.get(lg, 'journal.grid.paymentTerm'), dataIndex: 'payment_time', - dataType: 'string', - width: 120 + dataType : 'string', + width : 120 }, { - header: QUILocale.get(lg, 'journal.grid.paymentDate'), + header : QUILocale.get(lg, 'journal.grid.paymentDate'), dataIndex: 'paid_date', - dataType: 'date', - width: 120 + dataType : 'date', + width : 120 }, { - header: QUILocale.get(lg, 'journal.grid.paid'), + header : QUILocale.get(lg, 'journal.grid.paid'), dataIndex: 'display_paid', - dataType: 'currency', - width: 80 + dataType : 'currency', + width : 80 }, { - header: QUILocale.get(lg, 'journal.grid.open'), + header : QUILocale.get(lg, 'journal.grid.open'), dataIndex: 'display_missing', - dataType: 'currency', - width: 80 + dataType : 'currency', + width : 80 }, { - header: QUILocale.get(lg, 'journal.grid.brutto'), + header : QUILocale.get(lg, 'journal.grid.brutto'), dataIndex: 'isbrutto', - dataType: 'integer', - width: 50 + dataType : 'integer', + width : 50 }, { - header: QUILocale.get(lg, 'taxid'), + header : QUILocale.get(lg, 'taxid'), dataIndex: 'taxid', - dataType: 'string', - width: 120 + dataType : 'string', + width : 120 }, { - header: QUILocale.get(lg, 'journal.grid.orderDate'), + header : QUILocale.get(lg, 'journal.grid.orderDate'), dataIndex: 'order_id', - dataType: 'date', - width: 130 + dataType : 'date', + width : 130 // }, { // header: QUILocale.get(lg, 'journal.grid.dunning'), // dataIndex: 'dunning_level', // dataType: 'integer', // width: 80 }, { - header: QUILocale.get(lg, 'journal.grid.processing'), + header : QUILocale.get(lg, 'journal.grid.processing'), dataIndex: 'processing_status', - dataType: 'string', - width: 150 + dataType : 'string', + width : 150 }, { - header: QUILocale.get(lg, 'journal.grid.comments'), + header : QUILocale.get(lg, 'journal.grid.comments'), dataIndex: 'comments', - dataType: 'string', - width: 100 + dataType : 'string', + width : 100 }, { - header: QUILocale.get(lg, 'journal.grid.paymentData'), + header : QUILocale.get(lg, 'journal.grid.paymentData'), dataIndex: 'payment_data', - dataType: 'string', - width: 100 + dataType : 'string', + width : 100 }, { - header: QUILocale.get(lg, 'journal.grid.hash'), + header : QUILocale.get(lg, 'journal.grid.hash'), dataIndex: 'hash', - dataType: 'string', - width: 200 + dataType : 'string', + width : 200 }] }); @@ -363,7 +370,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', Invoices.removeEvents({ onDeleteInvoice: this.$onInvoicesChange, onCreateInvoice: this.$onInvoicesChange, - onCopyInvoice: this.$onInvoicesChange + onCopyInvoice : this.$onInvoicesChange }); }, @@ -389,21 +396,21 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', } new QUIConfirm({ - title: QUILocale.get(lg, 'dialog.ti.delete.title'), - text: QUILocale.get(lg, 'dialog.ti.delete.text'), + title : QUILocale.get(lg, 'dialog.ti.delete.title'), + text : QUILocale.get(lg, 'dialog.ti.delete.text'), information: QUILocale.get(lg, 'dialog.ti.delete.information', { id: selected[0].id }), - icon: 'fa fa-trash', - texticon: 'fa fa-trash', - maxHeight: 400, - maxWidth: 600, - autoclose: false, - ok_button: { - text: QUILocale.get('quiqqer/system', 'delete'), + icon : 'fa fa-trash', + texticon : 'fa fa-trash', + maxHeight : 400, + maxWidth : 600, + autoclose : false, + ok_button : { + text : QUILocale.get('quiqqer/system', 'delete'), textimage: 'fa fa-trash' }, - events: { + events : { onSubmit: function (Win) { Win.Loader.show(); @@ -421,7 +428,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', * Copy the temporary invoice and opens the invoice */ $clickCopyInvoice: function () { - var self = this, + var self = this, selected = this.$Grid.getSelectedData(); if (!selected.length) { @@ -429,21 +436,21 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoices', } new QUIConfirm({ - title: QUILocale.get(lg, 'dialog.ti.copy.title'), - text: QUILocale.get(lg, 'dialog.ti.copy.text'), + title : QUILocale.get(lg, 'dialog.ti.copy.title'), + text : QUILocale.get(lg, 'dialog.ti.copy.text'), information: QUILocale.get(lg, 'dialog.ti.copy.information', { id: selected[0].id }), - icon: 'fa fa-copy', - texticon: 'fa fa-copy', - maxHeight: 400, - maxWidth: 600, - autoclose: false, - ok_button: { - text: QUILocale.get('quiqqer/system', 'copy'), + icon : 'fa fa-copy', + texticon : 'fa fa-copy', + maxHeight : 400, + maxWidth : 600, + autoclose : false, + ok_button : { + text : QUILocale.get('quiqqer/system', 'copy'), textimage: 'fa fa-copy' }, - events: { + events : { onSubmit: function (Win) { Win.Loader.show(); diff --git a/composer.json b/composer.json index 702de2d2263d6def94f6a97b86a2cd15fb8aeaab..4a1122d17be7a841c81113cb80ff61eae700410c 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "require": { "php": ">=5.6", "quiqqer\/quiqqer": "1.*|dev-master|dev-dev", - "quiqqer\/erp": "1.*|dev-master|dev-dev" + "quiqqer\/erp": "1.*|dev-master|dev-dev", + "ramsey/uuid": "3.*" }, "autoload": { "psr-4": { diff --git a/database.xml b/database.xml index 5bcab3d3fef926aa18b299d6c116de7868cdafbe..40e2ae3df64db1a6bf7a40ab7a75bcfb8df39215 100644 --- a/database.xml +++ b/database.xml @@ -56,6 +56,7 @@ <table name="invoice_temporary"> <field type="INT NOT NULL">id</field> <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> diff --git a/locale.xml b/locale.xml index 4cd5751ebb020ccccc011e4098afccad2faa0fd9..66975648b740f6a0f6091e15cdfcf1204bced66c 100644 --- a/locale.xml +++ b/locale.xml @@ -71,6 +71,44 @@ <en><![CDATA[Total]]></en> </locale> + <locale name="cutomerData"> + <de><![CDATA[Kundendaten]]></de> + <en><![CDATA[Customer data]]></en> + </locale> + <locale name="customer"> + <de><![CDATA[Kunde]]></de> + <en><![CDATA[Customer]]></en> + </locale> + <locale name="address"> + <de><![CDATA[Adresse]]></de> + <en><![CDATA[Address]]></en> + </locale> + <locale name="company"> + <de><![CDATA[Firma]]></de> + <en><![CDATA[Company]]></en> + </locale> + <locale name="street"> + <de><![CDATA[Straße]]></de> + <en><![CDATA[Street]]></en> + </locale> + <locale name="zip"> + <de><![CDATA[PLZ]]></de> + <en><![CDATA[ZIP]]></en> + </locale> + <locale name="city"> + <de><![CDATA[Ort]]></de> + <en><![CDATA[City]]></en> + </locale> + + <locale name="invoice.temporary.extend.view.open"> + <de><![CDATA[Erweiterte Ansicht öffnen]]></de> + <en><![CDATA[Open the extended view]]></en> + </locale> + <locale name="invoice.temporary.extend.view.close"> + <de><![CDATA[Erweiterte Ansicht schließen]]></de> + <en><![CDATA[Close the extended view]]></en> + </locale> + </groups> <groups name="quiqqer/invoice" datatype="js"> @@ -247,4 +285,11 @@ </locale> </groups> + <groups name="quiqqer/invoice" datatype="php"> + <locale name="message.invoice.save.successfully"> + <de><![CDATA[Der Rechnungsentwurf wurde erfolgreich gespeichert.]]></de> + <en><![CDATA[The invoice was successfully saved.]]></en> + </locale> + </groups> + </locales> \ No newline at end of file diff --git a/src/QUI/ERP/Accounting/Invoice/Factory.php b/src/QUI/ERP/Accounting/Invoice/Factory.php index 06621d9887785ee22e361cc7f5c86f1f43195894..818043d71f5ab75caca63181df12338d2d251823 100644 --- a/src/QUI/ERP/Accounting/Invoice/Factory.php +++ b/src/QUI/ERP/Accounting/Invoice/Factory.php @@ -3,6 +3,7 @@ namespace QUI\ERP\Accounting\Invoice; use QUI; +use Ramsey\Uuid\Uuid; /** * Class Factory @@ -38,14 +39,17 @@ public function createInvoice() { $Handler = Handler::getInstance(); $Database = QUI::getDataBase(); + $Hash = Uuid::uuid1(); $Database->insert( $Handler->temporaryInvoiceTable(), - array() + array( + 'hash' => $Hash->toString() + ) ); $newId = $Database->getPDO()->lastInsertId(); return $Handler->getTemporaryInvoice($newId); } -} \ No newline at end of file +} diff --git a/src/QUI/ERP/Accounting/Invoice/Handler.php b/src/QUI/ERP/Accounting/Invoice/Handler.php index 4536406d745f70810a6d018869f9f4c3058c8103..29571ee043e391c882b8c17606aa05bf91590683 100644 --- a/src/QUI/ERP/Accounting/Invoice/Handler.php +++ b/src/QUI/ERP/Accounting/Invoice/Handler.php @@ -13,6 +13,11 @@ */ class Handler extends QUI\Utils\Singleton { + /** + * @var string + */ + const EMPTY_VALUE = '---'; + /** * @var string */ diff --git a/src/QUI/ERP/Accounting/Invoice/TemporaryInvoice.php b/src/QUI/ERP/Accounting/Invoice/TemporaryInvoice.php index f32ecd4a3cbd87395dd59332ce12e6eed5da67f4..160cb99cbbc813b38cd9c894135a6e65416606fa 100644 --- a/src/QUI/ERP/Accounting/Invoice/TemporaryInvoice.php +++ b/src/QUI/ERP/Accounting/Invoice/TemporaryInvoice.php @@ -98,9 +98,9 @@ public function save($User = null) QUI::getDataBase()->update( Handler::getInstance()->temporaryInvoiceTable(), array( - 'customer_id' => $this->getAttribute('customer_id'), - 'order_id' => $this->getAttribute('order_id'), - 'hash' => '', + 'customer_id' => (int)$this->getAttribute('customer_id'), + 'address_id' => (int)$this->getAttribute('address_id'), + 'order_id' => (int)$this->getAttribute('order_id') || '', 'payment_method' => $this->getAttribute('payment_method'), 'payment_data' => '', 'payment_time' => '', @@ -190,7 +190,7 @@ public function copy($User = null) * * @param QUI\Interfaces\Users\User|null $User * @return Invoice - * @throws Exception|QUI\Permissions\Exception + * @throws Exception|QUI\Permissions\Exception|QUI\Exception */ public function post($User = null) { @@ -198,7 +198,15 @@ public function post($User = null) // check all current data + // user and user-address check + $customerId = $this->getAttribute('customer_id'); + $addressId = $this->getAttribute('address_id'); + $Customer = QUI::getUsers()->get($customerId); + $Address = $Customer->getAddress($addressId); + + + // create invoice } /**