diff --git a/app/Exports/CooperationCompletionExport.php b/app/Exports/CooperationCompletionExport.php new file mode 100644 index 0000000..e6b7f22 --- /dev/null +++ b/app/Exports/CooperationCompletionExport.php @@ -0,0 +1,124 @@ +media = $media; + $this->status = $status; + $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 = CooperationCompletion::with(['media.company']); + }else if(is_role(['3'])){ + $mediaId = Auth::user()->company->media->id; + $query = CooperationCompletion::with(['media.company', 'order.cooperation'])->where('media_id', '=', $mediaId); + } + + if (!empty($this->media[0])) { + $query->whereIn('media_id', $this->media); + } + + if ($this->status) { + switch($this->status){ + case 'waiting': + $query->where('status', '0'); + break; + case 'accepted': + $query->where('status', '1'); + break; + case 'rejected': + $query->where('status', '2'); + break; + } + } + + 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->created_at)->locale('id')->translatedFormat('l, d F Y'), + $report->status === '0' ? 'Menunggu' : ($report->status === '1' ? 'Diterima' : 'Ditolak'), + ]; + } + + public function headings(): array + { + return [ + ['Penyelesaian Kerja Sama', '', '', '', '', ''], + ['NO', 'Nama Kerjasama', 'Media', 'Perusahaan', 'Tanggal Upload', 'Status'] + ]; + } + + public function styles(Worksheet $sheet) + { + $sheet->mergeCells('A1:F1'); // A1 sampai F1 digabung + + // Set alignment untuk pusat horizontal dan vertikal + $sheet->getStyle('A1:F1')->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); + $sheet->getStyle('F:F')->getAlignment()->setWrapText(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/Exports/ReportExport.php b/app/Exports/ReportExport.php index 483546d..6d624d4 100644 --- a/app/Exports/ReportExport.php +++ b/app/Exports/ReportExport.php @@ -80,7 +80,7 @@ public function map($report): array public function headings(): array { return [ - ['Data Rekap Konten', '', '', '', '', '', '', ''], + ['Laporan Bukti Tayang', '', '', '', '', '', '', ''], ['NO', 'Nama Kerjasama', 'Media', 'Perusahaan', 'Tanggal Upload', 'Tanggal Melaporkan', 'Status'] ]; } diff --git a/app/Http/Controllers/Dashboard/CooperationCompletionController.php b/app/Http/Controllers/Dashboard/CooperationCompletionController.php index ec46d00..444c2dd 100644 --- a/app/Http/Controllers/Dashboard/CooperationCompletionController.php +++ b/app/Http/Controllers/Dashboard/CooperationCompletionController.php @@ -2,14 +2,19 @@ namespace App\Http\Controllers\Dashboard; +use App\Exports\CooperationCompletionExport; use App\Http\Controllers\Controller; use App\Http\Requests\CooperationCompletionRequest; use App\Models\Announcement; use App\Models\Cooperation; use App\Models\CooperationCompletion; +use App\Models\Media; +use Barryvdh\DomPDF\Facade\Pdf; +use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; +use Maatwebsite\Excel\Facades\Excel; class CooperationCompletionController extends Controller { @@ -17,8 +22,12 @@ class CooperationCompletionController extends Controller public function index(Request $request){ return view('dashboard.cooperation-completions.index', [ 'title' => 'Penyelesaian Kerjasama', + 'mediaCollection' => Media::all(), + 'media' => $request->input('media', []), + 'status' => $request->input('status', null), 'date' => $request->input('date', null), - 'month' => $request->input('month', null), + 'from_month' => $request->input('from_month', null), + 'to_month' => $request->input('to_month', null), 'year' => $request->input('year', null), ]); } @@ -190,4 +199,87 @@ public function rejectActionIndex(Request $request, $id){ return redirect()->back()->with('success-status', 'Berhasil menolak penyelesaian kerjasama.'); } + + public function export(Request $request) + { + try{ + $export_type = $request->input('export_type', 'excel'); + + $status = $request->input('status', null); + $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 CooperationCompletionExport($media, $status, $year, $from_month, $to_month, $date), 'reports-'.$formattedNow.'.xlsx'); + }elseif($export_type === 'pdf'){ + if(is_role(['1', '5'])){ + $query = CooperationCompletion::with(['media.company']); + }else if(is_role(['3'])){ + $mediaId = Auth::user()->company->media->id; + $query = CooperationCompletion::with(['media.company', 'order.cooperation'])->where('media_id', '=', $mediaId); + } + + if (!empty($media) && is_array($media)) { + $query->whereIn('media_id', $media); + } + + if ($status) { + switch($status){ + case 'waiting': + $query->where('status', '0'); + break; + case 'accepted': + $query->where('status', '1'); + break; + case 'rejected': + $query->where('status', '2'); + break; + } + } + + 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); + } + + $cooperationCompletions = $query->get(); + + $pdf = Pdf::loadView('dashboard.cooperation-completions.prints.collection', compact('cooperationCompletions')); + + 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{ + $cooperationCompletion = CooperationCompletion::with(['media.company'])->first(); + // dd('hai'); + + $pdf = Pdf::loadView('dashboard.cooperation-completions.prints.single', compact('cooperationCompletion')); + + + return $pdf->stream(slugify('Penyelesaian kerja sama '. $cooperationCompletion->media->name).'.pdf'); + }catch(\Exception $e){ + return redirect()->back()->with('failed-status', 'Gagal melakukan proses print data.'); + } + } } diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index 57eeed7..b487a08 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -2126,13 +2126,58 @@ class="text-dark" public function cooperationCompletionIndex(Request $request){ if ($request->ajax()) { + $mediaStrArr = $request->input('media', null); + $media = explode(',', $mediaStrArr); + + $status = $request->input('status', 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(is_role(['1', '5'])){ - $data = CooperationCompletion::with(['media.company'])->get(); + $query = CooperationCompletion::with(['media.company']); }else if(is_role(['3'])){ $mediaId = Auth::user()->company->media->id; - $data = CooperationCompletion::with(['media.company', 'order.cooperation'])->where('media_id', '=', $mediaId)->get(); + $query = CooperationCompletion::with(['media.company', 'order.cooperation'])->where('media_id', '=', $mediaId); } + if (!empty($media[0])) { + $query->whereIn('media_id', $media); + } + + if ($status) { + switch($status){ + case 'waiting': + $query->where('status', '0'); + break; + case 'accepted': + $query->where('status', '1'); + break; + case 'rejected': + $query->where('status', '2'); + break; + } + } + + 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) { @@ -2169,6 +2214,8 @@ class="text-dark" $processUrl = route('dashboard.cooperation.completions.process.index', ['id' => encrypt_id($data->id)]); + $printUrl = route('dashboard.cooperation.completions.print.single', ['id' => encrypt_id($data->id)]); + // $rejectUrl = route('dashboard.cooperation.completions.reject', ['id' => encrypt_id($data->id)]); $dropdown = '