AYINTBOX) ? trim($request->AYINTBOX) : ''; $AYCO = isset($request->AYCO) ? trim($request->AYCO) : ''; $AYWHS = isset($request->AYWHS) ? trim($request->AYWHS) : ''; $AYUSER = isset($request->AYUSER) ? trim($request->AYUSER) : ''; if ($AYINTBOX!='') { # Get the record from ICM695M1 $ICM695M1Sel = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m1') ->select() ->where('AYINTBOX',$AYINTBOX) ->where('AYCO',$AYCO) ->where('AYWHS',$AYWHS) ->where('AYSTATUS','') ->first(); $allowDeletion = isset($ICM695M1Sel->AYSENTPKR) ? ($ICM695M1Sel->AYSENTPKR !='' ? true : false ) : false; if ($allowDeletion) { $timestamp = date('Y-m-d H:i:s.u'); $date1 = date('Ymd'); $time1 = date('His'); # Delete Records from ICM695M1 And ICM695M2 $ICM695M1Del = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m1') ->where('AYINTBOX',$AYINTBOX) ->where('AYCO',$AYCO) ->where('AYWHS',$AYWHS) ->delete(); $ICM695M2Del = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m2') ->where('AZINTBOX',$AYINTBOX) ->where('AZCO',$AYCO) ->where('AZWHS',$AYWHS) ->delete(); # Log the event as an unusual transaction to appear on SPD bottom right: $InsertValues = "'$ICM695M1Sel->AYCO', '$ICM695M1Sel->AYWHS', '$ICM695M1Sel->AYSENTPKR', '$ICM695M1Sel->AYMACPKR', '$ICM695M1Sel->AYONO', '$ICM695M1Sel->AYRLNO', '$ICM695M1Sel->AYSHNO', '', 'Box $AYINTBOX emptied and repacked', '$timestamp', '$date1', '$time1', '$AYUSER','$timestamp', '$date1', '$time1', '$AYUSER','$AYINTBOX'"; $ICM689MInsert = DB::connection(config('m3.connection', 'pgsql'))->insert("INSERT INTO ICM689M (A7CO, A7WHS, A7SENTPKR, A7MACPKR, A7ONO, A7RLNO, A7SHNO, A7SOURCE, A7ERRMSG, A7DISRAITS, A7DISRAID, A7DISRAIT, A7DISRAIU, A7DISRESTS ,A7DISRESD ,A7DISREST ,A7DISRESU , A7SPR15A01) values ($InsertValues)"); return response()->json(['success'=>true , 'message' => 'Line Deleted']); } else{ return response()->json(['success'=>false , 'message' => 'Line already packed']); } } else{ return response()->json(['success'=>false , 'message' => 'Line missing']); } } }