80 lines
2.4 KiB
PHP
80 lines
2.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Models;
|
||
|
|
||
|
use Illuminate\Database\Eloquent\Model;
|
||
|
use Illuminate\Support\Facades\Auth;
|
||
|
use Illuminate\Support\Facades\DB;
|
||
|
use Yajra\DataTables\DataTables;
|
||
|
|
||
|
class CriticalLevelModel extends Model
|
||
|
{
|
||
|
//
|
||
|
protected $primaryKey = ['id', 'company_id'];
|
||
|
protected $table = 'ref_critical_level';
|
||
|
public $timestamps = false;
|
||
|
|
||
|
public function initData($request,$route)
|
||
|
{
|
||
|
// INIT DB
|
||
|
$data['title'] = 'Referensi Critical Level';
|
||
|
$data['actButton'] = ['edit','hapus'];
|
||
|
$data['tableHead'] =
|
||
|
array(
|
||
|
["Critical Level","all","definition"],
|
||
|
["Bobot","all","bobot"],
|
||
|
["Status Aktif","all","is_active"],
|
||
|
["Nama Perusahaan","all","company_name"],
|
||
|
["Act","all","action"]
|
||
|
);
|
||
|
|
||
|
$data['db'] = $this->table;
|
||
|
$data['db_key'] = $this->primaryKey;
|
||
|
$data['route'] = $route;
|
||
|
$data['timestamps'] = false;
|
||
|
$data['bisaAdd'] = false;
|
||
|
$data['adaDetail'] = false;
|
||
|
$data['idManual'] = true;
|
||
|
$data['seq'] = false;
|
||
|
$data['serial'] = false;
|
||
|
|
||
|
|
||
|
$dtable = DB::select("SELECT {$this->table}.*, mc.company_name FROM {$this->table} JOIN master_company mc ON mc.id = {$this->table}.company_id
|
||
|
where {$this->table}.company_id = ? order by {$this->table}.id desc", [Auth::user()->company_id]);
|
||
|
|
||
|
|
||
|
// LIST DATA TABLE
|
||
|
$data['data_table'] = $dtable;
|
||
|
|
||
|
// FORM FIELD FOR STORE
|
||
|
$data['set_field'] = [
|
||
|
'definition' => $request->post('definition'),
|
||
|
'bobot' => $request->post('bobot'),
|
||
|
'company_id' => Auth::user()->company_id,
|
||
|
'is_active' => $request->post('is_active')
|
||
|
];
|
||
|
|
||
|
// GET DATA FOR EDIT
|
||
|
if ($request->post('id')) {
|
||
|
$multPrim = explode('|', $request->post('id'));
|
||
|
$data['get_data_edit'] = DB::selectOne("SELECT * FROM {$this->table} where id = ? and company_id = ?",[$multPrim[0], $multPrim[1]]);
|
||
|
}
|
||
|
|
||
|
foreach($data['tableHead'] as $v){
|
||
|
$arrHead[] = $v[2];
|
||
|
}
|
||
|
$data['head'] = implode(",",$arrHead);
|
||
|
|
||
|
return $data;
|
||
|
}
|
||
|
|
||
|
public function getDT($data,$init)
|
||
|
{
|
||
|
$dt = DataTables::of($data);
|
||
|
$dt->editColumn('is_active', function($data) {
|
||
|
return $data->is_active?'Aktif':'Non Aktif';
|
||
|
});
|
||
|
return $dt;
|
||
|
}
|
||
|
}
|