Merge branch 'omis_dharma' of ssh://bibgit.com:22022/dharmaraj/New-OMIS

This commit is contained in:
2024-04-11 16:41:44 +05:45
182 changed files with 5178 additions and 5511 deletions

View File

@ -3,13 +3,15 @@
namespace Modules\Employee\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\Role;
use Carbon\Carbon;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage;
use Modules\Admin\Services\AdminService;
use Modules\Employee\Repositories\EmployeeInterface;
use Modules\User\Repositories\UserInterface;
use Spatie\Permission\Models\Role;
class EmployeeController extends Controller
{
@ -17,10 +19,13 @@ class EmployeeController extends Controller
private $employeeRepository;
private $userRepository;
public function __construct(EmployeeInterface $employeeRepository, UserInterface $userRepository)
private $adminService;
public function __construct(EmployeeInterface $employeeRepository, UserInterface $userRepository, AdminService $adminService)
{
$this->employeeRepository = $employeeRepository;
$this->userRepository = $userRepository;
$this->adminService = $adminService;
}
/**
@ -42,8 +47,10 @@ class EmployeeController extends Controller
$data['title'] = 'Create Employee';
$data['departmentList'] = [];
$data['designationList'] = [];
$data['genderList'] = [];
$data['nationalityList'] = [];
$data['nationalityList'] = $this->adminService->pluckNationalities();
$data['genderList'] = $this->adminService->pluckGenders();
$data['casteList'] = $this->adminService->pluckCastes();
$data['cityList'] = $this->adminService->pluckCities();
return view('employee::create', $data);
}
@ -56,15 +63,19 @@ class EmployeeController extends Controller
$inputData = $request->all();
try {
if ($request->hasFile('profile_pic')) {
$fileName = time() . '_' . $request->profile_pic->getClientOriginalName();
$filePath = $request->file('profile_pic')->storeAs('uploads', $fileName, 'public');
$inputData['profile_picture'] = time() . '_' . $request->profile_pic->getClientOriginalName();
if ($request->hasFile('profile_picture')) {
$image = $request->profile_picture;
$fileName = time() . '_' . $image->getClientOriginalName();
$filePath = Storage::disk('public')->putFileAs('uploads', $image, $fileName);
$inputData['profile_picture'] = 'storage/' . $filePath;
}
$this->employeeRepository->create($inputData);
toastr()->success('Employee Created Succesfully');
} catch (\Throwable $th) {
echo $th->getMessage();
toastr()->error($th->getMessage());
}
return redirect()->route('employee.index');
@ -95,17 +106,22 @@ class EmployeeController extends Controller
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
try {
if ($request->hasFile('profile_pic')) {
$fileName = time() . '_' . $request->profile_pic->getClientOriginalName();
$filePath = $request->file('profile_pic')->storeAs('uploads', $fileName, 'public');
$inputData['profile_picture'] = time() . '_' . $request->profile_pic->getClientOriginalName();
if ($request->hasFile('profile_picture')) {
$image = $request->profile_picture;
$fileName = time() . '_' . $image->getClientOriginalName();
$filePath = Storage::disk('public')->putFileAs('uploads', $image, $fileName);
$inputData['profile_picture'] = 'storage/' . $filePath;
}
$this->employeeRepository->update($id, $inputData);
toastr()->success('Employee Created Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('employee.index');
@ -114,19 +130,25 @@ class EmployeeController extends Controller
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
public function destroy(Request $request)
{
try {
$employeeModel = $this->employeeRepository->getEmployeeById($id);
$employeeModel->user->roles()->detach();
$employeeModel->user->delete();
$employeeModel->delete();
$employeeModel = $this->employeeRepository->getEmployeeById($request->id);
optional($employeeModel)->user?->roles()?->detach();
optional($employeeModel)->user?->delete();
optional($employeeModel)->delete();
toastr()->success('Employee Delete Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('employee.index');
return response()->json(['status' => true, 'message' => 'Employee Delete Succesfully']);
}
@ -153,4 +175,14 @@ class EmployeeController extends Controller
return redirect()->route('employee.index');
}
public function changePassword(Request $request)
{
dd($request->all());
try {
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
}
}