Compare commits
17 Commits
df2f91cc57
...
new_adk
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b51a4f039 | ||
|
|
0b28760f41 | ||
|
|
f3872e0665 | ||
|
|
4270f152d2 | ||
|
|
9539c2572f | ||
|
|
ff94434032 | ||
|
|
7313f64a70 | ||
|
|
a4aab54735 | ||
| c9bd6664f2 | |||
|
|
59721337a8 | ||
|
|
c348af2484 | ||
|
|
e3c7bf711c | ||
|
|
7cb2f798d0 | ||
|
|
21521b384e | ||
|
|
0a2add800e | ||
|
|
fdbef3a5e8 | ||
|
|
becbf8aee2 |
@@ -9,10 +9,21 @@ use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
|||||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||||
use Modules\Usermanagement\Models\User;
|
use Modules\Usermanagement\Models\User;
|
||||||
|
|
||||||
class UsersExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
|
class UsersExport implements WithColumnFormatting, WithHeadings, FromCollection, WithMapping
|
||||||
{
|
{
|
||||||
|
protected $search;
|
||||||
|
|
||||||
|
public function __construct($search = null)
|
||||||
|
{
|
||||||
|
$this->search = $search;
|
||||||
|
}
|
||||||
|
|
||||||
public function collection(){
|
public function collection(){
|
||||||
return User::all();
|
return User::query()
|
||||||
|
->when($this->search, function ($query) {
|
||||||
|
$query->whereAny(['name','email'],'like','%'.$this->search.'%');
|
||||||
|
})
|
||||||
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function map($row): array{
|
public function map($row): array{
|
||||||
@@ -21,7 +32,8 @@ class UsersExport implements WithColumnFormatting, WithHeadings, FromCollection,
|
|||||||
$row->name,
|
$row->name,
|
||||||
$row->email,
|
$row->email,
|
||||||
$row->nik,
|
$row->nik,
|
||||||
$row->branch->name,
|
$row->branch?->name,
|
||||||
|
$row->roles?->pluck('name')->implode(', '),
|
||||||
$row->created_at
|
$row->created_at
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -32,6 +44,7 @@ class UsersExport implements WithColumnFormatting, WithHeadings, FromCollection,
|
|||||||
'Email',
|
'Email',
|
||||||
'NIK',
|
'NIK',
|
||||||
'Branch',
|
'Branch',
|
||||||
|
'Roles',
|
||||||
'Created At'
|
'Created At'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -39,7 +52,7 @@ class UsersExport implements WithColumnFormatting, WithHeadings, FromCollection,
|
|||||||
public function columnFormats(): array{
|
public function columnFormats(): array{
|
||||||
return [
|
return [
|
||||||
'A' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER,
|
'A' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER,
|
||||||
'F' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME
|
'G' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
app/Helpers/RolePermission.php
Normal file
30
app/Helpers/RolePermission.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
if (!function_exists('check_permission')) {
|
||||||
|
function check_permission(string $permission, bool $abort = true): bool
|
||||||
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
|
||||||
|
if (!$user || !$user->can($permission)) {
|
||||||
|
if ($abort) {
|
||||||
|
abort(403, 'Unauthorized');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('user_has_role')) {
|
||||||
|
function user_has_role(array $roles): bool
|
||||||
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
|
||||||
|
if (!$user) return false;
|
||||||
|
|
||||||
|
return $user->roles->pluck('name')->intersect($roles)->isNotEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
/**
|
/**
|
||||||
* @var \Illuminate\Contracts\Auth\Authenticatable|null
|
* @var \Illuminate\Contracts\Auth\Authenticatable|null
|
||||||
*/
|
*/
|
||||||
public $user;
|
protected $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UsersController constructor.
|
* UsersController constructor.
|
||||||
@@ -32,7 +32,14 @@
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->user = Auth::guard('web')->user();
|
// Mengatur middleware auth
|
||||||
|
$this->middleware('auth');
|
||||||
|
|
||||||
|
// Mengatur user setelah middleware auth dijalankan
|
||||||
|
$this->middleware(function ($request, $next) {
|
||||||
|
$this->user = Auth::user();
|
||||||
|
return $next($request);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,8 +70,8 @@
|
|||||||
public function store(PermissionRequest $request)
|
public function store(PermissionRequest $request)
|
||||||
{
|
{
|
||||||
// Check if the authenticated user has the required permission to store permissions
|
// Check if the authenticated user has the required permission to store permissions
|
||||||
if (is_null($this->user) || !$this->user->can('usermanagement.store')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.create')) {
|
||||||
abort(403, 'Sorry! You are not allowed to store permissions.');
|
abort(403, 'Sorry! You are not allowed to create permissions.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$validate = $request->validated();
|
$validate = $request->validated();
|
||||||
@@ -80,7 +87,8 @@
|
|||||||
$group_name . '.delete',
|
$group_name . '.delete',
|
||||||
$group_name . '.export',
|
$group_name . '.export',
|
||||||
$group_name . '.authorize',
|
$group_name . '.authorize',
|
||||||
$group_name . '.report'
|
$group_name . '.report',
|
||||||
|
$group_name . '.restore'
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($data as $permission) {
|
foreach ($data as $permission) {
|
||||||
@@ -126,7 +134,7 @@
|
|||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
// Check if the authenticated user has the required permission to edit permissions
|
// Check if the authenticated user has the required permission to edit permissions
|
||||||
if (is_null($this->user) || !$this->user->can('usermanagement.edit')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.update')) {
|
||||||
abort(403, 'Sorry! You are not allowed to edit permissions.');
|
abort(403, 'Sorry! You are not allowed to edit permissions.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +181,8 @@
|
|||||||
$group_name . '.delete',
|
$group_name . '.delete',
|
||||||
$group_name . '.export',
|
$group_name . '.export',
|
||||||
$group_name . '.authorize',
|
$group_name . '.authorize',
|
||||||
$group_name . '.report'
|
$group_name . '.report',
|
||||||
|
$group_name . '.restore'
|
||||||
];
|
];
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
@@ -203,7 +212,7 @@
|
|||||||
{
|
{
|
||||||
// Check if the authenticated user has the required permission to delete permissions
|
// Check if the authenticated user has the required permission to delete permissions
|
||||||
if (is_null($this->user) || !$this->user->can('usermanagement.delete')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.delete')) {
|
||||||
abort(403, 'Sorry! You are not allowed to delete permissions.');
|
return response()->json(['message' => 'Sorry! You are not allowed to delete permissions.','success' => false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$permission = PermissionGroup::find($id);
|
$permission = PermissionGroup::find($id);
|
||||||
@@ -258,7 +267,7 @@
|
|||||||
public function dataForDatatables(Request $request)
|
public function dataForDatatables(Request $request)
|
||||||
{
|
{
|
||||||
if (is_null($this->user) || !$this->user->can('usermanagement.read')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.read')) {
|
||||||
abort(403, 'Sorry! You are not allowed to view users.');
|
return response()->json(['message' => 'Sorry! You are not allowed to view permissions.','success' => false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve data from the database
|
// Retrieve data from the database
|
||||||
@@ -267,9 +276,7 @@
|
|||||||
// Apply search filter if provided
|
// Apply search filter if provided
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$query->where(function ($q) use ($search) {
|
$query->where('name', 'like', '%' . $search . '%');
|
||||||
$q->whereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%']);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply sorting if provided
|
// Apply sorting if provided
|
||||||
@@ -294,14 +301,11 @@
|
|||||||
// Get the filtered count of records
|
// Get the filtered count of records
|
||||||
$filteredRecords = $query->count();
|
$filteredRecords = $query->count();
|
||||||
|
|
||||||
|
|
||||||
// Get the data for the current page
|
// Get the data for the current page
|
||||||
$permissions = $query->get();
|
$data = $query->get();
|
||||||
|
|
||||||
|
$data = $data->map(function ($permission) {
|
||||||
$permissions = $permissions->map(function ($permission) {
|
|
||||||
$permission->roles = $permission->roles($permission);
|
$permission->roles = $permission->roles($permission);
|
||||||
|
|
||||||
return $permission;
|
return $permission;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -319,12 +323,17 @@
|
|||||||
'pageCount' => $pageCount,
|
'pageCount' => $pageCount,
|
||||||
'page' => $currentPage,
|
'page' => $currentPage,
|
||||||
'totalCount' => $totalRecords,
|
'totalCount' => $totalRecords,
|
||||||
'data' => $permissions,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function export()
|
public function export()
|
||||||
{
|
{
|
||||||
|
// Check if the authenticated user has the required permission to export permissions
|
||||||
|
if (is_null($this->user) || !$this->user->can('usermanagement.export')) {
|
||||||
|
abort(403, 'Sorry! You are not allowed to export permissions.');
|
||||||
|
}
|
||||||
|
|
||||||
return Excel::download(new PermissionExport, 'permissions.xlsx');
|
return Excel::download(new PermissionExport, 'permissions.xlsx');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,24 @@
|
|||||||
/**
|
/**
|
||||||
* @var \Illuminate\Contracts\Auth\Authenticatable|null
|
* @var \Illuminate\Contracts\Auth\Authenticatable|null
|
||||||
*/
|
*/
|
||||||
public $user;
|
protected $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UsersController constructor.
|
||||||
|
*
|
||||||
|
* Initializes the user property with the authenticated user.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// Mengatur middleware auth
|
||||||
|
$this->middleware('auth');
|
||||||
|
|
||||||
|
// Mengatur user setelah middleware auth dijalankan
|
||||||
|
$this->middleware(function ($request, $next) {
|
||||||
|
$this->user = Auth::user();
|
||||||
|
return $next($request);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
@@ -32,11 +49,8 @@
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
// Get the authenticated user
|
|
||||||
$user = Auth::guard('web')->user();
|
|
||||||
|
|
||||||
// Check if the authenticated user has the required permission to view positions
|
// Check if the authenticated user has the required permission to view positions
|
||||||
if (is_null($user) || !$user->can('usermanagement.read')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.read')) {
|
||||||
abort(403, 'Sorry! You are not allowed to view positions.');
|
abort(403, 'Sorry! You are not allowed to view positions.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,12 +70,9 @@
|
|||||||
*/
|
*/
|
||||||
public function store(PositionRequest $request)
|
public function store(PositionRequest $request)
|
||||||
{
|
{
|
||||||
// Get the authenticated user
|
|
||||||
$user = Auth::guard('web')->user();
|
|
||||||
|
|
||||||
// Check if the authenticated user has the required permission to store positions
|
// Check if the authenticated user has the required permission to store positions
|
||||||
if (is_null($user) || !$user->can('usermanagement.create')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.create')) {
|
||||||
abort(403, 'Sorry! You are not allowed to store positions.');
|
abort(403, 'Sorry! You are not allowed to create positions.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get validated data
|
// Get validated data
|
||||||
@@ -89,11 +100,8 @@
|
|||||||
*/
|
*/
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
// Get the authenticated user
|
|
||||||
$user = Auth::guard('web')->user();
|
|
||||||
|
|
||||||
// Check if the authenticated user has the required permission to create positions
|
// Check if the authenticated user has the required permission to create positions
|
||||||
if (is_null($user) || !$user->can('usermanagement.create')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.create')) {
|
||||||
abort(403, 'Sorry! You are not allowed to create positions.');
|
abort(403, 'Sorry! You are not allowed to create positions.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,11 +118,8 @@
|
|||||||
*/
|
*/
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
// Get the authenticated user
|
|
||||||
$user = Auth::guard('web')->user();
|
|
||||||
|
|
||||||
// Check if the authenticated user has the required permission to edit positions
|
// Check if the authenticated user has the required permission to edit positions
|
||||||
if (is_null($user) || !$user->can('usermanagement.update')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.update')) {
|
||||||
abort(403, 'Sorry! You are not allowed to edit positions.');
|
abort(403, 'Sorry! You are not allowed to edit positions.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,11 +140,8 @@
|
|||||||
*/
|
*/
|
||||||
public function update(PositionRequest $request, $id)
|
public function update(PositionRequest $request, $id)
|
||||||
{
|
{
|
||||||
// Get the authenticated user
|
|
||||||
$user = Auth::guard('web')->user();
|
|
||||||
|
|
||||||
// Check if the authenticated user has the required permission to update positions
|
// Check if the authenticated user has the required permission to update positions
|
||||||
if (is_null($user) || !$user->can('usermanagement.update')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.update')) {
|
||||||
abort(403, 'Sorry! You are not allowed to update positions.');
|
abort(403, 'Sorry! You are not allowed to update positions.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,12 +175,9 @@
|
|||||||
*/
|
*/
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
// Get the authenticated user
|
|
||||||
$user = Auth::guard('web')->user();
|
|
||||||
|
|
||||||
// Check if the authenticated user has the required permission to delete positions
|
// Check if the authenticated user has the required permission to delete positions
|
||||||
if (is_null($user) || !$user->can('usermanagement.delete')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.delete')) {
|
||||||
abort(403, 'Sorry! You are not allowed to delete positions.');
|
return response()->json(['message' => 'Sorry! You are not allowed to delete positions.','success' => false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the position by ID
|
// Find the position by ID
|
||||||
@@ -213,12 +212,9 @@
|
|||||||
*/
|
*/
|
||||||
public function dataForDatatables(Request $request)
|
public function dataForDatatables(Request $request)
|
||||||
{
|
{
|
||||||
// Get the authenticated user
|
|
||||||
$user = Auth::guard('web')->user();
|
|
||||||
|
|
||||||
// Check if the authenticated user has the required permission to view positions
|
// Check if the authenticated user has the required permission to view positions
|
||||||
if (is_null($user) || !$user->can('usermanagement.read')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.read')) {
|
||||||
abort(403, 'Sorry! You are not allowed to view positions.');
|
return response()->json(['message' => 'Sorry! You are not allowed to view positions.','success' => false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve data from the database
|
// Retrieve data from the database
|
||||||
@@ -227,11 +223,7 @@
|
|||||||
// Apply search filter if provided
|
// Apply search filter if provided
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$query->where(function ($q) use ($search) {
|
$query->whereAny(['code', 'name', 'level'], 'like', '%' . $search . '%');
|
||||||
$q->whereRaw('LOWER(code) LIKE ?', ['%' . strtolower($search) . '%'])
|
|
||||||
->orWhereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%'])
|
|
||||||
->orWhereRaw('CAST(level AS TEXT) LIKE ?', ['%' . $search . '%']);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply sorting if provided
|
// Apply sorting if provided
|
||||||
@@ -257,7 +249,7 @@
|
|||||||
$filteredRecords = $query->count();
|
$filteredRecords = $query->count();
|
||||||
|
|
||||||
// Get the data for the current page
|
// Get the data for the current page
|
||||||
$positions = $query->get();
|
$data = $query->get();
|
||||||
|
|
||||||
// Calculate the page count
|
// Calculate the page count
|
||||||
$size = $request->get('size', 10); // Default to 10 if not set
|
$size = $request->get('size', 10); // Default to 10 if not set
|
||||||
@@ -274,7 +266,7 @@
|
|||||||
'pageCount' => $pageCount,
|
'pageCount' => $pageCount,
|
||||||
'page' => $currentPage,
|
'page' => $currentPage,
|
||||||
'totalCount' => $totalRecords,
|
'totalCount' => $totalRecords,
|
||||||
'data' => $positions,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,11 +278,8 @@
|
|||||||
*/
|
*/
|
||||||
public function export(Request $request)
|
public function export(Request $request)
|
||||||
{
|
{
|
||||||
// Get the authenticated user
|
|
||||||
$user = Auth::guard('web')->user();
|
|
||||||
|
|
||||||
// Check if the authenticated user has the required permission to export positions
|
// Check if the authenticated user has the required permission to export positions
|
||||||
if (is_null($user) || !$user->can('usermanagement.export')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.export')) {
|
||||||
abort(403, 'Sorry! You are not allowed to export positions.');
|
abort(403, 'Sorry! You are not allowed to export positions.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
/**
|
/**
|
||||||
* @var \Illuminate\Contracts\Auth\Authenticatable|null
|
* @var \Illuminate\Contracts\Auth\Authenticatable|null
|
||||||
*/
|
*/
|
||||||
public $user;
|
protected $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UsersController constructor.
|
* UsersController constructor.
|
||||||
@@ -35,7 +35,14 @@
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->user = Auth::guard('web')->user();
|
// Mengatur middleware auth
|
||||||
|
$this->middleware('auth');
|
||||||
|
|
||||||
|
// Mengatur user setelah middleware auth dijalankan
|
||||||
|
$this->middleware(function ($request, $next) {
|
||||||
|
$this->user = Auth::user();
|
||||||
|
return $next($request);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -260,20 +267,23 @@
|
|||||||
public function dataForDatatables(Request $request)
|
public function dataForDatatables(Request $request)
|
||||||
{
|
{
|
||||||
if (is_null($this->user) || !$this->user->can('usermanagement.read')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.read')) {
|
||||||
abort(403, 'Sorry! You are not allowed to view users.');
|
return response()->json(['message' => 'Sorry! You are not allowed to view roles.','success' => false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve data from the database
|
// Retrieve data from the database
|
||||||
$query = Role::query();
|
$query = Role::query();
|
||||||
|
|
||||||
|
if(!$this->user->hasRole('administrator')){
|
||||||
|
$query->where('name', '!=', 'administrator');
|
||||||
|
}
|
||||||
|
|
||||||
// Apply search filter if provided
|
// Apply search filter if provided
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$query->where(function ($q) use ($search) {
|
$query->where(function ($q) use ($search) {
|
||||||
$q->whereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%'])
|
$q->where('name', 'like', '%' . $search . '%')
|
||||||
->orWhereHas('position', function ($query) use ($search) {
|
->orWhereHas('position', function ($query) use ($search) {
|
||||||
$query->whereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%'])
|
$query->whereAny(['name', 'level'], 'like','%'.$search.'%');
|
||||||
->orWhereRaw('CAST(level AS TEXT) LIKE ?', ['%' . $search . '%']);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -283,19 +293,17 @@
|
|||||||
$order = $request->get('sortOrder');
|
$order = $request->get('sortOrder');
|
||||||
$column = $request->get('sortField');
|
$column = $request->get('sortField');
|
||||||
|
|
||||||
// Handle sorting for position-related columns
|
|
||||||
if ($column === 'position_name') {
|
if ($column === 'position_name') {
|
||||||
$query->leftJoin('positions', 'roles.position_id', '=', 'positions.id')
|
$query->leftJoin('positions', 'roles.position_id', '=', 'positions.id')
|
||||||
->orderByRaw('LOWER(positions.name) ' . $order)
|
->orderBy('positions.name', $order)
|
||||||
->select('roles.*'); // Select only from roles table to avoid column conflicts
|
->select('roles.*'); // Select only from roles table to avoid column conflicts
|
||||||
} else if ($column === 'level') {
|
} else if ($column === 'level') {
|
||||||
$query->leftJoin('positions', 'roles.position_id', '=', 'positions.id')
|
$query->leftJoin('positions', 'roles.position_id', '=', 'positions.id')
|
||||||
->orderBy('positions.level', $order)
|
->orderBy('positions.level', $order)
|
||||||
->select('roles.*'); // Select only from roles table to avoid column conflicts
|
->select('roles.*'); // Select only from roles table to avoid column conflicts
|
||||||
} else {
|
} else {
|
||||||
// Make sorting case-insensitive for string columns
|
|
||||||
if ($column === 'name') {
|
if ($column === 'name') {
|
||||||
$query->orderByRaw('LOWER(roles.name) ' . $order);
|
$query->orderBy('roles.name', $order);
|
||||||
} else {
|
} else {
|
||||||
$query->orderBy($column, $order);
|
$query->orderBy($column, $order);
|
||||||
}
|
}
|
||||||
@@ -321,7 +329,7 @@
|
|||||||
$filteredRecords = $countQuery->distinct()->count('roles.id');
|
$filteredRecords = $countQuery->distinct()->count('roles.id');
|
||||||
|
|
||||||
// Get the data for the current page
|
// Get the data for the current page
|
||||||
$roles = $query->with('position')->get();
|
$data = $query->with('position')->get();
|
||||||
|
|
||||||
// Calculate the page count - ensure we don't divide by zero
|
// Calculate the page count - ensure we don't divide by zero
|
||||||
$pageSize = $request->get('size', 10); // Default to 10 if not provided
|
$pageSize = $request->get('size', 10); // Default to 10 if not provided
|
||||||
@@ -338,12 +346,16 @@
|
|||||||
'pageCount' => $pageCount,
|
'pageCount' => $pageCount,
|
||||||
'page' => $currentPage,
|
'page' => $currentPage,
|
||||||
'totalCount' => $totalRecords,
|
'totalCount' => $totalRecords,
|
||||||
'data' => $roles,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function export()
|
public function export()
|
||||||
{
|
{
|
||||||
|
if (is_null($this->user) || !$this->user->can('usermanagement.export')) {
|
||||||
|
abort(403, 'Sorry! You are not allowed to export roles.');
|
||||||
|
}
|
||||||
|
|
||||||
return Excel::download(new RolesExport, 'roles.xlsx');
|
return Excel::download(new RolesExport, 'roles.xlsx');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,13 @@
|
|||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
use Modules\Lpj\Models\Branch;
|
use Modules\Basicdata\Models\Branch;
|
||||||
use Modules\Usermanagement\Exports\UsersExport;
|
use Modules\Usermanagement\Exports\UsersExport;
|
||||||
use Modules\Usermanagement\Http\Requests\User as UserRequest;
|
use Modules\Usermanagement\Http\Requests\User as UserRequest;
|
||||||
use Modules\Usermanagement\Models\Role;
|
use Modules\Usermanagement\Models\Role;
|
||||||
use Modules\Usermanagement\Models\User;
|
use Modules\Usermanagement\Models\User;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UsersController
|
* Class UsersController
|
||||||
@@ -28,7 +29,7 @@
|
|||||||
/**
|
/**
|
||||||
* @var \Illuminate\Contracts\Auth\Authenticatable|null
|
* @var \Illuminate\Contracts\Auth\Authenticatable|null
|
||||||
*/
|
*/
|
||||||
public $user;
|
protected $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UsersController constructor.
|
* UsersController constructor.
|
||||||
@@ -37,7 +38,14 @@
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->user = Auth::guard('web')->user();
|
// Mengatur middleware auth
|
||||||
|
$this->middleware('auth');
|
||||||
|
|
||||||
|
// Mengatur user setelah middleware auth dijalankan
|
||||||
|
$this->middleware(function ($request, $next) {
|
||||||
|
$this->user = Auth::user();
|
||||||
|
return $next($request);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +57,7 @@
|
|||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
if (is_null($this->user) || !$this->user->can('usermanagement.read')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.read')) {
|
||||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
abort(403, 'Sorry! You are not allowed to view users.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('usermanagement::users.index');
|
return view('usermanagement::users.index');
|
||||||
@@ -65,61 +73,61 @@
|
|||||||
*/
|
*/
|
||||||
public function dataForDatatables(Request $request)
|
public function dataForDatatables(Request $request)
|
||||||
{
|
{
|
||||||
if (is_null($this->user) || !$this->user->can('usermanagement.view')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.read')) {
|
||||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
return response()->json([
|
||||||
|
'message' => 'Sorry! You are not allowed to view users.',
|
||||||
|
'success' => false
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve data from the database
|
$query = User::query()->with(['branches', 'roles']);
|
||||||
$query = User::query();
|
|
||||||
|
|
||||||
// Apply search filter if provided
|
if (!$this->user->hasRole('administrator')) {
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
$query->whereHas('roles', function ($q) {
|
||||||
$search = $request->get('search');
|
$q->where('name', '!=', 'administrator');
|
||||||
$query->where(function ($q) use ($search) {
|
});
|
||||||
$q
|
}
|
||||||
->whereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%'])
|
|
||||||
->orWhereRaw('LOWER(email) LIKE ?', ['%' . strtolower($search) . '%']);
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
|
$search = $request->get('search');
|
||||||
|
$query->where(function ($q) use ($search) {
|
||||||
|
$q->where('name', 'like', '%' . $search . '%')
|
||||||
|
->orWhere('email', 'like', '%' . $search . '%')
|
||||||
|
->orWhereHas('branches', function ($qb) use ($search) {
|
||||||
|
$qb->where('name', 'like', '%' . $search . '%');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply sorting if provided
|
|
||||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||||
$order = $request->get('sortOrder');
|
$order = $request->get('sortOrder');
|
||||||
$column = $request->get('sortField');
|
$column = $request->get('sortField');
|
||||||
$query->orderBy($column, $order);
|
$query->orderBy($column, $order);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the total count of records
|
|
||||||
$totalRecords = $query->count();
|
$totalRecords = $query->count();
|
||||||
|
|
||||||
// Apply pagination if provided
|
$page = $request->get('page', 1);
|
||||||
if ($request->has('page') && $request->has('size')) {
|
$size = $request->get('size', 10);
|
||||||
$page = $request->get('page');
|
$offset = ($page - 1) * $size;
|
||||||
$size = $request->get('size');
|
|
||||||
$offset = ($page - 1) * $size; // Calculate the offset
|
|
||||||
|
|
||||||
$query->skip($offset)->take($size);
|
$query->skip($offset)->take($size);
|
||||||
}
|
|
||||||
|
|
||||||
// Get the filtered count of records
|
|
||||||
$filteredRecords = $query->count();
|
$filteredRecords = $query->count();
|
||||||
|
|
||||||
// Get the data for the current page
|
$users = $query->get()->map(function ($user) {
|
||||||
$users = $query->with(['branch', 'roles'])->get();
|
$user->branch_names = $user->branches->pluck('name')->join(', ');
|
||||||
|
return $user;
|
||||||
|
});
|
||||||
|
|
||||||
// Calculate the page count
|
$pageCount = ceil($totalRecords / $size);
|
||||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
|
||||||
|
|
||||||
// Calculate the current page number
|
|
||||||
$currentPage = 0 + 1;
|
|
||||||
|
|
||||||
// Return the response data as a JSON object
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'draw' => $request->get('draw'),
|
'draw' => $request->get('draw'),
|
||||||
'recordsTotal' => $totalRecords,
|
'recordsTotal' => $totalRecords,
|
||||||
'recordsFiltered' => $filteredRecords,
|
'recordsFiltered' => $filteredRecords,
|
||||||
'pageCount' => $pageCount,
|
'pageCount' => $pageCount,
|
||||||
'page' => $currentPage,
|
'page' => $page,
|
||||||
'totalCount' => $totalRecords,
|
'totalCount' => $totalRecords,
|
||||||
'data' => $users,
|
'data' => $users,
|
||||||
]);
|
]);
|
||||||
@@ -135,12 +143,15 @@
|
|||||||
*/
|
*/
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
if (is_null($this->user) || !$this->user->can('usermanagement.edit')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.update')) {
|
||||||
//abort(403, 'Sorry! You are not allowed to edit users.');
|
abort(403, 'Sorry! You are not allowed to edit users.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = User::find($id);
|
$user = User::find($id);
|
||||||
$roles = Role::all();
|
$roles = Role::all();
|
||||||
|
if (!$this->user->hasRole('administrator')) {
|
||||||
|
$roles = $roles->where('name', '!=', 'administrator');
|
||||||
|
}
|
||||||
$branches = Branch::all();
|
$branches = Branch::all();
|
||||||
return view('usermanagement::users.create', compact('user', 'roles', 'branches'));
|
return view('usermanagement::users.create', compact('user', 'roles', 'branches'));
|
||||||
}
|
}
|
||||||
@@ -156,7 +167,7 @@
|
|||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
if (is_null($this->user) || !$this->user->can('usermanagement.delete')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.delete')) {
|
||||||
//abort(403, 'Sorry! You are not allowed to delete users.');
|
return response()->json(['message' => 'Sorry! You are not allowed to delete users.', 'success' => false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = User::find($id);
|
$user = User::find($id);
|
||||||
@@ -198,15 +209,31 @@
|
|||||||
*/
|
*/
|
||||||
public function store(UserRequest $request)
|
public function store(UserRequest $request)
|
||||||
{
|
{
|
||||||
|
if (is_null($this->user) || !$this->user->can('usermanagement.create')) {
|
||||||
|
abort(403, 'Sorry! You are not allowed to create a user.');
|
||||||
|
}
|
||||||
|
|
||||||
$validated = $request->validated();
|
$validated = $request->validated();
|
||||||
|
|
||||||
if ($validated) {
|
if ($validated) {
|
||||||
$user = User::create($validated);
|
$user = User::create($validated);
|
||||||
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
if ($request->roles) {
|
if ($request->roles) {
|
||||||
$user->assignRole($request->roles);
|
$user->assignRole($request->roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$branches = $request->input('branches', []);
|
||||||
|
|
||||||
|
$user->branches()->sync($branches);
|
||||||
|
|
||||||
|
if (!empty($branches)) {
|
||||||
|
$firstBranchId = $branches[0];
|
||||||
|
|
||||||
|
$user->branch_id = $firstBranchId;
|
||||||
|
$user->save();
|
||||||
|
}
|
||||||
|
|
||||||
return redirect()->route('users.index')->with('success', 'User created successfully.');
|
return redirect()->route('users.index')->with('success', 'User created successfully.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,17 +250,27 @@
|
|||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
if (is_null($this->user) || !$this->user->can('usermanagement.create')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.create')) {
|
||||||
//abort(403, 'Sorry! You are not allowed to create a user.');
|
abort(403, 'Sorry! You are not allowed to create a user.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$roles = Role::all();
|
$roles = Role::all();
|
||||||
|
if (!$this->user->hasRole('administrator')) {
|
||||||
|
$roles = $roles->where('name', '!=', 'administrator');
|
||||||
|
}
|
||||||
$branches = Branch::all();
|
$branches = Branch::all();
|
||||||
return view('usermanagement::users.create', compact('roles', 'branches'));
|
return view('usermanagement::users.create', compact('roles', 'branches'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function export()
|
public function export(Request $request)
|
||||||
{
|
{
|
||||||
return Excel::download(new UsersExport, 'users.xlsx');
|
if (is_null($this->user) || !$this->user->can('usermanagement.export')) {
|
||||||
|
abort(403, 'Sorry! You are not allowed to export users.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get search parameter from request
|
||||||
|
$search = $request->get('search');
|
||||||
|
|
||||||
|
return Excel::download(new UsersExport($search), 'users.xlsx');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function profile()
|
public function profile()
|
||||||
@@ -249,7 +286,6 @@
|
|||||||
$validatedData = $request->validate([
|
$validatedData = $request->validate([
|
||||||
'name' => 'required|string|max:255',
|
'name' => 'required|string|max:255',
|
||||||
'email' => 'required|string|email|max:255|unique:users,email,' . $user->id,
|
'email' => 'required|string|email|max:255|unique:users,email,' . $user->id,
|
||||||
'nik' => 'required|string|max:255|unique:users,nik,' . $user->id,
|
|
||||||
'sign' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048',
|
'sign' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -316,32 +352,45 @@
|
|||||||
public function update(UserRequest $request, $id)
|
public function update(UserRequest $request, $id)
|
||||||
{
|
{
|
||||||
if (is_null($this->user) || !$this->user->can('usermanagement.update')) {
|
if (is_null($this->user) || !$this->user->can('usermanagement.update')) {
|
||||||
//abort(403, 'Sorry! You are not allowed to update users.');
|
abort(403, 'Sorry! You are not allowed to update users.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$validated = $request->validated();
|
$validated = $request->validated();
|
||||||
|
|
||||||
if ($validated) {
|
if ($validated) {
|
||||||
try {
|
try {
|
||||||
$user = User::find($id);
|
$user = User::findOrFail($id);
|
||||||
|
|
||||||
|
// Handle file upload e-sign
|
||||||
if ($request->hasFile('sign')) {
|
if ($request->hasFile('sign')) {
|
||||||
$sign = $request->file('sign');
|
$sign = $request->file('sign');
|
||||||
|
|
||||||
$signName = time() . '.' . $sign->getClientOriginalExtension();
|
$signName = time() . '.' . $sign->getClientOriginalExtension();
|
||||||
|
|
||||||
|
// Simpan file ke storage
|
||||||
$sign->storeAs(
|
$sign->storeAs(
|
||||||
'public/signatures/' . $user->id . '/',
|
'public/signatures/' . $user->id . '/',
|
||||||
$signName,
|
$signName
|
||||||
);
|
);
|
||||||
|
|
||||||
$validated['sign'] = $signName;
|
$validated['sign'] = $signName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update data user
|
||||||
$user->update($validated);
|
$user->update($validated);
|
||||||
|
|
||||||
|
// Update roles
|
||||||
if ($request->roles) {
|
if ($request->roles) {
|
||||||
$user->roles()->detach();
|
$user->roles()->detach();
|
||||||
$user->assignRole($request->roles);
|
$user->assignRole($request->roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$user->branches()->sync($request->input('branches', []));
|
||||||
|
|
||||||
|
$branchIds = $user->branches()->pluck('branches.id')->toArray();
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
Log::error('Failed to update user: ' . $e->getMessage());
|
||||||
return redirect()->back()->withErrors(['error' => 'Failed to update user. Please try again.']);
|
return redirect()->back()->withErrors(['error' => 'Failed to update user. Please try again.']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Modules\Basicdata\Models\Branch;
|
use Modules\Basicdata\Models\Branch;
|
||||||
|
use Modules\Adk\Models\Appointment;
|
||||||
use Spatie\Permission\Traits\HasRoles;
|
use Spatie\Permission\Traits\HasRoles;
|
||||||
use Mattiverse\Userstamps\Traits\Userstamps;
|
use Mattiverse\Userstamps\Traits\Userstamps;
|
||||||
|
|
||||||
@@ -68,8 +69,7 @@
|
|||||||
*
|
*
|
||||||
* @return array<string, string>
|
* @return array<string, string>
|
||||||
*/
|
*/
|
||||||
protected function casts()
|
protected function casts(): array
|
||||||
: array
|
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'email_verified_at' => 'datetime',
|
'email_verified_at' => 'datetime',
|
||||||
@@ -78,7 +78,8 @@
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function branch(){
|
public function branch()
|
||||||
|
{
|
||||||
return $this->belongsTo(Branch::class);
|
return $this->belongsTo(Branch::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,4 +92,25 @@
|
|||||||
{
|
{
|
||||||
return \Modules\Usermanagement\Database\Factories\UserFactory::new();
|
return \Modules\Usermanagement\Database\Factories\UserFactory::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all of the appointments for the User
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
*/
|
||||||
|
public function appointments()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Appointment::class, 'admin_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function appointment_cabangs()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Appointment::class, 'admin_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function branches()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Branch::class, 'user_branches', 'user_id', 'branch_id')
|
||||||
|
->withTimestamps();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
app/Models/UserBranch.php
Normal file
35
app/Models/UserBranch.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Usermanagement\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Modules\Usermanagement\Models\User;
|
||||||
|
use Modules\Basicdata\Models\Branch;
|
||||||
|
|
||||||
|
// use Modules\Usermanagement\Database\Factories\UserBranchFactory;
|
||||||
|
|
||||||
|
class UserBranch extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*/
|
||||||
|
protected $table = 'user_branches';
|
||||||
|
protected $fillable = [
|
||||||
|
'user_id',
|
||||||
|
'branch_id',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class)
|
||||||
|
->withTimestamps();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function branch()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Branch::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
||||||
@@ -46,8 +45,12 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::dropIfExists('users');
|
Schema::disableForeignKeyConstraints();
|
||||||
Schema::dropIfExists('password_reset_tokens');
|
|
||||||
Schema::dropIfExists('sessions');
|
Schema::dropIfExists('sessions');
|
||||||
|
Schema::dropIfExists('password_reset_tokens');
|
||||||
|
Schema::dropIfExists('users');
|
||||||
|
|
||||||
|
Schema::enableForeignKeyConstraints();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('user_branches', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->unsignedBigInteger('user_id');
|
||||||
|
$table->unsignedBigInteger('branch_id');
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||||
|
$table->foreign('branch_id')->references('id')->on('branches')->onDelete('cascade');
|
||||||
|
|
||||||
|
$table->unique(['user_id', 'branch_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('user_branches');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -28,8 +28,11 @@
|
|||||||
public function data()
|
public function data()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['name' => 'usermanagement'],
|
['name' => 'adk'],
|
||||||
['name' => 'basic-data']
|
['name' => 'basicdata'],
|
||||||
|
['name' => 'location'],
|
||||||
|
['name' => 'logs'],
|
||||||
|
['name' => 'usermanagement']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,40 +9,40 @@
|
|||||||
|
|
||||||
class PermissionsSeeder extends Seeder
|
class PermissionsSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$data = $this->data();
|
$data = $this->data();
|
||||||
|
|
||||||
foreach ($data as $value) {
|
foreach ($data as $value) {
|
||||||
|
|
||||||
$permission = Permission::updateOrCreate([
|
$permission = Permission::updateOrCreate([
|
||||||
'name' => $value['name'],
|
'name' => $value['name'],
|
||||||
'guard_name' => 'web' // or 'api
|
'guard_name' => 'web',
|
||||||
], [
|
], [
|
||||||
'permission_group_id' => $value['group']
|
'permission_group_id' => $value['group_id'],
|
||||||
|
'module' => $value['module'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$roles = Role::all();
|
foreach (Role::all() as $role) {
|
||||||
foreach ($roles as $role) {
|
|
||||||
$role->givePermissionTo($permission);
|
$role->givePermissionTo($permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function data()
|
public function data()
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
// list of model permission
|
|
||||||
$groups = PermissionGroup::all();
|
$groups = PermissionGroup::all();
|
||||||
|
|
||||||
foreach ($groups as $group) {
|
foreach ($groups as $group) {
|
||||||
|
|
||||||
foreach ($this->crudActions($group->name) as $action) {
|
foreach ($this->crudActions($group->name) as $action) {
|
||||||
$data[] = ['name' => $action, 'group' => $group->id];
|
|
||||||
|
$data[] = [
|
||||||
|
'name' => $action,
|
||||||
|
'group_id' => $group->id,
|
||||||
|
'module' => $group->name,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,15 +51,13 @@
|
|||||||
|
|
||||||
public function crudActions($name)
|
public function crudActions($name)
|
||||||
{
|
{
|
||||||
$actions = [];
|
$actions = ['create', 'read', 'update', 'delete', 'export', 'authorize', 'report', 'restore'];
|
||||||
// list of permission actions
|
$result = [];
|
||||||
$crud = ['create', 'read', 'update', 'delete','export', 'authorize', 'report'];
|
|
||||||
|
|
||||||
|
foreach ($actions as $value) {
|
||||||
foreach ($crud as $value) {
|
$result[] = $name . '.' . $value;
|
||||||
$actions[] = $name . '.' . $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $actions;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
database/seeders/UserBranchesSeeder.php
Normal file
38
database/seeders/UserBranchesSeeder.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Usermanagement\Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Modules\Usermanagement\Models\User;
|
||||||
|
|
||||||
|
class UserBranchesSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
$users = User::all();
|
||||||
|
|
||||||
|
foreach ($users as $user) {
|
||||||
|
if ($user->branch_id) {
|
||||||
|
$exists = DB::table('user_branches')
|
||||||
|
->where('user_id', $user->id)
|
||||||
|
->where('branch_id', $user->branch_id)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if (!$exists) {
|
||||||
|
DB::table('user_branches')->insert([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'branch_id' => $user->branch_id,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->command->info('User branches seeded successfully.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,34 +2,195 @@
|
|||||||
|
|
||||||
namespace Modules\Usermanagement\Database\Seeders;
|
namespace Modules\Usermanagement\Database\Seeders;
|
||||||
|
|
||||||
use Faker\Generator;
|
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Modules\Usermanagement\Models\User;
|
use Modules\Usermanagement\Models\User;
|
||||||
|
use Modules\Usermanagement\Database\Seeders\RolesSeeder;
|
||||||
use Spatie\Permission\Models\Role;
|
use Spatie\Permission\Models\Role;
|
||||||
|
|
||||||
class UsersSeeder extends Seeder
|
class UsersSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Run the database seeds.
|
* Run the database seeds.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function run(Generator $faker)
|
public function run(): void
|
||||||
{
|
{
|
||||||
$roles = Role::all();
|
$roleSeeder = new RolesSeeder();
|
||||||
|
$rolesData = $roleSeeder->data();
|
||||||
|
|
||||||
foreach ($roles as $role) {
|
/**
|
||||||
$user = User::create([
|
* ==================================================
|
||||||
'name' => $role->name,
|
* STEP 0: Pastikan semua roles dari RolesSeeder sudah dibuat di tabel roles
|
||||||
'email' => $role->name . '@ag.co.id',
|
* ==================================================
|
||||||
|
*/
|
||||||
|
foreach ($rolesData as $roleData) {
|
||||||
|
Role::firstOrCreate(
|
||||||
|
['name' => $roleData['name']],
|
||||||
|
['guard_name' => 'web']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ==================================================
|
||||||
|
* Helper function untuk membuat user
|
||||||
|
* ==================================================
|
||||||
|
*/
|
||||||
|
$createUser = function ($roleName, $branchId = null, $includeBranchInEmail = true, $includeBranchInName = true) {
|
||||||
|
$email = $roleName . ($includeBranchInEmail && $branchId ? $branchId : '') . '@ag.co.id';
|
||||||
|
|
||||||
|
$name = ucfirst($roleName);
|
||||||
|
if ($includeBranchInName && $branchId) {
|
||||||
|
$name .= ' ' . $branchId;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = User::firstOrCreate(
|
||||||
|
['email' => $email],
|
||||||
|
[
|
||||||
|
'name' => $name,
|
||||||
'password' => Hash::make('bagbag'),
|
'password' => Hash::make('bagbag'),
|
||||||
'branch_id' => 1,
|
'branch_id' => $branchId,
|
||||||
'nik' => '000000',
|
'nik' => rand(100000, 999999),
|
||||||
'email_verified_at' => now(),
|
'email_verified_at' => now(),
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$role = Role::where('name', $roleName)->first();
|
||||||
|
if ($role) {
|
||||||
$user->assignRole($role);
|
$user->assignRole($role);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ==================================================
|
||||||
|
* STEP 1: Buat user per role (branch_id = 1)
|
||||||
|
* ==================================================
|
||||||
|
* - Tanpa angka "1" di email
|
||||||
|
* - Tanpa angka "1" di nama
|
||||||
|
*/
|
||||||
|
foreach ($rolesData as $roleData) {
|
||||||
|
$roleName = $roleData['name'];
|
||||||
|
$createUser($roleName, 1, false, false); // tanpa 1 di email & nama
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ==================================================
|
||||||
|
* STEP 2: Jalankan logic lama (user per cabang)
|
||||||
|
* ==================================================
|
||||||
|
*/
|
||||||
|
$branchLuar = [
|
||||||
|
24,
|
||||||
|
25,
|
||||||
|
29,
|
||||||
|
35,
|
||||||
|
37,
|
||||||
|
41,
|
||||||
|
42,
|
||||||
|
45,
|
||||||
|
46,
|
||||||
|
50,
|
||||||
|
71,
|
||||||
|
74,
|
||||||
|
77,
|
||||||
|
82,
|
||||||
|
84,
|
||||||
|
85,
|
||||||
|
88,
|
||||||
|
90,
|
||||||
|
91,
|
||||||
|
93,
|
||||||
|
97,
|
||||||
|
107,
|
||||||
|
108,
|
||||||
|
111,
|
||||||
|
112,
|
||||||
|
113,
|
||||||
|
114,
|
||||||
|
115
|
||||||
|
];
|
||||||
|
|
||||||
|
$branchDalam = [
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
7,
|
||||||
|
8,
|
||||||
|
9,
|
||||||
|
10,
|
||||||
|
11,
|
||||||
|
12,
|
||||||
|
14,
|
||||||
|
15,
|
||||||
|
17,
|
||||||
|
18,
|
||||||
|
22,
|
||||||
|
23,
|
||||||
|
53,
|
||||||
|
55,
|
||||||
|
58,
|
||||||
|
60,
|
||||||
|
61,
|
||||||
|
66,
|
||||||
|
70,
|
||||||
|
95,
|
||||||
|
96,
|
||||||
|
98,
|
||||||
|
100,
|
||||||
|
105
|
||||||
|
];
|
||||||
|
|
||||||
|
$kpno = 6;
|
||||||
|
|
||||||
|
// LEGAL
|
||||||
|
foreach ($branchLuar as $branchId) {
|
||||||
|
$createUser('legal', $branchId);
|
||||||
|
}
|
||||||
|
$createUser('legal', $kpno);
|
||||||
|
|
||||||
|
// SPV LEGAL
|
||||||
|
$createUser('spvlegal', $kpno);
|
||||||
|
|
||||||
|
// USER CABANG
|
||||||
|
foreach (array_merge($branchLuar, $branchDalam) as $branchId) {
|
||||||
|
$createUser('cabang', $branchId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ADMIN DOKUMEN
|
||||||
|
foreach ($branchLuar as $branchId) {
|
||||||
|
$createUser('admindokumen', $branchId);
|
||||||
|
}
|
||||||
|
$createUser('admindokumen', $kpno);
|
||||||
|
|
||||||
|
// ADMIN KREDIT
|
||||||
|
$createUser('adminkredit', $kpno);
|
||||||
|
|
||||||
|
// AUDITOR
|
||||||
|
foreach ($branchLuar as $branchId) {
|
||||||
|
$createUser('auditor', $branchId);
|
||||||
|
}
|
||||||
|
$createUser('auditor', $kpno);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ==================================================
|
||||||
|
* NEW STEP: BRANCHDIRECTOR UNTUK SEMUA BRANCH
|
||||||
|
* ==================================================
|
||||||
|
*/
|
||||||
|
foreach (array_merge($branchLuar, $branchDalam) as $branchId) {
|
||||||
|
$createUser('branchdirector', $branchId);
|
||||||
|
}
|
||||||
|
$createUser('branchdirector', $kpno);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ==================================================
|
||||||
|
* NEW STEP: SO ADMIN DOKUMEN UNTUK SEMUA BRANCH
|
||||||
|
* ==================================================
|
||||||
|
*/
|
||||||
|
foreach (array_merge($branchLuar, $branchDalam) as $branchId) {
|
||||||
|
$createUser('soadmindokumen', $branchId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// tetap buat juga untuk KPNO
|
||||||
|
$createUser('soadmindokumen', $kpno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
"providers": [
|
"providers": [
|
||||||
"Modules\\Usermanagement\\Providers\\UsermanagementServiceProvider"
|
"Modules\\Usermanagement\\Providers\\UsermanagementServiceProvider"
|
||||||
],
|
],
|
||||||
"files": [],
|
"files": [
|
||||||
|
"app/Helpers/RolePermission.php"
|
||||||
|
],
|
||||||
"menu": {
|
"menu": {
|
||||||
"main": [],
|
"main": [],
|
||||||
"master": [],
|
"master": [],
|
||||||
|
|||||||
@@ -7,8 +7,10 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="5" data-datatable-state-save="true" id="permissions-table" data-api-url="{{ route('users.permissions.datatables') }}">
|
<div class="min-w-full card card-grid" data-datatable="false" data-datatable-page-size="5"
|
||||||
<div class="card-header py-5 flex-wrap">
|
data-datatable-state-save="true" id="permissions-table"
|
||||||
|
data-api-url="{{ route('users.permissions.datatables') }}">
|
||||||
|
<div class="flex-wrap py-5 card-header">
|
||||||
<h3 class="card-title">
|
<h3 class="card-title">
|
||||||
List of Permissions
|
List of Permissions
|
||||||
</h3>
|
</h3>
|
||||||
@@ -21,14 +23,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex flex-wrap gap-2.5 lg:gap-5">
|
<div class="flex flex-wrap gap-2.5 lg:gap-5">
|
||||||
<div class="h-[24px] border border-r-gray-200"> </div>
|
<div class="h-[24px] border border-r-gray-200"> </div>
|
||||||
<a class="btn btn-sm btn-light" href="{{ route('users.permissions.export') }}"> Export to Excel </a>
|
<a class="btn btn-sm btn-light" href="{{ route('users.permissions.export') }}"> Export to Excel
|
||||||
<a class="btn btn-sm btn-primary" href="{{ route('users.permissions.create') }}"> Add Permission </a>
|
</a>
|
||||||
|
<a class="btn btn-sm btn-primary" href="{{ route('users.permissions.create') }}"> Add Permission
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="scrollable-x-auto">
|
<div class="scrollable-x-auto">
|
||||||
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
|
<table class="table text-sm font-medium text-gray-700 align-middle table-auto table-border"
|
||||||
|
data-datatable-table="true">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-14">
|
<th class="w-14">
|
||||||
@@ -47,12 +52,14 @@
|
|||||||
</thead>
|
</thead>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
|
<div
|
||||||
<div class="flex items-center gap-2">
|
class="flex-col gap-3 justify-center font-medium text-gray-600 card-footer md:justify-between md:flex-row text-2sm">
|
||||||
|
<div class="flex gap-2 items-center">
|
||||||
Show
|
Show
|
||||||
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"> </select> per page
|
<select class="w-16 select select-sm" data-datatable-size="true" name="perpage"> </select> per
|
||||||
|
page
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex gap-4 items-center">
|
||||||
<span data-datatable-info="true"> </span>
|
<span data-datatable-info="true"> </span>
|
||||||
<div class="pagination" data-datatable-pagination="true">
|
<div class="pagination" data-datatable-pagination="true">
|
||||||
</div>
|
</div>
|
||||||
@@ -154,7 +161,7 @@
|
|||||||
searchInput.addEventListener('input', function() {
|
searchInput.addEventListener('input', function() {
|
||||||
const searchValue = this.value.trim();
|
const searchValue = this.value.trim();
|
||||||
dataTable.search(searchValue, true);
|
dataTable.search(searchValue, true);
|
||||||
|
dataTable.goPage(1);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="5" data-datatable-state-save="true" id="positions-table" data-api-url="{{ route('users.positions.datatables') }}">
|
<div class="min-w-full card card-grid" data-datatable="false" data-datatable-page-size="5"
|
||||||
<div class="card-header py-5 flex-wrap">
|
data-datatable-state-save="true" id="positions-table" data-api-url="{{ route('users.positions.datatables') }}">
|
||||||
|
<div class="flex-wrap py-5 card-header">
|
||||||
<h3 class="card-title">
|
<h3 class="card-title">
|
||||||
List of Positions
|
List of Positions
|
||||||
</h3>
|
</h3>
|
||||||
@@ -20,14 +21,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex flex-wrap gap-2.5 lg:gap-5">
|
<div class="flex flex-wrap gap-2.5 lg:gap-5">
|
||||||
<div class="h-[100%] border border-r-gray-200"> </div>
|
<div class="h-[100%] border border-r-gray-200"> </div>
|
||||||
<a class="btn btn-sm btn-light" id="export-btn" href="{{ route('users.positions.export') }}"> Export to Excel </a>
|
<a class="btn btn-sm btn-light" id="export-btn" href="{{ route('users.positions.export') }}">
|
||||||
<a class="btn btn-sm btn-primary" href="{{ route('users.positions.create') }}"> Add Position </a>
|
Export to Excel </a>
|
||||||
|
<a class="btn btn-sm btn-primary" href="{{ route('users.positions.create') }}"> Add Position
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="scrollable-x-auto">
|
<div class="scrollable-x-auto">
|
||||||
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
|
<table class="table text-sm font-medium text-gray-700 align-middle table-auto table-border"
|
||||||
|
data-datatable-table="true">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-14">
|
<th class="w-14">
|
||||||
@@ -50,12 +54,14 @@
|
|||||||
</thead>
|
</thead>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
|
<div
|
||||||
<div class="flex items-center gap-2">
|
class="flex-col gap-3 justify-center font-medium text-gray-600 card-footer md:justify-between md:flex-row text-2sm">
|
||||||
|
<div class="flex gap-2 items-center">
|
||||||
Show
|
Show
|
||||||
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"> </select> per page
|
<select class="w-16 select select-sm" data-datatable-size="true" name="perpage"> </select> per
|
||||||
|
page
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex gap-4 items-center">
|
||||||
<span data-datatable-info="true"> </span>
|
<span data-datatable-info="true"> </span>
|
||||||
<div class="pagination" data-datatable-pagination="true">
|
<div class="pagination" data-datatable-pagination="true">
|
||||||
</div>
|
</div>
|
||||||
@@ -153,6 +159,7 @@
|
|||||||
searchInput.addEventListener('input', function() {
|
searchInput.addEventListener('input', function() {
|
||||||
const searchValue = this.value.trim();
|
const searchValue = this.value.trim();
|
||||||
dataTable.search(searchValue, true);
|
dataTable.search(searchValue, true);
|
||||||
|
dataTable.goPage(1);
|
||||||
|
|
||||||
// Update export URL with search parameter
|
// Update export URL with search parameter
|
||||||
if (searchValue) {
|
if (searchValue) {
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="5" data-datatable-state-save="true" id="roles-table" data-api-url="{{ route('users.roles.datatables') }}">
|
<div class="min-w-full card card-grid" data-datatable="false" data-datatable-page-size="5"
|
||||||
<div class="card-header py-5 flex-wrap">
|
data-datatable-state-save="true" id="roles-table" data-api-url="{{ route('users.roles.datatables') }}">
|
||||||
|
<div class="flex-wrap py-5 card-header">
|
||||||
<h3 class="card-title">
|
<h3 class="card-title">
|
||||||
List of Roles
|
List of Roles
|
||||||
</h3>
|
</h3>
|
||||||
@@ -28,7 +29,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="scrollable-x-auto">
|
<div class="scrollable-x-auto">
|
||||||
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
|
<table class="table text-sm font-medium text-gray-700 align-middle table-auto table-border"
|
||||||
|
data-datatable-table="true">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-14">
|
<th class="w-14">
|
||||||
@@ -51,12 +53,14 @@
|
|||||||
</thead>
|
</thead>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
|
<div
|
||||||
<div class="flex items-center gap-2">
|
class="flex-col gap-3 justify-center font-medium text-gray-600 card-footer md:justify-between md:flex-row text-2sm">
|
||||||
|
<div class="flex gap-2 items-center">
|
||||||
Show
|
Show
|
||||||
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"> </select> per page
|
<select class="w-16 select select-sm" data-datatable-size="true" name="perpage"> </select> per
|
||||||
|
page
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex gap-4 items-center">
|
||||||
<span data-datatable-info="true"> </span>
|
<span data-datatable-info="true"> </span>
|
||||||
<div class="pagination" data-datatable-pagination="true">
|
<div class="pagination" data-datatable-pagination="true">
|
||||||
</div>
|
</div>
|
||||||
@@ -159,6 +163,7 @@
|
|||||||
searchInput.addEventListener('input', function() {
|
searchInput.addEventListener('input', function() {
|
||||||
const searchValue = this.value.trim();
|
const searchValue = this.value.trim();
|
||||||
dataTable.search(searchValue, true);
|
dataTable.search(searchValue, true);
|
||||||
|
dataTable.goPage(1);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|||||||
@@ -35,7 +35,8 @@
|
|||||||
Name
|
Name
|
||||||
</label>
|
</label>
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
<input class="input @error('name') border-danger @enderror" type="text" name="name" value="{{ $user->name ?? '' }}">
|
<input class="input @error('name') border-danger @enderror" type="text" name="name"
|
||||||
|
value="{{ $user->name ?? '' }}">
|
||||||
@error('name')
|
@error('name')
|
||||||
<em class="alert text-danger text-sm">{{ $message }}</em>
|
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||||
@enderror
|
@enderror
|
||||||
@@ -46,7 +47,8 @@
|
|||||||
Email
|
Email
|
||||||
</label>
|
</label>
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
<input class="w-full input @error('email') border-danger @enderror" type="email" name="email" value="{{ $user->email ?? '' }}">
|
<input class="w-full input @error('email') border-danger @enderror" type="email" name="email"
|
||||||
|
value="{{ $user->email ?? '' }}">
|
||||||
@error('email')
|
@error('email')
|
||||||
<em class="alert text-danger text-sm">{{ $message }}</em>
|
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||||
@enderror
|
@enderror
|
||||||
@@ -57,7 +59,8 @@
|
|||||||
NIK
|
NIK
|
||||||
</label>
|
</label>
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
<input class="w-full input @error('nik') border-danger @enderror" type="number" name="nik" value="{{ $user->nik ?? '' }}">
|
<input class="w-full input @error('nik') border-danger @enderror" type="number" name="nik"
|
||||||
|
value="{{ $user->nik ?? '' }}">
|
||||||
@error('nik')
|
@error('nik')
|
||||||
<em class="alert text-danger text-sm">{{ $message }}</em>
|
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||||
@enderror
|
@enderror
|
||||||
@@ -68,23 +71,17 @@
|
|||||||
Branch
|
Branch
|
||||||
</label>
|
</label>
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
<select class="input tomselect w-full @error('branch_id') border-danger @enderror" name="branch_id" id="branch_id">
|
<select class="input tomselect w-full @error('branches') border-danger @enderror" name="branches[]"
|
||||||
<option value="">Pilih Branch</option>
|
id="branches" multiple>
|
||||||
@if(isset($branches))
|
<option value="">-- Select Branch --</option>
|
||||||
@foreach($branches as $row)
|
@foreach ($branches as $branch)
|
||||||
@if(isset($user))
|
<option value="{{ $branch->id }}"
|
||||||
<option value="{{ $row->id }}" {{ isset($user->branch_id) && $user->branch_id == $row->id?'selected' : '' }}>
|
{{ isset($user) && $user->branches->pluck('id')->contains($branch->id) ? 'selected' : '' }}>
|
||||||
{{ $row->name }}
|
{{ $branch->name }}
|
||||||
</option>
|
</option>
|
||||||
@else
|
|
||||||
<option value="{{ $row->id }}">
|
|
||||||
{{ $row->name }}
|
|
||||||
</option>
|
|
||||||
@endif
|
|
||||||
@endforeach
|
@endforeach
|
||||||
@endif
|
|
||||||
</select>
|
</select>
|
||||||
@error('branch_id')
|
@error('branches')
|
||||||
<em class="alert text-danger text-sm">{{ $message }}</em>
|
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||||
@enderror
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
@@ -105,7 +102,8 @@
|
|||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
<div class="input @error('password') border-danger @enderror" data-toggle-password="true" data-toggle-password-permanent="true">
|
<div class="input @error('password') border-danger @enderror" data-toggle-password="true"
|
||||||
|
data-toggle-password-permanent="true">
|
||||||
<input placeholder="Password" type="password" name="password" />
|
<input placeholder="Password" type="password" name="password" />
|
||||||
<div class="btn btn-icon" data-toggle-password-trigger="true">
|
<div class="btn btn-icon" data-toggle-password-trigger="true">
|
||||||
<i class="ki-outline ki-eye toggle-password-active:hidden"></i>
|
<i class="ki-outline ki-eye toggle-password-active:hidden"></i>
|
||||||
@@ -122,7 +120,8 @@
|
|||||||
Password Confirmation
|
Password Confirmation
|
||||||
</label>
|
</label>
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
<div class="input @error('password_confirmation') border-danger @enderror" data-toggle-password="true" data-toggle-password-permanent="true">
|
<div class="input @error('password_confirmation') border-danger @enderror"
|
||||||
|
data-toggle-password="true" data-toggle-password-permanent="true">
|
||||||
<input placeholder="Password Confirmation" type="password" name="password_confirmation" />
|
<input placeholder="Password Confirmation" type="password" name="password_confirmation" />
|
||||||
<div class="btn btn-icon" data-toggle-password-trigger="true">
|
<div class="btn btn-icon" data-toggle-password-trigger="true">
|
||||||
<i class="ki-outline ki-eye toggle-password-active:hidden"></i>
|
<i class="ki-outline ki-eye toggle-password-active:hidden"></i>
|
||||||
@@ -144,23 +143,31 @@
|
|||||||
<div class="rounded-xl border p-4 flex items-center justify-between gap-2.5">
|
<div class="rounded-xl border p-4 flex items-center justify-between gap-2.5">
|
||||||
<div class="flex items-center gap-3.5">
|
<div class="flex items-center gap-3.5">
|
||||||
<div class="relative size-[45px] shrink-0">
|
<div class="relative size-[45px] shrink-0">
|
||||||
<svg class="w-full h-full stroke-gray-300 fill-gray-100" fill="none" height="48" viewBox="0 0 44 48" width="44" xmlns="http://www.w3.org/2000/svg">
|
<svg class="w-full h-full stroke-gray-300 fill-gray-100" fill="none"
|
||||||
<path d="M16 2.4641C19.7128 0.320509 24.2872 0.320508 28 2.4641L37.6506 8.0359C41.3634 10.1795 43.6506 14.141 43.6506
|
height="48" viewBox="0 0 44 48" width="44"
|
||||||
|
xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path
|
||||||
|
d="M16 2.4641C19.7128 0.320509 24.2872 0.320508 28 2.4641L37.6506 8.0359C41.3634 10.1795 43.6506 14.141 43.6506
|
||||||
18.4282V29.5718C43.6506 33.859 41.3634 37.8205 37.6506 39.9641L28 45.5359C24.2872 47.6795 19.7128 47.6795 16 45.5359L6.34937
|
18.4282V29.5718C43.6506 33.859 41.3634 37.8205 37.6506 39.9641L28 45.5359C24.2872 47.6795 19.7128 47.6795 16 45.5359L6.34937
|
||||||
39.9641C2.63655 37.8205 0.349365 33.859 0.349365 29.5718V18.4282C0.349365 14.141 2.63655 10.1795 6.34937 8.0359L16 2.4641Z" fill="">
|
39.9641C2.63655 37.8205 0.349365 33.859 0.349365 29.5718V18.4282C0.349365 14.141 2.63655 10.1795 6.34937 8.0359L16 2.4641Z"
|
||||||
|
fill="">
|
||||||
</path>
|
</path>
|
||||||
<path d="M16.25 2.89711C19.8081 0.842838 24.1919 0.842837 27.75 2.89711L37.4006 8.46891C40.9587 10.5232 43.1506 14.3196 43.1506
|
<path
|
||||||
|
d="M16.25 2.89711C19.8081 0.842838 24.1919 0.842837 27.75 2.89711L37.4006 8.46891C40.9587 10.5232 43.1506 14.3196 43.1506
|
||||||
18.4282V29.5718C43.1506 33.6804 40.9587 37.4768 37.4006 39.5311L27.75 45.1029C24.1919 47.1572 19.8081 47.1572 16.25 45.1029L6.59937
|
18.4282V29.5718C43.1506 33.6804 40.9587 37.4768 37.4006 39.5311L27.75 45.1029C24.1919 47.1572 19.8081 47.1572 16.25 45.1029L6.59937
|
||||||
39.5311C3.04125 37.4768 0.849365 33.6803 0.849365 29.5718V18.4282C0.849365 14.3196 3.04125 10.5232 6.59937 8.46891L16.25 2.89711Z" stroke="">
|
39.5311C3.04125 37.4768 0.849365 33.6803 0.849365 29.5718V18.4282C0.849365 14.3196 3.04125 10.5232 6.59937 8.46891L16.25 2.89711Z"
|
||||||
|
stroke="">
|
||||||
</path>
|
</path>
|
||||||
</svg>
|
</svg>
|
||||||
<div class="absolute leading-none left-2/4 top-2/4 -translate-y-2/4 -translate-x-2/4">
|
<div
|
||||||
|
class="absolute leading-none left-2/4 top-2/4 -translate-y-2/4 -translate-x-2/4">
|
||||||
<i class="ki-filled ki-category text-lg text-gray-500">
|
<i class="ki-filled ki-category text-lg text-gray-500">
|
||||||
</i>
|
</i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-1">
|
<div class="flex flex-col gap-1">
|
||||||
<span class="flex items-center gap-1.5 leading-none font-medium text-sm text-gray-900">
|
<span
|
||||||
|
class="flex items-center gap-1.5 leading-none font-medium text-sm text-gray-900">
|
||||||
{{ $role->name }}
|
{{ $role->name }}
|
||||||
</span>
|
</span>
|
||||||
<span class="text-2sm text-gray-700">
|
<span class="text-2sm text-gray-700">
|
||||||
@@ -170,7 +177,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="switch switch-sm">
|
<div class="switch switch-sm">
|
||||||
@if (isset($user))
|
@if (isset($user))
|
||||||
<input {{ in_array($role->name,$user->roles->pluck("name")->toArray()) ? 'checked' : '' }} name="roles" type="radio" value="{{ $role->name }}">
|
<input
|
||||||
|
{{ in_array($role->name, $user->roles->pluck('name')->toArray()) ? 'checked' : '' }}
|
||||||
|
name="roles" type="radio" value="{{ $role->name }}">
|
||||||
@else
|
@else
|
||||||
<input name="roles" type="radio" value="{{ $role->name }}">
|
<input name="roles" type="radio" value="{{ $role->name }}">
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="5" data-datatable-state-save="true" id="users-table" data-api-url="{{ route('users.datatables') }}">
|
<div class="min-w-full card card-grid" data-datatable="false" data-datatable-page-size="5"
|
||||||
<div class="card-header py-5 flex-wrap">
|
data-datatable-state-save="true" id="users-table" data-api-url="{{ route('users.datatables') }}">
|
||||||
|
<div class="flex-wrap py-5 card-header">
|
||||||
<h3 class="card-title">
|
<h3 class="card-title">
|
||||||
List of Users
|
List of Users
|
||||||
</h3>
|
</h3>
|
||||||
@@ -21,14 +22,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex flex-wrap gap-2.5 lg:gap-5">
|
<div class="flex flex-wrap gap-2.5 lg:gap-5">
|
||||||
<div class="h-[24px] border border-r-gray-200"> </div>
|
<div class="h-[24px] border border-r-gray-200"> </div>
|
||||||
<a class="btn btn-sm btn-light" href="{{ route('users.export') }}"> Export to Excel </a>
|
<a class="btn btn-sm btn-light" id="export-btn" href="{{ route('users.export') }}"> Export to
|
||||||
|
Excel </a>
|
||||||
<a class="btn btn-sm btn-primary" href="{{ route('users.create') }}"> Add User </a>
|
<a class="btn btn-sm btn-primary" href="{{ route('users.create') }}"> Add User </a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="scrollable-x-auto">
|
<div class="scrollable-x-auto">
|
||||||
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
|
<table class="table text-sm font-medium text-gray-700 align-middle table-auto table-border"
|
||||||
|
data-datatable-table="true">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-14">
|
<th class="w-14">
|
||||||
@@ -59,12 +62,14 @@
|
|||||||
</thead>
|
</thead>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
|
<div
|
||||||
<div class="flex items-center gap-2">
|
class="flex-col gap-3 justify-center font-medium text-gray-600 card-footer md:justify-between md:flex-row text-2sm">
|
||||||
|
<div class="flex gap-2 items-center">
|
||||||
Show
|
Show
|
||||||
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"> </select> per page
|
<select class="w-16 select select-sm" data-datatable-size="true" name="perpage"> </select> per
|
||||||
|
page
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex gap-4 items-center">
|
||||||
<span data-datatable-info="true"> </span>
|
<span data-datatable-info="true"> </span>
|
||||||
<div class="pagination" data-datatable-pagination="true">
|
<div class="pagination" data-datatable-pagination="true">
|
||||||
</div>
|
</div>
|
||||||
@@ -113,6 +118,20 @@
|
|||||||
<script type="module">
|
<script type="module">
|
||||||
const element = document.querySelector('#users-table');
|
const element = document.querySelector('#users-table');
|
||||||
const searchInput = document.getElementById('search');
|
const searchInput = document.getElementById('search');
|
||||||
|
const exportBtn = document.getElementById('export-btn');
|
||||||
|
|
||||||
|
// Update export URL with filters
|
||||||
|
function updateExportUrl() {
|
||||||
|
let url = new URL(exportBtn.href);
|
||||||
|
|
||||||
|
if (searchInput.value) {
|
||||||
|
url.searchParams.set('search', searchInput.value);
|
||||||
|
} else {
|
||||||
|
url.searchParams.delete('search');
|
||||||
|
}
|
||||||
|
|
||||||
|
exportBtn.href = url.toString();
|
||||||
|
};
|
||||||
|
|
||||||
const apiUrl = element.getAttribute('data-api-url');
|
const apiUrl = element.getAttribute('data-api-url');
|
||||||
const dataTableOptions = {
|
const dataTableOptions = {
|
||||||
@@ -141,12 +160,16 @@
|
|||||||
branch: {
|
branch: {
|
||||||
title: 'Branch',
|
title: 'Branch',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
return data.branch.name;
|
if (data.branches && data.branches.length > 0) {
|
||||||
|
return data.branches.map(b => b.name).join(', ');
|
||||||
|
}
|
||||||
|
return '-';
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
role: {
|
role: {
|
||||||
title: 'Role',
|
title: 'Role',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
|
console.log(data);
|
||||||
return data.roles.map(role => role.name).join(', ');
|
return data.roles.map(role => role.name).join(', ');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -171,7 +194,8 @@
|
|||||||
searchInput.addEventListener('input', function() {
|
searchInput.addEventListener('input', function() {
|
||||||
const searchValue = this.value.trim();
|
const searchValue = this.value.trim();
|
||||||
dataTable.search(searchValue, true);
|
dataTable.search(searchValue, true);
|
||||||
|
updateExportUrl();
|
||||||
|
dataTable.goPage(1);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user