Example #1
0
 function add(array $request)
 {
     DB::beginTransaction();
     try {
         $client = Client::create(['preferred_name' => $request['preferred_name'], 'given_name' => $request['given_name'], 'surname' => $request['surname'], 'email' => $request['email'], 'salary' => $request['salary'], 'occupation' => $request['occupation'], 'salary_type' => $request['salary_type'], 'introducer' => $request['introducer'], 'title' => $request['title'], 'added_by_users_id' => \Auth::user()->id]);
         $address = Addresses::create(['line1' => $request['line1'], 'line2' => $request['line2'], 'suburb' => $request['suburb'], 'state' => $request['state'], 'postcode' => $request['postcode'], 'country' => $request['country']]);
         $client_address = ClientAddress::create(['ex_clients_id' => $client->id, 'address_type_id' => 1, 'is_current' => 1, 'address_id' => $address->id]);
         /* Add Phone numbers*/
         $phone_numbers = $request['phone'];
         foreach ($phone_numbers as $key => $phone_num) {
             if ($phone_num != '') {
                 $phone = Phone::create(['number' => $phone_num, 'type' => $request['phonetype'][$key]]);
                 ClientPhone::create(['phones_id' => $phone->id, 'ex_clients_id' => $client->id]);
             }
         }
         DB::commit();
         return $client->id;
         // all good
     } catch (\Exception $e) {
         DB::rollback();
         dd($e);
         // something went wrong
     }
     if ($client) {
         return true;
     } else {
         return false;
     }
 }
Example #2
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;
     }
 }