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 ?? ''));
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) {
Log::warning('M3 picking user list unavailable', ['exception' => $e->getMessage()]);
$user_array = [];
}
// Filter by date
if (isset($request->dates)) {
$date = explode(' - ', $request->dates);
$start = str_replace([' ', '-'], '', $date[0]);
$end = str_replace([' ', '-'], '', $date[1]);
$starting = $date[0];
$ending = $date[1];
} else {
$start = date('Ymd', strtotime('-5 days'));
$end = date('Ymd');
$starting = date('Y-m-d', strtotime('-5 days'));
// $starting = "2021-11-01";
$ending = date('Y-m-d');
}
// calculate day difference between 2 dates
$str_date = new DateTime($starting);
$end_date = new DateTime($ending);
$interval = $str_date->diff($end_date);
$days = $interval->format('%a'); // retrieve number of days %a
// echo "diff=$days
";
$user = $request->user;
// retrieve session user and pw, also the HTTP server host address and port
$username = $request->header('php-auth-user');
$pw = $request->header('php-auth-pw');
$http_host = $request->server('HTTP_HOST');
$urlStats4 = "http://$http_host/userPickingStats4";
// initialize arrays
$statistic5 = $totals_array = [];
// initialize totals
$totals_array['performance'] = 0;
$totals_array['blendedTargetLPH'] = 0;
$totals_array['actualLPH'] = 0;
$totals_array['grossHours'] = 0;
$y = 0;
// loop for the days difference and passing proper date to v4 to get json encoded response
if (isset($request->dates)) {
for ($x = 0; $x <= $days; $x++) {
$next_date = date('Y-m-d', strtotime($starting . "+$x days"));
$parameters = ['dates' => $next_date, 'user' => $request->user, 'format' => 'json'];
// echo "
"; print_r($parameters); echo "$urlStats4"; $response = Http::withBasicAuth($username, $pw)->get($urlStats4, $parameters); // echo $response; $statusCode = $response->status(); // echo "$statusCode json return=".$response->getBody()."
';
print_r($statistic5);
echo '';
} else {
// dd($statistic5);
// if($statistic5[1]!=null)
return view('m3::liberty-theme.pages.userPickingStats5', compact('statistic5', 'totals_array', 'user_array', 'user', 'starting', 'ending', 'request'));
}
}
}