2024-06-26 12:28:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use App\Models\Ticket;
|
|
|
|
|
use App\Models\Comment;
|
|
|
|
|
use App\Models\Response;
|
2024-06-28 06:58:04 +00:00
|
|
|
use App\Models\Company;
|
2024-07-01 11:17:16 +00:00
|
|
|
use App\Models\CompanyMeta;
|
|
|
|
|
use App\Models\Tag;
|
2024-06-26 12:28:46 +00:00
|
|
|
use Carbon\Carbon;
|
2024-06-28 06:58:04 +00:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2024-07-01 11:17:16 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2024-06-26 12:28:46 +00:00
|
|
|
|
|
|
|
|
class TicketController extends Controller
|
|
|
|
|
{
|
2024-07-01 11:17:16 +00:00
|
|
|
public function get_canned_responses(){
|
|
|
|
|
$companyId = getSelectedCompany();;
|
|
|
|
|
return CompanyMeta::where('company_id', $companyId)->where('key', 'canned_responses')->get();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-26 12:28:46 +00:00
|
|
|
public function allTickets()
|
|
|
|
|
{
|
2024-06-28 06:58:04 +00:00
|
|
|
$tickets = get_current_company_tickets();
|
2024-06-26 12:28:46 +00:00
|
|
|
return view('all-tickets', ['tickets' => $tickets]);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 11:17:16 +00:00
|
|
|
public function waiting()
|
2024-06-26 12:28:46 +00:00
|
|
|
{
|
2024-07-01 11:17:16 +00:00
|
|
|
|
|
|
|
|
$tickets = get_current_company_tickets(['status' => 'waiting']);
|
|
|
|
|
return view('waiting', ['tickets' => $tickets]);
|
|
|
|
|
}
|
2024-06-26 12:28:46 +00:00
|
|
|
|
2024-07-01 11:17:16 +00:00
|
|
|
public function showTicket($id)
|
|
|
|
|
{
|
|
|
|
|
$tickets = get_current_company_tickets([
|
|
|
|
|
|
|
|
|
|
'type' => 'inbox',
|
|
|
|
|
'orderby' => 'id',
|
|
|
|
|
'order' => 'desc',
|
|
|
|
|
'with' => 'lastResponse'
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$single_ticket = Ticket::find($id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$messages = [];
|
|
|
|
|
$canned_response = $this->get_canned_responses();
|
2024-06-26 12:28:46 +00:00
|
|
|
|
2024-07-01 11:17:16 +00:00
|
|
|
return view('show-ticket', ['tickets' => $tickets, 'single_ticket' => $single_ticket, 'messages' => $messages, 'canned_response' => $canned_response]);
|
2024-06-26 12:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateStatus(Request $request, $ticketId)
|
|
|
|
|
{
|
|
|
|
|
$request->validate([
|
|
|
|
|
'status' => 'required|in:open,waiting,done',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$ticket = Ticket::find($ticketId);
|
|
|
|
|
$ticket->status = $request->status;
|
|
|
|
|
$ticket->save();
|
|
|
|
|
|
|
|
|
|
// Return a response if necessary
|
|
|
|
|
return response()->json(['message' => 'Ticket status updated successfully']);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 11:17:16 +00:00
|
|
|
public function updateTicket(Request $request, $ticketId)
|
2024-06-26 12:28:46 +00:00
|
|
|
{
|
2024-07-01 11:17:16 +00:00
|
|
|
$ticket = Ticket::find($ticketId);
|
|
|
|
|
//Update Ticket
|
|
|
|
|
if(isset($request->priority)) {
|
|
|
|
|
$ticket->priority = $request->priority;
|
|
|
|
|
}
|
|
|
|
|
if(isset($request->user_assigned)) {
|
|
|
|
|
$ticket->user_assigned = $request->user_assigned;
|
|
|
|
|
}
|
|
|
|
|
$ticket->save();
|
2024-06-26 12:28:46 +00:00
|
|
|
|
2024-07-01 11:17:16 +00:00
|
|
|
return response()->json(['success' => true, 'message' => 'Ticket Updated successfully!']);
|
2024-06-26 12:28:46 +00:00
|
|
|
}
|
2024-06-28 06:58:04 +00:00
|
|
|
|
2024-07-01 11:17:16 +00:00
|
|
|
public function storeTags(Request $request)
|
2024-06-28 06:58:04 +00:00
|
|
|
{
|
2024-07-01 11:17:16 +00:00
|
|
|
$company = getSelectedCompany();
|
|
|
|
|
$tags = json_decode($request->tags);
|
|
|
|
|
foreach($tags as $tag)
|
|
|
|
|
{
|
|
|
|
|
//Update Tags Table
|
|
|
|
|
Tag::updateOrCreate([
|
|
|
|
|
'company_id' => $company,
|
|
|
|
|
'name' => $tag->value
|
|
|
|
|
],[
|
|
|
|
|
'company_id' => $company,
|
|
|
|
|
'name' => $tag->value,
|
|
|
|
|
'type' => 'inbox'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
//Update Company Meta Table
|
|
|
|
|
CompanyMeta::updateOrCreate([
|
|
|
|
|
'company_id' => $company,
|
|
|
|
|
'value' => $tag->value
|
|
|
|
|
],[
|
|
|
|
|
'company_id' => $company,
|
|
|
|
|
'value' => $tag->value,
|
|
|
|
|
'key' => 'tag',
|
|
|
|
|
'type' => 'tags'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json(['success' => true, 'message' => 'Tags Added Successfully']);
|
2024-06-28 06:58:04 +00:00
|
|
|
}
|
2024-06-26 12:28:46 +00:00
|
|
|
}
|