pms module status dynamic

This commit is contained in:
2024-04-16 16:59:18 +05:45
parent 3f0d9a420b
commit de082f8bca
39 changed files with 19827 additions and 30 deletions

View File

@ -0,0 +1,110 @@
<?php
namespace Modules\PMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\PMS\Models\Client;
use Modules\PMS\Repositories\ClientInterface;
class ClientController extends Controller
{
private $clientRepository;
public function __construct(ClientInterface $clientRepository)
{
$this->clientRepository = $clientRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Client List';
$data['clients'] = $this->clientRepository->findAll();
return view('pms::client.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Client';
$data['status'] = Client::STATUS;
$data['countryList'] = [1 => 'Nepal'];
return view('pms::client.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
try {
$this->clientRepository->create($inputData);
toastr()->success('Client Created Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('client.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'View Client';
$data['client'] = $this->clientRepository->getClientById($id);
$data['status'] = Client::STATUS;
$data['countryList'] = [1 => 'Nepal'];
return view('pms::client.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Client';
$data['client'] = $this->clientRepository->getClientById($id);
$data['status'] = Client::STATUS;
$data['countryList'] = [1 => 'Nepal'];
return view('pms::client.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
try {
$this->clientRepository->update($id, $inputData);
toastr()->success('Client Update Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('client.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->clientRepository->delete($id);
toastr()->success('Client Deleted Succesfully');
} catch (\Throwable $th) {
//throw $th;
toastr()->error($th->getMessage());
}
}
}

View File

@ -0,0 +1,123 @@
<?php
namespace Modules\PMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Employee\Repositories\EmployeeInterface;
use Modules\PMS\Models\Project;
use Modules\PMS\Repositories\ClientInterface;
use Modules\PMS\Repositories\ProjectInterface;
class ProjectController extends Controller
{
private $projectRepository;
private $clientRepository;
private $employeeRepository;
public function __construct(
ProjectInterface $projectRepository,
ClientInterface $clientRepository,
EmployeeInterface $employeeRepository) {
$this->projectRepository = $projectRepository;
$this->clientRepository = $clientRepository;
$this->employeeRepository = $employeeRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Project List';
$data['projects'] = $this->projectRepository->findAll();
return view('pms::project.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Project';
$data['status'] = Project::STATUS;
$data['categoryList'] = Project::CATEGORY;
$data['clientList'] = $this->clientRepository->pluck();
$data['memberList'] = $this->employeeRepository->pluck();
return view('pms::project.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
try {
$this->projectRepository->create($inputData);
toastr()->success('Project Created Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('project.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'View Project';
$data['project'] = $this->projectRepository->getProjectById($id);
$data['status'] = Project::STATUS;
$data['countryList'] = [1 => 'Nepal'];
return view('pms::project.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Project';
$data['project'] = $this->projectRepository->getProjectById($id);
$data['status'] = Project::STATUS;
$data['categoryList'] = Project::CATEGORY;
$data['clientList'] = $this->clientRepository->pluck();
$data['memberList'] = $this->employeeRepository->pluck();
return view('pms::project.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
try {
$this->projectRepository->update($id, $inputData);
toastr()->success('Project Update Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('project.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->projectRepository->delete($id);
toastr()->success('Project Deleted Succesfully');
} catch (\Throwable $th) {
//throw $th;
toastr()->error($th->getMessage());
}
}
}

View File

@ -0,0 +1,122 @@
<?php
namespace Modules\PMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Employee\Repositories\EmployeeInterface;
use Modules\PMS\Models\Task;
use Modules\PMS\Repositories\ProjectInterface;
use Modules\PMS\Repositories\TaskInterface;
class TaskController extends Controller
{
private $taskRepository;
private $projectRepository;
private $employeeRepository;
public function __construct(
TaskInterface $taskRepository,
ProjectInterface $projectRepository,
EmployeeInterface $employeeRepository) {
$this->taskRepository = $taskRepository;
$this->projectRepository = $projectRepository;
$this->employeeRepository = $employeeRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Task List';
$data['tasks'] = $this->taskRepository->findAll();
return view('pms::task.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Task';
$data['status'] = Task::STATUS;
$data['categoryList'] = Task::CATEGORY;
$data['projectList'] = $this->projectRepository->pluck();
$data['memberList'] = $this->employeeRepository->pluck();
return view('pms::task.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
try {
$this->taskRepository->create($inputData);
toastr()->success('Task Created Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('task.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'View Task';
$data['task'] = $this->taskRepository->getTaskById($id);
$data['status'] = Task::STATUS;
return view('pms::task.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Task';
$data['task'] = $this->taskRepository->getTaskById($id);
$data['status'] = Task::STATUS;
$data['categoryList'] = Task::CATEGORY;
$data['projectList'] = $this->projectRepository->pluck();
$data['memberList'] = $this->employeeRepository->pluck();
return view('pms::task.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
try {
$this->taskRepository->update($id, $inputData);
toastr()->success('Task Update Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('task.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->taskRepository->delete($id);
toastr()->success('Task Deleted Succesfully');
} catch (\Throwable $th) {
//throw $th;
toastr()->error($th->getMessage());
}
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Modules\PMS\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ClientRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
//
];
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace Modules\PMS\Models;
use App\Traits\CreatedUpdatedBy;
use App\Traits\StatusTrait;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
class Client extends Model
{
use StatusTrait, CreatedUpdatedBy;
/**
* The attributes that are mass assignable.
*/
protected $table = 'tbl_clients';
protected $guarded = [];
protected $appends = ['status_name'];
}

View File

@ -0,0 +1,22 @@
<?php
namespace Modules\PMS\Models;
use App\Traits\CreatedUpdatedBy;
use App\Traits\StatusTrait;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
use StatusTrait, CreatedUpdatedBy;
protected $table = 'tbl_projects';
protected $guarded = [];
protected $appends = ['status_name'];
const CATEGORY = [
10 => 'Vue',
11 => 'Laravel',
];
}

View File

@ -0,0 +1,22 @@
<?php
namespace Modules\PMS\Models;
use App\Traits\CreatedUpdatedBy;
use App\Traits\StatusTrait;
use Illuminate\Database\Eloquent\Model;
class Task extends Model
{
use StatusTrait, CreatedUpdatedBy;
protected $table = 'tbl_tasks';
protected $guarded = [];
protected $appends = ['status_name'];
const CATEGORY = [
10 => 'Vue',
11 => 'Laravel',
];
}

View File

@ -4,6 +4,12 @@ namespace Modules\PMS\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\PMS\Repositories\ClientInterface;
use Modules\PMS\Repositories\ClientRepository;
use Modules\PMS\Repositories\ProjectInterface;
use Modules\PMS\Repositories\ProjectRepository;
use Modules\PMS\Repositories\TaskInterface;
use Modules\PMS\Repositories\TaskRepository;
class PMSServiceProvider extends ServiceProvider
{
@ -29,6 +35,9 @@ class PMSServiceProvider extends ServiceProvider
*/
public function register(): void
{
$this->app->bind(ClientInterface::class, ClientRepository::class);
$this->app->bind(ProjectInterface::class, ProjectRepository::class);
$this->app->bind(TaskInterface::class, TaskRepository::class);
$this->app->register(RouteServiceProvider::class);
}
@ -56,7 +65,7 @@ class PMSServiceProvider extends ServiceProvider
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.$this->moduleNameLower);
$langPath = resource_path('lang/modules/' . $this->moduleNameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
@ -72,7 +81,7 @@ class PMSServiceProvider extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower . '.php')], 'config');
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
}
@ -81,14 +90,14 @@ class PMSServiceProvider extends ServiceProvider
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->moduleNameLower);
$viewPath = resource_path('views/modules/' . $this->moduleNameLower);
$sourcePath = module_path($this->moduleName, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']);
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
$componentNamespace = str_replace('/', '\\', config('modules.namespace').'\\'.$this->moduleName.'\\'.ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder','')));
$componentNamespace = str_replace('/', '\\', config('modules.namespace') . '\\' . $this->moduleName . '\\' . ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder', '')));
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
}
@ -104,8 +113,8 @@ class PMSServiceProvider extends ServiceProvider
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path.'/modules/'.$this->moduleNameLower)) {
$paths[] = $path.'/modules/'.$this->moduleNameLower;
if (is_dir($path . '/modules/' . $this->moduleNameLower)) {
$paths[] = $path . '/modules/' . $this->moduleNameLower;
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace Modules\PMS\Repositories;
interface ClientInterface
{
public function findAll();
public function getClientById($clientId);
public function delete($clientId);
public function create($clientDetails);
public function update($clientId, array $newDetails);
public function pluck();
}

View File

@ -0,0 +1,39 @@
<?php
namespace Modules\PMS\Repositories;
use Modules\PMS\Models\Client;
class ClientRepository implements ClientInterface
{
public function findAll()
{
return Client::paginate(20);
}
public function getClientById($ClientId)
{
return Client::findOrFail($ClientId);
}
public function delete($ClientId)
{
Client::destroy($ClientId);
}
public function create($ClientDetails)
{
return Client::create($ClientDetails);
}
public function update($ClientId, array $newDetails)
{
return Client::whereId($ClientId)->update($newDetails);
}
public function pluck()
{
return Client::pluck('client_name', 'id');
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace Modules\PMS\Repositories;
interface ProjectInterface
{
public function findAll();
public function getProjectById($clientId);
public function delete($clientId);
public function create($clientDetails);
public function update($clientId, array $newDetails);
public function pluck();
}

View File

@ -0,0 +1,39 @@
<?php
namespace Modules\PMS\Repositories;
use Modules\PMS\Models\Project;
class ProjectRepository implements ProjectInterface
{
public function findAll()
{
return Project::paginate(20);
}
public function getProjectById($ProjectId)
{
return Project::findOrFail($ProjectId);
}
public function delete($ProjectId)
{
Project::destroy($ProjectId);
}
public function create($ProjectDetails)
{
return Project::create($ProjectDetails);
}
public function update($ProjectId, array $newDetails)
{
return Project::whereId($ProjectId)->update($newDetails);
}
public function pluck()
{
return Project::pluck('project_name', 'id');
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace Modules\PMS\Repositories;
interface TaskInterface
{
public function findAll();
public function getTaskById($clientId);
public function delete($clientId);
public function create($clientDetails);
public function update($clientId, array $newDetails);
public function pluck();
}

View File

@ -0,0 +1,40 @@
<?php
namespace Modules\PMS\Repositories;
use Illuminate\Support\Facades\DB;
use Modules\PMS\Models\Task;
class TaskRepository implements TaskInterface
{
public function findAll()
{
return Task::paginate(20);
}
public function getTaskById($TaskId)
{
return Task::findOrFail($TaskId);
}
public function delete($TaskId)
{
Task::destroy($TaskId);
}
public function create($TaskDetails)
{
return Task::create($TaskDetails);
}
public function update($TaskId, array $newDetails)
{
return Task::whereId($TaskId)->update($newDetails);
}
public function pluck()
{
return Task::pluck(DB::raw('CONCAT(first_name," ", middle_name , " ",last_name) AS full_name'), 'id');
}
}