diff --git a/modules/erp/bestellungen/service.php b/modules/erp/bestellungen/service.php index ccd95af..11a434f 100644 --- a/modules/erp/bestellungen/service.php +++ b/modules/erp/bestellungen/service.php @@ -181,8 +181,7 @@ function normalize_sales_order_sort_column(string $sortColumn): string $allowed = [ 'order_date', 'external_ref', - 'last_name', - 'first_name', + 'name', 'total_amount', ]; @@ -224,6 +223,7 @@ WHERE ( so.external_ref ILIKE :search_term ESCAPE '\' OR COALESCE(ad.last_name, '') ILIKE :search_term ESCAPE '\' OR COALESCE(ad.first_name, '') ILIKE :search_term ESCAPE '\' + OR (COALESCE(ad.first_name, '') || ' ' || COALESCE(ad.last_name, '')) ILIKE :search_term ESCAPE '\' ) SQL; $params[':search_term'] = '%' . escape_sales_order_search_term($searchTerm) . '%'; @@ -232,8 +232,7 @@ SQL; $sortExpressions = [ 'order_date' => 'so.order_date', 'external_ref' => 'so.external_ref', - 'last_name' => 'COALESCE(ad.last_name, \'\')', - 'first_name' => 'COALESCE(ad.first_name, \'\')', + 'name' => 'COALESCE(ad.first_name, \'\') || \' \' || COALESCE(ad.last_name, \'\')', 'total_amount' => 'COALESCE(so.total_amount, 0)', ]; $sortExpression = $sortExpressions[$sortColumn] ?? 'so.order_date'; diff --git a/modules/shared/auth/ui/home.php b/modules/shared/auth/ui/home.php index 6b3190e..23ed5ba 100644 --- a/modules/shared/auth/ui/home.php +++ b/modules/shared/auth/ui/home.php @@ -64,8 +64,7 @@ function auth_render_bestellungen_large_table(array $bestellungenTable): string $sortColumns = [ 'order_date' => 'Bestelldatum', 'external_ref' => 'Bestellnummer', - 'last_name' => 'Nachname', - 'first_name' => 'Vorname', + 'name' => 'Name', 'total_amount' => 'Gesamtsumme', ]; @@ -118,6 +117,7 @@ function auth_render_bestellungen_large_table(array $bestellungenTable): string $totalAmount = auth_format_bestellung_total(isset($row['total_amount']) ? (float) $row['total_amount'] : null); $firstName = (string) ($row['first_name'] ?? ''); $lastName = (string) ($row['last_name'] ?? ''); + $name = trim($firstName . ' ' . $lastName); $street = (string) ($row['street'] ?? ''); $houseNumber = (string) ($row['house_number'] ?? ''); $zip = (string) ($row['zip'] ?? ''); @@ -129,8 +129,7 @@ function auth_render_bestellungen_large_table(array $bestellungenTable): string $html[] = '
'; $html[] = ''; $html[] = '
'; - $html[] = '
' . auth_escape_html($lastName) . '
'; - $html[] = '
' . auth_escape_html($firstName) . '
'; + $html[] = '
' . auth_escape_html($name) . '
'; $html[] = '
' . auth_escape_html($totalAmount) . '
'; $html[] = ''; } @@ -505,24 +504,43 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best echo "function initBestellungenBindings() {"; echo " const contentRoot = document.querySelector('[data-left-navigation-content-body]');"; echo " if (!contentRoot) { return; }"; - echo " let table = contentRoot.querySelector('[data-bestellungen-large-table]');"; + echo " const getTable = () => contentRoot.querySelector('[data-bestellungen-large-table]');"; + echo " let table = getTable();"; echo " if (!table) { return; }"; echo " let searchTimer = null;"; echo " let requestToken = 0;"; - echo " const getSearchInput = () => table.querySelector('[data-large-table-search]');"; + echo " const getSearchInput = () => {"; + echo " const currentTable = getTable();"; + echo " return currentTable ? currentTable.querySelector('[data-large-table-search]') : null;"; + echo " };"; echo " const getSearchWrap = () => {"; echo " const input = getSearchInput();"; echo " return input ? input.closest('[data-component=\\'single-line-input\\']') : null;"; echo " };"; - echo " const getClearButton = () => table.querySelector('.sg-input-clear-button');"; + echo " const getClearButton = () => {"; + echo " const currentTable = getTable();"; + echo " return currentTable ? currentTable.querySelector('.sg-input-clear-button') : null;"; + echo " };"; echo " const getSearchValue = () => {"; echo " const input = getSearchInput();"; echo " return input ? input.value.trim() : '';"; echo " };"; - echo " const getSortColumn = () => table.dataset.bestellungenSortColumn || 'order_date';"; - echo " const getSortDirection = () => (table.dataset.bestellungenSortDirection || 'DESC').toUpperCase();"; - echo " const getCurrentLimit = () => parseInt(table.dataset.bestellungenLimit || table.dataset.bestellungenPageSize || '20', 10);"; - echo " const getPageSize = () => parseInt(table.dataset.bestellungenPageSize || '20', 10);"; + echo " const getSortColumn = () => {"; + echo " const currentTable = getTable();"; + echo " return currentTable ? (currentTable.dataset.bestellungenSortColumn || 'order_date') : 'order_date';"; + echo " };"; + echo " const getSortDirection = () => {"; + echo " const currentTable = getTable();"; + echo " return (currentTable ? (currentTable.dataset.bestellungenSortDirection || 'DESC') : 'DESC').toUpperCase();"; + echo " };"; + echo " const getCurrentLimit = () => {"; + echo " const currentTable = getTable();"; + echo " return parseInt((currentTable ? currentTable.dataset.bestellungenLimit : null) || (currentTable ? currentTable.dataset.bestellungenPageSize : null) || '20', 10);"; + echo " };"; + echo " const getPageSize = () => {"; + echo " const currentTable = getTable();"; + echo " return parseInt((currentTable ? currentTable.dataset.bestellungenPageSize : null) || '20', 10);"; + echo " };"; echo " const syncSearchState = () => {"; echo " const input = getSearchInput();"; echo " const wrap = getSearchWrap();"; @@ -592,14 +610,15 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best echo " return false;"; echo " }"; echo " contentRoot.innerHTML = fragment.innerHTML;"; - echo " table = contentRoot.querySelector('[data-bestellungen-large-table]');"; + echo " table = getTable();"; echo " return !!table;"; echo " };"; echo " const loadFragment = async (params, updateHistory = true) => {"; echo " if (searchTimer) { window.clearTimeout(searchTimer); searchTimer = null; }"; echo " const url = buildUrl(params);"; echo " const activeRequest = ++requestToken;"; - echo " table.setAttribute('aria-busy', 'true');"; + echo " const currentTable = getTable();"; + echo " if (currentTable) { currentTable.setAttribute('aria-busy', 'true'); }"; echo " try {"; echo " const response = await fetch(url.toString(), { headers: { 'X-Requested-With': 'XMLHttpRequest' } });"; echo " const html = await response.text();"; @@ -607,7 +626,7 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best echo " return;"; echo " }"; echo " const replaced = replaceFragment(html);"; - echo " table = contentRoot.querySelector('[data-bestellungen-large-table]');"; + echo " table = getTable();"; echo " if (replaced && updateHistory) {"; echo " const historyUrl = new URL(url.toString());"; echo " historyUrl.searchParams.delete('bestellungen_fragment');"; @@ -616,7 +635,7 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best echo " bindTable();"; echo " } finally {"; echo " if (activeRequest === requestToken) {"; - echo " table = contentRoot.querySelector('[data-bestellungen-large-table]');"; + echo " table = getTable();"; echo " if (table) {"; echo " table.removeAttribute('aria-busy');"; echo " }"; @@ -624,7 +643,7 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best echo " }"; echo " };"; echo " const bindTable = () => {"; - echo " table = contentRoot.querySelector('[data-bestellungen-large-table]');"; + echo " table = getTable();"; echo " if (!table) { return; }"; echo " const searchInput = getSearchInput();"; echo " const clearButton = getClearButton();";