option('con'); $param = $this->option('param'); if(!empty($con)) { switch ($con) { case 'jobs': $data_ref = Arr::get($param,'data_ref',null); $of_reference = Arr::get($param,'of_reference',null); $data = Arr::get($param,'data',null); $this->updateWebhook($of_reference, $param); if($of_reference){ if ($data_ref == self::$Approved) { $this->updateLoan($of_reference, self::$CFApproved); }else if($data_ref == self::$CreditRemark && isset($data['comments']['comment'])){ $this->saveComment($of_reference, $data['comments']['comment']); } } else { return Utility::handlerSendFailed([\Config::get("constants.txt.txt_errors") => ['Missing parameter ExecuteJob']]); } 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']]); } } private function updateWebhook($of_reference, $data){ $homevilleLoan = $this->getApplicationID($of_reference); if (isset($homevilleLoan->application_id)) { $homevilleWebhookHandler = new HomevilleWebhookHandler(); $homevilleWebhookHandler->fill([ 'application_id' => $homevilleLoan->application_id, 'response' => json_encode($data) ]); $homevilleWebhookHandler->save(); } } private function getApplicationID($of_reference){ return HomevilleLoans::where('case_id', $of_reference)->first(['application_id']); } public function saveComment($of_reference, $comment){ $homevilleLoan = $this->getApplicationID($of_reference); saveComment('Homeville: '.$comment, $homevilleLoan->application_id, 107); } public function updateLoan($of_reference, $status){ $homevilleLoan = $this->getApplicationID($of_reference); if (isset($homevilleLoan->application_id)) { $this->changeStatus($homevilleLoan->application_id, Singularity::$lender_id, $status); saveComment('Homeville Decision: Approved', $homevilleLoan->application_id, 107); } } public function changeStatus($id, $lender_id, $status, $message = ''){ (new Slack(new Request(['title' => 'Homeville Change Status', 'fields' => ['application_id' => $id], 'group' => Slack::$STAGE_TESTING])))->send(); request()->merge(['lender_id' => $lender_id, 'state' => $status, 'source' => 'hv_bre']); if ($message) { saveComment($message, $id, 107); } $application = ConsumerApplication::where('id', $id)->where('state', 'cf approved')->first(['id', 'state']); if(isset($application->id)) { $applicationController = new ConsumerApplicationController(); $applicationController->updateStatus($id); } } }