update 1.0.7

This commit is contained in:
Sujit Prasad
2016-04-19 19:19:42 +05:30
parent 723ef47e19
commit 5327b0c0da
153 changed files with 20711 additions and 1727 deletions

View File

@@ -35,9 +35,9 @@ class MailController extends Controller
*
* @param type TicketController $TicketController
*/
public function __construct(TicketController $TicketController)
public function __construct(TicketWorkflowController $TicketWorkflowController)
{
$this->TicketController = $TicketController;
$this->TicketWorkflowController = $TicketWorkflowController;
}
/**
@@ -76,6 +76,9 @@ class MailController extends Controller
$protocol_value = $e_mail->mailbox_protocol;
$get_mailboxprotocol = MailboxProtocol::where('id', '=', $protocol_value)->first();
$protocol = $get_mailboxprotocol->value;
} elseif ($e_mail->fetching_encryption == '/none') {
$fetching_encryption2 = '/novalidate-cert';
$protocol = $fetching_encryption2;
} else {
if ($e_mail->fetching_protocol) {
$fetching_protocol = '/'.$e_mail->fetching_protocol;
@@ -83,7 +86,7 @@ class MailController extends Controller
$fetching_protocol = '';
}
if ($e_mail->fetching_encryption) {
$fetching_encryption = '/'.$e_mail->fetching_encryption;
$fetching_encryption = $e_mail->fetching_encryption;
} else {
$fetching_encryption = '';
}
@@ -130,7 +133,9 @@ class MailController extends Controller
$assign = $get_helptopic->auto_assign;
$form_data = null;
$result = $this->TicketController->create_user($fromaddress, $fromname, $subject, $body, $phone, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $form_data, $auto_response);
$team_assign = null;
$ticket_status = null;
$result = $this->TicketWorkflowController->workflow($fromaddress, $fromname, $subject, $body, $phone, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response);
// dd($result);
if ($result[1] == true) {
$ticket_table = Tickets::where('ticket_number', '=', $result[0])->first();

View File

@@ -76,6 +76,10 @@ class NotificationController extends Controller
$view = View::make('emails.notifications.admin', ['company' => $company, 'name' => $user_name]);
$contents = $view->render();
$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
// \Mail::send('emails.notifications.admin', ['company' => $company, 'name' => $user_name], function ($message) use ($email, $user_name, $company) {
// $message->to($email, $user_name)->subject($company.' Daily Report ');
// });
}
}
@@ -99,6 +103,10 @@ class NotificationController extends Controller
$view = View::make('emails.notifications.manager', ['company' => $company, 'name' => $user_name]);
$contents = $view->render();
$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
// \Mail::send('emails.notifications.manager', ['company' => $company, 'name' => $user_name, 'dept_id' => $dept->id, 'dept_name' => $dept->name], function ($message) use ($email, $user_name, $company, $dept_name) {
// $message->to($email, $user_name)->subject($company.' Daily Report for department manager of '.$dept_name.' department.');
// });
}
}
}
@@ -124,6 +132,10 @@ class NotificationController extends Controller
$view = View::make('emails.notifications.lead', ['company' => $company, 'name' => $user_name]);
$contents = $view->render();
$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
// \Mail::send('emails.notifications.lead', ['company' => $company, 'name' => $user_name, 'team_id' => $team->id], function ($message) use ($email, $user_name, $company, $team_name) {
// $message->to($email, $user_name)->subject($company.' Daily Report for Team Lead of team '.$team_name);
// });
}
}
}
@@ -145,6 +157,10 @@ class NotificationController extends Controller
$view = View::make('emails.notifications.agent', ['company' => $company, 'name' => $user_name, 'user_id' => $user->id]);
$contents = $view->render();
$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
// \Mail::send('emails.notifications.agent', ['company' => $company, 'name' => $user_name, 'user_id' => 1], function ($message) use ($email, $user_name, $company) {
// $message->to($email, $user_name)->subject($company.' Daily Report for Agents');
// });
}
}
@@ -166,4 +182,13 @@ class NotificationController extends Controller
return $company;
}
// // testing
// public function test(){
// $email = "sujit.prasad@ladybirdweb.com";
// $user_name = "sujit prasad";
// \Mail::send('emails.notifications.test', ['user_id' => 1], function ($message) use($email, $user_name) {
// $message->to($email, $user_name)->subject('testing reporting');
// });
// }
}

View File

@@ -8,18 +8,11 @@ use App\Http\Controllers\Controller;
// requests
// models
use App\Model\helpdesk\Agent\Department;
use App\Model\helpdesk\Ticket\Ticket_attachments;
use App\Model\helpdesk\Ticket\Ticket_Collaborator;
use App\Model\helpdesk\Ticket\Ticket_Priority;
use App\Model\helpdesk\Ticket\Ticket_Thread;
use App\Model\helpdesk\Ticket\Tickets;
use App\User;
use Auth;
use DB;
// classes
use Illuminate\support\Collection;
use Input;
use UTC;
use Ttable;
/**
* TicketController2.
@@ -67,89 +60,7 @@ class Ticket2Controller extends Controller
$tickets = Tickets::where('status', '=', 1)->where('isanswered', '=', 0)->where('dept_id', '=', $dept->id)->get();
}
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
if (isset($subject->title)) {
$string = $subject->title;
if (strlen($string) > 20) {
$stringCut = substr($string, 0, 30);
$string = substr($stringCut, 0, strrpos($stringCut, ' ')).' ...';
}
} else {
$string = '(no subject)';
}
//collabrations
$collaborators = DB::table('ticket_collaborator')->where('ticket_id', '=', $ticket->id)->get();
$collab = count($collaborators);
if ($collab > 0) {
$collabString = '&nbsp;<i class="fa fa-users"></i>';
} else {
$collabString = null;
}
$threads = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first(); //
$count = Ticket_Thread::where('ticket_id', '=', $ticket->id)->count(); //
$attachment = Ticket_attachments::where('thread_id', '=', $threads->id)->get();
$attachCount = count($attachment);
if ($attachCount > 0) {
$attachString = '&nbsp;<i class="fa fa-paperclip"></i>';
} else {
$attachString = '';
}
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$subject->title."'>".$string."&nbsp;<span style='color:green'>(".$count.")<i class='fa fa-comment'></i></span></a>".$collabString.$attachString;
})
->addColumn('ticket_number', function ($ticket) {
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$ticket->ticket_number."'>#".$ticket->ticket_number.'</a>';
})
->addColumn('priority', function ($ticket) {
$priority = DB::table('ticket_priority')->select('priority_desc', 'priority_color')->where('priority_id', '=', $ticket->priority_id)->first();
return '<span class="btn btn-'.$priority->priority_color.' btn-xs">'.$priority->priority_desc.'</span>';
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
return "<span style='color:#508983'>".$from->user_name.'</span>';
})
->addColumn('Last Replier', function ($ticket) {
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->where('is_internal', '=', 0)->max('id');
$TicketDatarow = Ticket_Thread::where('id', '=', $TicketData)->first();
$LastResponse = User::where('id', '=', $TicketDatarow->user_id)->first();
if ($LastResponse->role == 'user') {
$rep = '#F39C12';
$username = $LastResponse->user_name;
} else {
$rep = '#000';
$username = $LastResponse->first_name.' '.$LastResponse->last_name;
if ($LastResponse->first_name == null || $LastResponse->last_name == null) {
$username = $LastResponse->user_name;
}
}
return "<span style='color:".$rep."'>".$username.'</span>';
})
->addColumn('assigned_to', function ($ticket) {
if ($ticket->assigned_to == null) {
return "<span style='color:red'>Unassigned</span>";
} else {
$assign = DB::table('users')->where('id', '=', $ticket->assigned_to)->first();
return "<span style='color:green'>".$assign->first_name.' '.$assign->last_name.'</span>';
}
})
->addColumn('Last', function ($ticket) {
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
return UTC::usertimezone($TicketDatarow->updated_at);
})
->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')
->orderColumns('subject', 'from', 'assigned_to', 'Last Replier', 'ticket_number', 'priority', 'Last')
->make();
return Ttable::getTable($tickets);
}
/**
@@ -180,89 +91,7 @@ class Ticket2Controller extends Controller
$tickets = Tickets::where('status', '=', '2')->where('dept_id', '=', $dept->id)->get();
}
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
if (isset($subject->title)) {
$string = $subject->title;
if (strlen($string) > 20) {
$stringCut = substr($string, 0, 30);
$string = substr($stringCut, 0, strrpos($stringCut, ' ')).' ...';
}
} else {
$string = '(no subject)';
}
//collabrations
$collaborators = DB::table('ticket_collaborator')->where('ticket_id', '=', $ticket->id)->get();
$collab = count($collaborators);
if ($collab > 0) {
$collabString = '&nbsp;<i class="fa fa-users"></i>';
} else {
$collabString = null;
}
$threads = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first();
$count = Ticket_Thread::where('ticket_id', '=', $ticket->id)->count();
$attachment = Ticket_attachments::where('thread_id', '=', $threads->id)->get();
$attachCount = count($attachment);
if ($attachCount > 0) {
$attachString = '&nbsp;<i class="fa fa-paperclip"></i>';
} else {
$attachString = '';
}
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$subject->title."'>".$string."&nbsp;<span style='color:green'>(".$count.")<i class='fa fa-comment'></i></span></a>".$collabString.$attachString;
})
->addColumn('ticket_number', function ($ticket) {
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$ticket->ticket_number."'>#".$ticket->ticket_number.'</a>';
})
->addColumn('priority', function ($ticket) {
$priority = DB::table('ticket_priority')->select('priority_desc', 'priority_color')->where('priority_id', '=', $ticket->priority_id)->first();
return '<span class="btn btn-'.$priority->priority_color.' btn-xs">'.$priority->priority_desc.'</span>';
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
return "<span style='color:#508983'>".$from->user_name.'</span>';
})
->addColumn('Last Replier', function ($ticket) {
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->where('is_internal', '!=', 1)->max('id');
$TicketDatarow = Ticket_Thread::where('id', '=', $TicketData)->first();
$LastResponse = User::where('id', '=', $TicketDatarow->user_id)->first();
if ($LastResponse->role == 'user') {
$rep = '#F39C12';
$username = $LastResponse->user_name;
} else {
$rep = '#000';
$username = $LastResponse->first_name.' '.$LastResponse->last_name;
if ($LastResponse->first_name == null || $LastResponse->last_name == null) {
$username = $LastResponse->user_name;
}
}
return "<span style='color:".$rep."'>".$username.'</span>';
})
->addColumn('assigned_to', function ($ticket) {
if ($ticket->assigned_to == null) {
return "<span style='color:red'>Usernassigned</span>";
} else {
$assign = DB::table('users')->where('id', '=', $ticket->assigned_to)->first();
return "<span style='color:green'>".$assign->first_name.' '.$assign->last_name.'</span>';
}
})
->addColumn('Last', function ($ticket) {
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
return UTC::usertimezone($TicketDatarow->updated_at);
})
->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')
->orderColumns('subject', 'from', 'assigned_to', 'Last Replier', 'ticket_number', 'priority', 'Last')
->make();
return Ttable::getTable($tickets);
}
/**
@@ -298,88 +127,6 @@ class Ticket2Controller extends Controller
$tickets = Tickets::where('status', '=', '1')->where('assigned_to', '>', 0)->where('dept_id', '=', $dept->id)->get();
}
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
if (isset($subject->title)) {
$string = $subject->title;
if (strlen($string) > 20) {
$stringCut = substr($string, 0, 30);
$string = substr($stringCut, 0, strrpos($stringCut, ' ')).' ...';
}
} else {
$string = '(no subject)';
}
//collabrations
$collaborators = DB::table('ticket_collaborator')->where('ticket_id', '=', $ticket->id)->get();
$collab = count($collaborators);
if ($collab > 0) {
$collabString = '&nbsp;<i class="fa fa-users"></i>';
} else {
$collabString = null;
}
$threads = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first();
$count = Ticket_Thread::where('ticket_id', '=', $ticket->id)->count();
$attachment = Ticket_attachments::where('thread_id', '=', $threads->id)->get();
$attachCount = count($attachment);
if ($attachCount > 0) {
$attachString = '&nbsp;<i class="fa fa-paperclip"></i>';
} else {
$attachString = '';
}
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$subject->title."'>".$string."&nbsp;<span style='color:green'>(".$count.")<i class='fa fa-comment'></i></span></a>".$collabString.$attachString;
})
->addColumn('ticket_number', function ($ticket) {
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$ticket->ticket_number."'>#".$ticket->ticket_number.'</a>';
})
->addColumn('priority', function ($ticket) {
$priority = DB::table('ticket_priority')->select('priority_desc', 'priority_color')->where('priority_id', '=', $ticket->priority_id)->first();
return '<span class="btn btn-'.$priority->priority_color.' btn-xs">'.$priority->priority_desc.'</span>';
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
return "<span style='color:#508983'>".$from->user_name.'</span>';
})
->addColumn('Last Replier', function ($ticket) {
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->where('is_internal', '!=', 1)->max('id');
$TicketDatarow = Ticket_Thread::where('id', '=', $TicketData)->first();
$LastResponse = User::where('id', '=', $TicketDatarow->user_id)->first();
if ($LastResponse->role == 'user') {
$rep = '#F39C12';
$username = $LastResponse->user_name;
} else {
$rep = '#000';
$username = $LastResponse->first_name.' '.$LastResponse->last_name;
if ($LastResponse->first_name == null || $LastResponse->last_name == null) {
$username = $LastResponse->user_name;
}
}
return "<span style='color:".$rep."'>".$username.'</span>';
})
->addColumn('assigned_to', function ($ticket) {
if ($ticket->assigned_to == null) {
return "<span style='color:red'>Usernassigned</span>";
} else {
$assign = DB::table('users')->where('id', '=', $ticket->assigned_to)->first();
return "<span style='color:green'>".$assign->first_name.' '.$assign->last_name.'</span>';
}
})
->addColumn('Last', function ($ticket) {
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
return UTC::usertimezone($TicketDatarow->updated_at);
})
->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')
->orderColumns('subject', 'from', 'assigned_to', 'Last Replier', 'ticket_number', 'priority', 'Last')
->make();
return Ttable::getTable($tickets);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,510 @@
<?php
namespace App\Http\Controllers\Agent\helpdesk;
// controllers
use App\Http\Controllers\Controller;
// models
use App\Model\helpdesk\Agent\Department;
use App\Model\helpdesk\Agent\Teams;
use App\Model\helpdesk\Email\Emails;
use App\Model\helpdesk\Manage\Help_topic;
use App\Model\helpdesk\Manage\Sla_plan;
use App\Model\helpdesk\Ticket\Ticket_Priority;
use App\Model\helpdesk\Ticket\Ticket_Status;
use App\Model\helpdesk\Workflow\WorkflowAction;
use App\Model\helpdesk\Workflow\WorkflowName;
use App\Model\helpdesk\Workflow\WorkflowRules;
use App\User;
/**
* TicketWorkflowController.
*
* @author Ladybird <info@ladybirdweb.com>
*/
class TicketWorkflowController extends Controller
{
/**
* constructor
* Create a new controller instance.
*
* @param type TicketController $TicketController
*/
public function __construct(TicketController $TicketController)
{
$this->TicketController = $TicketController;
}
/**
* This is the core function from where the workflow is applied.
*
* @return type response
*/
public function workflow($fromaddress, $fromname, $subject, $body, $phone, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response)
{
$contact_details = ['email' => $fromaddress, 'email_name' => $fromname, 'subject' => $subject, 'message' => $body];
$ticket_settings_details = ['help_topic' => $helptopic, 'sla' => $sla, 'priority' => $priority, 'source' => $source, 'dept' => $dept, 'assign' => $assign, 'team' => $team_assign, 'status' => $ticket_status, 'reject' => false];
// get all the workflow common to the entire system which includes any type of ticket creation where the execution order of the workflow should be starting with ascending order
$workflows = WorkflowName::where('target', '=', 'A-0')->where('status', '=', '1')->orderBy('order', 'asc')->get();
foreach ($workflows as $workflow) {
// checking if any workflow defined in the system
if ($workflow) {
// get all the rules of workflow which has a foreign key of those workflow which are applied to creating any ticket from any source
$worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflow->id)->get();
foreach ($worklfow_rules as $worklfow_rule) {
// checking for the workflow rules to which workflow rule type it is
if ($worklfow_rule->matching_scenario == 'email') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'email_name') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'subject') {
if ($rule_condition = $this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'message') {
if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
}
}
}
}
}
if ($source == 1) {
// get all the workflow which are applied to ticket generated via webforms and in ascending order
$workflows_webs = WorkflowName::where('target', '=', 'A-1')->where('status', '=', '1')->orderBy('order', 'asc')->get();
foreach ($workflows_webs as $workflows_web) {
if ($workflows_web) {
$worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflows_web->id)->get();
foreach ($worklfow_rules as $worklfow_rule) {
if ($worklfow_rule) {
// checking for the workflow rules to which workflow rule type it is
if ($worklfow_rule->matching_scenario == 'email') {
if ($this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'email_name') {
if ($this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'subject') {
if ($this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'message') {
if ($this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
}
}
}
}
}
}
}
if ($source == 2) {
// get all the workflow which are applied to ticket generated via emails and in ascending order
$workflows_emails = WorkflowName::where('target', '=', 'A-2')->where('status', '=', '1')->orderBy('order', 'asc')->get();
foreach ($workflows_emails as $workflows_email) {
if ($workflows_email) {
$worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflows_email->id)->get();
foreach ($worklfow_rules as $worklfow_rule) {
if ($worklfow_rule) {
// checking for the workflow rules to which workflow rule type it is
if ($worklfow_rule->matching_scenario == 'email') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'email_name') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'subject') {
if ($rule_condition = $this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'message') {
if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
}
}
}
}
}
}
}
if ($source == 4) {
// get all the workflow which are applied to ticket generated via API and in ascending order
$workflows_apis = WorkflowName::where('target', '=', 'A-4')->where('status', '=', '1')->orderBy('order', 'asc')->get();
foreach ($workflows_apis as $workflows_api) {
if ($workflows_api) {
$worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflows_api->id)->get();
foreach ($worklfow_rules as $worklfow_rule) {
if ($worklfow_rule) {
// checking for the workflow rules to which workflow rule type it is
if ($worklfow_rule->matching_scenario == 'email') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'email_name') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'subject') {
if ($rule_condition = $this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
}
} elseif ($worklfow_rule->matching_scenario == 'message') {
if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
}
}
}
}
}
}
}
if ($ticket_settings_details['reject'] == true) {
return ['0' => false, '1' => false];
} else {
$create_ticket = $this->TicketController->create_user($contact_details['email'], $contact_details['email_name'], $contact_details['subject'], $contact_details['message'], $phone, $ticket_settings_details['help_topic'], $ticket_settings_details['sla'], $ticket_settings_details['priority'], $source, $collaborator, $ticket_settings_details['dept'], $ticket_settings_details['assign'], $form_data, $auto_response, $ticket_settings_details['status']);
return $create_ticket;
}
}
/**
* function to check the rules applied to the ticket workflow.
*
* @param type $to_check
* @param type $condition
* @param type $statement
*
* @return type boolean
*/
public function checkRuleCondition($to_check, $condition, $statement)
{
if ($condition == 'equal') {
$return = $this->checkEqual($statement, $to_check);
} elseif ($condition == 'not_equal') {
$return = $this->checkNotEqual($statement, $to_check);
} elseif ($condition == 'contains') {
$return = $this->checkContains($statement, $to_check);
} elseif ($condition == 'dn_contain') {
$return = $this->checkDoNotContain($statement, $to_check);
} elseif ($condition == 'starts') {
$return = $this->checkStarts($statement, $to_check);
} elseif ($condition == 'ends') {
$return = $this->checkEnds($statement, $to_check);
}
// elseif($condition == 'match') {
//
// } elseif($condition == 'not_match') {
//
// }
return $return;
}
/**
* function to check if the equal functions are applied.
*
* @param type $statement
* @param type $to_check
*
* @return bool
*/
public function checkEqual($statement, $to_check)
{
if ($statement == $to_check) {
return true;
} else {
return false;
}
}
/**
* function to check if the not-equal functions are applied.
*
* @param type $statement
* @param type $to_check
*
* @return bool
*/
public function checkNotEqual($statement, $to_check)
{
if ($statement != $to_check) {
return true;
} else {
return false;
}
}
/**
* function to check if the contains functions are applied.
*
* @param type $statement
* @param type $to_check
*
* @return bool
*/
public function checkContains($statement, $to_check)
{
if (strpos($to_check, $statement) !== false) {
return true;
} else {
return false;
}
}
/**
* function to check if the do not contain functions are applied.
*
* @param type $statement
* @param type $to_check
*
* @return bool
*/
public function checkDoNotContain($statement, $to_check)
{
if (strpos($to_check, $statement) == false) {
return true;
} else {
return false;
}
}
/**
* function to check if the start functions are applied.
*
* @param type $statement
* @param type $to_check
*
* @return bool
*/
public function checkStarts($statement, $to_check)
{
if (substr($to_check, 0, strlen($statement)) == $statement) {
return true;
} else {
return false;
}
}
/**
* function to check if the ends functions are applied.
*
* @param type $statement
* @param type $to_check
*
* @return bool
*/
public function checkEnds($statement, $to_check)
{
$to_check = strip_tags($to_check);
if (substr($to_check, -strlen($statement)) == $statement) {
return true;
} else {
return false;
}
}
// function startsWith($to_check, $statement) {
// // search backwards starting from haystack length characters from the end
// return $statement === "" || strrpos($to_check, $statement, -strlen($to_check)) !== false;
// }
// function endsWith($to_check, $statement) {
// // search forward starting from end minus needle length characters
// return $statement === "" || (($temp = strlen($to_check) - strlen($statement)) >= 0 && strpos($to_check, $statement, $temp) !== false);
// }
/**
* function to apply the action to a ticket.
*
* @param type $workflow_id
* @param type $ticket_settings_details
*
* @return type array
*/
public function applyActionCondition($workflow_id, $ticket_settings_details)
{
$workflow_actions = WorkflowAction::where('workflow_id', '=', $workflow_id)->get();
foreach ($workflow_actions as $workflow_action) {
if ($workflow_action->condition == 'reject') {
$ticket_settings_details = $this->rejectTicket($ticket_settings_details);
} elseif ($workflow_action->condition == 'department') {
$ticket_settings_details = $this->changeDepartment($workflow_action, $ticket_settings_details);
} elseif ($workflow_action->condition == 'priority') {
$ticket_settings_details = $this->changePriority($workflow_action, $ticket_settings_details);
} elseif ($workflow_action->condition == 'sla') {
$ticket_settings_details = $this->changeSla($workflow_action, $ticket_settings_details);
} elseif ($workflow_action->condition == 'team') {
$ticket_settings_details = $this->changeTeam($workflow_action, $ticket_settings_details);
} elseif ($workflow_action->condition == 'agent') {
$ticket_settings_details = $this->changeAgent($workflow_action, $ticket_settings_details);
} elseif ($workflow_action->condition == 'helptopic') {
$ticket_settings_details = $this->changeHelptopic($workflow_action, $ticket_settings_details);
} elseif ($workflow_action->condition == 'status') {
$ticket_settings_details = $this->changeStatus($workflow_action, $ticket_settings_details);
}
}
return $ticket_settings_details;
}
/**
* function to reject ticket.
*
* @param array $ticket_settings_details
*
* @return type array
*/
public function rejectTicket($ticket_settings_details)
{
$ticket_settings_details['reject'] = true;
return $ticket_settings_details;
}
/**
* function to change the department of a ticket.
*
* @param type $workflow_action
* @param type $ticket_settings_details
*
* @return type array
*/
public function changeDepartment($workflow_action, $ticket_settings_details)
{
$dept = Department::where('id', '=', $workflow_action->action)->first();
if ($dept == null) {
return $ticket_settings_details;
} else {
$ticket_settings_details['dept'] = $dept->id;
return $ticket_settings_details;
}
}
/**
* function to change the priority of a ticket.
*
* @param type $workflow_action
* @param type $ticket_settings_details
*
* @return type array
*/
public function changePriority($workflow_action, $ticket_settings_details)
{
$priority = Ticket_Priority::where('priority_id', '=', $workflow_action->action)->first();
if ($priority == null) {
return $ticket_settings_details;
} else {
$ticket_settings_details['priority'] = $priority->priority_id;
return $ticket_settings_details;
}
}
/**
* function to change the SLA of a ticket.
*
* @param type $workflow_action
* @param type $ticket_settings_details
*
* @return type array
*/
public function changeSla($workflow_action, $ticket_settings_details)
{
$sla_plan = Sla_plan::where('id', '=', $workflow_action->action)->first();
if ($sla_plan == null) {
return $ticket_settings_details;
} else {
$ticket_settings_details['sla'] = $sla_plan->id;
return $ticket_settings_details;
}
}
/**
* function to assign tean to a ticket.
*
* @param type $workflow_action
* @param type $ticket_settings_details
*
* @return type array
*/
public function changeTeam($workflow_action, $ticket_settings_details)
{
$team = Teams::where('id', '=', $workflow_action->action)->first();
if ($team == null) {
return $ticket_settings_details;
} else {
$ticket_settings_details['team'] = $team->id;
return $ticket_settings_details;
}
}
/**
* function to assing a ticket to an agent.
*
* @param type $workflow_action
* @param type $ticket_settings_details
*
* @return type array
*/
public function changeAgent($workflow_action, $ticket_settings_details)
{
$agent = User::where('id', '=', $workflow_action->action)->where('role', '!=', 'user')->first();
if ($agent == null) {
return $ticket_settings_details;
} else {
$ticket_settings_details['assign'] = $agent->id;
return $ticket_settings_details;
}
}
/**
* function to change the helptopic of a ticket.
*
* @param type $workflow_action
* @param type $ticket_settings_details
*
* @return type array
*/
public function changeHelptopic($workflow_action, $ticket_settings_details)
{
$help_topic = Help_topic::where('id', '=', $workflow_action->action)->first();
if ($help_topic == null) {
return $ticket_settings_details;
} else {
$ticket_settings_details['help_topic'] = $help_topic->id;
return $ticket_settings_details;
}
}
/**
* function to change the status of a ticket.
*
* @param type $workflow_action
* @param type $ticket_settings_details
*
* @return type array
*/
public function changeStatus($workflow_action, $ticket_settings_details)
{
$status = Ticket_Status::where('id', '=', $workflow_action->action)->first();
if ($status == null) {
return $ticket_settings_details;
} else {
$ticket_settings_details['status'] = $status->id;
return $ticket_settings_details;
}
}
}

View File

@@ -2,7 +2,8 @@
namespace App\Http\Controllers\Agent\kb;
// Controllersuse App\Http\Controllers\Agent\helpdesk\TicketController;
// Controllers
use App\Http\Controllers\Agent\helpdesk\TicketController;
use App\Http\Controllers\Controller;
// Request
use App\Http\Requests\kb\ProfilePassword;