commit 501a8e18e0fc22dae6b86d5ed3ac88a8f66154cc Author: kris@sentientgeeks.com Date: Mon Feb 8 19:09:14 2021 +0530 initial commit diff --git a/app/BaseModel.php b/app/BaseModel.php new file mode 100644 index 0000000..a15d730 --- /dev/null +++ b/app/BaseModel.php @@ -0,0 +1,103 @@ + 'fa-file-text', + 'htm' => 'fa-file-code-o', + 'html' => 'fa-file-code-o', + // 'php' => 'fa-file-code-o', + 'css' => 'fa-file-code-o', + 'js' => 'fa-file-code-o', + 'json' => 'fa-file-code-o', + 'xml' => 'fa-file-code-o', + 'swf' => 'fa-file-o', + 'CR2' => 'fa-file-o', + 'flv' => 'fa-file-video-o', + + // images + 'png' => 'fa-file-image-o', + 'jpe' => 'fa-file-image-o', + 'jpeg' => 'fa-file-image-o', + 'jpg' => 'fa-file-image-o', + 'gif' => 'fa-file-image-o', + 'bmp' => 'fa-file-image-o', + 'ico' => 'fa-file-image-o', + 'tiff' => 'fa-file-image-o', + 'tif' => 'fa-file-image-o', + 'svg' => 'fa-file-image-o', + 'svgz' => 'fa-file-image-o', + + // archives + 'zip' => 'fa-file-o', + 'rar' => 'fa-file-o', + 'exe' => 'fa-file-o', + 'msi' => 'fa-file-o', + 'cab' => 'fa-file-o', + + // audio/video + 'mp3' => 'fa-file-audio-o', + 'qt' => 'fa-file-video-o', + 'mov' => 'fa-file-video-o', + 'mp4' => 'fa-file-video-o', + 'mkv' => 'fa-file-video-o', + 'avi' => 'fa-file-video-o', + 'wmv' => 'fa-file-video-o', + 'mpg' => 'fa-file-video-o', + 'mp2' => 'fa-file-video-o', + 'mpeg' => 'fa-file-video-o', + 'mpe' => 'fa-file-video-o', + 'mpv' => 'fa-file-video-o', + '3gp' => 'fa-file-video-o', + 'm4v' => 'fa-file-video-o', + + // adobe + 'pdf' => 'fa-file-pdf-o', + 'psd' => 'fa-file-image-o', + 'ai' => 'fa-file-o', + 'eps' => 'fa-file-o', + 'ps' => 'fa-file-o', + + // ms office + 'doc' => 'fa-file-text', + 'rtf' => 'fa-file-text', + 'xls' => 'fa-file-excel-o', + 'ppt' => 'fa-file-powerpoint-o', + 'docx' => 'fa-file-text', + 'xlsx' => 'fa-file-excel-o', + 'pptx' => 'fa-file-powerpoint-o', + + + // open office + 'odt' => 'fa-file-text', + 'ods' => 'fa-file-text', + ]; + + public function getIconAttribute($value) { + + $isColExist = Schema::hasColumn($this->getTable(),'icon'); + + if($isColExist){ + return $value; + } + if (is_null($this->external_link) && !$isColExist) { + $ext = pathinfo($this->filename, PATHINFO_EXTENSION); + if ($ext == 'png' || $ext == 'jpe' || $ext == 'jpeg' || $ext == 'jpg' || $ext == 'gif' || $ext == 'bmp' || + $ext == 'ico' || $ext == 'tif' || $ext == 'svg' || $ext == 'svgz' || $ext == 'psd' || $ext == 'csv') + { + return 'images'; + } + else{ + return $this->mimeType[$ext]; + } + } + } + +} diff --git a/app/Company.php b/app/Company.php new file mode 100644 index 0000000..79995a1 --- /dev/null +++ b/app/Company.php @@ -0,0 +1,212 @@ +getStripeKey() + // ); + + // $stripeInvoice->lines = StripeInvoice::retrieve($id, $this->getStripeKey()) + // ->lines + // ->all(['limit' => 1000]); + + // $stripeInvoice->date = $stripeInvoice->created; + // return new Invoice($this, $stripeInvoice); + + // } catch (\Exception $e) { + // // + // } + + + // } + + public static function boot() + { + parent::boot(); + static::observe(CompanyObserver::class); + } + + public function currency() + { + return $this->belongsTo(Currency::class, 'currency_id')->withoutGlobalScopes(['enable']); + } + + public function package() + { + return $this->belongsTo(Package::class, 'package_id'); + } + + public function employees() + { + return $this->hasMany(User::class) + ->join('employee_details', 'employee_details.user_id', 'users.id'); + } + + public function file_storage() + { + return $this->hasMany(FileStorage::class, 'company_id'); + } + + public function getLogoUrlAttribute() + { + if (is_null($this->logo)) { + $global = global_settings(); + return $global->logo_url; + } + return asset_url('app-logo/' . $this->logo); + } + + public function getLoginBackgroundUrlAttribute() + { + if (is_null($this->login_background) || $this->login_background == 'login-background.jpg') { + return asset('img/login-bg.jpg'); + } + + return asset_url('login-background/' . $this->login_background); + } + + public function validateGoogleRecaptcha($googleRecaptchaResponse) + { + $global = global_settings(); + $client = new Client(); + $response = $client->post( + 'https://www.google.com/recaptcha/api/siteverify', + ['form_params' => + [ + 'secret' => $global->google_recaptcha_secret, + 'response' => $googleRecaptchaResponse, + 'remoteip' => $_SERVER['REMOTE_ADDR'] + ]] + ); + + $body = json_decode((string) $response->getBody()); + + return $body->success; + } + + public function getMomentDateFormatAttribute() + { + $momentDateFormats = [ + 'd-m-Y' => 'DD-MM-YYYY', + 'm-d-Y' => 'MM-DD-YYYY', + 'Y-m-d' => 'YYYY-MM-DD', + 'd.m.Y' => 'DD.MM.YYYY', + 'm.d.Y' => 'MM.DD.YYYY', + 'Y.m.d' => 'YYYY.MM.DD', + 'd/m/Y' => 'DD/MM/YYYY', + 'm/d/Y' => 'MM/DD/YYYY', + 'Y/m/d' => 'YYYY/MM/DD', + 'd/M/Y' => 'DD/MMM/YYYY', + 'd.M.Y' => 'DD.MMM.YYYY', + 'd-M-Y' => 'DD-MMM-YYYY', + 'd M Y' => 'DD MMM YYYY', + 'd F, Y' => 'DD MMMM, YYYY', + 'D/M/Y' => 'ddd/MMM/YYYY', + 'D.M.Y' => 'ddd.MMM.YYYY', + 'D-M-Y' => 'ddd-MMM-YYYY', + 'D M Y' => 'ddd MMM YYYY', + 'd D M Y' => 'DD ddd MMM YYYY', + 'D d M Y' => 'ddd DD MMM YYYY', + 'dS M Y' => 'Do MMM YYYY', + ]; + return $momentDateFormats[$this->date_format]; + } + + public function addUser($company, $request) + { + // Save Admin + $user = User::withoutGlobalScopes([CompanyScope::class, 'active'])->where('email', $request->email)->first(); + if (is_null($user)) { + $user = new User(); + } + $user->company_id = $company->id; + $user->name = 'admin'; + $user->email = $request->email; + $user->password = bcrypt($request->password); + $user->status = 'active'; + $user->email_verification_code = str_random(40); + $user->save(); + + return $user; + } + public function addEmployeeDetails($user) + { + $employee = new EmployeeDetails(); + $employee->user_id = $user->id; + $employee->employee_id = 'emp-' . $user->id; + $employee->company_id = $user->company_id; + $employee->address = 'address'; + $employee->hourly_rate = '50'; + $employee->save(); + + $global = global_settings(); + + if ($global->email_verification == 1) { + // Send verification mail + $user->notify(new EmailVerification($user)); + $user->status = 'deactive'; + $user->save(); + + $message = __('messages.signUpThankYouVerify'); + } else { + + $user->notify(new NewUser(request()->password)); + $message = __('messages.signUpThankYou') . ' Login Now.'; + } + return $message; + } + public function recaptchaValidate($request) + { + $global = global_settings(); + if ($global->google_recaptcha_status) { + $gRecaptchaResponseInput = 'g-recaptcha-response'; + $gRecaptchaResponse = $request->{$gRecaptchaResponseInput}; + $validateRecaptcha = $this->validateGoogleRecaptcha($gRecaptchaResponse); + if (!$validateRecaptcha) { + return false; + } + } + return true; + } + + public function assignRoles($user) + { + + // Assign roles even before verification + $adminRole = Role::where('name', 'admin')->where('company_id', $user->company_id)->first(); + $user->roles()->attach($adminRole->id); + + $employeeRole = Role::where('name', 'employee')->where('company_id', $user->company_id)->first(); + $user->roles()->attach($employeeRole->id); + + return $user; + } + + public function setSubDomainAttribute($value) + { + // domain is added in the request Class + $this->attributes['sub_domain'] = strtolower($value); + } +} diff --git a/app/CompanySetting.php b/app/CompanySetting.php new file mode 100644 index 0000000..57ebe86 --- /dev/null +++ b/app/CompanySetting.php @@ -0,0 +1,10 @@ +company = $company; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('company-registered'); + } +} diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php new file mode 100644 index 0000000..31da2e6 --- /dev/null +++ b/app/Exceptions/Handler.php @@ -0,0 +1,72 @@ +json( + // [ + // 'message' => __('validation.givenDataInvalid'), + // 'errors' => $exception->validator->getMessageBag() + // ], + // 422 + // ); + // } + // } + if ($exception instanceof TokenMismatchException) { + + return redirect(route('login'))->with('message', 'You page session expired. Please try again'); + } + + return parent::render($request, $exception); + } + + /** + * Convert an authentication exception into an unauthenticated response. + * + * @param \Illuminate\Http\Request $request + * @param \Illuminate\Auth\AuthenticationException $exception + * @return \Illuminate\Http\Response + */ + protected function unauthenticated($request, AuthenticationException $exception) + { + if ($request->expectsJson()) { + return response()->json(['error' => 'Unauthenticated.'], 401); + } + + return redirect()->guest(route('login')); + } +} diff --git a/app/Helper/Files.php b/app/Helper/Files.php new file mode 100644 index 0000000..4a56d0e --- /dev/null +++ b/app/Helper/Files.php @@ -0,0 +1,184 @@ + 'local']); + + /** @var UploadedFile $uploadedFile */ + $uploadedFile = $image; + $folder = $dir . '/'; + + if (!$uploadedFile->isValid()) { + throw new \Exception('File was not uploaded correctly'); + } + + $newName = self::generateNewFileName($uploadedFile->getClientOriginalName()); + + $tempPath = public_path('user-uploads/temp/' . $newName); + + /** Check if folder exits or not. If not then create the folder */ + if (!\File::exists(public_path('user-uploads/' . $folder))) { + \File::makeDirectory(public_path('user-uploads/' . $folder), 0775, true); + } + + $newPath = $folder . '/' . $newName; + + /** @var UploadedFile $uploadedFile */ + $uploadedFile->storeAs('temp', $newName); + + if (!empty($crop)) { + // Crop image + if (isset($crop[0])) { + // To store the multiple images for the copped ones + foreach ($crop as $cropped) { + $image = Image::make($tempPath); + + if (isset($cropped['resize']['width']) && isset($cropped['resize']['height'])) { + + $image->crop(floor($cropped['width']), floor($cropped['height']), floor($cropped['x']), floor($cropped['y'])); + + $fileName = str_replace('.', '_' . $cropped['resize']['width'] . 'x' . $cropped['resize']['height'] . '.', $newName); + $tempPathCropped = public_path('user-uploads/temp') . '/' . $fileName; + $newPathCropped = $folder . '/' . $fileName; + + // Resize in Proper format + $image->resize($cropped['resize']['width'], $cropped['resize']['height'], function ($constraint) { + //$constraint->aspectRatio(); + // $constraint->upsize(); + }); + + $image->save($tempPathCropped); + + \Storage::put($newPathCropped, \File::get($tempPathCropped), ['public']); + + // Deleting cropped temp file + \File::delete($tempPathCropped); + } + + } + } else { + $image = Image::make($tempPath); + $image->crop(floor($crop['width']), floor($crop['height']), floor($crop['x']), floor($crop['y'])); + $image->save(); + } + + } + // Do not compress if the gif is uploaded + if (($width || $height) && \File::extension($uploadedFile->getClientOriginalName()) !=='gif') { + // Crop image + + $image = Image::make($tempPath); + $image->resize($width, $height, function ($constraint) { + $constraint->aspectRatio(); + $constraint->upsize(); + }); + $image->save(); + } + + \Storage::put($newPath, \File::get($tempPath), ['public']); + + // Deleting temp file + \File::delete($tempPath); + + + return $newName; + } + + public static function generateNewFileName($currentFileName) + { + $ext = strtolower(\File::extension($currentFileName)); + $newName = md5(microtime()); + + if ($ext === '') { + return $newName; + } + + return $newName . '.' . $ext; + } + + public static function uploadLocalOrS3($uploadedFile, $dir) + { + if (!$uploadedFile->isValid()) { + throw new \Exception('File was not uploaded correctly'); + } + + if(config('filesystems.default') === 'local'){ + $fileName = self::upload($uploadedFile,$dir,false,false,false); + + self::storeSize($uploadedFile,$dir,$fileName); + + return $fileName; + } + + $newName = self::generateNewFileName($uploadedFile->getClientOriginalName()); + + self::storeSize($uploadedFile,$dir,$newName); + + // We have given 2 options of upload for now s3 and local + #Storage::disk('s3')->putFileAs($dir, $uploadedFile, $newName, 'public'); + Storage::disk('s3')->putFileAs($dir, $uploadedFile, $newName); + return $newName; + } + + private static function storeSize($uploadedFile,$dir,$fileName){ + FileStorage::create( + [ + 'name' => $fileName, + 'path' => $dir, + 'type' => $uploadedFile->getMimeType(), + 'size' => $uploadedFile->getSize(), + ] + ); + } + + public static function deleteFile($image, $folder) + { + $dir = trim($folder, '/'); + $path = $dir . '/' . $image; + + if (!\File::exists(public_path($path))) { + \Storage::delete($path); + } + + try { + session()->forget('company_setting'); + session()->forget('company'); + FileStorage::where('name', $image)->delete(); + } catch (\Exception $e) { + // + } + + return true; + } + + public static function deleteDirectory($folder) + { + $dir = trim($folder); + \Storage::deleteDirectory($dir); + return true; + } + +} diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php new file mode 100644 index 0000000..e6a2f05 --- /dev/null +++ b/app/Http/Controllers/Controller.php @@ -0,0 +1,57 @@ +showInstall(); + + $this->checkMigrateStatus(); + + $this->middleware(function ($request, $next) { + + + + $this->global = global_settings(); + $this->superadmin = global_settings(); + + config(['app.name' => $this->global->company_name]); + config(['app.url' => url('/')]); + + App::setLocale($this->superadmin->locale); + Carbon::setLocale($this->superadmin->locale); + setlocale(LC_TIME, 'en' . '_' . strtoupper('en')); + + $user = auth()->user(); + if ($user && $user->super_admin == 1) { + config(['froiden_envato.allow_users_id' => true]); + } + + return $next($request); + }); + + } + + public function checkMigrateStatus() + { + $status = Artisan::call('migrate:check'); + + if ($status && !request()->ajax()) { + Artisan::call('migrate', array('--force' => true)); //migrate database + Artisan::call('optimize:clear'); + } + } +} diff --git a/app/Http/Controllers/NotificationController.php b/app/Http/Controllers/NotificationController.php new file mode 100644 index 0000000..a3d39a3 --- /dev/null +++ b/app/Http/Controllers/NotificationController.php @@ -0,0 +1,59 @@ +user->unreadNotifications->markAsRead(); + return Reply::success(__('messages.notificationRead')); + } + + public function showAdminNotifications() + { + $view = view('notifications.admin_user_notifications', $this->data)->render(); + return Reply::dataOnly(['status' => 'success', 'html' => $view]); + } + + public function showUserNotifications() + { + $view = view('notifications.user_notifications', $this->data)->render(); + return Reply::dataOnly(['status' => 'success', 'html' => $view]); + } + + public function showClientNotifications() + { + $view = view('notifications.client_notifications', $this->data)->render(); + return Reply::dataOnly(['status' => 'success', 'html' => $view]); + } + + public function showAllMemberNotifications() + { + return view('notifications.member.all_notifications', $this->data); + } + + public function showAllClientNotifications() + { + return view('notifications.client.all_notifications', $this->data); + } + + public function showAllAdminNotifications() + { + return view('notifications.admin.all_notifications', $this->data); + } + + public function showAllSuperAdminNotifications() + { + return view('notifications.superadmin.all_notifications', $this->data); + } +} diff --git a/app/Http/Controllers/SuperAdmin/SuperAdminBaseController.php b/app/Http/Controllers/SuperAdmin/SuperAdminBaseController.php new file mode 100644 index 0000000..9ceb1ef --- /dev/null +++ b/app/Http/Controllers/SuperAdmin/SuperAdminBaseController.php @@ -0,0 +1,82 @@ +data[$name] = $value; + } + + /** + * @param $name + * @return mixed + */ + public function __get($name) + { + return $this->data[$name]; + } + + /** + * @param $name + * @return bool + */ + public function __isset($name) + { + return isset($this->data[ $name ]); + } + + /** + * UserBaseController constructor. + */ + public function __construct() + { + $this->global = global_settings(); + $this->superadmin = $this->global; + + App::setLocale($this->global->locale); + Carbon::setLocale($this->global->locale); + setlocale(LC_TIME, $this->global->locale . '_' . strtoupper($this->global->locale)); + + $this->adminTheme = superadmin_theme(); + $this->languageSettings = LanguageSetting::where('status', 'enabled')->get(); + $this->pushSetting = PushNotificationSetting::first(); + + // Done for the purpose of updating. When updating this code runs before migration + try{ + $this->offlineRequestCount = OfflinePlanChange::where('status', 'pending')->count(); + }catch (\Exception $e){ + $this->offlineRequestCount = 0; + } + + $this->worksuitePlugins = worksuite_plugins(); + + + $this->middleware(function ($request, $next) { + $this->user = user(); + $this->unreadNotificationCount = count($this->user->unreadNotifications); + return $next($request); + }); + } +} diff --git a/app/Http/Controllers/SuperAdmin/SuperAdminCompanyController.php b/app/Http/Controllers/SuperAdmin/SuperAdminCompanyController.php new file mode 100644 index 0000000..616ff75 --- /dev/null +++ b/app/Http/Controllers/SuperAdmin/SuperAdminCompanyController.php @@ -0,0 +1,402 @@ +pageTitle = 'Companies'; + $this->pageIcon = 'icon-layers'; + $this->colClass = '6'; + if (module_enabled('Subdomain')) { + $this->colClass = '4'; + } + } + + /** + * Display a listing of the resource. + * + * @return \Illuminate\Http\Response + */ + public function index() + { + $this->totalCompanies = Company::count(); + $this->packages = Package::all(); + return view('super-admin.companies.index', $this->data); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + $this->timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL); + $this->currencies = GlobalCurrency::all(); + return view('super-admin.companies.create', $this->data); + } + + /** + * Store a newly created resource in storage. + * @param StoreRequest $request + * @return array + */ + public function store(StoreRequest $request) + { + DB::beginTransaction(); + + $company = new Company(); + + $companyDetail = $this->storeAndUpdate($company, $request); + + $globalCurrency = GlobalCurrency::findOrFail($request->currency_id); + $currency = Currency::where('currency_code', $globalCurrency->currency_code) + ->where('company_id', $companyDetail->id)->first(); + + if (is_null($currency)) { + $currency = new Currency(); + $currency->currency_name = $globalCurrency->currency_name; + $currency->currency_symbol = $globalCurrency->currency_symbol; + $currency->currency_code = $globalCurrency->currency_code; + $currency->is_cryptocurrency = $globalCurrency->is_cryptocurrency; + $currency->usd_price = $globalCurrency->usd_price; + $currency->company_id = $companyDetail->id; + $currency->save(); + } + + $company->currency_id = $currency->id; + $company->save(); + + $user = $company->addUser($company, $request); + $company->addEmployeeDetails($user); + + $adminRole = Role::where('name', 'admin')->where('company_id', $companyDetail->id)->withoutGlobalScope('active')->first(); + $user->roles()->attach($adminRole->id); + + $employeeRole = Role::where('name', 'employee')->where('company_id', $user->company_id)->first(); + $user->roles()->attach($employeeRole->id); + + DB::commit(); + return Reply::redirect(route('super-admin.companies.index'), 'Company added successfully.'); + } + + /** + * Display the specified resource. + * + * @param int $id + */ + public function show($id) + { + // + } + + + /** + * @param $companyId + * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response + * @throws \Throwable + */ + public function editPackage($companyId) + { + $packages = Package::all(); + $global = $this->global; + $company = Company::find($companyId); + $currentPackage = Package::find($company->package_id); + $lastInvoice = StripeInvoice::where('company_id', $companyId)->orderBy('created_at', 'desc')->first(); + $packageInfo = []; + foreach ($packages as $package) { + $packageInfo[$package->id] = [ + 'monthly' => $package->monthly_price, + 'annual' => $package->annual_price + ]; + } + + $offlinePaymentMethod = OfflinePaymentMethod::whereNull('company_id')->get(); + $modal = view('super-admin.companies.editPackage', compact('packages', 'company', 'currentPackage', 'lastInvoice', 'packageInfo', 'global', 'offlinePaymentMethod'))->render(); + + return response(['status' => 'success', 'data' => $modal], 200); + } + + public function updatePackage(PackageUpdateRequest $request, $companyId) + { + $company = Company::find($companyId); + + try { + $package = Package::find($request->package); + $company->package_id = $package->id; + $company->package_type = $request->packageType; + $company->status = 'active'; + + $payDate = $request->pay_date ? Carbon::parse($request->pay_date) : Carbon::now(); + + $company->licence_expire_on = ($company->package_type == 'monthly') ? + $payDate->copy()->addMonth()->format('Y-m-d') : + $payDate->copy()->addYear()->format('Y-m-d'); + + $nextPayDate = $request->next_pay_date ? Carbon::parse($request->next_pay_date) : $company->licence_expire_on; + + if ($company->isDirty('package_id') || $company->isDirty('package_type')) { + $offlineInvoice = new OfflineInvoice(); + } else { + $offlineInvoice = OfflineInvoice::where('company_id', $companyId)->orderBy('created_at', 'desc')->first(); + if (!$offlineInvoice) { + $offlineInvoice = new OfflineInvoice(); + } + } + $offlineInvoice->company_id = $company->id; + $offlineInvoice->package_id = $company->package_id; + $offlineInvoice->package_type = $request->packageType; + $offlineInvoice->amount = $request->amount ?: $package->{$request->packageType . '_price'}; + $offlineInvoice->pay_date = $payDate; + $offlineInvoice->next_pay_date = $nextPayDate; + $offlineInvoice->status = 'paid'; + + $offlineInvoice->save(); + $company->save(); + + return response(['status' => 'success', 'message' => 'Package Updated Successfully.'], 200); + } catch (\Exception $e) { + return $e; + } + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function edit($id) + { + $this->company = Company::find($id); + + $this->timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL); + $this->currencies = Currency::where('company_id', $id)->get(); + $this->packages = Package::all(); + $this->companyUser = User::where('company_id', $id)->withoutGlobalScope('active')->first(); + + return view('super-admin.companies.edit', $this->data); + } + + public function defaultLanguage() + { + $this->languages = LanguageSetting::where('status', 'enabled')->get(); + return view('super-admin.companies.default-language', $this->data); + } + + /** + * @param Request $request + * @return array + */ + public function defaultLanguageUpdate(Request $request) + { + $this->global->new_company_locale = $request->default_language; + $this->global->save(); + + return Reply::success(__('messages.defaultCompanyLanguage')); + } + + /** + * Update the specified resource in storage. + * + * @param UpdateRequest $request + * @param int $id + * @return array + */ + public function update(UpdateRequest $request, $id) + { + $company = Company::find($id); + $this->storeAndUpdate($company, $request); + + $company->currency_id = $request->currency_id; + $company->save(); + + $user = User::where('company_id', $id)->withoutGlobalScope('active')->first(); + $user->email = $request->email; + + if (!is_null($request->password)) { + $user->password = bcrypt($request->password); + } + $user->save(); + + + return Reply::redirect(route('super-admin.companies.index'), __('messages.updateSuccess')); + } + + /** + * Remove the specified resource from storage. + * + * @param DeleteRequest $request + * @param int $id + * @return array + */ + public function destroy(DeleteRequest $request, $id) + { + Company::destroy($id); + return Reply::success(__('messages.deleteSuccess')); + } + + /** + * @param Request $request + * @return mixed + * @throws \Exception + */ + public function data(Request $request) + { + $packages = Company::with('currency', 'package'); + + if ($request->package != 'all' && $request->package != '') { + $packages = $packages->where('package_id', $request->package); + } + + if ($request->type != 'all' && $request->type != '') { + $packages = $packages->where('package_type', $request->type); + } + + return Datatables::of($packages) + ->addColumn('action', function ($row) { + $companyUser = User::withoutGlobalScope(CompanyScope::class)->withoutGlobalScope('active')->where('company_id', $row->id)->first(); + + $list = '

'; + + if ($companyUser && $companyUser->email_verification_code != null) { + $list .= '

'; + } else if (module_enabled('Subdomain')) { + $list .= '

'; + } + + $list .= '

'; + return $list; + }) + ->editColumn('company_name', function ($row) { + return ucfirst($row->company_name) . '
' . ''; + }) + ->editColumn('status', function ($row) { + $class = ($row->status == 'active') ? 'label-custom' : 'label-danger'; + return '' . ucfirst($row->status) . ''; + }) + ->editColumn('company_email', function ($row) { + return '' . $row->company_email . ''; + }) + ->editColumn('sub_domain', function ($row) { + return '' . $row->sub_domain . ''; + }) + ->editColumn('last_login', function ($row) { + if ($row->last_login != null) { + return $row->last_login->diffForHumans(); + } + return '-'; + }) + ->editColumn('package', function ($row) { + $package = '
'; + $package .= '
' . ucwords($row->package->name) . ' (' . ucfirst($row->package_type) . ')' . '
'; + + $package .= ' Change '; + $package .= '
'; + return $package; + }) + ->addColumn('details', function ($row) { + $companyUser = User::withoutGlobalScope(CompanyScope::class)->withoutGlobalScope('active')->where('company_id', $row->id)->first(); + + if ($companyUser && $companyUser->email_verification_code == null) { + $verified = ''; + } else if ($companyUser && $companyUser->email_verification_code != null) { + $verified = ''; + } else { + $verified = '-'; + } + + $registerDate = $row->created_at->format('d-m-Y'); + $totalUsers = User::withoutGlobalScope(CompanyScope::class)->withoutGlobalScope('active')->where('company_id', $row->id)->count(); + + $string = ""; + + return $string; + }) + ->rawColumns(['action', 'details', 'company_email', 'company_name', 'status', 'package', 'sub_domain']) + ->make(true); + } + + public function storeAndUpdate($company, $request) + { + $company->company_name = $request->input('company_name'); + $company->company_email = $request->input('company_email'); + $company->company_phone = $request->input('company_phone'); + $company->website = $request->input('website'); + $company->address = $request->input('address'); + $company->timezone = $request->input('timezone'); + $company->locale = $request->input('locale'); + $company->status = $request->status; + + if ($request->hasFile('logo')) { + $company->logo = Files::upload($request->logo, 'app-logo'); + } + + $company->last_updated_by = $this->user->id; + + if (module_enabled('Subdomain')) { + $company->sub_domain = $request->sub_domain; + } + + $company->save(); + + + try { + $this->updateExchangeRatesCompanyWise($company); + } catch (\Exception $e) { + } + + + return $company; + } + + public function verifyUser() + { + $userId = request('user_id'); + $user = User::withoutGlobalScope(CompanyScope::class)->withoutGlobalScope('active')->find($userId); + User::emailVerify($user->email_verification_code); + + return Reply::success(__('messages.updateSuccess')); + } +} diff --git a/app/Http/Middleware/SuperAdmin.php b/app/Http/Middleware/SuperAdmin.php new file mode 100644 index 0000000..db948ef --- /dev/null +++ b/app/Http/Middleware/SuperAdmin.php @@ -0,0 +1,36 @@ +user(); + + $exists = Storage::disk('storage')->exists('down'); + $setting = GlobalSetting::first(); + + if($exists && is_null($setting->purchase_code) && (strpos(request()->getHost(), '.test') === false) ){ + return Redirect::route('verify-purchase'); + } + + if (!Auth::check() || $user->super_admin == '0'){ + return Redirect::route('login'); + } + return $next($request); + } +} diff --git a/app/Http/Requests/SuperAdmin/Companies/DeleteRequest.php b/app/Http/Requests/SuperAdmin/Companies/DeleteRequest.php new file mode 100644 index 0000000..fea5ef2 --- /dev/null +++ b/app/Http/Requests/SuperAdmin/Companies/DeleteRequest.php @@ -0,0 +1,21 @@ +join('client_details', 'client_details.user_id', 'users.id') + ->where('users.email', $value) + ->first(); + + $userTable = User::withoutGlobalScopes(['active', CompanyScope::class]) + ->where('users.email', $value)->first(); + + if(!is_null($user) && (!is_null($userTable) && !$userTable->hasRole('admin'))){ + return true; + } + + elseif((!is_null($userTable) && is_null($user) && $userTable->hasRole('admin')) ){ + return false; + } + elseif(is_null($userTable) && is_null($user)){ + return true; + } + return false; + + }); + + return [ + "company_name" => "required", + "company_email" => "required|email|unique:companies", + 'sub_domain' => module_enabled('Subdomain') ?'required|min:4|unique:companies,sub_domain|max:50|sub_domain':'', + "company_phone" => "required", + "address" => "required", + "status" => "required", + 'email' => 'required|check_client', + 'password' => 'required|min:6' + + ]; + + } + + public function prepareForValidation() + { + if (empty($this->sub_domain)) { + return; + } + + // Add servername domain suffix at the end + $subdomain = trim($this->sub_domain, '.') . '.' . get_domain(); + $this->merge(['sub_domain' => $subdomain]); + request()->merge(['sub_domain' => $subdomain]); + } + + public function messages() + { + return [ + 'email.check_client' => 'The email has already been taken.' + ]; + } +} diff --git a/app/Http/Requests/SuperAdmin/Companies/UpdateRequest.php b/app/Http/Requests/SuperAdmin/Companies/UpdateRequest.php new file mode 100644 index 0000000..51acfe2 --- /dev/null +++ b/app/Http/Requests/SuperAdmin/Companies/UpdateRequest.php @@ -0,0 +1,37 @@ + 'required', + 'company_email' => 'required|email|unique:companies,company_email,'.$this->route('company'), + 'sub_domain' => module_enabled('Subdomain')?'required|min:4|max:50|sub_domain|unique:companies,sub_domain,'.$this->route('company'):'', + 'company_phone' => 'required', + 'address' => 'required', + 'status' => 'required' + ]; + } + + public function prepareForValidation() + { + if (empty($this->sub_domain)) { + return; + } + + // Add servername domain suffix at the end + $subdomain = trim($this->sub_domain, '.') . '.' . get_domain(); + $this->merge(['sub_domain' => $subdomain]); + request()->merge(['sub_domain' => $subdomain]); + } +} diff --git a/app/Http/Requests/SuperAdmin/SuperAdminBaseRequest.php b/app/Http/Requests/SuperAdmin/SuperAdminBaseRequest.php new file mode 100644 index 0000000..ba9980f --- /dev/null +++ b/app/Http/Requests/SuperAdmin/SuperAdminBaseRequest.php @@ -0,0 +1,18 @@ +company; + + $generatedBy = User::whereNull('company_id')->get(); + Notification::send($generatedBy, new NewCompanyRegister($company)); + } + } +} diff --git a/app/Notifications/NewCompanyRegister.php b/app/Notifications/NewCompanyRegister.php new file mode 100644 index 0000000..3429f99 --- /dev/null +++ b/app/Notifications/NewCompanyRegister.php @@ -0,0 +1,96 @@ +company = $company; + $this->setMailConfigs(); + } + + /** + * Get the notification's delivery channels. + *t('mail::layout') + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + $via = ['database']; + if ($notifiable->email_notifications) { + array_push($via, 'mail'); + } + return $via; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail($notifiable) + { + + return (new MailMessage) + ->subject(__('email.newCompany.subject').' '.config('app.name').'!') + ->greeting(__('email.hello').' '.ucwords($notifiable->name).'!') + ->line(__('email.newCompany.text')) + ->line('With name:- '.$this->company->company_name) + ->action(__('email.loginDashboard'), getDomainSpecificUrl(url('/login'))) + ->line(__('email.thankyouNote')); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return array_merge($notifiable->toArray(), ['company_name' => $this->company->company_name]); + } + + /** + * Get the Slack representation of the notification. + * + * @param mixed $notifiable + * @return SlackMessage + */ + public function toSlack($notifiable) + { + $slack = SlackSetting::first(); + if(count($notifiable->employee) > 0 && !is_null($notifiable->employee[0]->slack_username)){ + return (new SlackMessage()) + ->from(config('app.name')) + ->image($slack->slack_logo_url) + ->to('@' . $notifiable->employee[0]->slack_username) + ->content('Welcome to ' . config('app.name') . '! New company has been registered.'); + } + return (new SlackMessage()) + ->from(config('app.name')) + ->image($slack->slack_logo_url) + ->content('This is a redirected notification. Add slack username for *'.ucwords($notifiable->name).'*'); + } + +} diff --git a/app/Observers/CompanyObserver.php b/app/Observers/CompanyObserver.php new file mode 100644 index 0000000..21d3aff --- /dev/null +++ b/app/Observers/CompanyObserver.php @@ -0,0 +1,1046 @@ +first(); + $packages = Package::all(); + + // get trial package data + $trialPackage = $packages->filter(function ($value, $key) { + return $value->default == 'trial'; + })->first(); + + // get default package data + $defaultPackage = $packages->filter(function ($value, $key) { + return $value->default == 'yes'; + })->first(); + + // get another package data if trial and default package not found + $otherPackage = $packages->filter(function ($value, $key) { + return $value->default == 'no'; + })->first(); + + // if trial package is active set package to company + if ($packageSetting && !is_null($trialPackage)) { + $company->package_id = $trialPackage->id; + // set company license expire date + $noOfDays = (!is_null($packageSetting->no_of_days) && $packageSetting->no_of_days != 0) ? $packageSetting->no_of_days : 30; + $company->licence_expire_on = Carbon::now()->addDays($noOfDays)->format('Y-m-d'); + } + + // if trial package is not active set default package to company + elseif (!is_null($defaultPackage)) + $company->package_id = $defaultPackage->id; + else { + $company->package_id = $otherPackage->id; + } + + if ($company->date_picker_format == '') { + $company->date_picker_format = 'dd-mm-yyyy'; + } + + if(is_null($company->locale)){ + $company->locale = global_settings()->new_company_locale; + } + + switch ($company->date_format) { + case 'd-m-Y': + $company->moment_format = 'DD-MM-YYYY'; + break; + case 'm-d-Y': + $company->moment_format = 'MM-DD-YYYY'; + break; + case 'Y-m-d': + $company->moment_format = 'YYYY-MM-DD'; + break; + case 'd.m.Y': + $company->moment_format = 'DD.MM.YYYY'; + break; + case 'm.d.Y': + $company->moment_format = 'MM.DD.YYYY'; + break; + case 'Y.m.d': + $company->moment_format = 'YYYY.MM.DD'; + break; + case 'd/m/Y': + $company->moment_format = 'DD/MM/YYYY'; + break; + case 'Y/m/d': + $company->moment_format = 'YYYY/MM/DD'; + break; + case 'd-M-Y': + $company->moment_format = 'DD-MMM-YYYY'; + break; + case 'd/M/Y': + $company->moment_format = 'DD/MMM/YYYY'; + break; + case 'd.M.Y': + $company->moment_format = 'DD.MMM.YYYY'; + break; + case 'd M Y': + $company->moment_format = 'DD MMM YYYY'; + break; + case 'd F, Y': + $company->moment_format = 'DD MMMM, YYYY'; + break; + case 'D/M/Y': + $company->moment_format = 'ddd/MMM/YYYY'; + break; + case 'D.M.Y': + $company->moment_format = 'ddd.MMM.YYYY'; + break; + case 'D-M-Y': + $company->moment_format = 'ddd-MMM-YYYY'; + break; + case 'D M Y': + $company->moment_format = 'ddd MMM YYYY'; + break; + case 'd D M Y': + $company->moment_format = 'DD ddd MMM YYYY'; + break; + case 'D d M Y': + $company->moment_format = 'ddd DD MMMM YYYY'; + break; + case 'dS M Y': + $company->moment_format = 'Do MMM YYYY'; + break; + default: + $company->moment_format = 'DD-MM-YYYY'; + break; + } + + $company->save(); + + $this->addTaskBoard($company); + $this->addTicketChannel($company); + $this->addTicketType($company); + $this->addTicketGroup($company); + $this->addLeaveType($company); + $this->addEmailNotificationSettings($company); + $this->addDefaultCurrencies($company); + $this->addDefaultThemeSettings($company); + $this->addPaymentGatewaySettings($company); + $this->addInvoiceSettings($company); + $this->addSlackSettings($company); + $this->addProjectSettings($company); + $this->addAttendanceSettings($company); + $this->addCustomFieldGroup($company); + $this->addRoles($company); + $this->addMessageSetting($company); + $this->addLogTImeForSetting($company); + $this->addLeadSourceAndLeadStatus($company); + $this->addProjectCategory($company); + $this->addDashboardWidget($company); + $this->insertGDPR($company); + + $this->addDefaultTimezone($company); + + event(new CompanyRegistered($company)); + } + + public function addDefaultTimezone($company){ + $globalSetting = GlobalSetting::first(); + $company->timezone = $globalSetting->timezone; + $company->save(); + } + + public function updated(Company $company) + { + + if ($company->isDirty('package_id')) { + ModuleSetting::where('company_id', $company->id)->delete(); + ModuleSetting::whereNull('company_id')->delete(); + $package = Package::findOrFail($company->package_id); + + $moduleInPackage = (array) json_decode($package->module_in_package); + $clientModules = ['projects', 'tickets', 'invoices', 'estimates', 'events', 'products', 'tasks', 'messages', 'payments', 'contracts', 'notices', 'timelogs']; + foreach ($moduleInPackage as $module) { + + if (in_array($module, $clientModules)) { + $moduleSetting = new ModuleSetting(); + $moduleSetting->company_id = $company->id; + $moduleSetting->module_name = $module; + $moduleSetting->status = 'active'; + $moduleSetting->type = 'client'; + $moduleSetting->save(); + } + + $moduleSetting = new ModuleSetting(); + $moduleSetting->company_id = $company->id; + $moduleSetting->module_name = $module; + $moduleSetting->status = 'active'; + $moduleSetting->type = 'employee'; + $moduleSetting->save(); + + $moduleSetting = new ModuleSetting(); + $moduleSetting->company_id = $company->id; + $moduleSetting->module_name = $module; + $moduleSetting->status = 'active'; + $moduleSetting->type = 'admin'; + $moduleSetting->save(); + } + } + session()->forget('company_setting'); + } + + public function updating(Company $company) + { + + $user = user(); + + if ($user) { + $company->last_updated_by = $user->id; + } + + if ($company->isDirty('date_format')) { + switch ($company->date_format) { + case 'd-m-Y': + $company->date_picker_format = 'dd-mm-yyyy'; + break; + case 'm-d-Y': + $company->date_picker_format = 'mm-dd-yyyy'; + break; + case 'Y-m-d': + $company->date_picker_format = 'yyyy-mm-dd'; + break; + case 'd.m.Y': + $company->date_picker_format = 'dd.mm.yyyy'; + break; + case 'm.d.Y': + $company->date_picker_format = 'mm.dd.yyyy'; + break; + case 'Y.m.d': + $company->date_picker_format = 'yyyy.mm.dd'; + break; + case 'd/m/Y': + $company->date_picker_format = 'dd/mm/yyyy'; + break; + case 'Y/m/d': + $company->date_picker_format = 'yyyy/mm/dd'; + break; + case 'd-M-Y': + $company->date_picker_format = 'dd-M-yyyy'; + break; + case 'd/M/Y': + $company->date_picker_format = 'dd/M/yyyy'; + break; + case 'd.M.Y': + $company->date_picker_format = 'dd.M.yyyy'; + break; + case 'd M Y': + $company->date_picker_format = 'dd M yyyy'; + break; + case 'd F, Y': + $company->date_picker_format = 'dd MM, yyyy'; + break; + case 'D/M/Y': + $company->date_picker_format = 'D/M/yyyy'; + break; + case 'D.M.Y': + $company->date_picker_format = 'D.M.yyyy'; + break; + case 'D-M-Y': + $company->date_picker_format = 'D-M-yyyy'; + break; + case 'D M Y': + $company->date_picker_format = 'D M yyyy'; + break; + case 'd D M Y': + $company->date_picker_format = 'dd D M yyyy'; + break; + case 'D d M Y': + $company->date_picker_format = 'D dd M yyyy'; + break; + case 'dS M Y': + $company->date_picker_format = 'dd M yyyy'; + break; + default: + $company->date_picker_format = 'mm/dd/yyyy'; + break; + } + + switch ($company->date_format) { + case 'd-m-Y': + $company->moment_format = 'DD-MM-YYYY'; + break; + case 'm-d-Y': + $company->moment_format = 'MM-DD-YYYY'; + break; + case 'Y-m-d': + $company->moment_format = 'YYYY-MM-DD'; + break; + case 'd.m.Y': + $company->moment_format = 'DD.MM.YYYY'; + break; + case 'm.d.Y': + $company->moment_format = 'MM.DD.YYYY'; + break; + case 'Y.m.d': + $company->moment_format = 'YYYY.MM.DD'; + break; + case 'd/m/Y': + $company->moment_format = 'DD/MM/YYYY'; + break; + case 'Y/m/d': + $company->moment_format = 'YYYY/MM/DD'; + break; + case 'd-M-Y': + $company->moment_format = 'DD-MMM-YYYY'; + break; + case 'd/M/Y': + $company->moment_format = 'DD/MMM/YYYY'; + break; + case 'd.M.Y': + $company->moment_format = 'DD.MMM.YYYY'; + break; + case 'd M Y': + $company->moment_format = 'DD MMM YYYY'; + break; + case 'd F, Y': + $company->moment_format = 'DD MMMM, YYYY'; + break; + case 'D/M/Y': + $company->moment_format = 'ddd/MMM/YYYY'; + break; + case 'D.M.Y': + $company->moment_format = 'ddd.MMM.YYYY'; + break; + case 'D-M-Y': + $company->moment_format = 'ddd-MMM-YYYY'; + break; + case 'D M Y': + $company->moment_format = 'ddd MMM YYYY'; + break; + case 'd D M Y': + $company->moment_format = 'DD ddd MMM YYYY'; + break; + case 'D d M Y': + $company->moment_format = 'ddd DD MMMM YYYY'; + break; + case 'dS M Y': + $company->moment_format = 'Do MMM YYYY'; + break; + default: + $company->moment_format = 'MM/DD/YYYY'; + break; + } + } + } + + public function deleting(Company $company) + { + $projects = \App\Project::where('company_id', $company->id)->get(); + + $otherCompanyClient = ClientDetails::with('user') + ->select('client_details.id as clientid','users.id as userid','client_details.company_id as client_company_id', + 'client_details.name as clientname') + ->withoutGlobalScope(CompanyScope::class)->where('client_details.company_id', '<>',$company->id) + ->join('users', 'users.id', 'client_details.user_id') + ->where('users.company_id', $company->id) + ->get(); + + foreach($otherCompanyClient as $clientUser){ + + $userData = User::withoutGlobalScopes(['active', CompanyScope::class])->find($clientUser->userid); + $userData->company_id = $clientUser->client_company_id; + $userData->name = $clientUser->clientname; + $userData->save(); + $employeeRole = Role::where('name', 'admin')->first(); + RoleUser::where('user_id', $userData->id)->where('role_id', $employeeRole->id)->delete(); + } + + + foreach ($projects as $project) { + File::deleteDirectory('user-uploads/project-files/' . $project->id); + $project->forceDelete(); + } + + $expenses = \App\Expense::where('company_id', $company->id)->get(); + foreach ($expenses as $expense) { + File::delete('user-uploads/expense-invoice/' . $expense->bill); + } + + $users = \App\User::where('company_id', $company->id)->get(); + foreach ($users as $user) { + File::delete('user-uploads/avatar/' . $user->image); + } + + File::delete('user-uploads/app-logo/' . $company->logo); + } + + public function addTaskBoard($company) + { + + $uncatColumn = new TaskboardColumn(); + $uncatColumn->company_id = $company->id; + $uncatColumn->column_name = 'Incomplete'; + $uncatColumn->slug = 'incomplete'; + $uncatColumn->label_color = '#d21010'; + $uncatColumn->label_color = '#d21010'; + $uncatColumn->priority = 1; + $uncatColumn->save(); + + $completeColumn = new TaskboardColumn(); + $completeColumn->company_id = $company->id; + $completeColumn->column_name = 'Completed'; + $completeColumn->slug = 'completed'; + $completeColumn->label_color = '#679c0d'; + $completeColumn->priority = $uncatColumn->priority + 1; + $completeColumn->save(); + } + + public function addTicketChannel($company) + { + $channel = new TicketChannel(); + $channel->company_id = $company->id; + $channel->channel_name = 'Email'; + $channel->save(); + + $channel = new TicketChannel(); + $channel->company_id = $company->id; + $channel->channel_name = 'Phone'; + $channel->save(); + + $channel = new TicketChannel(); + $channel->company_id = $company->id; + $channel->channel_name = 'Twitter'; + $channel->save(); + + $channel = new TicketChannel(); + $channel->company_id = $company->id; + $channel->channel_name = 'Facebook'; + $channel->save(); + } + + public function addTicketType($company) + { + $type = new TicketType(); + $type->company_id = $company->id; + $type->type = 'Question'; + $type->save(); + + $type = new TicketType(); + $type->company_id = $company->id; + $type->type = 'Problem'; + $type->save(); + + $type = new TicketType(); + $type->company_id = $company->id; + $type->type = 'Incident'; + $type->save(); + + $type = new TicketType(); + $type->company_id = $company->id; + $type->type = 'Feature Request'; + $type->save(); + } + + public function addTicketGroup($company) + { + $group = new TicketGroup(); + $group->company_id = $company->id; + $group->group_name = 'Sales'; + $group->save(); + + $group = new TicketGroup(); + $group->company_id = $company->id; + $group->group_name = 'Code'; + $group->save(); + + $group = new TicketGroup(); + $group->company_id = $company->id; + $group->group_name = 'Management'; + $group->save(); + } + + public function addLeaveType($company) + { + $category = new LeaveType(); + $category->company_id = $company->id; + $category->type_name = 'Casual'; + $category->color = 'success'; + $category->save(); + + $category = new LeaveType(); + $category->company_id = $company->id; + $category->type_name = 'Sick'; + $category->color = 'danger'; + $category->save(); + + $category = new LeaveType(); + $category->company_id = $company->id; + $category->type_name = 'Earned'; + $category->color = 'info'; + $category->save(); + + $leaveTypes = LeaveType::where('company_id', $company->id)->get(); + $employees = EmployeeDetails::where('company_id', $company->id)->get(); + + foreach ($employees as $key => $employee) { + foreach ($leaveTypes as $key => $value) { + EmployeeLeaveQuota::create( + [ + 'company_id' => $company->id, + 'user_id' => $employee->user_id, + 'leave_type_id' => $value->id, + 'no_of_leaves' => $value->no_of_leaves + ] + ); + } + } + } + + public function addEmailNotificationSettings($company) + { + // When new expense added by member + \App\EmailNotificationSetting::create([ + 'setting_name' => 'New Expense/Added by Admin', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // When new expense added by member + \App\EmailNotificationSetting::create([ + 'setting_name' => 'New Expense/Added by Member', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // When expense status changed + \App\EmailNotificationSetting::create([ + 'setting_name' => 'Expense Status Changed', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // New Support Ticket Request + \App\EmailNotificationSetting::create([ + 'setting_name' => 'New Support Ticket Request', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // When new user registers or added by admin + \App\EmailNotificationSetting::create([ + 'setting_name' => 'User Registration/Added by Admin', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // When employee is added to project + \App\EmailNotificationSetting::create([ + 'setting_name' => 'Employee Assign to Project', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // When notice published by admin + \App\EmailNotificationSetting::create([ + 'setting_name' => 'New Notice Published', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // When user is assigned to a task + \App\EmailNotificationSetting::create([ + 'setting_name' => 'User Assign to Task', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // When new leave application added + \App\EmailNotificationSetting::create([ + 'setting_name' => 'New Leave Application', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // When task completed + \App\EmailNotificationSetting::create([ + 'setting_name' => 'Task Completed', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // When task completed + \App\EmailNotificationSetting::create([ + 'setting_name' => 'Invoice Create/Update Notification', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // When task completed + \App\EmailNotificationSetting::create([ + 'setting_name' => 'Payment Create/Update Notification', + 'send_email' => 'yes', + 'send_push' => 'yes', + 'company_id' => $company->id + ]); + + // New + \App\EmailNotificationSetting::create([ + 'setting_name' => 'Discussion Reply', + 'send_push' => 'yes', + 'send_email' => 'yes', + 'company_id' => $company->id + ]); + } + + /** + * @param $company + */ + public function addDashboardWidget($company) + { + // When new widget added + \App\DashboardWidget::create([ + 'widget_name' => 'total_clients', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'total_employees', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'total_projects', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'total_unpaid_invoices', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'total_hours_logged', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'total_pending_tasks', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'total_today_attendance', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'total_unresolved_tickets', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'total_resolved_tickets', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'recent_earnings', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'settings_leaves', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'new_tickets', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'overdue_tasks', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'completed_tasks', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + +// \App\DashboardWidget::create([ +// 'widget_name' => 'client_feedbacks', +// 'status' => 1, +// 'company_id' => $company->id, +// 'dashboard_type' => 'admin-dashboard' +// ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'pending_follow_up', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'project_activity_timeline', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + \App\DashboardWidget::create([ + 'widget_name' => 'user_activity_timeline', + 'status' => 1, + 'company_id' => $company->id, + 'dashboard_type' => 'admin-dashboard' + ]); + + $widgets = [ + ['widget_name' => 'total_clients', 'status' => 1,'company_id' => $company->id, 'dashboard_type' => 'admin-client-dashboard'], + ['widget_name' => 'total_leads', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-client-dashboard'], + ['widget_name' => 'total_lead_conversions', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-client-dashboard'], + ['widget_name' => 'total_contracts_generated', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-client-dashboard'], + ['widget_name' => 'total_contracts_signed', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-client-dashboard'], + ['widget_name' => 'client_wise_earnings', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-client-dashboard'], + ['widget_name' => 'client_wise_timelogs', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-client-dashboard'], + ['widget_name' => 'lead_vs_status', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-client-dashboard'], + ['widget_name' => 'lead_vs_source', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-client-dashboard'], + ['widget_name' => 'latest_client', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-client-dashboard'], + ['widget_name' => 'recent_login_activities', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-client-dashboard'], + + ['widget_name' => 'total_paid_invoices', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'total_expenses', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'total_earnings', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'total_profit', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'total_pending_amount', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'invoice_overview', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'estimate_overview', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'proposal_overview', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'invoice_tab', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'estimate_tab', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'expense_tab', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'payment_tab', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'due_payments_tab', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'proposal_tab', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'earnings_by_client', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + ['widget_name' => 'earnings_by_projects', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-finance-dashboard'], + + ['widget_name' => 'total_leaves_approved', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-hr-dashboard'], + ['widget_name' => 'total_new_employee', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-hr-dashboard'], + ['widget_name' => 'total_employee_exits', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-hr-dashboard'], + ['widget_name' => 'average_attendance', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-hr-dashboard'], + ['widget_name' => 'department_wise_employee', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-hr-dashboard'], + ['widget_name' => 'designation_wise_employee', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-hr-dashboard'], + ['widget_name' => 'gender_wise_employee', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-hr-dashboard'], + ['widget_name' => 'role_wise_employee', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-hr-dashboard'], + ['widget_name' => 'leaves_taken', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-hr-dashboard'], + ['widget_name' => 'late_attendance_mark', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-hr-dashboard'], + + ['widget_name' => 'total_project', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-project-dashboard'], + ['widget_name' => 'total_hours_logged', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-project-dashboard'], + ['widget_name' => 'total_overdue_project', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-project-dashboard'], + ['widget_name' => 'status_wise_project', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-project-dashboard'], + ['widget_name' => 'pending_milestone', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-project-dashboard'], + + ['widget_name' => 'total_unresolved_tickets', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-ticket-dashboard'], + ['widget_name' => 'total_unassigned_ticket', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-ticket-dashboard'], + ['widget_name' => 'type_wise_ticket', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-ticket-dashboard'], + ['widget_name' => 'status_wise_ticket', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-ticket-dashboard'], + ['widget_name' => 'channel_wise_ticket', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-ticket-dashboard'], + ['widget_name' => 'new_tickets', 'status' => 1, 'company_id' => $company->id, 'dashboard_type' => 'admin-ticket-dashboard'], + ]; + + foreach ($widgets as $widget) { + DashboardWidget::create($widget); + } + + } + + public function addDefaultCurrencies($company) + { + $globalCurrencies = GlobalCurrency::all(); + $globalSetting = GlobalSetting::first(); + + foreach ($globalCurrencies as $globalCurrency) { + $currency = new Currency(); + $currency->company_id = $company->id; + $currency->currency_name = $globalCurrency->currency_name; + $currency->currency_symbol = $globalCurrency->currency_symbol; + $currency->currency_code = $globalCurrency->currency_code; + $currency->currency_position = $globalCurrency->currency_position; + $currency->save(); + + if ($globalSetting->currency_id == $globalCurrency->id) { + $company->currency_id = $currency->id; + $company->save(); + } + } + } + + public function addDefaultThemeSettings($company) + { + $theme = new ThemeSetting(); + $theme->company_id = $company->id; + $theme->panel = "admin"; + $theme->header_color = "#ed4040"; + $theme->sidebar_color = "#292929"; + $theme->sidebar_text_color = "#cbcbcb"; + $theme->save(); + + // project admin panel + $theme = new ThemeSetting(); + $theme->company_id = $company->id; + $theme->panel = "project_admin"; + $theme->header_color = "#5475ed"; + $theme->sidebar_color = "#292929"; + $theme->sidebar_text_color = "#cbcbcb"; + $theme->save(); + + // employee panel + $theme = new ThemeSetting(); + $theme->company_id = $company->id; + $theme->panel = "employee"; + $theme->header_color = "#f7c80c"; + $theme->sidebar_color = "#292929"; + $theme->sidebar_text_color = "#cbcbcb"; + $theme->save(); + + // client panel + $theme = new ThemeSetting(); + $theme->company_id = $company->id; + $theme->panel = "client"; + $theme->header_color = "#00c292"; + $theme->sidebar_color = "#292929"; + $theme->sidebar_text_color = "#cbcbcb"; + $theme->save(); + } + + public function addPaymentGatewaySettings($company) + { + $credential = new \App\PaymentGatewayCredentials(); + $credential->company_id = $company->id; + $credential->paypal_client_id = null; + $credential->paypal_secret = null; + $credential->save(); + } + + public function addInvoiceSettings($company) + { + $invoice = new \App\InvoiceSetting(); + $invoice->company_id = $company->id; + $invoice->invoice_prefix = 'INV'; + $invoice->template = 'invoice-1'; + $invoice->due_after = 15; + $invoice->invoice_terms = 'Thank you for your business. Please process this invoice within the due date.'; + $invoice->save(); + } + + public function addSlackSettings($company) + { + $slack = new \App\SlackSetting(); + $slack->company_id = $company->id; + $slack->slack_webhook = null; + $slack->slack_logo = null; + $slack->save(); + } + + public function addProjectSettings($company) + { + $project_setting = new ProjectSetting(); + + $project_setting->company_id = $company->id; + $project_setting->send_reminder = 'no'; + $project_setting->remind_time = 5; + $project_setting->remind_type = 'days'; + + $project_setting->save(); + } + + public function addAttendanceSettings($company) + { + $attendance = new \App\AttendanceSetting(); + $attendance->company_id = $company->id; + $attendance->office_start_time = '09:00:00'; + $attendance->office_end_time = '18:00:00'; + $attendance->late_mark_duration = '20'; + $attendance->save(); + } + + public function addCustomFieldGroup($company) + { + \DB::table('custom_field_groups')->insert([ + 'name' => 'Client', + 'model' => 'App\ClientDetails', + 'company_id' => $company->id + ]); + + \DB::table('custom_field_groups')->insert([ + 'name' => 'Employee', + 'model' => 'App\EmployeeDetails', + 'company_id' => $company->id + ]); + + \DB::table('custom_field_groups')->insert([ + 'name' => 'Project', + 'model' => 'App\Project', + 'company_id' => $company->id + ]); + } + + public function addRoles($company) + { + $admin = new Role(); + $admin->company_id = $company->id; + $admin->name = 'admin'; + $admin->display_name = 'App Administrator'; // optional + $admin->description = 'Admin is allowed to manage everything of the app.'; // optional + $admin->save(); + + $employee = new Role(); + $employee->company_id = $company->id; + $employee->name = 'employee'; + $employee->display_name = 'Employee'; // optional + $employee->description = 'Employee can see tasks and projects assigned to him.'; // optional + $employee->save(); + + $client = new Role(); + $client->company_id = $company->id; + $client->name = 'client'; + $client->display_name = 'Client'; // optional + $client->description = 'Client can see own tasks and projects.'; // optional + $client->save(); + } + + public function addMessageSetting($company) + { + $setting = new MessageSetting(); + $setting->company_id = $company->id; + $setting->allow_client_admin = 'yes'; + $setting->allow_client_employee = 'yes'; + $setting->save(); + } + + + public function addLogTImeForSetting($company) + { + $storage = new LogTimeFor(); + $storage->company_id = $company->id; + $storage->log_time_for = 'project'; + $storage->save(); + } + + public function addLeadSourceAndLeadStatus($company) + { + $sources = [ + ['type' => 'email', 'company_id' => $company->id], + ['type' => 'google', 'company_id' => $company->id], + ['type' => 'facebook', 'company_id' => $company->id], + ['type' => 'friend', 'company_id' => $company->id], + ['type' => 'direct visit', 'company_id' => $company->id], + ['type' => 'tv ad', 'company_id' => $company->id] + ]; + + LeadSource::insert($sources); + + $status = [ + ['type' => 'pending', 'company_id' => $company->id, 'default' => 1, 'priority' => 1], + ['type' => 'inprocess', 'company_id' => $company->id, 'default' => 0, 'priority' => 2], + ['type' => 'converted', 'company_id' => $company->id, 'default' => 0, 'priority' => 3] + ]; + + LeadStatus::insert($status); + } + + public function addProjectCategory($company) + { + $category = new \App\ProjectCategory(); + $category->category_name = 'Laravel'; + $category->company_id = $company->id; + $category->save(); + + $category = new \App\ProjectCategory(); + $category->category_name = 'Java'; + $category->company_id = $company->id; + $category->save(); + } + + private function insertGDPR($company) + { + $gdpr = new GdprSetting(); + $gdpr->company_id = $company->id; + $gdpr->save(); + } + +} diff --git a/app/Scopes/CompanyScope.php b/app/Scopes/CompanyScope.php new file mode 100644 index 0000000..8195e64 --- /dev/null +++ b/app/Scopes/CompanyScope.php @@ -0,0 +1,35 @@ +user() do not work in apply so we have use auth()->hasUser() + if ((session()->has('client_company') && $model->getTable() != "users") || !session()->has('client_company') ) { + if (auth()->hasUser() && Schema::hasColumn($model->getTable(), 'company_id')) { + $company = company(); + if ($company) { + $builder->where($model->getTable() . '.company_id', '=', $company->id); + } + } + if (session()->has('company') && Schema::hasColumn($model->getTable(), 'company_id')) { + $company = company(); + if ($company) { + $builder->where($model->getTable() . '.company_id', '=', $company->id); + } + } + } + + } +}