dates)) { $date = $request->dates; $starting = $date; } else { $starting = date('Y-m-d', strtotime('-1 days')); } // #$min_work_hours_for_break = 4; $min_work_hours_for_break = implode(',', Config::get('arrays.min_work_hours_for_break')); // #$ignore_picks_that_last_longer_than_this_many_hours = 8; $ignore_picks_that_last_longer_than_this_many_hours = implode(',', Config::get('arrays.ignore_picks_that_last_longer_than_this_many_hours')); // $user_array = Config::get('arrays.user_array'); // 618 // Get Logged User CO & WH // Get Users from ICM428M $co = ''; $whs = ''; $ICM428M = []; $schema = 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 = []; // while($row = odbc_fetch_object($result)) { $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++; } array_multisort(array_column($user_array, 'name'), SORT_ASC, $user_array); // fill array of Lines per Hour per Monitor $lph_per_monitor_array = Config::get('arrays_custom.lph_per_code_array'); // echo "
"; print_r($user_array); echo ""; if (isset($request->user)) { $user = $request->user; $empno = 0; foreach ($user_array as $key => $val) { if ($user_array[$key]['userprf'] == $user) { $empno = $user_array[$key]['empno']; } } } else { $empno = 0; $user = ''; } // get data from LBPF for user and day $payrollCodes = ''; ksort($lph_per_monitor_array); foreach ($lph_per_monitor_array as $key => $val) { $payrollCodes .= $key . ','; } $payrollCodes = substr($payrollCodes, 0, -1); $yr = substr($starting, 0, 4) - 2000; $mth = substr($starting, 5, 2); $day = substr($starting, 8, 2); $sqlstmt = "select oppno, sum(cast (hrs as integer)+ (hrs-cast (hrs as integer))/0.6) as hrs from LBPF where empno=$empno and lbyr=$yr and lbmo=$mth and lbdy=$day and oppno in ($payrollCodes) group by oppno"; // echo "$sqlstmt
"; print_r($statistic4); echo ""; // $duration = microtime(true) - $start; // initialize arrays $monitor_array = $totals_array = $perf_array = []; $totals_array['value'] = 0; $totals_array['weight'] = 0; $totals_array['timediff'] = 0; $totals_array['picked'] = 0; $totals_array['entries'] = 0; $diff = 0; // echo "
"; print_r($lbpf1); echo ""; foreach ($lbpf1 as $key => $val) { $monitor_array[$val->OPPNO]['tot_hours'] = $val->HRS; // Initialize these variables in case not existant in statistic4 $monitor_array[$val->OPPNO]['header'] = 'Mon' . $val->OPPNO; $monitor_array[$val->OPPNO]['timediff'] = 0; $monitor_array[$val->OPPNO]['percent_per_monitor'] = 0; $monitor_array[$val->OPPNO]['percent_per_activity'] = 0; $monitor_array[$val->OPPNO]['lph_blended_per_activity'] = 0; $monitor_array[$val->OPPNO]['picked'] = 0; $monitor_array[$val->OPPNO]['weight'] = 0; $monitor_array[$val->OPPNO]['lines'] = 0; } if (! empty($statistic4)) { // echo "in !empty
"; print_r($statistic4);
// build array for Performance with Greg's time entry (at one point we had a [0] array as well)
if (! is_null($lbpf)) {
$perf_array['tot_hours'] = (isset($lbpf) ? $lbpf : 0);
if ($perf_array['tot_hours'] != 0) {
$perf_array['per_hour_actual'] = $totals_array['entries'] / $perf_array['tot_hours'];
} else {
$perf_array['per_hour_actual'] = 0;
}
}
// cycle through monitors array and compute percentage to allocate to each monitor (code)
ksort($monitor_array);
foreach ($monitor_array as $key => $val) {
if ($key != '0') {
if (! isset($monitor_array[$key]['tot_hours'])) {
$monitor_array[$key]['tot_hours'] = 0;
}
if ($totals_array['timediff'] != 0) {
$monitor_array[$key]['percent_per_monitor'] = $monitor_array[$key]['timediff'] / $totals_array['timediff'];
}
if ($lbpf != 0) {
$monitor_array[$key]['percent_per_activity'] = $monitor_array[$key]['tot_hours'] / $lbpf;
}
$monitor_array[$key]['lph_blended_per_activity'] = $monitor_array[$key]['percent_per_activity'] * (isset($lph_per_monitor_array[$key]) ? $lph_per_monitor_array[$key] : 0);
$monitor_array[0]['lph_blended_per_activity'] += $monitor_array[$key]['lph_blended_per_activity'];
}
}
if ($monitor_array[0]['lph_blended_per_activity'] != 0) {
$perf_array['performance_activity'] = $perf_array['per_hour_actual'] / $monitor_array[0]['lph_blended_per_activity'];
}
}
// echo "";
// print_r($request);
// print_r($perf_array); print_r($monitor_array);
// return encoded json if input field named format is json
if ($request->format == 'json') {
if (! array_key_exists('performance_activity', $perf_array)) {
$performance = 0;
} else {
$performance = number_format($perf_array['performance_activity'] * 100, 0);
}
if (! array_key_exists('0', $monitor_array)) {
$blendedTargetLPH = 0;
} else {
$blendedTargetLPH = number_format($monitor_array[0]['lph_blended_per_activity'], 1);
}
if (! array_key_exists('per_hour_actual', $perf_array)) {
$actualLPH = 0;
} else {
$actualLPH = number_format($perf_array['per_hour_actual'], 1);
}
if (! array_key_exists('tot_hours', $perf_array)) {
$grossHours = 0;
} else {
$grossHours = $perf_array['tot_hours'];
}
$json_data = [
'day' => $starting,
'performance' => $performance,
'blendedTargetLPH' => $blendedTargetLPH,
'actualLPH' => $actualLPH,
'grossHours' => $grossHours,
];
// echo ""; print_r($json_data);
return json_encode($json_data);
} else {
// display webpage of statistic version 4
$request->ports = Config::get('arrays.env_ports');
$no_data = 'N';
if (count($statistic4) == 0 && $_SERVER['REQUEST_URI'] != '/userPickingStats4') {
$no_data = 'Y';
}
// error_log("Time required to xyz: " . $duration . "\n", 3, "/temp/v4.log");
return view(
'm3::liberty-theme.pages.userPickingStats4',
compact('statistic4', 'starting', 'user', 'user_array', 'monitor_array', 'totals_array', 'perf_array', 'request', 'no_data'),
);
}
}
}