diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index fc20fbd..fa47e2d 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -103,11 +103,7 @@ class DashboardController extends Controller $applyFileFilters = function ($q) use ($keyword, $katArray, $subArray, $entryPegawaiId) { $q->where(function($subQuery) use ($entryPegawaiId){ - $subQuery->where('status_action', '!=', 'rejected') - ->orWhere(function ($pending) use ($entryPegawaiId) { - $pending->whereNull('status_action') - ->where('pegawai_id_entry', $entryPegawaiId); - }); + $subQuery->where('status_action', '!=', 'rejected')->whereNotNull('status_action'); }) ->when($subArray, fn($sq) => $sq->whereIn('id_sub_unit_kerja', $subArray)) ->when($katArray, fn($sq) => $sq->whereIn('master_kategori_directory_id', $katArray)) @@ -243,7 +239,24 @@ class DashboardController extends Controller $file->storeAs($path, $imageName, 'file_directory'); $payload['file'] =$path .'/' .$imageName; } - FileDirectory::create($payload); + $fd = FileDirectory::create($payload); + + $payloadLog = [ + 'file_directory_id' => $fd->file_directory_id, + 'pegawai_id_entry' => $fd->pegawai_id_entry, + 'pegawai_nama_entry' => $fd->pegawai_nama_entry, + 'entry_at' => Carbon::now(), + 'action_type' => 'Upload Dokumen', + 'statusenabled' => true, + 'mod_change' => $fd->entry_at, + 'id_unit_kerja' => $fd->id_unit_kerja, + 'id_sub_unit_kerja' => $fd->id_sub_unit_kerja, + 'file' => $fd->file, + 'tanggal_terbit' => $fd->tanggal_terbit ?? null, + 'no_dokumen' => $fd->no_dokumen ?? null, + 'permission_file' => $fd->permission_file ?? null, + ]; + LogActivity::create($payloadLog); } } } @@ -465,11 +478,7 @@ class DashboardController extends Controller $query = FileDirectory::where('statusenabled', true) ->where(function($subQuery) use ($entryPegawaiId){ - $subQuery->where('status_action', '!=', 'rejected') - ->orWhere(function ($pending) use ($entryPegawaiId) { - $pending->whereNull('status_action') - ->where('pegawai_id_entry', $entryPegawaiId); - }); + $subQuery->where('status_action', '!=', 'rejected')->whereNotNull('status_action'); })->when($keyword, function ($q) use ($keyword) { $q->where(function ($sub) use ($keyword) { $sub->where('file', 'ILIKE', "%{$keyword}%") @@ -533,7 +542,10 @@ class DashboardController extends Controller if(!$uploadedFile){ throw new \RuntimeException('File wajib diunggah pada baris ke-' . ($index+1)); } - + $unitPegawaiIds = auth()->user()->masterPersetujuan->details->pluck('unit_pegawai_id')->unique()->toArray(); + $status = in_array($id_unit_kerja, $unitPegawaiIds) + ? 'approved' + : null; $payload = [ 'id_unit_kerja' => $id_unit_kerja, 'id_sub_unit_kerja' => $id_sub_unit_kerja, @@ -543,6 +555,9 @@ class DashboardController extends Controller 'tanggal_terbit' => $data['date_active'] ?? null, 'no_dokumen' => $data['no_dokumen'] ?? null, 'permission_file' => ($data['is_permission'] ?? null) == "1", + 'status_action' => $status, + 'action_by' => $status === "approved" ? auth()->user()->objectpegawaifk : null, + 'action_at' => $status === "approved" ? now() : null ]; $imageName = $uploadedFile->getClientOriginalName(); @@ -556,7 +571,7 @@ class DashboardController extends Controller 'file_directory_id' => $fd->file_directory_id, 'pegawai_id_entry' => $fd->pegawai_id_entry, 'pegawai_nama_entry' => $fd->pegawai_nama_entry, - 'entry_at' => $fd->entry_at, + 'entry_at' => now(), 'action_type' => 'Upload Dokumen', 'statusenabled' => true, 'mod_change' => $fd->entry_at, @@ -882,7 +897,7 @@ class DashboardController extends Controller } $data->update([ 'status_action' => 'approved', - 'action_at' => Carbon::now(), + 'action_at' => now(), 'action_by' => auth()->user()->dataUser->id, ]); $payloadLog = [ @@ -924,7 +939,7 @@ class DashboardController extends Controller } $data->update([ 'status_action' => 'rejected', - 'action_at' => Carbon::now(), + 'action_at' => now(), 'action_by' => auth()->user()->dataUser->id, ]); $payloadLog = [ @@ -973,4 +988,62 @@ class DashboardController extends Controller ]); } } + + public function pengajuanFile(){ + return view('pengajuanFile.index', ['title' => 'Data Pending']); + } + + public function dataPengajuanFile(){ + $perPage = (int) request('per_page', 10); + $keyword = request('keyword'); + $start = request('start_date'); + $end = request('end_date'); + $query = FileDirectory::where('statusenabled', true)->where('pegawai_id_entry', auth()->user()->objectpegawaifk) + ->where(function($q){ + $q->where('status_action', '!=', 'approved') + ->orWhereNull('status_action'); + })->orderBy('entry_at','desc'); + if($keyword){ + $query->where(function($q) use ($keyword){ + $q->where('file', 'ILIKE', "%{$keyword}%") + ->orWhere('no_dokumen', 'ILIKE', "%{$keyword}%"); + }); + } + if($start){ + $query->whereDate('entry_at','>=',$start); + } + if($end){ + $query->whereDate('entry_at','<=',$end); + } + + $paginated = $query->paginate($perPage); + $data = $paginated->getCollection()->map(function($item){ + $dataSlice = array_values(array_filter(explode('/', $item->file))); + return [ + 'file_directory_id' => $item->file_directory_id, + 'pegawai_nama_entry' => $item->pegawai_nama_entry, + 'part' => $dataSlice[0] . '/' . $dataSlice[1], + 'folder' => $dataSlice[2], + 'fileName' =>$dataSlice[3], + 'file' => $item->file, + 'no_dokumen' => $item->no_dokumen, + 'entry_at' => $item->entry_at, + 'tanggal_terbit' => $item->tanggal_terbit, + 'permission_file' => $item->permission_file, + 'status_action' => $item->status_action + ]; + }); + return response()->json([ + 'status' => true, + 'data' => $data, + 'pagination' => [ + 'current_page' => $paginated->currentPage(), + 'next_page' => $paginated->hasMorePages() ? $paginated->currentPage() + 1 : null, + 'has_more' => $paginated->hasMorePages(), + 'last_page' => $paginated->lastPage(), + 'per_page' => $paginated->perPage(), + 'total' => $paginated->total(), + ] + ]); + } } diff --git a/config/app.php b/config/app.php index 423eed5..213c66e 100644 --- a/config/app.php +++ b/config/app.php @@ -65,7 +65,7 @@ return [ | */ - 'timezone' => 'UTC', + 'timezone' => env('APP_TIMEZONE'), /* |-------------------------------------------------------------------------- diff --git a/public/js/pengajuanFile/index.js b/public/js/pengajuanFile/index.js new file mode 100644 index 0000000..275a18d --- /dev/null +++ b/public/js/pengajuanFile/index.js @@ -0,0 +1,230 @@ +document.addEventListener('DOMContentLoaded', () => { + const tableState = { data: [], page: 1, pageSize: 10, search: '', lastPage: 1, total: 0, startDate: '', endDate: '' }; + const tbody = document.getElementById('tablePengajuanFile'); + const paginationEl = document.getElementById('paginationControls'); + const summaryEl = document.getElementById('tableSummary'); + const pageSizeSelect = document.getElementById('tablePageSize'); + const startDateInput = document.getElementById('startDate'); + const endDateInput = document.getElementById('endDate'); + + if (pageSizeSelect) { + const initialSize = parseInt(pageSizeSelect.value); + if (!isNaN(initialSize)) tableState.pageSize = initialSize; + pageSizeSelect.addEventListener('change', (e) => { + const val = parseInt(e.target.value); + if (!isNaN(val) && val > 0) { + tableState.pageSize = val; + tableState.page = 1; + fetchData(); + } + }); + } + + window.applyDateFilter = function(){ + tableState.startDate = startDateInput.value || ''; + tableState.endDate = endDateInput.value || ''; + tableState.page = 1; + fetchData(); + } + + function formatTanggal(dateString) { + if (!dateString) return '-'; + const d = new Date(dateString); + return d.toLocaleDateString('id-ID', { + day: '2-digit', + month: 'short', + year: 'numeric', + hour: '2-digit', + minute: '2-digit' + }); + } + + function buildRow(item){ + let tanggal = item.entry_at ? formatTanggal(item.entry_at) : '-'; + const aksi = ` +
| No Dokumen | +Status | +File | +Folder | +Unit/Sub Unit | +Tanggal | +
|---|