update structure for ticket function
This commit is contained in:
parent
a1b2246666
commit
f1e7af7bf4
|
|
@ -0,0 +1,105 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Modules\Admin\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use App\Traits\HasCacheModel;
|
||||
|
||||
class Ticket extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasCacheModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'tickets';
|
||||
$this->guarded = [];
|
||||
}
|
||||
}
|
||||
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tickets', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue