This commit is contained in:
Manish Verma
2016-12-13 18:18:25 +05:30
parent fc98add11c
commit 2d8e640e9b
2314 changed files with 97798 additions and 75664 deletions

View File

@@ -22,25 +22,23 @@ use View;
*
* @author Ladybird <info@ladybirdweb.com>
*/
class NotificationController extends Controller
{
public function __construct(PhpMailController $PhpMailController)
{
class NotificationController extends Controller {
public function __construct(PhpMailController $PhpMailController) {
$this->PhpMailController = $PhpMailController;
}
/**
* This function is for sending daily report/notification about the system.
* */
public function send_notification()
{
// dd('sdckjdsc');
public function send_notification() {
// dd('sdckjdsc');
//fetching email settings
$email = Email::where('id', '=', '1')->first();
//dd('yes');
$send = 0;
$date = [0];
// dd($date);
// dd($date);
// checking if the daily notification is enabled or not
if ($email->notification_cron == 1) {
// checking if current date is equal to the last entered daily notification log
@@ -48,22 +46,21 @@ class NotificationController extends Controller
if ($notification) {
$date = explode(' ', $notification->created_at);
}
// if (date('Y-m-d') !== $date[0]) {
// creating a daily notification log
// if (date('Y-m-d') !== $date[0]) {
// creating a daily notification log
$company = $this->company();
// Send notification details to admin
$send += $this->send_notification_to_admin($company);
// Send notification details to team lead
$send += $this->send_notification_to_team_lead($company);
// Send notification details to manager of a department
$send += $this->send_notification_to_manager($company);
// Send notification details to all the agents
$send += $this->send_notification_to_agent($company);
$company = $this->company();
// Send notification details to admin
$send += $this->send_notification_to_admin($company);
// Send notification details to team lead
$send += $this->send_notification_to_team_lead($company);
// Send notification details to manager of a department
$send += $this->send_notification_to_manager($company);
// Send notification details to all the agents
$send += $this->send_notification_to_agent($company);
//}
Log_notification::create(['log' => 'NOT-1']);
Log_notification::create(['log' => 'NOT-1']);
}
return $send;
}
@@ -74,31 +71,27 @@ class NotificationController extends Controller
*
* @return mail
* */
public function send_notification_to_admin($company)
{
public function send_notification_to_admin($company) {
// get all admin users
$users = User::where('role', '=', 'admin')->get();
foreach ($users as $user) {
// Send notification details to admin
$email = $user->email;
$user_name = $user->first_name.' '.$user->last_name;
$user_name = $user->first_name . ' ' . $user->last_name;
$view = View::make('emails.notifications.admin', ['company' => $company, 'name' => $user_name]);
$contents = $view->render();
$from = $this->PhpMailController->mailfrom('1', '0');
$to = [
'name' => $user_name,
'email' => $email,
'name' => $user_name,
'email' => $email
];
$message = [
'subject' => 'Daily Report',
'subject' => 'Daily Report',
'scenario' => null,
'body' => $contents,
'body' => $contents
];
$job = new \App\Jobs\SendEmail($from, $to, $message);
$dispatch = $this->dispatch($job);
return $dispatch;
//return $this->PhpMailController->sendEmail($from,$to,$message);
return $this->PhpMailController->sendEmail($from, $to, $message);
}
}
@@ -107,8 +100,7 @@ class NotificationController extends Controller
*
* @return mail
* */
public function send_notification_to_manager($company)
{
public function send_notification_to_manager($company) {
// get all department managers
$depts = Department::all();
foreach ($depts as $dept) {
@@ -118,22 +110,20 @@ class NotificationController extends Controller
foreach ($users as $user) {
// Send notification details to manager of a department
$email = $user->email;
$user_name = $user->first_name.' '.$user->last_name;
$user_name = $user->first_name . ' ' . $user->last_name;
$view = View::make('emails.notifications.manager', ['company' => $company, 'name' => $user_name]);
$contents = $view->render();
$from = $this->PhpMailController->mailfrom('1', '0');
$to = [
'name' => $user_name,
'email' => $email,
'name' => $user_name,
'email' => $email
];
$message = [
'subject' => 'Daily Report',
'subject' => 'Daily Report',
'scenario' => null,
'body' => $contents,
'body' => $contents
];
return $this->dispatch((new \App\Jobs\SendEmail($from, $to, $message)));
//$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
return $this->PhpMailController->sendEmail($from, $to, $message);
}
}
}
@@ -144,8 +134,7 @@ class NotificationController extends Controller
*
* @return mail
* */
public function send_notification_to_team_lead($company)
{
public function send_notification_to_team_lead($company) {
// get all Team leads
$teams = Teams::all();
foreach ($teams as $team) {
@@ -155,22 +144,20 @@ class NotificationController extends Controller
foreach ($users as $user) {
// Send notification details to team lead
$email = $user->email;
$user_name = $user->first_name.' '.$user->last_name;
$user_name = $user->first_name . ' ' . $user->last_name;
$view = View::make('emails.notifications.lead', ['company' => $company, 'name' => $user_name, 'team_id' => $team->id]);
$contents = $view->render();
$from = $this->PhpMailController->mailfrom('1', '0');
$to = [
'name' => $user_name,
'email' => $email,
'name' => $user_name,
'email' => $email
];
$message = [
'subject' => 'Daily Report',
'subject' => 'Daily Report',
'scenario' => null,
'body' => $contents,
'body' => $contents
];
return $this->dispatch((new \App\Jobs\SendEmail($from, $to, $message)));
//$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
return $this->PhpMailController->sendEmail($from, $to, $message);
}
}
}
@@ -181,29 +168,26 @@ class NotificationController extends Controller
*
* @return mail
* */
public function send_notification_to_agent($company)
{
public function send_notification_to_agent($company) {
// get all agents users
$users = User::where('role', '=', 'agent')->get();
foreach ($users as $user) {
// Send notification details to all the agents
$email = $user->email;
$user_name = $user->first_name.' '.$user->last_name;
$user_name = $user->first_name . ' ' . $user->last_name;
$view = View::make('emails.notifications.agent', ['company' => $company, 'name' => $user_name, 'user_id' => $user->id]);
$contents = $view->render();
$from = $this->PhpMailController->mailfrom('1', '0');
$to = [
'name' => $user_name,
'email' => $email,
];
'name' => $user_name,
'email' => $email
];
$message = [
'subject' => 'Daily Report',
'subject' => 'Daily Report',
'scenario' => null,
'body' => $contents,
];
return $this->dispatch((new \App\Jobs\SendEmail($from, $to, $message)));
//$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
'body' => $contents
];
return $this->PhpMailController->sendEmail($from,$to,$message);
}
}
@@ -212,8 +196,7 @@ class NotificationController extends Controller
*
* @return type variable
*/
public function company()
{
public function company() {
// fetching comapny model
$company = Company::Where('id', '=', '1')->first();
// fetching company name
@@ -225,4 +208,5 @@ class NotificationController extends Controller
return $company;
}
}