示例#1
0
 function add(array $request)
 {
     DB::beginTransaction();
     try {
         if ($request['ex_clients_id'] == 0) {
             $client = Client::create(['preferred_name' => $request['preferred_name'], 'title' => $request['title'], 'given_name' => $request['given_name'], 'surname' => $request['surname'], 'added_by_users_id' => \Auth::user()->id]);
             $phone_number = $request['phone'];
             $phone = Phone::create(['number' => $phone_number, 'type' => 'home']);
             ClientPhone::create(['phones_id' => $phone->id, 'ex_clients_id' => $client->id, 'is_current' => 1]);
             $client_id = $client->id;
         } else {
             $client_id = $request['ex_clients_id'];
         }
         $lead = Lead::create(['referral_notes' => $request['referral_notes'], 'status' => 0, 'ex_clients_id' => $client_id, 'added_by_users_id' => \Auth::user()->id]);
         $loan = Loan::create(['loan_purpose' => $request['loan_purpose'], 'loan_type' => $request['loan_type'], 'ex_leads_id' => $lead->id]);
         //add logs
         $log = Log::create(['added_by' => \Auth::user()->id, 'comment' => 'Lead Created']);
         LeadLog::create(['ex_lead_id' => $lead->id, 'log_id' => $log->id]);
         DB::commit();
         return $lead->id;
     } catch (\Exception $e) {
         DB::rollback();
         dd($e);
         return false;
     }
 }
示例#2
0
 function dataTablePagination(Request $request, array $select = array())
 {
     if (is_array($select) and count($select) < 1) {
         $select = "*";
     }
     $take = $request->input('length') > 0 ? $request->input('length') : 10;
     $start = $request->input('start') > 0 ? $request->input('start') : 0;
     $search = $request->input('search');
     $search = $search['value'];
     $order = $request->input('order');
     $column_id = $order[0]['column'];
     $columns = $request->input('columns');
     $orderColumn = $columns[$column_id]['data'];
     $orderdir = $order[0]['dir'];
     $client = array();
     $query = $this->select($select);
     if ($orderColumn != '' and $orderdir != '') {
         $query = $query->orderBy($orderColumn, $orderdir);
     }
     if ($search != '') {
         $query = $query->where('domain', 'LIKE', "%{$search}%")->orwhere('email', 'LIKE', "%{$search}%");
     }
     //if not super admin
     if (!current_user()->isSuperAdmin) {
         $query = $query->where('added_by_users_id', current_user_id());
     }
     $client['total'] = $query->count();
     $query->skip($start)->take($take);
     $data = $query->get();
     foreach ($data as $key => &$value) {
         $value->fullname = $value->given_name . " " . $value->surname;
         $value->DT_RowId = "row-" . $value->id;
         $phone = ClientPhone::where('ex_clients_id', $value->id)->where('is_current', 1)->with('phone')->first();
         $value->phone = !empty($phone) ? $phone->phone->number : '';
     }
     $client['data'] = $data->toArray();
     $json = new \stdClass();
     $json->draw = $request->input('draw') > 0 ? $request->input('draw') : 1;
     $json->recordsTotal = $client['total'];
     $json->recordsFiltered = $client['total'];
     $json->data = $client['data'];
     return $json;
 }