option('con'); $param = $this->option('param'); if(!empty($con)) { switch ($con) { case 'jobs': $status = Arr::get($param,'status',null); $this->utr_number = Arr::get($param,'utr_number',null); $client_loan_id = Arr::get($param,'client_loan_id',null); $reject_reason = Arr::get($param,'reject_reason',null); if ($reject_reason){ $reject_reason = 'Reason: '.$reject_reason; } if($status){ $this->updateLoan($status, $reject_reason, $client_loan_id); } 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 updateLoan($status, $reason, $client_loan_id){ $loan = UtkarshLoans::where('loan_id', $client_loan_id)->first(['id', 'application_id']); if (isset($loan->id)){ UtkarshLoans::where('id', $loan->id)->update(['status' => $status]); if ($status == 'approved'){ request()->merge(['lender_id' => Utkarsh::$lender_id, 'state' => $status, 'source' => 'utkarsh_bre']); saveComment("Utkarsh Decision : " .$status, $loan->application_id, 107); $applicationController = new ConsumerApplicationController(); $applicationController->updateStatus($loan->application_id); }else if($status == 'borrower_disbursed'){ $wrapper = new Wrapper(); $wrapperMethods = $wrapper->register(UtkarshMethods::class); $wrapper->payload->addPayload(new Request(['id' => $loan->application_id, 'client_name' => UtkarshController::$client_name, 'loan_id' => $client_loan_id])); $wrapperRes = $wrapperMethods->createRepayment($wrapper); if ($wrapperRes->errorBag) return response()->json(['status' => 'FAIL', 'data' => array_filter($wrapperRes->errorBag)]); $this->changeStatus($loan->application_id, Utkarsh::$lender_id, 'disbursed'); }else{ saveComment("Utkarsh Decision : " .$status.' '.$reason, $loan->application_id, 107); } } } public function changeStatus($id, $lender_id, $status, $message = ''){ request()->merge(['lender_id' => $lender_id, 'state' => $status, 'source' => 'utkarsh_bre']); if ($message) { saveComment('Utkarsh Update : '.$message, $id, 107); } $application = ConsumerApplication::where('id', $id)->where('state', $status)->first(['id']); if(!isset($application->id)) { $applicationController = new ConsumerApplicationController(); $applicationController->updateStatus($id); if ($this->utr_number) { ConsumerApplicationElement::where('application_id', $id)->update(['reference_number' => $this->utr_number]); } } } }