Bestellungen-Suche und Name-Spalte fixen

This commit is contained in:
2026-06-15 15:09:27 +02:00
parent f8a468a4f9
commit 27971bde63
2 changed files with 38 additions and 20 deletions
+3 -4
View File
@@ -181,8 +181,7 @@ function normalize_sales_order_sort_column(string $sortColumn): string
$allowed = [ $allowed = [
'order_date', 'order_date',
'external_ref', 'external_ref',
'last_name', 'name',
'first_name',
'total_amount', 'total_amount',
]; ];
@@ -224,6 +223,7 @@ WHERE (
so.external_ref ILIKE :search_term ESCAPE '\' so.external_ref ILIKE :search_term ESCAPE '\'
OR COALESCE(ad.last_name, '') 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, '') ILIKE :search_term ESCAPE '\'
OR (COALESCE(ad.first_name, '') || ' ' || COALESCE(ad.last_name, '')) ILIKE :search_term ESCAPE '\'
) )
SQL; SQL;
$params[':search_term'] = '%' . escape_sales_order_search_term($searchTerm) . '%'; $params[':search_term'] = '%' . escape_sales_order_search_term($searchTerm) . '%';
@@ -232,8 +232,7 @@ SQL;
$sortExpressions = [ $sortExpressions = [
'order_date' => 'so.order_date', 'order_date' => 'so.order_date',
'external_ref' => 'so.external_ref', 'external_ref' => 'so.external_ref',
'last_name' => 'COALESCE(ad.last_name, \'\')', 'name' => 'COALESCE(ad.first_name, \'\') || \' \' || COALESCE(ad.last_name, \'\')',
'first_name' => 'COALESCE(ad.first_name, \'\')',
'total_amount' => 'COALESCE(so.total_amount, 0)', 'total_amount' => 'COALESCE(so.total_amount, 0)',
]; ];
$sortExpression = $sortExpressions[$sortColumn] ?? 'so.order_date'; $sortExpression = $sortExpressions[$sortColumn] ?? 'so.order_date';
+35 -16
View File
@@ -64,8 +64,7 @@ function auth_render_bestellungen_large_table(array $bestellungenTable): string
$sortColumns = [ $sortColumns = [
'order_date' => 'Bestelldatum', 'order_date' => 'Bestelldatum',
'external_ref' => 'Bestellnummer', 'external_ref' => 'Bestellnummer',
'last_name' => 'Nachname', 'name' => 'Name',
'first_name' => 'Vorname',
'total_amount' => 'Gesamtsumme', '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); $totalAmount = auth_format_bestellung_total(isset($row['total_amount']) ? (float) $row['total_amount'] : null);
$firstName = (string) ($row['first_name'] ?? ''); $firstName = (string) ($row['first_name'] ?? '');
$lastName = (string) ($row['last_name'] ?? ''); $lastName = (string) ($row['last_name'] ?? '');
$name = trim($firstName . ' ' . $lastName);
$street = (string) ($row['street'] ?? ''); $street = (string) ($row['street'] ?? '');
$houseNumber = (string) ($row['house_number'] ?? ''); $houseNumber = (string) ($row['house_number'] ?? '');
$zip = (string) ($row['zip'] ?? ''); $zip = (string) ($row['zip'] ?? '');
@@ -129,8 +129,7 @@ function auth_render_bestellungen_large_table(array $bestellungenTable): string
$html[] = '<div class="sg-large-table__cell" role="cell">'; $html[] = '<div class="sg-large-table__cell" role="cell">';
$html[] = '<a class="sg-hyperlink" href="#" aria-haspopup="dialog" aria-expanded="false" data-order-drawer-open="true" data-order-id="' . (int) ($row['id'] ?? 0) . '" data-order-number="' . auth_escape_html($orderNumber) . '" data-order-date="' . auth_escape_html($orderDate) . '" data-order-total="' . auth_escape_html($totalAmount) . '" data-order-first-name="' . auth_escape_html($firstName) . '" data-order-last-name="' . auth_escape_html($lastName) . '" data-order-street="' . auth_escape_html($street) . '" data-order-house-number="' . auth_escape_html($houseNumber) . '" data-order-zip="' . auth_escape_html($zip) . '" data-order-city="' . auth_escape_html($city) . '" data-order-country="' . auth_escape_html($country) . '">' . auth_escape_html($orderNumber) . '</a>'; $html[] = '<a class="sg-hyperlink" href="#" aria-haspopup="dialog" aria-expanded="false" data-order-drawer-open="true" data-order-id="' . (int) ($row['id'] ?? 0) . '" data-order-number="' . auth_escape_html($orderNumber) . '" data-order-date="' . auth_escape_html($orderDate) . '" data-order-total="' . auth_escape_html($totalAmount) . '" data-order-first-name="' . auth_escape_html($firstName) . '" data-order-last-name="' . auth_escape_html($lastName) . '" data-order-street="' . auth_escape_html($street) . '" data-order-house-number="' . auth_escape_html($houseNumber) . '" data-order-zip="' . auth_escape_html($zip) . '" data-order-city="' . auth_escape_html($city) . '" data-order-country="' . auth_escape_html($country) . '">' . auth_escape_html($orderNumber) . '</a>';
$html[] = '</div>'; $html[] = '</div>';
$html[] = '<div class="sg-large-table__cell" role="cell">' . auth_escape_html($lastName) . '</div>'; $html[] = '<div class="sg-large-table__cell" role="cell">' . auth_escape_html($name) . '</div>';
$html[] = '<div class="sg-large-table__cell" role="cell">' . auth_escape_html($firstName) . '</div>';
$html[] = '<div class="sg-large-table__cell" role="cell">' . auth_escape_html($totalAmount) . '</div>'; $html[] = '<div class="sg-large-table__cell" role="cell">' . auth_escape_html($totalAmount) . '</div>';
$html[] = '</div>'; $html[] = '</div>';
} }
@@ -505,24 +504,43 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best
echo "function initBestellungenBindings() {"; echo "function initBestellungenBindings() {";
echo " const contentRoot = document.querySelector('[data-left-navigation-content-body]');"; echo " const contentRoot = document.querySelector('[data-left-navigation-content-body]');";
echo " if (!contentRoot) { return; }"; 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 " if (!table) { return; }";
echo " let searchTimer = null;"; echo " let searchTimer = null;";
echo " let requestToken = 0;"; 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 getSearchWrap = () => {";
echo " const input = getSearchInput();"; echo " const input = getSearchInput();";
echo " return input ? input.closest('[data-component=\\'single-line-input\\']') : null;"; echo " return input ? input.closest('[data-component=\\'single-line-input\\']') : null;";
echo " };"; 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 getSearchValue = () => {";
echo " const input = getSearchInput();"; echo " const input = getSearchInput();";
echo " return input ? input.value.trim() : '';"; echo " return input ? input.value.trim() : '';";
echo " };"; echo " };";
echo " const getSortColumn = () => table.dataset.bestellungenSortColumn || 'order_date';"; echo " const getSortColumn = () => {";
echo " const getSortDirection = () => (table.dataset.bestellungenSortDirection || 'DESC').toUpperCase();"; echo " const currentTable = getTable();";
echo " const getCurrentLimit = () => parseInt(table.dataset.bestellungenLimit || table.dataset.bestellungenPageSize || '20', 10);"; echo " return currentTable ? (currentTable.dataset.bestellungenSortColumn || 'order_date') : 'order_date';";
echo " const getPageSize = () => parseInt(table.dataset.bestellungenPageSize || '20', 10);"; 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 syncSearchState = () => {";
echo " const input = getSearchInput();"; echo " const input = getSearchInput();";
echo " const wrap = getSearchWrap();"; echo " const wrap = getSearchWrap();";
@@ -592,14 +610,15 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best
echo " return false;"; echo " return false;";
echo " }"; echo " }";
echo " contentRoot.innerHTML = fragment.innerHTML;"; echo " contentRoot.innerHTML = fragment.innerHTML;";
echo " table = contentRoot.querySelector('[data-bestellungen-large-table]');"; echo " table = getTable();";
echo " return !!table;"; echo " return !!table;";
echo " };"; echo " };";
echo " const loadFragment = async (params, updateHistory = true) => {"; echo " const loadFragment = async (params, updateHistory = true) => {";
echo " if (searchTimer) { window.clearTimeout(searchTimer); searchTimer = null; }"; echo " if (searchTimer) { window.clearTimeout(searchTimer); searchTimer = null; }";
echo " const url = buildUrl(params);"; echo " const url = buildUrl(params);";
echo " const activeRequest = ++requestToken;"; 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 " try {";
echo " const response = await fetch(url.toString(), { headers: { 'X-Requested-With': 'XMLHttpRequest' } });"; echo " const response = await fetch(url.toString(), { headers: { 'X-Requested-With': 'XMLHttpRequest' } });";
echo " const html = await response.text();"; echo " const html = await response.text();";
@@ -607,7 +626,7 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best
echo " return;"; echo " return;";
echo " }"; echo " }";
echo " const replaced = replaceFragment(html);"; echo " const replaced = replaceFragment(html);";
echo " table = contentRoot.querySelector('[data-bestellungen-large-table]');"; echo " table = getTable();";
echo " if (replaced && updateHistory) {"; echo " if (replaced && updateHistory) {";
echo " const historyUrl = new URL(url.toString());"; echo " const historyUrl = new URL(url.toString());";
echo " historyUrl.searchParams.delete('bestellungen_fragment');"; echo " historyUrl.searchParams.delete('bestellungen_fragment');";
@@ -616,7 +635,7 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best
echo " bindTable();"; echo " bindTable();";
echo " } finally {"; echo " } finally {";
echo " if (activeRequest === requestToken) {"; echo " if (activeRequest === requestToken) {";
echo " table = contentRoot.querySelector('[data-bestellungen-large-table]');"; echo " table = getTable();";
echo " if (table) {"; echo " if (table) {";
echo " table.removeAttribute('aria-busy');"; echo " table.removeAttribute('aria-busy');";
echo " }"; echo " }";
@@ -624,7 +643,7 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best
echo " }"; echo " }";
echo " };"; echo " };";
echo " const bindTable = () => {"; echo " const bindTable = () => {";
echo " table = contentRoot.querySelector('[data-bestellungen-large-table]');"; echo " table = getTable();";
echo " if (!table) { return; }"; echo " if (!table) { return; }";
echo " const searchInput = getSearchInput();"; echo " const searchInput = getSearchInput();";
echo " const clearButton = getClearButton();"; echo " const clearButton = getClearButton();";