Skip to content

Commit

Permalink
Merge pull request #892 from ladybirdweb/development
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh pathak authored Sep 18, 2019
2 parents 75e2f67 + 6be6518 commit a29d133
Show file tree
Hide file tree
Showing 359 changed files with 3,140 additions and 240 deletions.
35 changes: 18 additions & 17 deletions app/Http/Controllers/Api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@ class ApiController extends Controller
public function checkDomain(Request $request)
{
try {
$result = 'fails';
$url = $request->input('url');
$url2 = preg_replace('#^https?://#', '', $url);
// $result = 'fails';
$result = 'success';
// $url = $request->input('url');
// $url2 = preg_replace('#^https?://#', '', $url);

// if (ends_with($domain, '/')) {
// $domain = substr_replace($domain,"", -1, 1);
// }
// // if (ends_with($domain, '/')) {
// // $domain = substr_replace($domain,"", -1, 1);
// // }

$url_info = parse_url($url);
$domain1 = $url_info['host'];
$url1 = preg_replace('#^www\.(.+\.)#i', '$1', $url_info['host']); //remove www from domain
$domain2 = 'www.'.$url1;
$domain1check = $url1.','.$domain2;
$orders = new Order();
$order = $orders->where('domain', $domain1check)->orWhere('domain', $url1)->orWhere('domain', $domain2)->orWhere('domain', $url2)->first();
if ($order) {
$product = Product::where('id', $order->product)->pluck('name')->first();
$result = 'success';
}
// $url_info = parse_url($url);
// $domain1 = $url_info['host'];
// $url1 = preg_replace('#^www\.(.+\.)#i', '$1', $url_info['host']); //remove www from domain
// $domain2 = 'www.'.$url1;
// $domain1check = $url1.','.$domain2;
// $orders = new Order();
// $order = $orders->where('domain', $domain1check)->orWhere('domain', $url1)->orWhere('domain', $domain2)->orWhere('domain', $url2)->first();
// if ($order) {
// $product = Product::where('id', $order->product)->pluck('name')->first();
// $result = 'success';
// }

return response()->json(compact('result'));
} catch (Exception $ex) {
Expand Down
61 changes: 42 additions & 19 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,6 @@ public function checkVerify($user)
return $check;
}

public function accountManager()
{
$manager = '';
$users = new User();
$account_count = $users->select(\DB::raw("count('manager') as count"), 'manager')
->whereNotNull('manager')
->groupBy('manager')
->pluck('count', 'manager')
->toArray();
if ($account_count) {
$manager = array_keys($account_count, min($account_count))[0];
}

return $manager;
}

public function getState(Request $request, $state)
{
try {
Expand All @@ -356,7 +340,7 @@ public function getState(Request $request, $state)
}
}

public function accountManagerMail($user)
public function salesManagerMail($user, $bcc = [])
{
$manager = $user->manager()

Expand All @@ -371,7 +355,44 @@ public function accountManagerMail($user)
$templates = new \App\Model\Common\Template();
$template = $templates
->join('template_types', 'templates.type', '=', 'template_types.id')
->where('template_types.name', '=', 'manager_email')
->where('template_types.name', '=', 'sales_manager_email')
->select('templates.data', 'templates.name')
->first();
$template_data = $template->data;
$template_name = $template->name;
$template_controller = new \App\Http\Controllers\Common\TemplateController();
$replace = [
'name' => $user->first_name.' '.$user->last_name,
'manager_first_name' => $manager->first_name,
'manager_last_name' => $manager->last_name,
'manager_email' => $manager->email,
'manager_code' => $manager->mobile_code,
'manager_mobile' => $manager->mobile,
'manager_skype' => $manager->skype,
];
$job = new \App\Jobs\SendEmail($from, $to, $template_data, $template_name, $replace, 'sales_manager_email', $bcc);
dispatch($job);
//dd($from, $to, $template_data, $template_name, $replace);
// $template_controller->mailing($from, $to, $template_data, $template_name, $replace, 'sales_manager_email');
}
}

public function accountManagerMail($user, $bcc = [])
{
$manager = $user->accountManager()

->where('position', 'account_manager')
->select('first_name', 'last_name', 'email', 'mobile_code', 'mobile', 'skype')
->first();
if ($user && $user->role == 'user' && $manager) {
$settings = new \App\Model\Common\Setting();
$setting = $settings->first();
$from = $setting->email;
$to = $user->email;
$templates = new \App\Model\Common\Template();
$template = $templates
->join('template_types', 'templates.type', '=', 'template_types.id')
->where('template_types.name', '=', 'account_manager_email')
->select('templates.data', 'templates.name')
->first();
$template_data = $template->data;
Expand All @@ -386,8 +407,10 @@ public function accountManagerMail($user)
'manager_mobile' => $manager->mobile,
'manager_skype' => $manager->skype,
];
$job = new \App\Jobs\SendEmail($from, $to, $template_data, $template_name, $replace, 'account_manager_email', $bcc);
dispatch($job);
//dd($from, $to, $template_data, $template_name, $replace);
$template_controller->mailing($from, $to, $template_data, $template_name, $replace, 'manager_email');
// $template_controller->mailing($from, $to, $template_data, $template_name, $replace, 'account__manager_email',$bcc);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Common/BaseSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function getNewEntry($properties, $model)
? ($model->properties['attributes']) : null;

$display = [];

if ($properties != null) {
if (array_key_exists('parent', $properties)) {
unset($properties['parent']);
Expand Down Expand Up @@ -53,6 +52,7 @@ public function getOldEntry($data, $model)
$display[] = '<strong>'.'ucfirst'($key).'</strong>'.' : '.$value.'<br/>';
}
}

$old = (count($oldData) > 0) ? implode('', $display) : '--';

return $old;
Expand Down
162 changes: 162 additions & 0 deletions app/Http/Controllers/Common/SystemManagerController.php
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()];
}
}
}
11 changes: 8 additions & 3 deletions app/Http/Controllers/Common/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,16 @@ public function destroy(Request $request)
}

public function mailing($from, $to, $data, $subject, $replace = [],
$type = '', $fromname = '', $toname = '', $cc = [], $attach = [])
$type = '', $bcc = [], $fromname = '', $toname = '', $cc = [], $attach = [])
{
try {
$transform = [];
$page_controller = new \App\Http\Controllers\Front\PageController();
$transform[0] = $replace;
$data = $page_controller->transform($type, $data, $transform);

$settings = \App\Model\Common\Setting::find(1);
$fromname = $settings->company;
\Mail::send('emails.mail', ['data' => $data], function ($m) use ($from, $to, $subject, $fromname, $toname, $cc, $attach) {
\Mail::send('emails.mail', ['data' => $data], function ($m) use ($from, $to, $subject, $fromname, $toname, $cc, $attach, $bcc) {
$m->from($from, $fromname);

$m->to($to, $toname)->subject($subject);
Expand All @@ -290,6 +289,12 @@ public function mailing($from, $to, $data, $subject, $replace = [],
}
}

if (!empty($bcc)) {
foreach ($bcc as $address) {
$m->bcc($address);
}
}

/* if attachment is need */
if (!empty($attach)) {
foreach ($attach as $file) {
Expand Down
Loading

0 comments on commit a29d133

Please sign in to comment.