Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jovitamaharani committed Jul 15, 2024
2 parents 7891ee4 + 737e1b9 commit 727d077
Show file tree
Hide file tree
Showing 28 changed files with 1,211 additions and 864 deletions.
3 changes: 2 additions & 1 deletion app/Contracts/Interfaces/AttendanceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use App\Contracts\Interfaces\Eloquent\ShowInterface;
use App\Contracts\Interfaces\Eloquent\StoreInterface;
use App\Contracts\Interfaces\Eloquent\UpdateInterface;
use App\Contracts\Interfaces\Eloquent\WhereSchoolInterface;

interface AttendanceInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, PaginateInterface
interface AttendanceInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, PaginateInterface, WhereSchoolInterface
{
//
}
9 changes: 7 additions & 2 deletions app/Contracts/Repositories/AttendanceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function show(mixed $id): mixed
{
return $this->model->query()->findOrFail($id);
}

public function update(mixed $id, array $data): mixed
{
return $this->model->query()->findOrFail($id)->update($data);
Expand All @@ -41,4 +41,9 @@ public function paginate() : mixed
{
return $this->model->query()->latest()->paginate(10);
}
}

public function whereSchool(mixed $id): mixed
{
return $this->model->query()->whereRelation('classroomStudent.classroom.schoolYear.school', 'id', $id)->latest()->paginate(10);
}
}
2 changes: 1 addition & 1 deletion app/Contracts/Repositories/AttendanceRuleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function get(): mixed

public function store(array $data): mixed
{
return $this->model->query()->updateOrCreate(['school_id' => auth()->user()->school->id, 'day' => $data['day']], $data);
return $this->model->query()->updateOrCreate(['day' => $data['day'], 'role' => $data['role']], $data);
}

public function show(mixed $id): mixed
Expand Down
10 changes: 9 additions & 1 deletion app/Http/Controllers/AttendanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@

namespace App\Http\Controllers;

use App\Contracts\Interfaces\AttendanceInterface;
use App\Models\Attendance;
use App\Http\Requests\StoreAttendanceRequest;
use App\Http\Requests\UpdateAttendanceRequest;

class AttendanceController extends Controller
{
private AttendanceInterface $attendance;

public function __construct(AttendanceInterface $attendance)
{
$this->attendance = $attendance;
}
/**
* Display a listing of the resource.
*/
public function index()
{
//
$attendances = $this->attendance->whereSchool(auth()->user()->school->id);
return view('school.pages.attendace.presence', compact('attendances'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/LessonHourController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(LessonHourInterface $lessonHour, LessonHourService $
public function index()
{
$lessonHours = $this->lessonHour->get();
return view('', compact('lessonHours'));
return view('school.pages.subjects.lesson-hours', compact('lessonHours'));
}

/**
Expand Down
20 changes: 15 additions & 5 deletions app/Http/Requests/StoreAttendanceRuleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@ public function authorize(): bool
*/
public function rules(): array
{
return [
'checkin_start' => 'required',
'checkin_end' => 'required',
'checkout_start' => 'required',
'checkout_end' => 'required',
$rules = [
'is_holiday' => 'nullable'
];

if ($this->has('is_holiday')) {
$rules['checkin_start'] = 'nullable';
$rules['checkin_end'] = 'nullable';
$rules['checkout_start'] = 'nullable';
$rules['checkout_end'] = 'nullable';
} else {
$rules['checkin_start'] = 'required';
$rules['checkin_end'] = 'required';
$rules['checkout_start'] = 'required';
$rules['checkout_end'] = 'required';
}

return $rules;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions app/Http/Requests/StoreLessonHourRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ public function messages(): array
'end.required' => 'Mohon untuk masukan waktu selesai jam pelajaran.',
];
}

// public function withValidator($validator)
// {
// $validator->after(function ($validator) {
// if ($validator->fails()) {
// session()->flash('create_errors', true);
// }
// });
// }
}
20 changes: 15 additions & 5 deletions app/Http/Requests/UpdateLessonHourRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UpdateLessonHourRequest extends FormRequest
*/
public function authorize(): bool
{
return false;
return true;
}

/**
Expand All @@ -24,7 +24,7 @@ public function rules(): array
return [
'name' => 'required',
'start' => 'required',
'end' => 'required'
'end' => 'required|after:start'
];
}

Expand All @@ -36,9 +36,19 @@ public function rules(): array
public function messages(): array
{
return [
'name.required' => 'Mohon untuk masukan nama jam pelajaran.',
'start.required' => 'Mohon untuk masukan waktu mulai jam pelajaran.',
'end.required' => 'Mohon untuk masukan waktu selesai jam pelajaran.',
'name.required' => 'Nama jam pelajaran harus diisi.',
'start.required' => 'Waktu mulai jam pelajaran harus diisi.',
'end.required' => 'Waktu selesai jam pelajaran harus diisi.',
'end.after' => 'Waktu selesai harus setelah waktu mulai.',
];
}

// public function withValidator($validator)
// {
// $validator->after(function ($validator) {
// if ($validator->fails()) {
// session()->flash('edit_errors', true);
// }
// });
// }
}
3 changes: 3 additions & 0 deletions app/Models/Attendance.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ class Attendance extends Model
'classroom_student_id',
'point',
'status',
'proof',
'checkin',
'checkout'
];
}
2 changes: 1 addition & 1 deletion app/Models/Employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Employee extends Model
'nip',
'birth_date',
'birth_place',
'genre',
'gender',
'nik',
'phone_number',
'address',
Expand Down
48 changes: 48 additions & 0 deletions app/Observers/LessonHourObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Observers;

use App\Models\LessonHour;

class LessonHourObserver
{
/**
* Handle the LessonHour "created" event.
*/
public function creating(LessonHour $lessonHour): void
{
$lessonHour->name = "Jam ke " . $lessonHour->name;
}

/**
* Handle the LessonHour "updated" event.
*/
public function updating(LessonHour $lessonHour): void
{
$lessonHour->name = "Jam ke " . $lessonHour->name;
}

/**
* Handle the LessonHour "deleted" event.
*/
public function deleted(LessonHour $lessonHour): void
{
//
}

/**
* Handle the LessonHour "restored" event.
*/
public function restored(LessonHour $lessonHour): void
{
//
}

/**
* Handle the LessonHour "force deleted" event.
*/
public function forceDeleted(LessonHour $lessonHour): void
{
//
}
}
4 changes: 3 additions & 1 deletion app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Providers;

use App\Models\LessonHour;
use App\Observers\LessonHourObserver;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
Expand All @@ -25,7 +27,7 @@ class EventServiceProvider extends ServiceProvider
*/
public function boot(): void
{
//
LessonHour::observe(LessonHourObserver::class);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions app/Services/AttendanceRuleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public function storeOrUpdate(StoreAttendanceRuleRequest $request, string $day,
$data['day'] = $day;
$data['role'] = $role;
$data['school_id'] = auth()->user()->school->id;
$data['is_holiday'] = isset($data['is_holiday']) ? 1 : 0;

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public function up(): void
$this->addForeignId($table, 'classroom_student_id');
$table->integer('point');
$table->enum('status', [AttendanceEnum::PRESENT->value, AttendanceEnum::PERMIT->value, AttendanceEnum::SICK->value, AttendanceEnum::ALPHA->value]);
$table->text('proof');
$table->text('proof')->nullable();
$table->time('checkin');
$table->time('checkout');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ public function up(): void
$this->addForeignId($table, 'school_id');
$table->enum('day', [DayEnum::MONDAY->value, DayEnum::TUESDAY->value, DayEnum::WEDNESDAY->value, DayEnum::THRUSDAY->value, DayEnum::FRIDAY->value, DayEnum::SATURDAY->value, DayEnum::SUNDAY->value]);
$table->enum('role', [RoleEnum::STUDENT->value, RoleEnum::TEACHER->value]);
$table->time('checkin_start');
$table->time('checkin_end');
$table->time('checkout_start');
$table->time('checkout_end');
$table->time('checkin_start')->default('00:00:00');
$table->time('checkin_end')->default('00:00:00');
$table->time('checkout_start')->default('00:00:00');
$table->time('checkout_end')->default('00:00:00');
$table->boolean('is_holiday')->default(false);
$table->unique(['day']);
$table->timestamps();
});
}
Expand Down
12 changes: 11 additions & 1 deletion database/seeders/AttendanceSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Database\Seeders;

use App\Enums\AttendanceEnum;
use App\Models\Attendance;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

Expand All @@ -12,6 +14,14 @@ class AttendanceSeeder extends Seeder
*/
public function run(): void
{
//
Attendance::create([
'id' => '1',
'classroom_student_id' => '1',
'point' => '11',
'proof' => null,
'status' => AttendanceEnum::PRESENT->value,
'checkin' => '07:00:00',
'checkout' => '16:00:00'
]);
}
}
9 changes: 8 additions & 1 deletion database/seeders/ClassroomSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Database\Seeders;

use App\Models\Classroom;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

Expand All @@ -12,6 +13,12 @@ class ClassroomSeeder extends Seeder
*/
public function run(): void
{
//
Classroom::create([
'id' => '1',
'name' => '11 Rpl 1',
'employee_id' => '1',
'school_year_id' => '4',
'level_class_id' => '2'
]);
}
}
7 changes: 6 additions & 1 deletion database/seeders/ClassroomStudentSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Database\Seeders;

use App\Models\ClassroomStudent;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

Expand All @@ -12,6 +13,10 @@ class ClassroomStudentSeeder extends Seeder
*/
public function run(): void
{
//
ClassroomStudent::create([
'id' => '1',
'student_id' => '1',
'classroom_id' => '1',
]);
}
}
7 changes: 6 additions & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ public function run(): void
SchoolSeeder::class,
LessonHourSeeder::class,
SchoolYearSeeder::class,
LevelClassSeeder::class
LevelClassSeeder::class,
EmployeeSeeder::class,
StudentSeeder::class,
ClassroomSeeder::class,
ClassroomStudentSeeder::class,
AttendanceSeeder::class
]);
}
}
Loading

0 comments on commit 727d077

Please sign in to comment.