| No | +Nama Kegiatan | + {{--Tanggal Mulai Pengajuan | +Tanggal Akhir Pengajuan | --}} +Dibuat Pada | +Step/Status | ++ |
|---|
diff --git a/app/Exports/CooperationArchiveExport.php b/app/Exports/CooperationArchiveExport.php new file mode 100644 index 0000000..4d9565b --- /dev/null +++ b/app/Exports/CooperationArchiveExport.php @@ -0,0 +1,109 @@ +year = $year; + $this->month = $month; + $this->date = $date; + } + + public function collection() + { + $query = Cooperation::with(['media', 'mediaOrder']); + + if (is_role(['1'])) { + // Hanya untuk role 1: filter kerja sama lebih dari 1 tahun + if (!$this->year && !$this->month && !$this->date) { + $query->where('created_at', '<=', Carbon::now()->subYear()); + } + } else if (is_role(['3'])) { + $mediaId = Auth::user()->company->media->id; + + $query->whereHas('proposals', function ($query) use ($mediaId) { + $query->where('status', 1)->where('media_id', $mediaId); + }); + + if (!$this->year && !$this->month && !$this->date) { + $query->where('created_at', '<=', Carbon::now()->subYear()); + } + } + + if ($this->year) { + $query->whereYear('created_at', $this->year); + } + + if ($this->month) { + $monthYear = Carbon::parse($this->month); + $query->whereYear('created_at', $monthYear->year) + ->whereMonth('created_at', $monthYear->month); + } + + if ($this->date) { + $query->whereDate('created_at', $this->date); + } + + return $query->get(); + } + + public function map($cooperationArchive): array + { + return [ + $this->no++, + $cooperationArchive->name, + Carbon::parse($cooperationArchive->start_date)->locale('id')->translatedFormat('l, d F Y'), + Carbon::parse($cooperationArchive->end_date)->locale('id')->translatedFormat('l, d F Y'), + $cooperationArchive->description, + Carbon::parse($cooperationArchive->created_at)->locale('id')->translatedFormat('l, d F Y'), + ]; + } + + public function headings(): array + { + return [ + ['Data Rekap Konten', '', '', '', '', ''], + ['NO', 'Nama Kerjasama', 'Taanggal Mulai', 'Tanggal Selesai', 'Deskripsi', 'Dibuat Pada'] + ]; + } + + public function styles(Worksheet $sheet) + { + $sheet->mergeCells('A1:I1'); // A1 sampai D1 digabung + + // Set alignment untuk pusat horizontal dan vertikal + $sheet->getStyle('A1:J1')->getAlignment()->setHorizontal('center'); + $sheet->getStyle('A1:F1')->getAlignment()->setVertical('center'); + + $sheet->getColumnDimension('A')->setWidth(7); // Set column A width + $sheet->getColumnDimension('B')->setAutoSize(true); + $sheet->getColumnDimension('C')->setAutoSize(true); + $sheet->getColumnDimension('D')->setAutoSize(true); + $sheet->getColumnDimension('E')->setAutoSize(true); + $sheet->getColumnDimension('F')->setAutoSize(true); + + // Menambahkan gaya lain jika diperlukan + $sheet->getStyle('A1:F1')->getFont()->setBold(true); + $sheet->getStyle('A1:F1')->getFont()->setSize(14); + } +} diff --git a/app/Helpers/CustomHelper.php b/app/Helpers/CustomHelper.php index 535927a..e726635 100644 --- a/app/Helpers/CustomHelper.php +++ b/app/Helpers/CustomHelper.php @@ -17,182 +17,184 @@ // } // } -// if (! function_exists('store_file')) { -// function store_file($file = null, $path, $disk = null) -// { -// $disk = $disk ?? env('FILESYSTEM_DISK', 'public'); +if(env('FILESYSTEM_DISK') === 's3'){ + if (! function_exists('store_file')) { + function store_file($file = null, $path, $disk = null) + { + $disk = $disk ?? env('FILESYSTEM_DISK', 'public'); -// if (filled($file) && $file instanceof \Illuminate\Http\UploadedFile) { -// $randomFilename = Str::random(35) . time() . '.' . $file->getClientOriginalExtension(); -// $originalFileName = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)) . '.' . $file->getClientOriginalExtension(); + if (filled($file) && $file instanceof \Illuminate\Http\UploadedFile) { + $randomFilename = Str::random(35) . time() . '.' . $file->getClientOriginalExtension(); + $originalFileName = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)) . '.' . $file->getClientOriginalExtension(); -// $stored = $file->storeAs($path, $randomFilename, $disk); + $stored = $file->storeAs($path, $randomFilename, $disk); -// if ($stored) { -// $url = Storage::disk($disk)->url($stored); + if ($stored) { + $url = Storage::disk($disk)->url($stored); -// return [ -// 'randomFileName' => $randomFilename, -// 'originalFileName' => $originalFileName, -// 'url' => $url, -// 'isSuccess' => true, -// ]; -// } -// } + return [ + 'randomFileName' => $randomFilename, + 'originalFileName' => $originalFileName, + 'url' => $url, + 'isSuccess' => true, + ]; + } + } -// return [ -// 'randomFileName' => null, -// 'originalFileName' => null, -// 'url' => null, -// 'isSuccess' => false, -// ]; -// } -// } - -if (! function_exists('store_file')) { - function store_file($file = null, $path, $disk = 'public') - { - if (filled($file) && $file && $file instanceof \Illuminate\Http\UploadedFile) { - $randomFilename = Str::random(35).time().'.'.$file->getClientOriginalExtension(); - $originalFileName = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)).'.'.$file->getClientOriginalExtension(); - - $file->storeAs($path, $randomFilename, $disk); - - return [ - 'randomFileName' => $randomFilename, - 'originalFileName' => $originalFileName, - 'isSuccess' => true, - ]; - } else { return [ 'randomFileName' => null, 'originalFileName' => null, + 'url' => null, 'isSuccess' => false, ]; } } -} -// if (!function_exists('display_file')) { -// function display_file($dir, $filename, $disk = null, $expirationMinutes = 60): string -// { -// $disk = $disk ?? env('FILESYSTEM_DISK', 'public'); + if (!function_exists('display_file')) { + function display_file($dir, $filename, $disk = null, $expirationMinutes = 60): string + { + $disk = $disk ?? env('FILESYSTEM_DISK', 'public'); -// if (!filled($filename)) { -// return '
Belum ditambahkan.
'; -// } + if (!filled($filename)) { + return 'Belum ditambahkan.
'; + } -// $path = "uploads/{$dir}/{$filename}"; + $path = "uploads/{$dir}/{$filename}"; -// try { -// $fileExists = is_file_exists($path, $disk); + try { + $fileExists = is_file_exists($path, $disk); -// if (!$fileExists) { -// return 'File tidak ditemukan.
'; -// } + if (!$fileExists) { + return 'File tidak ditemukan.
'; + } -// if ($disk === 's3') { -// $fileUrl = Storage::disk($disk)->temporaryUrl($path, now()->addMinutes($expirationMinutes)); -// } else { -// $fileUrl = Storage::disk($disk)->url($path); -// } + if ($disk === 's3') { + $fileUrl = Storage::disk($disk)->temporaryUrl($path, now()->addMinutes($expirationMinutes)); + } else { + $fileUrl = Storage::disk($disk)->url($path); + } -// $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); -// $mimeType = match ($ext) { -// 'jpg', 'jpeg', 'png', 'gif', 'webp' => 'image/' . $ext, -// 'pdf' => 'application/pdf', -// default => 'unknown', -// }; + $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + $mimeType = match ($ext) { + 'jpg', 'jpeg', 'png', 'gif', 'webp' => 'image/' . $ext, + 'pdf' => 'application/pdf', + default => 'unknown', + }; -// if (str_contains($mimeType, 'image')) { -// return "Format file tidak didukung
'; -// } catch (\Exception $e) { -// return 'Terjadi kesalahan saat menampilkan file.
'; -// } -// } -// } - -if (!function_exists('display_file')) { - function display_file($dir, $filename) - { - $path = storage_path("app/public/uploads/{$dir}/{$filename}"); - - if(!filled($filename)){ - return 'Belum ditambahkan.
'; + return 'Format file tidak didukung
'; + } catch (\Exception $e) { + return 'Terjadi kesalahan saat menampilkan file.
'; + } } - - if (!file_exists($path)) { - return 'File tidak ditemukan.
'; - } - - $mimeType = mime_content_type($path); - $fileUrl = asset("storage/uploads/{$dir}/{$filename}"); - - if (str_contains($mimeType, 'image')) { - return "Format file tidak didukung
'; } -} -// if (! function_exists('delete_file')) { -// function delete_file($path, $disk = null): bool -// { -// $disk = $disk ?? env('FILESYSTEM_DISK', 'public'); + if (! function_exists('delete_file')) { + function delete_file($path, $disk = null): bool + { + $disk = $disk ?? env('FILESYSTEM_DISK', 'public'); -// try { -// if(is_file_exists($path)){ -// return Storage::disk($disk)->delete($path); -// }else{ -// return false; -// } -// } catch (\Exception $e) { -// return false; -// } -// } -// } - -if (! function_exists('delete_file')) { - function delete_file($path) - { - // Menggunakan public_path untuk file yang berada di dalam storage/public - $fullPath = public_path('storage/' . $path); - - if (File::exists($fullPath)) { - File::delete($fullPath); - return true; + try { + if(is_file_exists($path)){ + return Storage::disk($disk)->delete($path); + }else{ + return false; + } + } catch (\Exception $e) { + return false; + } } - - return false; } -} -// if (!function_exists('is_file_exists')) { -// function is_file_exists($path, $disk = null): bool -// { -// $disk = $disk ?? env('FILESYSTEM_DISK', 'public'); + if (!function_exists('is_file_exists')) { + function is_file_exists($path, $disk = null): bool + { + $disk = $disk ?? env('FILESYSTEM_DISK', 'public'); -// try { -// $file = Storage::disk($disk)->get($path); -// return !empty($file); -// } catch (\Throwable $e) { -// return false; -// } -// } -// } + try { + $file = Storage::disk($disk)->get($path); + return !empty($file); + } catch (\Throwable $e) { + return false; + } + } + } +}else if(env('FILESYSTEM_DISK') === 'local'){ + if (! function_exists('store_file')) { + function store_file($file = null, $path, $disk = 'public') + { + if (filled($file) && $file && $file instanceof \Illuminate\Http\UploadedFile) { + $randomFilename = Str::random(35).time().'.'.$file->getClientOriginalExtension(); + $originalFileName = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)).'.'.$file->getClientOriginalExtension(); -if (! function_exists('is_file_exists')) { - function is_file_exists($path) - { - return File::exists(public_path('storage/' . $path)); + $file->storeAs($path, $randomFilename, $disk); + + return [ + 'randomFileName' => $randomFilename, + 'originalFileName' => $originalFileName, + 'isSuccess' => true, + ]; + } else { + return [ + 'randomFileName' => null, + 'originalFileName' => null, + 'isSuccess' => false, + ]; + } + } + } + + if (!function_exists('display_file')) { + function display_file($dir, $filename) + { + $path = storage_path("app/public/uploads/{$dir}/{$filename}"); + + if(!filled($filename)){ + return 'Belum ditambahkan.
'; + } + + if (!file_exists($path)) { + return 'File tidak ditemukan.
'; + } + + $mimeType = mime_content_type($path); + $fileUrl = asset("storage/uploads/{$dir}/{$filename}"); + + if (str_contains($mimeType, 'image')) { + return "Format file tidak didukung
'; + } + } + + if (! function_exists('delete_file')) { + function delete_file($path) + { + // Menggunakan public_path untuk file yang berada di dalam storage/public + $fullPath = public_path('storage/' . $path); + + if (File::exists($fullPath)) { + File::delete($fullPath); + return true; + } + + return false; + } + } + + if (! function_exists('is_file_exists')) { + function is_file_exists($path) + { + return File::exists(public_path('storage/' . $path)); + } } } diff --git a/app/Http/Controllers/Dashboard/CooperationArchiveController.php b/app/Http/Controllers/Dashboard/CooperationArchiveController.php new file mode 100644 index 0000000..d23b9dc --- /dev/null +++ b/app/Http/Controllers/Dashboard/CooperationArchiveController.php @@ -0,0 +1,52 @@ + 'Arsip Kerjasama', + 'date' => $request->input('date', null), + 'month' => $request->input('month', null), + 'year' => $request->input('year', null), + ]); + } + + public function export(Request $request) + { + + try{ + $year = $request->input('year', null); + $month = $request->input('month', null); + $date = $request->input('date', null); + + return Excel::download(new CooperationArchiveExport($year, $month, $date), 'cooperation-archive.xlsx'); + }catch(\Exception $e){ + return redirect()->back()->with('failed-status', 'Gagal melakukan proses export data.'); + } + + } + + public function filter(Request $request){ + + try{ + $filteredRequest = $request->except('_token'); + + $filterField = array_filter($filteredRequest, function ($value) { + return filled($value); + }); + + return redirect()->route('dashboard.cooperation.archives.index', $filterField); + }catch(\Exception $e){ + return redirect()->back()->with('status-failed', 'Gagal melakukan proses filtering data.'); + } + + + } +} diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index 39c10c9..a3b8c42 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -2092,6 +2092,108 @@ class="text-dark" } + public function cooperationArchive(Request $request){ + if ($request->ajax()) { + + $year = $request->input('year', null); + $month = $request->input('month', null); + $date = $request->input('date', null); + + $query = Cooperation::with(['media', 'mediaOrder']); + + if (is_role(['1'])) { + // Hanya untuk role 1: filter kerja sama lebih dari 1 tahun + if (!$year && !$month && !$date) { + $query->where('created_at', '<=', Carbon::now()->subYear()); + } + } else if (is_role(['3'])) { + $mediaId = Auth::user()->company->media->id; + + $query->whereHas('proposals', function ($query) use ($mediaId) { + $query->where('status', 1)->where('media_id', $mediaId); + }); + + if (!$year && !$month && !$date) { + $query->where('created_at', '<=', Carbon::now()->subYear()); + } + } + + if ($year) { + $query->whereYear('created_at', $year); + } + + if ($month) { + $monthYear = Carbon::parse($month); + $query->whereYear('created_at', $monthYear->year) + ->whereMonth('created_at', $monthYear->month); + } + + if ($date) { + $query->whereDate('created_at', $date); + } + + $data = $query->get(); + + + return DataTables::of($data) + ->addIndexColumn() + ->addColumn('name', function ($data) { + return '