| Server IP : 77.68.25.176 / Your IP : 216.73.216.25 Web Server : Apache System : Linux plesk 4.15.0-159-generic #167-Ubuntu SMP Tue Sep 21 08:55:05 UTC 2021 x86_64 User : dwp ( 10001) PHP Version : 7.4.33 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/dazzlingwebplanet.co.uk/rightway-admin.dazzlingwebplanet.co.uk/app/ |
Upload File : |
<?php
namespace App;
use App\Http\Controllers\Driverapplication\DriverApplicationControllers;
use App\Model\UserCode;
use Exception;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Session;
use TCG\Voyager\Models\Role;
class User extends \TCG\Voyager\Models\User
{
use Notifiable, SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
'avatar',
'last_activity',
'role_id',
'phone_code',
'phone_num',
'cred_sent',
'deleted_at',
'created_by',
'created_by_ip',
'deleted_by',
'deleted_by_ip',
'last_updated_by',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
'last_login' => 'datetime',
'last_activity' => 'datetime',
];
public function get_company_list()
{
$statuses = session('include_in_active_companies') == 1
? ['Active', 'Inactive'] : ['Active'];
if (Auth::check()) {
$snUserId = Auth::user()->id;
$check_cmp_list = DB::table('company_user')
->where('user_id', $snUserId)
->get()->toArray();
if (empty($check_cmp_list)) {
$saCmpList = DB::table('companies')
->select('company_name', 'companies.id')
->whereIn('company_status', $statuses)
->orderBy('company_name', 'asc')->get()->toArray();
} else {
$saCmpList = DB::table('company_user')
->select('companies.company_name', 'companies.id')
->where('user_id', $snUserId)
->whereIn('company_status', $statuses)
->join('companies', 'company_user.company_id', '=', 'companies.id')
->orderBy('company_name', 'asc')->get()->toArray();
}
return $saCmpList;
} else {
$saCmpList = array();
return $saCmpList;
}
}
public function get_company_list_2()
{
if (Auth::check()) {
$snUserId = Auth::user()->id;
$statuses = session('include_in_active_companies') == 1
? ['Active', 'Delinquent', 'Inactive']
: ['Active', 'Delinquent'];
$check_cmp_list = DB::table('company_user')
->where('user_id', $snUserId)
->get()->toArray();
if (empty($check_cmp_list)) {
$saCmpList = DB::table('companies')
->select('company_name', 'companies.id')
->whereIn('company_status', $statuses)
->orderBy('company_name', 'asc')->get()->toArray();
} else {
$saCmpList = DB::table('company_user')
->select('companies.company_name', 'companies.id')
->join('companies', 'company_user.company_id', '=', 'companies.id')
->where('user_id', $snUserId)
->whereIn('companies.company_status', $statuses)
->orderBy('company_name', 'asc')->get()->toArray();
}
return $saCmpList;
} else {
$saCmpList = array();
return $saCmpList;
}
}
public function get_all_company_list_with_inactive()
{
if (Auth::check()) {
$user_id = Auth::user()->id;
$check_cmp_list = DB::table('company_user')
->where('user_id', $user_id)
->get()->toArray();
if (empty($check_cmp_list)) {
$cmp_list = DB::table('companies')
->select('company_name', 'id', 'company_status')
->orderBy('company_name', 'asc')->get()->toArray();
} else {
$cmp_list = DB::table('company_user')
->select('companies.company_name', 'companies.id', 'company_status')
->where('user_id', $user_id)
->join('companies', 'company_user.company_id', '=', 'companies.id')
->orderBy('company_name', 'asc')->get()->toArray();
}
return $cmp_list;
} else {
$cmp_list = array();
return $cmp_list;
}
}
public function get_company_list_dropdown()
{
if (Auth::check()) {
$user_id = Auth::user()->id;
$includeInactive = session('include_in_active_companies') == 1;
$check_cmp_list = DB::table('company_user')
->where('user_id', $user_id)
->whereNull('deleted_at')
->exists();
if (empty($check_cmp_list)) {
$query = DB::table('companies')
->select('company_name', 'companies.id', 'company_status')
->whereNull('deleted_at');
if (!$includeInactive) {
$query->where('company_status', '!=', 'Inactive');
}
$cmp_list = $query
->orderBy('company_name', 'asc')
->get()
->toArray();
} else {
$query = DB::table('company_user')
->select('companies.company_name', 'companies.id', 'company_status')
->join('companies', 'company_user.company_id', '=', 'companies.id')
->where('user_id', $user_id)
->whereNull('company_user.deleted_at')
->whereNull('companies.deleted_at');
if (!$includeInactive) {
$query->where('companies.company_status', '!=', 'Inactive');
}
$cmp_list = $query
->orderBy('company_name', 'asc')
->get()
->toArray();
}
return $cmp_list;
} else {
$cmp_list = array();
return $cmp_list;
}
}
public function get_companies_list()
{
$company_session = Session::get('cmpSession');
if (Auth::check()) {
$snUserId = Auth::user()->id;
$snUserRole = Auth::user()->role_id;
if ($snUserRole == 3 || $snUserRole == 4) {
$query = DB::table('company_user')
->join('companies', 'company_user.company_id', '=', 'companies.id')
->where('companies.company_status', 'Active')
->where('user_id', $snUserId)
->select('companies.company_name', 'companies.id');
if (!empty($company_session) && $company_session != 'All') {
$query->where('company_user.company_id', $company_session);
}
$saCmpList = $query->orderBy('company_name', 'asc')->get()->toArray();
return $saCmpList;
} else {
$saCmpList = array();
return $saCmpList;
}
} else {
$saCmpList = array();
return $saCmpList;
}
}
public function update_last_login($ssAddress)
{
if (Auth::check()) {
$snUserId = Auth::user()->id;
$getUserDetail = User::where('id', $snUserId)->first();
if (!empty($snUserId)) {
$getUserDetail['last_address'] = $ssAddress;
$getUserDetail->save();
}
}
}
public function get_state()
{
$states = DB::table('states')->where('country_id', 38)->get()->toArray();
return $states;
}
public function get_all_us_can_state()
{
$states = DB::table('states')->whereIn('country_id', ['38', '231'])
->orderBy('name', 'asc')->get()->toArray();
foreach ($states as $key => $value) {
$options[$value->id] = $value->name;
}
return $options;
}
public function get_state_on_country($country_id)
{
$get_states = DB::table('states')->where('country_id', $country_id)->get()->toArray();
if (!empty($get_states)) {
return $get_states;
} else {
return array();
}
}
public function get_city_on_state($state_id)
{
$get_city = DB::table('cities')->where('state_id', $state_id)->get()->toArray();
return $get_city;
}
public function get_country_on_state($state_id)
{
if (!empty($state_id)) {
$get_state = DB::table('states')->select('country_id')->where('id', $state_id)->first();
} else {
$get_state = null;
}
return $get_state;
}
public function get_country_name_on_id($country_id)
{
$get = DB::table('countries')->where('id', $country_id)->first();
if (!empty($get->name)) {
return $get->name;
} else {
if (!empty($country_id)) {
return $country_id;
}
return 'Not Found';
}
}
public function get_state_name_on_id($state_id)
{
$get = DB::table('states')->where('id', $state_id)->first();
if (!empty($get->name)) {
return $get->name;
} else {
if (!empty($state_id)) {
return $state_id;
}
return 'Not Found';
}
}
public function get_city_name_on_id($snCityId)
{
$get = DB::table('cities')->where('id', $snCityId)->first();
if (!empty($get->name)) {
return $get->name;
} else {
if (!empty($snCityId)) {
return $snCityId;
}
return 'Not Found';
}
}
public function get_all_country_option()
{
$get_country = DB::table('countries')->select('id', 'name')->whereNotIn('id', ['53'])->get()->toArray();
$data = array();
$data[''] = 'Country';
foreach ($get_country as $key => $value) {
$data[$value->id] = $value->name;
}
return $data;
}
/**
* Write code on Method
*
* @return response()
*/
public function generateCode($otp_send_on)
{
//Generate 5 Digits OTP
$digits = 5;
$code = str_pad(rand(0, pow(10, $digits) - 1), $digits, '0', STR_PAD_LEFT);
//Send Mail with OTP
$mail_data['email'] = auth()->user()->email;
$mail_data['name'] = auth()->user()->name;
$mail_data['otp'] = $code;
$new_code = new UserCode();
$new_code->user_id = auth()->user()->id;
$new_code->code = $code;
$new_code->save();
try {
if ($otp_send_on == 'phone' && !empty(auth()->user()->phone_num)) {
$sendSms = new DriverApplicationControllers;
$mobile_number = auth()->user()->phone_code . auth()->user()->phone_num;
$sendSms->sendSmsTwilio($mobile_number, 'Your OTP is: ' . $code);
} else {
Mail::send('mail.otp', $mail_data, function ($saMessage) use ($mail_data) {
$saMessage->to($mail_data['email'], $mail_data['name']);
$saMessage->subject('VDM OTP');
});
}
} catch (Exception $e) {
info("Error: " . $e->getMessage());
}
}
public function role()
{
return $this->belongsTo(Role::class, 'role_id');
}
}