chore: add filter and export cooperation data
This commit is contained in:
parent
74fe0c05a6
commit
99f725b102
@ -17,7 +17,7 @@ class CooperationArchiveExport implements FromCollection, WithHeadings, WithStyl
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
|
||||
protected $no = 1;
|
||||
protected $no = 1;
|
||||
protected $year;
|
||||
protected $month;
|
||||
protected $date;
|
||||
@ -74,7 +74,7 @@ public function map($cooperationArchive): array
|
||||
$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,
|
||||
strip_tags($cooperationArchive->description),
|
||||
Carbon::parse($cooperationArchive->created_at)->locale('id')->translatedFormat('l, d F Y'),
|
||||
];
|
||||
}
|
||||
|
||||
106
app/Exports/CooperationExport.php
Normal file
106
app/Exports/CooperationExport.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Cooperation;
|
||||
use App\Models\Media;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class CooperationExport implements FromCollection, WithHeadings, WithStyles, WithMapping
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
|
||||
protected $no = 1;
|
||||
protected $year;
|
||||
protected $month;
|
||||
protected $date;
|
||||
|
||||
public function __construct($year, $month, $date)
|
||||
{
|
||||
$this->year = $year;
|
||||
$this->month = $month;
|
||||
$this->date = $date;
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
$query = Cooperation::with(['media', 'mediaOrder']);
|
||||
|
||||
if (is_role(['3'])) {
|
||||
$mediaId = Auth::user()->company->media->id;
|
||||
|
||||
$query->whereHas('proposals', function ($q) use ($mediaId) {
|
||||
$q->where('status', 1)
|
||||
->where('media_id', $mediaId);
|
||||
});
|
||||
}
|
||||
|
||||
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($cooperation): array
|
||||
{
|
||||
return [
|
||||
$this->no++,
|
||||
$cooperation->name,
|
||||
Carbon::parse($cooperation->start_date)->locale('id')->translatedFormat('l, d F Y'),
|
||||
Carbon::parse($cooperation->end_date)->locale('id')->translatedFormat('l, d F Y'),
|
||||
strip_tags($cooperation->description),
|
||||
$cooperation->media->pluck('name')->implode(', '),
|
||||
Carbon::parse($cooperation->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', 'Media', 'Dibuat Pada']
|
||||
];
|
||||
}
|
||||
|
||||
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->getStyle('F:F')->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);
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,7 @@ public function export(Request $request)
|
||||
$month = $request->input('month', null);
|
||||
$date = $request->input('date', null);
|
||||
|
||||
return Excel::download(new CooperationArchiveExport($year, $month, $date), 'cooperation-archive.xlsx');
|
||||
return Excel::download(new CooperationArchiveExport($year, $month, $date), 'cooperation-archives.xlsx');
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('failed-status', 'Gagal melakukan proses export data.');
|
||||
}
|
||||
|
||||
@ -1405,17 +1405,48 @@ public function journalistSubmission(Request $request, $role){
|
||||
public function cooperation(Request $request){
|
||||
if ($request->ajax()) {
|
||||
|
||||
if(is_role(['1'])){
|
||||
$data = Cooperation::with(['media', 'mediaOrder'])->get();
|
||||
}else if(is_role(['3'])){
|
||||
$year = $request->input('year', null);
|
||||
$month = $request->input('month', null);
|
||||
$date = $request->input('date', null);
|
||||
|
||||
// if(is_role(['1'])){
|
||||
// $data = Cooperation::with(['media', 'mediaOrder'])->get();
|
||||
// }else if(is_role(['3'])){
|
||||
// $mediaId = Auth::user()->company->media->id;
|
||||
// $media = Media::findOrFail($mediaId);
|
||||
// $data = $media->cooperations->filter(function ($cooperation) use ($mediaId){
|
||||
// // Filter cooperation berdasarkan status proposal yang 1
|
||||
// return $cooperation->proposals->where('status', 1)->where('media_id', $mediaId)->isNotEmpty();
|
||||
// });
|
||||
// }
|
||||
|
||||
$query = Cooperation::with(['media', 'mediaOrder']);
|
||||
|
||||
if (is_role(['3'])) {
|
||||
$mediaId = Auth::user()->company->media->id;
|
||||
$media = Media::findOrFail($mediaId);
|
||||
$data = $media->cooperations->filter(function ($cooperation) use ($mediaId){
|
||||
// Filter cooperation berdasarkan status proposal yang 1
|
||||
return $cooperation->proposals->where('status', 1)->where('media_id', $mediaId)->isNotEmpty();
|
||||
|
||||
$query->whereHas('proposals', function ($q) use ($mediaId) {
|
||||
$q->where('status', 1)
|
||||
->where('media_id', $mediaId);
|
||||
});
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Exports\CooperationExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\CooperationRequest;
|
||||
use App\Models\Announcement;
|
||||
@ -9,16 +10,21 @@
|
||||
use App\Models\CooperationProposal;
|
||||
use App\Models\Media;
|
||||
use App\Models\MediaOrder;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class MediaCooperationController extends Controller
|
||||
{
|
||||
public function index(){
|
||||
public function index(Request $request){
|
||||
return view('dashboard.media-cooperations.index', [
|
||||
'title' => 'Kerjasama'
|
||||
'title' => 'Kerjasama',
|
||||
'date' => $request->input('date', null),
|
||||
'month' => $request->input('month', null),
|
||||
'year' => $request->input('year', null),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -162,6 +168,39 @@ public function show($id){
|
||||
]);
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
|
||||
try{
|
||||
$year = $request->input('year', null);
|
||||
$month = $request->input('month', null);
|
||||
$date = $request->input('date', null);
|
||||
|
||||
$formattedNow = Carbon::parse(now())->locale('id')->translatedFormat('d-m-Y');
|
||||
return Excel::download(new CooperationExport($year, $month, $date), 'cooperations-'.$formattedNow.'.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.cooperations.index', $filterField);
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('status-failed', 'Gagal melakukan proses filtering data.');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function mediaProposal($id){
|
||||
$mediaCooperation = Cooperation::with(['media'])->findOrFail(decrypt_id($id));
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
</li> --}}
|
||||
{{-- <li class="nk-block-tools-opt"><a href="{{route('dashboard.cooperations.create')}}" class="btn btn-primary"><em class="icon ni ni-plus"></em><span>Tambah</span></a></li> --}}
|
||||
<li>
|
||||
@if (filled(value: $year))
|
||||
@if (filled(value: $date) || filled(value: $month) ||filled(value: $year))
|
||||
<span class="mx-1">
|
||||
<a href="{{route('dashboard.cooperation.archives.index')}}" class="text-secondary">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" class="icon icon-tabler icons-tabler-filled icon-tabler-xbox-x"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 2c5.523 0 10 4.477 10 10s-4.477 10 -10 10s-10 -4.477 -10 -10s4.477 -10 10 -10m3.6 5.2a1 1 0 0 0 -1.4 .2l-2.2 2.933l-2.2 -2.933a1 1 0 1 0 -1.6 1.2l2.55 3.4l-2.55 3.4a1 1 0 1 0 1.6 1.2l2.2 -2.933l2.2 2.933a1 1 0 0 0 1.6 -1.2l-2.55 -3.4l2.55 -3.4a1 1 0 0 0 -.2 -1.4" /></svg>
|
||||
|
||||
@ -29,6 +29,23 @@
|
||||
</div>
|
||||
</div>
|
||||
</li> --}}
|
||||
<li>
|
||||
@if (filled(value: $date) || filled(value: $month) ||filled(value: $year))
|
||||
<span class="mx-1">
|
||||
<a href="{{route('dashboard.cooperations.index')}}" class="text-secondary">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" class="icon icon-tabler icons-tabler-filled icon-tabler-xbox-x"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 2c5.523 0 10 4.477 10 10s-4.477 10 -10 10s-10 -4.477 -10 -10s4.477 -10 10 -10m3.6 5.2a1 1 0 0 0 -1.4 .2l-2.2 2.933l-2.2 -2.933a1 1 0 1 0 -1.6 1.2l2.55 3.4l-2.55 3.4a1 1 0 1 0 1.6 1.2l2.2 -2.933l2.2 2.933a1 1 0 0 0 1.6 -1.2l-2.55 -3.4l2.55 -3.4a1 1 0 0 0 -.2 -1.4" /></svg>
|
||||
</a>
|
||||
</span>
|
||||
@endif
|
||||
<div>
|
||||
<a href="javascript: void(0);" class="btn btn-white btn-dim btn-outline-light" data-bs-toggle="modal" data-bs-target="#modalFilter"><em class="d-none d-sm-inline icon ni ni-filter"></em><span><span class="d-none d-md-inline">Filter</a>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div>
|
||||
<a href="javascript: void(0);" class="btn btn-info" data-bs-toggle="modal" data-bs-target="#modalExport"><em class="d-none d-sm-inline icon ni ni-upload"></em><span><span class="d-none d-md-inline">Export</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nk-block-tools-opt"><a href="{{route('dashboard.cooperations.create')}}" class="btn btn-primary"><em class="icon ni ni-plus"></em><span>Tambah</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -58,6 +75,86 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="modalFilter">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Filter</h5>
|
||||
<a href="javascript:void(0);" class="close" data-bs-dismiss="modal" aria-label="Close">
|
||||
<em class="icon ni ni-cross"></em>
|
||||
</a>
|
||||
</div>
|
||||
<form action="{{route('dashboard.cooperations.filter')}}" class="form-validate is-alter" method="post">
|
||||
@csrf
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="year">Tahun</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="number" class="form-control" id="year" placeholder="Data kerjasama pada tahun" name="year" value="{{ old('year', $year ?? '') }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="month">Bulan</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="month" class="form-control" id="month" placeholder="Data berita pada bulan dan tahun" name="month" value="{{ old('month', $month ?? '') }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="date">Tanggal</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="date" class="form-control" id="date" placeholder="Data berita pada bulan dan tahun" name="date" value="{{ old('date', $date ?? '') }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer bg-light">
|
||||
<span class="sub-text">
|
||||
<button type="submit" class="btn btn-sm btn-primary">Filter</button>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="modalExport">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Export</h5>
|
||||
<a href="javascript:void(0);" class="close" data-bs-dismiss="modal" aria-label="Close">
|
||||
<em class="icon ni ni-cross"></em>
|
||||
</a>
|
||||
</div>
|
||||
<form action="{{route('dashboard.cooperations.export')}}" class="form-validate is-alter" method="post">
|
||||
@csrf
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="year">Tahun</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="number" class="form-control" id="year" placeholder="Data kerjasama pada tahun" name="year" value="{{ old('year', $year ?? '') }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="month">Bulan</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="month" class="form-control" id="month" placeholder="Data berita pada bulan dan tahun" name="month" value="{{ old('month', $month ?? '') }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="date">Tanggal</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="date" class="form-control" id="date" placeholder="Data berita pada bulan dan tahun" name="date" value="{{ old('date', $date ?? '') }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer bg-light">
|
||||
<span class="sub-text">
|
||||
<button type="submit" class="btn btn-sm btn-primary">Export</button>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -709,7 +709,15 @@
|
||||
$('#cooperationsTable').DataTable({
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
ajax: '{{ route('dashboard.cooperations.data') }}',
|
||||
ajax: {
|
||||
url: '{{ route('dashboard.cooperations.data') }}',
|
||||
type: 'GET',
|
||||
data: function(d) {
|
||||
d.year = '{{ $year }}';
|
||||
d.month = '{{ $month }}';
|
||||
d.date = '{{ $date }}';
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
{ data: 'DT_RowIndex', name: 'DT_RowIndex', orderable: false, searchable: false },
|
||||
{ data: 'name', name: 'name' },
|
||||
@ -753,7 +761,7 @@
|
||||
{ data: 'id', name: 'id', orderable: true, searchable: false, visible: false },
|
||||
],
|
||||
language: datatableLanguage,
|
||||
responsive: true,
|
||||
// responsive: true,
|
||||
autoWidth: false,
|
||||
order: [[7, 'desc']],
|
||||
pagingType: "simple",
|
||||
|
||||
@ -369,8 +369,13 @@
|
||||
Route::get('/{id}/media-proposals/{proposal_id}/reject', 'mediaProposalReject')->name('media.proposal.reject');
|
||||
Route::post('/{id}/media-proposals/{proposal_id}/reject', 'mediaProposalRejectAction')->name('media.proposal.reject.action');
|
||||
|
||||
Route::post('/export', 'export')->name('export');
|
||||
Route::post('/filter', 'filter')->name('filter');
|
||||
|
||||
Route::get('/create', 'create')->name('create');
|
||||
Route::post('/', 'store')->name('store');
|
||||
|
||||
|
||||
Route::get('/{id}/edit', 'edit')->name('edit');
|
||||
Route::put('/{id}', 'update')->name('update');
|
||||
Route::delete('/{id}', 'destroy')->name('destroy');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user