From 4d9a17cfbd6fc26aaded0ebe397c9ab970c07648 Mon Sep 17 00:00:00 2001 From: Jagad R R Date: Wed, 8 Jan 2025 15:01:42 +0700 Subject: [PATCH] added generate reports --- .../Controllers/Backend/ReportController.php | 130 ++++- .../backend/pages/admins/index.blade.php | 2 +- .../backend/pages/report/index.blade.php | 533 ++++++++++++++---- 3 files changed, 550 insertions(+), 115 deletions(-) diff --git a/app/Http/Controllers/Backend/ReportController.php b/app/Http/Controllers/Backend/ReportController.php index 0731531..93f34a8 100644 --- a/app/Http/Controllers/Backend/ReportController.php +++ b/app/Http/Controllers/Backend/ReportController.php @@ -11,13 +11,139 @@ use App\Models\FormEntertaimentPresentation; use App\Models\FormMeetingSeminar; use App\Models\FormVehicleRunningCost; use App\Models\FormOthers; +use App\Models\UserHasCabang; +use App\Models\Cabang; class ReportController extends Controller { public function index() { - return view('backend.pages.report.index', [ + $role = auth()->user()->getRoleNames()[0]; + $cabangs = []; + $forms = []; - ]); + if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') { + $region_id = auth()->user()->getMyCabangAndRegionId()['region']; + + if ($region_id) { + $users = UserHasCabang::whereHas('cabang', function ($query) use ($region_id) { + $query->where('region_id', $region_id); + })->get(); + + $userIds = $users->pluck('user_id')->toArray(); + + $cabangs = Cabang::where('region_id', $region_id)->get(); + $forms = [ + 'form_up_country' => FormUpCountry::whereIn('user_id', $userIds)->get(), + 'form_entertainment_presentation' => FormEntertaimentPresentation::whereIn('user_id', $userIds)->get(), + 'form_vehicle_running_cost' => FormVehicleRunningCost::whereIn('user_id', $userIds)->get(), + 'form_others' => FormOthers::whereIn('user_id', $userIds)->get(), + 'form_meeting_seminar' => FormMeetingSeminar::whereIn('user_id', $userIds)->get(), + ]; + } + } else if ($role == 'Area Manager Cabang') { + $cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang']; + + if ($cabang_id) { + $users = UserHasCabang::where('cabang_id', $cabang_id)->get(); + $userIds = $users->pluck('user_id')->toArray(); + + $cabangs = Cabang::where('id', $cabang_id)->get(); + $forms = [ + 'form_up_country' => FormUpCountry::whereIn('user_id', $userIds)->get(), + 'form_entertainment_presentation' => FormEntertaimentPresentation::whereIn('user_id', $userIds)->get(), + 'form_vehicle_running_cost' => FormVehicleRunningCost::whereIn('user_id', $userIds)->get(), + 'form_others' => FormOthers::whereIn('user_id', $userIds)->get(), + 'form_meeting_seminar' => FormMeetingSeminar::whereIn('user_id', $userIds)->get(), + ]; + } + } else if ($role == 'Medical Representatif') { + $userId = auth()->user()->id; + + $cabangs = null; + $forms = [ + 'form_up_country' => FormUpCountry::where('user_id', $userId)->get(), + 'form_entertainment_presentation' => FormEntertaimentPresentation::where('user_id', $userId)->get(), + 'form_vehicle_running_cost' => FormVehicleRunningCost::where('user_id', $userId)->get(), + 'form_others' => FormOthers::where('user_id', $userId)->get(), + 'form_meeting_seminar' => FormMeetingSeminar::where('user_id', $userId)->get(), + ]; + } else { + $cabangs = Cabang::all(); + $forms = [ + 'form_up_country' => FormUpCountry::all(), + 'form_entertainment_presentation' => FormEntertaimentPresentation::all(), + 'form_vehicle_running_cost' => FormVehicleRunningCost::all(), + 'form_others' => FormOthers::all(), + 'form_meeting_seminar' => FormMeetingSeminar::all(), + ]; + } + + // get all params in url + $params = request()->all(); + + if($params) { + if ($params['cabang']) { + $cabang = Cabang::where('code', $params['cabang'])->first(); + $users = UserHasCabang::where('cabang_id', $cabang->id)->get(); + $userIds = $users->pluck('user_id')->toArray(); + + $forms = [ + 'form_up_country' => FormUpCountry::whereIn('user_id', $userIds)->get(), + 'form_entertainment_presentation' => FormEntertaimentPresentation::whereIn('user_id', $userIds)->get(), + 'form_vehicle_running_cost' => FormVehicleRunningCost::whereIn('user_id', $userIds)->get(), + 'form_others' => FormOthers::whereIn('user_id', $userIds)->get(), + 'form_meeting_seminar' => FormMeetingSeminar::whereIn('user_id', $userIds)->get(), + ]; + } + + if($params['start_date'] && $params['end_date']) { + $forms = [ + 'form_up_country' => FormUpCountry::whereBetween('tanggal', [$params['start_date'], $params['end_date']])->get(), + 'form_entertainment_presentation' => FormEntertaimentPresentation::whereBetween('tanggal', [$params['start_date'], $params['end_date']])->get(), + 'form_vehicle_running_cost' => FormVehicleRunningCost::whereBetween('tanggal', [$params['start_date'], $params['end_date']])->get(), + 'form_others' => FormOthers::whereBetween('tanggal', [$params['start_date'], $params['end_date']])->get(), + 'form_meeting_seminar' => FormMeetingSeminar::whereBetween('created_at', [$params['start_date'], $params['end_date']])->get(), + ]; + } + + if($params['start_date'] && !$params['end_date']) { + $forms = [ + 'form_up_country' => FormUpCountry::where('tanggal', $params['start_date'])->get(), + 'form_entertainment_presentation' => FormEntertaimentPresentation::where('tanggal', $params['start_date'])->get(), + 'form_vehicle_running_cost' => FormVehicleRunningCost::where('tanggal', $params['start_date'])->get(), + 'form_others' => FormOthers::where('tanggal', $params['start_date'])->get(), + 'form_meeting_seminar' => FormMeetingSeminar::where('created_at', $params['start_date'])->get(), + ]; + } + + if(!$params['start_date'] && $params['end_date']) { + $forms = [ + 'form_up_country' => FormUpCountry::where('tanggal', $params['end_date'])->get(), + 'form_entertainment_presentation' => FormEntertaimentPresentation::where('tanggal', $params['end_date'])->get(), + 'form_vehicle_running_cost' => FormVehicleRunningCost::where('tanggal', $params['end_date'])->get(), + 'form_others' => FormOthers::where('tanggal', $params['end_date'])->get(), + 'form_meeting_seminar' => FormMeetingSeminar::where('created_at', $params['end_date'])->get(), + ]; + } + + if($params['status']) { + $forms = [ + 'form_up_country' => FormUpCountry::where('status', $params['status'])->get(), + 'form_entertainment_presentation' => FormEntertaimentPresentation::where('status', $params['status'])->get(), + 'form_vehicle_running_cost' => FormVehicleRunningCost::where('status', $params['status'])->get(), + 'form_others' => FormOthers::where('status', $params['status'])->get(), + 'form_meeting_seminar' => FormMeetingSeminar::where('status', $params['status'])->get(), + ]; + } + } + + return view('backend.pages.report.index', [ + 'pageInfo' => [ + 'title' => 'Generate Reports', + ], + 'forms' => $forms, + 'cabang' => $cabangs + ]); } } diff --git a/resources/views/backend/pages/admins/index.blade.php b/resources/views/backend/pages/admins/index.blade.php index f8d468c..8856907 100644 --- a/resources/views/backend/pages/admins/index.blade.php +++ b/resources/views/backend/pages/admins/index.blade.php @@ -26,7 +26,7 @@
-
+

{{ $pageInfo['title'] }}

diff --git a/resources/views/backend/pages/report/index.blade.php b/resources/views/backend/pages/report/index.blade.php index 78441a4..c2092e7 100644 --- a/resources/views/backend/pages/report/index.blade.php +++ b/resources/views/backend/pages/report/index.blade.php @@ -1,7 +1,7 @@ @extends('layouts.app') @section('title') - Dashboard + {{ $pageInfo['title'] }} @endsection @section('admin-content') @@ -9,119 +9,401 @@
-

Active Budgets

+

{{ $pageInfo['title'] }}

-
-
-
-
-
-
-
-
-

Rp {{ number_format(2000000, 0, ',', '.') }}

-

Total Budget Bulan Ini

-
-
- -
-
-
-
-
-
-

Rp {{ number_format(2000000, 0, ',', '.') }}

-

Total Budget Tersedia

-
-
- -
-
-
-
-
-
-

Rp {{ number_format(2000000, 0, ',', '.') }}

-

Total Budget Terpakai

-
-
- +
+
+
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+ {{-- submit button --}} +
+ +
+
+
-
-
+ + + + @php + use App\Helpers\NextCloudHelper; + @endphp +
-
-
-

Current Active Budget

-
-
- @include('backend.layouts.partials.messages') -
- - - - - - - - - - - - - - - - - @foreach ($data as $item) - - - - - - - - - - - - - @endforeach - -
#PenerimaCabangPengirimTotalKeteranganPeriodeTanggal ClosingStatusAksi
{{ $loop->iteration }}{{ $item->receiver->name }}{{ $item->cabang->name }}{{ $item->sender->name }}{{ number_format($item->amount, 0, ',', '.') }}{{ $item->remarks }}{{ strtoupper($item->periode_month) }} {{ $item->periode_year }}{{ \Carbon\Carbon::parse($item->closing_at)->locale('id')->isoFormat('D MMMM Y H:mm') }} - @if ($item->status == 'Unassigned') - {{ $item->status }} - @elseif ($item->status == 'Assigned') - {{ $item->status }} - @else - {{ $item->status }} - @endif - - @if (auth()->user()->can('budget_control.delete')) -
- @csrf - @method('DELETE') - -
- @endif -
-
-
+ +
+
+
+
+

Form Up Country

+
+ @include('backend.layouts.partials.messages') +
+ + + + + + + + + + + + + + + + + + + @foreach ($forms['form_up_country'] as $index => $item) + + + + + + + + + + + + + + + @endforeach + +
#No ExpenseNamaCabangRayonTanggalTujuanJarakTotalTotal ApprovedAccount NumberStatus
{{ $loop->iteration }}{{ $item->expense_number }}{{ $item->user->name }}{{ $item->user->cabang->cabang->name }}{{ $item->rayon->code }}{{ \Carbon\Carbon::parse($item->tanggal)->locale('id')->isoFormat('D MMMM Y') }}{{ $item->tujuan }}{{ $item->jarak }} km{{ number_format($item->total, 0, ',', '.') }} + @if ($item->approved_total) + {{ number_format($item->approved_total, 0, ',', '.') }} + @else + - + @endif + {{ $item->account_number }} + @if ($item->status == 'On Progress') + {{ $item->status }} + @elseif ($item->status == 'Approved' || $item->status == 'Final Approved') + {{ $item->status }} + @else + {{ $item->status }} + @endif +
+
+
+
+
+
+
+ + +
+
+
+
+

Form Vehicle Running Cost

+
+
+ + + + + + + + + + + + + + + + + + + + @foreach ($forms['form_vehicle_running_cost'] as $index => $item) + + + + + + + + + + + + + + + + @endforeach + +
#NamaCabangTanggalLiterTotalTotal ApprovedJarakTipe BensinNomor PolisiBuktiAccount NumberStatus
{{ $loop->iteration }}{{ $item->user->name }}{{ $item->user->cabang->cabang->name }}{{ \Carbon\Carbon::parse($item->tanggal)->locale('id')->isoFormat('dddd, D MMMM Y HH:mm:ss') }}{{ $item->liter }}{{ number_format($item->total, 0, ',', '.') }}{{ number_format($item->approved_total, 0, ',', '.') }}{{ $item->jarak }} km{{ $item->tipe_bensin }}{{ $item->nopol }} + @if ($item->bukti_total) + + Download + + @else + - + @endif + {{ $item->account_number }} + @if ($item->status == 'On Progress') + {{ $item->status }} + @elseif ($item->status == 'Approved' || $item->status == 'Final Approved') + {{ $item->status }} + @else + {{ $item->status }} + @endif +
+
+
+
+
+
+
+ + +
+
+
+
+

Form Entertainment Presentation

+
+
+ + + + + + + + + + + + + + + + + + + @foreach ($forms['form_entertainment_presentation'] as $index => $item) + + + + + + + + + + + + + + + @endforeach + +
#UserCabangNama PenerimaTanggalJenisKeteranganTotalTotal ApprovedBuktiAccount NumberStatus
{{ $loop->iteration }}{{ $item->user->name }}{{ $item->user->cabang->cabang->name }}{{ $item->name }}{{ \Carbon\Carbon::parse($item->tanggal)->locale('id')->isoFormat('D MMMM Y') }}{{ $item->jenis }}{{ $item->keterangan }}{{ number_format($item->total, 0, ',', '.') }}{{ number_format($item->approved_total, 0, ',', '.') }} + @if ($item->bukti_total) + + Download + + @else + - + @endif + {{ $item->account_number }} + @if ($item->status == 'On Progress') + {{ $item->status }} + @elseif ($item->status == 'Approved' || $item->status == 'Final Approved') + {{ $item->status }} + @else + {{ $item->status }} + @endif +
+
+
+
+
+
+
+ + +
+
+
+
+

Form Meeting Seminar

+
+
+ + + + + + + + + + + + + + + + + + + @foreach ($forms['form_meeting_seminar'] as $index => $item) + + + + + + + + + + + + + + + @endforeach + +
#No ExpenseNamaCabangTanggalAllowanceTransport AnkotHotelTotalTotal ApprovedAccount NumberStatus
{{ $loop->iteration }}{{ $item->expense_number }}{{ $item->user->name }}{{ $item->user->cabang->cabang->name }}{{ \Carbon\Carbon::parse($item->created_at)->locale('id')->isoFormat('D MMMM Y') }}{{ number_format($item->allowance, 0, ',', '.') }}{{ number_format($item->transport_ankot, 0, ',', '.') }}{{ number_format($item->hotel, 0, ',', '.') }}{{ number_format($item->total, 0, ',', '.') }}{{ number_format($item->approved_total, 0, ',', '.') }}{{ $item->account_number }} + @if ($item->status == 'On Progress') + {{ $item->status }} + @elseif ($item->status == 'Approved' || $item->status == 'Final Approved') + {{ $item->status }} + @else + {{ $item->status }} + @endif +
+
+
+
+
+
+
+ + +
+
+
+
+

Form Others

+
+
+ + + + + + + + + + + + + + + + + @foreach ($forms['form_others'] as $index => $item) + + + + + + + + + + + + + @endforeach + +
#NamaCabangTanggalJenisKeteranganTotalBukti TotalAccount NumberStatus
{{ $loop->iteration }}{{ $item->user->name }}{{ $item->user->cabang->cabang->name }}{{ \Carbon\Carbon::parse($item->tanggal)->locale('id')->isoFormat('D MMMM Y') }}{{ $item->kategori->name }}{{ $item->keterangan }}{{ number_format($item->total, 0, ',', '.') }} + @if ($item->bukti_total) + + Download + + @else + - + @endif + {{ $item->account_number }} + @if ($item->status == 'On Progress') + {{ $item->status }} + @elseif ($item->status == 'Approved' || $item->status == 'Final Approved') + {{ $item->status }} + @else + {{ $item->status }} + @endif +
+
+
+
+
@@ -130,14 +412,41 @@ @section('scripts') + // Initialize DataTables for each table + if ($('#dataTable-form_up_country').length) { + $('#dataTable-form_up_country').DataTable({ + responsive: false, + dom: 'Bfrtip', + buttons: ['excel', 'pdf', 'print', 'colvis'], + }); + } + if ($('#dataTable-form_vehicle_running_cost').length) { + $('#dataTable-form_vehicle_running_cost').DataTable({ + responsive: false, + dom: 'Bfrtip', + buttons: ['excel', 'pdf', 'print', 'colvis'], + }); + } + if ($('#dataTable-form_entertainment_presentation').length) { + $('#dataTable-form_entertainment_presentation').DataTable({ + responsive: false, + dom: 'Bfrtip', + buttons: ['excel', 'pdf', 'print', 'colvis'], + }); + } + if ($('#dataTable-form_meeting_seminar').length) { + $('#dataTable-form_meeting_seminar').DataTable({ + responsive: false, + dom: 'Bfrtip', + buttons: ['excel', 'pdf', 'print', 'colvis'], + }); + } + if ($('#dataTable-form_others').length) { + $('#dataTable-form_others').DataTable({ + responsive: false, + dom: 'Bfrtip', + buttons: ['excel', 'pdf', 'print', 'colvis'], + }); + } + @endsection