option('con'); $param = $this->option('param'); $bre_api_payload = $param['payload']; $req_id = isset($param['req_id']) ? $param['req_id'] : 0 ; if(!empty($con)) { switch ($con) { case 'jobs': $response = (new GradeController(new Request()))->runAutoDecisionBRE($bre_api_payload); $data = $response->getData(); $decoded_response = isset($data->res) ? json_decode($data->res) : ""; $log = new BreLog(); $log->application_id = $bre_api_payload['identifier']; $log->request = json_encode($data->req); $log->response = json_encode($decoded_response); $log->created_at = Carbon::now()->toDateTimeString(); $log->request_batch_id = $req_id; $log->save(); if (!empty($decoded_response)) { // Loop through the associative array foreach ($decoded_response as $key => $value) { // Store the key as a variable if ($key === 'status') { continue; // This skips the rest of the loop for this iteration } $logv2 = new JsonBreApprovalStatusLog(); $logv2->rule_id = (int)substr($key, 7); $logv2->application_id = $bre_api_payload['identifier']; $logv2->failed_condition = isset($value->failed_condition) ? json_encode($value->failed_condition->key) : ""; $logv2->reason = isset($value->reason)? json_encode($value->failed_condition->reason) : ""; $logv2->request_batch_id = $req_id; $logv2->status=(int)$value->policy_status; $logv2->created_at = Carbon::now()->toDateTimeString(); $logv2->save(); } } else{ $logv2 = new JsonBreApprovalStatusLog(); $logv2->rule_id = 0; $logv2->application_id = $bre_api_payload['identifier']; $logv2->failed_condition = ''; $logv2->reason = 'Unhandled Scenario'; $logv2->request_batch_id = $req_id; $logv2->status=0; $logv2->created_at = Carbon::now()->toDateTimeString(); $logv2->save(); } if ($data->code == 200) { return Utility::handlerSendSuccess([],Lang::get('message.jobs_success')); } else { return Utility::handlerSendFailed([\Config::get("constants.txt.txt_errors") => ['Exception encountered Http Code: '. $data->code]]); } break; default: return Utility::handlerSendFailed([\Config::get("constants.txt.txt_errors") => ['No case found to handle in ExecuteJob']]); } } else { return Utility::handlerSendFailed([\Config::get("constants.txt.txt_errors") => ['Context is missing']]); } } }