Skip to content
Code-Schnipsel Gruppen Projekte
Commit 23b3bed2 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

Merge branch 'next' into 'master'

feat: own template for articles at the article list

Closes brassberg/ecoyn/tickets#120

See merge request !82
Übergeordnete 6ba5914d 1483429b
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
2 Merge Requests!140Update 'next-4.x' with latest changes from 'main',!82feat: own template for articles at the article list
Pipeline-Nr. 6892 bestanden
werden angezeigt mit 1139 Ergänzungen und 131 Löschungen
<?php
/**
* This file contains package_quiqqer_products_ajax_products_calcNettoPrice
*/
use QUI\ERP\Processes;
/**
* Return the entity files
*
* @param string $hash - Entity hash
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_customerFiles_addFile',
function ($hash, $fileHash) {
$Entity = (new Processes())->getEntity($hash);
$Entity->addCustomerFile($fileHash);
},
['hash', 'fileHash']
);
<?php
/**
* This file contains package_quiqqer_products_ajax_products_calcNettoPrice
*/
use QUI\ERP\Processes;
/**
* add multiple files to the customer files of the entity
*
* @param string $hash - Entity hash
* @param string $fileHashes - json array
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_customerFiles_addFiles',
function ($hash, $fileHashes) {
$Entity = (new Processes())->getEntity($hash);
$fileHashes = json_decode($fileHashes, true) ?? [];
foreach ($fileHashes as $fileHash) {
$Entity->addCustomerFile($fileHash);
}
},
['hash', 'fileHashes']
);
<?php
/**
* This file contains package_quiqqer_products_ajax_products_calcNettoPrice
*/
use QUI\ERP\Processes;
/**
* Return the entity files
*
* @param string $hash - Entity hash
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_customerFiles_getCustomer',
function ($hash) {
$Entity = (new Processes())->getEntity($hash);
return $Entity->getCustomer()->getUniqueId();
},
['hash']
);
<?php
/**
* This file contains package_quiqqer_products_ajax_products_calcNettoPrice
*/
use QUI\ERP\Processes;
/**
* Return the entity files
*
* @param string $hash - Entity hash
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_customerFiles_getFiles',
function ($hash) {
$Entity = (new Processes())->getEntity($hash);
return $Entity->getCustomerFiles(true);
},
['hash']
);
<?php
/**
* This file contains package_quiqqer_products_ajax_products_calcNettoPrice
*/
use QUI\ERP\Processes;
/**
* Return the entity files
*
* @param string $hash - Entity hash
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_customerFiles_update',
function ($hash, $files) {
$files = json_decode($files, true);
$Entity = (new Processes())->getEntity($hash);
$Entity->setCustomFiles($files);
},
['hash', 'files']
);
<?php
/**
* This file contains package_quiqqer_erp_ajax_getEntityTitle
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_getEntityTitle',
function ($uuid) {
$Instance = (new QUI\ERP\Processes())->getEntity($uuid);
$class = get_class($Instance);
return QUI::getLocale()->get('quiqqer/erp', 'entity.title.' . $class);
},
['uuid'],
'Permission::checkAdminUser'
);
<?php
/**
* This file contains package_quiqqer_erp_ajax_getEntityType
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_getEntityType',
function ($uuid) {
$Instance = (new QUI\ERP\Processes())->getEntity($uuid);
return get_class($Instance);
},
['uuid'],
'Permission::checkAdminUser'
);
<?php
/**
* Returns delivery address of the user
*
* @param int $userId
* @return array
*/
use QUI\Users\Address;
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_userData_getDeliveryAddress',
function ($userId) {
try {
$User = QUI::getUsers()->get($userId);
$address = $User->getAttribute('quiqqer.delivery.address');
$Address = $User->getAddress($address);
return $Address->getAttributes();
} catch (QUI\Exception) {
return false;
}
},
['userId'],
'Permission::checkAdminUser'
);
...@@ -17,21 +17,22 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -17,21 +17,22 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
'package/quiqqer/countries/bin/Countries', 'package/quiqqer/countries/bin/Countries',
'Users', 'Users',
'Ajax',
'Locale', 'Locale',
'Mustache', 'Mustache',
'text!package/quiqqer/erp/bin/backend/controls/DeliveryAddress.html', 'text!package/quiqqer/erp/bin/backend/controls/DeliveryAddress.html',
'css!package/quiqqer/erp/bin/backend/controls/DeliveryAddress.css' 'css!package/quiqqer/erp/bin/backend/controls/DeliveryAddress.css'
], function (QUI, QUIControl, QUIButton, Countries, Users, QUILocale, Mustache, template) { ], function(QUI, QUIControl, QUIButton, Countries, Users, QUIAjax, QUILocale, Mustache, template) {
"use strict"; 'use strict';
const lg = 'quiqqer/erp'; const lg = 'quiqqer/erp';
return new Class({ return new Class({
Extends: QUIControl, Extends: QUIControl,
Type : 'package/quiqqer/erp/bin/backend/controls/DeliveryAddress', Type: 'package/quiqqer/erp/bin/backend/controls/DeliveryAddress',
Binds: [ Binds: [
'$onImport', '$onImport',
...@@ -43,7 +44,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -43,7 +44,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
'reset' 'reset'
], ],
initialize: function (options) { initialize: function(options) {
this.parent(options); this.parent(options);
this.$Addresses = null; this.$Addresses = null;
...@@ -63,8 +64,8 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -63,8 +64,8 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
this.$AddressSelectBtn = null; this.$AddressSelectBtn = null;
this.addEvents({ this.addEvents({
onImport : this.$onImport, onImport: this.$onImport,
onInject : this.$onInject, onInject: this.$onInject,
onSetAttribute: this.$onSetAttribute onSetAttribute: this.$onSetAttribute
}); });
}, },
...@@ -72,30 +73,33 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -72,30 +73,33 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
/** /**
* event: on import * event: on import
*/ */
$onImport: function () { $onImport: function() {
const self = this, const self = this,
Elm = this.getElm(); Elm = this.getElm();
Elm.set('html', Mustache.render(template, { Elm.set('html', Mustache.render(template, {
labelDifferentDeliveryAddress: QUILocale.get(lg, 'control.DeliveryAddress.tpl.labelDifferentDeliveryAddress'), labelDifferentDeliveryAddress: QUILocale.get(
textAddresses : QUILocale.get('quiqqer/quiqqer', 'address'), lg,
textCompany : QUILocale.get('quiqqer/quiqqer', 'company'), 'control.DeliveryAddress.tpl.labelDifferentDeliveryAddress'
textStreet : QUILocale.get('quiqqer/quiqqer', 'street_no'), ),
textZip : QUILocale.get('quiqqer/quiqqer', 'zip'), textAddresses: QUILocale.get('quiqqer/quiqqer', 'address'),
textCity : QUILocale.get('quiqqer/quiqqer', 'city'), textCompany: QUILocale.get('quiqqer/quiqqer', 'company'),
textCountry : QUILocale.get('quiqqer/quiqqer', 'country'), textStreet: QUILocale.get('quiqqer/quiqqer', 'street_no'),
textSalutation : QUILocale.get('quiqqer/quiqqer', 'salutation'), textZip: QUILocale.get('quiqqer/quiqqer', 'zip'),
textFirstname : QUILocale.get('quiqqer/quiqqer', 'firstname'), textCity: QUILocale.get('quiqqer/quiqqer', 'city'),
textLastname : QUILocale.get('quiqqer/quiqqer', 'lastname') textCountry: QUILocale.get('quiqqer/quiqqer', 'country'),
textSalutation: QUILocale.get('quiqqer/quiqqer', 'salutation'),
textFirstname: QUILocale.get('quiqqer/quiqqer', 'firstname'),
textLastname: QUILocale.get('quiqqer/quiqqer', 'lastname')
})); }));
// Address select // Address select
this.$AddressSelectBtn = new QUIButton({ this.$AddressSelectBtn = new QUIButton({
'class' : 'quiqqer-erp-delivery-address-select-btn', 'class': 'quiqqer-erp-delivery-address-select-btn',
text : QUILocale.get(lg, 'controls.DeliveryAddress.btn.select.text'), text: QUILocale.get(lg, 'controls.DeliveryAddress.btn.select.text'),
textimage: 'fa fa-address-book-o', textimage: 'fa fa-address-book-o',
disabled : true, disabled: true,
events : { events: {
onClick: this.$onClickSelectAddress onClick: this.$onClickSelectAddress
} }
}).inject( }).inject(
...@@ -131,18 +135,54 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -131,18 +135,54 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
this.getElm().getParent('.qui-panel').get('data-quiid') this.getElm().getParent('.qui-panel').get('data-quiid')
); );
this.$Customer = QUI.Controls.getById( const CustomerNode = Panel.getElm().getElement('[name="customer"]');
Panel.getElm().getElement('[name="customer"]').get('data-quiid')
); if (CustomerNode) {
let loadCustomer = Promise.resolve();
if (CustomerNode.get('data-quiid')) {
this.$Customer = QUI.Controls.getById(CustomerNode.get('data-quiid'));
} else {
loadCustomer = new Promise((resolve) => {
CustomerNode.addEvent('load', () => {
this.$Customer = QUI.Controls.getById(CustomerNode.get('data-quiid'));
resolve();
});
});
}
loadCustomer.then(() => {
if (!this.$Customer) {
return;
}
this.$userId = this.$Customer.getValue();
if (this.$Customer) { this.$Customer.addEvent('onChange', () => {
this.$userId = this.$Customer.getValue(); this.$userId = this.$Customer.getValue();
this.$getDeliveryAddressFromUser().then((result) => {
if (!result) {
this.$Checked.checked = false;
this.$checkBoxChange();
return;
}
//this.$Checked.checked = true;
this.setValue(result);
}).catch((err) => {
console.error(err);
this.$Checked.checked = false;
this.$checkBoxChange();
});
});
});
} }
Countries.getCountries().then(function (result) { Countries.getCountries().then(function(result) {
new Element('option', { new Element('option', {
value: '', value: '',
html : '' html: ''
}).inject(self.$Country); }).inject(self.$Country);
for (let code in result) { for (let code in result) {
...@@ -152,7 +192,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -152,7 +192,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
new Element('option', { new Element('option', {
value: code, value: code,
html : result[code] html: result[code]
}).inject(self.$Country); }).inject(self.$Country);
} }
...@@ -167,16 +207,25 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -167,16 +207,25 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
}); });
}, },
$onInject: function () { $onInject: function() {
this.$onImport(); this.$onImport();
}, },
$getDeliveryAddressFromUser: function() {
return new Promise((resolve) => {
QUIAjax.get('package_quiqqer_erp_ajax_userData_getDeliveryAddress', resolve, {
'package': 'quiqqer/erp',
userId: this.$userId
});
});
},
/** /**
* Return the current value * Return the current value
* *
* @return {{zip, uid: *, country, firstname, city, street_no, company, id: (boolean|*), salutation, lastname}|null} * @return {{zip, uid: *, country, firstname, city, street_no, company, id: (boolean|*), salutation, lastname}|null}
*/ */
getValue: function () { getValue: function() {
if (!this.$Checked.checked) { if (!this.$Checked.checked) {
return null; return null;
} }
...@@ -184,37 +233,37 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -184,37 +233,37 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
return { return {
//uid : this.$userId, //uid : this.$userId,
//id : this.$addressId, //id : this.$addressId,
company : this.$Company.value, company: this.$Company.value,
salutation: this.$Salutation.value, salutation: this.$Salutation.value,
firstname : this.$Firstname.value, firstname: this.$Firstname.value,
lastname : this.$Lastname.value, lastname: this.$Lastname.value,
street_no : this.$Street.value, street_no: this.$Street.value,
zip : this.$ZIP.value, zip: this.$ZIP.value,
city : this.$City.value, city: this.$City.value,
country : this.$Country.value country: this.$Country.value
}; };
}, },
/** /**
* Clears the selection - no address are selected * Clears the selection - no address are selected
*/ */
clear: function () { clear: function() {
this.$displayAddressData({ this.$displayAddressData({
company : '', company: '',
street_no : '', street_no: '',
zip : '', zip: '',
city : '', city: '',
country : '', country: '',
salutation: '', salutation: '',
firstname : '', firstname: '',
lastname : '', lastname: ''
}); });
}, },
/** /**
* Reset control * Reset control
*/ */
reset: function () { reset: function() {
this.clear(); this.clear();
this.$Checked.checked = false; this.$Checked.checked = false;
this.$checkBoxChange(); this.$checkBoxChange();
...@@ -225,31 +274,31 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -225,31 +274,31 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
* *
* @param {Object} value * @param {Object} value
*/ */
setValue: function (value) { setValue: function(value) {
if (typeOf(value) !== 'object') { if (typeOf(value) !== 'object') {
return; return;
} }
// Set address from address id OR custom input // Set address from address id OR custom input
if ("id" in value && value.id) { if ('id' in value && value.id) {
this.$addressId = value.id; this.$addressId = value.id;
} else { } else {
this.$addressId = false; this.$addressId = false;
} }
if ("uid" in value) { if ('uid' in value) {
this.$userId = value.uid; this.$userId = value.uid;
} }
const Address = { const Address = {
company : '', company: '',
street_no : '', street_no: '',
zip : '', zip: '',
city : '', city: '',
country : '', country: '',
salutation: '', salutation: '',
firstname : '', firstname: '',
lastname : '', lastname: ''
}; };
Object.merge(Address, value); Object.merge(Address, value);
...@@ -264,7 +313,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -264,7 +313,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
* *
* @return {Promise} * @return {Promise}
*/ */
getUser: function () { getUser: function() {
if (!this.$userId) { if (!this.$userId) {
return Promise.reject('No User-ID'); return Promise.reject('No User-ID');
} }
...@@ -283,7 +332,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -283,7 +332,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
* *
* @package {Object} Address * @package {Object} Address
*/ */
$displayAddressData: function (Address) { $displayAddressData: function(Address) {
this.$Company.value = Address.company; this.$Company.value = Address.company;
this.$Street.value = Address.street_no; this.$Street.value = Address.street_no;
this.$ZIP.value = Address.zip; this.$ZIP.value = Address.zip;
...@@ -303,7 +352,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -303,7 +352,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
* @param {String} key * @param {String} key
* @param {String} value * @param {String} value
*/ */
$onSetAttribute: function (key, value) { $onSetAttribute: function(key, value) {
if (key === 'userId') { if (key === 'userId') {
this.$userId = value; this.$userId = value;
...@@ -316,14 +365,14 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -316,14 +365,14 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
}, },
/** /**
* event if the check box changes * event if the checkbox changes
* *
* @param {DocumentEvent} [event] * @param {DocumentEvent} [event]
*/ */
$checkBoxChange: function (event) { $checkBoxChange: function(event) {
const self = this, const self = this,
Checkbox = this.getElm().getElement('[name="differentDeliveryAddress"]'), Checkbox = this.getElm().getElement('[name="differentDeliveryAddress"]'),
closables = this.getElm().getElements('.closable'); closables = this.getElm().getElements('.closable');
if (event) { if (event) {
event.stop(); event.stop();
...@@ -350,7 +399,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -350,7 +399,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
if (!this.$userId) { if (!this.$userId) {
Checkbox.checked = false; Checkbox.checked = false;
QUI.getMessageHandler().then(function (MH) { QUI.getMessageHandler().then(function(MH) {
MH.addInformation( MH.addInformation(
QUILocale.get('quiqqer/erp', 'controls.DeliveryAddress.msg.select_customer'), QUILocale.get('quiqqer/erp', 'controls.DeliveryAddress.msg.select_customer'),
self.$Customer.getElm() self.$Customer.getElm()
...@@ -358,7 +407,6 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -358,7 +407,6 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
}); });
this.$AddressSelectBtn.disable(); this.$AddressSelectBtn.disable();
return; return;
} }
...@@ -380,14 +428,14 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -380,14 +428,14 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
* *
* @return {boolean} * @return {boolean}
*/ */
isLoaded: function () { isLoaded: function() {
return this.$loaded; return this.$loaded;
}, },
/** /**
* Select customer address to pre-fill address fields * Select customer address to pre-fill address fields
*/ */
$onClickSelectAddress: function () { $onClickSelectAddress: function() {
const self = this; const self = this;
if (!this.$userId) { if (!this.$userId) {
...@@ -396,18 +444,18 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -396,18 +444,18 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
require([ require([
'package/quiqqer/customer/bin/backend/controls/customer/address/Window' 'package/quiqqer/customer/bin/backend/controls/customer/address/Window'
], function (Win) { ], function(Win) {
new Win({ new Win({
userId : self.$userId, userId: self.$userId,
autoclose: false, autoclose: false,
events: { events: {
onSubmit: function (Win, addressId) { onSubmit: function(Win, addressId) {
Win.Loader.show(); Win.Loader.show();
self.getUser().then(function (User) { self.getUser().then(function(User) {
return User.getAddressList(); return User.getAddressList();
}).then(function (addresses) { }).then(function(addresses) {
for (let i = 0, len = addresses.length; i < len; i++) { for (let i = 0, len = addresses.length; i < len; i++) {
if (addresses[i].id === addressId) { if (addresses[i].id === addressId) {
self.$displayAddressData(addresses[i]); self.$displayAddressData(addresses[i]);
...@@ -416,7 +464,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [ ...@@ -416,7 +464,7 @@ define('package/quiqqer/erp/bin/backend/controls/DeliveryAddress', [
} }
Win.close(); Win.close();
}).catch(function () { }).catch(function() {
Win.Loader.hide(); Win.Loader.hide();
}); });
......
.drag-drop-dropper {
background: rgba(0, 0, 0, 0.5);
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
z-index: 10000;
}
define('package/quiqqer/erp/bin/backend/controls/customerFiles/Grid', [
'qui/QUI',
'qui/controls/Control',
'classes/request/Upload',
'package/quiqqer/erp/bin/backend/utils/ERPEntities',
'controls/grid/Grid',
'Ajax',
'Locale',
'css!package/quiqqer/erp/bin/backend/controls/customerFiles/Grid.css'
], function(QUI, QUIControl, Upload, ERPEntityUtils, Grid, QUIAjax, QUILocale) {
'use strict';
const lg = 'quiqqer/erp';
let entityTitle = '';
return new Class({
Extends: QUIControl,
Type: 'package/quiqqer/erp/bin/backend/controls/customerFiles/Grid',
Binds: [
'openCustomerFiles',
'removeSelectedFiles',
'$onInject'
],
options: {
hash: false,
customerId: false
},
initialize: function(options) {
this.parent(options);
this.$DropInfo = new Element('div');
this.addEvents({
onInject: this.$onInject
});
},
$onInject: function() {
this.getElm().set('data-qui', this.getType());
this.getElm().setStyles({
height: '100%',
width: '100%'
});
// drag drop
this.$DropInfo = new Element('div.drag-drop-dropper').inject(this.getElm());
this.$DropInfo.setStyle('display', 'none');
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
this.getElm().addEventListener(eventName, (e) => {
e.preventDefault();
e.stopPropagation();
}, false);
});
['dragenter', 'dragover'].forEach(eventName => {
this.getElm().addEventListener(eventName, () => {
this.$DropInfo.setStyle('display', null);
}, false);
});
['dragleave', 'drop'].forEach(eventName => {
this.getElm().addEventListener(eventName, (e) => {
if (!e.relatedTarget || e.relatedTarget.parentNode !== this.getElm()) {
this.$DropInfo.setStyle('display', 'none');
}
}, false);
});
this.getElm().addEventListener('drop', (e) => {
const dt = e.dataTransfer;
const files = Array.from(dt.files);
this.$Grid.showLoader();
require(['classes/request/BulkUpload'], (BulkUpload) => {
new BulkUpload({
phpOnFinish: 'package_quiqqer_customer_ajax_backend_files_upload',
params: {
hash: this.getAttribute('hash'),
customerId: this.getAttribute('customerId')
},
events: {
onFinish: (Instance, uploadedFiles) => {
this.addFiles(uploadedFiles).then(() => {
this.refresh();
});
}
}
}).upload(files);
});
}, false);
// grid
const Container = new Element('div', {
style: {
height: '100%',
width: '100%'
}
}).inject(this.getElm());
ERPEntityUtils.getEntityTitle(this.getAttribute('hash')).then((result) => {
entityTitle = result;
this.$Grid = new Grid(Container, {
multipleSelection: true,
buttons: [
{
text: QUILocale.get(lg, 'customer.grid.customerFiles'),
textimage: 'fa fa-user-o',
title: QUILocale.get(lg, 'customer.grid.customerFiles.title'),
events: {
click: this.openCustomerFiles
}
}, {
text: QUILocale.get(lg, 'customer.grid.button.remove', {
entity: entityTitle
}),
textimage: 'fa fa-link-slash',
name: 'remove',
disabled: true,
position: 'right',
events: {
click: this.removeSelectedFiles
}
}
],
columnModel: [
{
header: '<span class="fa fa-envelope" title="' +
QUILocale.get(lg, 'customer.grid.mail.checkbox.title') + '"></span>',
dataIndex: 'mail',
dataType: 'node',
width: 50
}, {
header: QUILocale.get('quiqqer/quiqqer', 'type'),
dataIndex: 'icon',
dataType: 'node',
width: 40
}, {
header: QUILocale.get('quiqqer/quiqqer', 'file'),
dataIndex: 'basename',
dataType: 'string',
width: 300
}, {
header: QUILocale.get('quiqqer/quiqqer', 'size'),
dataIndex: 'filesize_formatted',
dataType: 'string',
width: 100
}, {
header: QUILocale.get('quiqqer/customer', 'window.customer.tbl.header.uploadTime'),
dataIndex: 'uploadTime',
dataType: 'string',
width: 100
}, {
dataIndex: 'hash',
dataType: 'string',
hidden: true
}
]
});
this.$Grid.addEvents({
refresh: () => {
this.$Grid.getButtons('remove')[0].disable();
},
click: () => {
const selected = this.$Grid.getSelectedData();
const Remove = this.$Grid.getButtons('remove')[0];
if (selected.length) {
Remove.enable();
}
}
});
this.$Grid.showLoader();
return this.getCustomer();
}).then((customerHash) => {
this.setAttribute('customerId', customerHash);
}).then(() => {
return this.refresh();
});
},
refresh: function() {
if (!this.$Grid) {
return Promise.resolve();
}
this.$Grid.showLoader();
return new Promise((resolve, reject) => {
QUIAjax.get('package_quiqqer_erp_ajax_customerFiles_getFiles', (files) => {
const data = [];
files.forEach((entry) => {
data.push({
hash: entry.hash,
basename: entry.file.basename,
filesize_formatted: entry.file.filesize_formatted,
uploadTime: entry.file.uploadTime_formatted,
icon: new Element('img', {
src: entry.file.icon,
styles: {
margin: '5px 0'
}
}),
mail: new Element('input', {
type: 'checkbox',
checked: entry.options.attachToEmail
})
});
});
this.$Grid.setData({
data: data
});
this.getElm().getElements('[type="checkbox"]').addEvent('change', () => {
this.update();
});
this.$Grid.hideLoader();
resolve(files);
}, {
'package': 'quiqqer/erp',
hash: this.getAttribute('hash'),
onError: reject
});
});
},
addFile: function(fileHash) {
this.$Grid.showLoader();
QUIAjax.post('package_quiqqer_erp_ajax_customerFiles_addFile', () => {
this.refresh();
}, {
'package': 'quiqqer/erp',
hash: this.getAttribute('hash'),
fileHash: fileHash
});
},
addFiles: function(fileHashes) {
this.$Grid.showLoader();
return new Promise((resolve) => {
QUIAjax.post('package_quiqqer_erp_ajax_customerFiles_addFiles', () => {
this.refresh();
resolve();
}, {
'package': 'quiqqer/erp',
hash: this.getAttribute('hash'),
fileHashes: JSON.encode(fileHashes)
});
});
},
getCustomer: function() {
return new Promise((resolve, reject) => {
QUIAjax.get('package_quiqqer_erp_ajax_customerFiles_getCustomer', resolve, {
'package': 'quiqqer/erp',
hash: this.getAttribute('hash'),
onError: reject
});
});
},
update: function() {
const gridData = this.$Grid.getData().map((entry) => {
return {
hash: entry.hash,
options: {
attachToEmail: entry.mail.checked ? 1 : 0
}
};
});
return new Promise((resolve, reject) => {
QUIAjax.get('package_quiqqer_erp_ajax_customerFiles_update', () => {
QUI.getMessageHandler().then((MH) => {
MH.addSuccess(
QUILocale.get(lg, 'customer.grid.saved', {
entity: entityTitle
})
);
});
resolve();
}, {
'package': 'quiqqer/erp',
hash: this.getAttribute('hash'),
files: JSON.encode(gridData),
onError: reject
});
});
},
/**
* open customer file window
*/
openCustomerFiles: function() {
require([
'package/quiqqer/customer/bin/backend/controls/customer/userFiles/Window'
], (Window) => {
new Window({
userId: this.getAttribute('customerId'),
events: {
onSelect: (selectedFiles, Win) => {
// @todo
for (let File of selectedFiles) {
this.addFile(File.hash);
}
Win.close();
}
}
}).open();
});
},
removeSelectedFiles: function() {
require(['qui/controls/windows/Confirm'], (QUIConfirm) => {
new QUIConfirm({
maxHeight: 500,
maxWidth: 600,
information: QUILocale.get(lg, 'window.delete.customer.grid.information', {
entity: entityTitle
}),
text: QUILocale.get(lg, 'window.delete.customer.grid.text', {
entity: entityTitle
}),
title: QUILocale.get(lg, 'window.delete.customer.grid.title', {
entity: entityTitle
}),
texticon: 'fa fa-link-slash',
icon: 'fa fa-link-slash',
ok_button: {
textimage: 'fa fa-link-slash',
text: QUILocale.get(lg, 'window.delete.customer.grid.title', {
entity: entityTitle
})
},
events: {
onOpen: (Win) => {
const List = new Element('ul').inject(Win.getContent().getElement('.textbody'));
this.$Grid.getSelectedData().each((entry) => {
new Element('li', {
html: entry.basename
}).inject(List);
});
},
onSubmit: (Win) => {
this.$Grid.deleteRows(this.$Grid.getSelectedIndices());
Win.Loader.show();
this.update().then(() => {
Win.close();
this.refresh();
});
}
}
}).open();
});
},
/**
* Get file info
*
* @param {String} fileHash
* @return {Promise}
*/
$getFileData: function(fileHash) {
return new Promise((resolve, reject) => {
QUIAjax.get('package_quiqqer_customer_ajax_backend_files_get', resolve, {
'package': 'quiqqer/customer',
customerId: this.getAttribute('customerId'),
fileHash: fileHash,
onError: reject
});
});
}
});
});
...@@ -58,7 +58,7 @@ define('package/quiqqer/erp/bin/backend/controls/process/ProcessGrid', [ ...@@ -58,7 +58,7 @@ define('package/quiqqer/erp/bin/backend/controls/process/ProcessGrid', [
width: 60 width: 60
}, { }, {
header: QUILocale.get(lg, 'erp.process.state'), header: QUILocale.get(lg, 'erp.process.state'),
dataIndex: 'status', dataIndex: 'paid_status',
dataType: 'node', dataType: 'node',
width: 100 width: 100
}, { }, {
...@@ -95,6 +95,7 @@ define('package/quiqqer/erp/bin/backend/controls/process/ProcessGrid', [ ...@@ -95,6 +95,7 @@ define('package/quiqqer/erp/bin/backend/controls/process/ProcessGrid', [
events: { events: {
click: this.$click click: this.$click
}, },
icon: 'fa ' + window.ERP_ENTITY_ICONS[entry.entityType],
entityType: entry.entityType, entityType: entry.entityType,
uuid: entry.uuid, uuid: entry.uuid,
styles: { styles: {
...@@ -104,20 +105,34 @@ define('package/quiqqer/erp/bin/backend/controls/process/ProcessGrid', [ ...@@ -104,20 +105,34 @@ define('package/quiqqer/erp/bin/backend/controls/process/ProcessGrid', [
switch (entry.entityType) { switch (entry.entityType) {
case 'QUI\\ERP\\Order\\Order': case 'QUI\\ERP\\Order\\Order':
Type.setAttribute('icon', 'fa fa-shopping-basket');
Type.setAttribute('title', QUILocale.get(lg, 'processGrid.order.open')); Type.setAttribute('title', QUILocale.get(lg, 'processGrid.order.open'));
break; break;
case 'QUI\\ERP\\Invoice\\Invoice': case 'QUI\\ERP\\Accounting\\Invoice\\Invoice':
case 'QUI\\ERP\\Accounting\\Invoice\\InvoiceTemporary':
Type.setAttribute('icon', 'fa fa-file-text-o');
Type.setAttribute('title', QUILocale.get(lg, 'processGrid.invoice.open')); Type.setAttribute('title', QUILocale.get(lg, 'processGrid.invoice.open'));
break; break;
case 'QUI\\ERP\\Accounting\\Invoice\\InvoiceTemporary':
Type.setAttribute('title', QUILocale.get(lg, 'processGrid.invoiceTemporary.open'));
break;
case 'QUI\\ERP\\SalesOrders\\SalesOrder':
Type.setAttribute('title', QUILocale.get(lg, 'processGrid.salesOrder.open'));
break;
} }
if (typeof entry.paid_status === 'undefined') {
entry.paid_status = 0;
}
const PaymentStatus = new Element('span', {
'class': 'payment-status payment-status-' + entry.paid_status,
html: QUILocale.get('quiqqer/erp', 'payment.status.' + entry.paid_status)
});
data.push({ data.push({
type: Type, type: Type,
status: entry.status, paid_status: PaymentStatus,
prefixedNumber: entry.prefixedNumber, prefixedNumber: entry.prefixedNumber,
uuid: entry.uuid uuid: entry.uuid
}); });
...@@ -144,7 +159,7 @@ define('package/quiqqer/erp/bin/backend/controls/process/ProcessGrid', [ ...@@ -144,7 +159,7 @@ define('package/quiqqer/erp/bin/backend/controls/process/ProcessGrid', [
panel = 'package/quiqqer/order/bin/backend/controls/panels/Order'; panel = 'package/quiqqer/order/bin/backend/controls/panels/Order';
break; break;
case 'QUI\\ERP\\Invoice\\Invoice': case 'QUI\\ERP\\Accounting\\Invoice\\Invoice':
panel = 'package/quiqqer/invoice/bin/backend/controls/panels/Invoice'; panel = 'package/quiqqer/invoice/bin/backend/controls/panels/Invoice';
break; break;
...@@ -152,6 +167,10 @@ define('package/quiqqer/erp/bin/backend/controls/process/ProcessGrid', [ ...@@ -152,6 +167,10 @@ define('package/quiqqer/erp/bin/backend/controls/process/ProcessGrid', [
panel = 'package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice'; panel = 'package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice';
break; break;
case 'QUI\\ERP\\SalesOrders\\SalesOrder':
panel = 'package/quiqqer/salesorders/bin/js/backend/controls/panels/SalesOrder';
break;
default: default:
console.error('missing', uuid, Btn.getAttribute('entityType')); console.error('missing', uuid, Btn.getAttribute('entityType'));
return; return;
......
/**
* @module package/quiqqer/erp/bin/backend/utils/ERPEntities
* @author www.pcsg.de (Henning Leutz)
*/
define('package/quiqqer/erp/bin/backend/utils/ERPEntities', function() {
'use strict';
return {
/**
* Return the AMD Panel for the entity type
*
* @param {String} entityType
* @return {String}
*/
getPanelByEntity: function(entityType) {
switch (entityType) {
case 'QUI\\ERP\\Order\\Order':
return 'package/quiqqer/order/bin/backend/controls/panels/Order';
case 'QUI\\ERP\\Accounting\\Invoice\\Invoice':
return 'package/quiqqer/invoice/bin/backend/controls/panels/Invoice';
case 'QUI\\ERP\\Accounting\\Invoice\\InvoiceTemporary':
return 'package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice';
case 'QUI\\ERP\\SalesOrders\\SalesOrder':
return 'package/quiqqer/salesorders/bin/js/backend/controls/panels/SalesOrder';
default:
console.error('missing', entityType);
}
return '';
},
getEntityTitle: function(uuid) {
return new Promise(function(resolve) {
require(['Ajax'], function(QUIAjax) {
QUIAjax.get('package_quiqqer_erp_ajax_getEntityTitle', resolve, {
'package': 'quiqqer/erp',
uuid: uuid
});
});
});
},
openPanelByUUID: function(uuid) {
return this.getTypeByUUID(uuid).then((entityType) => {
const panel = this.getPanelByEntity(entityType);
return new Promise(function(resolve) {
require(['utils/Panels', panel], (PanelUtils, Panel) => {
const PanelInstance = new Panel({
uuid: uuid
});
PanelUtils.openPanelInTasks(PanelInstance);
resolve(PanelInstance);
});
});
});
},
getTypeByUUID: function(uuid) {
return new Promise(function(resolve) {
require(['Ajax'], function(QUIAjax) {
QUIAjax.get('package_quiqqer_erp_ajax_getEntityType', resolve, {
'package': 'quiqqer/erp',
uuid: uuid
});
});
});
}
};
});
\ No newline at end of file
...@@ -281,6 +281,14 @@ ...@@ -281,6 +281,14 @@
<de><![CDATA[Rechnung öffnen]]></de> <de><![CDATA[Rechnung öffnen]]></de>
<en><![CDATA[Open invoice]]></en> <en><![CDATA[Open invoice]]></en>
</locale> </locale>
<locale name="processGrid.invoiceTemporary.open">
<de><![CDATA[Rechnungsentwurf öffnen]]></de>
<en><![CDATA[Open temporary invoice]]></en>
</locale>
<locale name="processGrid.salesOrder.open">
<de><![CDATA[Auftrag öffnen]]></de>
<en><![CDATA[Open sales order]]></en>
</locale>
<locale name="erp.process.type"> <locale name="erp.process.type">
<de><![CDATA[Typ]]></de> <de><![CDATA[Typ]]></de>
<en><![CDATA[Type]]></en> <en><![CDATA[Type]]></en>
...@@ -301,6 +309,49 @@ ...@@ -301,6 +309,49 @@
<de><![CDATA[Entitäts UUID]]></de> <de><![CDATA[Entitäts UUID]]></de>
<en><![CDATA[Entity uuid]]></en> <en><![CDATA[Entity uuid]]></en>
</locale> </locale>
<locale name="payment.status.0">
<de><![CDATA[offen]]></de>
<en><![CDATA[open]]></en>
</locale>
<locale name="payment.status.1">
<de><![CDATA[bezahlt]]></de>
<en><![CDATA[paid]]></en>
</locale>
<locale name="payment.status.2">
<de><![CDATA[Teilzahlung]]></de>
<en><![CDATA[part payment]]></en>
</locale>
<locale name="payment.status.3">
<de><![CDATA[storniert]]></de>
<en><![CDATA[canceled]]></en>
</locale>
<locale name="payment.status.4">
<de><![CDATA[error]]></de>
<en><![CDATA[error]]></en>
</locale>
<locale name="payment.status.5">
<de><![CDATA[storniert]]></de>
<en><![CDATA[canceled]]></en>
</locale>
<locale name="payment.status.11">
<de><![CDATA[Lastschrift]]></de>
<en><![CDATA[Debit]]></en>
</locale>
<locale name="payment.status.12">
<de><![CDATA[Abonnement]]></de>
<en><![CDATA[Subscription plan]]></en>
</locale>
<locale name="entity.title.QUI\ERP\Accounting\Invoice\Invoice">
<de><![CDATA[Rechnung]]></de>
<en><![CDATA[Invoice]]></en>
</locale>
<locale name="entity.title.QUI\ERP\Accounting\Invoice\InvoiceTemporary">
<de><![CDATA[Rechnungsentwurf]]></de>
<en><![CDATA[Temporary Invoice]]></en>
</locale>
</groups> </groups>
<groups name="quiqqer/erp" datatype="php"> <groups name="quiqqer/erp" datatype="php">
...@@ -1519,6 +1570,38 @@ Allowed characters: Letters, numbers and _ ä ö ü ß]]></en> ...@@ -1519,6 +1570,38 @@ Allowed characters: Letters, numbers and _ ä ö ü ß]]></en>
<de><![CDATA[Prozess: [globalProcessId]]]></de> <de><![CDATA[Prozess: [globalProcessId]]]></de>
<en><![CDATA[Process: [globalProcessId]]]></en> <en><![CDATA[Process: [globalProcessId]]]></en>
</locale> </locale>
<locale name="window.delete.customer.grid.information">
<de><![CDATA[Die Dateien werden nicht gelöscht, sondern nur von der ausgewählten [entity] getrennt.]]></de>
<en><![CDATA[The files are not deleted, but only separated from the selected [entity].]]></en>
</locale>
<locale name="window.delete.customer.grid.text">
<de><![CDATA[Dateien aus [entity] entfernen]]></de>
<en><![CDATA[Remove files from [entity]]]></en>
</locale>
<locale name="window.delete.customer.grid.title">
<de><![CDATA[Dateien aus [entity] entfernen]]></de>
<en><![CDATA[Remove files from [entity]]]></en>
</locale>
<locale name="customer.grid.mail.checkbox.title">
<de><![CDATA[Als Mailanhang setzen]]></de>
<en><![CDATA[Set as mail attachment]]></en>
</locale>
<locale name="customer.grid.customerFiles">
<de><![CDATA[Kundendateien]]></de>
<en><![CDATA[Customer files]]></en>
</locale>
<locale name="customer.grid.customerFiles.title">
<de><![CDATA[Datei aus Kundendateien auswählen]]></de>
<en><![CDATA[Select file from customer files]]></en>
</locale>
<locale name="customer.grid.button.remove">
<de><![CDATA[Datei aus [entity] entfernen]]></de>
<en><![CDATA[Remove file from [entity]]]></en>
</locale>
<locale name="customer.grid.saved">
<de><![CDATA[Dateien von [entity]: Änderungen der Kundendaten wurden erfolgreich gespeichert]]></de>
<en><![CDATA[Files from [entity]: Changes to customer data were successfully saved]]></en>
</locale>
</groups> </groups>
</locales> </locales>
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<tbody> <tbody>
{foreach $articles as $Article} {foreach $articles as $Article}
{$Article->toHTML()} {$Article->toHTML($articleTemplate)}
{/foreach} {/foreach}
</tbody> </tbody>
</table> </table>
......
...@@ -392,8 +392,10 @@ public function setExchangeRate(float $rate): void ...@@ -392,8 +392,10 @@ public function setExchangeRate(float $rate): void
* *
* @throws QUI\Exception * @throws QUI\Exception
*/ */
public function toHTML(bool|string $template = false): string public function toHTML(
{ bool|string $template = false,
bool|string $articleTemplate = false
): string {
$Engine = QUI::getTemplateManager()->getEngine(); $Engine = QUI::getTemplateManager()->getEngine();
$vatArray = []; $vatArray = [];
...@@ -458,7 +460,10 @@ public function toHTML(bool|string $template = false): string ...@@ -458,7 +460,10 @@ public function toHTML(bool|string $template = false): string
$Currency->setExchangeRate($this->exchangeRate); $Currency->setExchangeRate($this->exchangeRate);
} }
if ($Currency instanceof QUI\ERP\CryptoCurrency\Currency) { if (
class_exists('QUI\ERP\CryptoCurrency\Currency')
&& $Currency instanceof QUI\ERP\CryptoCurrency\Currency
) {
$ExchangeCurrency->setExchangeRate($this->exchangeRate); $ExchangeCurrency->setExchangeRate($this->exchangeRate);
$exchangeRate = $Currency->convertFormat(1, $ExchangeCurrency); $exchangeRate = $Currency->convertFormat(1, $ExchangeCurrency);
} else { } else {
...@@ -479,7 +484,10 @@ public function toHTML(bool|string $template = false): string ...@@ -479,7 +484,10 @@ public function toHTML(bool|string $template = false): string
$showExchangeRate = true; $showExchangeRate = true;
$DefaultCurrency = QUI\ERP\Defaults::getCurrency(); $DefaultCurrency = QUI\ERP\Defaults::getCurrency();
if ($Currency instanceof QUI\ERP\CryptoCurrency\Currency) { if (
class_exists('QUI\ERP\CryptoCurrency\Currency')
&& $Currency instanceof QUI\ERP\CryptoCurrency\Currency
) {
$DefaultCurrency->setExchangeRate($this->exchangeRate); $DefaultCurrency->setExchangeRate($this->exchangeRate);
$exchangeRate = $Currency->convertFormat(1, $DefaultCurrency); $exchangeRate = $Currency->convertFormat(1, $DefaultCurrency);
} else { } else {
...@@ -512,6 +520,7 @@ public function toHTML(bool|string $template = false): string ...@@ -512,6 +520,7 @@ public function toHTML(bool|string $template = false): string
'showHeader' => $this->showHeader, 'showHeader' => $this->showHeader,
'this' => $this, 'this' => $this,
'articles' => $articles, 'articles' => $articles,
'articleTemplate' => $articleTemplate,
'calculations' => $this->calculations, 'calculations' => $this->calculations,
'vatArray' => $vatArray, 'vatArray' => $vatArray,
'Locale' => $this->Locale, 'Locale' => $this->Locale,
......
...@@ -8,8 +8,13 @@ ...@@ -8,8 +8,13 @@
use QUI; use QUI;
use QUI\ERP\Accounting\Calc as ErpCalc; use QUI\ERP\Accounting\Calc as ErpCalc;
use QUI\Exception;
use function dirname;
use function file_exists;
use function implode; use function implode;
use function is_array;
use function is_string;
/** /**
* Class ArticleView * Class ArticleView
...@@ -29,9 +34,9 @@ class ArticleView extends QUI\QDOM ...@@ -29,9 +34,9 @@ class ArticleView extends QUI\QDOM
protected Article $Article; protected Article $Article;
/** /**
* @var QUI\ERP\Currency\Currency * @var ?QUI\ERP\Currency\Currency
*/ */
protected QUI\ERP\Currency\Currency $Currency; protected ?QUI\ERP\Currency\Currency $Currency = null;
/** /**
* ArticleView constructor. * ArticleView constructor.
...@@ -110,7 +115,7 @@ public function getCustomFields(): array ...@@ -110,7 +115,7 @@ public function getCustomFields(): array
} }
if (isset($field['custom_calc']['valueText'])) { if (isset($field['custom_calc']['valueText'])) {
if (!\is_string($field['custom_calc']['valueText'])) { if (!is_string($field['custom_calc']['valueText'])) {
if (isset($field['custom_calc']['valueText'][$current])) { if (isset($field['custom_calc']['valueText'][$current])) {
$field['custom_calc']['valueText'] = $field['custom_calc']['valueText'][$current]; $field['custom_calc']['valueText'] = $field['custom_calc']['valueText'][$current];
} else { } else {
...@@ -175,11 +180,12 @@ public function getPrice(): string ...@@ -175,11 +180,12 @@ public function getPrice(): string
/** /**
* Create the html * Create the html
* *
* @param string|bool $template
* @return string * @return string
* *
* @throws QUI\Exception * @throws Exception
*/ */
public function toHTML(): string public function toHTML(string|bool $template = false): string
{ {
$Engine = QUI::getTemplateManager()->getEngine(); $Engine = QUI::getTemplateManager()->getEngine();
$Currency = $this->getCurrency(); $Currency = $this->getCurrency();
...@@ -189,7 +195,7 @@ public function toHTML(): string ...@@ -189,7 +195,7 @@ public function toHTML(): string
$calc = $article['calculated']; $calc = $article['calculated'];
// quantity unit // quantity unit
if (isset($article['quantityUnit']) && \is_array($article['quantityUnit'])) { if (isset($article['quantityUnit']) && is_array($article['quantityUnit'])) {
$article['quantityUnit'] = $article['quantityUnit']['title']; $article['quantityUnit'] = $article['quantityUnit']['title'];
} }
...@@ -237,10 +243,14 @@ public function toHTML(): string ...@@ -237,10 +243,14 @@ public function toHTML(): string
'hasAppliedVat' => !empty($articleData['calculated']['vatArray']['vat']) 'hasAppliedVat' => !empty($articleData['calculated']['vatArray']['vat'])
]); ]);
if ($template && file_exists($template)) {
return $Engine->fetch($template);
}
if ($this->Article instanceof QUI\ERP\Accounting\Articles\Text) { if ($this->Article instanceof QUI\ERP\Accounting\Articles\Text) {
return $Engine->fetch(\dirname(__FILE__) . '/ArticleViewText.html'); return $Engine->fetch(dirname(__FILE__) . '/ArticleViewText.html');
} }
return $Engine->fetch(\dirname(__FILE__) . '/ArticleView.html'); return $Engine->fetch(dirname(__FILE__) . '/ArticleView.html');
} }
} }
<?php
namespace QUI\ERP;
use QUI;
use QUI\ERP\Customer\CustomerFiles;
use QUI\ERP\User as ErpUser;
use function is_array;
trait ErpEntityCustomerFiles
{
// region needed methods
abstract public function getCustomer(): ?ErpUser;
abstract public function getId(): int;
abstract public function addCustomDataEntry(string $key, mixed $value): void;
abstract public function getCustomDataEntry(string $key): mixed;
//endregion
// region extended customer file methods
protected array $defaultCustomerFilesOptions = [
'attachToEmail' => false
];
/**
* Add a customer file to this invoice
*
* @param string $fileHash - SHA256 hash of the file basename
* @param array $options (optional) - File options; see $defaultOptions in code for what's possible
*
* @throws Exception
* @throws QUI\Exception
*/
public function addCustomerFile(string $fileHash, array $options = []): void
{
$Customer = $this->getCustomer();
$file = CustomerFiles::getFileByHash($Customer->getId(), $fileHash);
if (empty($file)) {
throw new Exception(
QUI::getLocale()->get('quiqqer/invoice', 'exception.Invoice.addCustomerFile.file_not_found')
);
}
$fileEntry = [
'hash' => $fileHash,
'options' => $this->cleanCustomerFilesOptions($options)
];
$customerFiles = $this->getCustomerFiles();
$customerFiles[] = $fileEntry;
$this->addCustomDataEntry('customer_files', $customerFiles);
}
/**
* @param array $files
* @return void
*
* @throws Exception
* @throws QUI\Exception
*/
public function setCustomFiles(array $files = []): void
{
if (empty($files)) {
return;
}
$this->clearCustomerFiles();
$customerFiles = [];
foreach ($files as $file) {
$options = $file['options'];
if (!is_array($options)) {
$options = [];
}
$fileEntry = [
'hash' => $file['hash'],
'options' => $this->cleanCustomerFilesOptions($options)
];
$customerFiles[] = $fileEntry;
}
$this->addCustomDataEntry('customer_files', $customerFiles);
}
/**
* Clear customer files
*
* @return void
*/
public function clearCustomerFiles(): void
{
try {
$this->addCustomDataEntry('customer_files', []);
} catch (\Exception $e) {
QUI\System\Log::addError($e->getMessage());
}
}
/**
* Get customer files that are attached to this invoice.
*
* @param bool $parsing - true = parses the file hash
* ]
* @return array - Contains file hash and file options
*/
public function getCustomerFiles(bool $parsing = false): array
{
$customerFiles = $this->getCustomDataEntry('customer_files');
if (empty($customerFiles)) {
return [];
}
try {
$Customer = $this->getCustomer();
} catch (\Exception) {
return [];
}
$result = [];
foreach ($customerFiles as $customerFile) {
try {
// check if file is from customer
$file = CustomerFiles::getFileByHash($Customer->getId(), $customerFile['hash']);
if ($parsing) {
$file['uploadTime_formatted'] = QUI::getLocale()->formatDate($file['uploadTime']);
$file['icon'] = QUI\Projects\Media\Utils::getIconByExtension($file['extension']);
$customerFile['file'] = $file;
}
$result[] = $customerFile;
} catch (\Exception) {
}
}
return $result;
}
/**
* cleans a customer files option array
*
* @param array $options
* @return array
*/
protected function cleanCustomerFilesOptions(array $options = []): array
{
// set default options
foreach ($this->defaultCustomerFilesOptions as $k => $v) {
if (!isset($options[$k])) {
$options[$k] = $v;
}
}
// cleanup
foreach ($options as $k => $v) {
if (!isset($this->defaultCustomerFilesOptions[$k])) {
unset($options[$k]);
}
}
return $options;
}
// endregion
}
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
use function is_array; use function is_array;
use function is_string; use function is_string;
use function json_decode; use function json_decode;
use function json_encode;
/** /**
* Class EventHandler * Class EventHandler
...@@ -32,6 +33,8 @@ class EventHandler ...@@ -32,6 +33,8 @@ class EventHandler
*/ */
public static function onAdminLoadFooter(): void public static function onAdminLoadFooter(): void
{ {
echo '<link href="' . URL_OPT_DIR . 'quiqqer/erp/bin/backend/payment-status.css" rel="stylesheet" type="text/css" />';
echo '<script>window.ERP_ENTITY_ICONS = ' . json_encode(QUI\ERP\Utils\Utils::$entityIcons) . '</script>';
echo '<script src="' . URL_OPT_DIR . 'quiqqer/erp/bin/load.js"></script>'; echo '<script src="' . URL_OPT_DIR . 'quiqqer/erp/bin/load.js"></script>';
} }
......
...@@ -42,7 +42,7 @@ public static function getManufacturerGroupIds(): array ...@@ -42,7 +42,7 @@ public static function getManufacturerGroupIds(): array
$groupIds = []; $groupIds = [];
try { try {
$Conf = QUI::getPackage('quiqqer/erp')->getConfig(); $Conf = QUI::getPackage('quiqqer/erp')->getConfig();
$defaultGroupId = $Conf->get('manufacturers', 'groupId'); $defaultGroupId = $Conf->get('manufacturers', 'groupId');
if (!empty($defaultGroupId)) { if (!empty($defaultGroupId)) {
...@@ -100,7 +100,7 @@ public static function createManufacturer( ...@@ -100,7 +100,7 @@ public static function createManufacturer(
): QUI\Users\User { ): QUI\Users\User {
QUI\Permissions\Permission::checkPermission('quiqqer.erp_manufacturers.create'); QUI\Permissions\Permission::checkPermission('quiqqer.erp_manufacturers.create');
$Users = QUI::getUsers(); $Users = QUI::getUsers();
$manufacturerId = $Users::clearUsername($manufacturerId); $manufacturerId = $Users::clearUsername($manufacturerId);
// Check ID // Check ID
...@@ -115,12 +115,12 @@ public static function createManufacturer( ...@@ -115,12 +115,12 @@ public static function createManufacturer(
} }
$SystemUser = $Users->getSystemUser(); $SystemUser = $Users->getSystemUser();
$User = $Users->createChild($manufacturerId, $SystemUser); $User = $Users->createChild($manufacturerId, $SystemUser);
if (!empty($address)) { if (!empty($address)) {
try { try {
$Address = $User->getStandardAddress(); $Address = $User->getStandardAddress();
} catch (QUI\Exception $Exception) { } catch (QUI\Exception) {
$Address = $User->addAddress(); $Address = $User->addAddress();
} }
...@@ -198,12 +198,12 @@ public static function createManufacturer( ...@@ -198,12 +198,12 @@ public static function createManufacturer(
*/ */
public static function search(array $searchParams, bool $countOnly = false) public static function search(array $searchParams, bool $countOnly = false)
{ {
$Grid = new QUI\Utils\Grid($searchParams); $Grid = new QUI\Utils\Grid($searchParams);
$gridParams = $Grid->parseDBParams($searchParams); $gridParams = $Grid->parseDBParams($searchParams);
$usersTbl = QUI::getDBTableName('users'); $usersTbl = QUI::getDBTableName('users');
$usersAddressTbl = QUI::getDBTableName('users_address'); $usersAddressTbl = QUI::getDBTableName('users_address');
$binds = []; $binds = [];
$where = []; $where = [];
if ($countOnly) { if ($countOnly) {
$sql = "SELECT COUNT(*)"; $sql = "SELECT COUNT(*)";
...@@ -215,16 +215,16 @@ public static function search(array $searchParams, bool $countOnly = false) ...@@ -215,16 +215,16 @@ public static function search(array $searchParams, bool $countOnly = false)
$sql .= " FROM `" . $usersTbl . "` as u LEFT JOIN `" . $usersAddressTbl . "` as ua ON u.`address` = ua.`id`"; $sql .= " FROM `" . $usersTbl . "` as u LEFT JOIN `" . $usersAddressTbl . "` as ua ON u.`address` = ua.`id`";
// Only fetch users in manufacturer groups // Only fetch users in manufacturer groups
$gc = 0; $gc = 0;
$whereOr = []; $whereOr = [];
foreach (self::getManufacturerGroupIds() as $groupId) { foreach (self::getManufacturerGroupIds() as $groupId) {
$whereOr[] = "u.`usergroup` LIKE :group" . $gc; $whereOr[] = "u.`usergroup` LIKE :group" . $gc;
$bind = 'group' . $gc++; $bind = 'group' . $gc++;
$binds[$bind] = [ $binds[$bind] = [
'value' => '%,' . $groupId . ',%', 'value' => '%,' . $groupId . ',%',
'type' => PDO::PARAM_STR 'type' => PDO::PARAM_STR
]; ];
} }
...@@ -254,12 +254,12 @@ public static function search(array $searchParams, bool $countOnly = false) ...@@ -254,12 +254,12 @@ public static function search(array $searchParams, bool $countOnly = false)
if ($DateFrom) { if ($DateFrom) {
$DateFrom->setTime(0, 0, 0); $DateFrom->setTime(0, 0, 0);
$bind = 'datefrom'; $bind = 'datefrom';
$where[] = 'u.`regdate` >= :' . $bind; $where[] = 'u.`regdate` >= :' . $bind;
$binds[$bind] = [ $binds[$bind] = [
'value' => $DateFrom->getTimestamp(), 'value' => $DateFrom->getTimestamp(),
'type' => PDO::PARAM_INT 'type' => PDO::PARAM_INT
]; ];
} }
} }
...@@ -270,12 +270,12 @@ public static function search(array $searchParams, bool $countOnly = false) ...@@ -270,12 +270,12 @@ public static function search(array $searchParams, bool $countOnly = false)
if ($DateTo) { if ($DateTo) {
$DateTo->setTime(23, 59, 59); $DateTo->setTime(23, 59, 59);
$bind = 'dateto'; $bind = 'dateto';
$where[] = 'u.`regdate` <= :' . $bind; $where[] = 'u.`regdate` <= :' . $bind;
$binds[$bind] = [ $binds[$bind] = [
'value' => $DateTo->getTimestamp(), 'value' => $DateTo->getTimestamp(),
'type' => PDO::PARAM_INT 'type' => PDO::PARAM_INT
]; ];
} }
} }
...@@ -283,8 +283,8 @@ public static function search(array $searchParams, bool $countOnly = false) ...@@ -283,8 +283,8 @@ public static function search(array $searchParams, bool $countOnly = false)
if (!empty($searchParams['search'])) { if (!empty($searchParams['search'])) {
$searchValue = $searchParams['search']; $searchValue = $searchParams['search'];
$fc = 0; $fc = 0;
$whereOr = []; $whereOr = [];
// search value filters // search value filters
foreach ($searchFields as $filter) { foreach ($searchFields as $filter) {
...@@ -309,7 +309,7 @@ public static function search(array $searchParams, bool $countOnly = false) ...@@ -309,7 +309,7 @@ public static function search(array $searchParams, bool $countOnly = false)
$binds[$bind] = [ $binds[$bind] = [
'value' => '%' . $searchValue . '%', 'value' => '%' . $searchValue . '%',
'type' => PDO::PARAM_STR 'type' => PDO::PARAM_STR
]; ];
$fc++; $fc++;
...@@ -411,7 +411,7 @@ public static function parseListForGrid(array $data): array ...@@ -411,7 +411,7 @@ public static function parseListForGrid(array $data): array
$result = []; $result = [];
$Groups = QUI::getGroups(); $Groups = QUI::getGroups();
$Users = QUI::getUsers(); $Users = QUI::getUsers();
foreach ($data as $entry) { foreach ($data as $entry) {
$entry['usergroup'] = trim($entry['usergroup'], ','); $entry['usergroup'] = trim($entry['usergroup'], ',');
...@@ -425,7 +425,7 @@ public static function parseListForGrid(array $data): array ...@@ -425,7 +425,7 @@ public static function parseListForGrid(array $data): array
$Group = $Groups->get($groupId); $Group = $Groups->get($groupId);
return $Group->getName(); return $Group->getName();
} catch (QUI\Exception $Exception) { } catch (QUI\Exception) {
} }
return ''; return '';
...@@ -437,12 +437,12 @@ public static function parseListForGrid(array $data): array ...@@ -437,12 +437,12 @@ public static function parseListForGrid(array $data): array
$groups = trim($groups, ','); $groups = trim($groups, ',');
$addressData = []; $addressData = [];
$Address = null; $Address = null;
try { try {
$User = $Users->get((int)$entry['id']); $User = $Users->get($entry['id']);
$Address = $User->getStandardAddress(); $Address = $User->getStandardAddress();
} catch (QUI\Exception $Exception) { } catch (QUI\Exception) {
} }
if ($Address && (empty($entry['firstname']) || empty($entry['lastname']))) { if ($Address && (empty($entry['firstname']) || empty($entry['lastname']))) {
...@@ -450,12 +450,12 @@ public static function parseListForGrid(array $data): array ...@@ -450,12 +450,12 @@ public static function parseListForGrid(array $data): array
if ($Address->getAttribute('firstname')) { if ($Address->getAttribute('firstname')) {
$entry['firstname'] = $Address->getAttribute('firstname'); $entry['firstname'] = $Address->getAttribute('firstname');
$name[] = $Address->getAttribute('firstname'); $name[] = $Address->getAttribute('firstname');
} }
if ($Address->getAttribute('lastname')) { if ($Address->getAttribute('lastname')) {
$entry['lastname'] = $Address->getAttribute('lastname'); $entry['lastname'] = $Address->getAttribute('lastname');
$name[] = $Address->getAttribute('lastname'); $name[] = $Address->getAttribute('lastname');
} }
if (!empty($name)) { if (!empty($name)) {
...@@ -480,18 +480,18 @@ public static function parseListForGrid(array $data): array ...@@ -480,18 +480,18 @@ public static function parseListForGrid(array $data): array
} }
$result[] = [ $result[] = [
'id' => (int)$entry['id'], 'id' => (int)$entry['id'],
'status' => !!$entry['active'], 'status' => !!$entry['active'],
'username' => $entry['username'], 'username' => $entry['username'],
'firstname' => $entry['firstname'], 'firstname' => $entry['firstname'],
'lastname' => $entry['lastname'], 'lastname' => $entry['lastname'],
'company' => $entry['company'], 'company' => $entry['company'],
'email' => $entry['email'], 'email' => $entry['email'],
'regdate' => $DateFormatterLong->format($entry['regdate']), 'regdate' => $DateFormatterLong->format($entry['regdate']),
'usergroup_display' => $groups, 'usergroup_display' => $groups,
'usergroup' => $entry['usergroup'], 'usergroup' => $entry['usergroup'],
'address_display' => implode(' - ', $addressData) 'address_display' => implode(' - ', $addressData)
]; ];
} }
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren