diff --git a/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php b/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php new file mode 100644 index 0000000..fa810c2 --- /dev/null +++ b/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php @@ -0,0 +1,105 @@ + 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; + } +} diff --git a/BACKEND/Modules/Admin/app/Http/Controllers/TimekeepingController.php b/BACKEND/Modules/Admin/app/Http/Controllers/TimekeepingController.php index 95445ef..f22f6cb 100644 --- a/BACKEND/Modules/Admin/app/Http/Controllers/TimekeepingController.php +++ b/BACKEND/Modules/Admin/app/Http/Controllers/TimekeepingController.php @@ -16,8 +16,6 @@ use Modules\Admin\app\Models\Admin; use Modules\Admin\app\Models\MonthlyTimekeeping; use Modules\Admin\app\Models\Tracking; -use function PHPSTORM_META\type; - class TimekeepingController extends Controller { use HasOrderByRequest; diff --git a/BACKEND/Modules/Admin/app/Models/Ticket.php b/BACKEND/Modules/Admin/app/Models/Ticket.php new file mode 100644 index 0000000..029bfe9 --- /dev/null +++ b/BACKEND/Modules/Admin/app/Models/Ticket.php @@ -0,0 +1,20 @@ +table = 'tickets'; + $this->guarded = []; + } +} diff --git a/BACKEND/Modules/Admin/routes/api.php b/BACKEND/Modules/Admin/routes/api.php index 1b32759..b0db66f 100755 --- a/BACKEND/Modules/Admin/routes/api.php +++ b/BACKEND/Modules/Admin/routes/api.php @@ -11,6 +11,7 @@ use Modules\Admin\app\Http\Controllers\CustomThemeController; use Modules\Admin\app\Http\Controllers\DashboardController; use Modules\Admin\app\Http\Controllers\JiraController; use Modules\Admin\app\Http\Controllers\SettingController; +use Modules\Admin\app\Http\Controllers\TicketController; use Modules\Admin\app\Http\Controllers\TimekeepingController; use Modules\Admin\app\Http\Controllers\TrackingController; use Modules\Admin\app\Http\Middleware\AdminMiddleware; @@ -126,6 +127,15 @@ Route::middleware('api') Route::get('/get-list-master', [CategoryController::class, 'getListMaster']); }); + + Route::group([ + 'prefix' => 'ticket', + ], function () { + Route::get('/', [TicketController::class, 'get']); + Route::post('/create', [TrackingController::class, 'createTicket'])->middleware('check.permission:admin.hr.staff'); + Route::get('/delete', [TrackingController::class, 'deleteTicket'])->middleware('check.permission:admin.hr.staff'); + Route::post('/handle-ticket', [TrackingController::class, 'handleTicket'])->middleware('check.permission:admin'); + }); }); }); diff --git a/BACKEND/database/migrations/2024_08_06_135632_create_tickets_table.php b/BACKEND/database/migrations/2024_08_06_135632_create_tickets_table.php new file mode 100644 index 0000000..8c23ae9 --- /dev/null +++ b/BACKEND/database/migrations/2024_08_06_135632_create_tickets_table.php @@ -0,0 +1,36 @@ +id(); + $table->integer('user_id'); + $table->timestamps('start_date'); + $table->string('start_period'); + $table->timestamps('end_date'); + $table->string('end_period'); + $table->string('type'); + $table->string('reason'); + $table->string('admin_note')->nullable(); + $table->string('updated_by'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('tickets'); + } +};