Commit 47aac7d8 by Triyah Fatmawati

Add API SAKU

parent 20f6a56a
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Admin\Penelaah;
use App\Models\Admin\Pengajuan;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ApiSakuController extends Controller
{
public function index(){
$penelaah = Penelaah::query()
->with('penelaah')
// ->where('created_at', '<', '2024-05-20')
->orderBy('nip')
->get();
foreach ($penelaah as $key => $pen) {
$dataTelaah[] = [
'id' => $pen->id,
'nama' => $pen->nama,
'nip' => $pen->nip,
'nik' => $pen->nik,
'unit' => $pen->unit,
'created_at' => $pen->created_at,
'updated_at' => $pen->updated_at,
'judul' => $pen->penelaah->judul,
'kode_kategori' => $pen->penelaah->kategori->kode_kategori,
'nama_kategori' => $pen->penelaah->kategori->nama_kategori,
'poin_saku' => $pen->penelaah->kategori->poin_saku,
'tahun' => $pen->penelaah->tahun
];
}
return response()->json($dataTelaah);
}
public function saku1() {
$totalPoin = 0;
$jmlTelaah = Penelaah::query()
->select('nip', DB::raw('COUNT(nip) as jumlah'))
->groupBy('nip')
->where('created_at', '<', '2024-05-20')
->get();
foreach ($jmlTelaah as $key => $telaah) {
$penelaah = Penelaah::query()
->with('penelaah')
->where('nip', $telaah->nip)
->where('created_at', '<', '2024-05-20')
->get();
foreach ($penelaah as $keys => $pen) {
$totalPoin = $totalPoin + $pen->penelaah->kategori->poin_saku;
$dataPenelaah[$telaah->nip] = [
'nama' => $pen->nama,
'nik' => $pen->nik,
'nip' => $pen->nip,
'unit' => $pen->unit,
'jumlah' => $telaah->jumlah,
];
$dataTelaah[$keys] = [
'id_pengajuan_epk' => $pen->penelaah->id_pengajuan,
'judul' => $pen->penelaah->judul,
'peneliti' => $pen->penelaah->peneliti,
'klasifikasi' => $pen->penelaah->klasifikasi,
'file_ec' => $pen->penelaah->file_ec,
'no_sk' => $pen->penelaah->no_sk,
'kode_kategori' => $pen->penelaah->kategori->kode_kategori,
'nama_kategori' => $pen->penelaah->kategori->nama_kategori,
'poin_saku' => $pen->penelaah->kategori->poin_saku,
];
$dataPenelaah[$telaah->nip]['telaah']=$dataTelaah;
$dataPenelaah[$telaah->nip]['totalPoin']=$totalPoin;
}
}
return response()->json($dataPenelaah);
}
}
......@@ -22,4 +22,8 @@ class MsKategori extends Model
'poin_saku',
'status'
];
public function rKategori(){
return $this->belongsToMany(Pengajuan::class, 'id', 'id_kategori');
}
}
......@@ -23,4 +23,8 @@ class Penelaah extends Model
'nip',
'unit'
];
public function penelaah(){
return $this->belongsTo(Pengajuan::class, 'id_pengajuan', 'id')->with('kategori');
}
}
......@@ -26,4 +26,12 @@ class Pengajuan extends Model
'file_ec',
'no_sk'
];
public function rPenelaah() {
return $this->hasOne(Penelaah::class, 'id_pengajuan', 'id');
}
public function kategori(){
return $this->hasOne(MsKategori::class, 'id', 'id_kategori');
}
}
<?php
use App\Http\Controllers\Api\ApiSakuController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
......@@ -17,3 +18,6 @@
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Route::get('/saku', [ApiSakuController::class, 'index']);
Route::get('/saku1', [ApiSakuController::class, 'saku1']);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment