Wykrywanie imienia i nazwiska kelnera oraz info czy sesja dostala sie do aplikacji
This commit is contained in:
74
api/resolve_table_operator.php
Normal file
74
api/resolve_table_operator.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
function tableNameMatchesBill(string $tableParam, string $stolikNazwa, string $opis): bool
|
||||
{
|
||||
if ($tableParam === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$normalizedTableParam = str_replace('o', '0', strtolower($tableParam));
|
||||
$normalizedStolikNazwa = str_replace('o', '0', strtolower($stolikNazwa));
|
||||
$normalizedOpis = str_replace('o', '0', strtolower($opis));
|
||||
|
||||
if (
|
||||
$normalizedStolikNazwa === $normalizedTableParam ||
|
||||
$normalizedOpis === $normalizedTableParam
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$pattern = '/\b' . preg_quote($normalizedTableParam, '/') . '\b/i';
|
||||
|
||||
return (bool) (preg_match($pattern, $normalizedStolikNazwa) || preg_match($pattern, $normalizedOpis));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{imie: string, nazwisko: string, nick: string}
|
||||
*/
|
||||
function resolveOperatorForTable($conn, string $tableParam): array
|
||||
{
|
||||
$empty = ['imie' => '', 'nazwisko' => '', 'nick' => ''];
|
||||
if (!$conn || $tableParam === '') {
|
||||
return $empty;
|
||||
}
|
||||
|
||||
$tsql = "
|
||||
SELECT
|
||||
s.Nazwa AS NazwaStolika,
|
||||
r.Opis,
|
||||
o.Imie,
|
||||
o.Nazwisko,
|
||||
o.Nick
|
||||
FROM dbo.NGastroDTRachunek r
|
||||
LEFT JOIN dbo.NGastroStolik s ON s.ID = r.StolikID
|
||||
LEFT JOIN dbo.NGastroUzytkownik u ON u.ID = r.UzytkownikOtwierajacyID
|
||||
LEFT JOIN dbo.NSysOperator o ON o.ID = u.OperatorID
|
||||
WHERE CAST(r.DataOtwarcia AS DATE) = CAST(GETDATE() AS DATE)
|
||||
AND r.Status = 0
|
||||
";
|
||||
|
||||
$stmt = sqlsrv_query($conn, $tsql);
|
||||
if ($stmt === false) {
|
||||
return $empty;
|
||||
}
|
||||
|
||||
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
|
||||
$stolikNazwa = (string) ($row['NazwaStolika'] ?? '');
|
||||
$opis = (string) ($row['Opis'] ?? '');
|
||||
if (!tableNameMatchesBill($tableParam, $stolikNazwa, $opis)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
return [
|
||||
'imie' => trim((string) ($row['Imie'] ?? '')),
|
||||
'nazwisko' => trim((string) ($row['Nazwisko'] ?? '')),
|
||||
'nick' => trim((string) ($row['Nick'] ?? '')),
|
||||
];
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
return $empty;
|
||||
}
|
||||
Reference in New Issue
Block a user