m3 Security Fixes
This commit is contained in:
@@ -2,22 +2,18 @@
|
||||
|
||||
namespace Modules\M3\Http\Controllers;
|
||||
|
||||
use Modules\M3\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Config;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Str;
|
||||
|
||||
class BoxPackToPalletController extends Controller
|
||||
{
|
||||
|
||||
public static function index(Request $request)
|
||||
{
|
||||
return view('m3::liberty-theme.pages.BoxPackToPallet');
|
||||
}
|
||||
|
||||
# Load Existing Boxes from ICM659M
|
||||
// Load Existing Boxes from ICM659M
|
||||
public static function getBoxes(Request $request)
|
||||
{
|
||||
$R659PALT = $request->R659PALT ?? abort(404, 'Manifest Not Found');
|
||||
@@ -37,15 +33,15 @@ class BoxPackToPalletController extends Controller
|
||||
'c.AYSPR15A01',
|
||||
'cv.A4APR8N001',
|
||||
'cv.A4SHSHCT',
|
||||
'cnv.R652SORTK as CONVEYOR_NAME'
|
||||
'cnv.R652SORTK as CONVEYOR_NAME',
|
||||
)
|
||||
->leftJoin('ICM695M1 as c', 'p.R659BOX', '=', 'c.AYINTBOX')
|
||||
->leftJoin('ICM688M1 as cv', 'c.AYMACPKR', '=', 'cv.A4MACPKR')
|
||||
->leftJoin('ICM652M as cnv', 'cv.A4APR8N001', '=', 'cnv.R652SEQ')
|
||||
->where('p.R659PALT', $R659PALT)
|
||||
->where('p.R659CO', trim($userWhsCoPlant["USERCO"]))
|
||||
->where('p.R659WHS', trim($userWhsCoPlant["USERWHS"]))
|
||||
->where('p.R659PLANT', trim($userWhsCoPlant["USERPL"]))
|
||||
->where('p.R659CO', trim($userWhsCoPlant['USERCO']))
|
||||
->where('p.R659WHS', trim($userWhsCoPlant['USERWHS']))
|
||||
->where('p.R659PLANT', trim($userWhsCoPlant['USERPL']))
|
||||
->orderBy('p.R659DATE', 'desc')
|
||||
->orderBy('p.R659TIME', 'desc')
|
||||
->distinct()
|
||||
@@ -67,7 +63,7 @@ class BoxPackToPalletController extends Controller
|
||||
return view('m3::liberty-theme.pages.BoxPackToPalletScan', compact('boxes', 'palletHeader', 'R659PALT'));
|
||||
}
|
||||
|
||||
# Scan Boxes
|
||||
// Scan Boxes
|
||||
public static function scanBoxes(Request $request)
|
||||
{
|
||||
$R659PALT = $request->R659PALT ?? abort(400, 'Pallet Not Found');
|
||||
@@ -77,22 +73,22 @@ class BoxPackToPalletController extends Controller
|
||||
|
||||
$boxMessage = '';
|
||||
|
||||
# Step 1: Check for duplicate — same pallet + box combo
|
||||
// Step 1: Check for duplicate — same pallet + box combo
|
||||
$exists = DB::connection(config('m3.connection', 'pgsql'))
|
||||
->table('icm659m')
|
||||
->select('R659PALT')
|
||||
->where('R659PALT', $R659PALT)
|
||||
->where('R659BOX', $R659BOX)
|
||||
->where('R659CO', trim($userWhsCoPlant["USERCO"]))
|
||||
->where('R659WHS', trim($userWhsCoPlant["USERWHS"]))
|
||||
->where('R659PLANT', trim($userWhsCoPlant["USERPL"]))
|
||||
->where('R659CO', trim($userWhsCoPlant['USERCO']))
|
||||
->where('R659WHS', trim($userWhsCoPlant['USERWHS']))
|
||||
->where('R659PLANT', trim($userWhsCoPlant['USERPL']))
|
||||
->first();
|
||||
|
||||
if ($exists) {
|
||||
$boxMessage = "• Box {$R659BOX} is already assigned to Pallet {$exists->R659PALT}.";
|
||||
}
|
||||
|
||||
# Step 2: Check if Box exists in ICM695M1 (with carrier + conveyor joined)
|
||||
// Step 2: Check if Box exists in ICM695M1 (with carrier + conveyor joined)
|
||||
$ICM695M1Sel = DB::connection(config('m3.connection', 'pgsql'))
|
||||
->table('ICM695M1 as c')
|
||||
->select(
|
||||
@@ -101,20 +97,20 @@ class BoxPackToPalletController extends Controller
|
||||
'c.AYTYPE',
|
||||
'c.AYMACPKR',
|
||||
'cv.A4APR8N001',
|
||||
'cnv.R652SORTK as CONVEYOR_NAME'
|
||||
'cnv.R652SORTK as CONVEYOR_NAME',
|
||||
)
|
||||
->leftJoin('ICM688M1 as cv', 'c.AYMACPKR', '=', 'cv.A4MACPKR')
|
||||
->leftJoin('ICM652M as cnv', 'cv.A4APR8N001', '=', 'cnv.R652SEQ')
|
||||
->where('c.AYINTBOX', $R659BOX)
|
||||
->where('c.AYCO', trim($userWhsCoPlant["USERCO"]))
|
||||
->where('c.AYWHS', trim($userWhsCoPlant["USERWHS"]))
|
||||
->where('c.AYPLANT', trim($userWhsCoPlant["USERPL"]))
|
||||
->where('c.AYCO', trim($userWhsCoPlant['USERCO']))
|
||||
->where('c.AYWHS', trim($userWhsCoPlant['USERWHS']))
|
||||
->where('c.AYPLANT', trim($userWhsCoPlant['USERPL']))
|
||||
->first();
|
||||
|
||||
$boxExistInICM695M = isset($ICM695M1Sel->AYINTBOX);
|
||||
$boxExistInICM695M = isset($ICM695M1Sel->AYINTBOX);
|
||||
$boxisPalletICM695M = isset($ICM695M1Sel->AYTYPE) && $ICM695M1Sel->AYTYPE != 'BX';
|
||||
|
||||
if (!$boxExistInICM695M) {
|
||||
if (! $boxExistInICM695M) {
|
||||
$br = $boxMessage == '' ? '' : '<br>';
|
||||
$boxMessage .= $br . "• Box {$R659BOX} does not exist in ICM695M1 or it belongs to another Company.";
|
||||
}
|
||||
@@ -124,28 +120,28 @@ class BoxPackToPalletController extends Controller
|
||||
$boxMessage .= $br . "• Scanned barcode {$R659BOX} is not a Box.";
|
||||
}
|
||||
|
||||
# Step 3: Check that all boxes on the pallet share the same Carrier and Conveyor
|
||||
if ($boxExistInICM695M && !$boxisPalletICM695M && !$exists) {
|
||||
// Step 3: Check that all boxes on the pallet share the same Carrier and Conveyor
|
||||
if ($boxExistInICM695M && ! $boxisPalletICM695M && ! $exists) {
|
||||
$firstPalletBox = DB::connection(config('m3.connection', 'pgsql'))
|
||||
->table('ICM659M as p')
|
||||
->select(
|
||||
'c.AYSPR15A01',
|
||||
'cnv.R652SORTK as CONVEYOR_NAME'
|
||||
'cnv.R652SORTK as CONVEYOR_NAME',
|
||||
)
|
||||
->leftJoin('ICM695M1 as c', 'p.R659BOX', '=', 'c.AYINTBOX')
|
||||
->leftJoin('ICM688M1 as cv', 'c.AYMACPKR', '=', 'cv.A4MACPKR')
|
||||
->leftJoin('ICM652M as cnv', 'cv.A4APR8N001', '=', 'cnv.R652SEQ')
|
||||
->where('p.R659PALT', $R659PALT)
|
||||
->where('p.R659CO', trim($userWhsCoPlant["USERCO"]))
|
||||
->where('p.R659WHS', trim($userWhsCoPlant["USERWHS"]))
|
||||
->where('p.R659PLANT', trim($userWhsCoPlant["USERPL"]))
|
||||
->where('p.R659CO', trim($userWhsCoPlant['USERCO']))
|
||||
->where('p.R659WHS', trim($userWhsCoPlant['USERWHS']))
|
||||
->where('p.R659PLANT', trim($userWhsCoPlant['USERPL']))
|
||||
->first();
|
||||
|
||||
if ($firstPalletBox) {
|
||||
$incomingCarrier = trim($ICM695M1Sel->AYSPR15A01 ?? '');
|
||||
$incomingCarrier = trim($ICM695M1Sel->AYSPR15A01 ?? '');
|
||||
$incomingConveyor = trim($ICM695M1Sel->CONVEYOR_NAME ?? '');
|
||||
$palletCarrier = trim($firstPalletBox->AYSPR15A01 ?? '');
|
||||
$palletConveyor = trim($firstPalletBox->CONVEYOR_NAME ?? '');
|
||||
$palletCarrier = trim($firstPalletBox->AYSPR15A01 ?? '');
|
||||
$palletConveyor = trim($firstPalletBox->CONVEYOR_NAME ?? '');
|
||||
|
||||
if ($incomingCarrier !== $palletCarrier) {
|
||||
$br = $boxMessage == '' ? '' : '<br>';
|
||||
@@ -159,29 +155,29 @@ class BoxPackToPalletController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ($exists || !$boxExistInICM695M || $boxisPalletICM695M || $boxMessage !== '') {
|
||||
if ($exists || ! $boxExistInICM695M || $boxisPalletICM695M || $boxMessage !== '') {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $boxMessage,
|
||||
], 409);
|
||||
}
|
||||
|
||||
# Step 4: Insert new box record
|
||||
// Step 4: Insert new box record
|
||||
DB::connection(config('m3.connection', 'pgsql'))
|
||||
->table('icm659m')
|
||||
->insert([
|
||||
'R659PALT' => $R659PALT,
|
||||
'R659BOX' => $R659BOX,
|
||||
'R659PALT' => $R659PALT,
|
||||
'R659BOX' => $R659BOX,
|
||||
'R659LOADED' => '',
|
||||
'R659USER' => $SHUSER,
|
||||
'R659DATE' => date('Y-m-d'),
|
||||
'R659TIME' => date('H:i:s'),
|
||||
'R659CO' => trim($userWhsCoPlant["USERCO"]),
|
||||
'R659WHS' => trim($userWhsCoPlant["USERWHS"]),
|
||||
'R659PLANT' => trim($userWhsCoPlant["USERPL"]),
|
||||
'R659USER' => $SHUSER,
|
||||
'R659DATE' => date('Y-m-d'),
|
||||
'R659TIME' => date('H:i:s'),
|
||||
'R659CO' => trim($userWhsCoPlant['USERCO']),
|
||||
'R659WHS' => trim($userWhsCoPlant['USERWHS']),
|
||||
'R659PLANT' => trim($userWhsCoPlant['USERPL']),
|
||||
]);
|
||||
|
||||
# Step 5: Return the full refreshed box list
|
||||
// Step 5: Return the full refreshed box list
|
||||
$boxes = DB::connection(config('m3.connection', 'pgsql'))->table('ICM659M as p')
|
||||
->select(
|
||||
'p.R659PALT',
|
||||
@@ -194,15 +190,15 @@ class BoxPackToPalletController extends Controller
|
||||
'c.AYSPR15A01',
|
||||
'cv.A4APR8N001',
|
||||
'cv.A4SHSHCT',
|
||||
'cnv.R652SORTK as CONVEYOR_NAME'
|
||||
'cnv.R652SORTK as CONVEYOR_NAME',
|
||||
)
|
||||
->leftJoin('ICM695M1 as c', 'p.R659BOX', '=', 'c.AYINTBOX')
|
||||
->leftJoin('ICM688M1 as cv', 'c.AYMACPKR', '=', 'cv.A4MACPKR')
|
||||
->leftJoin('ICM652M as cnv', 'cv.A4APR8N001', '=', 'cnv.R652SEQ')
|
||||
->where('p.R659PALT', $R659PALT)
|
||||
->where('p.R659CO', trim($userWhsCoPlant["USERCO"]))
|
||||
->where('p.R659WHS', trim($userWhsCoPlant["USERWHS"]))
|
||||
->where('p.R659PLANT', trim($userWhsCoPlant["USERPL"]))
|
||||
->where('p.R659CO', trim($userWhsCoPlant['USERCO']))
|
||||
->where('p.R659WHS', trim($userWhsCoPlant['USERWHS']))
|
||||
->where('p.R659PLANT', trim($userWhsCoPlant['USERPL']))
|
||||
->orderBy('p.R659DATE', 'desc')
|
||||
->orderBy('p.R659TIME', 'desc')
|
||||
->distinct()
|
||||
@@ -213,11 +209,11 @@ class BoxPackToPalletController extends Controller
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "• Box {$R659BOX} added to Pallet {$R659PALT}.",
|
||||
'data' => $boxes,
|
||||
'data' => $boxes,
|
||||
]);
|
||||
}
|
||||
|
||||
# Delete Box
|
||||
// Delete Box
|
||||
public static function deleteBox(Request $request)
|
||||
{
|
||||
$R659PALT = $request->R659PALT ?? abort(400, 'Pallet Not Found');
|
||||
@@ -225,21 +221,21 @@ class BoxPackToPalletController extends Controller
|
||||
|
||||
$userWhsCoPlant = self::getUserWhsCoPlant();
|
||||
|
||||
# Guard: only allow delete if R659LOADED is empty
|
||||
// Guard: only allow delete if R659LOADED is empty
|
||||
$record = DB::connection(config('m3.connection', 'pgsql'))
|
||||
->table('icm659m')
|
||||
->where('R659PALT', $R659PALT)
|
||||
->where('R659BOX', $R659BOX)
|
||||
->first();
|
||||
|
||||
if (!$record) {
|
||||
if (! $record) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "Box {$R659BOX} not found on Pallet {$R659PALT}.",
|
||||
], 404);
|
||||
}
|
||||
|
||||
if (!empty(trim($record->R659LOADED))) {
|
||||
if (! empty(trim($record->R659LOADED))) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "Box {$R659BOX} is already loaded and cannot be removed.",
|
||||
@@ -252,7 +248,7 @@ class BoxPackToPalletController extends Controller
|
||||
->where('R659BOX', $R659BOX)
|
||||
->delete();
|
||||
|
||||
# Return refreshed list
|
||||
// Return refreshed list
|
||||
$boxes = DB::connection(config('m3.connection', 'pgsql'))->table('ICM659M as p')
|
||||
->select(
|
||||
'p.R659PALT',
|
||||
@@ -265,15 +261,15 @@ class BoxPackToPalletController extends Controller
|
||||
'c.AYSPR15A01',
|
||||
'cv.A4APR8N001',
|
||||
'cv.A4SHSHCT',
|
||||
'cnv.R652SORTK as CONVEYOR_NAME'
|
||||
'cnv.R652SORTK as CONVEYOR_NAME',
|
||||
)
|
||||
->leftJoin('ICM695M1 as c', 'p.R659BOX', '=', 'c.AYINTBOX')
|
||||
->leftJoin('ICM688M1 as cv', 'c.AYMACPKR', '=', 'cv.A4MACPKR')
|
||||
->leftJoin('ICM652M as cnv', 'cv.A4APR8N001', '=', 'cnv.R652SEQ')
|
||||
->where('p.R659PALT', $R659PALT)
|
||||
->where('p.R659CO', trim($userWhsCoPlant["USERCO"]))
|
||||
->where('p.R659WHS', trim($userWhsCoPlant["USERWHS"]))
|
||||
->where('p.R659PLANT', trim($userWhsCoPlant["USERPL"]))
|
||||
->where('p.R659CO', trim($userWhsCoPlant['USERCO']))
|
||||
->where('p.R659WHS', trim($userWhsCoPlant['USERWHS']))
|
||||
->where('p.R659PLANT', trim($userWhsCoPlant['USERPL']))
|
||||
->orderBy('p.R659DATE', 'desc')
|
||||
->orderBy('p.R659TIME', 'desc')
|
||||
->distinct()
|
||||
@@ -288,11 +284,11 @@ class BoxPackToPalletController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
# Get Logged User CO/WHS/PLANT
|
||||
// Get Logged User CO/WHS/PLANT
|
||||
public static function getUserWhsCoPlant()
|
||||
{
|
||||
$SHUSER = m3_user() !== '' ? Str::upper(trim(m3_user())) : '';
|
||||
# Get users from ICM428M
|
||||
// Get users from ICM428M
|
||||
$ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
|
||||
->select('R428US', 'R428CO', 'R428WH', 'R428PL')
|
||||
->where('R428US', '=', $SHUSER)
|
||||
@@ -304,11 +300,12 @@ class BoxPackToPalletController extends Controller
|
||||
$R428PL = isset($ICM428M->R428PL) ? $ICM428M->R428PL : '';
|
||||
|
||||
$userWhsCoPlant = [
|
||||
"R428US" => $R428US,
|
||||
"USERCO" => $USERCO,
|
||||
"USERWHS" => $USERWH,
|
||||
"USERPL" => $R428PL,
|
||||
'R428US' => $R428US,
|
||||
'USERCO' => $USERCO,
|
||||
'USERWHS' => $USERWH,
|
||||
'USERPL' => $R428PL,
|
||||
];
|
||||
|
||||
return $userWhsCoPlant;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user