diff --git a/ajax/userData/getContactEmailAddress.php b/ajax/userData/getContactEmailAddress.php new file mode 100644 index 0000000000000000000000000000000000000000..959fb69b4cacdae9035390d18e4dc5541f928324 --- /dev/null +++ b/ajax/userData/getContactEmailAddress.php @@ -0,0 +1,27 @@ +<?php + +use QUI\ERP\Customer\Utils; + +/** + * Get contact email address. + * + * @param int $userId + * @return string + */ +QUI::$Ajax->registerFunction( + 'package_quiqqer_erp_ajax_userData_getContactEmailAddress', + function ($userId) { + try { + $email = Utils::getInstance()->getContactEmailByCustomer( + QUI::getUsers()->get((int)$userId) + ); + } catch (\Exception $Exception) { + QUI\System\Log::writeException($Exception); + return ''; + } + + return $email ?: ''; + }, + ['userId'], + 'Permission::checkAdminUser' +); diff --git a/ajax/userData/getUserEmailAddresses.php b/ajax/userData/getUserEmailAddresses.php new file mode 100644 index 0000000000000000000000000000000000000000..3c7e09ab5116df4137193790b517676659d35bb9 --- /dev/null +++ b/ajax/userData/getUserEmailAddresses.php @@ -0,0 +1,38 @@ +<?php + +use QUI\ERP\Customer\Utils; + +/** + * Get contact email address. + * + * @param int $userId + * @return string + */ +QUI::$Ajax->registerFunction( + 'package_quiqqer_erp_ajax_userData_getUserEmailAddresses', + function ($userId) { + $emailAddresses = []; + + try { + $User = QUI::getUsers()->get((int)$userId); + } catch (\Exception $Exception) { + QUI\System\Log::writeException($Exception); + return $emailAddresses; + } + + if (!empty($User->getAttribute('email'))) { + $emailAddresses[] = $User->getAttribute('email'); + } + + /** @var \QUI\Users\Address $Address */ + foreach ($User->getAddressList() as $Address) { + foreach ($Address->getMailList() as $email) { + $emailAddresses[] = $email; + } + } + + return \array_values(\array_unique($emailAddresses)); + }, + ['userId'], + 'Permission::checkAdminUser' +); diff --git a/bin/backend/controls/userData/ContactEmailSelectWindow.js b/bin/backend/controls/userData/ContactEmailSelectWindow.js new file mode 100644 index 0000000000000000000000000000000000000000..abcfdff8981fff15e622ad26cbede4dcf13c426f --- /dev/null +++ b/bin/backend/controls/userData/ContactEmailSelectWindow.js @@ -0,0 +1,103 @@ +/** + * Window for selecting user email addresses. + * + * @module package/quiqqer/erp/bin/backend/controls/userData/ContactEmailSelectWindow + * @author www.pcsg.de (Patrick Müller) + * + * @event onSubmit [selectedEmailAddress, this] + */ +define('package/quiqqer/erp/bin/backend/controls/userData/ContactEmailSelectWindow', [ + + 'qui/controls/windows/Confirm', + 'Locale', + 'Ajax' + +], function (QUIConfirm, QUILocale, QUIAjax) { + "use strict"; + + const pkg = 'quiqqer/erp'; + + return new Class({ + + Extends: QUIConfirm, + Type : 'package/quiqqer/erp/bin/backend/controls/userData/ContactEmailSelectWindow', + + Binds: [ + '$onOpen' + ], + + options: { + userId : false, + icon : 'fa fa-at', + title : QUILocale.get(pkg, 'ContactEmailSelectWindow.title'), + maxHeight: 300, + maxWidth : 550, + autoclose: false + }, + + initialize: function (options) { + this.parent(options); + + this.$Select = []; + + this.addEvents({ + onOpen: this.$onOpen + }); + }, + + $onOpen: function (Win) { + Win.Loader.show(); + + Win.getContent() + .set('html', QUILocale.get(pkg, 'ContactEmailSelectWindow.information')); + + this.$Select = new Element('select', { + styles: { + display: 'block', + clear : 'both', + margin : '1rem auto 0', + width : 500 + } + }).inject(Win.getContent()); + + this.$getUserEmailAddresses().then((emailAddresses) => { + emailAddresses.forEach((emailAddress) => { + new Element('option', { + value: emailAddress, + html : emailAddress + }).inject(this.$Select); + }); + + Win.Loader.hide(); + }); + }, + + /** + * Return the loaded user object + * + * @return {Promise<Array>} + */ + $getUserEmailAddresses: function () { + return new Promise((resolve, reject) => { + QUIAjax.get('package_quiqqer_erp_ajax_userData_getUserEmailAddresses', resolve, { + 'package': pkg, + userId : this.getAttribute('userId'), + onError : reject + }); + }); + }, + + /** + * Submit the window + * + * @method qui/controls/windows/Confirm#submit + */ + submit: function () { + this.fireEvent('submit', [this.$Select.value, this]); + + if (this.getAttribute('autoclose')) { + this.close(); + } + } + }); +}); diff --git a/bin/backend/controls/userData/UserData.css b/bin/backend/controls/userData/UserData.css new file mode 100644 index 0000000000000000000000000000000000000000..41f17791ad9ce492e78bfcb70c8331d29e462db8 --- /dev/null +++ b/bin/backend/controls/userData/UserData.css @@ -0,0 +1,26 @@ +.quiqqer-erp-userdata-address-userEdit { + background: #dedede; + border-radius: 5px 5px 0 0; + bottom: 0; + cursor: pointer; + display: none; + float: right; + left: 10px; + padding: 5px 10px; + position: absolute; +} + +.quiqqer-erp-userdata-address-opener { + background: #dedede; + border-radius: 5px 0 0 0; + bottom: 0; + cursor: pointer; + float: right; + padding: 5px 10px; + position: absolute; + right: 0; +} + +.quiqqer-erp-userdata-addressExtra { + height: 30px; +} \ No newline at end of file diff --git a/bin/backend/controls/userData/UserData.html b/bin/backend/controls/userData/UserData.html new file mode 100644 index 0000000000000000000000000000000000000000..82bc8e5141ee88651825b35da9decc0440cca103 --- /dev/null +++ b/bin/backend/controls/userData/UserData.html @@ -0,0 +1,140 @@ +<table class="data-table data-table-flexbox quiqqer-erp-userdata--customer"> + <thead> + <tr> + <th>{{labelTitle}}</th> + </tr> + </thead> + + <tbody> + <tr> + <td> + <label class="field-container"> + <span class="field-container-item" title="{{labelCustomer}}"> + {{labelCustomer}} + </span> + <span class="field-container-field field-container-field-no-padding"> + <input type="hidden" + name="customer" + data-qui="{{userSelectWindowControl}}" + data-qui-options-max="1" + data-qui-options-multiple="0" + /> + </span> + </label> + </td> + </tr> + <tr class="address-row" style="display: none;"> + <td> + <label class="field-container"> + <span class="field-container-item" title="{{labelAddress}}"> + {{labelAddress}} + </span> + <input type="text" class="field-container-field" name="address" disabled/> + <button name="select-address" + class="qui-button qui-utils-noselect" + style="width: 50px" + > + <span class="fa fa-address-book-o"></span> + </button> + </label> + </td> + </tr> + <tr class="quiqqer-erp-userdata-row-contactPerson"> + <td> + <label class="field-container"> + <span class="field-container-item" title="{{labelContactPerson}}"> + {{labelContactPerson}} + </span> + <input type="text" class="field-container-field" name="contact_person"/> + <button name="select-contact-id-address" + class="qui-button qui-utils-noselect" + style="width: 50px" + disabled + > + <span class="fa fa-address-book-o"></span> + </button> + </label> + </td> + </tr> + <tr> + <td> + <label class="field-container"> + <span class="field-container-item" title="{{labelContactEmail}}"> + {{labelContactEmail}} + </span> + <input type="email" class="field-container-field" name="contact_email"/> + <button name="select-contact-email" + class="qui-button qui-utils-noselect" + style="width: 50px" + disabled + > + <span class="fa fa-at"></span> + </button> + </label> + </td> + </tr> + <tr class="address-row" style="display: none;"> + <td> + <label class="field-container"> + <span class="field-container-item" title="{{labelContactAddress}}"> + {{labelContactAddress}} + </span> + <select class="field-container-field" name="address_contact"> + </select> + </label> + </td> + </tr> + <tr class="closable" style="display: none;"> + <td> + <label class="field-container"> + <span class="field-container-item" title="{{labelCompany}}"> + {{labelCompany}} + </span> + <input type="text" class="field-container-field" name="company" disabled/> + </label> + </td> + </tr> + <tr class="closable" style="display: none;"> + <td> + <label class="field-container"> + <span class="field-container-item" title="{{labelStreet}}"> + {{labelStreet}} + </span> + <input type="text" class="field-container-field" name="street_no" disabled/> + </label> + </td> + </tr> + <tr class="closable" style="display: none;"> + <td> + <label class="field-container"> + <span class="field-container-item" title="{{labelZip}}"> + {{labelZip}} + </span> + <input type="text" class="field-container-field" name="zip" disabled/> + </label> + </td> + </tr> + <tr class="closable" style="display: none;"> + <td> + <label class="field-container"> + <span class="field-container-item" title="{{labelCity}}"> + {{labelCity}} + </span> + <input type="text" class="field-container-field" name="city" disabled/> + </label> + </td> + </tr> + <tr> + <td class="quiqqer-erp-userdata-addressExtra"> + <div class="quiqqer-erp-userdata-address-userEdit"> + <span class="fa fa-edit"></span> {{labelUserEdit}} + </div> + <div class="quiqqer-erp-userdata-address-opener" + data-open="0" + > + <span class="fa fa-chevron-right"></span> {{labelExtra}} + </div> + </td> + </tr> + </tbody> +</table> diff --git a/bin/backend/controls/userData/UserData.js b/bin/backend/controls/userData/UserData.js new file mode 100644 index 0000000000000000000000000000000000000000..c40c4f69ee40c6b4fd98248020dfeb29bb14cd02 --- /dev/null +++ b/bin/backend/controls/userData/UserData.js @@ -0,0 +1,880 @@ +/** + * Control for selecting a user / address / contact data for ERP entities (e.g. invoice customer). + * + * @module package/quiqqer/erp/bin/backend/controls/userData/UserData + * @author www.pcsg.de (Henning Leutz) + * @author www.pcsg.de (Patrick Müller) + * + * @event onChange [userData, this] + */ +define('package/quiqqer/erp/bin/backend/controls/userData/UserData', [ + + 'qui/QUI', + 'qui/controls/Control', + + 'package/quiqqer/customer/bin/backend/controls/customer/address/Window', + 'package/quiqqer/erp/bin/backend/controls/userData/ContactEmailSelectWindow', + + 'Users', + 'Locale', + 'Ajax', + 'Mustache', + + 'text!package/quiqqer/erp/bin/backend/controls/userData/UserData.html', + 'css!package/quiqqer/erp/bin/backend/controls/userData/UserData.css' + +], function (QUI, QUIControl, AddressWindow, ContactEmailSelectWindow, Users, QUILocale, QUIAjax, Mustache, template) { + "use strict"; + + const pkg = 'quiqqer/erp'; + + const fields = [ + 'userId', + 'addressId', + 'contactPerson', + 'contactEmail', + + 'suffix', + 'firstname', + 'lastname', + 'name', + 'company', + 'street_no', + 'zip', + 'city', + 'country', + + 'isCommercial' + ]; + + return new Class({ + + Extends: QUIControl, + Type : 'package/quiqqer/erp/bin/backend/controls/userData/UserData', + + Binds: [ + 'toggleExtras', + 'editCustomer', + '$onInject', + '$fireChange' + ], + + options: { + userId : false, + addressId: false, + + editContactPerson: true, + editContactEmail : true, + + name : '', + contactPerson: '', + contactEmail : '', + company : false, + street_no : false, + zip : false, + city : false, + + labelUser : QUILocale.get(pkg, 'UserData.tpl.labelCustomer'), + userSelectWindowControl: 'package/quiqqer/customer/bin/backend/controls/customer/Select', + userPanelControl : 'package/quiqqer/customer/bin/backend/Handler' + }, + + initialize: function (options) { + this.parent(options); + + this.addEvents({ + onInject: this.$onInject + }); + + this.$CustomerSelect = null; + this.$ContactPerson = null; + this.$BtnContactPersonSelect = null; + + this.$ContactEmail = null; + this.$BtnContactEmailSelect = null; + this.$RowContactPerson = null; + + this.$Extras = null; + this.$Company = null; + this.$Street = null; + this.$Zip = null; + this.$City = null; + this.$Table = null; + this.$AddressRow = null; + this.$AddressField = null; + + this.$rows = []; + this.$extrasAreOpen = false; + this.$oldUserId = false; + + this.$loading = true; + this.$setValues = false; + + this.$Panel = null; + }, + + /** + * Create the DOMNoe Element + * @returns {*} + */ + create: function () { + const labelUser = this.getAttribute('labelUser'); + + this.$Elm = new Element('div', { + html: Mustache.render(template, { + labelTitle : labelUser, + labelCustomer : labelUser, + labelAddress : QUILocale.get('quiqqer/quiqqer', 'address'), + labelCompany : QUILocale.get('quiqqer/quiqqer', 'company'), + labelStreet : QUILocale.get('quiqqer/quiqqer', 'street'), + labelZip : QUILocale.get('quiqqer/quiqqer', 'zip'), + labelCity : QUILocale.get('quiqqer/quiqqer', 'city'), + labelExtra : QUILocale.get(pkg, 'UserData.btn.extra'), + labelUserEdit : QUILocale.get(pkg, 'UserData.btn.userEdit', {labelUser}), + labelContactPerson : QUILocale.get(pkg, 'UserData.tpl.labelContactPerson'), + labelContactEmail : QUILocale.get(pkg, 'UserData.tpl.labelContactEmail'), + userSelectWindowControl: this.getAttribute('userSelectWindowControl'), + }) + }); + + // Extras (show address fields) + this.$Extras = this.$Elm.getElement('.quiqqer-erp-userdata-address-opener'); + this.$Extras.addEvent('click', this.toggleExtras); + + // Customer edit (button that opens customer / user panel) + this.$CustomerEdit = this.$Elm.getElement('.quiqqer-erp-userdata-address-userEdit'); + this.$CustomerEdit.addEvent('click', this.editCustomer); + + // Contact person + this.$RowContactPerson = this.$Elm.getElement('.quiqqer-erp-userdata-row-contactPerson'); + this.$ContactPerson = this.$Elm.getElement('input[name="contact_person"]'); + this.$BtnContactPersonSelect = this.$Elm.getElement('button[name="select-contact-id-address"]'); + + this.$ContactPerson.addEvent('keyup', () => { + this.setAttribute('contactPerson', this.$ContactPerson.value); + this.$fireChange(); + }); + + this.$BtnContactPersonSelect.addEvent('click', () => { + new AddressWindow({ + autoclose: false, + userId : this.getAttribute('userId'), + events : { + onSubmit: (Win, addressId, address) => { + Win.close(); + + this.$setContactPersonByAddress(address); + this.$fireChange(); + } + } + }).open(); + }); + + // Contact email + this.$ContactEmail = this.$Elm.getElement('input[name="contact_email"]'); + + this.$BtnContactEmailSelect = this.$Elm.getElement('button[name="select-contact-email"]'); + this.$ContactEmail.addEvent('keyup', () => { + this.setAttribute('contactEmail', this.$ContactEmail.value); + this.$fireChange(); + }); + + this.$BtnContactEmailSelect.addEvent('click', () => { + new ContactEmailSelectWindow({ + autoclose: false, + userId : this.getAttribute('userId'), + events : { + onSubmit: (emailAddress, Win) => { + Win.close(); + this.$ContactEmail.value = emailAddress; + this.setAttribute('contactEmail', emailAddress); + + this.$fireChange(); + } + } + }).open(); + }); + + // Customer address + this.$Company = this.$Elm.getElement('[name="company"]'); + this.$Street = this.$Elm.getElement('[name="street_no"]'); + this.$Zip = this.$Elm.getElement('[name="zip"]'); + this.$City = this.$Elm.getElement('[name="city"]'); + + this.$Table = this.$Elm.getElement('.quiqqer-erp-userdata--customer'); + this.$rows = this.$Table.getElements('.closable'); + this.$AddressRow = this.$Table.getElement('.address-row'); + this.$AddressField = this.$Table.getElement('[name="address"]'); + this.$AddressDisplay = null; + this.$triggerChange = null; + + this.$AddressField.type = 'hidden'; + + this.$AddressDisplay = new Element('input', { + 'class' : 'field-container-field', + disabled: true + }).inject(this.$AddressField, 'after'); + + return this.$Elm; + }, + + /** + * Return the data value + * + * @return {Object} + */ + getValue: function () { + const result = {}; + + fields.forEach((field) => { + if (this.getAttribute(field)) { + result[field] = this.getAttribute(field); + } + }); + + return result; + }, + + /** + * Set the complete data values + * + * @param {Object} data + * @return {void} + */ + setValue: function (data) { + if (this.$CustomerEdit) { + this.$CustomerEdit.setStyle('display', 'inline'); + } + + let dataPromise = Promise.resolve(); + + if ('userId' in data) { + this.$setValues = true; + + if (this.$CustomerSelect) { + this.$CustomerSelect.addItem(data.userId); + } + + dataPromise = this.$setDataByUserId(data.userId); + } + + dataPromise.then(() => { + fields.forEach((field) => { + if (typeof data[field] !== 'undefined') { + this.setAttribute(field, data[field]); + } + }); + + this.$refreshValues(); + + this.$setValues = false; + }); + }, + + /** + * Refresh the displayed address values. + * + * @return {void} + */ + $refreshValues: function () { + const checkVal = function (val) { + return !(!val || val === '' || val === 'false'); + }; + + if (checkVal(this.getAttribute('company'))) { + this.$Company.value = this.getAttribute('company'); + } + + if (checkVal(this.getAttribute('street_no'))) { + this.$Street.value = this.getAttribute('street_no'); + } + + if (checkVal(this.getAttribute('zip'))) { + this.$Zip.value = this.getAttribute('zip'); + } + + if (checkVal(this.getAttribute('city'))) { + this.$City.value = this.getAttribute('city'); + } + + this.$AddressDisplay.value = this.$getAddressLabel(); + + if (this.getAttribute('isCommercial')) { + if (checkVal(this.getAttribute('contactPerson'))) { + this.$ContactPerson.value = this.getAttribute('contactPerson'); + } else if (checkVal(this.getAttribute('contact_person'))) { + this.$ContactPerson.value = this.getAttribute('contact_person'); + } + + this.$RowContactPerson.setStyle('display', null); + } else { + this.$RowContactPerson.setStyle('display', 'none'); + } + + if (checkVal(this.getAttribute('contactEmail'))) { + this.$ContactEmail.value = this.getAttribute('contactEmail'); + } else if (checkVal(this.getAttribute('contact_email'))) { + this.$ContactEmail.value = this.getAttribute('contact_email'); + } + }, + + /** + * Get address label. + * + * @param {Object} [address] - Build address label based on given address; if omitted, use attributes. + * @return {string} + */ + $getAddressLabel(address) { + const getVal = (key) => { + let val; + + if (address) { + val = key in address ? address.key : false; + } else { + val = this.getAttribute(key); + } + + if (!val || val === '' || val === 'false') { + return false; + } + + return val; + }; + + const addressLabelParts = []; + + const company = getVal('company'); + + if (company) { + addressLabelParts.push(company); + } + + const streetNo = getVal('street_no'); + + if (streetNo) { + addressLabelParts.push(streetNo); + } + + const zip = getVal('zip'); + + if (zip) { + addressLabelParts.push(zip); + } + + const city = getVal('city'); + + if (city) { + addressLabelParts.push(city); + } + + return addressLabelParts.join(', '); + }, + + /** + * Set address data via user id. + * + * @param userId + * @return {Promise} + */ + $setDataByUserId: function (userId) { + this.$oldUserId = this.getAttribute('userId'); + + this.$clearData(); + + this.setAttribute('userId', userId); + + if (this.$CustomerEdit) { + this.$CustomerEdit.setStyle('display', 'inline'); + } + + if (!this.$Elm) { + return Promise.resolve(); + } + + if (!userId || userId === '') { + return Promise.resolve(); + } + + this.$ContactPerson.disabled = true; + this.$BtnContactPersonSelect.disabled = true; + this.$BtnContactEmailSelect.disabled = true; + + return this.$getUser().then((User) => { + if (!User) { + return; + } + + this.setAttribute('isCommercial', User.getAttribute('quiqqer.erp.isNettoUser')); + + return this.getAddressList(User).then((addresses) => { + return [User, addresses]; + }); + }).then((result) => { + if (!result) { + return; + } + + const User = result[0]; + const addresses = result[1]; + + if (!addresses.length) { + this.$AddressRow.setStyle('display', 'none'); + return; + } + + const contactAddressId = parseInt(User.getAttribute('quiqqer.erp.customer.contact.person')); + + let defaultAddress = addresses[0]; + let contactAddress = false; + + addresses.forEach((address) => { + if (address.default) { + defaultAddress = address; + } + + if (address.id === contactAddressId) { + contactAddress = address; + } + }); + + // Set address data + this.$setDataByAddress(defaultAddress); + + // Set contact person data + if (contactAddress) { + this.$setContactPersonByAddress(contactAddress); + } + + return this.$getContactEmailAddress(userId); + }).then((contactEmailAddress) => { + if (contactEmailAddress && !this.$setValues) { + this.$ContactEmail.value = contactEmailAddress; + this.setAttribute('contactEmail', contactEmailAddress); + } + }).then(() => { + this.$ContactPerson.disabled = false; + this.$BtnContactPersonSelect.disabled = false; + this.$BtnContactEmailSelect.disabled = false; + }).then(() => { + this.$fireChange(); + }); + }, + + /** + * Sets data by specific address. + * + * @param {Object} address - Adress data + * @return {void} + */ + $setDataByAddress: function (address) { + this.setAttributes(address); + this.$AddressField.value = address.id; + + this.setAttribute('id', address.id); + this.setAttribute('addressId', address.id); + + this.$refreshValues(); + + this.$AddressRow.setStyle('display', null); + }, + + /** + * Clears all fields. + * + * @return {void} + */ + $clearData: function () { + this.$Company.set('value', ''); + this.$Street.set('value', ''); + this.$Zip.set('value', ''); + this.$City.set('value', ''); + + this.$AddressRow.setStyle('display', 'none'); + + this.$ContactPerson.value = ''; + this.$BtnContactPersonSelect.disabled = true; + + this.$ContactEmail.value = ''; + this.$BtnContactEmailSelect.disabled = true; + + fields.forEach((field) => { + this.setAttribute(field, null); + }); + }, + + /** + * Set a address to the user data + * + * @param {String|Number} addressId + * @return {Promise} + */ + setAddressId: function (addressId) { + var self = this; + + return new Promise(function (resolve) { + if (self.getAttribute('userId') === '') { + return Promise.resolve([]); + } + + QUIAjax.get('ajax_users_address_get', function (address) { + self.setAttributes(address); + self.$refreshValues(); + + if (!self.$setValues) { + self.$fireChange(); + } + + if (self.$CustomerEdit) { + self.$CustomerEdit.setStyle('display', 'inline'); + } + + resolve(address); + }, { + uid: self.getAttribute('userId'), + aid: addressId + }); + }); + }, + + /** + * Return the loaded user object. + * + * @returns {Promise} + */ + $getUser: function () { + const userId = this.getAttribute('userId'); + + if (!userId || userId === '') { + return Promise.reject(); + } + + const User = Users.get(userId); + + if (!User.isLoaded()) { + return Promise.resolve(User); + } + + return User.load(); + }, + + /** + * Get user address list. + * + * @param User + * @return {Promise} + */ + getAddressList: function (User) { + return new Promise((resolve, reject) => { + return User.getAddressList().then((result) => { + if (result.length) { + return resolve(result); + } + + // create new address + return this.openCreateAddressDialog(User).then(function () { + return User.getAddressList().then(resolve); + }).catch(reject); + }).catch(function () { + resolve([]); + }); + }); + }, + + /** + * Open the address window + * + * @return {Promise} + */ + openAddressWindow: function () { + var self = this; + + return new Promise(function (resolve, reject) { + new AddressWindow({ + userId: self.getAttribute('userId'), + events: { + onSubmit: function (Win, addressId) { + resolve(addressId); + Win.close(); + }, + onCancel: reject + } + }).open(); + }); + }, + + /** + * Events + */ + + /** + * event on import + */ + $onInject: function () { + const CustomerSelectElm = this.$Elm.getElement('[name="customer"]'); + + this.$Elm.getElement('button[name="select-address"]').addEvent('click', () => { + this.openAddressWindow().then((addressId) => { + return this.setAddressId(addressId); + }).catch(function () { + // nothing + }); + }); + + QUI.parse(this.$Elm).then(() => { + this.$CustomerSelect = QUI.Controls.getById( + CustomerSelectElm.get('data-quiid') + ); + + this.$CustomerSelect.addEvents({ + onChange: (Control) => { + if (this.$loading) { + this.$loading = false; + return; + } + + if (this.$setValues) { + return; + } + + this.$setDataByUserId(Control.getValue()); + }, + + onSearch: (Control, searchTerm) => { + if (searchTerm) { + this.setAttribute('name', searchTerm); + } else { + this.setAttribute('name', false); + } + + this.$fireChange(); + }, + + onRemoveItem: () => { + if (this.$CustomerEdit) { + this.$CustomerEdit.setStyle('display', 'none'); + } + + this.$BtnContactPersonSelect.disabled = true; + this.$ContactPerson.value = ''; + + this.$fireChange(); + } + }); + + if (this.getAttribute('userId')) { + this.$CustomerSelect.addItem(this.getAttribute('userId')); + } else { + this.$loading = false; + + if (this.getAttribute('name')) { + this.$CustomerSelect.$Search.value = this.getAttribute('name'); + } + } + + if (this.getElm().getParent('.qui-panel')) { + this.$Panel = QUI.Controls.getById( + this.getElm().getParent('.qui-panel').get('data-quiid') + ); + } + }); + }, + + /** + * fire the change event + */ + $fireChange: function () { + if (this.$triggerChange) { + clearTimeout(this.$triggerChange); + } + + this.$triggerChange = (function () { + this.fireEvent('change', [this.getValue(), this]); + }).delay(100, this); + }, + + /** + * Address creation + */ + + /** + * + * @param User + * @return {Promise} + */ + openCreateAddressDialog: function (User) { + return new Promise(function (resolve, reject) { + require([ + 'package/quiqqer/erp/bin/backend/controls/userData/customers/customer/address/Window' + ], function (Win) { + new Win({ + userId: User.getId(), + events: { + onSubmit: resolve, + onCancel: function () { + reject('No User selected'); + } + } + }).open(); + }); + }); + }, + + /** + * Extras + */ + + /** + * Toggle the extra view + * + * @returns {Promise} + */ + toggleExtras: function () { + if (this.$extrasAreOpen) { + return this.closeExtras(); + } + + return this.openExtras(); + }, + + /** + * Open the extra data + * + * @return {Promise} + */ + openExtras: function () { + var self = this; + + return new Promise(function (resolve) { + self.$rows.setStyles({ + height : 0, + opacity : 0, + overflow: 'hidden', + position: 'relative' + }); + + self.$rows.setStyle('display', 'block'); + + var height = self.$rows[0].getScrollSize().y; + + moofx(self.$rows).animate({ + height: height + }, { + duration: 250, + callback: function () { + self.$rows.setStyles({ + display : null, + height : null, + overflow: null, + position: null + }); + + moofx(self.$rows).animate({ + opacity: 1 + }, { + duration: 250, + callback: function () { + self.$Extras.set({ + html: '<span class="fa fa-chevron-up"></span> ' + + QUILocale.get(pkg, 'UserData.btn.extraClose') + }); + + self.$extrasAreOpen = true; + resolve(); + } + }); + } + }); + }); + }, + + /** + * Close the extra data + * + * @return {Promise} + */ + closeExtras: function () { + var self = this; + + return new Promise(function (resolve) { + moofx(self.$rows).animate({ + opacity: 0 + }, { + duration: 250, + callback: function () { + self.$rows.setStyle('display', 'none'); + self.$extrasAreOpen = false; + + self.$Extras.set({ + html: '<span class="fa fa-chevron-right"></span> ' + + QUILocale.get(pkg, 'UserData.btn.extra') + }); + + resolve(); + } + }); + }); + }, + + /** + * open the user edit panel for the customer + */ + editCustomer: function () { + var self = this; + + if (this.$Panel) { + this.$Panel.Loader.show(); + } + + require(['package/quiqqer/customer/bin/backend/Handler'], function (CustomerHandler) { + CustomerHandler.openCustomer(self.getAttribute('userId')).then(function () { + self.$Panel.Loader.hide(); + }); + }); + }, + + /** + * Set the contact person by an address data object to the contact person input field. + * + * @param {Object} address - Address data + * @return {void} + */ + $setContactPersonByAddress: function (address) { + if (typeof address.salutation === 'undefined' && + typeof address.firstname === 'undefined' && + typeof address.lastname === 'undefined') { + return; + } + + const parts = []; + + if (typeof address.salutation !== 'undefined') { + parts.push(address.salutation); + } + + if (typeof address.firstname !== 'undefined') { + parts.push(address.firstname); + } + + if (typeof address.lastname !== 'undefined') { + parts.push(address.lastname); + } + + this.$ContactPerson.value = parts.join(' ').trim(); + this.setAttribute('contactPerson', this.$ContactPerson.value); + }, + + /** + * @param {Number} userId + * @return {Promise<String>} + */ + $getContactEmailAddress: function (userId) { + return new Promise((resolve, reject) => { + QUIAjax.get('package_quiqqer_erp_ajax_userData_getContactEmailAddress', resolve, { + 'package': pkg, + userId : userId, + onError : reject + }); + }); + } + }); +}); diff --git a/locale.xml b/locale.xml index 5d0f1fac6500023246b4c9e0ebd7731750af89ca..ad1301a14dbb82d87744c1312260d1f04c5c02d5 100644 --- a/locale.xml +++ b/locale.xml @@ -263,7 +263,7 @@ <de><![CDATA[E-COYN]]></de> <en><![CDATA[E-COYN]]></en> </locale> - + <locale name="menu.erp.category.bankAccounts.title"> <de><![CDATA[Bankverbindungen]]></de> <en><![CDATA[Bank accounts]]></en> @@ -276,6 +276,10 @@ <groups name="quiqqer/erp" datatype="php"> + <locale name="bankAccounts.patch.bankAccount_created"> + <de><![CDATA[Es wurde automatisch ein Standard-Bankkonto auf Basis der Firmen-Bankdaten in der ecoyn-Konfiguration angelegt.]]></de> + <en><![CDATA[A default bank account was automatically created based on the company bank data in the ecoyn configuration.]]></en> + </locale> <locale name="manufacturers.default_group_name"> <de><![CDATA[Hersteller]]></de> <en><![CDATA[Manufacturers]]></en> @@ -673,6 +677,39 @@ <groups name="quiqqer/erp" datatype="js"> + <locale name="ContactEmailSelectWindow.title"> + <de><![CDATA[Kontat E-Mail-Adresse auswählen]]></de> + <en><![CDATA[Choose contact email address]]></en> + </locale> + <locale name="ContactEmailSelectWindow.information"> + <de><![CDATA[Bitte wähle eine E-Mail-Adresse aus.]]></de> + <en><![CDATA[Please choose an email address.]]></en> + </locale> + <locale name="UserData.tpl.labelCustomer"> + <de><![CDATA[Kunde]]></de> + <en><![CDATA[Customer]]></en> + </locale> + <locale name="UserData.tpl.labelContactPerson"> + <de><![CDATA[Ansprechpartner]]></de> + <en><![CDATA[Contact person]]></en> + </locale> + <locale name="UserData.tpl.labelContactEmail"> + <de><![CDATA[Kontakt E-Mail-Adresse]]></de> + <en><![CDATA[Contact email address]]></en> + </locale> + <locale name="UserData.btn.extra"> + <de><![CDATA[Erweiterte Ansicht öffnen]]></de> + <en><![CDATA[Open extended view]]></en> + </locale> + <locale name="UserData.btn.extraClose"> + <de><![CDATA[Erweiterte Ansicht schließen]]></de> + <en><![CDATA[Close extended view]]></en> + </locale> + <locale name="UserData.btn.userEdit"> + <de><![CDATA[[labelUser] öffnen]]></de> + <en><![CDATA[Open [labelUser]]]]></en> + </locale> + <locale name="controls.BankAccounts.btn.create"> <de><![CDATA[Neue Bankverbindung]]></de> <en><![CDATA[New bank account]]></en> @@ -714,7 +751,8 @@ <en><![CDATA[Default bank account]]></en> </locale> <locale name="controls.BankAccounts.Entry.tpl.descDefault"> - <de><![CDATA[Die Standard-Bankverbindung wird automatisch ausgewählt, wenn keine andere Bankverbindung gesetzt ist. Es kann genau eine Verbindung als Standard-Bankverbindung gesetzt werden.]]></de> + <de> + <![CDATA[Die Standard-Bankverbindung wird automatisch ausgewählt, wenn keine andere Bankverbindung gesetzt ist. Es kann genau eine Verbindung als Standard-Bankverbindung gesetzt werden.]]></de> <en><![CDATA[The default bank account is automatically selected if no other bank connection is set. Only one account can be set as the default bank account.]]></en> </locale> <locale name="controls.BankAccounts.Entry.tpl.titleEdit"> diff --git a/src/QUI/ERP/Address.html b/src/QUI/ERP/Address.html index faf9a636b15bc2ced9977f92a5c0a9b737dafb64..1ce39b4bceddab7ff7ff556d278cc5028b748feb 100644 --- a/src/QUI/ERP/Address.html +++ b/src/QUI/ERP/Address.html @@ -1,10 +1,12 @@ <address class="vcard"> <div class="adr"> - {if $Address->getAttribute('company')} + {if $isCompany} + {if $Address->getAttribute('company')} <div class="company"> {$Address->getAttribute('company')} </div> + {/if} {if !empty($suffix)} <div class="suffix">