m3 Security Fixes
This commit is contained in:
@@ -2,44 +2,44 @@
|
||||
|
||||
namespace Modules\M3\Http\Controllers;
|
||||
|
||||
use DB;
|
||||
use Config;
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class userPickingStats4 extends Controller
|
||||
{
|
||||
|
||||
public static function index(Request $request)
|
||||
{
|
||||
|
||||
#$start = microtime(true);
|
||||
#dd($request);
|
||||
// $start = microtime(true);
|
||||
// dd($request);
|
||||
// Filter by date
|
||||
if (isset($request->dates)) {
|
||||
$date = $request->dates;
|
||||
$starting = $date;
|
||||
} else {
|
||||
$starting = date("Y-m-d", strtotime("-1 days"));
|
||||
$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'));
|
||||
// #$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'));
|
||||
// #$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
|
||||
// $user_array = Config::get('arrays.user_array');
|
||||
// 618
|
||||
// Get Logged User CO & WH
|
||||
// Get Users from ICM428M
|
||||
$co = '';
|
||||
$whs = '';
|
||||
$ICM428M = [];
|
||||
$schema = \Illuminate\Support\Facades\Schema::connection(config('m3.connection', 'pgsql'));
|
||||
$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()))
|
||||
->select('R428US', 'R428CO', 'R428WH')
|
||||
->where('R428US', '=', strtoupper(m3_user()))
|
||||
->first();
|
||||
$co = $profile->R428CO ?? '';
|
||||
$whs = $profile->R428WH ?? '';
|
||||
@@ -50,22 +50,22 @@ class userPickingStats4 extends Controller
|
||||
->where('R428CO', $co)->where('R428WH', $whs)->get()->all();
|
||||
}
|
||||
|
||||
$user_array=array();
|
||||
#while($row = odbc_fetch_object($result)) {
|
||||
$x=0;
|
||||
foreach($ICM428M as $key=>$row) {
|
||||
$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;
|
||||
$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 "<pre>"; print_r($user_array); echo "</pre>";
|
||||
// echo "<pre>"; print_r($user_array); echo "</pre>";
|
||||
if (isset($request->user)) {
|
||||
$user = $request->user;
|
||||
$empno = 0;
|
||||
@@ -76,14 +76,14 @@ class userPickingStats4 extends Controller
|
||||
}
|
||||
} else {
|
||||
$empno = 0;
|
||||
$user = "";
|
||||
$user = '';
|
||||
}
|
||||
|
||||
// get data from LBPF for user and day
|
||||
$payrollCodes = "";
|
||||
$payrollCodes = '';
|
||||
ksort($lph_per_monitor_array);
|
||||
foreach ($lph_per_monitor_array as $key => $val) {
|
||||
$payrollCodes .= $key . ",";
|
||||
$payrollCodes .= $key . ',';
|
||||
}
|
||||
$payrollCodes = substr($payrollCodes, 0, -1);
|
||||
|
||||
@@ -95,7 +95,7 @@ class userPickingStats4 extends Controller
|
||||
and oppno in ($payrollCodes)
|
||||
group by oppno";
|
||||
|
||||
#echo "$sqlstmt<br>";
|
||||
// echo "$sqlstmt<br>";
|
||||
|
||||
$lbpf1 = $schema->hasTable('lbpf')
|
||||
? DB::connection(config('m3.connection', 'pgsql'))->select($sqlstmt)
|
||||
@@ -107,62 +107,62 @@ class userPickingStats4 extends Controller
|
||||
}
|
||||
|
||||
$sql = "select * from perfstat where dt='$starting' and a5pickcomu='$user' ";
|
||||
#@dd($sql);
|
||||
// @dd($sql);
|
||||
|
||||
if ((isset($request->dates) || isset($request->user)) && $schema->hasTable('perfstat')) {
|
||||
$statistic4 = DB::connection(config('m3.connection', 'pgsql'))->select($sql);
|
||||
} else {
|
||||
$statistic4 = array();
|
||||
$statistic4 = [];
|
||||
}
|
||||
|
||||
#echo "<pre>"; print_r($statistic4); echo "</pre>";
|
||||
// echo "<pre>"; print_r($statistic4); echo "</pre>";
|
||||
|
||||
#$duration = microtime(true) - $start;
|
||||
// $duration = microtime(true) - $start;
|
||||
|
||||
// initialize arrays
|
||||
$monitor_array = $totals_array = $perf_array = array();
|
||||
$totals_array["value"] = 0;
|
||||
$totals_array["weight"] = 0;
|
||||
$totals_array["timediff"] = 0;
|
||||
$totals_array["picked"] = 0;
|
||||
$totals_array["entries"] = 0;
|
||||
$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 "<pre>"; print_r($lbpf1); echo "</pre>";
|
||||
// echo "<pre>"; print_r($lbpf1); echo "</pre>";
|
||||
|
||||
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]['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;
|
||||
$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<br>";
|
||||
if (! empty($statistic4)) {
|
||||
// echo "in !empty<br>";
|
||||
// Initialize the Monitor array
|
||||
foreach ($statistic4 as $key => $val) {
|
||||
|
||||
// Initialize these variables in case not existant in LBPF
|
||||
$monitor_array[$val->CODE]['header'] = "Mon" . $statistic4[$key]->CODE;
|
||||
$monitor_array[$val->CODE]['header'] = 'Mon' . $statistic4[$key]->CODE;
|
||||
$monitor_array[$val->CODE]['timediff'] = 0;
|
||||
$monitor_array[$val->CODE]["percent_per_monitor"] = 0;
|
||||
$monitor_array[$val->CODE]["percent_per_activity"] = 0;
|
||||
$monitor_array[$val->CODE]["lph_blended_per_activity"] = 0;
|
||||
$monitor_array[$val->CODE]["picked"] = 0;
|
||||
$monitor_array[$val->CODE]["weight"] = 0;
|
||||
$monitor_array[$val->CODE]["lines"] = 0;
|
||||
$monitor_array[$val->CODE]['percent_per_monitor'] = 0;
|
||||
$monitor_array[$val->CODE]['percent_per_activity'] = 0;
|
||||
$monitor_array[$val->CODE]['lph_blended_per_activity'] = 0;
|
||||
$monitor_array[$val->CODE]['picked'] = 0;
|
||||
$monitor_array[$val->CODE]['weight'] = 0;
|
||||
$monitor_array[$val->CODE]['lines'] = 0;
|
||||
}
|
||||
#echo "after 1st init<br>";
|
||||
// echo "after 1st init<br>";
|
||||
|
||||
// add another element (0) in monitor_array to capture the total blended lph value expected
|
||||
$monitor_array[0]["lph_blended_per_activity"] = 0;
|
||||
$monitor_array[0]['header'] = "0";
|
||||
$monitor_array[0]['lph_blended_per_activity'] = 0;
|
||||
$monitor_array[0]['header'] = '0';
|
||||
|
||||
// cycle thru stats again, and accumulate totals at global level (totals_array) and at monitor level (monitor_array)
|
||||
foreach ($statistic4 as $key => $val) {
|
||||
@@ -174,7 +174,7 @@ class userPickingStats4 extends Controller
|
||||
$statistic4[$key]->A5PICKCMTS = date('Y-m-d H:i', strtotime($statistic4[$key]->A5PICKCMTS));
|
||||
|
||||
// Calculate difference from previous time entry in seconds and save in TIMEDIFF key of STATISTIC4 array
|
||||
# $time_now=strtotime($statistic4[$key]->A5PICKCMTSADJ);
|
||||
// $time_now=strtotime($statistic4[$key]->A5PICKCMTSADJ);
|
||||
$time_now = strtotime($statistic4[$key]->A5CMTSADJ);
|
||||
if ($key > 0) {
|
||||
$diff = round(abs($time_now - $time_prev));
|
||||
@@ -186,20 +186,20 @@ class userPickingStats4 extends Controller
|
||||
$statistic4[$key]->TIMEDIFF = $diff;
|
||||
|
||||
if ($diff / 60 < 5) {
|
||||
$statistic4[$key]->COLOUR = "";
|
||||
$statistic4[$key]->COLOUR = '';
|
||||
}
|
||||
if ($diff / 60 >= 5 && $diff / 60 <= 10) {
|
||||
$statistic4[$key]->COLOUR = "yellow";
|
||||
$statistic4[$key]->COLOUR = 'yellow';
|
||||
}
|
||||
if ($diff / 60 > 10 && $diff / 60 <= 15) {
|
||||
$statistic4[$key]->COLOUR = "#88ace0";
|
||||
$statistic4[$key]->COLOUR = '#88ace0';
|
||||
}
|
||||
if ($diff / 60 > 15) {
|
||||
$statistic4[$key]->COLOUR = "red";
|
||||
$statistic4[$key]->COLOUR = 'red';
|
||||
}
|
||||
|
||||
// save the time for previous entry
|
||||
# $time_prev=strtotime($statistic4[$key]->A5PICKCMTSADJ);
|
||||
// $time_prev=strtotime($statistic4[$key]->A5PICKCMTSADJ);
|
||||
$time_prev = strtotime($statistic4[$key]->A5CMTSADJ);
|
||||
|
||||
// accumulate totals at monitor level
|
||||
@@ -208,26 +208,25 @@ class userPickingStats4 extends Controller
|
||||
$monitor_array[$val->CODE]['weight'] += $statistic4[$key]->WEIGHT;
|
||||
$monitor_array[$val->CODE]['lines']++;
|
||||
|
||||
|
||||
// calculate totals at global level
|
||||
$totals_array["entries"] = count($statistic4);
|
||||
$totals_array["weight"] += $statistic4[$key]->WEIGHT;
|
||||
$totals_array["value"] += $statistic4[$key]->A5VALUE;
|
||||
$totals_array["timediff"] += $diff;
|
||||
$totals_array["picked"] += $statistic4[$key]->A5PICKED;
|
||||
$totals_array['entries'] = count($statistic4);
|
||||
$totals_array['weight'] += $statistic4[$key]->WEIGHT;
|
||||
$totals_array['value'] += $statistic4[$key]->A5VALUE;
|
||||
$totals_array['timediff'] += $diff;
|
||||
$totals_array['picked'] += $statistic4[$key]->A5PICKED;
|
||||
|
||||
}
|
||||
#echo "after 2<pre>"; print_r($statistic4);
|
||||
// echo "after 2<pre>"; 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)) {
|
||||
if (! is_null($lbpf)) {
|
||||
|
||||
$perf_array["tot_hours"] = (isset($lbpf) ? $lbpf : 0);
|
||||
$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"];
|
||||
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;
|
||||
$perf_array['per_hour_actual'] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -235,85 +234,85 @@ class userPickingStats4 extends Controller
|
||||
// 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 ($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 ($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;
|
||||
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"];
|
||||
$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"];
|
||||
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 "<pre>";
|
||||
#print_r($request);
|
||||
#print_r($perf_array); print_r($monitor_array);
|
||||
// echo "<pre>";
|
||||
// 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 ($request->format == 'json') {
|
||||
|
||||
if (!array_key_exists("performance_activity", $perf_array)) {
|
||||
if (! array_key_exists('performance_activity', $perf_array)) {
|
||||
$performance = 0;
|
||||
} else {
|
||||
$performance = number_format($perf_array["performance_activity"] * 100, 0);
|
||||
$performance = number_format($perf_array['performance_activity'] * 100, 0);
|
||||
}
|
||||
if (!array_key_exists("0", $monitor_array)) {
|
||||
if (! array_key_exists('0', $monitor_array)) {
|
||||
$blendedTargetLPH = 0;
|
||||
} else {
|
||||
$blendedTargetLPH = number_format($monitor_array[0]["lph_blended_per_activity"], 1);
|
||||
$blendedTargetLPH = number_format($monitor_array[0]['lph_blended_per_activity'], 1);
|
||||
}
|
||||
if (!array_key_exists("per_hour_actual", $perf_array)) {
|
||||
if (! array_key_exists('per_hour_actual', $perf_array)) {
|
||||
$actualLPH = 0;
|
||||
} else {
|
||||
$actualLPH = number_format($perf_array["per_hour_actual"], 1);
|
||||
$actualLPH = number_format($perf_array['per_hour_actual'], 1);
|
||||
}
|
||||
if (!array_key_exists("tot_hours", $perf_array)) {
|
||||
if (! array_key_exists('tot_hours', $perf_array)) {
|
||||
$grossHours = 0;
|
||||
} else {
|
||||
$grossHours = $perf_array["tot_hours"];
|
||||
$grossHours = $perf_array['tot_hours'];
|
||||
}
|
||||
|
||||
$json_data = array(
|
||||
"day" => $starting,
|
||||
"performance" => $performance,
|
||||
"blendedTargetLPH" => $blendedTargetLPH,
|
||||
"actualLPH" => $actualLPH,
|
||||
"grossHours" => $grossHours
|
||||
);
|
||||
#echo "<pre>"; print_r($json_data);
|
||||
$json_data = [
|
||||
'day' => $starting,
|
||||
'performance' => $performance,
|
||||
'blendedTargetLPH' => $blendedTargetLPH,
|
||||
'actualLPH' => $actualLPH,
|
||||
'grossHours' => $grossHours,
|
||||
];
|
||||
|
||||
// echo "<pre>"; 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";
|
||||
$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");
|
||||
// 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')
|
||||
compact('statistic4', 'starting', 'user', 'user_array', 'monitor_array', 'totals_array', 'perf_array', 'request', 'no_data'),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user