Файловый менеджер - Редактировать - /home/clickysoft/public_html/somni.clickysoft.net/app/Http/Controllers/TenantController.php
Назад
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Repositories\TenantRepository; use App\Repositories\NotificationRepository; use App\Repositories\UserRepository; use App\Repositories\PaymentRepository; use App\Repositories\WalletRepository; use App\Repositories\TransactionRepository; use App\Repositories\EventRepository; use App\Repositories\PropertyRepository; use App\Repositories\AdRepository; use App\Interfaces\TenantRepositoryInterface; use App\Interfaces\NotificationRepositoryInterface; use App\Interfaces\UserRepositoryInterface; use App\Interfaces\PaymentRepositoryInterface; use App\Interfaces\WalletRepositoryInterface; use App\Interfaces\TransactionRepositoryInterface; use App\Interfaces\EventRepositoryInterface; use App\Interfaces\PropertyRepositoryInterface; use App\Interfaces\AdRepositoryInterface; use App\Models\Category; use Carbon\Carbon; use App\Models\Lease; use Datatables; class TenantController extends Controller { private TenantRepositoryInterface $tenantInterfaceObj; //Tenant Interface Object private NotificationRepositoryInterface $notificationInterfaceObj; private UserRepositoryInterface $userInterfaceObj; private PaymentRepositoryInterface $paymentInterfaceObj; private WalletRepositoryInterface $walletInterfaceObj; private TransactionRepositoryInterface $transactionInterfaceObj; private EventRepositoryInterface $eventInterfaceObj; private PropertyRepositoryInterface $propertyInterfaceObj; private AdRepositoryInterface $adInterfaceObj; private $secret; public function __construct(AdRepository $adRepo,TenantRepository $tenantRepo, NotificationRepository $notificationRepo, UserRepository $userRepo,PaymentRepository $paymentRepo,WalletRepository $walletRepo,TransactionRepository $transactionRepo,EventRepository $eventRepo,PropertyRepository $propertyRepo) { $this->tenantInterfaceObj = $tenantRepo; $this->notificationInterfaceObj = $notificationRepo; $this->userInterfaceObj = $userRepo; $this->paymentInterfaceObj = $paymentRepo; $this->walletInterfaceObj = $walletRepo; $this->transactionInterfaceObj = $transactionRepo; $this->eventInterfaceObj = $eventRepo; $this->propertyInterfaceObj = $propertyRepo; $this->adInterfaceObj = $adRepo; $this->secret = config('constants.stripe.secret_key'); \Stripe\Stripe::setApiKey($this->secret); } public function index() { $flag = false; $rents = []; $rented_unit = []; $transactions = ''; $user = $this->tenantInterfaceObj->getTenantById(auth()->user()->id); $verify = $this->userInterfaceObj->checkVerification($user); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $ads = $this->adInterfaceObj->getLatestBoxAdsTenant(); if(!$user->tenantUnits->isEmpty()){ $rented_unit = $user->tenantUnits[0]; } $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); if (empty($user->tenantUnits[0])) { $flag = true; } if(!empty($rented_unit)){ $rents = $this->paymentInterfaceObj->getCurrentMonthCalculatedRentByDays($rented_unit->id ,$user->id,null); $transactions = $this->transactionInterfaceObj->getTransactionListByUnitTenant($rented_unit,$user); } ($transactions == null) ? $transactions = [] : $transactions = $transactions; // dd($rents); if($verify['flag']){ return view('tenant.dashboard', compact('ads','user', 'flag', 'nCount', 'notifications','rents','transactions'))->with('verification','Please verify your account. It will be deactivated in '.$verify['days'].' days. <a href="javascript:void(0)" onclick="sendEmailVerification()">Send Verification Email</a>');; } return view('tenant.dashboard', compact('ads','user', 'flag', 'nCount', 'notifications','rents','transactions')); } public function messageIndex() { $user = $this->tenantInterfaceObj->getTenantById(auth()->user()->id); $verify = $this->userInterfaceObj->checkVerification($user); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); if($verify['flag']){ return view('tenant.message', compact('user', 'nCount', 'notifications'))->with('verification','Please verify your account. It will be deactivated in '.$verify['days'].' days. <a href="javascript:void(0)" onclick="sendEmailVerification()">Send Verification Email</a>'); } return view('tenant.message', compact('user', 'nCount', 'notifications')); } public function walletIndex() { $property = ''; $user = $this->tenantInterfaceObj->getTenantById(auth()->user()->id); $verify = $this->userInterfaceObj->checkVerification($user); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); $rented_unit = $user->tenantUnits[0]; $wallet = $this->walletInterfaceObj->getWalletByUserId($user->id); $ad = $this->adInterfaceObj->getSingleAddLatestTenant(); if (!empty($rented_unit)) { $property = $this->tenantInterfaceObj->getPropertyById($rented_unit->property_id); } $transactions = $this->transactionInterfaceObj->getTransactionListByUnitTenant($rented_unit,$user); if($verify['flag']){ return view('tenant.wallet', compact('ad','user', 'property', 'nCount', 'notifications','rented_unit','wallet','transactions'))->with('verification','Please verify your account. It will be deactivated in '.$verify['days'].' days. <a href="javascript:void(0)" onclick="sendEmailVerification()">Send Verification Email</a>'); } return view('tenant.wallet', compact('ad','user', 'property', 'nCount', 'notifications','rented_unit','wallet','transactions')); } public function paymentIndex() { $rents = []; $rented_unit = []; // $user->deletePaymentMethods(); try { $user = $this->tenantInterfaceObj->getTenantById(auth()->user()->id); $verify = $this->userInterfaceObj->checkVerification($user); $intent = $user->createSetupIntent(); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); if(!$user->tenantUnits->isEmpty()){ $rented_unit = $user->tenantUnits[0]; } if(!empty($rented_unit)){ $rents = $this->paymentInterfaceObj->getCurrentMonthCalculatedRentByDays($rented_unit->id ,$user->id,null); } $transactions = $this->transactionInterfaceObj->getTransactionListByUnitTenant($rented_unit,$user); // Fetch the user's saved cards from Stripe $paymentMethods = $user->paymentMethods(); $bank_intent = $this->createSetupIntentBank(); // $stripeCustomerId = $user->stripe_id; if($verify['flag']){ return view('tenant.make-payment', compact('bank_intent','user','nCount','notifications','intent','paymentMethods','rents','rented_unit','transactions'))->with('verification','Please verify your account. It will be deactivated in '.$verify['days'].' days. <a href="javascript:void(0)" onclick="sendEmailVerification()">Send Verification Email</a>'); } return view('tenant.make-payment', compact('bank_intent','user','nCount','notifications','intent','paymentMethods','rents','rented_unit','transactions')); } catch (\Throwable $th) { return back()->with('error',$th->getMessage()); } } public function cardIndex(){ $user = $this->tenantInterfaceObj->getTenantById(auth()->user()->id); $intent = $user->createSetupIntent(); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); try { //code... $paymentMethods = $user->paymentMethods(); return view('tenant.add_card', compact('user', 'nCount', 'notifications', 'intent', 'paymentMethods'))->with('success','Card Added'); } catch (\Throwable $th) { //throw $th; return view('tenant.add_card', compact('user', 'nCount', 'notifications', 'intent', 'paymentMethods'))->with('error',$th->getMessage()); } // Fetch the user's saved cards from Stripe } public function maintenanceIndex() { $maintenances = null; $event_in_progress = null; $user = $this->tenantInterfaceObj->getTenantById(auth()->user()->id); $verify = $this->userInterfaceObj->checkVerification($user); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); $all_notifications = $this->notificationInterfaceObj->recentNotificationsAll($user->id); $ad = $this->adInterfaceObj->getSingleAddLatestTenant(); if(!empty($user->tenantUnits) && count($user->tenantUnits) > 0){ $maintenances = $this->eventInterfaceObj->getEventsByUnitIdAndTenantID($user->id,$user->tenantUnits[0]->id); $event_in_progress = $this->eventInterfaceObj->getLatestMaintenanceActivityByUnitId($user->tenantUnits[0]->id); }else{ $maintenances = $this->eventInterfaceObj->getEventsByTenantId($user->id); } if($verify['flag']){ return view('tenant.maintenance', compact('ad','user', 'nCount', 'notifications','maintenances','event_in_progress','all_notifications'))->with('verification','Please verify your account. It will be deactivated in '.$verify['days'].' days. <a href="javascript:void(0)" onclick="sendEmailVerification()">Send Verification Email</a>'); } return view('tenant.maintenance', compact('ad','user', 'nCount', 'notifications','maintenances','event_in_progress','all_notifications')); } public function calendarIndex() { $user = $this->tenantInterfaceObj->getTenantById(auth()->user()->id); $property_array = $user->propertyUnitTenant; $property = $property_array[0]->property; $unit = $property_array[0]->unit; $verify = $this->userInterfaceObj->checkVerification($user); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); if($verify['flag']){ return view('tenant.calendar', compact('property','unit','user', 'nCount', 'notifications'))->with('verification','Please verify your account. It will be deactivated in '.$verify['days'].' days. <a href="javascript:void(0)" onclick="sendEmailVerification()">Send Verification Email</a>'); } return view('tenant.calendar', compact('property','unit','user', 'nCount', 'notifications')); } public function settingIndex() { $user = $this->tenantInterfaceObj->getTenantById(auth()->user()->id); $verify = $this->userInterfaceObj->checkVerification($user); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); if($verify['flag']){ return view('tenant.settings', compact('user', 'nCount', 'notifications'))->with('verification','Please verify your account. It will be deactivated in '.$verify['days'].' days. <a href="javascript:void(0)" onclick="sendEmailVerification()">Send Verification Email</a>'); } return view('tenant.settings', compact('user', 'nCount', 'notifications')); } public function paymentdetailIndex(Request $request){ $method = ''; $amount = ''; $rents = []; $card_id = ''; $date_to_show = ''; $bank_intent = ''; $user = auth()->user(); try { $user->createOrGetStripeCustomer(); } catch (\Throwable $th) { return back()->with('error',$th->getMessage()); } $payment_through = $request->payment_through; if($payment_through != 'bank'){ if ($user->hasPaymentMethod()) { $paymentMethods = $user->paymentMethods(); // dd($paymentMethods); $method = $paymentMethods[0]; } else { $method = $user->addPaymentMethod($request->paymentMethodId); } } $rented_unit = $user->tenantUnits[0]; if(!empty($rented_unit)){ $rents = $this->paymentInterfaceObj->getCurrentMonthCalculatedRentByDays($rented_unit->id ,$user->id,$payment_through); } $type = $request->payment_type; switch ($type) { case 'full_balance': $amount = $rents['totalRent'] ?? 0; break; case 'current_balance': $amount = $rents['currentMonthRent'] ?? 0; break; case 'other_balance': $amount = $request->payment_amount; break; } if($type == 'other_balance'){ $breakdown = []; }else{ $breakdown = $this->paymentInterfaceObj->getBreakdownOfPayment($rented_unit->id ,$user->id,$type,$payment_through); } $today_date = now()->format('F j, Y'); $date = \Carbon\Carbon::parse($rented_unit->rent_due_date); $month = $date->format('M'); $day = $date->format('d'); $year = now()->format('Y'); $date_to_show = $month.' '.$day.', '.$year; if($payment_through != 'bank'){ if($request->save_card == null){ $card_id = $method->id; }else{ $card_id = $request->save_card; } }else{ $bank_intent = $request->paymentMethodId; } // dd($card_id); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); $paymentMethods = $user->paymentMethods(); $intent = $user->createSetupIntent(); // dd($amount); return view('tenant.make-payment-detail', compact('user','breakdown', 'nCount', 'notifications','method','intent','rented_unit','date_to_show','today_date','amount','type','card_id','payment_through','bank_intent')); } public function paymentthankyouIndex() { $user = $this->tenantInterfaceObj->getTenantById(auth()->user()->id); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); $paymentMethods = $user->paymentMethods(); $intent = $user->createSetupIntent(); $amount = 200.98; return view('tenant.payment-thankyou', compact('user', 'nCount', 'notifications','paymentMethods','intent','amount')); } public function notificationShow() { $user = $this->landlordInterfaceObj->getLandlordById(auth()->user()->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); if ($verify['flag']) { return view('tenant.notifications', compact('user', 'notifications'))->with('verification', 'Please verify your account. It will be deactivated in ' . $verify['days'] . ' days. <a href="javascript:void(0)" onclick="sendEmailVerification()">Send Verification Email</a>'); } return view('tenant.notifications', compact('user', 'notifications')); } public function transactionShow(){ $rented_unit = null; $user = $this->tenantInterfaceObj->getTenantById(auth()->user()->id); $verify = $this->userInterfaceObj->checkVerification($user); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); if($verify['flag']){ return view('tenant.transaction_all',compact('user','nCount','notifications'))->with('verification','Please verify your account. It will be deactivated in '.$verify['days'].' days. <a href="javascript:void(0)" onclick="sendEmailVerification()">Send Verification Email</a>'); } return view('tenant.transaction_all',compact('user','nCount','notifications')); } public function transactionAjax(Request $request){ if($request->ajax()){ $user = auth()->user(); if(!$user->tenantUnits->isEmpty()){ $rented_unit = $user->tenantUnits[0]; } $transactions = $this->transactionInterfaceObj->getTransactionListByUnitTenantNoPagination($rented_unit,$user); return Datatables::of($transactions) ->addIndexColumn() ->addColumn('action',function($row){ $actionBtn = '<button type="button" class="download-cta dashed-cta generate_pdf_btn" data-transaction_id="'.$row->id.'">Download</button>'; return $actionBtn; }) ->addColumn('date',function($row){ $first = $row->created_at->format('M. d, Y'); $second = $row->created_at->format(' h:i A'); $date = ' <strong>'.$first.'</strong> '.$second.''; return $date; }) ->addColumn('unit_no',function($row){ $unitNumber = $row->transactionDetails[0]->unit->number ?? 'N/A'; return $unitNumber; }) ->addColumn('payee_name',function($row){ $payeeName = $row->payee->name ?? 'N/A'; return $payeeName; }) ->addColumn('invoice_number',function($row){ $invoiceNumber = 'Invoice-'; $invoiceNumber .= $row->id ?? 'N/A'; return $invoiceNumber; }) ->addColumn('amount',function($row){ $amount = number_format((double) str_replace(',', '', $row->amount), 2); return $amount; }) ->addColumn('status',function($row){ if($row->status == 'paid'){ $status = '<span class="status-completed part-paid">'.$row->status.'</span>'; }else{ $status = '<span class="status-completed">'.$row->status.'</span>'; } return $status; }) ->rawColumns(['action','unit_no','date','payee_name','invoice_number','status','amount']) ->make(true); } } public function maintenanceShow(){ $rented_unit = null; $user = $this->tenantInterfaceObj->getTenantById(auth()->user()->id); $verify = $this->userInterfaceObj->checkVerification($user); $nCount = $this->notificationInterfaceObj->unreadCount($user->id); $notifications = $this->notificationInterfaceObj->recentNotifications($user->id); if($verify['flag']){ return view('tenant.maintenance_all',compact('user','nCount','notifications'))->with('verification','Please verify your account. It will be deactivated in '.$verify['days'].' days. <a href="javascript:void(0)" onclick="sendEmailVerification()">Send Verification Email</a>'); } return view('tenant.maintenance_all',compact('user','nCount','notifications')); } public function maintenanceAjax(Request $request){ if($request->ajax()){ $user = auth()->user(); $maintenances = null; if(!empty($user->tenantUnits) && count($user->tenantUnits) > 0){ $maintenances = $this->eventInterfaceObj->getEventsByUnitIdAndTenantID($user->id,$user->tenantUnits[0]->id); }else{ $maintenances = $this->eventInterfaceObj->getEventsByTenantId($user->id); } return Datatables::of($maintenances) ->addIndexColumn() ->addColumn('date',function($row){ $first = $row->created_at->format('M. d, Y'); $second = $row->created_at->format(' h:i A'); $date = ' <strong>'.$first.'</strong> '.$second.''; return $date; }) ->addColumn('status',function($row){ $class = ($row->status == 'in-progress') ? "progress-cta" : "status-completed"; $status = '<span class="'.$class.'">'.$row->status.'</span>'; return $status; }) ->addColumn('unit_name',function($row){ return $row->unit->number ?? 'N/A'; }) ->addColumn('category',function($row){ return $row->category->name ?? 'N/A'; }) ->rawColumns(['unit_name','category','date','status']) ->make(true); } } public function createSetupIntentBank(){ // retruve customer stripe id from database first $customer = auth()->user(); $intent = \Stripe\SetupIntent::create([ 'payment_method_types' => ['us_bank_account'], 'customer' => $customer->stripe_id, ]); // save setup intent id in database as well for recurring future //payments // $customer->update([ // 'setup_intent_id' => $intent->id // ]); return $intent->client_secret; } public function testFunction(){ // $tenants_with_units = $this->userInterfaceObj->getAssignedTenants(); // foreach($tenants_with_units as $tenant){ // $payment_record = $this->paymentInterfaceObj->getLastRentPaymentRecord($tenant->unit->id,$tenant->tenant->id); // if($payment_record == null){ // Which means there is no records and there should be one in rent_payment table // //store in table // $renting['user_id'] = $tenant->tenant->id; // $renting['unit_id'] = $tenant->unit->id; // $rent_due_dat = $tenant->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'] = 'active'; // $renting['created_at'] = now(); // RentPayment::create($renting); // } // } } public function getSingleEvent($id){ try { $user = auth()->user(); $dd_units = []; $event = $this->eventInterfaceObj->getEventByEventId($id); // $properties = $this->propertyInterfaceObj->getUsersActiveProperty($user->id); $property = $this->propertyInterfaceObj->getPropertyById($event->event_property->id); if($property){ $dd_units = $this->propertyInterfaceObj->getUnitsByPropertyId($property->id); } $categories = Category::all(); if($event){ // Assuming $event is an instance of your Event model or a stdClass object $eventDate = Carbon::parse($event->date); $today = Carbon::now(); if ($eventDate->lte($today)) { // Event date is before or equal to today return response()->json( [ 'code' => 400, 'message' => 'Event Uneditable', 'event' => $event, 'properties' => [$property], 'units' => $dd_units, 'categories' => $categories ], 200 ); } return response()->json( [ 'code' => 200, 'message' => 'Event Found', 'event' => $event, 'properties' => $property, 'units' => $dd_units, 'categories' => $categories ], 200 ); }else{ return response()->json( [ 'code' => 404, 'message' => 'Event Not Found' ], 404 ); } } catch (\Throwable $th) { return response()->json( [ 'code' => 500, 'message' => $th->getMessage() ], 500 ); } } public function lesesIndex(){ $user = auth()->user(); return view('tenant.lease',compact('user')); } public function ajaxLease(Request $request){ if($request->ajax()){ $leases = Lease::where('tenant_id', auth()->user()->id)->with(['unit','template'])->get(); return Datatables::of($leases) ->addIndexColumn() ->addColumn('view',function($row){ $flag = $row->status; if($flag == 0){ $actionBtn = '<a href="/storage/'.$row->template->document_path.'" target="_blank">View</a>'; }else{ $actionBtn = '<a href="/storage/'.$row->document_path.'" target="_blank">View</a>'; } return $actionBtn; }) ->addColumn('unit',function($row){ return $row->unit->number; }) ->addColumn('lease_start',function($row){ return Carbon::parse($row->created_at)->format('m/d/Y');; }) ->addColumn('lease_end',function($row){ if($row->status == 0){ return '-'; }else{ // Get the original created_at timestamp $createdAt = $row->created_at; // Add a year to the timestamp $createdAtWithOneYearAdded = Carbon::parse($createdAt)->addYear(); // Format the timestamp with the added year $formattedDateWithOneYearAdded = $createdAtWithOneYearAdded->format('m/d/Y'); return $formattedDateWithOneYearAdded; } }) ->addColumn('documents', function($row){ if($row->status == 0){ return 'Sent To Sign'; }else{ return 'Signed Lease'; } }) ->rawColumns(['lease_end','lease_start','unit','view','documents']) ->make(true); } } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка