Файловый менеджер - Редактировать - /home/clickysoft/public_html/somni.clickysoft.net/app/Repositories/TenantRepository.php
Назад
<?php namespace App\Repositories; use App\Interfaces\TenantRepositoryInterface; use App\Repositories\WalletRepository; use App\Repositories\NotificationRepository; use App\Models\Property; use App\Models\Newsletter; use App\Models\Country; use App\Models\City; use App\Models\InvitationPropertyUnit; use App\Models\PropertyUnitTenant; use App\Models\Role; use App\Models\State; use App\Models\Unit; use App\Models\User; use App\Models\UserInfo; use App\Models\RentPayment; use Illuminate\Support\Facades\Hash; use DB; class TenantRepository implements TenantRepositoryInterface { public function getTenantById($user_id) { $tenant = User::whereHas('roles', function ($query) { $query->whereTitle('Tenant'); })->whereId($user_id)->first(); return $tenant; } public function createTenant($data) { return DB::transaction(function () use ($data) { $user = new User([ 'name' => $data->firstname . ' ' . $data->lastname, 'email' => $data->email, 'password' => Hash::make($data->password), 'has_completed_tour' => 0, 'phone' => $data->phone_number, 'about' => $data->bio, ]); $user->save(); $user->roles()->attach(Role::where('title', 'tenant')->first()); if (isset($data->languages) || isset($data->bio)) { $userInfo = new UserInfo([ 'user_id' => $user->id, 'languages' => $data->languages, 'bio' => $data->bio, ]); $userInfo->save(); } if (isset($data->subscribe)) { Newsletter::create(['email' => $data->email]); } $invitation = InvitationPropertyUnit::where('invitation_code', $data->invitationCode) ->where('email', $data->email) ->first(); if ($invitation) { $check_for_accepted = InvitationPropertyUnit::where('unit_id', $invitation->unit_id) ->get(); if($check_for_accepted->count() > 1){ foreach($check_for_accepted as $invite){ if($invite->is_accepted == 1){ DB::rollback(); return false; } } } $unit = Unit::find($invitation->unit_id); $propertyUnitTenant = new PropertyUnitTenant([ 'property_id' => $unit->property->id, 'unit_id' => $unit->id, 'tenant_user_id' => $user->id, 'from_date' => now(), ]); $propertyUnitTenant->save(); $invitation->is_accepted = true; $invitation->save(); $notiObj = new NotificationRepository; $landlord = $unit->property->user; $title = "Invitation Accepted"; $message = "The user ".$data->email." has accepted your invitation under the Unit: ".$unit->name."."; $sent = $notiObj->CreateAndSendNotification($landlord, $title, $message); $renting['user_id'] = $user->id; $renting['unit_id'] = $unit->id; $rent_due_dat = $unit->rent_due_date; $date = \Carbon\Carbon::parse($rent_due_dat); $current_date = now(); $renting['month'] = $current_date->format('m'); $renting['year'] = $date->format('Y'); $renting['amount_due'] = $unit->monthly_rent; $renting['amount_paid'] = 0; $renting['status'] = 'unpaid'; $renting['payment_type'] = 'monthly_rent'; $renting['created_at'] = now(); RentPayment::create($renting); $renting_somni_fee['user_id'] = $user->id; $renting_somni_fee['unit_id'] = $unit->id; $rent_due_dat = $unit->rent_due_date; $date = \Carbon\Carbon::parse($rent_due_dat); $current_date = now(); $renting_somni_fee['month'] = $current_date->format('m'); $renting_somni_fee['year'] = $date->format('Y'); $renting_somni_fee['amount_due'] = config('constants.payment.tenant_anual_fee'); $renting_somni_fee['amount_paid'] = 0; $renting_somni_fee['status'] = 'unpaid'; $renting_somni_fee['payment_type'] = 'annual_somni_fee'; $renting_somni_fee['created_at'] = now(); RentPayment::create($renting_somni_fee); $renting_security_deposit['user_id'] = $user->id; $renting_security_deposit['unit_id'] = $unit->id; $rent_due_dat = $unit->rent_due_date; $date = \Carbon\Carbon::parse($rent_due_dat); $current_date = now(); $renting_security_deposit['month'] = $current_date->format('m'); $renting_security_deposit['year'] = $date->format('Y'); $renting_security_deposit['amount_due'] = $unit->security_deposit ?? 0; $renting_security_deposit['amount_paid'] = 0; $renting_security_deposit['status'] = 'unpaid'; $renting_security_deposit['payment_type'] = 'security_deposit'; $renting_security_deposit['created_at'] = now(); RentPayment::create($renting_security_deposit); } $walletRepo = new WalletRepository; $wallet['user_id'] = $user->id; $wallet['balance'] = 0; $wallet['created_at'] = now(); $wallet_created = $walletRepo->createWallet($wallet); DB::commit(); return $user; }); } public function getPropertyById($property_id){ return Property::whereId($property_id)->first(); } public function acceptInvitation($invitationCode, $email,$user_id){ $invitation = InvitationPropertyUnit::where('invitation_code', $invitationCode) ->where('email', $email) ->first(); if ($invitation) { $check_for_accepted = InvitationPropertyUnit::where('unit_id', $invitation->unit_id) ->get(); if($check_for_accepted->count() > 1){ foreach($check_for_accepted as $invite){ if($invite->is_accepted == 1){ return false; } } } DB::beginTransaction(); $unit = Unit::find($invitation->unit_id); $propertyUnitTenant = new PropertyUnitTenant([ 'property_id' => $unit->property->id, 'unit_id' => $unit->id, 'tenant_user_id' => $user_id, 'from_date' => now(), ]); $renting['user_id'] = $user_id; $renting['unit_id'] = $unit->id; $rent_due_dat = $unit->rent_due_date; $date = \Carbon\Carbon::parse($rent_due_dat); $current_date = now(); $renting['month'] = $current_date->format('m'); $renting['year'] = $date->format('Y'); $renting['amount_due'] = $unit->monthly_rent; $renting['amount_paid'] = 0; $renting['status'] = 'unpaid'; $renting['payment_type'] = 'monthly_rent'; $renting['created_at'] = now(); RentPayment::create($renting); $renting_somni_fee['user_id'] = $user_id; $renting_somni_fee['unit_id'] = $unit->id; $rent_due_dat = $unit->rent_due_date; $date = \Carbon\Carbon::parse($rent_due_dat); $current_date = now(); $renting_somni_fee['month'] = $current_date->format('m'); $renting_somni_fee['year'] = $date->format('Y'); $renting_somni_fee['amount_due'] = config('constants.payment.tenant_anual_fee'); $renting_somni_fee['amount_paid'] = 0; $renting_somni_fee['status'] = 'unpaid'; $renting_somni_fee['payment_type'] = 'annual_somni_fee'; $renting_somni_fee['created_at'] = now(); RentPayment::create($renting_somni_fee); $renting_security_deposit['user_id'] = $user_id; $renting_security_deposit['unit_id'] = $unit->id; $rent_due_dat = $unit->rent_due_date; $date = \Carbon\Carbon::parse($rent_due_dat); $current_date = now(); $renting_security_deposit['month'] = $current_date->format('m'); $renting_security_deposit['year'] = $date->format('Y'); $renting_security_deposit['amount_due'] = $unit->security_deposit ?? 0; $renting_security_deposit['amount_paid'] = 0; $renting_security_deposit['status'] = 'unpaid'; $renting_security_deposit['payment_type'] = 'security_deposit'; $renting_security_deposit['created_at'] = now(); RentPayment::create($renting_security_deposit); $propertyUnitTenant->save(); $invitation->is_accepted = true; $invitation->save(); $notiObj = new NotificationRepository; $landlord = $unit->property->user; $title = "Invitation Accepted"; $message = "The user ".$email." has accepted your invitation under the Unit: ".$unit->number."."; $sent = $notiObj->CreateAndSendNotification($landlord, $title, $message); DB::commit(); return true; }else{ return false; } } public function getUnitById($unit_id){ return $unit = Unit::whereId($unit_id)->first(); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0.01 |
proxy
|
phpinfo
|
Настройка