100 lines
2.9 KiB
PHP
100 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Pelaporan;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
class ALModel extends Model
|
|
{
|
|
protected $table = 'Pelaporan.SKL_AL';
|
|
protected $primaryKey = 'PelaporanId';
|
|
public $timestamps = false;
|
|
|
|
/**
|
|
* Sesuaikan SKL pelaporan.
|
|
*
|
|
* 1. Pelaporan.SKL_AL, dari hitung-hitungan per komponen.
|
|
* 2. Pelaporan.SKL, dari rata-rata skl-nya.
|
|
*/
|
|
public static function sesuaikanSklPelaporan($idmcpelaporan)
|
|
{
|
|
// Hitung nilai skl sesuai query asli
|
|
$nilai_skl = DB::table('Komponen')
|
|
->leftJoin('NilaiKomponen', 'NilaiKomponen.KomponenId', '=', 'Komponen.KomponenId')
|
|
->where('Komponen.PelaporanId', 2)
|
|
->where('Komponen.Kode', '!=', 'SK')
|
|
->selectRaw('SUM(NilaiKomponen.Nilai) / COUNT(Komponen.KomponenId) AS skl')
|
|
->value('skl');
|
|
|
|
if (isset($nilai_skl)) {
|
|
// Panggil metode update_nilai_skl dan update_avg_skl dari PelaporanModel (asumsi sudah dibuat)
|
|
Pelaporan::updateNilaiSkl($idmcpelaporan, 2, $nilai_skl);
|
|
Pelaporan::updateAvgSkl($idmcpelaporan);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sesuaikan SPL pelaporan.
|
|
*
|
|
* 1. Pelaporan.SPL_AL, disamakan dengan mcspl_al.nilaispl.
|
|
* 2. Pelaporan.SPL, dari rata-rata spl-nya.
|
|
*/
|
|
public static function sesuaikanSplPelaporan($idmcpelaporan)
|
|
{
|
|
$spl = DB::table('Spl_AL')
|
|
->where('PelaporanId', $idmcpelaporan)
|
|
->first();
|
|
|
|
if ($spl && $spl->nilaispl) {
|
|
Pelaporan::updateNilaiSpl($idmcpelaporan, 2, $spl->nilaispl);
|
|
Pelaporan::updateAvgSpl($idmcpelaporan);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Ambil status Komunal berdasarkan idmcpelaporan.
|
|
*/
|
|
public static function getStatusMckomunal($idmcpelaporan)
|
|
{
|
|
return DB::table('Komunal')
|
|
->where('PelaporanId', $idmcpelaporan)
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* Update atau insert status mckomunal.
|
|
*/
|
|
public static function updateStatusMckomunal($idmcpelaporan, $status)
|
|
{
|
|
$existing = self::getStatusMckomunal($idmcpelaporan);
|
|
|
|
if ($existing) {
|
|
DB::table('Komunal')
|
|
->where('PelaporanId', $idmcpelaporan)
|
|
->update(['Tersambung' => $status]);
|
|
} else {
|
|
DB::table('Komunal')
|
|
->insert([
|
|
'PelaporanId' => $idmcpelaporan,
|
|
'Tersambung' => $status,
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Cek lampiran surat kerjasama berdasarkan PelaporanId dan KomponenId.
|
|
*/
|
|
public static function cekLampiranSk($idmcpelaporan, $idrefkomponen)
|
|
{
|
|
return DB::table('Lampiran')
|
|
->where([
|
|
'PelaporanId' => $idmcpelaporan,
|
|
'KomponenId' => $idrefkomponen,
|
|
])->first();
|
|
}
|
|
}
|