option('con'); $param = $this->option('param'); if(!empty($con)) { switch ($con) { case 'jobs': $id = Arr::get($param,'id',null); if($id) { try { $cwFactory = new CloudWatchLoggerFactory(); $application = ConsumerApplication::with('merchant')->where('id', $id)->first(['id','merchant_id', 'state', 'co_applicant_name', 'updated_by']); if($application->merchant && ($application->merchant->is_auto_approve || $application->merchant->is_auto_doc || $application->merchant->pre_approval) && $application->merchant->grade_id) { $param['co_applicant'] = !empty($application->co_applicant_name) ? true : false; $applicationController = new ConsumerApplicationController(); $applicationController->isRoot = false; $testImport = new TestImport(new Request()); $requestID = $testImport->random_strings(8); \request()->merge(['request_ap_id' => $requestID, 'log_decision' => true]); $runBRE = true; if (isset($param['electricity_bill_validation']) && $param['electricity_bill_validation'] == 'Fail' && isset($param['electricity_bill_upload']) && $param['electricity_bill_upload'] == 0 && $application->updated_by == 'MERCHANT API') { $runBRE = false; } $cwFactory->logger(json_encode(array('title' => 'AutoDecisionQueueLog', 'application_id' => $id ?? ''))); $response = $applicationController->generateSoftBureauReport($id, 'autoBRE', 1, $runBRE); if (!empty($application->co_applicant_name)) { $coAppResponse = $applicationController->generateSoftBureauReport($id, 'autoBRE', 2, false); } $responseData = $response->getData(); if ($responseData->status == 'OK' && !$responseData->is_rejected && !$responseData->is_pre_approved) { // Dont change status in case, application is rejected or pre approved $consumerApplicationController = new ConsumerApplicationController(); $consumerApplicationController->updateProforma($id); $hasApproval = DB::connection('mysql_primary')->selectOne(" SELECT EXISTS ( SELECT 1 FROM approval_status_log WHERE application_id = ? AND request_batch_id = ( SELECT request_batch_id FROM approval_status_log WHERE application_id = ? ORDER BY created_at DESC LIMIT 1 ) AND status = 1 ) as status", [$id, $id]); if (isset($responseData->is_approved) && $responseData->is_approved && $hasApproval->status) { // SSE Mconnect Integration block if ($application->merchant->id == _env('SSE_MERCHANT_ID')) { $status = $this->sseSetStatus($id, $responseData->is_approved, $consumerApplicationController, $param); } else { $status = 'approved'; if ($applicationController->isMultiLender($application->merchant_id) > 1) { $status = 'cf approved'; } } $cwFactory->logger(json_encode(array('title' => 'AutoDecisionQueueLog', 'application_id' => $id ?? '', 'status' => $status, 'is_approved' => $responseData->is_approved))); } else if (isset($responseData->is_approved) && !$responseData->is_approved) { $status = ($application->merchant->id == _env('SSE_MERCHANT_ID')) ? $this->sseSetStatus($id, $responseData->is_approved, $consumerApplicationController, $param) : 'waiting for decision'; } if ($status != $application->state) { $cwFactory->logger(json_encode(array('title' => 'AutoDecisionQueueLog', 'application_id' => $id ?? '', 'status' => $status, 'is_approved' => $responseData->is_approved))); \request()->merge(['status' => $status]); $consumerApplicationController->updateStatus($id, true); } } else { return Utility::handlerSendFailed([\Config::get("constants.txt.txt_errors") => [$responseData->message]]); } } }catch (\Exception $e){ return Utility::handlerSendFailed([\Config::get("constants.txt.txt_errors") => [$e->getMessage().'|'.$e->getLine().'|'.$e->getTraceAsString()]]); } } 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']]); } } public function sseSetStatus($id, $bre_status, $applicationController, $param) { $status = 'waiting for documents'; $reasonString = 'Co-applicant needed for Ebill Match'; $addn_data = ['user_id' => Input::get('auth_user_id'), 'reason' => $reasonString]; $webhookName = 'Add-Co-applicant'; $fileTyepQuery = DB::select('select id, file_type, ebill_name_verify from consumer_application_files caf where consumer_application_id ='.$id.' and file_type = "electricity_bill_validation_report" order by created_at desc limit 1'); // Electricity bill validation failed, document uploaded or only doc uploaded flow if (isset($param['electricity_bill_validation']) && isset($param['electricity_bill_upload']) && $param['electricity_bill_validation'] == 'Fail' && $param['electricity_bill_upload'] == 1) { $status = 'waiting for decision'; $comment = $bre_status ? 'BRE approved. Electricity bill document verification is pending.' : 'BRE not approved. Electricity bill document verification is pending.'; // Electricity bill validation failed and no doc uploaded } else if (isset($param['electricity_bill_validation']) && isset($param['electricity_bill_upload']) && $param['electricity_bill_validation'] == 'Fail' && $param['electricity_bill_upload'] == 0) { $comment = 'Electricity bill validation failed. Electricity bill document required.'; } else if (isset($param['electricity_bill_validation']) && $param['electricity_bill_validation'] == 'Success') { $eBill = isset($fileTyepQuery[0]->ebill_name_verify) ? json_decode($fileTyepQuery[0]->ebill_name_verify, true) : ''; if ($bre_status) { // Approved if (isset($eBill['applicant_match']) && $eBill['applicant_match'] < 91) { if (isset($param['co_applicant']) && !$param['co_applicant']) { if (isset($eBill['applicant_match']) && $eBill['applicant_match'] >= 51) { $status = 'waiting for decision'; // Approved, applicant fuzzy between 51-89 but no co-applicant $comment = 'Auto approved rules passed. Please check Owner name as per E-bill and take action accordingly.'; } if (isset($eBill['applicant_match']) && $eBill['applicant_match'] <= 50) { // Approved, applicant fuzzy less than 50 but no co-applicant $comment = 'Auto approved rules passed. Applicant name mismatched with E-bill. Please add owner in the co-applicant details.'; $applicationController->webhook($id, ['merchant_id' => _env('SSE_MERCHANT_ID'), 'type' => 'Application-Webhook', 'status' => $webhookName, 'data' => $applicationController->getMConnectPayload($id, $webhookName, $addn_data)]); } } else { if (isset($eBill['co_applicant_match']) && $eBill['co_applicant_match'] <= 50 && $eBill['applicant_match'] < 50) { // Approved, applicant fuzzy less than 50 and co-applicant fuzzy less than 50 $comment = 'Add Co-Applicant using the name mentioned on the e-bill.'; $applicationController->webhook($id, ['merchant_id' => _env('SSE_MERCHANT_ID'), 'type' => 'Application-Webhook', 'status' => $webhookName, 'data' => $applicationController->getMConnectPayload($id, $webhookName, $addn_data)]); } else if (isset($eBill['co_applicant_match']) && $eBill['co_applicant_match'] >= 90) { $status = 'cf approved'; // Approved, applicant fuzzy less than 50 and co-applicant fuzzy more than 90 } else { $status = 'waiting for decision'; // Approved, applicant fuzzy less than 50 or 51-89 and co-applicant fuzzy greater than 90 or 51-89 $comment = 'Auto approved rules passed. Please check Owner name as per E-bill and take action accordingly.'; } } } else { $status = 'cf approved'; // Approved & applicant fuzzy match success } } else { // Not approved if (isset($eBill['applicant_match']) && $eBill['applicant_match'] < 50) { if ((!$param['co_applicant']) || (isset($eBill['co_applicant_match']) && $eBill['co_applicant_match'] <= 50)) { $applicationController->webhook($id, ['merchant_id' => _env('SSE_MERCHANT_ID'), 'type' => 'Application-Webhook', 'status' => $webhookName, 'data' => $applicationController->getMConnectPayload($id, $webhookName, $addn_data)]); $comment = 'Add Co-applicant using the name mentioned on the e-bill. Bank Statement required of the applicant'; } else if (!$param['co_applicant'] || (isset($eBill['co_applicant_match']) && $eBill['co_applicant_match'] > 50 && $eBill['co_applicant_match'] < 90)) { $comment = 'Bank Statement required of the applicant. Please perform manual name validation, as the match result for applicant - '.$eBill['applicant_match'].' & co-applicant - '.$eBill['co_applicant_match']; } else { $comment = 'Bank Statement required for decision'; } } else if (isset($eBill['applicant_match']) && $eBill['applicant_match'] < 90) { $comment = 'Bank Statement required of the applicant. Please perform manual name validation, as the match result for applicant - '.$eBill['applicant_match']; } else { $comment = 'Bank Statement required for decision'; } } } if (isset($comment)) { (new GradeController(new Request))->addComment($id, 107, $comment); } return $status; } }