diff --git a/app/Exports/CooperationExport.php b/app/Exports/CooperationExport.php index 7f1c9ed..579784d 100644 --- a/app/Exports/CooperationExport.php +++ b/app/Exports/CooperationExport.php @@ -77,7 +77,7 @@ public function headings(): array { return [ ['Data Rekap Konten', '', '', '', '', '', ''], - ['NO', 'Nama Kerjasama', 'Taanggal Mulai', 'Tanggal Selesai', 'Deskripsi', 'Media', 'Dibuat Pada'] + ['NO', 'Nama Kerjasama', 'Tanggal Mulai', 'Tanggal Selesai', 'Deskripsi', 'Media', 'Dibuat Pada'] ]; } diff --git a/app/Exports/ReportExport.php b/app/Exports/ReportExport.php new file mode 100644 index 0000000..483546d --- /dev/null +++ b/app/Exports/ReportExport.php @@ -0,0 +1,111 @@ +media = $media; + $this->year = $year; + $this->from_month = $from_month; + $this->to_month = $to_month; + $this->date = $date; + } + + public function collection() + { + if(is_role(['1', '5'])){ + $query = Report::with(['media.company', 'order.cooperation']); + }else if(is_role(['3'])){ + $mediaId = Auth::user()->company->media->id; + $query = Report::with(['media.company', 'order.cooperation'])->where('media_id', '=', $mediaId); + } + + if (!empty($this->media) && is_array($this->media)) { + $query->whereIn('media_id', $this->media); + } + + if ($this->year) { + $query->whereYear('created_at', $this->year); + } + + if ($this->from_month && $this->to_month) { + $start = Carbon::parse($this->from_month)->startOfMonth(); + $end = Carbon::parse($this->to_month)->endOfMonth(); + + $query->whereBetween('created_at', [$start, $end]); + } + + if ($this->date) { + $query->whereDate('created_at', $this->date); + } + + return $query->get(); + } + + public function map($report): array + { + return [ + $this->no++, + $report->order->cooperation->name, + $report->media->name, + $report->media->company->name, + Carbon::parse($report->publication_date)->locale('id')->translatedFormat('l, d F Y'), + Carbon::parse($report->created_at)->locale('id')->translatedFormat('l, d F Y'), + $report->status === '0' ? 'Menunggu' : ($report->status === '1' ? 'Diterima' : 'Ditolak'), + ]; + } + + public function headings(): array + { + return [ + ['Data Rekap Konten', '', '', '', '', '', '', ''], + ['NO', 'Nama Kerjasama', 'Media', 'Perusahaan', 'Tanggal Upload', 'Tanggal Melaporkan', 'Status'] + ]; + } + + public function styles(Worksheet $sheet) + { + $sheet->mergeCells('A1:G1'); // A1 sampai G1 digabung + + // Set alignment untuk pusat horizontal dan vertikal + $sheet->getStyle('A1:G1')->getAlignment()->setHorizontal('center'); + $sheet->getStyle('A1:G1')->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); + $sheet->getColumnDimension('G')->setAutoSize(true); + $sheet->getStyle('G:G')->getAlignment()->setWrapText(true); + + $sheet->getColumnDimension('G')->setAutoSize(true); + + // Menambahkan gaya lain jika diperlukan + $sheet->getStyle('A1:G1')->getFont()->setBold(true); + $sheet->getStyle('A1:G1')->getFont()->setSize(14); + } +} diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index a2b2f6c..57eeed7 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -23,6 +23,7 @@ use App\Models\MediaOrder; use App\Models\News; use App\Models\Order; +use App\Models\Report; use App\Models\Role; use App\Models\SubClassification; use App\Models\SubLocation; @@ -2199,6 +2200,121 @@ class="text-dark" } + public function reportIndex(Request $request){ + if ($request->ajax()) { + + $mediaStrArr = $request->input('media', null); + $media = explode(',', $mediaStrArr); + + $year = $request->input('year', null); + $from_month = $request->input('from_month', null); + $to_month = $request->input('to_month', null); + $date = $request->input('date', null); + + if(is_role(['1', '5'])){ + $query = Report::with(['media.company', 'order.cooperation']); + }else if(is_role(['3'])){ + $mediaId = Auth::user()->company->media->id; + $query = Report::with(['media.company', 'order.cooperation'])->where('media_id', '=', $mediaId); + } + + if (!empty($media[0])) { + $query->whereIn('media_id', $media); + } + + if ($year) { + $query->whereYear('created_at', $year); + } + + if ($from_month && $to_month) { + $start = Carbon::parse($from_month)->startOfMonth(); + $end = Carbon::parse($to_month)->endOfMonth(); + + $query->whereBetween('created_at', [$start, $end]); + } + + if ($date) { + $query->whereDate('created_at', $date); + } + + $data = $query->get(); + + return DataTables::of($data) + ->addIndexColumn() + ->addColumn('cooperation', function ($data) use ($media) { + return $data->order->cooperation->name; + }) + ->addColumn('media_name', function ($data) { + return $data->media->name; + }) + ->addColumn('company_name', function ($data) { + return $data->media->company->name; + }) + ->addColumn('email', function ($data) { + return $data->media->company->email; + }) + ->addColumn('date', function ($data){ + return idn_date($data->created_at, 'l, d F Y'); + }) + ->addColumn('status', function ($data) { + switch($data->status){ + case 0: + return 'Menunggu'; + case 1: + return 'Diterima'; + case 2: + return 'Ditolak + + '; + default: + return 'Tidak Diketahui'; + } + }) + ->addColumn('action', function ($data){ + $showUrl = route('dashboard.reports.show.index', ['id' => encrypt_id($data->id)]); + + $printUrl = route('dashboard.reports.print.single', ['id' => encrypt_id($data->id)]); + + $processUrl = route('dashboard.reports.process.index', ['id' => encrypt_id($data->id)]); + + // $rejectUrl = route('dashboard.cooperation.completions.reject', ['id' => encrypt_id($data->id)]); + + $dropdown = ''; + + return $dropdown; + }) + + ->rawColumns(['status', 'action']) + ->make(true); + } + + return response()->json(['error' => 'Unauthorized'], 401); + + } + public function cooperationArchive(Request $request){ if ($request->ajax()) { diff --git a/app/Http/Controllers/Dashboard/ReportController.php b/app/Http/Controllers/Dashboard/ReportController.php index c6d5fed..479363b 100644 --- a/app/Http/Controllers/Dashboard/ReportController.php +++ b/app/Http/Controllers/Dashboard/ReportController.php @@ -2,15 +2,33 @@ namespace App\Http\Controllers\Dashboard; +use App\Exports\ReportExport; use App\Http\Controllers\Controller; use App\Http\Requests\ReportRequest; use App\Models\Announcement; +use App\Models\Media; use App\Models\Report; +use Barryvdh\DomPDF\Facade\Pdf; +use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Maatwebsite\Excel\Facades\Excel; class ReportController extends Controller { + + public function index(Request $request){ + return view('dashboard.reports.index', [ + 'mediaCollection' => Media::all(), + 'title' => 'Laporan Bukti Tayang', + 'media' => $request->input('media', []), + 'date' => $request->input('date', null), + 'from_month' => $request->input('from_month', null), + 'to_month' => $request->input('to_month', null), + 'year' => $request->input('year', null), + ]); + } + public function create($id){ return view('dashboard.reports.create', [ 'title' => 'Buat Laporan', @@ -83,6 +101,24 @@ public function show($mediaOrderId, $id){ ]); } + public function showIndex($id){ + $report = Report::findOrFail(decrypt_id($id)); + + return view('dashboard.reports.index.show', [ + 'title' => 'Detail Penyelesaian Kerjasama', + 'report' => $report + ]); + } + + public function processIndex($id){ + $report = Report::findOrFail(decrypt_id($id)); + + return view('dashboard.reports.index.process', [ + 'title' => 'Detail Penyelesaian Kerjasama', + 'report' => $report + ]); + } + public function accept($id){ $report = Report::findOrFail(decrypt_id($id)); @@ -152,6 +188,41 @@ public function rejectAction(Request $request, $mediaOrderId, $id){ } } + public function rejectActionIndex(Request $request, $id){ + $validatedData = $request->validate([ + 'rejection_reason' => ['required'], + ], [ + 'rejection_reason.required' => 'Alasan penolakan wajib diisi.', + ]); + + try{ + $report = Report::findOrFail(decrypt_id($id)); + + $rejectedReport = $report->update([ + 'status' => '2', + 'rejection_reason' => $validatedData['rejection_reason'] + ]); + + // Announcements + $announcementData = [ + 'headline' => 'Laporan bukti tayang kerjasama '. $report->order->cooperation->name .' telah ditolak', + 'content' => '

Admin telah menolak laporan bukti tayang Anda.

', + 'enhancer_id' => Auth::id() + ]; + $createdAnnouncement = Announcement::create($announcementData); + $createdAnnouncement->users()->attach($report->media->company->user->id, ['category' => 'system']); + // End Announcements + + if ($rejectedReport) { + return redirect()->back()->with('success-status', 'Berhasil menolak laporan bukti tayang.'); + } else { + return redirect()->back()->with('failed-status', 'Gagal menolak laporan bukti tayang'); + } + }catch(\Exception $e){ + return redirect()->back()->with('failed-status', 'Gagal menolak laporan bukti tayang'); + } + } + public function destroy($id){ try { $report = Report::findOrFail(decrypt_id($id)); @@ -175,4 +246,70 @@ public function checkLink(Request $request) 'exists' => $linkExists ]); } + + public function export(Request $request) + { + try{ + $export_type = $request->input('export_type', 'excel'); + + $media = $request->input('media', null); + $year = $request->input('year', null); + $from_month = $request->input('from_month', null); + $to_month = $request->input('to_month', null); + $date = $request->input('date', null); + + if($export_type === 'excel'){ + $formattedNow = Carbon::parse(now())->locale('id')->translatedFormat('d-m-Y'); + return Excel::download(new ReportExport($media, $year, $from_month, $to_month, $date), 'reports-'.$formattedNow.'.xlsx'); + }elseif($export_type === 'pdf'){ + if(is_role(['1', '5'])){ + $query = Report::with(['media.company', 'order.cooperation']); + }else if(is_role(['3'])){ + $mediaId = Auth::user()->company->media->id; + $query = Report::with(['media.company', 'order.cooperation'])->where('media_id', '=', $mediaId); + } + + if (!empty($media) && is_array($media)) { + $query->whereIn('media_id', $media); + } + + if ($year) { + $query->whereYear('created_at', $year); + } + + if ($from_month && $to_month) { + $start = Carbon::parse($from_month)->startOfMonth(); + $end = Carbon::parse($to_month)->endOfMonth(); + + $query->whereBetween('created_at', [$start, $end]); + } + + if ($date) { + $query->whereDate('created_at', $date); + } + + $reports = $query->get(); + + $pdf = Pdf::loadView('dashboard.reports.prints.collection', compact('reports')); + + return $pdf->stream(slugify('laporan bukti tayang ').'.pdf'); + } + + }catch(\Exception $e){ + return redirect()->back()->with('failed-status', 'Gagal melakukan proses export data.'); + } + + } + + public function singlePrint(){ + try{ + $report = Report::with(['media.company', 'order.cooperation'])->first(); + + $pdf = Pdf::loadView('dashboard.reports.prints.single', compact('report')); + + return $pdf->stream(slugify('laporan bukti tayang '. $report->title. ' '. $report->media->name).'.pdf'); + }catch(\Exception $e){ + return redirect()->back()->with('failed-status', 'Gagal melakukan proses print data.'); + } + } } diff --git a/resources/views/dashboard/cooperation-completions/index.blade.php b/resources/views/dashboard/cooperation-completions/index.blade.php index 8379fe6..1b9f29f 100644 --- a/resources/views/dashboard/cooperation-completions/index.blade.php +++ b/resources/views/dashboard/cooperation-completions/index.blade.php @@ -90,7 +90,7 @@
- +
@@ -130,7 +130,7 @@
- +
diff --git a/resources/views/dashboard/reports/index.blade.php b/resources/views/dashboard/reports/index.blade.php new file mode 100644 index 0000000..1c09f5d --- /dev/null +++ b/resources/views/dashboard/reports/index.blade.php @@ -0,0 +1,225 @@ +@include('partials.dashboard.head') +@include('partials.dashboard.sidebar', ['page' => 'reports']) +@include('partials.dashboard.header') + +
+
+
+
+
+
+
+

{{$title}}

+
+ @if (is_role(['1'])) +
+
+ +
+ +
+
+
+ @endif +
+
+ {{-- {{dd($media)}} --}} +
+
+
+
+ + + + + + + + + {{-- + --}} + + + + +
NoKerjasamaPerusahanMediaTanggal MelaporTanggal Mulai PengajuanTanggal Akhir PengajuanStatus
+
+
+
+
+ + +
+
+
+
+ +@include('partials.dashboard.footer' ,['datatable' => 'report_index']) diff --git a/resources/views/dashboard/reports/index/process.blade.php b/resources/views/dashboard/reports/index/process.blade.php new file mode 100644 index 0000000..9977c4b --- /dev/null +++ b/resources/views/dashboard/reports/index/process.blade.php @@ -0,0 +1,183 @@ +@include('partials.dashboard.head') +@include('partials.dashboard.sidebar', ['page' => 'reports']) +@include('partials.dashboard.header') + +
+
+
+
+
+
+
+
+ +
+
+ {{--
+
Personal Information
+

Basic info, like your name and address, that you use on Nio Platform.

+
--}} +
+
+
+ Judul Konten + {{$report->title}} +
+
+
+
+ Tanggal Publikasi + {{idn_date($report->publication_date, 'l, d F Y')}} +
+
+
+
+ Link + + @if ($report->link != '') + {{$report->link}} + @else + - + @endif + +
+
+
+
+ Status + + @if ($report->status === '0') + Menunggu + @elseif($report->status === '1') + Menerima + @elseif($report->status === '2') + Ditolak + @else + Tidak Diketahui + @endif + +
+
+
+
+ Tanggal Melaporkan + {{idn_date($report->created_at, 'l, d F Y')}} +
+
+
+
+
+
+ Deskripsi +
+
+
+
+ {!!$report->description!!} +
+
+
+
+
+
+ Gambar +
+
+
+
+ @if (is_file_exists('uploads/reports/'.$report->proof)) + + @else + Tidak ada gambar + @endif +
+
+
+
+ @if ($report->status !== '2') +
+ Kembali + @if ($report->status === '0') + + Tolak + + + Terima + + @endif +
+ @endif +
+
+
+
+ @if ($report->status === '2') +
+ +
+ {{-- {{dd($mediaCooperationPivot->status != '0')}} --}} +
+ @csrf +
+ +
+
+
+ {!!$report->rejection_reason!!} +
+
+
+
+
+
+ Kembali +
+
+
+
+ @endif + +
+
+
+
+
+ +@include('partials.dashboard.footer', ['rich_editor' => false]) diff --git a/resources/views/dashboard/reports/index/show.blade.php b/resources/views/dashboard/reports/index/show.blade.php new file mode 100644 index 0000000..abe1507 --- /dev/null +++ b/resources/views/dashboard/reports/index/show.blade.php @@ -0,0 +1,145 @@ +@include('partials.dashboard.head') +@include('partials.dashboard.sidebar', ['page' => 'reports']) +@include('partials.dashboard.header') + +
+
+
+
+
+
+
+
+ +
+
+ {{--
+
Personal Information
+

Basic info, like your name and address, that you use on Nio Platform.

+
--}} +
+
+
+ Judul Konten + {{$report->title}} +
+
+
+
+ Tanggal Publikasi + {{idn_date($report->publication_date, 'l, d F Y')}} +
+
+
+
+ Link + + @if ($report->link != '') + {{$report->link}} + @else + - + @endif + +
+
+
+
+ Status + + @if ($report->status === '0') + Menunggu + @elseif($report->status === '1') + Menerima + @elseif($report->status === '2') + Ditolak + @else + Tidak Diketahui + @endif + +
+
+
+
+ Tanggal Melaporkan + {{idn_date($report->created_at, 'l, d F Y')}} +
+
+
+
+
+
+ Deskripsi +
+
+
+
+ {!!$report->description!!} +
+
+
+
+
+
+ Gambar +
+
+
+
+ @if (is_file_exists('uploads/reports/'.$report->proof)) + + @else + Tidak ada gambar + @endif +
+
+
+
+ @if ($report->status !== '2') +
+ Kembali +
+ @endif +
+
+
+
+ @if ($report->status === '2') +
+ +
+ {{-- {{dd($mediaCooperationPivot->status != '0')}} --}} +
+ @csrf +
+ +
+
+
+ {!!$report->rejection_reason!!} +
+
+
+
+
+
+ Kembali +
+
+
+
+ @endif +
+
+
+
+
+ +@include('partials.dashboard.footer', ['rich_editor' => false]) diff --git a/resources/views/dashboard/reports/prints/collection.blade.php b/resources/views/dashboard/reports/prints/collection.blade.php new file mode 100644 index 0000000..b754823 --- /dev/null +++ b/resources/views/dashboard/reports/prints/collection.blade.php @@ -0,0 +1,177 @@ + + + + + Laporan Bukti Tayang + + + +
+
+ Logo +
+
+ +
+
+

Laporan Bukti Tayang

+
+ + + + + + + + + + + + + + + + + @foreach($reports as $i => $report) + + + + + + + + + + + + @endforeach + +
NoKerja SamaMediaPerusahaanLinkTgl PublikasiTgl MelaporStatusBukti
{{ $i + 1 }}{{ $report->order->cooperation->name }}{{ $report->media->name }}{{ $report->media->company->name }}{{ \Carbon\Carbon::parse($report->publication_date)->locale('id')->translatedFormat('l, d F Y') }}{{ \Carbon\Carbon::parse($report->created_at)->locale('id')->translatedFormat('l, d F Y') }} + @if ($report->status === '0') + Menunggu + @elseif ($report->status === '1') + Diterima + @elseif ($report->status === '2') + Ditolak + @endif + + @php + $ext = pathinfo($report->proof, PATHINFO_EXTENSION); + @endphp + @if($report->proof) + @if(in_array(strtolower($ext), ['jpg', 'jpeg', 'png', 'gif', 'webp'])) + Bukti + @elseif(strtolower($ext) === 'pdf') + Lihat PDF + @else + Tidak dikenali + @endif + @else + Tidak ada + @endif +
+ + +
+ + diff --git a/resources/views/dashboard/reports/prints/single.blade.php b/resources/views/dashboard/reports/prints/single.blade.php new file mode 100644 index 0000000..d4674a6 --- /dev/null +++ b/resources/views/dashboard/reports/prints/single.blade.php @@ -0,0 +1,208 @@ + + + + + Laporan Bukti Tayang {{$report->media->name}} + + + +
+
+ +
+
+
+
+

Laporan Bukti Tayang

+ {{--

{{ $report->content_theme }}

--}} +
+ +
+
+
Kerja Sama
+
{{ $report->order->cooperation->name }}
+
+
+
Media
+
{{ $report->media->name }}
+
+
+
Perusahaan
+
{{ $report->media->company->name }}
+
+
+
Link
+
+ @if (filled(($report->link))) + {{$report->link}} + @else + Tidak ada link + @endif +
+
+
+
Tanggal Publikasi
+
{{ idn_date($report->publication_date, format: 'l, d F Y') }}
+
+
+
Tanggal Melaporkan
+
{{ idn_date($report->created_at, 'l, d F Y') }}
+
+
+
Status
+
+ @if ($report->status === '0') + Menunggu + @elseif ($report->status === '1') + Diterima + @elseif ($report->status === '2') + Ditolak + @endif +
+
+
+ + {{-- Dokumen --}} +
+ + @php + $documents = [ + 'Bukti (Gambar)' => $report->proof, + ]; + @endphp + + @foreach($documents as $label => $doc) +
+ {{ $label }}
+
+ @if($doc) + @php + $ext = pathinfo($doc, PATHINFO_EXTENSION); + @endphp + @if(in_array(strtolower($ext), ['jpg', 'jpeg', 'png', 'gif', 'webp'])) + {{ + @elseif(strtolower($ext) === 'pdf') + Lihat Dokumen PDF + @else + File tidak dikenali. + @endif + @else + Tidak Ada Dokumen + @endif +
+
+ @endforeach +
+ + +
+ + diff --git a/resources/views/dashboard/reports/show.blade.php b/resources/views/dashboard/reports/show.blade.php index 8478025..2d26818 100644 --- a/resources/views/dashboard/reports/show.blade.php +++ b/resources/views/dashboard/reports/show.blade.php @@ -55,13 +55,19 @@ @elseif($report->status === '1') Menerima @elseif($report->status === '2') - Menolak + Ditolak @else Tidak Diketahui @endif
+
+
+ Tanggal Melaporkan + {{idn_date($report->created_at, 'l, d F Y')}} +
+
diff --git a/resources/views/partials/app/datatable.blade.php b/resources/views/partials/app/datatable.blade.php index eb1bc22..5e3595e 100644 --- a/resources/views/partials/app/datatable.blade.php +++ b/resources/views/partials/app/datatable.blade.php @@ -1010,6 +1010,46 @@ @endif +@if ($datatable === 'report_index') + +@endif + @if ($datatable === 'cooperation_archive') + diff --git a/resources/views/partials/dashboard/sidebar.blade.php b/resources/views/partials/dashboard/sidebar.blade.php index eea7270..85091d6 100644 --- a/resources/views/partials/dashboard/sidebar.blade.php +++ b/resources/views/partials/dashboard/sidebar.blade.php @@ -143,6 +143,12 @@ Kerjasama Media +
  • + + + Laporan Bukti Tayang + +
  • diff --git a/resources/views/partials/homepage/header.blade.php b/resources/views/partials/homepage/header.blade.php index be2f6df..97ded7d 100644 --- a/resources/views/partials/homepage/header.blade.php +++ b/resources/views/partials/homepage/header.blade.php @@ -43,7 +43,7 @@
    - Search +