insyaallah revisi done

This commit is contained in:
Jagad R R
2025-01-23 17:46:38 +07:00
parent 6034c331c5
commit 3a01df56e9
32 changed files with 825 additions and 360 deletions
@@ -20,6 +20,7 @@ use App\Models\FormMeetingSeminar;
use App\Models\UserHasCabang;
use App\Models\Cabang;
use App\Helpers\AuditTrailHelper;
use App\Models\Region;
class AdminsController extends Controller
{
@@ -35,7 +36,7 @@ class AdminsController extends Controller
'path' => url()->current()
];
$admins = Admin::with(['region', 'cabang', 'roles'])->get();
$admins = Admin::with(['region', 'cabang', 'roles', 'getRayon', 'getRegion'])->get();
return view('backend.pages.admins.index', [
'admins' => $admins,
'pageInfo' => $pageInfo,
@@ -55,7 +56,7 @@ class AdminsController extends Controller
return view('backend.pages.admins.create', [
'roles' => Role::all(),
'pageInfo' => $pageInfo,
'cabangs' => Cabang::all()
'regions' => Region::all(),
]);
}
@@ -63,15 +64,16 @@ class AdminsController extends Controller
{
$this->checkAuthorization(auth()->user(), ['admin.create']);
$admin = new Admin();
$admin->name = $request->name;
$admin->password = Hash::make($request->password);
$admin->username = $request->username;
$admin->email = $request->email;
$admin->phone = $request->phone;
$admin->save();
$admin = Admin::create([
'name' => $request->name,
'password' => Hash::make($request->password),
'username' => $request->username,
'email' => $request->email,
'phone' => $request->phone,
'region_id' => $request->region_id ? $request->region_id : null,
'rayon_id' => $request->rayon_id ? $request->rayon_id : null,
])->assignRole($request->roles);
// Assign the user to a cabang
if($request->cabang_id) {
UserHasCabang::create([
'user_id' => $admin->id,
@@ -79,21 +81,6 @@ class AdminsController extends Controller
]);
}
if ($request->roles) {
$admin->assignRole($request->roles);
}
// Create a folder in Nextcloud
// $response = NextcloudHelper::createUser(env('NEXT_CLOUD_URL'), env('NEXT_CLOUD_USERNAME'), env('NEXT_CLOUD_PASSWORD'), $request->username, $request->password, $request->name, $request->email);
// if ($response['success']) {
// session()->flash('success', __('Admin has been created.'));
// return redirect()->route('admin.admins.index');
// } else {
// session()->flash('error', $response['message']);
// return redirect()->route('admin.admins.index');
// }
AuditTrailHelper::AddAuditTrail('Insert', 'Added New User (' . $request->email . ') to the User Table');
session()->flash('success', 'Admin has been created.');
return redirect()->back();
@@ -115,29 +102,33 @@ class AdminsController extends Controller
'admin' => $admin,
'roles' => Role::all(),
'pageInfo' => $pageInfo,
'cabangs' => Cabang::all()
'regions' => Region::all(),
]);
}
public function update(AdminRequest $request, int $id): RedirectResponse
{
$this->checkAuthorization(auth()->user(), ['admin.edit']);
$admin = Admin::findOrFail($id);
$admin->name = $request->name;
$admin->email = $request->email;
$admin->username = $request->username;
$admin->phone = $request->phone;
if ($request->password) {
$admin->password = Hash::make($request->password);
}
$admin->save();
$admin->update([
'name' => $request->name,
'email' => $request->email,
'username' => $request->username,
'phone' => $request->phone,
'region_id' => $request->region_id ? $request->region_id : null,
'rayon_id' => $request->rayon_id ? $request->rayon_id : null,
]);
$admin->roles()->detach();
if ($request->roles) {
$admin->assignRole($request->roles);
}
if ($request->password) {
$admin->password = Hash::make($request->password);
$admin->save();
}
// Update the user's cabang
if($request->cabang_id) {
$userHasCabang = UserHasCabang::where('user_id', $admin->id)->first();
@@ -22,36 +22,28 @@ class DashboardController extends Controller
public function index()
{
$role = auth()->user()->getRoleNames()[0];
$closing_date = env('CLOSING_DATE');
$startDate = date('Y-m-' . env('STARTING_DATE')); // Starting date from .env for the current month
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE'); // Closing date for the next month
$forms = [
'vehicle' => FormVehicleRunningCost::whereMonth('tanggal', date('m'))
->whereYear('tanggal', date('Y'))
->where('tanggal', '<=', date('Y-m-'.$closing_date))
->whereRaw('DAY(CURDATE()) <= '.$closing_date)
->whereBetween('tanggal', [$startDate, $closingDateNextMonth])
->orderBy('tanggal', 'desc')
->get(),
'upcountry' => FormUpCountry::whereMonth('tanggal', date('m'))
->whereYear('tanggal', date('Y'))
->where('tanggal', '<=', date('Y-m-'.$closing_date))
->whereRaw('DAY(CURDATE()) <= '.$closing_date)
->whereBetween('tanggal', [$startDate, $closingDateNextMonth])
->orderBy('tanggal', 'desc')
->get(),
'entertainment' => FormEntertaimentPresentation::whereMonth('tanggal', date('m'))
->whereYear('tanggal', date('Y'))
->where('tanggal', '<=', date('Y-m-'.$closing_date))
->whereRaw('DAY(CURDATE()) <= '.$closing_date)
->whereBetween('tanggal', [$startDate, $closingDateNextMonth])
->orderBy('tanggal', 'desc')
->get(),
'meeting' => FormMeetingSeminar::whereMonth('created_at', date('m'))
->whereYear('created_at', date('Y'))
->where('created_at', '<=', date('Y-m-'.$closing_date))
->whereRaw('DAY(CURDATE()) <= '.$closing_date)
->whereBetween('created_at', [$startDate, $closingDateNextMonth])
->orderBy('created_at', 'desc')
->get(),
'others' => FormOthers::whereMonth('tanggal', date('m'))
->whereYear('tanggal', date('Y'))
->where('tanggal', '<=', date('Y-m-'.$closing_date))
->whereRaw('DAY(CURDATE()) <= '.$closing_date)
->whereBetween('tanggal', [$startDate, $closingDateNextMonth])
->orderBy('tanggal', 'desc')
->get(),
];
@@ -117,14 +109,24 @@ class DashboardController extends Controller
]);
}
public function mark_read()
public function mark_read($id)
{
$this->checkAuthorization(auth()->user(), ['notification.delete']);
$receiver_id = auth()->user()->id;
Notifications::where('receiver_id', $receiver_id)->where('id', $id)->update(['is_read' => 1]);
return response()->json(['message' => 'Notification marked as read.']);
}
public function mark_all_read()
{
$this->checkAuthorization(auth()->user(), ['notification.delete']);
$receiver_id = auth()->user()->id;
Notifications::where('receiver_id', $receiver_id)->update(['is_read' => 1]);
session()->flash('success', 'Notifications marked as read.');
session()->flash('success', 'All notifications marked as read.');
return redirect()->back();
}
}