M3 Integration fixes

This commit is contained in:
Mark Gregory
2026-09-21 13:33:05 +01:00
parent 3521e47ef0
commit 66aeefbba5
23 changed files with 674 additions and 691 deletions
+17 -21
View File
@@ -313,7 +313,7 @@ class Helper
public static function getUserCOWHSPLT()
{
$defaults = [
$result = [
'UserCO' => '',
'UserWHS' => '',
'UserPL' => '',
@@ -321,32 +321,28 @@ class Helper
$loggedUser = strtoupper(trim((string) m3User()));
if ($loggedUser === '') {
return $defaults;
return $result;
}
try {
if (! Schema::connection(config('m3.connection', 'pgsql'))->hasTable('icm428m')) {
return $defaults;
if (Schema::connection(config('m3.connection', 'pgsql'))->hasTable('icm428m')) {
$user = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
->select('R428US', 'R428ADMUSR', 'R428PWRUSR', 'R428CO', 'R428PL', 'R428WH', 'R42811A', 'R42821A')
->where('R428US', $loggedUser)
->first();
if ($user) {
$result = [
'UserCO' => trim((string) ($user->R428CO ?? '')),
'UserWHS' => trim((string) ($user->R428WH ?? '')),
'UserPL' => trim((string) ($user->R428PL ?? '')),
];
}
}
$user = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
->select('R428US', 'R428ADMUSR', 'R428PWRUSR', 'R428CO', 'R428PL', 'R428WH', 'R42811A', 'R42821A')
->where('R428US', $loggedUser)
->first();
if (! $user) {
return $defaults;
}
return [
'UserCO' => trim((string) ($user->R428CO ?? '')),
'UserWHS' => trim((string) ($user->R428WH ?? '')),
'UserPL' => trim((string) ($user->R428PL ?? '')),
];
} catch (\Throwable $e) {
\Illuminate\Support\Facades\Log::warning('M3 user context unavailable', ['exception' => $e->getMessage()]);
return $defaults;
}
return $result;
}
}