fix some revisi
This commit is contained in:
@@ -181,6 +181,82 @@ class FormHelper
|
||||
});
|
||||
}
|
||||
|
||||
public static function getAllForms2() {
|
||||
// Get all users with eager loading for 'region' and 'cabang'
|
||||
$users = Admin::with(['region', 'cabang'])
|
||||
->get();
|
||||
|
||||
$formUpCountryQuery = FormUpCountry::select(
|
||||
'expense_number',
|
||||
'user_id',
|
||||
'total',
|
||||
'approved_total',
|
||||
'status',
|
||||
'account_number',
|
||||
'created_at',
|
||||
DB::raw("'Up Country' as type")
|
||||
);
|
||||
|
||||
$formVehicleRunningCostQuery = FormVehicleRunningCost::select(
|
||||
'expense_number',
|
||||
'user_id',
|
||||
'total',
|
||||
'approved_total',
|
||||
'status',
|
||||
'account_number',
|
||||
'created_at',
|
||||
DB::raw("'Vehicle Running Cost' as type")
|
||||
);
|
||||
|
||||
$formEntertaimentPresentationQuery = FormEntertaimentPresentation::select(
|
||||
'expense_number',
|
||||
'user_id',
|
||||
'total',
|
||||
'approved_total',
|
||||
'status',
|
||||
'account_number',
|
||||
'created_at',
|
||||
DB::raw("'Entertainment Presentation' as type")
|
||||
);
|
||||
|
||||
$formMeetingSeminarQuery = FormMeetingSeminar::select(
|
||||
'expense_number',
|
||||
'user_id',
|
||||
'total',
|
||||
'approved_total',
|
||||
'status',
|
||||
'account_number',
|
||||
'created_at',
|
||||
DB::raw("'Meeting Seminar' as type")
|
||||
);
|
||||
|
||||
$formOthersQuery = FormOthers::select(
|
||||
'expense_number',
|
||||
'user_id',
|
||||
'total',
|
||||
'approved_total',
|
||||
'status',
|
||||
'account_number',
|
||||
'created_at',
|
||||
DB::raw("'Others' as type")
|
||||
);
|
||||
|
||||
// Combine queries using union
|
||||
$forms = $formUpCountryQuery
|
||||
->union($formVehicleRunningCostQuery)
|
||||
->union($formEntertaimentPresentationQuery)
|
||||
->union($formMeetingSeminarQuery)
|
||||
->union($formOthersQuery)
|
||||
->get();
|
||||
|
||||
// Map users to the forms with eager loaded data
|
||||
return $forms->map(function ($form) use ($users) {
|
||||
$user = $users->firstWhere('id', $form->user_id);
|
||||
$form->user = $user;
|
||||
return $form;
|
||||
});
|
||||
}
|
||||
|
||||
public static function getNominalByFormType($cabang_id, $type, $type_id, $month, $year) {
|
||||
$users = UserHasCabang::where('cabang_id', $cabang_id)->get();
|
||||
$userIds = $users->pluck('user_id')->toArray();
|
||||
|
||||
@@ -104,27 +104,12 @@ class DashboardController extends Controller
|
||||
public function notifications()
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['notification.view']);
|
||||
$role = auth()->user()->getRoleNames()[0];
|
||||
|
||||
// Mulai dengan query dasar
|
||||
$notifications = Notifications::orderBy('created_at', 'desc')
|
||||
->where('receiver_id', auth()->user()->id)
|
||||
->where('is_read', 0);
|
||||
|
||||
// Tambahkan filter berdasarkan role
|
||||
if ($role == 'Admin Region') {
|
||||
$notifications->where('type', 'new_expense');
|
||||
} elseif ($role == 'Marketing Operational Manager Region') {
|
||||
$notifications->where('type', 'approve2_expense');
|
||||
} elseif ($role == 'Area Manager Cabang' || $role == 'Marketing Information System') {
|
||||
$notifications->where('type', 'approve_expense');
|
||||
} elseif ($role == 'Head of Sales Marketing') {
|
||||
$notifications->where('type', 'approve2_expense');
|
||||
} else {
|
||||
// Jika tidak ada role yang sesuai, kembalikan koleksi kosong
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
// Ambil data dan kembalikan sebagai JSON
|
||||
return response()->json($notifications->limit(6)->get());
|
||||
}
|
||||
|
||||
@@ -498,7 +498,7 @@ class ReportController extends Controller
|
||||
} else {
|
||||
$cabangs = Cabang::all();
|
||||
$regions = Region::all();
|
||||
$forms = FormHelper::getAllForms($month, $year)->sortByDesc('created_at');
|
||||
$forms = FormHelper::getAllForms2()->sortByDesc('created_at');
|
||||
}
|
||||
|
||||
// get all params in url
|
||||
@@ -565,7 +565,7 @@ class ReportController extends Controller
|
||||
} else {
|
||||
$cabangs = Cabang::all();
|
||||
$regions = Region::all();
|
||||
$forms = FormHelper::getAllForms($month, $year)->sortByDesc('tanggal')->sortByDesc('created_at');
|
||||
$forms = FormHelper::getAllForms($month, $year)->sortByDesc('tanggal')->sortByDesc('created_at');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,30 +114,32 @@ class FormEntertainmentPresentationController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.entertainment.create']);
|
||||
$cabang_id = UserHasCabang::where('user_id', auth()->user()->id)->first()->cabang_id;
|
||||
|
||||
$request->validate([
|
||||
'tanggal' => 'required',
|
||||
'jenis' => 'required|in:entertainment,presentation,sponsorship',
|
||||
'keterangan' => 'required',
|
||||
'total' => 'required|numeric|min:1|max:' . BudgetHelper::getAvailableBudget($cabang_id),
|
||||
'total' => 'required|numeric|min:1',
|
||||
'name' => 'required',
|
||||
'alamat' => 'required',
|
||||
'nik_or_npwp' => 'required',
|
||||
'bukti_total' => ['nullable', 'file', 'max:51200', new FileType(['php', 'exe', 'js', 'sh', 'bat', 'exe', 'sh', 'php', 'vbs'])],
|
||||
]);
|
||||
|
||||
$currentDate = date('Y-m-d');
|
||||
$startDate = date('Y-m-' . env('STARTING_DATE'));
|
||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
|
||||
|
||||
if ($currentDate < $startDate || $currentDate > $closingDateNextMonth) {
|
||||
return response()->json([
|
||||
'error' => 'Current date is not within the valid range.'
|
||||
], 400);
|
||||
if ($request->tanggal < $startDate || $request->tanggal > $closingDateNextMonth) {
|
||||
session()->flash('error', 'Gagal, Input expense sudah melewati periode input 12-10');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
if($request->total > BudgetHelper::getAvailableBudget($cabang->id)) {
|
||||
session()->flash('error', 'Alokasi budget bulanan cabang tidak mencukupi,silahkan ajukan pada periode expense berikutnya');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$region = Region::where('id', $cabang->region_id)->first();
|
||||
$kategori = Kategori::where('name', 'Entertainment')->first();
|
||||
|
||||
|
||||
@@ -133,9 +133,8 @@ class FormMeetingSeminarController extends Controller
|
||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
|
||||
|
||||
if ($currentDate < $startDate || $currentDate > $closingDateNextMonth) {
|
||||
return response()->json([
|
||||
'error' => 'Current date is not within the valid range.'
|
||||
], 400);
|
||||
session()->flash('error', 'Gagal, Input expense sudah melewati periode input 12-10');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
@@ -195,9 +194,8 @@ class FormMeetingSeminarController extends Controller
|
||||
];
|
||||
|
||||
// Check if the total nominal exceeds the available budget
|
||||
$cabang_id = UserHasCabang::where('user_id', auth()->user()->id)->first()->cabang_id;
|
||||
if(array_sum($data_nominal) > BudgetHelper::getAvailableBudget($cabang_id)) {
|
||||
session()->flash('error', 'The total nominal exceeds the available budget.');
|
||||
if(array_sum($data_nominal) > BudgetHelper::getAvailableBudget($cabang->id)) {
|
||||
session()->flash('error', 'Alokasi budget bulanan cabang tidak mencukupi,silahkan ajukan pada periode expense berikutnya');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
@@ -114,27 +114,29 @@ class FormOtherController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.other.create']);
|
||||
$cabang_id = UserHasCabang::where('user_id', auth()->user()->id)->first()->cabang_id;
|
||||
|
||||
$request->validate([
|
||||
'kategori_id' => 'required',
|
||||
'tanggal' => 'required|date',
|
||||
'keterangan' => 'required',
|
||||
'total' => 'required|numeric|min:1|max:' . BudgetHelper::getAvailableBudget($cabang_id),
|
||||
'total' => 'required|numeric|min:1',
|
||||
'bukti_total' => ['nullable', 'file', 'max:51200', new FileType(['php', 'exe', 'js', 'sh', 'bat', 'exe', 'sh', 'php', 'vbs'])],
|
||||
]);
|
||||
|
||||
$currentDate = date('Y-m-d');
|
||||
$startDate = date('Y-m-' . env('STARTING_DATE'));
|
||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
|
||||
|
||||
if ($currentDate < $startDate || $currentDate > $closingDateNextMonth) {
|
||||
return response()->json([
|
||||
'error' => 'Current date is not within the valid range.'
|
||||
], 400);
|
||||
if ($request->tanggal < $startDate || $request->tanggal > $closingDateNextMonth) {
|
||||
session()->flash('error', 'Gagal, Input expense sudah melewati periode input 12-10');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
if($request->total > BudgetHelper::getAvailableBudget($cabang->id)) {
|
||||
session()->flash('error', 'Alokasi budget bulanan cabang tidak mencukupi,silahkan ajukan pada periode expense berikutnya');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$region = Region::where('id', $cabang->region_id)->first();
|
||||
$kategori = Kategori::where('id', $request->kategori_id)->first();
|
||||
|
||||
|
||||
@@ -115,9 +115,10 @@ class FormUpCountryController extends Controller
|
||||
public function create()
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.country.create']);
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
|
||||
return view('backend.pages.forms.upcountry.create', [
|
||||
'rayons' => Rayon::all()
|
||||
'rayons' => Rayon::where('cabang_id', $cabang->id)->get()
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -140,14 +141,12 @@ class FormUpCountryController extends Controller
|
||||
'bukti_hotel' => ['nullable', 'file', 'max:51200', new FileType(['php', 'exe', 'js', 'sh', 'bat', 'exe', 'sh', 'php', 'vbs'])],
|
||||
]);
|
||||
|
||||
$currentDate = date('Y-m-d');
|
||||
$startDate = date('Y-m-' . env('STARTING_DATE'));
|
||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
|
||||
|
||||
if ($currentDate < $startDate || $currentDate > $closingDateNextMonth) {
|
||||
return response()->json([
|
||||
'error' => 'Current date is not within the valid range.'
|
||||
], 400);
|
||||
if ($request->tanggal < $startDate || $request->tanggal > $closingDateNextMonth) {
|
||||
session()->flash('error', 'Gagal, Input expense sudah melewati periode input 12-10');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
@@ -220,9 +219,8 @@ class FormUpCountryController extends Controller
|
||||
];
|
||||
|
||||
// Check if the total nominal exceeds the available budget
|
||||
$cabang_id = UserHasCabang::where('user_id', auth()->user()->id)->first()->cabang_id;
|
||||
if(array_sum($data_nominal) > BudgetHelper::getAvailableBudget($cabang_id)) {
|
||||
session()->flash('error', 'The total nominal exceeds the available budget.');
|
||||
if(array_sum($data_nominal) > BudgetHelper::getAvailableBudget($cabang->id)) {
|
||||
session()->flash('error', 'Alokasi budget bulanan cabang tidak mencukupi,silahkan ajukan pada periode expense berikutnya');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
@@ -307,6 +305,8 @@ class FormUpCountryController extends Controller
|
||||
$this->checkAuthorization(auth()->user(), ['forms.country.edit']);
|
||||
$role = auth()->user()->getRoleNames()[0];
|
||||
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
|
||||
$form = FormUpCountry::with('rayon')->findOrfail($id);
|
||||
if (($form->status != 'On Progress' && $form->status != 'Rejected') && $role == 'Medical Representatif') {
|
||||
session()->flash('error', 'You cannot edit this form because it has been approved or closed.');
|
||||
@@ -314,7 +314,7 @@ class FormUpCountryController extends Controller
|
||||
}
|
||||
|
||||
return view('backend.pages.forms.upcountry.edit', [
|
||||
'rayons' => Rayon::all(),
|
||||
'rayons' => Rayon::where('cabang_id', $cabang->id)->get(),
|
||||
'form' => $form
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -115,12 +115,11 @@ class FormVehicleController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.vehicle.create']);
|
||||
$cabang_id = UserHasCabang::where('user_id', auth()->user()->id)->first()->cabang_id;
|
||||
|
||||
$request->validate([
|
||||
'tanggal' => 'required',
|
||||
'liter' => 'required',
|
||||
'total' => 'required|numeric|min:1|max:' . BudgetHelper::getAvailableBudget($cabang_id),
|
||||
'total' => 'required|numeric|min:1',
|
||||
'jarak' => 'required',
|
||||
'tipe_bensin' => 'required|in:pertalite,pertamax',
|
||||
'nopol' => 'required',
|
||||
@@ -128,17 +127,20 @@ class FormVehicleController extends Controller
|
||||
'bukti_total' => ['nullable', 'file', 'max:51200', new FileType(['php', 'exe', 'js', 'sh', 'bat', 'exe', 'sh', 'php', 'vbs'])],
|
||||
]);
|
||||
|
||||
$currentDate = date('Y-m-d');
|
||||
$startDate = date('Y-m-' . env('STARTING_DATE'));
|
||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
|
||||
|
||||
if ($currentDate < $startDate || $currentDate > $closingDateNextMonth) {
|
||||
return response()->json([
|
||||
'error' => 'Current date is not within the valid range.'
|
||||
], 400);
|
||||
if ($request->tanggal < $startDate || $request->tanggal > $closingDateNextMonth) {
|
||||
session()->flash('error', 'Gagal, Input expense sudah melewati periode input 12-10');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
if($request->total > BudgetHelper::getAvailableBudget($cabang->id)) {
|
||||
session()->flash('error', 'Alokasi budget bulanan cabang tidak mencukupi,silahkan ajukan pada periode expense berikutnya');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$region = Region::where('id', $cabang->region_id)->first();
|
||||
$kategori = Kategori::where('name', 'Vehicle Running Cost')->first();
|
||||
|
||||
|
||||
@@ -10,5 +10,5 @@ class Rayon extends Model
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'rayon';
|
||||
protected $fillable = ['code', 'name'];
|
||||
protected $fillable = ['code', 'name', 'cabang_id'];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user