ManagementSystem/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php

106 lines
3.7 KiB
PHP

<?php
namespace Modules\Admin\app\Http\Controllers;
use App\Helper\Cache\CurrentMonthTimekeeping;
use App\Http\Controllers\Controller;
use App\Models\Notes;
use App\Traits\AnalyzeData;
use App\Traits\HasFilterRequest;
use App\Traits\HasOrderByRequest;
use App\Traits\HasSearchRequest;
use Carbon\Carbon;
use Carbon\CarbonPeriod;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class TicketController extends Controller
{
use HasOrderByRequest;
use HasFilterRequest;
use HasSearchRequest;
use AnalyzeData;
public function get(Request $request)
{
// Get data tickets and user -> pagination, orderby 'desc', filter: fromDate, toDate, status, type, name
}
public function createTicket(Request $request){
//Get data from request
$startDate = $request->input('start_date'); //Start day
$startPeriod = $request->input('start_period'); //The session begins
$endDate = $request->input('end_date'); //End date
$endPeriod = $request->input('end_period'); //Session ends
$user_id = $request->input('user_id'); // ID user create ticket
$results = $this->getAllPeriod($startDate, $startPeriod, $endDate, $endPeriod);
}
public function deleteTicket(Request $request){
$user = auth('admins')->user();
$ticket_id = $request->input('ticket_id');
// $user->id == user_id of ticket ---> delete
// else false
}
public function handleTicket(Request $request){
$ticket_id = $request->input('ticket_id');
$admin_note = $request->input('admin_note');
$action = $request->input('action'); // 'confirm' or 'refuse'
$admin = auth('admins')->user();
// $admin->id != user_id of ticket ---> continue
// Confirm
// Add records to the notes table like function Timekeeping.addNoteForUser() based on the $results array
// Update updated_by and admin_note in tickets table
// Send notification email to admin (list) and users
// Refuse
// Update updated_by and admin_note in tickets table
// Send notification email to admin (list) and users
// false
}
private function getAllPeriod($startDate, $startPeriod, $endDate, $endPeriod)
{
//Create an array to contain the results
$results = [];
//Use CarbonPeriod to create a period from the start date to the end date
$period = CarbonPeriod::create($startDate, $endDate);
foreach ($period as $date) {
//If it is the start date
if ($date->isSameDay($startDate)) {
//Add start session
$results[] = ['date' => $date->toDateString(), 'period' => $startPeriod];
//If the start date is morning, add afternoon
if ($startPeriod == 'morning') {
$results[] = ['date' => $date->toDateString(), 'period' => 'afternoon'];
}
} elseif ($date->isSameDay($endDate)) {
//If it is the end date
//If the end session is afternoon, add morning first
if ($endPeriod == 'afternoon') {
$results[] = ['date' => $date->toDateString(), 'period' => 'morning'];
}
$results[] = ['date' => $date->toDateString(), 'period' => $endPeriod];
} else {
//Add both sessions for days between intervals
$results[] = ['date' => $date->toDateString(), 'period' => 'morning'];
$results[] = ['date' => $date->toDateString(), 'period' => 'afternoon'];
}
}
//Returns results
return $results;
}
}