public function addPropertyRequest(Request $request) { $param_rules = array(); $params = $request->all(); $response = $this->__validateRequestParams($request->all(), $param_rules, ["property_id.exists" => "Property not published"]); if ($this->__is_error == true) return $response; $sMessage = "Property request submitted successfully."; if (!empty($request['property_id']) && $request['property_id'] > 0) { $sMessage = "Thank you for sending property request."; $PropertyRequest = new PropertyRequest(); $PropertyRequest->fill($params)->save(); $pdf_property_request_id = $PropertyRequest->id; $PropertyRequestVehicle = []; if (!empty($request['is_vehicle']) && $request['is_vehicle'] == 1) { for ($i = 0; $i < count($request->vehicle_name); $i++) { $PropertyRequestVehicle[$i]['property_request_id'] = $PropertyRequest->id; $PropertyRequestVehicle[$i]["vehicle_name"] = $request->vehicle_name[$i]; $PropertyRequestVehicle[$i]["vehicle_year"] = $request->vehicle_year[$i]; } PropertyRequestVehicle::insert($PropertyRequestVehicle); } if (isset($request['is_co_applicant']) && $request['is_co_applicant'] == 1) { for ($i = 0; $i < count($request->co_applicant_name); $i++) { $PropertyRequestCoApplicant = new PropertyRequestCoApplicant(); $PropertyRequestCoApplicant->property_request_id = $PropertyRequest->id; $PropertyRequestCoApplicant->co_applicant_name = $request->co_applicant_name[$i]; //$PropertyRequestCoApplicant->co_applicant_description = isset($request->co_applicant_description) ? $request->co_applicant_description[$i] : ""; $PropertyRequestCoApplicant->co_applicant_phone = $request->co_applicant_phone[$i]; $PropertyRequestCoApplicant->save(); } } $identifier_data = 'add_property_request_owner'; $property_id = $request['property_id']; $user = User::where('id', $request->user_id)->first(); $property = Property::where('id', $property_id)->first(); $targetUser = User::where('id', $property->user_id)->first(); $notification_settings = DB::select("SELECT * FROM notification_settings WHERE user_id = '" . $targetUser->id . "' AND is_notification_on = 1"); if (count($notification_settings) > 0) { $message_data = "You have received a request against property '" . $property->ad_title . "'."; $name = $user->first_name . " " . $user->last_name; $notification_data = [ 'appName' => 'Rent Now', 'user' => $user, 'targetUser' => $targetUser, 'referenceId' => $PropertyRequest->id, 'propertyRequestId' => $PropertyRequest->id, 'propertyId' => $property_id, 'title' => $name, 'referenceModule' => 'Property Rent Request', 'notificationIdentifier' => $identifier_data ]; $custom_data = ['propertyRequestId' => $PropertyRequest->id, 'propertyId' => $property_id, 'identifier' => $identifier_data, 'title' => $name, 'message' => $message_data]; NotificationIdentifier::notificationIdentifier('add_property_request_owner', $notification_data, $custom_data); $user = User::where('id', $targetUser->id)->first(); $mail_params['USER_NAME'] = $user->first_name . ' ' . $user->last_name; $mail_params['CONFIRMATION_LINK'] = url("/cat-detail/" . $PropertyRequest->property_id); $mail_params['PDF_LINK'] = url("/property-request-pdf/".'property-request-'.$pdf_property_request_id.'.pdf'); $mail_params['APP_NAME'] = getAppName(); sendMail($user->email, 'add_property_request_owner', $mail_params); } } $user_property_request = UserPropertyRequest::getUserPropertyRequestsByUserId($request->user_id); if (count($user_property_request) == 0) { $PropertyRequest = new UserPropertyRequest(); $PropertyRequest->user_id = trim($request['user_id']); if (isset($request['first_name']) && $request['first_name'] != "") { $PropertyRequest->first_name = trim($request['first_name']); } if (isset($request['last_name']) && $request['last_name'] != "") { $PropertyRequest->last_name = trim($request['last_name']); } if (isset($request['phone_number']) && $request['phone_number'] != "") { $PropertyRequest->phone_number = trim($request['phone_number']); } if (isset($request['email_address']) && $request['email_address'] != "") { $PropertyRequest->email_address = trim($request['email_address']); } if (isset($request['deposit']) && $request['deposit'] != "") { $PropertyRequest->deposit = trim($request['deposit']); } if (isset($request['age']) && $request['age'] != "") { $PropertyRequest->age = trim($request['age']); } if (isset($request['no_of_adults']) && $request['no_of_adults'] != "") { $PropertyRequest->no_of_adults = trim($request['no_of_adults']); } if (isset($request['no_of_kids']) && $request['no_of_kids'] != "") { $PropertyRequest->no_of_kids = trim($request['no_of_kids']); } if (isset($request['pets']) && $request['pets'] != "") { $PropertyRequest->pets = trim($request['pets']); } if (isset($request['no_of_pets']) && $request['no_of_pets'] != "") { $PropertyRequest->no_of_pets = trim($request['no_of_pets']); } if (isset($request['is_employed']) && $request['is_employed'] != "") { $PropertyRequest->is_employed = trim($request['is_employed']); } if (isset($request['position']) && $request['position'] != "") { $PropertyRequest->position = trim($request['position']); } if (isset($request['annual_income']) && $request['annual_income'] != "") { $PropertyRequest->annual_income = trim($request['annual_income']); } if (isset($request['length_of_service']) && $request['length_of_service'] != "") { $PropertyRequest->length_of_service = trim($request['length_of_service']); } if (isset($request['supervisor_name']) && $request['supervisor_name'] != "") { $PropertyRequest->supervisor_name = trim($request['supervisor_name']); } if (isset($request['supervisor_phone_number']) && $request['supervisor_phone_number'] != "") { $PropertyRequest->supervisor_phone_number = trim($request['supervisor_phone_number']); } if (isset($request['credit_history_id']) && $request['credit_history_id'] != "") { $PropertyRequest->credit_history_id = trim($request['credit_history_id']); } if (isset($request['landlord_reference_id']) && $request['landlord_reference_id'] != "") { $PropertyRequest->landlord_reference_id = trim($request['landlord_reference_id']); } if (isset($request['length_of_tenancy']) && $request['length_of_tenancy'] != "") { $PropertyRequest->length_of_tenancy = trim($request['length_of_tenancy']); } if (isset($request['current_rate']) && $request['current_rate'] != "") { $PropertyRequest->current_rate = trim($request['current_rate']); } if (isset($request['landlord_phone_no']) && $request['landlord_phone_no'] != "") { $PropertyRequest->landlord_phone_no = trim($request['landlord_phone_no']); } if (isset($request['current_rate']) && $request['current_rate'] != "") { $PropertyRequest->current_rate = trim($request['current_rate']); } if (isset($request['landlord_phone_no']) && $request['landlord_phone_no'] != "") { $PropertyRequest->landlord_phone_no = trim($request['landlord_phone_no']); } if (isset($request['landlord_name']) && $request['landlord_name'] != "") { $PropertyRequest->landlord_name = trim($request['landlord_name']); } if (isset($request['name']) && $request['name'] != "") { $PropertyRequest->name = trim($request['name']); } if (isset($request['personal_reference_id']) && $request['personal_reference_id'] != "") { $PropertyRequest->personal_reference_id = trim($request['personal_reference_id']); } if (isset($request['relationship']) && $request['relationship'] != "") { $PropertyRequest->relationship = trim($request['relationship']); } if (isset($request['secondary_phone_number']) && $request['secondary_phone_number'] != "") { $PropertyRequest->secondary_phone_number = trim($request['secondary_phone_number']); } if (isset($request['is_vehicle']) && $request['is_vehicle'] != "") { $PropertyRequest->is_vehicle = trim($request['is_vehicle']); } if (isset($request['is_message_to_landlord']) && $request['is_message_to_landlord'] != "") { $PropertyRequest->is_message_to_landlord = trim($request['is_message_to_landlord']); } if (isset($request['message_to_landlord']) && $request['message_to_landlord'] != "") { $PropertyRequest->message_to_landlord = trim($request['message_to_landlord']); } if (isset($request['is_consent_check']) && $request['is_consent_check'] != "") { $PropertyRequest->is_consent_check = trim($request['is_consent_check']); } if (isset($request['company_name']) && $request['company_name'] != "") { $PropertyRequest->company_name = trim($request['company_name']); } if (isset($request['is_co_applicant']) && $request['is_co_applicant'] != "") { $PropertyRequest->is_co_applicant = trim($request['is_co_applicant']); } if (isset($request['nummber_of_cats']) && $request['nummber_of_cats'] != "") { $PropertyRequest->nummber_of_cats = trim($request['nummber_of_cats']); } if (isset($request['nummber_of_dogs']) && $request['nummber_of_dogs'] != "") { $PropertyRequest->nummber_of_dogs = trim($request['nummber_of_dogs']); } if (isset($request['nummber_of_others']) && $request['nummber_of_others'] != "") { $PropertyRequest->nummber_of_others = trim($request['nummber_of_others']); } if (isset($request['co_applicant_description']) && !empty(trim($request['co_applicant_description']))) { $PropertyRequest->co_applicant_description = trim($request['co_applicant_description']); } $PropertyRequest->save(); if (isset($request['is_vehicle']) && $request['is_vehicle'] != "") { if (isset($request['vehicle_name']) && count($request['vehicle_name']) > 0) { for ($i = 0; $i < count($request->vehicle_name); $i++) { $PropertyRequestVehicle = new UserPropertyRequestVehicle(); $PropertyRequestVehicle->user_property_request_id = $PropertyRequest->id; $PropertyRequestVehicle->user_id = trim($request['user_id']); $PropertyRequestVehicle->vehicle_name = $request->vehicle_name[$i]; $PropertyRequestVehicle->vehicle_year = $request->vehicle_year[$i]; $PropertyRequestVehicle->save(); } } } if (isset($request['is_co_applicant']) && $request['is_co_applicant'] != "") { if (isset($request['co_applicant_name']) && count($request['co_applicant_name']) > 0) { for ($i = 0; $i < count($request->co_applicant_name); $i++) { $UserPropertyRequestCoApplicant = new UserPropertyRequestCoApplicant(); $UserPropertyRequestCoApplicant->user_property_request_id = $PropertyRequest->id; $UserPropertyRequestCoApplicant->user_id = trim($request['user_id']); $UserPropertyRequestCoApplicant->co_applicant_name = $request->co_applicant_name[$i]; $UserPropertyRequestCoApplicant->co_applicant_description = isset($request->co_applicant_description) ? $request->co_applicant_description[$i] : ''; // $UserPropertyRequestCoApplicant->co_applicant_phone = $request->co_applicant_phone[$i]; $UserPropertyRequestCoApplicant->save(); } } } } else { $UserPropertyRequest = array(); if (isset($request['first_name']) && $request['first_name'] != "") { $UserPropertyRequest['first_name'] = trim($request['first_name']); } if (isset($request['last_name']) && $request['last_name'] != "") { $UserPropertyRequest['last_name'] = trim($request['last_name']); } if (isset($request['phone_number']) && $request['phone_number'] != "") { $UserPropertyRequest['phone_number'] = trim($request['phone_number']); } if (isset($request['email_address']) && $request['email_address'] != "") { $UserPropertyRequest['email_address'] = trim($request['email_address']); } if (isset($request['deposit']) && $request['deposit'] != "") { $UserPropertyRequest['deposit'] = trim($request['deposit']); } if (isset($request['age']) && $request['age'] != "") { $UserPropertyRequest['age'] = trim($request['age']); } if (isset($request['no_of_adults']) && $request['no_of_adults'] != "") { $UserPropertyRequest['no_of_adults'] = trim($request['no_of_adults']); } if (isset($request['no_of_kids']) && $request['no_of_kids'] != "") { $UserPropertyRequest['no_of_kids'] = trim($request['no_of_kids']); } if (isset($request['pets']) && $request['pets'] != "") { $UserPropertyRequest['pets'] = trim($request['pets']); } if (isset($request['no_of_pets']) && $request['no_of_pets'] != "") { $UserPropertyRequest['no_of_pets'] = trim($request['no_of_pets']); } if (isset($request['is_employed']) && $request['is_employed'] != "") { $UserPropertyRequest['is_employed'] = trim($request['is_employed']); } else { $UserPropertyRequest['is_employed'] = 0; } if (isset($request['position']) && $request['position'] != "") { $UserPropertyRequest['position'] = trim($request['position']); } if (isset($request['annual_income']) && $request['annual_income'] != "") { $UserPropertyRequest['annual_income'] = trim($request['annual_income']); } if (isset($request['length_of_service']) && $request['length_of_service'] != "") { $UserPropertyRequest['length_of_service'] = trim($request['length_of_service']); } if (isset($request['supervisor_name']) && $request['supervisor_name'] != "") { $UserPropertyRequest['supervisor_name'] = trim($request['supervisor_name']); } if (isset($request['supervisor_phone_number']) && $request['supervisor_phone_number'] != "") { $UserPropertyRequest['supervisor_phone_number'] = trim($request['supervisor_phone_number']); } if (isset($request['credit_history_id']) && $request['credit_history_id'] != "") { $UserPropertyRequest['credit_history_id'] = trim($request['credit_history_id']); } if (isset($request['landlord_reference_id']) && $request['landlord_reference_id'] != "") { $UserPropertyRequest['landlord_reference_id'] = trim($request['landlord_reference_id']); } if (isset($request['length_of_tenancy']) && $request['length_of_tenancy'] != "") { $UserPropertyRequest['length_of_tenancy'] = trim($request['length_of_tenancy']); } if (isset($request['current_rate']) && $request['current_rate'] != "") { $UserPropertyRequest['current_rate'] = trim($request['current_rate']); } if (isset($request['landlord_phone_no']) && $request['landlord_phone_no'] != "") { $UserPropertyRequest['landlord_phone_no'] = trim($request['landlord_phone_no']); } if (isset($request['landlord_name']) && $request['landlord_name'] != "") { $UserPropertyRequest['landlord_name'] = trim($request['landlord_name']); } if (isset($request['name']) && $request['name'] != "") { $UserPropertyRequest['name'] = trim($request['name']); } if (isset($request['personal_reference_id']) && $request['personal_reference_id'] != "") { $UserPropertyRequest['personal_reference_id'] = trim($request['personal_reference_id']); } if (isset($request['relationship']) && $request['relationship'] != "") { $UserPropertyRequest['relationship'] = trim($request['relationship']); } if (isset($request['secondary_phone_number']) && $request['secondary_phone_number'] != "") { $UserPropertyRequest['secondary_phone_number'] = trim($request['secondary_phone_number']); } if (isset($request['is_vehicle']) && $request['is_vehicle'] != "") { $UserPropertyRequest['is_vehicle'] = trim($request['is_vehicle']); } else { $UserPropertyRequest['is_vehicle'] = 0; } if (isset($request['is_message_to_landlord']) && $request['is_message_to_landlord'] != "") { $UserPropertyRequest['is_message_to_landlord'] = trim($request['is_message_to_landlord']); } else { $UserPropertyRequest['is_message_to_landlord'] = 0; } if (isset($request['message_to_landlord']) && $request['message_to_landlord'] != "") { $UserPropertyRequest['message_to_landlord'] = trim($request['message_to_landlord']); } else { $UserPropertyRequest['message_to_landlord'] = ""; } if (isset($request['is_consent_check']) && $request['is_consent_check'] != "") { $UserPropertyRequest['is_consent_check'] = trim($request['is_consent_check']); } else { $UserPropertyRequest['is_consent_check'] = 0; } if (isset($request['company_name']) && $request['company_name'] != "") { $UserPropertyRequest['company_name'] = trim($request['company_name']); } if (isset($request['is_co_applicant']) && $request['is_co_applicant'] != "") { $UserPropertyRequest['is_co_applicant'] = trim($request['is_co_applicant']); } else { $UserPropertyRequest['is_co_applicant'] = 0; } if (isset($request['nummber_of_cats']) && $request['nummber_of_cats'] != "") { $UserPropertyRequest['nummber_of_cats'] = trim($request['nummber_of_cats']); } if (isset($request['nummber_of_dogs']) && $request['nummber_of_dogs'] != "") { $UserPropertyRequest['nummber_of_dogs'] = trim($request['nummber_of_dogs']); } if (isset($request['nummber_of_others']) && $request['nummber_of_others'] != "") { $UserPropertyRequest['nummber_of_others'] = trim($request['nummber_of_others']); } if (isset($request['co_applicant_description']) && !empty(trim($request['co_applicant_description']))) { $UserPropertyRequest['co_applicant_description'] = trim($request['co_applicant_description']); } UserPropertyRequest::where('user_id', $request['user_id'])->update($UserPropertyRequest); if (isset($request['is_vehicle']) && $request['is_vehicle'] != "") { if (isset($request->vehicle_name) && count($request->vehicle_name) > 0) { UserPropertyRequest::deleteUserPropertyRequest($request['user_id']); for ($i = 0; $i < count($request->vehicle_name); $i++) { $PropertyRequestVehicle = new UserPropertyRequestVehicle(); $PropertyRequestVehicle->user_id = trim($request['user_id']); $PropertyRequestVehicle->user_property_request_id = $user_property_request[0]->id; $PropertyRequestVehicle->vehicle_name = $request->vehicle_name[$i]; $PropertyRequestVehicle->vehicle_year = $request->vehicle_year[$i]; $PropertyRequestVehicle->save(); } } } if (isset($request['is_co_applicant']) && $request['is_co_applicant'] != "") { if (isset($request->co_applicant_name) && count($request->co_applicant_name) > 0) { UserPropertyRequest::deleteUserPropertyRequestCoApplicants($request['user_id']); for ($i = 0; $i < count($request->co_applicant_name); $i++) { $UserPropertyRequestCoApplicant = new UserPropertyRequestCoApplicant(); $UserPropertyRequestCoApplicant->user_id = trim($request['user_id']); $UserPropertyRequestCoApplicant->user_property_request_id = $user_property_request[0]->id; $UserPropertyRequestCoApplicant->co_applicant_name = $request->co_applicant_name[$i]; $UserPropertyRequestCoApplicant->co_applicant_phone = $request->co_applicant_phone[$i]; $UserPropertyRequestCoApplicant->co_applicant_description= isset($request->co_applicant_description) ? $request->co_applicant_description[$i] : ""; $UserPropertyRequestCoApplicant->save(); } } } } $PropertyRequests = UserPropertyRequest::getUserPropertyRequestsByUserId($request->user_id); $PropertyRequestsArray = array(); $PropertyRequestsArray2 = array(); if (count($PropertyRequests) > 0) { foreach ($PropertyRequests as $PropertyRequest) { $PropertyRequestsArray['user_id'] = $PropertyRequest->user_id; $PropertyRequestsArray['first_name'] = $PropertyRequest->first_name; $PropertyRequestsArray['company_name'] = $PropertyRequest->company_name; $PropertyRequestsArray['last_name'] = $PropertyRequest->last_name; $PropertyRequestsArray['phone_number'] = $PropertyRequest->phone_number; $PropertyRequestsArray['deposit'] = $PropertyRequest->deposit; $PropertyRequestsArray['age'] = $PropertyRequest->age; $PropertyRequestsArray['no_of_adults'] = $PropertyRequest->no_of_adults; $PropertyRequestsArray['no_of_kids'] = $PropertyRequest->no_of_kids; $PropertyRequestsArray['pets'] = $PropertyRequest->pets; $PropertyRequestsArray['no_of_pets'] = $PropertyRequest->no_of_pets; $is_employed = ""; if($PropertyRequest->is_employed==0){ $is_employed = "No"; } elseif($PropertyRequest->is_employed==1){ $is_employed = "Yes"; }else{ $is_employed = "Others"; } $PropertyRequestsArray['is_employed'] = $is_employed; $PropertyRequestsArray['position'] = $PropertyRequest->position; $PropertyRequestsArray['annual_income'] = $PropertyRequest->annual_income; $PropertyRequestsArray['length_of_service'] = $PropertyRequest->length_of_service; $PropertyRequestsArray['supervisor_name'] = $PropertyRequest->supervisor_name; $PropertyRequestsArray['supervisor_phone_number'] = $PropertyRequest->supervisor_phone_number; $PropertyRequestsArray['credit_history_id'] = $PropertyRequest->credit_history_id; $PropertyRequestsArray['landlord_reference_id'] = $PropertyRequest->landlord_reference_id; $PropertyRequestsArray['length_of_tenancy'] = $PropertyRequest->length_of_tenancy; $PropertyRequestsArray['current_rate'] = $PropertyRequest->current_rate; $PropertyRequestsArray['landlord_phone_no'] = $PropertyRequest->landlord_phone_no; $PropertyRequestsArray['landlord_name'] = $PropertyRequest->landlord_name; $PropertyRequestsArray['name'] = $PropertyRequest->name; $PropertyRequestsArray['personal_reference_id'] = $PropertyRequest->personal_reference_id; $PropertyRequestsArray['relationship'] = $PropertyRequest->relationship; $PropertyRequestsArray['secondary_phone_number'] = $PropertyRequest->secondary_phone_number; $PropertyRequestsArray['is_vehicle'] = $PropertyRequest->is_vehicle; $property_request_vehicles = DB::select("SELECT * FROM user_property_request_vehicles WHERE user_id = '" . $PropertyRequest->user_id . "'"); if (count($property_request_vehicles) > 0) { $PropertyRequestsArray['property_request_vehicles'] = $property_request_vehicles; } $property_request_co_applicants = DB::select("SELECT * FROM user_property_request_co_applicants WHERE user_id = '" . $PropertyRequest->user_id . "'"); if (count($property_request_co_applicants) > 0) { $PropertyRequestsArray['property_request_co_applicants'] = $property_request_co_applicants; }else{ $PropertyRequestsArray['property_request_co_applicants'] = array(); } $PropertyRequestsArray['is_message_to_landlord'] = $PropertyRequest->is_message_to_landlord; $PropertyRequestsArray['message_to_landlord'] = $PropertyRequest->message_to_landlord; $PropertyRequestsArray['is_consent_check'] = $PropertyRequest->is_consent_check; $PropertyRequestsArray['is_co_applicant'] = $PropertyRequest->is_co_applicant; $PropertyRequestsArray['co_applicant_name'] = $PropertyRequest->co_applicant_name; $PropertyRequestsArray['co_applicant_description'] = isset($PropertyRequest->co_applicant_description) ? $PropertyRequest->co_applicant_description : ''; $PropertyRequestsArray['co_applicant_phone'] = $PropertyRequest->co_applicant_phone; $PropertyRequestsArray['co_applicant_description'] = $PropertyRequest->co_applicant_description; $PropertyRequestsArray2[] = $PropertyRequestsArray; } } if (isset($request['property_id']) && $request['property_id'] > 0) { $pdf_html = view("pdf.property_request", ['property_data' => $PropertyRequests[0]])->render(); $pdf = PDF::loadHTML($pdf_html); $output = $pdf->output(); file_put_contents(public_path(Config::get("constants.PROPERTY_REQUEST_PDF")).'property-request-'.$pdf_property_request_id.'.pdf', $output); } $this->__is_paginate = false; $this->__is_collection = false; $this->__collection = false; return $this->__sendResponse($PropertyRequestsArray2[0], 200, $sMessage); }