150 lines
7.6 KiB
PHP
150 lines
7.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Backend;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\AuditTrail;
|
|
use App\Models\FormUpCountry;
|
|
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()
|
|
{
|
|
$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
|
|
]);
|
|
}
|
|
}
|