-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #892 from ladybirdweb/development
- Loading branch information
Showing
359 changed files
with
3,140 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
app/Http/Controllers/Common/SystemManagerController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Common; | ||
|
||
use App\Http\Controllers\Auth\AuthController; | ||
use App\Http\Controllers\Controller; | ||
use App\User; | ||
use Illuminate\Http\Request; | ||
|
||
class SystemManagerController extends Controller | ||
{ | ||
public function getSystemManagers() | ||
{ | ||
$accountManagers = User::where('role', 'admin') | ||
->where('position', 'account_manager') | ||
->pluck('first_name', 'id')->toArray(); | ||
|
||
$salesManager = User::where('role', 'admin') | ||
->where('position', 'manager') | ||
->pluck('first_name', 'id')->toArray(); | ||
|
||
return view('themes.default1.common.system-managers', compact('accountManagers', 'salesManager')); | ||
} | ||
|
||
public function searchAdmin(Request $request) | ||
{ | ||
try { | ||
$term = trim($request->q); | ||
if (empty($term)) { | ||
return \Response::json([]); | ||
} | ||
$users = User::where('email', 'LIKE', '%'.$term.'%') | ||
->orWhere('first_name', 'LIKE', '%'.$term.'%') | ||
->orWhere('last_name', 'LIKE', '%'.$term.'%') | ||
->select('id', 'email', 'profile_pic', 'first_name', 'last_name', 'role')->get(); | ||
$formatted_tags = []; | ||
|
||
foreach ($users as $user) { | ||
if ($user->role == 'admin') { | ||
$formatted_users[] = ['id' => $user->id, 'text' => $user->email, 'profile_pic' => $user->profile_pic, | ||
'first_name' => $user->first_name, 'last_name' => $user->last_name, ]; | ||
} | ||
} | ||
|
||
return \Response::json($formatted_users); | ||
} catch (\Exception $e) { | ||
// returns if try fails with exception meaagse | ||
return redirect()->back()->with('fails', $e->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Replace old account manager with the newly selected account manager. | ||
* | ||
* @author Ashutosh Pathak <[email protected]> | ||
* | ||
* @date 2019-08-21T12:54:03+0530 | ||
* | ||
* @param Request $request | ||
* | ||
* @return array | ||
*/ | ||
public function replaceAccountManager(Request $request) | ||
{ | ||
$this->validate($request, [ | ||
'existingAccManager' => 'required', | ||
'newAccManager' => 'required', | ||
], [ | ||
'existingAccManager.required' => 'Select system Account Manager', | ||
'newAccManager.required' => 'Select new Account Manager', | ||
]); | ||
|
||
try { | ||
$existingAccManager = $request->input('existingAccManager'); | ||
$newAccountManager = $request->input('newAccManager')[0]; | ||
if ($existingAccManager == $newAccountManager) { | ||
return ['message'=>'fails', 'update'=>'Existing and the new account manager cannot be same']; | ||
} | ||
//First make the selected Admin as account Manager- | ||
User::where('id', $newAccountManager)->update(['position'=>'account_manager']); | ||
$accManagers = User::where('account_manager', $existingAccManager)->get(); | ||
foreach ($accManagers as $accManager) { | ||
User::where('id', $accManager->id)->update(['account_manager'=>$newAccountManager]); | ||
} | ||
$arrayOfBccEmails = User::where('account_manager', $newAccountManager)->pluck('email')->toArray(); | ||
if (count($arrayOfBccEmails) > 0) { | ||
$user = User::where('email', $arrayOfBccEmails[0])->first(); | ||
$cont = new AuthController(); | ||
$sendMail = $cont->accountManagerMail($user, $arrayOfBccEmails); | ||
} | ||
|
||
$existingAccManager = $request->input('existingAccManager'); | ||
$newAccountManager = $request->input('newAccManager')[0]; | ||
if ($existingAccManager == $newAccountManager) { | ||
return ['message'=>'fails', 'update'=>'Existing and the new account manager cannot be same']; | ||
} | ||
//First make the selected Admin as account Manager- | ||
User::where('id', $newAccountManager)->update(['position'=>'account_manager']); | ||
$accManagers = User::where('account_manager', $existingAccManager)->get(); | ||
foreach ($accManagers as $accManager) { | ||
User::where('id', $accManager->id)->update(['account_manager'=>$newAccountManager]); | ||
} | ||
$arrayOfBccEmails = User::where('account_manager', $newAccountManager)->pluck('email')->toArray(); | ||
if (count($arrayOfBccEmails) > 0) { | ||
$user = User::where('email', $arrayOfBccEmails[0])->first(); | ||
$cont = new AuthController(); | ||
$sendMail = $cont->accountManagerMail($user, $arrayOfBccEmails); | ||
} | ||
|
||
return ['message' => 'success', 'update'=>\Lang::get('message.account_man_replaced_success')]; | ||
} catch (\Exception $ex) { | ||
return ['message'=>'fails', 'update'=>$ex->getMessage()]; | ||
} | ||
} | ||
|
||
/** | ||
* Replace old sales manager with the newly selected sales manager. | ||
* | ||
* @author Ashutosh Pathak <[email protected]> | ||
* | ||
* @date 2019-08-21T12:54:03+0530 | ||
* | ||
* @param Request $request | ||
* | ||
* @return array | ||
*/ | ||
public function replaceSalesManager(Request $request) | ||
{ | ||
$this->validate($request, [ | ||
'existingSaleManager' => 'required', | ||
'newSaleManager' => 'required', | ||
], [ | ||
'existingSaleManager.required' => 'Select system Sales Manager', | ||
'newSaleManager.required' => 'Select new Sales Manager', | ||
]); | ||
|
||
try { | ||
$existingSaleManager = $request->input('existingSaleManager'); | ||
$newSalesManager = $request->input('newSaleManager')[0]; | ||
if ($existingSaleManager == $newSalesManager) { | ||
return ['message'=>'fails', 'update'=>'Existing and the new sales manager cannot be same']; | ||
} | ||
//First make the selected Admin as account Manager- | ||
User::where('id', $newSalesManager)->update(['position'=>'manager']); | ||
|
||
$saleManagers = User::where('manager', $existingSaleManager)->get(); | ||
foreach ($saleManagers as $saleManager) { | ||
User::where('id', $saleManager->id)->update(['manager'=>$newSalesManager]); | ||
} | ||
$arrayOfBccEmails = User::where('manager', $newSalesManager)->pluck('email')->toArray(); | ||
if (count($arrayOfBccEmails) > 0) { | ||
$user = User::where('email', $arrayOfBccEmails[0])->first(); | ||
$cont = new AuthController(); | ||
$sendMail = $cont->salesManagerMail($user, $arrayOfBccEmails); | ||
} | ||
|
||
return ['message' => 'success', 'update'=>\Lang::get('message.sales_man_replaced_success')]; | ||
} catch (\Exception $ex) { | ||
return ['message'=>'fails', 'update'=>$ex->getMessage()]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.