$value !== null && $value !== '' ); $path = auth_current_path(); $queryString = http_build_query($query, '', '&', PHP_QUERY_RFC3986); return $queryString === '' ? $path : $path . '?' . $queryString; } function auth_format_bestellung_date(?string $value): string { if ($value === null || $value === '') { return ''; } try { return (new DateTimeImmutable($value))->format('d.m.Y H:i'); } catch (Throwable) { return $value; } } function auth_format_bestellung_total(?float $value): string { if ($value === null) { return ''; } return 'CHF ' . number_format($value, 2, '.', '\''); } function auth_render_bestellungen_large_table(array $bestellungenTable): string { $rows = $bestellungenTable['rows'] ?? []; $search = (string) ($bestellungenTable['search'] ?? ''); $sortColumn = (string) ($bestellungenTable['sort_column'] ?? 'order_date'); $sortDirection = strtoupper((string) ($bestellungenTable['sort_direction'] ?? 'DESC')); $limit = (int) ($bestellungenTable['limit'] ?? 20); $pageSize = (int) ($bestellungenTable['page_size'] ?? 20); $hasMore = (bool) ($bestellungenTable['has_more'] ?? false); $nextLimit = (int) ($bestellungenTable['next_limit'] ?? $limit); $sortColumns = [ 'order_date' => 'Bestelldatum', 'external_ref' => 'Bestellnummer', 'name' => 'Name', 'total_amount' => 'Gesamtsumme', ]; $html = []; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = '
Bestellungen
'; $html[] = ''; $html[] = ''; $html[] = ''; $html[] = ''; $html[] = ''; $html[] = ''; $html[] = '
'; $html[] = '
'; $headerIndex = 0; foreach ($sortColumns as $column => $label) { $isActive = $column === $sortColumn; $headerDirection = $isActive ? strtolower($sortDirection) : 'none'; $iconDirection = $isActive ? strtolower($sortDirection) : 'ascending'; $ariaLabel = $isActive ? $label . ' ' . ($sortDirection === 'ASC' ? 'aufsteigend sortiert' : 'absteigend sortiert') : $label . ' sortieren'; $targetDirection = $isActive ? ($sortDirection === 'ASC' ? 'DESC' : 'ASC') : ($column === 'order_date' ? 'DESC' : 'ASC'); $amountHeaderClass = $column === 'total_amount' ? ' sg-large-table__cell--amount' : ''; $html[] = '
'; $html[] = ''; $html[] = '
'; $headerIndex++; } $html[] = '
'; foreach ($rows as $index => $row) { $isStriped = $index % 2 === 1; $rowClass = 'sg-card-segment sg-card-segment--body sg-card-segment--white sg-large-table__row'; if ($isStriped) { $rowClass .= ' sg-large-table__row--striped-light'; } $orderNumber = (string) ($row['external_ref'] ?? ''); $orderDate = auth_format_bestellung_date((string) ($row['order_date'] ?? '')); $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'] ?? ''); $city = (string) ($row['city'] ?? ''); $country = (string) ($row['country_name'] ?? ''); $html[] = '
'; $html[] = '
' . auth_escape_html($orderDate) . '
'; $html[] = '
'; $html[] = ''; $html[] = '
'; $html[] = '
' . auth_escape_html($name) . '
'; $html[] = '
' . auth_escape_html($totalAmount) . '
'; $html[] = '
'; } if ($hasMore) { $loadMoreUrl = auth_build_path_with_query([ 'bestellungen_search' => $search !== '' ? $search : null, 'bestellungen_sort' => $sortColumn, 'bestellungen_dir' => $sortDirection, 'bestellungen_limit' => $nextLimit, ]); $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = 'Mehr laden'; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = '
'; } $html[] = '
'; $html[] = '
'; $html[] = ''; $html[] = ''; return implode('', $html); } function auth_render_bestellungen_content(array $bestellungenTable): string { return '
' . '
' . auth_render_bestellungen_large_table($bestellungenTable) . '
'; } function render_auth_home_page(array $user, array $otcProducts = [], array $bestellungenTable = []): void { $otcProductRows = ''; foreach ($otcProducts as $product) { $productId = (int) ($product['id'] ?? 0); $productName = auth_escape_html((string) ($product['name'] ?? '')); $availableQty = (int) max(0, (int) round((float) ($product['available_qty'] ?? 0))); $inputId = 'otc-product-' . $productId; $otcProductRows .= '
'; $otcProductRows .= ''; $otcProductRows .= ''; $otcProductRows .= '
'; } if ($otcProductRows === '') { $otcProductRows = '

Keine verfügbaren Produkte im Lager.

'; } $moduleNavigation = json_encode( [ 'Übersicht' => [], 'ERP' => ['Bestellungen', 'Lager', 'Produkte', 'Artikel', 'Kontakte'], 'Buchhaltung' => [], 'Kundenberatung' => [], ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); $bestellungenContent = auth_render_bestellungen_content($bestellungenTable); $moduleContentCards = json_encode( [ 'Bestellungen' => $bestellungenContent, ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); $moduleHeadings = json_encode( [ 'Übersicht' => 'Willkommen bei Naurua Übersicht', 'ERP' => 'Willkommen bei Naurua ERP', 'Buchhaltung' => 'Willkommen bei Naurua Buchhaltung', 'Kundenberatung' => 'Willkommen bei Naurua Kundenberatung', ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); echo ''; echo ''; echo ''; echo ''; echo ''; echo 'Naurua ERP'; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '
'; echo '
'; echo '
'; echo '

Naurua ERP

'; echo '
'; echo ''; echo '
'; echo 'Startseite'; echo 'Abmelden'; echo '
'; echo '
'; echo ''; echo '
'; echo '
'; echo '
'; echo '
'; echo '

Willkommen bei Naurua ERP

'; echo '
'; echo '
'; echo '
'; echo ''; echo ''; echo '
'; echo '
'; echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; }