main
Ilham Wara Nugroho 2025-09-09 14:17:02 +07:00
parent 467996fd13
commit 1bf8a417ff
21 changed files with 270 additions and 193 deletions

View File

@ -1,4 +1,8 @@
<?php
use PhpOffice\PhpSpreadsheet\Shared\Date;
use Carbon\Carbon;
use App\Models\Master\Menu;
use App\Models\Master\AccessMenu;
use App\Models\User;
@ -7,6 +11,25 @@ use App\Models\Master\Dataset;
use App\Models\Master\Topik;
use App\Models\Log;
if (!function_exists('taskLabel')) {
function transformDate($value)
{
try {
if (is_numeric($value)) {
// kalau numeric, berarti serial number Excel
return Carbon::instance(Date::excelToDateTimeObject($value));
} elseif ($value) {
// kalau sudah string (misal: 2025-08-27)
return Carbon::parse($value);
}
} catch (\Exception $e) {
return null;
}
return null;
}
}
if (!function_exists('taskLabel')) {
/**
* @param $val

View File

@ -101,6 +101,42 @@ class HomeController extends Controller
}
public function gridResource(Request $request)
{
if(session('group_id') == 1){
$data = Template::with(['dataset'])->where('show_dashboard',1)->get();
}else{
$data = Template::with(['dataset'])->whereHas('dataset',function($query){
$query->where('instansi_id',auth()->user()->ms_instansi_id);
})->where('show_dashboard',1)->get();
}
// $data = User::with(['group'])->orderBy('id','DESC')->get();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
if(session('group_id') == 1){
$action .= '<a href="'.url('dashboard/dataset/resource/'.encode_id($row->MsTemplateId)) .'" class="btn w-full bg-success text-white">Lihat Data</a>';
}else{
$action .= '<a href="'.url('dashboard/dataset/resource/instansi/'.encode_id(auth()->user()->ms_instansi_id).'/'.encode_id($row->MsTemplateId)).'" class="btn w-full bg-success text-white">Lihat Data</a>';
}
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->id),
'name' => @$row->name,
'jumlah' => $row->dataset->count(),
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
public function datasetGrid($alias,Request $request)
{
if(session('group_id') == 1){

View File

@ -30,7 +30,7 @@ public function startRow(): int
public function model(array $row)
{
// cek kalau row kosong jangan insert
// cek kalau row kosong jangan insert
if ($row[0] === null && $row[1] === null && $row[2] === null && $row[3] === null && $row[4] === null && $row[5] === null && $row[6] === null) {
return null; // baris kosong dilewati
}

View File

@ -32,7 +32,6 @@ public function model(array $row)
// cek kalau row kosong jangan insert
if (
$row[0] === null &&
$row[1] === null &&
$row[2] === null &&
$row[3] === null &&
@ -77,11 +76,12 @@ public function model(array $row)
) {
return null; // baris kosong dilewati
}
// dd($this->transformDate($row[2]));
return new DatasetTable22([
'dataset_id' => $this->datasetId,
'created_by' => $this->userId,
'lokasi' => $row[1],
'waktu' => $row[2],
'waktu' => transformDate($row[2]),
'lat' => $row[3],
'long' => $row[4],
'tempratur' => $row[5],

View File

@ -68,7 +68,7 @@ public function model(array $row)
'dataset_id' => $this->datasetId,
'created_by' => $this->userId,
'lokasi' => $row[1],
'waktu' => $row[2],
'waktu' => transformDate($row[2]),
'lat' => $row[3],
'long' => $row[4],
'lokasi_sampling' => $row[5],
@ -97,4 +97,5 @@ public function model(array $row)
'pcb' => $row[28],
]);
}
}

View File

@ -29,22 +29,24 @@ public function startRow(): int
public function model(array $row)
{
// cek kalau row kosong jangan insert
if ($row[0] === null && $row[1] === null && $row[2] === null && $row[3] === null && $row[4] === null && $row[5] === null && $row[6] === null && $row[7] === null && $row[8] === null) {
// dd($row);
// cek kalau row kosong jangan insert
if ($row[0] === null && $row[1] === null && $row[2] === null && $row[3] === null && $row[4] === null && $row[5] === null && $row[6] === null && $row[7] === null && $row[8] === null && $row[9] === null) {
return null; // baris kosong dilewati
}
// dd($row[1]);
return new DatasetTable25([
'dataset_id' => $this->datasetId,
'created_by' => $this->userId,
'mata_air' => $row[1],
'ledeng_pam' => $row[2],
'sumur_bor_pompa' => $row[3],
'sumur_tak_terlindung' => $row[4],
'sungai' => $row[5],
'terlindung_air' => $row[6],
'air_kemasan' => $row[7],
'lainnya' => $row[8],
'lokasi' => $row[1],
'mata_air' => $row[2],
'ledeng_pam' => $row[3],
'sumur_bor_pompa' => $row[4],
'sumur_tak_terlindung' => $row[5],
'sungai' => $row[6],
'terlindung_air' => $row[7],
'air_kemasan' => $row[8],
'lainnya' => $row[9],
]);
}
}

View File

@ -54,7 +54,7 @@ public function model(array $row)
'lokasi_pemantauan' => $row[0],
'latitude' => $row[1],
'longitude' => $row[2],
'waktu_pemantauan' => $row[3],
'waktu_pemantauan' => transformDate($row[3]),
'ph' => $row[4],
'dhl' => $row[5],
'so4' => $row[6],

View File

@ -37,11 +37,11 @@ public function model(array $row)
return new DatasetTable39([
'dataset_id' => $this->datasetId,
'created_by' => $this->userId,
'kendaraan' => $row[1],
'jumlah' => $row[2],
'bensin' => $row[3],
'solar' => $row[4],
'gas' => $row[5],
'kendaraan' => @$row[1] ? $row[1] : 0,
'jumlah' => @$row[2] ? $row[2] : 0,
'bensin' => @$row[3] ? $row[3] : 0,
'solar' => @$row[4] ? $row[4] : 0,
'gas' => @$row[5] ? $row[5] : 0,
]);
}
}

View File

@ -39,7 +39,7 @@ public function model(array $row)
'created_by' => $this->userId,
'lokasi' => $row[1],
'nama_perusahaan' => $row[3],
'waktu' => $row[4],
'waktu' => transformDate($row[4]),
'hasil_pengawasan' => $row[5],
]);
}

View File

@ -39,7 +39,7 @@ public function model(array $row)
'created_by' => $this->userId,
'lokasi' => $row[1],
'nama_perusahaan' => $row[3],
'waktu' => $row[4],
'waktu' => transformDate($row[4]),
'hasil_pengawasan' => $row[5],
]);
}

View File

@ -10,13 +10,13 @@ use Illuminate\Database\Eloquent\Model;
class DatasetTable15 extends Model
{
use HasFactory;
use SoftDeletes;
use SoftDeletes;
protected $table = 'dataset_table15';
protected $primaryKey = 'DatasetTable15Id';
protected $guarded = [];
function dataset() {
function dataset() {
return $this->belongsTo('App\Models\Dataset','dataset_id');
}
}

View File

@ -192,6 +192,7 @@ class DatasetRepository implements DatasetRepositoryInterface
// dd($data);
return DB::transaction(function () use ($modelClass, $importClass, $file, $data) {
try {
$keyId = decode_id($data['secure_id']);
$json = [];
$filePath = null;
@ -290,6 +291,23 @@ class DatasetRepository implements DatasetRepositoryInterface
}
return $masterModel;
}catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
$failures = $e->failures();
foreach ($failures as $failure) {
// Kolom & baris error
dump('Row: '.$failure->row());
dump('Attribute: '.$failure->attribute());
dump('Errors: ', $failure->errors());
dump('Values: ', $failure->values());
}
return $failures;
} catch (Exception $e) {
dd($e->getMessage());
}
});
}

View File

@ -14,6 +14,7 @@ return new class extends Migration
Schema::create('dataset_table25', function (Blueprint $table) {
$table->id('DatasetTable25Id');
$table->integer('dataset_id');
$table->string('lokasi')->nullable();
$table->float('mata_air')->default(0); // Mata Air
$table->float('ledeng_pam')->default(0); // Ledeng/PAM
$table->float('sumur_bor_pompa')->default(0); // Sumur Bor/Pompa

View File

@ -18,15 +18,15 @@ return new class extends Migration
$table->string('latitude')->nullable(); // Latitude (7 digit desimal cukup presisi)
$table->string('longitude')->nullable(); // Longitude
$table->timestamp('waktu_pemantauan')->nullable(); // Waktu Pemantauan
$table->float('ph')->default(0); // pH biasanya 0-14 (cukup 5,2)
$table->float('dhl')->default(0); // DHL (konduktivitas)
$table->float('so4')->default(0); // SO4
$table->float('no3')->default(0); // NO3
$table->float('cr')->default(0); // Cr
$table->float('nh4')->default(0); // NH4
$table->float('na')->default(0); // Na
$table->float('ca2')->default(0); // Ca2+
$table->float('mg2')->default(0); // Mg2+
$table->string('ph')->nullable(); // pH biasanya 0-14 (cukup 5,2)
$table->string('dhl')->nullable(); // DHL (konduktivitas)
$table->string('so4')->nullable(); // SO4
$table->string('no3')->nullable(); // NO3
$table->string('cr')->nullable(); // Cr
$table->string('nh4')->nullable(); // NH4
$table->string('na')->nullable(); // Na
$table->string('ca2')->nullable(); // Ca2+
$table->string('mg2')->nullable(); // Mg2+
$table->integer('created_by');
$table->timestampsTz();

View File

@ -15,12 +15,12 @@ return new class extends Migration
$table->id('DatasetTable31Id');
$table->integer('dataset_id');
$table->string('kabupaten_kota')->nullable(); // Kabupaten/Kota/Kec.
$table->float('jumlah_kk')->default(0);
$table->float('sendiri')->default(0);
$table->float('bersama')->default(0);
$table->float('umum')->default(0);
$table->float('tidak_menggunakan')->default(0);
$table->float('tidak_ada_fasilitas')->default(0);
$table->string('jumlah_kk')->nullable();
$table->string('sendiri')->nullable();
$table->string('bersama')->nullable();
$table->string('umum')->nullable();
$table->string('tidak_menggunakan')->nullable();
$table->string('tidak_ada_fasilitas')->nullable();
$table->integer('created_by');
$table->timestampsTz();
$table->softdeletesTz();

View File

@ -16,22 +16,22 @@ return new class extends Migration
$table->integer('dataset_id');
$table->string('lokasi')->nullable(); // Kabupaten/Kota/Kec.
// Jumlah penduduk per kategori pendidikan (L = Laki-laki, P = Perempuan)
$table->integer('tidak_sekolah_l')->default(0);
$table->integer('tidak_sekolah_p')->default(0);
$table->integer('sd_l')->default(0);
$table->integer('sd_p')->default(0);
$table->integer('sltp_l')->default(0);
$table->integer('sltp_p')->default(0);
$table->integer('slta_smk_l')->default(0);
$table->integer('slta_smk_p')->default(0);
$table->integer('pt_l')->nullable(); // defaultT0inggi
$table->integer('pt_p')->default(0);
$table->integer('s1_l')->default(0);
$table->integer('s1_p')->default(0);
$table->integer('s2_l')->default(0);
$table->integer('s2_p')->default(0);
$table->integer('s3_l')->default(0);
$table->integer('s3_p')->default(0);
$table->float('tidak_sekolah_l')->default(0);
$table->float('tidak_sekolah_p')->default(0);
$table->float('sd_l')->default(0);
$table->float('sd_p')->default(0);
$table->float('sltp_l')->default(0);
$table->float('sltp_p')->default(0);
$table->float('slta_smk_l')->default(0);
$table->float('slta_smk_p')->default(0);
$table->float('pt_l')->nullable(); // defaultT0inggi
$table->float('pt_p')->default(0);
$table->float('s1_l')->default(0);
$table->float('s1_p')->default(0);
$table->float('s2_l')->default(0);
$table->float('s2_p')->default(0);
$table->float('s3_l')->default(0);
$table->float('s3_p')->default(0);
$table->integer('created_by');
$table->timestampsTz();
$table->softdeletesTz();

View File

@ -15,8 +15,8 @@ return new class extends Migration
$table->id('DatasetTable34Id');
$table->integer('dataset_id');
$table->string('kabupaten_kota')->nullable();
$table->integer('jumlah_rumah_tangga')->default(0);
$table->integer('jumlah_rumah_tangga_miskin')->default(0);
$table->float('jumlah_rumah_tangga')->default(0);
$table->float('jumlah_rumah_tangga_miskin')->default(0);
$table->float('persentase_rumah_tangga_miskin')->default(0);
$table->integer('created_by');
$table->timestampsTz();

View File

@ -18,21 +18,20 @@ return new class extends Migration
$table->string('lat')->nullable();
$table->string('long')->nullable();
$table->string('lama_pengukuran')->nullable();
// parameter udara pakai float default 0
$table->float('so2')->default(0); // µg/Nm3
$table->float('co')->default(0); // µg/Nm3
$table->float('no2')->default(0); // µg/Nm3
$table->float('o3')->default(0); // µg/Nm3
$table->float('hc')->default(0); // µg/Nm3
$table->float('pm10')->default(0); // µg/Nm3
$table->float('pm25')->default(0); // µg/Nm3
$table->float('tsp')->default(0); // µg/Nm3
$table->float('pb')->default(0); // µg/Nm3
$table->float('dustfall')->default(0); // µg/Nm3
$table->float('total_fluorides')->default(0); // µg/Nm3
$table->float('fluor_index')->default(0); // µg/Nm3
$table->float('chlorine_dioxide')->default(0); // µg/Nm3
$table->float('sulphat_index')->default(0); // µg/Nm3
$table->string('so2')->nullable(); // µg/Nm3
$table->string('co')->nullable(); // µg/Nm3
$table->string('no2')->nullable(); // µg/Nm3
$table->string('o3')->nullable(); // µg/Nm3
$table->string('hc')->nullable(); // µg/Nm3
$table->string('pm10')->nullable(); // µg/Nm3
$table->string('pm25')->nullable(); // µg/Nm3
$table->string('tsp')->nullable(); // µg/Nm3
$table->string('pb')->nullable(); // µg/Nm3
$table->string('dustfall')->nullable(); // µg/Nm3
$table->string('total_fluorides')->nullable(); // µg/Nm3
$table->string('fluor_index')->nullable(); // µg/Nm3
$table->string('chlorine_dioxide')->nullable(); // µg/Nm3
$table->string('sulphat_index')->nullable(); // µg/Nm3
$table->integer('created_by');
$table->timestampsTz();
$table->softdeletesTz();

View File

@ -14,17 +14,17 @@ return new class extends Migration
Schema::create('dataset_table38', function (Blueprint $table) {
$table->id('DatasetTable38Id');
$table->integer('dataset_id');
$table->float('minyak_bakar')->default(0);
$table->float('minyak_diesel')->default(0);
$table->float('minyak_tanah')->default(0);
$table->float('gas')->default(0);
$table->float('batubara')->default(0);
$table->float('lpg')->default(0);
$table->float('briket')->default(0);
$table->float('kayu_bakar')->default(0);
$table->float('biomassa')->default(0);
$table->float('bensin')->default(0);
$table->float('solar')->default(0);
$table->string('minyak_bakar')->nullable();
$table->string('minyak_diesel')->nullable();
$table->string('minyak_tanah')->nullable();
$table->string('gas')->nullable();
$table->string('batubara')->nullable();
$table->string('lpg')->nullable();
$table->string('briket')->nullable();
$table->string('kayu_bakar')->nullable();
$table->string('biomassa')->nullable();
$table->string('bensin')->nullable();
$table->string('solar')->nullable();
$table->integer('created_by');
$table->timestampsTz();
$table->softdeletesTz();

View File

@ -64,39 +64,35 @@
<div class="p-6">
<div>
<div class="mb-5">
<h5 class="text-md font-bold">10 Data Update Terakhir</h5>
<h5 class="text-md font-bold">Data Resource</h5>
</div>
<table class="gridjs-table" >
<table class="gridjs-table"
data-search="false"
data-toggle="table"
data-pagination="true"
data-toolbar="#toolbar"
data-show-refresh="false"
data-url="{{route('modules.dashboard.gridResource')}}"
data-sort-name="ids"
data-sort-order="desc"
data-page-size="5"
data-id-field="id"
id="grid-data">
<thead class="gridjs-thead">
<tr class="gridjs-tr bg-primary-light">
<th width="15%" class="gridjs-td gridjs-th text-sm">#</th>
<th class="gridjs-td gridjs-th text-sm">No</th>
<th class="gridjs-td gridjs-th text-sm">Resource Data</th>
<th class="gridjs-td gridjs-th text-sm">Jumlah Upload Dataset</th>
<th class="gridjs-td gridjs-th text-sm" data-width="10" data-field="action">#</th>
<th class="gridjs-td gridjs-th text-sm" data-width="10" data-field="no">No</th>
<th class="gridjs-td gridjs-th text-sm" data-field="name">Resource Data</th>
<th class="gridjs-td gridjs-th text-sm" data-field="jumlah">Jumlah Upload Dataset</th>
</tr>
</thead>
<tbody class="gridjs-tbody">
@foreach ($resource as $k => $res)
<tr class="gridjs-tr">
<td class="gridjs-td gridjs-th text-sm">
@if(session('group_id') == 1)
<a href="{{ url('dashboard/dataset/resource/'.encode_id($res->MsTemplateId)) }}" class="btn w-full bg-success text-white">Lihat Data</a>
@else
<a href="{{ url('dashboard/dataset/resource/instansi/'.encode_id(auth()->user()->ms_instansi_id).'/'.encode_id($res->MsTemplateId)) }}" class="btn w-full bg-success text-white">Lihat Data</a>
@endif
</td>
<td class="gridjs-td gridjs-th text-sm">{{$k+1}}</td>
<td class="gridjs-td gridjs-th text-sm">{{ $res->name }}</td>
<td class="gridjs-td gridjs-th text-sm text-center">{{ $res->dataset->count() }}</td>
</tr>
@endforeach
</tbody>
<tbody class="gridjs-tbody"></tbody>
</table>
</div>
</div>
</div>
</div>
<div class="grid xl:grid-cols-1 lg:grid-cols-1 grid-cols-1 gap-6 mb-6 hidden">
{{-- <div class="grid xl:grid-cols-1 lg:grid-cols-1 grid-cols-1 gap-6 mb-6 hidden">
<div class="card">
<div class="p-6">
<div>
@ -131,7 +127,7 @@
</div>
</div>
</div>
</div>
</div> --}}
<!-- end row -->
@endsection
@section('js')

View File

@ -19,6 +19,7 @@ Route::name('dashboard.')->prefix('dashboard')->group(function () {
Route::get('/dataset/resource/{id}',[HomeController::class,'resource'])->name('resource');
Route::get('/dataset/resource/instansi/{instansi_id}/{id}',[HomeController::class,'resource_instansi'])->name('resource_instansi');
Route::get('/grid',[HomeController::class,'grid'])->name('grid');
Route::get('/gridResource',[HomeController::class,'gridResource'])->name('gridResource');
Route::get('/datasetGrid/{alias}',[HomeController::class,'datasetGrid'])->name('datasetGrid');
Route::get('/api/chart/{template_id}/{instansi_id}',[HomeController::class,'apiChart'])->name('apiChart');
});