function add_loan(array $request, $lead_id) { DB::beginTransaction(); try { /* Lead converted to application */ $lead = Lead::find($lead_id); /* If application is not created before and this is the first time */ if ($lead->status != 2) { $lead->status = 2; $lead->save(); /* Create application */ $application = Application::create(['date_created' => get_today_date(), 'ex_user_id' => \Auth::user()->id, 'ex_lead_id' => $lead_id, 'submitted' => 0]); $this->changeStatus($application->id, 1); //add logs for application addition $log = Log::create(['added_by' => \Auth::user()->id, 'comment' => 'Application Created']); ApplicationLog::create(['application_id' => $application->id, 'log_id' => $log->id]); } else { /* Delete removed loans */ $application = Application::where('ex_lead_id', $lead_id)->first(); if (isset($request['loan_id'])) { $loan_ids = NewApplicantLoan::where('application_id', $application->id)->lists('id')->toArray(); $removed_loans = array_diff($loan_ids, $request['loan_id']); NewApplicantLoan::whereIn('id', $removed_loans)->delete(); } } foreach ($request['loan_purpose'] as $key => $loan_purpose) { if (!isset($request['loan_id'][$key])) { NewApplicantLoan::create(['application_id' => $application->id, 'amount' => $request['amount'][$key], 'loan_purpose' => $loan_purpose, 'deposit_paid' => $request['deposit_paid'][$key], 'settlement_date' => $request['settlement_date'][$key], 'loan_usage' => $request['loan_usage'][$key], 'total_loan_term' => $request['total_loan_term'][$key], 'loan_type' => $request['loan_type'][$key], 'fixed_rate_term' => $request['fixed_rate_term'][$key], 'repayment_type' => $request['repayment_type'][$key], 'io_term' => $request['io_term'][$key], 'interest_rate' => $request['interest_rate'][$key]]); } else { $loan = NewApplicantLoan::find($request['loan_id'][$key]); $loan->application_id = $application->id; $loan->amount = $request['amount'][$key]; $loan->loan_purpose = $loan_purpose; $loan->deposit_paid = $request['deposit_paid'][$key]; $loan->settlement_date = $request['settlement_date'][$key]; $loan->loan_usage = $request['loan_usage'][$key]; $loan->total_loan_term = $request['total_loan_term'][$key]; $loan->loan_type = $request['loan_type'][$key]; $loan->fixed_rate_term = $request['fixed_rate_term'][$key]; $loan->repayment_type = $request['repayment_type'][$key]; $loan->io_term = $request['io_term'][$key]; $loan->interest_rate = $request['interest_rate'][$key]; $loan->save(); } } DB::commit(); return true; } catch (\Exception $e) { DB::rollback(); dd($e); return false; } }
function deleteLog() { $log_id = $this->request->route('id'); LeadLog::where('log_id', $log_id)->delete(); Log::find($log_id)->delete(); return $this->success(['message' => 'Log deleted Successfully']); }
function addLog(array $request, $lead_id) { DB::beginTransaction(); try { $log = Log::create(['added_by' => \Auth::user()->id, 'comment' => $request['comment'], 'emailed_to' => $request['emailed_to'], 'email' => $request['emailed_to'] == '' ? 0 : 1]); LeadLog::create(['ex_lead_id' => $lead_id, 'log_id' => $log->id]); DB::commit(); return true; } catch (\Exception $e) { DB::rollback(); dd($e); return false; } }