Skip to content

Commit

Permalink
Merge pull request sebastianbergmann#117 from sheby460/chumaBranch
Browse files Browse the repository at this point in the history
Chuma branch
  • Loading branch information
sheby460 authored Aug 6, 2024
2 parents 67ffd58 + 31743f2 commit 794b32a
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 54 deletions.
52 changes: 41 additions & 11 deletions app/Http/Controllers/DepartmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Departments;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use RealRashid\SweetAlert\Facades\Alert;

Expand All @@ -12,13 +13,42 @@ class DepartmentController extends Controller
/**
* Display a listing of the resource.
*/
public function index()
public function index1()
{
$departments = Departments::where('delete_status', 0)->get();
return view('department.index', compact('departments'));

}

public function index()
{
$departments = DB::table('departments')
->leftJoin('users', 'departments.id', '=', 'users.deptId')
->leftJoin('model_has_roles', 'users.id', '=', 'model_has_roles.model_id')
->leftJoin('roles', 'model_has_roles.role_id', '=', 'roles.id')
->select(
'departments.id as dept_id',
'departments.dept_name',
'departments.description',
'departments.delete_status',
DB::raw('CONCAT(users.fname, " ", users.lname) as head_of_department')
)
->where('departments.delete_status', 0)
->where('roles.name', 'line-manager')
->get();

return view('department.index', compact('departments'));
}

// public function index1(){
// $sops = DB::table('sops')->join('departments',
// 'sops.deptId', '=', 'departments.id')
// ->select(
// 'sops.*', 'departments.dept_name'
// )->get();
// return view('sops.index', compact('sops'));
// }

/**
* Show the form for creating a new resource.
*/
Expand Down Expand Up @@ -55,7 +85,7 @@ public function store(Request $request)
$dept = Departments::create([
'dept_name' => $request->input('dept_name'),
'description' => $request->input('description'),
'delete_status' => 0,
'delete_status' => 0,
]);
Alert::success('Department added successful','Department Added');
return redirect()->route('department.index')->with('success', 'Department added successfully.');
Expand Down Expand Up @@ -95,25 +125,25 @@ public function update(Request $request, string $id)
'dept_name' => 'required',
'description' => 'required',
]);

$validator = Validator::make($request->all(), [
'dept_name' => 'required',
'description' => 'required',
]);

if ($validator->fails()) {
return response()->json([
'status' => 400,
'errors' => $validator->errors(),
]);
}

$department = Departments::findOrFail($id);
$department->update([
'dept_name' => $request->input('dept_name'),
'description' => $request->input('description'),
]);

Alert::success('Department Updated successful','Department updated');
return redirect()->route('department.index')->with('success', 'Department updated successfully.');
}
Expand Down Expand Up @@ -143,19 +173,19 @@ public function destroy(string $id)
// public function softDelete(Request $request)
// {
// $dept = Departments::find($request->id);

// if (!$dept) {
// return response()->json([
// 'status' => 404,
// 'message' => 'Department not found',
// ]);
// }

// $dept->update([
// 'delete_status' => 1
// ]);

// return redirect()->route('department.index')->with('success', 'Department deleted successfully.');
// }
// }

}
13 changes: 7 additions & 6 deletions app/Http/Controllers/IctAccessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function index()
));
}


/**
* Show the form for creating a new resource.
*/
Expand Down Expand Up @@ -91,7 +92,7 @@ public function store(Request $request)
$hardwareRequest = $request->input('hardware_request') ? implode(',', $request->input('hardware_request')) : null;

\Log::info('Hardware request processed', ['hardware_request' => $hardwareRequest]);

// Create ICT Access Resource
$ict = IctAccessResource::create([
'remarkId' => $request->input('remarkId'),
Expand All @@ -110,7 +111,7 @@ public function store(Request $request)
'physical_access' => $request->input('physical_access'),
'delete_status' => 0,
]);


\Log::info('ICT Access Resource created', ['ict' => $ict]);

Expand All @@ -136,7 +137,7 @@ public function store(Request $request)
]);

\Log::info('Initial workflow history saved');

// Find the approver based on role (e.g., Line Manager)
$approver = $this->findLineManagerForRequesterDepartment();
// dd($approver );
Expand All @@ -154,9 +155,9 @@ public function store(Request $request)
]);
// dd(12345);
\Log::info('Workflow history forwarded for approval');

// Success alert and redirect

Alert::success('IT access form request submitted successfully', 'IT access Request Added');
return redirect()->route('request.index')->with('success', 'ICT Access Resource created successfully.');
dd(1234); });
Expand Down Expand Up @@ -259,4 +260,4 @@ public function destroy(string $id)

return redirect()->route('ict-access-form.index')->with('success', 'ICT Access Resource deleted successfully.');
}
}
}
20 changes: 13 additions & 7 deletions app/Http/Controllers/SopController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@
use App\Models\Sop;
use App\Models\User;
use App\Models\Departments;
use Illuminate\Support\Facades\DB;

class SopController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{


$sops = SOP::with('department')->get();
public function index(){
$sops = DB::table('sops')->join('departments',
'sops.deptId', '=', 'departments.id')
->select(
'sops.*', 'departments.dept_name'
)->get();
return view('sops.index', compact('sops'));
}

Expand All @@ -34,19 +40,19 @@ public function store(Request $request)
'deptId' => 'required|integer',
'pdf' => 'required|file|mimes:pdf|max:2048',
]);

// Handle the file upload
if ($request->hasFile('pdf')) {
$pdfPath = $request->file('pdf')->store('pdfs', 'public');
}

// Create the SOP record
$sop = new Sop();
$sop->title = $request->title;
$sop->deptId = $request->deptId;
$sop->pdf_path = $pdfPath; // Save the file path
$sop->save();

return redirect()->route('sops.index')->with('success', 'SOP created successfully.');
}

Expand Down Expand Up @@ -99,6 +105,6 @@ public function update(Request $request, $id)
*/
public function destroy(string $id)
{
return redirect()->route('sops.index')->with('success', 'SOP deleted successfully.');
return redirect()->route('sops.index')->with('success', 'SOP deleted successfully.');
}
}
1 change: 0 additions & 1 deletion app/Models/Departments.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Departments extends Model

protected $fillable = [
'dept_name',
'hod',
'description',
'delete_status',
];
Expand Down
9 changes: 7 additions & 2 deletions app/Models/Sop.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
class Sop extends Model
{
use HasFactory;
protected $fillable = ['deptId','title', 'pdf_path'];
public function department()
protected $fillable = [
'deptId',
'title',
'pdf_path'
];

public function departments()
{
return $this->belongsTo(Departments::class);
}
Expand Down
21 changes: 11 additions & 10 deletions resources/views/department/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@ class="btn btn-primary position-absolute top-0 end-0 mt-2 me-2"
@foreach ($departments as $department)
<tr>
<td>{{ $department->dept_name }}</td>
<td>{{ $department->headOfDepartment ? $department->headOfDepartment->fname . ' ' . $department->headOfDepartment->lname : 'N/A' }}
</td>
<td>{{ $department->head_of_department ?? 'N/A' }}</td>
<td>{{ $department->description }}</td>
<td>
<a href="{{ route('department.edit', $department->id) }}"
class="btn btn-sm edit-btn" data-id="{{ $department->id }}"><i
class="fas fa-edit"></i></a>
<a href="{{ route('department.edit', $department->dept_id) }}"
class="btn btn-sm edit-btn" data-id="{{ $department->dept_id }}">
<i class="fas fa-edit"></i>
</a>
<button
onclick="deleteConfirmation('{{ route('department.destroy', $department->id) }}')"
class="btn btn-sm btn-delete"><i class="fas fa-trash-alt"></i></button>
<form id="delete-form-{{ $department->id }}"
action="{{ route('department.destroy', $department->id) }}"
onclick="deleteConfirmation('{{ route('department.destroy', $department->dept_id) }}')"
class="btn btn-sm btn-delete">
<i class="fas fa-trash-alt"></i>
</button>
<form id="delete-form-{{ $department->dept_id }}"
action="{{ route('department.destroy', $department->dept_id) }}"
method="POST" style="display: none;">
@csrf
@method('DELETE')
Expand All @@ -71,7 +73,6 @@ class="btn btn-sm btn-delete"><i class="fas fa-trash-alt"></i></button>
</div>
</div>
</div>

</div>
</div>

Expand Down
28 changes: 17 additions & 11 deletions resources/views/ict-access-form/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@
<select class="form-control" id="pbax" name="pbax" required>
<option value="">Select an option</option>
@foreach ($privileges as $privilege)
<option value="{{ $privilege->id }}">{{ $privilege->prv_name }}
</option>
@endforeach
@if ($privilege->prv_name === 'user' || $privilege->prv_name === 'admin')
<option value="{{ $privilege->id }}">{{ $privilege->prv_name }}</option>
@endif
@endforeach
</select>
</div>

Expand Down Expand Up @@ -119,9 +120,10 @@
<select class="form-control" id="privilegeId" name="active_drt" required>
<option value="">Select an option</option>
@foreach ($privileges as $privilege)
<option value="{{ $privilege->id }}">{{ $privilege->prv_name }}
</option>
@endforeach
@if ($privilege->prv_name === 'user' || $privilege->prv_name === 'admin')
<option value="{{ $privilege->id }}">{{ $privilege->prv_name }}</option>
@endif
@endforeach
</select>
</div>
<div class="form-group">
Expand Down Expand Up @@ -200,11 +202,14 @@
<select class="form-control" id="privilegeId" name="privilegeId" required>
<option value="">Select an option</option>
@foreach ($privileges as $privilege)
<option value="{{ $privilege->id }}">{{ $privilege->prv_name }}
</option>
@if ($privilege->prv_name === 'user' || $privilege->prv_name === 'admin')
<option value="{{ $privilege->id }}">{{ $privilege->prv_name }}</option>
@endif
@endforeach
</select>
</div>

</div>
<div class="form-group">
<label for="openclinic_hms">SAP ERP<span style="color: red;">*</span></label>
<select class="form-control" id="privilegeId" name="sap" required>
Expand All @@ -220,9 +225,10 @@
<select class="form-control" id="VPN" name="VPN" required>
<option value="">Select an option</option>
@foreach ($privileges as $privilege)
<option value="{{ $privilege->id }}">{{ $privilege->prv_name }}
</option>
@endforeach
@if ($privilege->prv_name === 'user' || $privilege->prv_name === 'admin')
<option value="{{ $privilege->id }}">{{ $privilege->prv_name }}</option>
@endif
@endforeach
</select>
</div>

Expand Down
12 changes: 6 additions & 6 deletions resources/views/sops/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@
@foreach ($sops as $sop)
<tr>
<td>{{ $sop->title }}</td>
<td>{{ $sop->department ? $sop->department->dept_name : 'No Department' }}</td>
<td>{{ $sop->dept_name }}</td>
<td class="text-center">
<!-- View PDF Icon -->
@if ($sop->pdf_path)
<a href="{{ asset('storage/' . $sop->pdf_path) }}" target="_blank"
class="btn btn-warning btn-sm mx-1" title="View PDF">
class="btn btn-warning btn-sm mx-1" title="View PDF">
<i class="fas fa-file-pdf"></i>
</a>
@endif

<!-- Edit Icon -->
<a href="{{ route('sops.edit', $sop->id) }}"
class="btn btn-success btn-sm mx-1" title="Edit">
class="btn btn-success btn-sm mx-1" title="Edit">
<i class="fas fa-edit"></i>
</a>

<!-- Delete Icon -->
<form action="{{ route('sops.destroy', $sop->id) }}" method="POST"
style="display:inline;"
onsubmit="return confirm('Are you sure you want to delete this SOP?');">
style="display:inline;"
onsubmit="return confirm('Are you sure you want to delete this SOP?');">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger btn-sm mx-1"
title="Delete">
title="Delete">
<i class="fas fa-trash-alt"></i>
</button>
</form>
Expand Down

0 comments on commit 794b32a

Please sign in to comment.