public function add($employment_id, $request, $key) { $business_address = Addresses::create(['line1' => $request['accountant_line1'][$key], 'line2' => $request['accountant_line2'][$key], 'suburb' => $request['accountant_suburb'][$key], 'state' => $request['accountant_state'][$key], 'postcode' => $request['accountant_postcode'][$key], 'country' => $request['accountant_country'][$key]]); AccountantDetails::create(['accountant_business_name' => $request['accountant_business_name'][$key], 'contact_person' => $request['accountant_contact_person'][$key], 'phone_number' => $request['accountant_phone_number'][$key], 'business_address_id' => $business_address->id, 'employment_details_id' => $employment_id]); }
function deleteRemoved($lead_id, $income_ids) { $lead = new Lead(); $applicantIds = $lead->getLeadApplicantIds($lead_id); $old_ids = EmploymentDetails::whereIn('applicant_id', $applicantIds)->lists('id')->toArray(); $removed_incomes = array_diff($old_ids, $income_ids); $addressIds = EmploymentDetails::whereIn('id', $removed_incomes)->lists('address_id')->toArray(); $accountants = AccountantDetails::whereIn('employment_details_id', $removed_incomes); $accountant_address_ids = $accountants->lists('business_address_id')->toArray(); $accountants->delete(); Addresses::whereIn('id', $accountant_address_ids)->delete(); EmploymentIncome::whereIn('employment_detail_id', $removed_incomes)->delete(); EmploymentDetails::whereIn('id', $removed_incomes)->delete(); Addresses::whereIn('id', $addressIds)->delete(); }
function remove($client_id) { DB::beginTransaction(); try { //get details $client = Client::find($client_id); //change this later for multiple addresses $client_address = ClientAddress::where('ex_clients_id', $client->id)->first(); $address = Addresses::find($client_address->address_id); //phone numbers $all_client_phones = ClientPhone::where('ex_clients_id', $client->id); $client_phones = $all_client_phones->get(); $all_client_phones->delete(); /* delete data */ //delete phone numbers if (!empty($client_phones)) { foreach ($client_phones as $client_phone) { $phones = Phone::find($client_phone->phones_id)->delete(); } } //delete address $client_address->delete(); $address->delete(); //delete client $client->delete(); DB::commit(); // all good } catch (\Exception $e) { DB::rollback(); dd($e); // something went wrong } }
function addAddressDetails($request, $key, $applicant_id) { $home_address = Addresses::create(['line1' => $request['home_line1'][$key], 'line2' => $request['home_line2'][$key], 'suburb' => $request['home_suburb'][$key], 'state' => $request['home_state'][$key], 'postcode' => $request['home_postcode'][$key], 'country' => $request['home_country'][$key]]); ApplicantAddress::create(['address_id' => $home_address->id, 'applicant_id' => $applicant_id, 'iscurrent' => 1, 'address_type_id' => 1, 'live_there_since' => $request['live_there_since'][$key]]); /*RentExpense::create([ 'weekly_rent_expense' => $request['weekly_rent_expense'][$key], 'applicant_id' => $applicant_id, 'debit_from' => $request['debit_from'][$key] ]);*/ $postal_address = Addresses::create(['line1' => $request['postal_line1'][$key], 'line2' => $request['postal_line2'][$key], 'suburb' => $request['postal_suburb'][$key], 'state' => $request['postal_state'][$key], 'postcode' => $request['postal_postcode'][$key], 'country' => $request['postal_country'][$key]]); ApplicantAddress::create(['address_id' => $postal_address->id, 'applicant_id' => $applicant_id, 'iscurrent' => 0, 'address_type_id' => 3]); $previous_address = Addresses::create(['line1' => $request['previous_line1'][$key], 'line2' => $request['previous_line2'][$key], 'suburb' => $request['previous_suburb'][$key], 'state' => $request['previous_state'][$key], 'postcode' => $request['previous_postcode'][$key], 'country' => $request['previous_country'][$key]]); ApplicantAddress::create(['address_id' => $previous_address->id, 'applicant_id' => $applicant_id, 'iscurrent' => 0, 'address_type_id' => 4]); }
function deleteRemoved($lead_id, $property_ids) { $lead = new Lead(); $applicantIds = $lead->getLeadApplicantIds($lead_id); $old_ids = Property::whereIn('applicant_id', $applicantIds)->lists('id')->toArray(); $removed_properties = array_diff($old_ids, $property_ids); ExistingLoan::whereIn('property_id', $removed_properties)->delete(); Income::whereIn('property_id', $removed_properties)->delete(); ValuationAccess::whereIn('property_id', $removed_properties)->delete(); $props = Property::whereIn('id', $removed_properties); $removed_addresses = $props->lists('address_id')->toArray(); $props->delete(); Addresses::whereIn('id', $removed_addresses)->delete(); }