employee update

This commit is contained in:
Abhishek Mali
2025-12-19 16:08:34 +05:30
parent 8a0d122e2c
commit c4097ecbde
9 changed files with 283 additions and 100 deletions

View File

@@ -55,6 +55,7 @@ class AdminStaffController extends Controller
DB::beginTransaction();
try {
// 1⃣ Create staff WITHOUT employee_id (ID not available yet)
$admin = Admin::create([
'name' => $request->name,
'email' => $request->email,
@@ -69,23 +70,33 @@ class AdminStaffController extends Controller
'status' => $request->status,
'additional_info' => $request->additional_info,
'username' => $request->username,
// username may be NULL here
'username' => $request->username ?: null,
'password' => Hash::make($request->password),
'type' => 'staff',
]);
// Generate EMPLOYEE ID using admin ID (safe)
// 2 Generate EMPLOYEE ID
$employeeId = 'EMP' . str_pad($admin->id, 4, '0', STR_PAD_LEFT);
$admin->update(['employee_id' => $employeeId]);
// Assign permissions (if any)
// 3⃣ Auto-generate username if left blank
$username = $request->username ?: strtolower($employeeId);
// 4⃣ Update employee_id + username together
$admin->update([
'employee_id' => $employeeId,
'username' => $username,
]);
// 5⃣ Assign permissions (if any)
if ($request->permissions) {
$admin->givePermissionTo($request->permissions);
}
DB::commit();
return redirect()->route('admin.staff.index')
return redirect()
->route('admin.staff.index')
->with('success', 'Staff created successfully.');
} catch (\Exception $e) {
@@ -94,6 +105,7 @@ class AdminStaffController extends Controller
}
}
public function edit($id)
{
$staff = Admin::where('type', 'staff')->findOrFail($id);

View File

@@ -15,7 +15,12 @@ class UserRequestController extends Controller
public function index()
{
$requests = CustomerRequest::orderBy('id', 'desc')->get();
return view('admin.requests', compact('requests'));
$pendingProfileUpdates = \App\Models\UpdateRequest::where('status', 'pending')->count();
return view('admin.requests', compact(
'requests',
'pendingProfileUpdates'
));
}
// Approve user request

View File

@@ -18,7 +18,7 @@ class Admin extends Authenticatable
'name', 'email', 'password', 'username',
'phone', 'emergency_phone', 'address',
'role', 'department', 'designation', 'joining_date',
'status', 'additional_info', 'type', // admin/staff indicator
'status', 'additional_info', 'type','employee_id', // admin/staff indicator
];
protected $hidden = [

Binary file not shown.

View File

@@ -201,7 +201,7 @@
background: #fff;
padding: 10px 18px !important;
position: relative;
height: 48px;
height: 65px;
width: 100%;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}
@@ -221,6 +221,32 @@
font-size: 1.06rem;
font-weight: 500;
}
/* ================================
HEADER NOTIFICATION BADGE FIX
================================ */
/* Target ONLY badge inside bell icon */
header .bi-bell {
position: relative;
}
/* Override broken global badge styles */
header .bi-bell .badge {
width: 22px !important;
height: 22px !important;
min-width: 22px !important;
padding: 0 !important;
font-size: 12px !important;
line-height: 22px !important;
border-radius: 50% !important;
display: inline-flex !important;
align-items: center;
justify-content: center;
animation: none !important;
box-shadow: 0 0 0 2px #ffffff;
}
</style>
</head>
@@ -285,12 +311,12 @@
</a>
@endcan
{{-- Profile Update Requests --}}
<!-- {{-- Profile Update Requests --}}
@can('request.update_profile')
<a href="{{ route('admin.profile.requests') }}">
<i class="bi bi-person-lines-fill"></i> Profile Update Requests
</a>
@endcan
@endcan -->
{{-- Staff (NO PERMISSION REQUIRED) --}}
<a href="{{ route('admin.staff.index') }}" class="{{ request()->routeIs('admin.staff.*') ? 'active' : '' }}">

View File

@@ -10,70 +10,144 @@
$currentPage = request()->get('page', 1);
$currentPage = max(1, (int)$currentPage);
$total = $requests->count();
$totalPages = ceil($total / $perPage);
$currentItems = $requests->slice(($currentPage - 1) * $perPage, $perPage);
@endphp
<style>
.old-value { color: #6b7280; font-weight: 600; }
.new-value { color: #111827; font-weight: 700; }
.changed { background: #fef3c7; padding: 6px; border-radius: 6px; }
.box { padding: 10px 14px; border-radius: 8px; background: #f8fafc; margin-bottom: 10px; }
.diff-label { font-size: 13px; font-weight: 700; }
.actions { display: flex; gap: 10px; }
/* ===== Card Wrapper ===== */
.request-card {
background: #ffffff;
border-radius: 14px;
padding: 18px;
margin-bottom: 18px;
box-shadow: 0 6px 20px rgba(0,0,0,0.05);
}
/* ===== Header Row ===== */
.request-header {
display: grid;
grid-template-columns: 60px 1.5fr 1fr 1.2fr 1fr;
gap: 14px;
align-items: center;
border-bottom: 1px solid #e5e7eb;
padding-bottom: 12px;
margin-bottom: 14px;
}
.request-header strong {
font-size: 14px;
}
/* ===== Badges ===== */
.badge {
padding: 6px 14px;
font-size: 12px;
border-radius: 999px;
font-weight: 700;
}
.badge-pending {
background: #fff7ed;
color: #c2410c;
border: 1px solid #fed7aa;
}
.badge-approved {
background: #ecfdf5;
color: #047857;
border: 1px solid #a7f3d0;
}
.badge-rejected {
background: #fef2f2;
color: #b91c1c;
border: 1px solid #fecaca;
}
/* ===== Action Buttons ===== */
.actions {
display: flex;
gap: 10px;
}
.actions .btn {
padding: 6px 14px;
font-size: 13px;
border-radius: 999px;
font-weight: 600;
}
/* ===== Detail Grid ===== */
.detail-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 14px;
margin-top: 12px;
}
/* ===== Detail Box ===== */
.detail-box {
background: #f8fafc;
border-radius: 10px;
padding: 12px 14px;
border: 1px solid #e2e8f0;
}
.detail-box.changed {
background: linear-gradient(145deg, #fff7ed, #ffedd5);
border-left: 4px solid #f59e0b;
}
.detail-label {
font-size: 12px;
font-weight: 700;
color: #334155;
}
.old {
font-size: 12px;
color: #64748b;
}
.new {
font-size: 14px;
font-weight: 700;
color: #020617;
}
/* ===== Responsive ===== */
@media (max-width: 992px) {
.request-header {
grid-template-columns: 1fr;
}
.detail-grid {
grid-template-columns: 1fr;
}
}
</style>
<h4 class="fw-bold my-3">Profile Update Requests ({{ $total }})</h4>
<div class="card mb-4 shadow-sm">
<div class="card-body pb-1">
<div class="table-responsive custom-table-wrapper">
<table class="table align-middle mb-0 custom-table">
<thead>
<tr>
<th>#</th>
<th>User</th>
<th>Requested Changes</th>
<th>Status</th>
<th>Requested At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($currentItems as $index => $req)
@php
$user = $req->user;
// FIX: Convert string to array
$newData = is_array($req->data) ? $req->data : json_decode($req->data, true);
@endphp
<tr>
<td><strong>{{ ($currentPage - 1) * $perPage + $index + 1 }}</strong></td>
<div class="request-card">
<td>
<!-- HEADER -->
<div class="request-header">
<strong>#{{ ($currentPage - 1) * $perPage + $index + 1 }}</strong>
<div>
<strong>{{ $user->customer_name }}</strong><br>
<small>{{ $user->email }}</small><br>
<small>ID: {{ $user->customer_id }}</small>
</td>
<td>
@foreach($newData as $key => $newValue)
@php
$oldValue = $user->$key ?? '—';
$changed = $oldValue != $newValue;
@endphp
<div class="box {{ $changed ? 'changed' : '' }}">
<span class="diff-label">{{ ucfirst(str_replace('_',' ', $key)) }}:</span><br>
<span class="old-value">Old: {{ $oldValue }}</span><br>
<span class="new-value">New: {{ $newValue ?? '—' }}</span>
</div>
@endforeach
</td>
<td>
<div>
@if($req->status == 'pending')
<span class="badge badge-pending">Pending</span>
@elseif($req->status == 'approved')
@@ -81,31 +155,57 @@
@else
<span class="badge badge-rejected">Rejected</span>
@endif
</td>
</div>
<td>{{ $req->created_at->format('d M Y, h:i A') }}</td>
<div>{{ $req->created_at->format('d M Y, h:i A') }}</div>
<td class="actions">
<div class="actions">
@if($req->status == 'pending')
<a href="{{ route('admin.profile.approve', $req->id) }}" class="btn btn-success btn-sm">
<i class="bi bi-check-circle"></i> Approve
Approve
</a>
<a href="{{ route('admin.profile.reject', $req->id) }}" class="btn btn-danger btn-sm">
<i class="bi bi-x-circle"></i> Reject
Reject
</a>
@else
<span class="text-muted">Completed</span>
@endif
</td>
</div>
</div>
</tr>
<!-- DETAILS ROW 1 -->
<div class="detail-grid">
@foreach(['customer_name','company_name','email'] as $field)
@php
$old = $user->$field ?? '—';
$new = $newData[$field] ?? $old;
@endphp
<div class="detail-box {{ $old != $new ? 'changed' : '' }}">
<div class="detail-label">{{ ucfirst(str_replace('_',' ', $field)) }}</div>
<div class="old">Old: {{ $old }}</div>
<div class="new">New: {{ $new }}</div>
</div>
@endforeach
</div>
<!-- DETAILS ROW 2 -->
<div class="detail-grid">
@foreach(['mobile_no','address','pincode'] as $field)
@php
$old = $user->$field ?? '—';
$new = $newData[$field] ?? $old;
@endphp
<div class="detail-box {{ $old != $new ? 'changed' : '' }}">
<div class="detail-label">{{ ucfirst(str_replace('_',' ', $field)) }}</div>
<div class="old">Old: {{ $old }}</div>
<div class="new">New: {{ $new }}</div>
</div>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
@endforeach
</div>
@endsection

View File

@@ -307,14 +307,55 @@
justify-content: center;
}
}
/* ==============================================
PROFILE UPDATE REQUEST BUTTON BADGE FIX
============================================== */
/* Ensure button is positioning context */
a.btn.btn-primary.position-relative {
position: relative;
margin-right: 10px;
}
/* Fix badge inside Profile Update Requests button */
a.btn.btn-primary.position-relative .badge {
width: 30px !important;
height: 30px !important;
min-width: 30px !important;
padding: 0 !important;
font-size: 14px !important;
line-height: 30px !important;
border-radius: 50% !important;
display: inline-flex !important;
align-items: center;
justify-content: center;
animation: none !important;
box-shadow: 0 0 0 2px #ffffff;
}
</style>
<!-- Counts -->
<div class="d-flex justify-content-between align-items-center mb-2 mt-3">
<h4 class="fw-bold mb-0">User Requests (Total: {{ $total }})</h4>
@can('request.update_profile')
<a href="{{ route('admin.profile.requests') }}" class="btn btn-primary position-relative">
<i class="bi bi-person-lines-fill me-1"></i>
Profile Update Requests
@if($pendingProfileUpdates > 0)
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
{{ $pendingProfileUpdates }}
</span>
@endif
</a>
@endcan
</div>
<!-- Search + Table -->
<div class="card mb-4 shadow-sm">
<div class="card-body pb-1">

View File

@@ -849,8 +849,7 @@
name="username"
value="{{ old('username') }}"
class="form-input"
placeholder="Leave blank to generate automatically"
required>
placeholder="Leave blank to generate automatically">
<div class="helper-text">
<span></span>
If left blank, username will be generated from employee ID