public function getXMLLamudi() { $return = []; $qb = Property::active(); AddressHelper::addAddressQueryScope($qb); //By exclusive $qb->selectRaw('properties.*, IF(Pac.slug = \'exclusive\', 1, 0) as is_exclusive'); $qb->leftJoin('package_property AS PP', 'PP.property_id', '=', 'properties.id')->leftJoin('packages AS Pac', 'PP.package_id', '=', 'Pac.id')->leftJoin('package_categories AS PC', 'PC.id', '=', 'Pac.package_category_id'); $qb->groupBy('properties.id'); $qb->orderBy('is_exclusive', 'DESC'); $sellProperties = $qb->where('for_sell', 1)->get(); foreach ($sellProperties as $property) { if ($property->hasThumbnail() || $property->hasFloorplan()) { $propertyData = $this->generatePropertyData($property, 'sell'); $return[] = $propertyData; } } $rentProperties = $qb->where('for_rent', 1)->get(); foreach ($rentProperties as $property) { if ($property->hasThumbnail() || $property->hasFloorplan()) { $propertyData = $this->generatePropertyData($property, 'rent'); $return[] = $propertyData; } } return response()->xml($return, 200, [], 'Properties', null, 'Data'); }
public function getInbox($property_id = NULL) { $property = Property::find($property_id); if ($property && $property->status == Property::STATUS_DRAFT) { return redirect()->back()->withErrors([trans('property.messages.unauthorized_access')]); } $user = Auth::user(); $qb = $user->likedProperties(); AddressHelper::addAddressQueryScope($qb->getQuery()); $interested_properties = $qb->get(); $myPropertiesQb = $user->properties()->whereNotIn('status', [Property::STATUS_DRAFT]); AddressHelper::addAddressQueryScope($myPropertiesQb->getQuery()); $my_properties = $myPropertiesQb->get(); $confirmedViewingSchedule = null; if ($property) { $confirmedViewingSchedule = ViewingSchedule::confirmed()->where('property_id', $property->id)->where('user_id', $user->id)->first(); } return view('frontend.account.inbox', ['interested_properties' => $interested_properties, 'property' => $property, 'conversation' => $user->getPropertyConversation($property), 'user' => $user, 'confirmedViewingSchedule' => $confirmedViewingSchedule, 'my_properties' => $my_properties]); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { $user = Auth::user(); $qb = ReferralInformation::orderBy('created_at', 'DESC'); AddressHelper::addAddressQueryScope($qb); if ($request->has('search')) { if ($request->has('search.keyword')) { $qb->where(function ($query) use($request) { $query->orWhere('name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('contact_number', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('other_contact_number', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('email', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('address', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('province_name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('city_name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('subdistrict_name', 'LIKE', '%' . $request->input('search.keyword') . '%'); }); } if ($request->has('search.agent')) { $qb->whereHas('user', function ($query) use($request) { $query->where('id', $request->input('search.agent')); }); } if ($request->input('search.status', 'all') != 'all') { $qb->where('status', $request->input('search.status')); } if ($request->input('search.followed_up', 'all') != 'all') { $followedUp = $request->input('search.followed_up') == 'yes'; $qb->where('followed_up', $followedUp); } } $agentOptions = []; if ($user->is('agent')) { $qb->where('user_id', $user->id); } elseif ($user->is('property_manager')) { $qb->where('province', $user->profile->province); } else { $agentOptions = AgentHelper::getAgentOptions(); } $referrals = $qb->paginate(50); $referrals->appends(['search' => $request->input('search')]); $statusOptions = ['all' => 'Status'] + ReferralInformation::getStatusOptions(); $followedUpOptions = ['all' => 'Follow Up Status', 'yes' => 'Followed Up', 'no' => 'Unfollowed Up']; return view('admin.referrals.index', ['referrals' => $referrals, 'statusOptions' => $statusOptions, 'followedUpOptions' => $followedUpOptions, 'agentOptions' => $agentOptions]); }
public function indexAgent(Request $request, $type) { $user = $request->user(); switch ($type) { case 'referral-listing': $title = 'My Referral Properties'; $field = 'referral_list_id'; break; } $qb = Property::with(['agentList'])->whereNotNull('checkout_at')->orderBy('checkout_at', 'DESC'); AddressHelper::addAddressQueryScope($qb); $qb->where('properties.' . $field, $user->id); if ($request->has('search')) { if ($request->input('search.deleted', false)) { $qb->onlyTrashed(); } if ($request->has('search.keyword')) { $qb->where(function ($query) use($request) { $query->orWhere('listing_code', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('address', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('description', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('property_name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('province_name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('city_name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('subdistrict_name', 'LIKE', '%' . $request->input('search.keyword') . '%'); }); } if ($request->has('search.for')) { $qb->where('for_' . $request->input('search.for'), 1); } if ($request->has('search.owner')) { $qb->whereHas('user', function ($query) use($request) { $query->where('email', $request->input('search.owner')); }); } if ($request->has('search.upload_date')) { $uploadDateFilter = Carbon::createFromFormat('d-m-Y', $request->input('search.upload_date')); $qb->where('checkout_at', '>=', $uploadDateFilter->format('Y-m-d')); $qb->where('checkout_at', '<', $uploadDateFilter->modify('+1 day')->format('Y-m-d')); } if ($request->has('search.agentList')) { if ($request->input('search.agentList') == 'unassigned') { $qb->whereNull('agent_list_id'); } else { $qb->whereHas('agentList', function ($query) use($request) { $query->where('id', $request->input('search.agentList')); }); } } if ($request->has('search.agentSell')) { if ($request->input('search.agentSell') == 'unassigned') { $qb->whereNull('agent_sell_id'); } else { $qb->whereHas('agentSell', function ($query) use($request) { $query->where('id', $request->input('search.agentSell')); }); } } if ($request->has('search.referralList')) { if ($request->input('search.referralList') == 'unassigned') { $qb->whereNull('referral_list_id'); } else { $qb->whereHas('referralList', function ($query) use($request) { $query->where('id', $request->input('search.referralList')); }); } } if ($request->has('search.referralSell')) { if ($request->input('search.referralSell') == 'unassigned') { $qb->whereNull('referral_sell_id'); } else { $qb->whereHas('referralSell', function ($query) use($request) { $query->where('id', $request->input('search.referralSell')); }); } } if ($request->has('search.status')) { $qb->where('status', $request->input('search.status')); } } $properties = $qb->paginate(50); $properties->appends(['search' => $request->input('search')]); $forOptions = ['' => 'For', 'sell' => 'Sell', 'rent' => 'Rent']; $statusOptions = ['' => 'Status'] + Property::getStatusLabel(); unset($statusOptions[Property::STATUS_DRAFT]); return view('admin.property.index_agent', ['title' => $title, 'properties' => $properties, 'forOptions' => $forOptions, 'statusOptions' => $statusOptions]); }
public function getSearch(Request $request) { $for = $request->input('search.for'); $priceDefaultFrom = 10000000; $priceDefaultTo = 100000000000; $qb = Property::active(); AddressHelper::addAddressQueryScope($qb); if ($request->input('search.for') == 'sell') { $qb->where('for_sell', 1); } elseif ($request->input('search.for') == 'rent') { $qb->where('for_rent', 1); } if ($request->has('search.keyword')) { $qb->where(function ($query) use($request) { $query->orWhere('address', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('description', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('property_name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('province_name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('city_name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('subdistrict_name', 'LIKE', '%' . $request->input('search.keyword') . '%'); }); } $citySearch = ''; if ($request->has('search.subdistrict')) { $qb->where('subdistrict', $request->input('search.subdistrict')); $citySearch = AddressHelper::getAddressLabel($request->input('search.subdistrict'), 'subdistrict'); } if ($request->has('search.city')) { $qb->where('city', $request->input('search.city')); if (!empty($citySearch)) { $citySearch .= ', '; } $citySearch .= AddressHelper::getAddressLabel($request->input('search.city'), 'city'); } if ($request->has('search.province')) { $qb->where('province', $request->input('search.province')); if (empty($citySearch)) { $citySearch = AddressHelper::getAddressLabel($request->input('search.province'), 'province'); } } if ($request->has('search.rooms')) { $qb->where('rooms', '>=', $request->input('search.rooms')); } if ($request->has('search.type')) { $qb->where('property_type_id', $request->input('search.type')); } if ($request->has('search.price')) { $price = explode(',', $request->input('search.price')); if (isset($price[0])) { $priceDefaultFrom = $price[0]; if ($for == 'sell') { $qb->where('sell_price', '>=', $priceDefaultFrom); } elseif ($for == 'rent') { $qb->where('rent_price', '>=', $priceDefaultFrom); } else { $qb->where(function ($query) use($priceDefaultFrom) { $query->where('sell_price', '>=', $priceDefaultFrom)->orWhere('rent_price', '>=', $priceDefaultFrom); }); } } if (isset($price[1])) { $priceDefaultTo = $price[1]; if ($for == 'sell') { $qb->where('sell_price', '<=', $priceDefaultTo); } elseif ($for == 'rent') { $qb->where('rent_price', '<=', $priceDefaultTo); } else { $qb->where(function ($query) use($priceDefaultTo) { $query->where('sell_price', '<=', $priceDefaultTo)->orWhere('rent_price', '<=', $priceDefaultTo); }); } } } $resultCount = $qb->count(); //By exclusive $qb->selectRaw('properties.*, IF(Pac.slug = \'exclusive\', 1, 0) as is_exclusive'); $qb->leftJoin('package_property AS PP', 'PP.property_id', '=', 'properties.id')->leftJoin('packages AS Pac', 'PP.package_id', '=', 'Pac.id')->leftJoin('package_categories AS PC', 'PC.id', '=', 'Pac.package_category_id'); $qb->groupBy('properties.id'); $qb->orderBy('is_exclusive', 'DESC'); //Sorts $sortKeys = explode('_', $request->input('sort', 'date_desc')); if ($sortKeys[0] == 'price') { if ($for != 'all' && $for) { $sortColumn = $for . '_' . $sortKeys[0]; } else { $sortColumn = 'all_price'; } } else { $sortColumn = 'checkout_at'; } $sortOrder = isset($sortKeys[1]) ? $sortKeys[1] : 'desc'; if ($sortColumn == 'all_price') { $qb->orderBy('sell_price', $sortOrder); $qb->orderBy('rent_price', $sortOrder); } else { $qb->orderBy($sortColumn, $sortOrder); } $properties = $qb->paginate(16); $properties->appends(['sort' => $request->input('sort'), 'search' => $request->input('search')]); $sorts = ['date_desc' => trans('property.index.sort_by.date_desc'), 'date_asc' => trans('property.index.sort_by.date_asc'), 'price_asc' => trans('property.index.sort_by.price_asc'), 'price_desc' => trans('property.index.sort_by.price_desc')]; return view('frontend.property.public.search', ['for' => $for, 'paginator' => $properties, 'citySearch' => $citySearch, 'resultCount' => $resultCount, 'priceDefaultFrom' => $priceDefaultFrom, 'priceDefaultTo' => $priceDefaultTo, 'sorts' => $sorts]); }