M3 Security Fixes for Pass 34

This commit is contained in:
Mark Gregory
2026-09-17 12:04:08 +01:00
parent 0a05f05843
commit e1824f399e
69 changed files with 1804 additions and 1791 deletions
@@ -9,9 +9,13 @@ use Str;
class BoxPackToPalletController extends Controller
{
private const PALLET_TABLE_ALIAS = 'ICM659M as p';
private const CONVEYOR_SELECT = 'cnv.R652SORTK as CONVEYOR_NAME';
private const CARTON_TABLE_ALIAS = 'ICM695M1 as c';
private const CONVEYOR_VALUE_ALIAS = 'ICM688M1 as cv';
private const CONVEYOR_TABLE_ALIAS = 'ICM652M as cnv';
public static function index(Request $request)
@@ -22,7 +26,7 @@ class BoxPackToPalletController extends Controller
// Load Existing Boxes from ICM659M
public static function getBoxes(Request $request)
{
$R659PALT = $request->R659PALT ?? abort(404, 'Manifest Not Found');
$r659PALT = $request->R659PALT ?? abort(404, 'Manifest Not Found');
$userWhsCoPlant = self::getUserWhsCoPlant();
@@ -43,7 +47,7 @@ class BoxPackToPalletController extends Controller
->leftJoin(self::CARTON_TABLE_ALIAS, 'p.R659BOX', '=', 'c.AYINTBOX')
->leftJoin(self::CONVEYOR_VALUE_ALIAS, 'c.AYMACPKR', '=', 'cv.A4MACPKR')
->leftJoin(self::CONVEYOR_TABLE_ALIAS, 'cv.A4APR8N001', '=', 'cnv.R652SEQ')
->where('p.R659PALT', $R659PALT)
->where('p.R659PALT', $r659PALT)
->where('p.R659CO', trim($userWhsCoPlant['USERCO']))
->where('p.R659WHS', trim($userWhsCoPlant['USERWHS']))
->where('p.R659PLANT', trim($userWhsCoPlant['USERPL']))
@@ -63,7 +67,7 @@ class BoxPackToPalletController extends Controller
$palletHeader = $boxes->first();
return view('m3::liberty-theme.pages.BoxPackToPalletScan', compact('boxes', 'palletHeader', 'R659PALT'));
return view('m3::liberty-theme.pages.BoxPackToPalletScan', ['boxes' => $boxes, 'palletHeader' => $palletHeader, 'R659PALT' => $r659PALT]);
}
// Scan Boxes
@@ -169,8 +173,19 @@ class BoxPackToPalletController extends Controller
private static function boxesForPallet($pallet, array $profile)
{
return DB::connection(config('m3.connection', 'pgsql'))->table(self::PALLET_TABLE_ALIAS)
->select('p.R659PALT', 'p.R659BOX', 'p.R659LOADED', 'p.R659USER', 'p.R659DATE', 'p.R659TIME',
'c.AYMACPKR', 'c.AYSPR15A01', 'cv.A4APR8N001', 'cv.A4SHSHCT', self::CONVEYOR_SELECT)
->select(
'p.R659PALT',
'p.R659BOX',
'p.R659LOADED',
'p.R659USER',
'p.R659DATE',
'p.R659TIME',
'c.AYMACPKR',
'c.AYSPR15A01',
'cv.A4APR8N001',
'cv.A4SHSHCT',
self::CONVEYOR_SELECT,
)
->leftJoin(self::CARTON_TABLE_ALIAS, 'p.R659BOX', '=', 'c.AYINTBOX')
->leftJoin(self::CONVEYOR_VALUE_ALIAS, 'c.AYMACPKR', '=', 'cv.A4MACPKR')
->leftJoin(self::CONVEYOR_TABLE_ALIAS, 'cv.A4APR8N001', '=', 'cnv.R652SEQ')
@@ -182,36 +197,36 @@ class BoxPackToPalletController extends Controller
// Delete Box
public static function deleteBox(Request $request)
{
$R659PALT = $request->R659PALT ?? abort(400, 'Pallet Not Found');
$R659BOX = trim($request->R659BOX) ?? abort(400, 'Box Not Found');
$r659PALT = $request->R659PALT ?? abort(400, 'Pallet Not Found');
$r659BOX = trim($request->R659BOX) ?? abort(400, 'Box Not Found');
$userWhsCoPlant = self::getUserWhsCoPlant();
// Guard: only allow delete if R659LOADED is empty
$record = DB::connection(config('m3.connection', 'pgsql'))
->table('icm659m')
->where('R659PALT', $R659PALT)
->where('R659BOX', $R659BOX)
->where('R659PALT', $r659PALT)
->where('R659BOX', $r659BOX)
->first();
if (! $record) {
return response()->json([
'success' => false,
'message' => "Box {$R659BOX} not found on Pallet {$R659PALT}.",
'message' => "Box {$r659BOX} not found on Pallet {$r659PALT}.",
], 404);
}
if (! empty(trim($record->R659LOADED))) {
return response()->json([
'success' => false,
'message' => "Box {$R659BOX} is already loaded and cannot be removed.",
'message' => "Box {$r659BOX} is already loaded and cannot be removed.",
], 403);
}
DB::connection(config('m3.connection', 'pgsql'))
->table('icm659m')
->where('R659PALT', $R659PALT)
->where('R659BOX', $R659BOX)
->where('R659PALT', $r659PALT)
->where('R659BOX', $r659BOX)
->delete();
// Return refreshed list
@@ -232,7 +247,7 @@ class BoxPackToPalletController extends Controller
->leftJoin(self::CARTON_TABLE_ALIAS, 'p.R659BOX', '=', 'c.AYINTBOX')
->leftJoin(self::CONVEYOR_VALUE_ALIAS, 'c.AYMACPKR', '=', 'cv.A4MACPKR')
->leftJoin(self::CONVEYOR_TABLE_ALIAS, 'cv.A4APR8N001', '=', 'cnv.R652SEQ')
->where('p.R659PALT', $R659PALT)
->where('p.R659PALT', $r659PALT)
->where('p.R659CO', trim($userWhsCoPlant['USERCO']))
->where('p.R659WHS', trim($userWhsCoPlant['USERWHS']))
->where('p.R659PLANT', trim($userWhsCoPlant['USERPL']))
@@ -245,7 +260,7 @@ class BoxPackToPalletController extends Controller
return response()->json([
'success' => true,
'message' => "Box {$R659BOX} removed from Pallet {$R659PALT}.",
'message' => "Box {$r659BOX} removed from Pallet {$r659PALT}.",
'data' => $boxes,
]);
}
@@ -253,23 +268,23 @@ class BoxPackToPalletController extends Controller
// Get Logged User CO/WHS/PLANT
public static function getUserWhsCoPlant()
{
$SHUSER = m3_user() !== '' ? Str::upper(trim(m3_user())) : '';
$sHUSER = m3_user() !== '' ? Str::upper(trim(m3_user())) : '';
// Get users from ICM428M
$ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
$iCM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
->select('R428US', 'R428CO', 'R428WH', 'R428PL')
->where('R428US', '=', $SHUSER)
->where('R428US', '=', $sHUSER)
->first();
$R428US = isset($ICM428M->R428US) ? $ICM428M->R428US : '';
$USERCO = isset($ICM428M->R428CO) ? $ICM428M->R428CO : '';
$USERWH = isset($ICM428M->R428WH) ? $ICM428M->R428WH : '';
$R428PL = isset($ICM428M->R428PL) ? $ICM428M->R428PL : '';
$r428US = isset($iCM428M->R428US) ? $iCM428M->R428US : '';
$uSERCO = isset($iCM428M->R428CO) ? $iCM428M->R428CO : '';
$uSERWH = isset($iCM428M->R428WH) ? $iCM428M->R428WH : '';
$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;