Skip to content

Commit

Permalink
Rapor Admin 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
andarutr committed Mar 17, 2024
1 parent 5399a93 commit 2e6ae9c
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 18 deletions.
54 changes: 52 additions & 2 deletions app/Livewire/Rapor/RaporCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Request;
use Ramsey\Uuid\Uuid;
use Livewire\Component;
use App\Models\{User, Rapor, Exam, ContentRapor};
use App\Models\{User, Rapor, Exam, ExamResult, Remedial, AshResult, ContentRapor};
use Livewire\Attributes\Validate;
use Illuminate\Database\Eloquent\Builder;

Expand Down Expand Up @@ -36,11 +36,61 @@ public function mount()
public function store()
{
$this->validate();
$exam = Exam::where('id', $this->exam_id)->first();
if($exam->exam_type == 'ASTS'){
$asts = ExamResult::where(['exam_id' => $this->exam_id, 'user_id' => $this->user->id])
->whereHas('exam', function(Builder $query) use($exam){
$query->where('exam_type', $exam->exam_type);
})->sum('score');
$asts_remedial = Remedial::where(['exam_id' => $this->exam_id, 'user_id' => $this->user->id])
->whereHas('exam', function(Builder $query) use($exam){
$query->where('exam_type', $exam->exam_type);
})->sum('score');
// Nilai asli + remed :2
$asts_ = ($asts + $asts_remedial)/2;

$tp_count = AshResult::where(['user_id' => $this->user->id, 'lesson_id' => $exam->lesson_id])->count();
$tp = AshResult::where(['user_id' => $this->user->id, 'lesson_id' => $exam->lesson_id])->sum('total');
$tp_ = $tp/$tp_count;

$total = number_format(round(($tp_ + $asts_)/2),0,'.','');
}

if($exam->exam_type === 'ASAS'){
$asts = ExamResult::where(['exam_id' => $this->exam_id, 'user_id' => $this->user->id])
->whereHas('exam', function(Builder $query) use($exam){
$query->where('exam_type', 'ASTS');
})->sum('score');
$asts_remedial = Remedial::where(['exam_id' => $this->exam_id, 'user_id' => $this->user->id])
->whereHas('exam', function(Builder $query) use($exam){
$query->where('exam_type', 'ASTS');
})->sum('score');
// Nilai asli + remed :2
$asts_ = ($asts + $asts_remedial)/2;

$asas = ExamResult::where(['exam_id' => $this->exam_id, 'user_id' => $this->user->id])
->whereHas('exam', function(Builder $query) use($exam){
$query->where('exam_type', $exam->exam_type);
})->sum('score');
$asas_remedial = Remedial::where(['exam_id' => $this->exam_id, 'user_id' => $this->user->id])
->whereHas('exam', function(Builder $query) use($exam){
$query->where('exam_type', $exam->exam_type);
})->sum('score');
// Nilai asli + remed :2
$asas_ = ($asas + $asas_remedial)/2;

$tp_count = AshResult::where(['user_id' => $this->user->id, 'lesson_id' => $exam->lesson_id])->count();
$tp = AshResult::where(['user_id' => $this->user->id, 'lesson_id' => $exam->lesson_id])->sum('total');
$tp_ = $tp/$tp_count;

$total = number_format(round(($tp_ + $asts_ + $asas_)/3),0,'.','');
}

ContentRapor::create([
'uuid' => Uuid::uuid4()->toString(),
'rapor_id' => $this->rapor->id,
'exam_id' => $this->exam_id,
'nilai' => 1,
'nilai' => $total,
'description' => $this->description,
]);

Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Rapor/RaporList.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function mount()
public function destroy($uuid)
{
ContentRapor::where('uuid', $uuid)->delete();
return redirect()->back()->with('success','Berhasil menghapus nilai!');
toastr()->success('Berhasil menghapus nilai!');
}

public function render()
Expand Down
9 changes: 3 additions & 6 deletions app/Livewire/Rapor/RaporUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,25 @@ class RaporUpdate extends Component
public $uuid;
public $user_id;
public $rapor;
public $exams;
public $exam;
public $user;
public $kelas;
#[Validate('required')]
public $exam_id;
#[Validate('required')]
public $description;

public function mount()
{
$this->uuid = Request::segment(6);
$this->kelas = Request::segment(4);
$this->rapor = Rapor::where('uuid', $this->uuid)->first();
$this->exams = Exam::all();
$content = ContentRapor::whereHas('rapor', function(Builder $query){
$query->where('uuid', $this->uuid);
})->first();

$this->exam_id = $this->rapor->id;
$this->description = $content->description;
$this->exam = $content->exam->lesson->name.' ('.$content->exam->grade.') ['.$content->exam->exam_type.'] '.$content->exam->semester.' '.$content->exam->th_ajaran;
// }}
$this->user = User::where('id', $this->rapor->user_id)->first();
}

Expand All @@ -46,8 +45,6 @@ public function update()
$this->validate();

ContentRapor::where('rapor_id', $this->rapor->id)->update([
'exam_id' => $this->exam_id,
'nilai' => 2,
'description' => $this->description,
]);

Expand Down
13 changes: 13 additions & 0 deletions database/data/ashpurposes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"title": "1.5 Penelitian Sosial",
"tp_1": "Observasi",
"tp_2": "Kinerja",
"tp_3": "Proyek",
"tp_4": "Tes Tertulis",
"tp_5": "Tes Lisan",
"tp_6": "Penugasan",
"tp_7": "Portfolio",
"tp_8": null
}
]
36 changes: 36 additions & 0 deletions database/seeders/AshPurposeSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Database\Seeders;

use File;
use Ramsey\Uuid\Uuid;
use App\Models\AshPurpose;
use Illuminate\Database\Seeder;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;

class AshPurposeSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$json = File::get('database/data/ashpurposes.json');
$purposes = json_decode($json);

foreach($purposes as $purpose){
AshPurpose::create([
'uuid' => Uuid::uuid4()->toString(),
'title' => $purpose->title,
'tp_1' => $purpose->tp_1,
'tp_2' => $purpose->tp_2,
'tp_3' => $purpose->tp_3,
'tp_4' => $purpose->tp_4,
'tp_5' => $purpose->tp_5,
'tp_6' => $purpose->tp_6,
'tp_7' => $purpose->tp_7,
'tp_8' => $purpose->tp_8,
]);
}
}
}
3 changes: 2 additions & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function run(): void
ExResultSeeder::class,
PgAnswerSeeder::class,
EsAnswerSeeder::class,
// RaporSeeder::class,
RaporSeeder::class,
AshPurposeSeeder::class,
// ContentRaporSeeder::class,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/rapor/rapor-create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<select class="form-control" wire:model.live="exam_id">
<option value="">Pilih</option>
@foreach($exams as $exam)
<option value="{{ $exam->id }}">{{ $exam->lesson->name }} ({{ $exam->grade.' '.$exam->major }})[{{ $exam->exam_type }}] {{ $exam->semester.' '.$exam->th_ajaran }}</option>
<option value="{{ $exam->id }}">{{ $exam->lesson->name }} ({{ $exam->grade }})[{{ $exam->exam_type }}] {{ $exam->semester.' '.$exam->th_ajaran }}</option>
@endforeach
</select>
@error('exam_id')<p class="text-danger">{{ $message }}</p>@enderror
Expand Down
8 changes: 1 addition & 7 deletions resources/views/livewire/rapor/rapor-update.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
</div>
<div class="mt-1">
<label>Mata Pelajaran</label>
<select class="form-control" wire:model.live="exam_id">
<option value="">Pilih</option>
@foreach($exams as $exam)
<option value="{{ $exam->id }}">{{ $exam->lesson->name }} ({{ $exam->grade.' '.$exam->major }})[{{ $exam->exam_type }}] {{ $exam->semester.' '.$exam->th_ajaran }}</option>
@endforeach
</select>
@error('exam_id')<p class="text-danger">{{ $message }}</p>@enderror
<input type="text" class="form-control" placeholder="{{ $exam }}" disabled>
</div>
<div class="mt-1">
<label>Deskripsi</label>
Expand Down

0 comments on commit 2e6ae9c

Please sign in to comment.