StocksNew/Modules/Admin/app/Http/Controllers/PromotionDemotionController.php

126 lines
4.4 KiB
PHP
Raw Normal View History

2024-08-27 12:03:06 +00:00
<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\Admin\Repositories\DepartmentInterface;
use Modules\Admin\Repositories\DepartmentRepository;
use Modules\Admin\Repositories\DesignationInterface;
use Modules\Admin\Repositories\DesignationRepository;
use Modules\Admin\Repositories\FieldInterface;
use Modules\Admin\Repositories\FieldRepository;
use Modules\Admin\Repositories\PromotionDemotionInterface;
use Modules\Employee\Repositories\EmployeeInterface;
use Modules\Employee\Repositories\EmployeeRepository;
class PromotionDemotionController extends Controller
{
private $promotionDemotionRepository;
private $designationRepository;
private $departmentRepository;
private $employeeRepository;
private $fieldRepository;
public function __construct(PromotionDemotionInterface $promotionDemotionRepository, DepartmentInterface $departmentRepository, DesignationInterface $designationRepository, EmployeeInterface $employeeRepository, FieldInterface $fieldRepository)
{
$this->promotionDemotionRepository = $promotionDemotionRepository;
$this->designationRepository = $designationRepository;
$this->departmentRepository = $departmentRepository;
$this->employeeRepository = $employeeRepository;
$this->fieldRepository = $fieldRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = "Promotion/ Demotion Lists";
$data['promotionDemotionLists'] = $this->promotionDemotionRepository->findAll();
return view('admin::promotiondemotions.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['editable'] = false;
$data['title'] = "Create Promotion/ Demotion";
$data['employeeList'] = $this->employeeRepository->pluck();
$data['designationList'] = $this->designationRepository->pluck();
$data['departmentList'] = $this->departmentRepository->pluck();
$data['rankingTypeList'] = $this->fieldRepository->getDropdownByAlias('ranking-type');
return view('admin::promotiondemotions.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
try {
$this->promotionDemotionRepository->create($request->all());
toastr()->success('Record has been created!');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('promotionDemotion.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('admin::promotiondemotions.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['editable'] = false;
$data['title'] = "Edit Promotion/ Demotion";
$data['promotionDemotion'] = $this->promotionDemotionRepository->getPromotionDemotionById($id);
$data['designationList'] = $this->designationRepository->pluck();
$data['employeeList'] = $this->employeeRepository->pluck();
$data['departmentList'] = $this->departmentRepository->pluck();
$data['rankingTypeList'] = $this->fieldRepository->getDropdownByAlias('ranking-type');
return view('admin::promotiondemotions.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
try {
$this->promotionDemotionRepository->update($id, $request->all());
toastr()->success('Record has been updated');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('promotionDemotion.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->promotionDemotionRepository->delete($id);
toastr()->success('Record has been deleted!');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('promotionDemotion.index');
}
}