Start
This commit is contained in:
390
app/Http/Controllers/Superadmin/ManageUsersController.php
Normal file
390
app/Http/Controllers/Superadmin/ManageUsersController.php
Normal file
@@ -0,0 +1,390 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Superadmin;
|
||||
|
||||
use App\Form;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Notifications\UserNotification;
|
||||
use App\Package;
|
||||
use App\User;
|
||||
use App\UserForm;
|
||||
use Illuminate\Http\Request;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class ManageUsersController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (! auth()->user()->can('superadmin')) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
if ($request->ajax()) {
|
||||
$users = User::select('name', 'email', 'is_active', 'created_at', 'id');
|
||||
|
||||
if (! empty($request->input('status'))) {
|
||||
$is_active = ($request->input('status') == 'active') ? 1 : 0;
|
||||
$users->where('is_active', $is_active);
|
||||
}
|
||||
|
||||
return DataTables::of($users)
|
||||
->addColumn(
|
||||
'action',
|
||||
'
|
||||
@if($is_active)
|
||||
<span title="@lang("messages.mark_inactive")">
|
||||
<a class="btn btn-link btn-icon btn-sm text-danger toggle_is_active pointer" data-href="{{ action([\App\Http\Controllers\Superadmin\ManageUsersController::class, "toggleUserActiveStatus"], [$id])}}">
|
||||
<i class="fas fa-toggle-on font_icon_size"></i>
|
||||
</a>
|
||||
</span>
|
||||
@else
|
||||
<span title="@lang("messages.mark_active")">
|
||||
<a class="btn btn-link btn-icon btn-sm text-success toggle_is_active pointer" data-href="{{ action([\App\Http\Controllers\Superadmin\ManageUsersController::class, "toggleUserActiveStatus"], [$id])}}">
|
||||
<i class="fas fa-toggle-off font_icon_size"></i>
|
||||
</a>
|
||||
</span>
|
||||
@endif
|
||||
<a class="btn btn-link btn-icon btn-sm text-info edit_user pointer" data-href="{{action([\App\Http\Controllers\Superadmin\ManageUsersController::class, "edit"], [$id])}}" title="@lang("messages.edit")">
|
||||
<i class="fas fa-edit font_icon_size"></i>
|
||||
</a>
|
||||
<a class="btn btn-link btn-icon btn-sm text-info upgrade_account pointer" data-href="{{action([\App\Http\Controllers\Superadmin\ManageUsersController::class, "upgrade"], [$id])}}" title="@lang("messages.edit")">
|
||||
<i class="fas fa-money-check font_icon_size"></i>
|
||||
</a>
|
||||
<a class="btn btn-link btn-icon btn-sm text-danger delete_user pointer" data-href="{{action([\App\Http\Controllers\Superadmin\ManageUsersController::class, "destroy"], [$id])}}" title="@lang("messages.delete")">
|
||||
<i class="fas fa-trash-alt font_icon_size"></i>
|
||||
</a>
|
||||
'
|
||||
)
|
||||
->editColumn(
|
||||
'is_active',
|
||||
'
|
||||
@if($is_active)
|
||||
<span class="badge badge-pill badge-success">
|
||||
<i class="far fa-check-circle"></i>
|
||||
@lang(\'messages.active\')
|
||||
</span>
|
||||
@else
|
||||
<span class="badge badge-pill badge-danger">
|
||||
<i class="far fa-times-circle"></i>
|
||||
@lang(\'messages.inactive\')
|
||||
</span>
|
||||
@endif
|
||||
'
|
||||
)
|
||||
->editColumn(
|
||||
'created_at',
|
||||
'
|
||||
@php
|
||||
$date = \Carbon\Carbon::parse($created_at)->isoFormat("D/M/YY HH:mm A");
|
||||
@endphp
|
||||
{{$date}}
|
||||
'
|
||||
)
|
||||
->removeColumn('id')
|
||||
->rawColumns(['action', 'is_active', 'created_at'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
return view('superadmin.users.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
if (request()->ajax()) {
|
||||
$user = request()->user();
|
||||
|
||||
$forms = Form::where('is_template', 0)
|
||||
->where('created_by', $user->id)
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
|
||||
return view('superadmin.users.create')
|
||||
->with(compact('forms'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
if (! empty($this->notAllowedInDemo())) {
|
||||
return $this->notAllowedInDemo();
|
||||
}
|
||||
|
||||
$input = $request->only('name', 'email', 'is_active', 'can_create_form');
|
||||
|
||||
if (! empty($request->input('password'))) {
|
||||
$input['password'] = bcrypt($request->input('password'));
|
||||
}
|
||||
|
||||
$input['is_active'] = ! empty($input['is_active']) ? 1 : 0;
|
||||
$input['can_create_form'] = ! empty($input['can_create_form']) ? 1 : 0;
|
||||
|
||||
$user = User::create($input);
|
||||
|
||||
//save user forms (assgined)
|
||||
$permissions = $request->input('permissions');
|
||||
$form_ids = $request->input('form_id');
|
||||
$user_forms = [];
|
||||
if (! empty($form_ids) && ! empty($permissions)) {
|
||||
foreach ($form_ids as $key => $form_id) {
|
||||
$user_forms[] = [
|
||||
'form_id' => $form_id,
|
||||
'assigned_by' => \Auth::id(),
|
||||
'permissions' => $permissions,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$user->userForms()->createMany($user_forms);
|
||||
|
||||
if (! empty($request->input('send_email'))) {
|
||||
$input['password'] = $request->input('password');
|
||||
$user->notify(new UserNotification($input));
|
||||
}
|
||||
|
||||
$output = $this->respondSuccess();
|
||||
} catch (Exception $e) {
|
||||
$output = $this->respondWentWrong($e);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if (request()->ajax()) {
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
$logged_in_user = request()->user();
|
||||
|
||||
$forms = Form::where('is_template', 0)
|
||||
->where('created_by', $logged_in_user->id)
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
|
||||
$assigned_forms = UserForm::with('form')
|
||||
->where('assigned_by', \Auth::id())
|
||||
->where('assigned_to', $id)
|
||||
->get();
|
||||
|
||||
return view('superadmin.users.edit')
|
||||
->with(compact('user', 'forms', 'assigned_forms'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
if (! empty($this->notAllowedInDemo())) {
|
||||
return $this->notAllowedInDemo();
|
||||
}
|
||||
|
||||
$input = $request->only('name', 'email', 'is_active', 'can_create_form');
|
||||
$input['is_active'] = ! empty($input['is_active']) ? 1 : 0;
|
||||
$input['can_create_form'] = ! empty($input['can_create_form']) ? 1 : 0;
|
||||
|
||||
if (! empty($request->input('password'))) {
|
||||
$input['password'] = bcrypt($request->input('password'));
|
||||
}
|
||||
|
||||
$user = User::findOrFail($id);
|
||||
$user->update($input);
|
||||
|
||||
//update user forms (assgined)
|
||||
$edit_permissions = $request->input('edit_permissions');
|
||||
$assgined_form_ids = $request->input('edit_assigned_form_id');
|
||||
if (! empty($assgined_form_ids)) {
|
||||
$non_existing_ids = [];
|
||||
foreach ($assgined_form_ids as $key => $id) {
|
||||
if (! empty($edit_permissions[$id])) {
|
||||
$user_form = UserForm::find($id);
|
||||
$user_form->permissions = $edit_permissions[$id];
|
||||
$user_form->save();
|
||||
} else {
|
||||
$non_existing_ids[] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
UserForm::whereIn('id', $non_existing_ids)
|
||||
->delete();
|
||||
}
|
||||
|
||||
//save user forms (assgined)
|
||||
$permissions = $request->input('permissions');
|
||||
$form_ids = $request->input('form_id');
|
||||
$user_forms = [];
|
||||
if (! empty($form_ids) && ! empty($permissions)) {
|
||||
foreach ($form_ids as $key => $form_id) {
|
||||
$user_forms[] = [
|
||||
'form_id' => $form_id,
|
||||
'assigned_by' => \Auth::id(),
|
||||
'permissions' => $permissions,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$user->userForms()->createMany($user_forms);
|
||||
|
||||
if (! empty($request->input('send_email'))) {
|
||||
$input['password'] = $request->input('password');
|
||||
$user->notify(new UserNotification($input));
|
||||
}
|
||||
|
||||
$output = $this->respondSuccess();
|
||||
} catch (Exception $e) {
|
||||
$output = $this->respondWentWrong($e);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
if (request()->ajax()) {
|
||||
if (! empty($this->notAllowedInDemo())) {
|
||||
return $this->notAllowedInDemo();
|
||||
}
|
||||
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
if (\Auth::id() != $user->id) {
|
||||
$user->createdForms()->delete();
|
||||
$user->userForms()->delete();
|
||||
$user->delete();
|
||||
$output = $this->respondSuccess();
|
||||
} else {
|
||||
$output = $this->respondWithError(__('messages.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$output = $this->respondWentWrong($e);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle users status(active/inactive)
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function toggleUserActiveStatus($id)
|
||||
{
|
||||
try {
|
||||
if (request()->ajax()) {
|
||||
if (! empty($this->notAllowedInDemo())) {
|
||||
return $this->notAllowedInDemo();
|
||||
}
|
||||
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
if (\Auth::id() != $user->id) {
|
||||
$user->is_active = ! $user->is_active;
|
||||
$user->save();
|
||||
|
||||
$output = $this->respondSuccess();
|
||||
} else {
|
||||
$output = $this->respondWithError(__('messages.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$output = $this->respondWentWrong($e);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if email exist or not
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function checkIfEmailExist(Request $request)
|
||||
{
|
||||
$email = $request->input('email');
|
||||
|
||||
$query = User::where('email', $email);
|
||||
|
||||
if (! empty($request->input('user_id'))) {
|
||||
$user_id = $request->input('user_id');
|
||||
$query->where('id', '!=', $user_id);
|
||||
}
|
||||
|
||||
$exists = $query->exists();
|
||||
if (! $exists) {
|
||||
echo 'true';
|
||||
exit;
|
||||
} else {
|
||||
echo 'false';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade modal for upgrade the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function upgrade($id)
|
||||
{
|
||||
if (request()->ajax()) {
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
$active_packages = Package::where('is_active', 1)
|
||||
->orderBy('sort_order', 'asc')
|
||||
->paginate(20);
|
||||
|
||||
return view('superadmin.users.upgrade')
|
||||
->with(compact('user', 'active_packages'));
|
||||
}
|
||||
}
|
||||
}
|
||||
173
app/Http/Controllers/Superadmin/PackageController.php
Normal file
173
app/Http/Controllers/Superadmin/PackageController.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Superadmin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Package;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PackageController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if (! auth()->user()->can('superadmin')) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
$packages = Package::latest()
|
||||
->paginate(20);
|
||||
|
||||
return view('superadmin.packages.index')
|
||||
->with(compact('packages'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
if (! auth()->user()->can('superadmin')) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
$lists = Package::list();
|
||||
|
||||
return view('superadmin.packages.create')
|
||||
->with(compact('lists'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
if ($request->ajax()) {
|
||||
$input = $request->only('name', 'description', 'no_of_active_forms', 'price_interval', 'interval', 'price', 'sort_order', 'is_active', 'is_form_downloadable');
|
||||
|
||||
if (empty($input['is_active'])) {
|
||||
$input['is_active'] = 0;
|
||||
}
|
||||
if (empty($input['is_form_downloadable'])) {
|
||||
$input['is_form_downloadable'] = 0;
|
||||
}
|
||||
if (empty($input['no_of_active_forms'])) {
|
||||
$input['no_of_active_forms'] = 0;
|
||||
}
|
||||
if (empty($input['price'])) {
|
||||
$input['price'] = 0;
|
||||
}
|
||||
|
||||
Package::create($input);
|
||||
|
||||
$package_dashboard_url['redirect'] = action([\App\Http\Controllers\Superadmin\PackageController::class, 'index']);
|
||||
|
||||
$output = $this->respondSuccess(__('messages.saved_successfully'), $package_dashboard_url);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$output = $this->respondWentWrong($e);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if (! auth()->user()->can('superadmin')) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
if (! empty($id)) {
|
||||
$package = Package::find($id);
|
||||
$lists = Package::list();
|
||||
|
||||
return view('superadmin.packages.edit')
|
||||
->with(compact('package', 'lists'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
if ($request->ajax()) {
|
||||
$input = $request->only('name', 'description', 'no_of_active_forms', 'price_interval', 'interval', 'price', 'sort_order', 'is_active', 'is_form_downloadable');
|
||||
|
||||
if (empty($input['is_active'])) {
|
||||
$input['is_active'] = 0;
|
||||
}
|
||||
if (empty($input['is_form_downloadable'])) {
|
||||
$input['is_form_downloadable'] = 0;
|
||||
}
|
||||
if (empty($input['no_of_active_forms'])) {
|
||||
$input['no_of_active_forms'] = 0;
|
||||
}
|
||||
if (empty($input['price'])) {
|
||||
$input['price'] = 0;
|
||||
}
|
||||
|
||||
Package::where('id', $id)
|
||||
->update($input);
|
||||
|
||||
$package_dashboard_url['redirect'] = action([\App\Http\Controllers\Superadmin\PackageController::class, 'index']);
|
||||
|
||||
$output = $this->respondSuccess(__('messages.updated_successfully'), $package_dashboard_url);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$output = $this->respondWentWrong($e);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
Package::destroy($id);
|
||||
$output = $this->respondSuccess(__('messages.deleted_successfully'));
|
||||
} catch (Exception $e) {
|
||||
$output = $this->respondWentWrong($e);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Superadmin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Package;
|
||||
use App\PackageSubscription;
|
||||
use Illuminate\Http\Request;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class PackageSubscriptionsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (! auth()->user()->can('superadmin')) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
if ($request->ajax()) {
|
||||
$package_subscription = PackageSubscription::join('users', 'package_subscriptions.user_id', 'users.id')
|
||||
->select('users.name as user', 'package_subscriptions.package_details', 'start_date', 'end_date', 'package_price', 'payment_transaction_id', 'status', 'paid_via', 'package_subscriptions.id as package_subscription_id', 'users.email as user_email');
|
||||
|
||||
if (! empty($request->input('package_id'))) {
|
||||
$package_subscription->where('package_id', $request->input('package_id'));
|
||||
}
|
||||
|
||||
if (! empty($request->input('status'))) {
|
||||
$package_subscription->where('status', $request->input('status'));
|
||||
}
|
||||
|
||||
return Datatables::of($package_subscription)
|
||||
->addColumn('action', '
|
||||
<button type="button" data-href="{{action([\App\Http\Controllers\Superadmin\PackageSubscriptionsController::class, "edit"], [$package_subscription_id])}}" class="btn btn-icon btn-sm edit_subscription text-primary" data-toggle="tooltip"
|
||||
title="{{ __(\'messages.edit\') }}">
|
||||
<i class="far fa-edit font_icon_size" aria-hidden="true"></i>
|
||||
</button>
|
||||
')
|
||||
->editColumn('status', '
|
||||
<span class="badge
|
||||
@if($status == "approved")
|
||||
badge-success
|
||||
@elseif($status == "waiting")
|
||||
badge-warning text-white
|
||||
@elseif($status == "declined")
|
||||
badge-danger
|
||||
@endif
|
||||
">
|
||||
@lang("messages.".$status)
|
||||
</span>
|
||||
')
|
||||
->addColumn('package', function ($row) {
|
||||
$package_name = ! empty($row->package_details['name']) ? $row->package_details['name'] : '';
|
||||
|
||||
return $package_name;
|
||||
})
|
||||
->editColumn(
|
||||
'start_date',
|
||||
'@php
|
||||
$date = \Carbon\Carbon::parse($start_date)->isoFormat("D/M/YY");
|
||||
@endphp
|
||||
{{$date}}
|
||||
'
|
||||
)
|
||||
->editColumn('end_date', '@php
|
||||
$date = \Carbon\Carbon::parse($end_date)->isoFormat("D/M/YY");
|
||||
@endphp
|
||||
{{$date}}
|
||||
')
|
||||
->editColumn('package_price', '
|
||||
<span class="currency">
|
||||
{{$package_price}}
|
||||
</span>
|
||||
')
|
||||
->editColumn('paid_via', '
|
||||
@if($paid_via == "offline")
|
||||
@lang("messages.offline")
|
||||
@else
|
||||
{{ucfirst($paid_via)}}
|
||||
@endif
|
||||
')
|
||||
->removeColumn('package_subscription_id')
|
||||
->rawColumns(['action', 'package', 'status', 'start_date', 'end_date', 'package_price', 'paid_via'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
$subscription_status = PackageSubscription::status();
|
||||
$packages = Package::activePackages();
|
||||
|
||||
return view('superadmin.subscription.index')
|
||||
->with(compact('subscription_status', 'packages'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if (request()->ajax()) {
|
||||
$subscription = PackageSubscription::findOrFail($id);
|
||||
$status_list = PackageSubscription::status();
|
||||
|
||||
return view('superadmin.subscription.edit')
|
||||
->with(compact('subscription', 'status_list'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$subscription_info = $request->only('start_date', 'end_date', 'status', 'payment_transaction_id');
|
||||
|
||||
PackageSubscription::where('id', $id)
|
||||
->update($subscription_info);
|
||||
|
||||
$output = $this->respondSuccess(__('messages.updated_successfully'));
|
||||
} catch (Exception $e) {
|
||||
$output = $this->respondWentWrong($e);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Superadmin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Notifications\NotificationToUserForAccountUpgrade;
|
||||
use App\Notifications\SendApprovalNotificationToAdminForOfflinePayment;
|
||||
use App\Package;
|
||||
use App\PackageSubscription;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Notification;
|
||||
use Srmklive\PayPal\Services\ExpressCheckout;
|
||||
use Stripe\Checkout\Session;
|
||||
use Stripe\Stripe;
|
||||
|
||||
class SubscriptionPaymentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show pay form for a new package.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function subscriptionPay($package_id)
|
||||
{
|
||||
return $this->pay($package_id, $register_form = true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show pay form for a new package.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function pay($package_id, $register_form = null)
|
||||
{
|
||||
try {
|
||||
$package = Package::find($package_id);
|
||||
$user = request()->user();
|
||||
//Check for free package & subscribe it.
|
||||
if ($package->price == 0) {
|
||||
DB::beginTransaction();
|
||||
$paid_via = null;
|
||||
$payment_transaction_id = 'FREE';
|
||||
$status = 'approved';
|
||||
PackageSubscription::createSubscription($user->id, $package_id, $paid_via, $payment_transaction_id, $status);
|
||||
|
||||
DB::commit();
|
||||
|
||||
if (! empty($register_form)) {
|
||||
$output = [
|
||||
'success' => 1,
|
||||
'msg' => __('messages.registered_and_subscribed'),
|
||||
];
|
||||
|
||||
return redirect()->action([\App\Http\Controllers\SubscriptionsController::class, 'index'])
|
||||
->with('status', $output);
|
||||
} else {
|
||||
$output = [
|
||||
'success' => 1,
|
||||
'msg' => __('messages.success'),
|
||||
];
|
||||
|
||||
return redirect()->action([\App\Http\Controllers\SubscriptionsController::class, 'index'])
|
||||
->with('status', $output);
|
||||
}
|
||||
}
|
||||
|
||||
$nav = false;
|
||||
$payment_gateways = $this->paymentGateways();
|
||||
$stripe_payment_session = [];
|
||||
if (array_key_exists('stripe', $payment_gateways)) {
|
||||
Stripe::setApiKey(config('constants.STRIPE_SECRET_KEY'));
|
||||
$stripe_payment_session = \Stripe\Checkout\Session::create([
|
||||
'customer_email' => $user->email,
|
||||
'payment_method_types' => ['card'],
|
||||
'line_items' => [[
|
||||
'price_data' => [
|
||||
'currency' => strtolower(env('CURRENCY_CODE')),
|
||||
'unit_amount' => $package->price * 100,
|
||||
'product_data' => [
|
||||
'name' => $package->name,
|
||||
'description' => $package->description,
|
||||
'images' => [],
|
||||
],
|
||||
],
|
||||
'quantity' => 1,
|
||||
]],
|
||||
'mode' => 'payment',
|
||||
'success_url' => action([\App\Http\Controllers\Superadmin\SubscriptionPaymentController::class, 'confirmPayment'], [$package_id]).'?paid_via=stripe&session_id={CHECKOUT_SESSION_ID}',
|
||||
'cancel_url' => action([\App\Http\Controllers\Superadmin\SubscriptionPaymentController::class, 'pay'], [$package_id]),
|
||||
]);
|
||||
}
|
||||
|
||||
return view('payments.create')
|
||||
->with(compact('package', 'nav', 'payment_gateways', 'stripe_payment_session'));
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
$output = [
|
||||
'success' => 0,
|
||||
'msg' => __('messages.something_went_wrong'),
|
||||
];
|
||||
|
||||
return redirect()->action([\App\Http\Controllers\SubscriptionsController::class, 'index'])
|
||||
->with('status', $output);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* confirm the payment & Save the payment details and add subscription details
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function confirmPayment($package_id, Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$user = request()->user();
|
||||
$paid_via = $request->get('paid_via');
|
||||
//Call the payment method
|
||||
$pay_function = 'pay_'.$paid_via;
|
||||
$payment_transaction_id = null;
|
||||
$status = 'approved';
|
||||
if (method_exists($this, $pay_function)) {
|
||||
$payment_transaction_id = $this->$pay_function($package_id, $request);
|
||||
}
|
||||
|
||||
if (in_array($paid_via, ['offline'])) {
|
||||
$status = 'waiting';
|
||||
}
|
||||
//create subscription
|
||||
PackageSubscription::createSubscription($user->id, $package_id, $paid_via, $payment_transaction_id, $status);
|
||||
|
||||
DB::commit();
|
||||
$msg = __('messages.success');
|
||||
if ($request->get('paid_via') == 'offline') {
|
||||
$msg = __('messages.notification_sent_for_approval');
|
||||
}
|
||||
$output = ['success' => 1, 'msg' => $msg];
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
$output = [
|
||||
'success' => 0,
|
||||
'msg' => __('messages.something_went_wrong'),
|
||||
];
|
||||
}
|
||||
|
||||
return redirect()->action([\App\Http\Controllers\SubscriptionsController::class, 'index'])
|
||||
->with('status', $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Offline payment method
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
protected function pay_offline($package_id, $request)
|
||||
{
|
||||
$user = request()->user();
|
||||
$admin_emails = explode(',', env('SUPERADMIN_EMAILS'));
|
||||
$superadmins = User::whereIn('email', $admin_emails)
|
||||
->get();
|
||||
|
||||
$package = Package::find($package_id);
|
||||
$package['paid_via'] = 'Offline';
|
||||
$package['package_price'] = env('CURRENCY_SYMBOL').number_format($package->price, 2);
|
||||
|
||||
Notification::send($superadmins, new SendApprovalNotificationToAdminForOfflinePayment($user, $package));
|
||||
}
|
||||
|
||||
/**
|
||||
* Paypal payment method
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
protected function pay_paypal($package_id, $request)
|
||||
{
|
||||
$provider = new ExpressCheckout();
|
||||
config(['paypal.currency' => strtoupper(env('CURRENCY_CODE'))]);
|
||||
|
||||
$provider = new ExpressCheckout();
|
||||
$response = $provider->getExpressCheckoutDetails($request->token);
|
||||
|
||||
// if response ACK value is not SUCCESS or SUCCESSWITHWARNING return back with error
|
||||
if (! in_array(strtoupper($response['ACK']), ['SUCCESS', 'SUCCESSWITHWARNING'])) {
|
||||
return back()
|
||||
->with('status', ['success' => 0, 'msg' => 'Something went wrong with paypal transaction']);
|
||||
}
|
||||
|
||||
$invoice_id = $response['INVNUM'];
|
||||
$package = Package::find($package_id);
|
||||
$data = [];
|
||||
$data['items'] = [
|
||||
[
|
||||
'name' => $package->name,
|
||||
'price' => (float) $package->price,
|
||||
'qty' => 1,
|
||||
],
|
||||
];
|
||||
$data['invoice_id'] = $invoice_id;
|
||||
$data['invoice_description'] = "Order #{$data['invoice_id']} Invoice";
|
||||
$data['return_url'] = action([\App\Http\Controllers\Superadmin\SubscriptionPaymentController::class, 'confirmPayment'], [$package_id]);
|
||||
$data['cancel_url'] = action([\App\Http\Controllers\Superadmin\SubscriptionPaymentController::class, 'pay'], [$package_id]);
|
||||
$data['total'] = (float) $package->price;
|
||||
|
||||
$token = $request->get('token');
|
||||
$PayerID = $request->get('PayerID');
|
||||
|
||||
// if payment is not recurring just perform transaction on PayPal and get the payment status
|
||||
$payment_status = $provider->doExpressCheckoutPayment($data, $token, $PayerID);
|
||||
$status = isset($payment_status['PAYMENTINFO_0_PAYMENTSTATUS']) ? $payment_status['PAYMENTINFO_0_PAYMENTSTATUS'] : null;
|
||||
|
||||
if (! empty($status) && $status != 'Invalid') {
|
||||
return $invoice_id;
|
||||
} else {
|
||||
$error = 'Something went wrong with paypal transaction';
|
||||
throw new \Exception($error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Paypal payment method - redirect to paypal url for payments
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function paypalExpressCheckout($package_id, Request $request)
|
||||
{
|
||||
$package = Package::find($package_id);
|
||||
$data = [];
|
||||
$data['items'] = [
|
||||
[
|
||||
'name' => $package->name,
|
||||
'price' => (float) $package->price,
|
||||
'qty' => 1,
|
||||
],
|
||||
];
|
||||
$data['invoice_id'] = Str::random(5);
|
||||
$data['invoice_description'] = "Order #{$data['invoice_id']} Invoice";
|
||||
$data['return_url'] = action([\App\Http\Controllers\Superadmin\SubscriptionPaymentController::class, 'confirmPayment'], [$package_id]).'?paid_via=paypal';
|
||||
$data['cancel_url'] = action([\App\Http\Controllers\Superadmin\SubscriptionPaymentController::class, 'pay'], [$package_id]);
|
||||
$data['total'] = (float) $package->price;
|
||||
|
||||
//send request to paypal & in response get aaray of data and if it has payment link redirect on that
|
||||
$provider = new ExpressCheckout();
|
||||
$response = $provider->setCurrency(strtoupper(env('CURRENCY_CODE')))->setExpressCheckout($data);
|
||||
|
||||
// if there is no link redirect back with error message
|
||||
if (! $response['paypal_link']) {
|
||||
return back()
|
||||
->with('status', ['success' => 0, 'msg' => 'Something went wrong with paypal transaction']);
|
||||
}
|
||||
|
||||
return redirect($response['paypal_link']);
|
||||
}
|
||||
|
||||
/**
|
||||
* return transaction id
|
||||
* after successful payment
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
protected function pay_stripe($package_id, $request)
|
||||
{
|
||||
Stripe::setApiKey(config('constants.STRIPE_SECRET_KEY'));
|
||||
$stripe_payment = Session::retrieve($request->session_id);
|
||||
|
||||
return $stripe_payment->payment_intent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm subscription by admin
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function confirmAdminSubscription($package_id, $user_id)
|
||||
{
|
||||
if (request()->ajax()) {
|
||||
return view('superadmin.users.confirm_upgrade')
|
||||
->with(compact('package_id', 'user_id'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add subscription details by admin
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function adminSubscription($package_id, $user_id, Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
if (! empty($request->input('disable_all_packages'))) {
|
||||
PackageSubscription::disableAllPackagesForUser($user_id);
|
||||
}
|
||||
|
||||
$user = User::where('id', $user_id)->first();
|
||||
$package = Package::find($package_id);
|
||||
|
||||
$payment_transaction_id = '';
|
||||
$status = 'approved';
|
||||
|
||||
//create subscription
|
||||
$subscription_info = PackageSubscription::createSubscription(
|
||||
$user->id,
|
||||
$package_id,
|
||||
'admin',
|
||||
$payment_transaction_id,
|
||||
$status
|
||||
);
|
||||
|
||||
Notification::send($user, new NotificationToUserForAccountUpgrade($user, $subscription_info));
|
||||
|
||||
DB::commit();
|
||||
$output = [
|
||||
'success' => 1,
|
||||
'msg' => __('messages.success'),
|
||||
];
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
$output = [
|
||||
'success' => 0,
|
||||
'msg' => __('messages.something_went_wrong'),
|
||||
];
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
222
app/Http/Controllers/Superadmin/SuperadminSettingsController.php
Normal file
222
app/Http/Controllers/Superadmin/SuperadminSettingsController.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Superadmin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\System;
|
||||
use DateTimeZone;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SuperadminSettingsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
if (! auth()->user()->can('superadmin')) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
$languages = config('constants.langs');
|
||||
$timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
|
||||
|
||||
$settings = [
|
||||
'APP_NAME' => config('app.name'),
|
||||
'APP_TITLE' => config('app.title'),
|
||||
'CURRENCY_NAME' => env('CURRENCY_NAME'),
|
||||
'CURRENCY_SYMBOL' => env('CURRENCY_SYMBOL'),
|
||||
'CURRENCY_CODE' => env('CURRENCY_CODE'),
|
||||
'APP_TIMEZONE' => env('APP_TIMEZONE'),
|
||||
'MAIL_HOST' => config('mail.mailers.smtp.host'),
|
||||
'MAIL_PORT' => config('mail.mailers.smtp.port'),
|
||||
'MAIL_USERNAME' => config('mail.mailers.smtp.username'),
|
||||
'MAIL_PASSWORD' => config('mail.mailers.smtp.password'),
|
||||
'MAIL_ENCRYPTION' => config('mail.mailers.smtp.encryption'),
|
||||
'ENABLE_REGISTRATION' => env('ENABLE_REGISTRATION'),
|
||||
'ENABLE_SAAS_MODULE' => env('ENABLE_SAAS_MODULE'),
|
||||
'MAIL_FROM_ADDRESS' => config('mail.from.address'),
|
||||
'MAIL_FROM_NAME' => config('mail.from.name'),
|
||||
'APP_LOCALE' => $languages,
|
||||
'timezones' => $timezones,
|
||||
'PAYPAL_MODE' => config('paypal.mode'),
|
||||
'PAYPAL_SANDBOX_API_USERNAME' => config('paypal.sandbox.username'),
|
||||
'PAYPAL_SANDBOX_API_PASSWORD' => config('paypal.sandbox.password'),
|
||||
'PAYPAL_SANDBOX_API_SECRET' => config('paypal.sandbox.secret'),
|
||||
'PAYPAL_LIVE_API_USERNAME' => config('paypal.live.username'),
|
||||
'PAYPAL_LIVE_API_PASSWORD' => config('paypal.live.password'),
|
||||
'PAYPAL_LIVE_API_SECRET' => config('paypal.live.secret'),
|
||||
'STRIPE_PUB_KEY' => config('constants.STRIPE_PUB_KEY'),
|
||||
'STRIPE_SECRET_KEY' => config('constants.STRIPE_SECRET_KEY'),
|
||||
'ENABLE_OFFLINE_PAYMENT' => config('constants.ENABLE_OFFLINE_PAYMENT'),
|
||||
'ACELLE_MAIL_NAME' => config('constants.ACELLE_MAIL_NAME'),
|
||||
'ACELLE_MAIL_API' => config('constants.ACELLE_MAIL_API'),
|
||||
];
|
||||
|
||||
if ($this->isDemo()) {
|
||||
$settings['MAIL_USERNAME'] = '';
|
||||
$settings['MAIL_PASSWORD'] = '';
|
||||
}
|
||||
|
||||
$date_formats = System::dateFormats();
|
||||
|
||||
$additional_js = System::getValue('additional_js');
|
||||
$additional_css = System::getValue('additional_css');
|
||||
|
||||
return view('superadmin.settings.create')
|
||||
->with(compact('settings', 'date_formats', 'additional_js', 'additional_css'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (! auth()->user()->can('superadmin')) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
try {
|
||||
//check for demo
|
||||
if ($this->isDemo()) {
|
||||
return redirect()
|
||||
->action([\App\Http\Controllers\HomeController::class, 'index'])
|
||||
->with('status', ['success' => false, 'msg' => __('messages.feature_disabled_in_demo')]);
|
||||
}
|
||||
|
||||
//update or create system data
|
||||
$systems = $request->input('system');
|
||||
foreach ($systems as $key => $value) {
|
||||
System::updateOrCreate(['key' => $key], ['value' => ! empty($value) ? $value : '']);
|
||||
}
|
||||
|
||||
//update env settings
|
||||
$env_settings = $request->only('APP_NAME', 'APP_TITLE', 'MAIL_HOST', 'MAIL_PORT',
|
||||
'MAIL_USERNAME', 'MAIL_PASSWORD', 'MAIL_ENCRYPTION', 'APP_LOCALE',
|
||||
'APP_TIMEZONE', 'CURRENCY_NAME', 'CURRENCY_SYMBOL', 'MAIL_FROM_ADDRESS',
|
||||
'MAIL_FROM_NAME', 'CURRENCY_CODE', 'PAYPAL_MODE', 'PAYPAL_SANDBOX_API_USERNAME',
|
||||
'PAYPAL_SANDBOX_API_PASSWORD', 'PAYPAL_SANDBOX_API_SECRET', 'PAYPAL_LIVE_API_USERNAME',
|
||||
'PAYPAL_LIVE_API_PASSWORD', 'PAYPAL_LIVE_API_SECRET', 'STRIPE_PUB_KEY', 'STRIPE_SECRET_KEY',
|
||||
'APP_DATE_FORMAT', 'APP_TIME_FORMAT', 'ACELLE_MAIL_NAME', 'ACELLE_MAIL_API');
|
||||
|
||||
//checkboxes values
|
||||
$env_settings['ENABLE_REGISTRATION'] = ! empty($request->input('ENABLE_REGISTRATION')) ? $request->input('ENABLE_REGISTRATION') : 0;
|
||||
$env_settings['ENABLE_SAAS_MODULE'] = ! empty($request->input('ENABLE_SAAS_MODULE')) ? $request->input('ENABLE_SAAS_MODULE') : 0;
|
||||
$env_settings['ENABLE_OFFLINE_PAYMENT'] = ! empty($request->input('ENABLE_OFFLINE_PAYMENT')) ? $request->input('ENABLE_OFFLINE_PAYMENT') : 0;
|
||||
|
||||
$found_envs = [];
|
||||
$env_path = base_path('.env');
|
||||
$env_lines = file($env_path);
|
||||
foreach ($env_settings as $index => $value) {
|
||||
foreach ($env_lines as $key => $line) {
|
||||
//Check if present then replace it.
|
||||
if (strpos($line, $index) !== false) {
|
||||
$env_lines[$key] = $index.'="'.$value.'"'.PHP_EOL;
|
||||
|
||||
$found_envs[] = $index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Add the missing env settings
|
||||
$missing_envs = array_diff(array_keys($env_settings), $found_envs);
|
||||
if (! empty($missing_envs)) {
|
||||
$missing_envs = array_values($missing_envs);
|
||||
foreach ($missing_envs as $k => $key) {
|
||||
if ($k == 0) {
|
||||
$env_lines[] = PHP_EOL.$key.'="'.$env_settings[$key].'"'.PHP_EOL;
|
||||
} else {
|
||||
$env_lines[] = $key.'="'.$env_settings[$key].'"'.PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$env_content = implode('', $env_lines);
|
||||
|
||||
if (is_writable($env_path) && file_put_contents($env_path, $env_content)) {
|
||||
$output = [
|
||||
'success' => true,
|
||||
'msg' => __('messages.saved_successfully'),
|
||||
];
|
||||
} else {
|
||||
$output = [
|
||||
'success' => false,
|
||||
'msg' => __('messages.env_permission'),
|
||||
];
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->action([\App\Http\Controllers\HomeController::class, 'index'])
|
||||
->with('status', $output);
|
||||
} catch (\Exception $e) {
|
||||
return redirect()
|
||||
->action([\App\Http\Controllers\HomeController::class, 'index'])
|
||||
->with('status',
|
||||
[
|
||||
'success' => false,
|
||||
'msg' => __('messages.something_went_wrong'),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user