From 0237b1dc2ad6925fff2320f32109a094020e54be Mon Sep 17 00:00:00 2001 From: Mark Gregory Date: Wed, 16 Sep 2026 16:51:59 +0100 Subject: [PATCH] updates to M3 module --- Modules/M3/Helpers/Helper.php | 59 ++++++++++--------- .../Controllers/carrierMaintController.php | 17 ++++-- .../Controllers/execSummaryController.php | 6 ++ .../M3/Http/Controllers/userPickingStats4.php | 30 ++++++---- .../M3/Http/Controllers/userPickingStats5.php | 55 +++++++++-------- resources/views/layouts/app/sidebar.blade.php | 1 - 6 files changed, 99 insertions(+), 69 deletions(-) diff --git a/Modules/M3/Helpers/Helper.php b/Modules/M3/Helpers/Helper.php index 27b62cb3..8ee05fe5 100644 --- a/Modules/M3/Helpers/Helper.php +++ b/Modules/M3/Helpers/Helper.php @@ -343,36 +343,39 @@ class Helper } public static function getUserCOWHSPLT(){ - # Get Current USER - $loggedUser = strtoUpper(m3_user()); - // dump($loggedUser); - $getUsers = DB::connection(config('m3.connection', 'pgsql'))->select("select R428US, R428ADMUSR, R428PWRUSR, R428CO, R428PL, R428WH, R42811A,R42821A from ICM428M where R428US='".$loggedUser."'"); - - foreach ($getUsers as $key=>$user) { - if(trim($user->R428ADMUSR)=="Y") { - # Different logic from Qinclude version : this not an Array - $admin_users=trim($user->R428ADMUSR); - } - if(trim($user->R428PWRUSR)=="Y") { - # Different logic from Qinclude version : this not an Array - $power_users=trim($user->R428PWRUSR); - } - if(trim($user->R42811A)=="C") { - $csr="Y"; - } - if(trim($user->R42821A)=="Y") { - $execUser="Y"; - } - $UserCO = $user->R428CO; - $UserWHS = $user->R428WH; - $UserPL = $user->R428PL; + $defaults = [ + 'UserCO' => '', + 'UserWHS' => '', + 'UserPL' => '', + ]; - $currentUser = [ - 'UserCO' => $UserCO, - 'UserWHS' => $UserWHS, - 'UserPL' => $UserPL, + $loggedUser = strtoupper(trim((string) m3_user())); + if ($loggedUser === '') { + return $defaults; + } + + try { + if (!\Illuminate\Support\Facades\Schema::connection(config('m3.connection', 'pgsql'))->hasTable('icm428m')) { + return $defaults; + } + + $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 ?? '')), ]; - return $currentUser; + } catch (\Throwable $e) { + \Illuminate\Support\Facades\Log::warning('M3 user context unavailable', ['exception' => $e->getMessage()]); + return $defaults; } } diff --git a/Modules/M3/Http/Controllers/carrierMaintController.php b/Modules/M3/Http/Controllers/carrierMaintController.php index 10eb432f..1246bf23 100644 --- a/Modules/M3/Http/Controllers/carrierMaintController.php +++ b/Modules/M3/Http/Controllers/carrierMaintController.php @@ -17,10 +17,19 @@ class carrierMaintController extends Controller public static function index(Request $request) { $currentUser = Helper::getUserCOWHSPLT(); $UserCO = $currentUser['UserCO'] ?? ''; - $ICM160M = DB::connection(config('m3.connection', 'pgsql'))->select(" - select canum, canam, substr(CATPID,1,3) as TwoshipCarrierCode, substr(CATPID,4,1) as ParcelCarrierCode, caspr10A01, caspr1A01 - from icm160m WHERE CACO='$UserCO'"); - $power_user = DB::connection(config('m3.connection', 'pgsql'))->select("select R428PWRUSR, R428CO, R428PL, R428WH from ICM428M where R428US='".strtoUpper(m3_user())."'"); + $ICM160M = []; + $power_user = []; + $schema = \Illuminate\Support\Facades\Schema::connection(config('m3.connection', 'pgsql')); + if ($schema->hasTable('icm160m')) { + $ICM160M = DB::connection(config('m3.connection', 'pgsql'))->select(" + select canum, canam, substr(CATPID,1,3) as TwoshipCarrierCode, substr(CATPID,4,1) as ParcelCarrierCode, caspr10A01, caspr1A01 + from icm160m WHERE CACO=?", [$UserCO]); + } + if ($schema->hasTable('icm428m')) { + $power_user = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m') + ->select('R428PWRUSR', 'R428CO', 'R428PL', 'R428WH') + ->where('R428US', strtoUpper(m3_user()))->get()->all(); + } return view('m3::liberty-theme.pages.carrierMaint', compact('ICM160M','power_user')); } diff --git a/Modules/M3/Http/Controllers/execSummaryController.php b/Modules/M3/Http/Controllers/execSummaryController.php index e0c8a687..3f1bcfdd 100644 --- a/Modules/M3/Http/Controllers/execSummaryController.php +++ b/Modules/M3/Http/Controllers/execSummaryController.php @@ -14,6 +14,12 @@ use Log; class execSummaryController extends Controller { public static function index(Request $request){ + $IC670M = collect(); + $WHDDA = ''; + $COMPANY = '110'; + $PLANT = '144'; + $WHS = '322'; + try { # Ajax Call if ($request->ajax()) { diff --git a/Modules/M3/Http/Controllers/userPickingStats4.php b/Modules/M3/Http/Controllers/userPickingStats4.php index da9d154f..3126afd4 100644 --- a/Modules/M3/Http/Controllers/userPickingStats4.php +++ b/Modules/M3/Http/Controllers/userPickingStats4.php @@ -32,21 +32,25 @@ class userPickingStats4 extends Controller #618 # Get Logged User CO & WH # Get Users from ICM428M - $ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m') - ->select('R428US','R428CO', 'R428WH') - ->where('R428US','=',strtoUpper(m3_user())) - ->first(); - $co = $ICM428M->R428CO; - $whs = $ICM428M->R428WH; + $co = ''; + $whs = ''; + $ICM428M = []; + $schema = \Illuminate\Support\Facades\Schema::connection(config('m3.connection', 'pgsql')); + if ($schema->hasTable('icm428m')) { + $profile = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m') + ->select('R428US','R428CO', 'R428WH') + ->where('R428US','=',strtoUpper(m3_user())) + ->first(); + $co = $profile->R428CO ?? ''; + $whs = $profile->R428WH ?? ''; + + $ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m') + ->selectRaw("R428US as userprf, (trim(R428FIRST) || ' ' || trim(R428FAMILY)) as name, R428EMPCDE as empno") + ->where('R428STS', 'A')->where('R428EMPCDE', '!=', 0) + ->where('R428CO', $co)->where('R428WH', $whs)->get()->all(); + } $user_array=array(); - #$sqlstmt="SELECT R428US as userprf, R428FIRST, R428FAMILY, R428EMPCDE as empno FROM ICM428M where R428EMPCDE!=0"; - $sqlstmt="SELECT R428US as userprf, (trim(R428FIRST) || ' ' || trim(R428FAMILY)) as name, R428EMPCDE as empno FROM ICM428M - where R428STS='A' and R428EMPCDE!=0 and R428CO='$co' and R428WH='$whs'"; - $ICM428M = DB::connection(config('m3.connection', 'pgsql'))->select($sqlstmt); - // ->selectRaw("R428US, (trim(R428FIRST) || ' ' || trim(R428FAMILY)), R428EMPCDE ") - // ->where("R428EMPCDE!=0") - // ->get(); #while($row = odbc_fetch_object($result)) { $x=0; foreach($ICM428M as $key=>$row) { diff --git a/Modules/M3/Http/Controllers/userPickingStats5.php b/Modules/M3/Http/Controllers/userPickingStats5.php index b0155352..bef3e12d 100644 --- a/Modules/M3/Http/Controllers/userPickingStats5.php +++ b/Modules/M3/Http/Controllers/userPickingStats5.php @@ -17,31 +17,40 @@ class userPickingStats5 extends Controller public static function index(Request $request){ #618 - # Get Logged User CO & WH - # Get Users from ICM428M - $ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m') - ->select('R428US','R428CO', 'R428WH') - ->where('R428US','=',strtoUpper(m3_user())) - ->first(); - $co = $ICM428M->R428CO; - $whs = $ICM428M->R428WH; + # Get Logged User CO & WH. Legacy M3 profile data may not yet exist in PostgreSQL. + $co = ''; + $whs = ''; + $user_array = []; + try { + if (\Illuminate\Support\Facades\Schema::connection(config('m3.connection', 'pgsql'))->hasTable('icm428m')) { + $profile = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m') + ->select('R428US','R428CO', 'R428WH') + ->where('R428US', strtoupper((string) m3_user())) + ->first(); + $co = trim((string) ($profile->R428CO ?? '')); + $whs = trim((string) ($profile->R428WH ?? '')); - #@dd($request); - #$user_array=Config::get('arrays.user_array'); - $user_array=array(); - $sqlstmt="SELECT R428US as userprf, (trim(R428FIRST) || ' ' || trim(R428FAMILY)) as name, R428EMPCDE as empno FROM ICM428M - where R428EMPCDE!=0 and R428CO='$co' and R428WH='$whs'"; - $ICM428M = DB::connection(config('m3.connection', 'pgsql'))->select($sqlstmt); - $x=0; - foreach($ICM428M as $key=>$row) { - // print_r($row); - $user_array[$x]['userprf']=trim($row->USERPRF); - #$user_array[$x]['name']=trim($row->R428FIRST)+' '+trim($row->R428FAMILY); - $user_array[$x]['name']=trim($row->NAME); - $user_array[$x]['empno']=$row->EMPNO; - $x++; + if ($co !== '' && $whs !== '') { + $rows = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m') + ->selectRaw("R428US as userprf, (trim(R428FIRST) || ' ' || trim(R428FAMILY)) as name, R428EMPCDE as empno") + ->where('R428EMPCDE', '!=', 0) + ->where('R428CO', $co) + ->where('R428WH', $whs) + ->get(); + foreach ($rows as $row) { + $user_array[] = [ + 'userprf' => trim((string) $row->userprf), + 'name' => trim((string) $row->name), + 'empno' => $row->empno, + ]; + } + array_multisort(array_column($user_array, 'name'), SORT_ASC, $user_array); + } + } + } catch (\Throwable $e) { + \Illuminate\Support\Facades\Log::warning('M3 picking user list unavailable', ['exception' => $e->getMessage()]); + $user_array = []; } - array_multisort(array_column($user_array, 'name'), SORT_ASC, $user_array); // Filter by date if (isset($request->dates)) { diff --git a/resources/views/layouts/app/sidebar.blade.php b/resources/views/layouts/app/sidebar.blade.php index 0712453c..c6d2c327 100644 --- a/resources/views/layouts/app/sidebar.blade.php +++ b/resources/views/layouts/app/sidebar.blade.php @@ -263,7 +263,6 @@ @if (Route::has('m3.userPickingStats4')){{ __('KPI1 Bar') }}@endif @if (Route::has('m3.userPickingStats5')){{ __('KPI1 Line') }}@endif @if (Route::has('m3.execsummary')){{ __('OTTC') }}@endif - @if (Route::has('sentinel-integration.index')){{ __('Sentinel Home') }}@endif @endif @endif