fixing data di recap

This commit is contained in:
JokoPrasetio 2026-05-22 09:31:24 +07:00
parent e3b7ad4f12
commit 1d2f03aa18

View File

@ -130,7 +130,10 @@ class DashboardController extends Controller
public function index(){
$katDok = MasterKategori::where('statusenabled', true)->select('master_kategori_directory_id', 'nama_kategori_directory')->get();
$authMapping = auth()->user()?->dataUser?->mappingUnitKerjaPegawai[0];
$authMapping = auth()->user()?->dataUser?->mappingUnitKerjaPegawai()
->where('isprimary', true)
->first();
// dd(auth()->user()?->dataUser);
$authUnitKerja = $authMapping->objectunitkerjapegawaifk ?? null;
$authSubUnitKerja = $authMapping->objectsubunitkerjapegawaifk ?? null;
$data = [
@ -303,18 +306,20 @@ class DashboardController extends Controller
public function downloadDataUnitExcel()
{
$mapping = MappingUnitKerjaPegawai::where('statusenabled', true)
->where('objectpegawaifk', auth()->user()->dataUser->id)
->where('objectpegawaifk', auth()?->user()?->dataUser?->id)
->get(['objectunitkerjapegawaifk']);
$unitIds = $mapping->pluck('objectunitkerjapegawaifk')
->filter()
->unique()
->values()
->all();
// dd(auth('admin')->check());
$query = FileDirectory::where('statusenabled', true)
->where('status_action', 'approved')
->whereIn('id_unit_kerja', $unitIds)
->orderBy('master_kategori_directory_id', 'desc');
->where('status_action', 'approved');
if(!auth('admin')->check()){
$query= $query->whereIn('id_unit_kerja', $unitIds);
}
$query=$query->orderBy('master_kategori_directory_id', 'desc');
$rows = $query->get();
@ -351,9 +356,23 @@ class DashboardController extends Controller
$rowIdx = 5;
foreach ($rows as $item) {
$parts = array_values(array_filter(explode('/', (string) $item->file)));
$unitName = $parts[0] ?? '-';
$subUnitName = $parts[1] ?? '-';
$kategoriName = $parts[2] ?? '-';
if(!$item->is_akre){
$unitName = $parts[0] ?? '-';
$subUnitName = $parts[1] ?? '-';
if($item->master_kategori_directory_id){
$kategoriName = $parts[2] ?? '-';
}else{
$kategoriName = $item->kategori_hukum ?? '-';
}
}else{
$unitName = UnitKerja::where('id', $item->id_unit_kerja)->first()->name;
$subUnitName = SubUnitKerja::where('id', $item->id_unit_kerja)->first()->name;
if($item->master_kategori_directory_id){
$kategoriName = MasterKategori::where('id', $item->id_unit_kerja)->first()->nama_kategori_directory;
}else{
$kategoriName = $item->kategori_hukum ?? '-';
}
}
$sheet->fromArray([
$item->no_dokumen ?? '-',
@ -609,6 +628,7 @@ class DashboardController extends Controller
'pegawai_id_entry' => auth()->user()->dataUser->id ?? 1,
'pegawai_nama_entry' => auth()->user()->dataUser->namalengkap ?? 'tes',
];
dd($payload);
if($file){
$imageName = $file->getClientOriginalName();
$path = "{$nama_unit_kerja}/{$nama_sub_unit_kerja}/{$nama_kategori}/{$nama_klasifikasi}";
@ -1619,21 +1639,44 @@ class DashboardController extends Controller
->orWhereDate('tgl_expired', '>=', now()->toDateString());
})
->whereNotNull('status_action')->where('status_action', 'approved');
if(in_array(22, $unitIds)){
$rows = $rows->pluck('file');
}elseif(auth()->user()->username === "admin.turt"){
$rows = $rows->pluck('file');
}else{
$rows = $rows->whereIn('id_unit_kerja', $unitIds)->pluck('file');
// if(in_array(22, $unitIds)){
// $rows = $rows->pluck('file');
// }elseif(auth()->user()->username === "admin.turt"){
// $rows = $rows->pluck('file');
// }else{
// $rows = $rows->whereIn('id_unit_kerja', $unitIds)->pluck('file');
// }
if (
!in_array(22, $unitIds) &&
auth()->user()->username !== "admin.turt"
) {
$rows = $rows->whereIn('id_unit_kerja', $unitIds);
}
$rows = $rows->get();
// dd($rows);
$grouped = [];
foreach ($rows as $path) {
$parts = array_values(array_filter(explode('/', $path)));
if (count($parts) < 4) {
continue;
foreach ($rows as $item) {
$parts = array_values(array_filter(explode('/', $item->file)));
// if (count($parts) < 4) {
// continue;
// }
if(!$item->is_akre){
$unit = $parts[0] ?? '-';
if($item->master_kategori_directory_id){
$folder = $parts[2] ?? '-';
}else{
$folder = $item->kategori_hukum ?? '-';
}
}else{
$unit = UnitKerja::where('id', $item->id_unit_kerja)->first()->name ?? '-';
if($item->master_kategory_directory_id){
$folder = MasterKategori::where('master_kategori_directory_id', $item->master_kategori_directory_id)->first()->nama_kategory_directory;
}else{
$folder = $item->kategori_hukum ?? '-';
}
}
$unit = $parts[0];
$folder = $parts[2];
if ($keyword) {
$hit = str_contains(strtolower($unit), $keyword) || str_contains(strtolower($folder), $keyword);
@ -1649,7 +1692,6 @@ class DashboardController extends Controller
}
$grouped[$unit][$folder]++;
}
$result = [];
foreach ($grouped as $unitName => $folders) {
$data = [];
@ -1665,7 +1707,6 @@ class DashboardController extends Controller
'data' => $data,
];
}
return $result;
}