Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions app/Exports/ReportExport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Illuminate\Contracts\View\View;
use PhpOffice\PhpSpreadsheet\Helper\Html as HtmlHelper;

class ReportExport implements FromView, WithStyles, WithColumnWidths
{
protected $state;
protected $ticketTotal;
protected $ticketByApplication;
protected $ticketByService;
protected $ticketDuplicate;
protected $completionReport;

public function __construct($state, $ticketTotal, $ticketByApplication, $ticketByService, $ticketDuplicate, $completionReport)
{
$this->state = $state;
$this->ticketTotal = $ticketTotal;
$this->ticketByApplication = $ticketByApplication;
$this->ticketByService = $ticketByService;
$this->ticketDuplicate = $ticketDuplicate;
$this->completionReport = $completionReport;
}

public function view(): View
{
return view('export.report', [
'state' => $this->state,
'ticketTotal' => $this->ticketTotal,
'ticketByApplication' => $this->ticketByApplication,
'ticketByService' => $this->ticketByService,
'ticketDuplicate' => $this->ticketDuplicate,
'completionReport' => $this->completionReport,
]);
}

public function styles(Worksheet $sheet)
{
// Auto wrap text agar height cell mengikuti konten
foreach (range('A', $sheet->getHighestColumn()) as $col) {
$sheet->getStyle($col)->getAlignment()->setWrapText(true);
$sheet->getStyle($col)->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP);
}

$lastRow = $sheet->getHighestRow();

// Atur tinggi row terakhir secara manual
$sheet->getRowDimension($lastRow)->setRowHeight(500);

return [];
}

public function columnWidths(): array
{
return [
'A' => 30,
'B' => 30,
'C' => 30,
'D' => 30,
'E' => 30,
];
}
}
200 changes: 200 additions & 0 deletions app/Filament/Pages/ExportReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<?php

namespace App\Filament\Pages;

use Filament\Pages\Page;
use Filament\Forms;
use Filament\Forms\Components\RichEditor;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\DB;
use App\Exports\ReportExport;
use Maatwebsite\Excel\Facades\Excel;
use Carbon\Carbon;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Select;

class ExportReport extends Page implements Forms\Contracts\HasForms
{
use Forms\Concerns\InteractsWithForms;

protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.export-report';

public static function getNavigationLabel(): string
{
return __('Export Report');
}

public function getTitle(): string
{
return __('Export Report');
}

protected static ?int $navigationSort = 2;

public bool $saved = false;
public ?string $completion_report = null;

public function mount(): void
{
$month = now()->month;
$year = now()->year;

// cari data lama di tabel completion_report
$data = DB::table('completion_report')
->where('month', $month)
->where('year', $year)
->first();

$this->form->fill([
'month' => $month,
'year' => $year,
'completion_report' => $data ? $data->completion_report : '',
]);

$this->saved = $data ? true : false;
}

protected function getFormSchema(): array
{
return [
Grid::make(4)->schema([
Select::make('month')
->label(__('Month'))
->options($this->getMonths())
->reactive(),

Select::make('year')
->label(__('Year'))
->options($this->getYears())
->reactive(),
]),

RichEditor::make('completion_report')
->label(__('Completion'))
->reactive()
->afterStateUpdated(fn ($state) => $this->completion_report = $state),
];
}

public function updatedMonth($value, $key): void
{
$state = $this->form->getState();
$data = DB::table('completion_report')
->where('month', $state['month'])
->where('year', $state['year'])
->first();
// dd($data);
$this->form->fill([
'month' => $state['month'],
'year' => $state['year'],
'completion_report' => $data ? $data->completion_report : '',
]);

$this->saved = $data ? true : false;
}

public function updatedYear(): void
{
$state = $this->form->getState();
$this->updatedMonth($state['month'] ?? null, 'month'); // biar logika sama
}

protected function getMonths(): array
{
return collect(range(1, 12))
->mapWithKeys(fn ($m) => [$m => Carbon::create()->month($m)->translatedFormat('F')])
->toArray();
}

protected function getYears(): array
{
$now = now()->year;
return collect(range($now - 2, $now))
->mapWithKeys(fn ($y) => [$y => $y])
->toArray();
}

public function save(): void
{
$state = $this->form->getState();
// dd($state);
if (empty($state['month']) || empty($state['year']) || empty($state['completion_report'])) {
Notification::make()
->title(__('Isi semua field terlebih dahulu'))
->danger()
->send();
return;
}

DB::table('completion_report')->updateOrInsert(
['month' => $state['month'], 'year' => $state['year']],
['completion_report' => $state['completion_report']]
);

$this->saved = true;

Notification::make()
->title(__('Data berhasil disimpan'))
->success()
->send();
}

public function export()
{
if (! $this->saved) {
Notification::make()
->title(__('Isi & simpan data dulu sebelum export'))
->danger()
->send();
return;
}
$state = $this->form->getState();

$ticketTotal = DB::table('tickets')
->whereYear('created_at', $state['year'])
->whereMonth('created_at', $state['month'])
->get();

$ticketByApplication = DB::table('tickets')
->select('master_applications.name', DB::raw('COUNT(*) as total'))
->join('master_applications', 'tickets.master_application_id', '=', 'master_applications.id')
->whereYear('tickets.created_at', $state['year'])
->whereMonth('tickets.created_at', $state['month'])
->groupBy('master_applications.name')
->get();

$ticketByService = DB::table('tickets')
->select('projects.name', DB::raw('COUNT(*) as total'))
->join('projects', 'tickets.project_id', '=', 'projects.id')
->whereYear('tickets.created_at', $state['year'])
->whereMonth('tickets.created_at', $state['month'])
->groupBy('projects.name')
->get();

$ticketDuplicate = DB::table('ticket_relations')
->join('tickets', 'ticket_relations.relation_id', '=', 'tickets.id')
->selectRaw("
TRIM(
SUBSTRING_INDEX(tickets.name, '-', 1)
) as clean_name,
COUNT(*) as total
")
->whereYear('ticket_relations.created_at', $state['year'])
->whereMonth('ticket_relations.created_at', $state['month'])
->groupBy('tickets.name')
->orderByDesc('total')
->get();

$completionReport = DB::table('completion_report')
->where('month', $state['month'])
->where('year', $state['year'])
->value('completion_report');

// dd($ticketDuplicate);
return Excel::download(
new ReportExport($state, $ticketTotal, $ticketByApplication, $ticketByService, $ticketDuplicate, $completionReport),
'laporan-' . $state['year'] . '-' . str_pad($state['month'], 2, '0', STR_PAD_LEFT) . '.xlsx'
);
}
}
5 changes: 5 additions & 0 deletions app/Filament/Pages/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public static function getNavigationLabel(): string
return __('Report');
}

public function getTitle(): string
{
return __('Report');
}

public $activeTab = 1;

}
3 changes: 2 additions & 1 deletion catatan_rilis.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Di rilis v2507.0.0 berisi penambahan fitur dan perbaikan lain sesuai dengan pelayanan ke pelanggan.

#### Penambahan Fitur
1. [#41](https://github.com/OpenSID/help-desk/issues/38) fitur : ekspor laporan ke dalam excel

#### Perbaikan BUG
8. [#31](https://github.com/OpenSID/help-desk/issues/31) Perbaikan fitur pencarian tiket
1. [#31](https://github.com/OpenSID/help-desk/issues/31) Perbaikan fitur pencarian tiket

#### Panduan

Expand Down
6 changes: 5 additions & 1 deletion lang/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,9 @@
"Month": "Bulan",
"Year": "Tahun",
"Data not found": "Data tidak ditemukan",
"Tokens": "Token"
"Tokens": "Token",
"Completion": "Penyelesaian",
"Export to Excel": "Ekspor ke Excel",
"Export Report": "Ekspor Laporan",
"This is an action to export data based on the data on the report page, and is equipped with problem solving for the report and then exported to Excel.": "Ini merupakan aksi untuk mengekspor data berdasarkan data yang ada di page laporan, dan dilengkapi penyelesaian masalah untuk laporan kemudian di export ke Excel."
}
52 changes: 52 additions & 0 deletions resources/views/export/report.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<table>
{{-- Header --}}
<tr>
<td colspan="4" style="font-weight: bold; font-size: 14px; background: #d9ead3;">
Rilis {{ $state['year'] % 100 }}{{ str_pad($state['month'], 2, '0', STR_PAD_LEFT) }}
({{ \Carbon\Carbon::createFromDate($state['year'], $state['month'])->translatedFormat('F Y') }})
</td>
</tr>

{{-- Summary Tiket --}}
<tr>
<th>Jumlah Tiket Dibuat</th>
<th>Jumlah Tiket Terselesaikan</th>
<th>Aplikasi Beban Utama</th>
<th>Server Beban Utama</th>
<th>Masalah berulang / menyita waktu</th>
</tr>
<tr>
<td>{{ $ticketTotal->count() }}</td>
<td>{{ $ticketTotal->count() }}</td>

{{-- aplikasi --}}
<td>
@foreach ($ticketByApplication as $app)
{{ $app->name }} ({{ $app->total }})<br><br>
@endforeach
</td>

{{-- server --}}
<td>
@foreach ($ticketByService as $srv)
{{ $srv->name }} ({{ $srv->total }})<br><br>
@endforeach
</td>

{{-- masalah berulang --}}
<td>
@foreach ($ticketDuplicate as $dup)
{{ $dup->clean_name }} ({{ $dup->total }})<br><br>
@endforeach
</td>
</tr>

{{-- Aksi untuk mengurangi tiket --}}
<tr><td colspan="5" style="background: #d9ead3;">Aksi untuk mengurangi tiket</td></tr>
<tr>
<td colspan="5">
{!! $completionReport !!}
</td>
</tr>
</table>

23 changes: 23 additions & 0 deletions resources/views/filament/pages/export-report.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<x-filament::page>
<div class="!mt-[-15px] text-xs italic text-gray-500">
{{__('This is an action to export data based on the data on the report page, and is equipped with problem solving for the report and then exported to Excel.')}}
</div>
{{ $this->form }}

<div class="flex mt-4 gap-4">
<x-filament::button wire:click="save">
{{ __('Save') }}
</x-filament::button>

<div class="">
<x-filament::button
wire:click="export"
color="success"
:disabled="! $saved"
class="{{ $saved ? '' : 'disabled opacity-50 cursor-not-allowed' }}"
>
{{__('Export to Excel')}}
</x-filament::button>
</div>
</div>
</x-filament::page>