first change

This commit is contained in:
2025-07-27 17:40:56 +05:45
commit f8b9a6725b
3152 changed files with 229528 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
<?php
namespace Modules\PMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class CommentController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
return view('pms::index');
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('pms::create');
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
//
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('pms::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
return view('pms::edit');
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//
}
}

View File

@@ -0,0 +1,187 @@
<?php
namespace Modules\PMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Modules\PMS\Models\KanbanColumn;
use Modules\PMS\Repositories\KanbanColumnInterface;
class KanbanColumnController extends Controller
{
/**
* Display a listing of the resource.
*/
private $kanbanColumn;
public function __construct(KanbanColumnInterface $kanbanColumn)
{
$this->kanbanColumn = $kanbanColumn;
}
public function index()
{
$data['editable'] = false;
$data['title'] = 'Kanban Column Lists';
$data['kanbanColumnLists'] = $this->kanbanColumn->findAll();
return view('pms::kanbanColumn.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$validator = Validator::make($request->all(), [
'name' => 'required|unique:kanban_columns,name',
'category' => 'required|in:pending,backlog,in_progress,completed,on_hold,cancelled'
]);
$request->merge([
'position' => KanbanColumn::max('position') + 1 ?? 1,
]);
if ($validator->fails()) {
if ($request->ajax()) {
return response()->json([
'status' => false,
'msg' => $validator->errors(),
], 422);
}
$errors = implode(', ', $validator->errors()->all());
flash()->addError($errors);
return redirect()->back();
}
try {
$taskModel = $this->kanbanColumn->create($request->all());
if ($request->ajax()) {
return response()->json([
'status' => true,
'data' => $taskModel,
'msg' => 'Task Created Created',
]);
}
flash()->addSuccess('Kanban Column Created');
return redirect()->back();
} catch (\Throwable $th) {
if ($request->ajax()) {
return response()->json([
'status' => false,
'msg' => $th->getMessage(),
]);
}
flash()->addError($th->getMessage());
return redirect()->back()->withError($th->getMessage());
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'View Kanban Column';
$data['kanbanColumn'] = $this->kanbanColumn->getKanbanColumnById($id);
return view('pms::kanbanColumn.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
if (request()->ajax()) {
$data['editable'] = true;
$data['kanbanColumn'] = $this->kanbanColumn->getKanbanColumnById($id);
return view('pms::kanbanColumn.partials.action', $data);
}
$data['editable'] = true;
$data['title'] = 'Kanban Column Lists';
$data['kanbanColumn'] = $this->kanbanColumn->getKanbanColumnById($id);
$data['kanbanColumnLists'] = $this->kanbanColumn->findAll();
return view('pms::kanbanColumn.index', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$request->validate([
'position' => 'required|integer',
'name' => 'required|unique:kanban_columns,name,' . $id,
'category' => 'required|in:pending,backlog,in_progress,completed,on_hold,cancelled'
]);
try {
$kanbanColumn = $this->kanbanColumn->getKanbanColumnById($id);
$items = KanbanColumn::whereNot('id', $kanbanColumn->id)->orderBy('position')->get();
DB::transaction(function () use ($kanbanColumn, $items, $request) {
$items->splice($request->position - 1, 0, [$kanbanColumn]);
$items = $items->values();
foreach ($items as $index => $item) {
$item->position = $index + 1;
$item->save();
}
$kanbanColumn->update($request->only(['name', 'color', 'category']));
});
flash()->success('Kanban Column Updated Successfully');
return redirect()->back();
} catch (\Throwable $th) {
flash()->error($th->getMessage());
return redirect()->back()->withInput();
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
DB::transaction(function () use ($id) {
$column = KanbanColumn::findOrFail($id);
$column->delete();
$items = KanbanColumn::where('position', '>', $column->position)
->orderBy('position')
->get();
foreach ($items as $item) {
$item->position = $item->position - 1;
$item->save();
}
});
flash()->success('Column has been deleted');
return redirect()->back();
} catch (\Throwable $th) {
flash()->error($th->getMessage());
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Modules\PMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class PMSController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
return view('pms::index');
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('pms::create');
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
//
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('pms::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
return view('pms::edit');
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//
}
}

View File

@@ -0,0 +1,141 @@
<?php
namespace Modules\PMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Validator;
use Modules\PMS\Models\TaskCategory;
use Modules\PMS\Repositories\TaskCategoryInterface;
class TaskCategoryController extends Controller
{
/**
* Display a listing of the resource.
*/
private $taskCategory;
public function __construct(TaskCategoryInterface $taskCategory)
{
$this->taskCategory = $taskCategory;
}
public function index()
{
$data['title'] = 'Task Category Lists';
$data['taskCategoryLists'] = $this->taskCategory->findAll();
return view('pms::task-category.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Task Category';
$data['editable'] = false;
$data['status'] = TaskCategory::STATUS;
return view('pms::task-category.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$validator = Validator::make($request->all(), [
'title' => 'required',
]);
if ($validator->fails()) {
if ($request->ajax()) {
return response()->json([
'status' => false,
'msg' => $validator->errors(),
], 422);
}
return to_route('taskCategory.create')->withError($validator->errors()->all());
}
try {
if (!$request->has('status')) {
$request->merge(['status' => 11]);
}
$taskModel = $this->taskCategory->create($request->all());
if ($request->ajax()) {
return response()->json([
'status' => true,
'data' => $taskModel,
'msg' => 'Task Created Created',
]);
}
return redirect()->route('task.index')->withSucess('Task Category Created');
} catch (\Throwable $th) {
if ($request->ajax()) {
return response()->json([
'status' => false,
'msg' => $th->getMessage(),
]);
}
return redirect()->route('task.index')->withError($th->getMessage());
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'View Task Category';
$data['taskCategory'] = $this->taskCategory->getTaskCategoryById($id);
return view('pms::task-category.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
try {
$data['title'] = 'Edit Task Category';
$data['editable'] = true;
$data['status'] = TaskCategory::STATUS;
$data['taskCategory'] = $this->taskCategory->getTaskCategoryById($id);
} catch (\Throwable $th) {
flash()->error($th->getMessage());
}
return view('pms::task-category.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
try {
$this->taskCategory->update($id, $request->except(['_method', '_token']));
flash()->success('Task Category Updated Successfully');
} catch (\Throwable $th) {
flash()->error($th->getMessage());
}
return redirect()->route('task.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->taskCategory->delete($id);
flash()->success('Task Category Deleted Successfully');
} catch (\Throwable $th) {
flash()->error($th->getMessage());
}
}
}

View File

@@ -0,0 +1,627 @@
<?php
namespace Modules\PMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Facades\Excel;
use Modules\Employee\Models\Employee;
use Modules\Employee\Interfaces\EmployeeInterface;
use Modules\PMS\Exports\TaskExport;
use Modules\PMS\Models\KanbanColumn;
use Modules\PMS\Models\Task;
use Modules\PMS\Repositories\KanbanColumnInterface;
use Modules\PMS\Repositories\TaskCategoryInterface;
use Modules\PMS\Repositories\TaskInterface;
use Modules\Product\Interfaces\ProductInterface;
use Modules\Template\Emails\SendMail;
use Modules\Template\Repositories\TemplateInterface;
use Modules\Template\Repositories\TemplateRepository;
use Modules\User\Services\UserService;
class TaskController extends Controller
{
private $task;
private $project;
private $employee;
private $taskCategory;
private $product;
private $kanbanColumn;
private $template;
public function __construct(
TaskInterface $task,
EmployeeInterface $employee,
TaskCategoryInterface $taskCategory,
KanbanColumnInterface $kanbanColumn,
ProductInterface $product,
TemplateInterface $template,
) {
$this->task = $task;
$this->employee = $employee;
$this->taskCategory = $taskCategory;
$this->product = $product;
$this->kanbanColumn = $kanbanColumn;
$this->template = $template;
}
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$filters = $request->all();
$data['title'] = 'Task List';
$data['editable'] = false;
$data['tasks'] = $this->task->findAll($filters);
$data['products'] = $this->product->findAll();
$data['taskCategories'] = $this->taskCategory->findAll();
$data['memberList'] = $this->employee->pluck();
$data['statusList'] = $this->kanbanColumn->pluck(function ($query) {
$query->orderBy('position');
});
return view('pms::task.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Task';
$data['editable'] = false;
$data['status'] = $this->kanbanColumn->pluck(function ($query) {
$query->orderBy('position');
});
$data['priority'] = Task::PRIORITY;
$data['product'] = $this->product->pluck();
$data['memberList'] = $this->employee->pluck();
$data['categoryList'] = $this->taskCategory->pluck();
return view('pms::task.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$validator = Validator::make($request->all(), [
'title' => 'required|string|max:255',
]);
if ($validator->fails()) {
return to_route('task.create')->withError($validator->errors()->all());
}
$inputData = $request->except(['_token', 'file']);
$task = $this->task->create($inputData);
$statusName = $this->task->getTaskById($task->id)->statusName['status'];
if ($request->hasFile('file')) {
$path = 'uploads/task';
$inputData['file'] = uploadImage($request->file, $path);
$task->documents()->updateOrCreate([
'documentable_id' => $task->id,
'documentable_type' => 'Modules\PMS\Models\Task',
], [
'document_name' => 'Task Files',
'document_path' => $inputData['file'],
]);
}
$createdBy = UserService::getUserById($task->createdby);
$user = $task->assignedUser;
if (config('app.send_mail')) {
$templateModel = (new TemplateRepository())->where(['alias' => 'task-assignee-template'])->first();
$message = $templateModel->message;
$message = str_replace('#image', asset('storage/' . setting('logo_pic')), $message);
$message = str_replace('#task_subject', $task->title, $message);
$message = str_replace('#assigned_by', $createdBy->name, $message);
$message = str_replace('#task_desc', $task->desc, $message);
$message = str_replace('#task_deadline', $task->due_date, $message);
$data = [
'subject' => 'New Task Created',
'body' => $message,
];
Mail::to($user)->send(new SendMail($data));
}
$priorityLabel = Task::PRIORITY[$inputData['priority']] ?? 'Unknown';
$this->product->getProductById($inputData['product_id'])->client->createLog([
'title' => 'Task Created',
'data' => "Task titled '{$inputData['title']}' with an status '{$statusName}' has been created.",
]);
foreach ($inputData['assigned_id'] as $employeeId) {
$employee = $this->employee->getEmployeeById($employeeId);
if (is_iterable($employee)) {
foreach ($employee as $emp) {
$emp->createLog([
'title' => 'Task Has Been Assigned',
'data' => "Task titled '{$inputData['title']}' with status '{$statusName}' and priority '{$priorityLabel}' has been created.",
]);
}
} else {
$employee->user->createLog([
'title' => 'Task Has Been Assigned',
'data' => "Task titled '{$inputData['title']}' with status '{$statusName}' and priority '{$priorityLabel}' has been created.",
]);
}
}
return redirect()->route('task.index')->withSucess('Task Created');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'View Task';
$data['task'] = $this->task->getTaskById($id);
$data['time'] = $data['task']->latest_task_time;
$data['clientName'] = $this->product->getProductById($data['task']->product_id)->client->name;
$data['status'] = $this->kanbanColumn->pluck(function ($query) {
$query->orderBy('position');
});
$data['template'] = $this->template->pluck();
return view('pms::task.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Task';
$data['editable'] = true;
$data['task'] = $this->task->getTaskById($id);
$data['status'] = $this->kanbanColumn->pluck(function ($query) {
$query->orderBy('position');
});
$data['priority'] = Task::PRIORITY;
$data['categoryList'] = $this->taskCategory->pluck();
$data['product'] = $this->product->pluck();
$data['memberList'] = $this->employee->pluck();
return view('pms::task.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$statusName = $this->task->getTaskById($id)->statusName['status'];
$allAssignedIds = $request->assigned_id['ids'] ?? [];
$currentAssignedIds = $this->task->getTaskById($id)->assigned_id['ids'] ?? [];
$newAssignedEmployees = array_diff($allAssignedIds, $currentAssignedIds);
$validator = Validator::make($request->all(), [
'title' => 'required|string|max:255',
]);
if ($validator->fails()) {
return to_route('task.create')->withError($validator->errors()->all());
}
$inputData = $request->except(['_method', '_token']);
try {
// Updating Task
$task = $this->task->update($id, $inputData);
// Handling File Upload
if ($request->hasFile('file')) {
$path = 'uploads/task';
$inputData['file'] = uploadImage($request->file, $path);
$task->documents()->updateOrCreate(
[
'documentable_id' => $task->id,
'documentable_type' => 'Modules\Invoice\Models\ReceivedInvoice',
],
[
'document_name' => 'Task Files',
'document_path' => $inputData['file'],
]
);
// Log for file upload
foreach ($currentAssignedIds as $empId) {
$employee = Employee::find($empId);
if ($employee) {
$employee->user->createLog([
'title' => 'Document Added',
'data' => "A new document has been added to the task titled '{$task->title}'.",
]);
} else {
flash()->addError("Employee with ID {$empId} not found while creating log for file upload.");
}
}
$client = $this->product->getProductById($inputData['product_id'])->client;
$client->createLog([
'title' => 'Document Added',
'data' => "A new document has been added to the task titled '{$task->title}'.",
]);
}
// Creating Logs for Client
$priority = Task::PRIORITY[$inputData['priority']] ?? 'Unknown';
$client = $this->product->getProductById($inputData['product_id'])->client;
if ($client) {
$client->createLog([
'title' => 'Task Updated',
'data' => "Task titled '{$inputData['title']}' with status '{$statusName}' and priority '{$priority}' has been created.",
]);
} else {
flash()->addError("Client not found for product ID {$inputData['product_id']}.");
}
// Creating Logs for New Employees
if ($newAssignedEmployees) {
foreach ($newAssignedEmployees as $empId) {
$employee = Employee::find($empId);
if ($employee) {
$employee->user->createLog([
'title' => 'Task Assigned',
'data' => "Task titled '{$inputData['title']}' with status '{$statusName}' and priority '{$priority}' has been created.",
]);
} else {
flash()->addError("Employee with ID {$empId} not found while creating assignment log.");
}
}
}
// Creating Logs for Current Employees
if ($currentAssignedIds) {
foreach ($currentAssignedIds as $empId) {
$employee = Employee::find($empId);
if ($employee) {
$employee->user->createLog([
'title' => 'Task Updated',
'data' => "Task titled '{$inputData['title']}' with status '{$statusName}' and priority '{$priority}' has been created.",
]);
} else {
flash()->addError("Employee with ID {$empId} not found while creating update log.");
}
}
}
return redirect()->route('task.index')->withSuccess('Task updated successfully.');
} catch (\Throwable $th) {
flash()->addError("Error while updating task: {$th->getMessage()}");
return redirect()->route('task.index')->withErrors('Something went wrong, please try again.');
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->task->delete($id);
flash()->success('Task Deleted Succesfully');
} catch (\Throwable $th) {
flash()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Task Delete Succesfully']);
}
public function kanban(Request $request)
{
$data['title'] = 'Kanban Board';
$data['editable'] = false;
$data['statusList'] = $this->kanbanColumn->pluck(function ($query) {
$query->orderBy('position');
});
$data['memberList'] = $this->employee->pluck();
$data['columnsWithTasks'] = KanbanColumn::with([
'tasks' => function ($query) use ($request) {
$query->whereNull('parent_id');
if ($request->filled('search')) {
$search = $request->search;
$query->where('title', 'LIKE', "%$search%");
}
if ($request->filled('status')) {
$query->where('status', $request->status);
}
if ($request->filled('priority')) {
$query->where('priority', $request->priority);
}
if ($request->filled('date')) {
$dates = explode('to', $request->date);
$startDate = trim($dates[0]);
$endDate = isset($dates[1]) ? trim($dates[1]) : $startDate; // Handle single date or range
$query->whereBetween('start_date', [$startDate, $endDate]);
}
if ($request->filled('assigned_to')) {
$query->whereJsonContains("assigned_id->ids", (string) $request->assigned_to);
}
if (auth()->user()->hasRole('employee')) {
$assignedId = (string) auth()->user()->employee_id;
$query->whereJsonContains('assigned_id->ids', $assignedId);
}
$query->with('assignedUser:id,first_name,middle_name,last_name,profile_picture');
},
])
// ->withCount('tasks')
->orderBy('position')
->get();
// dd($data['columnsWithTasks']->toArray());
$data['columnLists'] = KanbanColumn::select(DB::raw("id, LOWER(REPLACE(name, ' ', '-')) as slug"))
->pluck('slug', 'id');
$data['taskCategories'] = $this->taskCategory->findAll();
return view('pms::task.kanban', $data);
}
public function changeStatus(Request $request)
{
try {
$taskModel = $this->task->getTaskById($request->id);
$prevTaskStatus = Task::findOrFail($request->id)->statusName['status'];
$client = $this->product->getProductById($taskModel->product_id)->client;
$taskModel->status = $request->changeStatus;
$taskModel->save();
$employeeIds = $taskModel->assigned_id['ids'];
// Creating logs for the client
$client->createLog([
'title' => 'Task Status Changed',
'data' => "Task Title: {$taskModel->title} | Status: From {$prevTaskStatus} to {$taskModel->statusName['status']}",
]);
// Creating logs for each employee assigned to the task
foreach ($employeeIds as $emp) {
$employee = Employee::findOrFail($emp);
$employee->user->createLog([
'title' => 'Task Status Changed',
'data' => "Task Title: {$taskModel->title} | Status: From {$prevTaskStatus} to {$taskModel->statusName['status']}",
]);
}
return response()->json([
'status' => true,
'msg' => 'Status Changed',
], 200);
} catch (\Throwable $th) {
return response()->json([
'status' => false,
'msg' => $th->getMessage(),
], 400);
}
}
public function fetchComment($task_id)
{
$data['task'] = $this->task->getTaskById($task_id);
return view('pms::task.partials.comment', $data);
}
public function storeComment(Request $request)
{
$request->validate([
'content' => 'required',
]);
$task = $this->task->getTaskById($request->task_id);
$task->comments()->create(['content' => $request->content, 'comment_by' => Auth::id()]);
$user = $task->assignedUser;
if (config('app.send_mail')) {
$templateModel = (new TemplateRepository())->where(['alias' => 'comment-template'])->first();
$message = $templateModel->message;
$message = str_replace('#image', asset('storage/' . setting('logo_pic')), $message);
$message = str_replace('#content', $request->content, $message);
$data = [
'subject' => 'New Comment Added on Your Task',
'body' => $message,
];
Mail::to($user)->send(new SendMail($data));
}
// Creating Logs for Client and Employees
$employeeIds = $this->task->getTaskById($request->task_id)->assigned_id['ids'];
$commentPreview = substr($request->content, 0, 50);
if (strlen($request->content) > 50) {
$commentPreview .= '...';
}
$task->product->client->createLog([
'title' => 'Comment Added in Task: "' . $task->title . '"',
'data' => 'Comment: ' . $commentPreview,
]);
foreach ($employeeIds as $emp) {
$employee = Employee::findOrFail($emp);
$employee->user->createLog([
'title' => 'New Comment Added in Task: "' . $task->title . '"',
'data' => 'Comment: ' . $commentPreview,
]);
}
return response()->json([
'status' => true,
'msg' => 'Comment Store',
], 200);
}
public function uploadFile(Request $request)
{
$task = $this->task->getTaskById($request->task_id);
$client = $task->product->client;
if ($request->hasFile('file')) {
$path = 'uploads/task';
$fileName = $request->file->getClientOriginalName();
$filePath = uploadImage($request->file, $path);
$task->documents()->create(['document_name' => $fileName, 'document_path' => $filePath]);
}
// Storing Logs for Client and Employees
$client->createLog([
'title' => "Document Uploaded",
'data' => "For Task Title '{$task->title}'",
]);
foreach ($task->assignedUser as $employee) {
$employee->user->createLog([
'title' => "Document Uploaded",
'data' => "For Task Title '{$task->title}'",
]);
}
return response()->json([
'status' => true,
'msg' => 'File Upload',
], 200);
}
public function storeSubTask(Request $request)
{
try {
$request->merge(['status' => 10]);
$request->validate([
'title' => 'required',
'start_date' => 'required',
]);
$task = $this->task->create($request->all());
// Creating Logs for Client and Employees
$employeeIds = $this->task->getTaskById($request->parent_id)->assigned_id['ids'];
$taskTitle = $this->task->getTaskById($request->parent_id)->title;
$client = $this->product->getProductById($this->task->getTaskById($request->parent_id)->product_id)->Client;
$client->createLog([
'title' => "Sub-Task Added.",
'data' => "For Task Title '{$taskTitle}'",
]);
foreach ($employeeIds as $emp) {
$employee = Employee::findOrFail($emp);
$employee->user->createLog([
'title' => "Sub-Task Added.",
'data' => "For Task Title '{$taskTitle}'",
]);
}
return redirect()->back()->withSucess('Sub Task Created');
} catch (\Throwable $th) {
return redirect()->back()->withError($th->getMessage());
}
}
public function gantChart()
{
$data['title'] = 'Gantt Chart';
return view('pms::task.gantt.chart', $data);
}
public function getGantChartTask(Request $request)
{
// try {
$filters = $request->all();
$tasks = $this->task->getAllTasks($filters);
// dd($tasks->toArray());
$finalArr = [];
foreach ($tasks as $key => $task) {
$finalArr[] = [
'taskID' => (string) $task->id,
'taskName' => $task->title . ' (' . $task->project?->project_name . ')',
'resource' => $task->title,
'startDate' => $task->start_date,
'endDate' => $task->due_date,
'duration' => null,
'percentComplete' => null,
'dependencies' => null,
];
if (isset($task['subTask']) && !empty($task['subTask'])) {
foreach ($task['subTask'] as $sub_task) {
array_push($finalArr, [
'taskID' => (string) $sub_task->id,
'taskName' => $sub_task->title,
'resource' => $sub_task->title,
'startDate' => $sub_task->start_date,
'endDate' => $sub_task->due_date,
'duration' => null,
'percentComplete' => null,
'dependencies' => (string) $task->id,
]);
}
}
}
return response()->json([
'status' => true,
'data' => $finalArr,
'msg' => 'Data fetched',
], 200);
// } catch (\Throwable $th) {
// return response()->json([
// 'status' => false,
// 'msg' => $th->getMessage(),
// ], 400);
// }
}
public function export(Request $request)
{
return Excel::download(new TaskExport($request), 'tasks.xlsx');
}
public function sendMail(Request $request)
{
try {
$task = $this->task->getTaskById($request->task_id);
$message = $request->message;
// $message = str_replace('#name', $task->name, $message);
// $message = str_replace('#email', $task->email, $message);
$data = [
'subject' => $request->subject,
'body' => $message,
];
Mail::to($task->assignedUser)->send(new SendMail($data));
return response()->json([
'status' => true,
'msg' => 'Mail send successfully',
], 200);
} catch (\Throwable $th) {
return response()->json([
'status' => false,
'msg' => $th->getMessage(),
], 500);
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace Modules\PMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\PMS\Repositories\TaskInterface;
use Modules\PMS\Repositories\TaskTimeInterface;
class TaskTimeController extends Controller
{
private $task;
private $tasktime;
public function __construct(
TaskInterface $task,
TaskTimeInterface $tasktime
) {
$this->task = $task;
$this->tasktime = $tasktime;
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
try {
// $request->validate([
// 'start_time' => 'required',
// ]);
$taskModel = $this->task->getTaskById($request->task_id);
$taskTimeModel = $this->tasktime->getLatestTimeByTaskId($request->task_id);
$start_time = is_null($taskTimeModel) ? '00:00:00' : $taskTimeModel->end_time;
$taskModel->taskTime()->create(['start_time' => $start_time, 'end_time' => $request->time]);
return response()->json([
'status' => true,
'msg' => 'Time Store',
], 200);
} catch (\Throwable $th) {
return response()->json([
'status' => false,
'msg' => $th->getMessage(),
], 400);
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('pms::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
return view('pms::edit');
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//
}
}

View File

@@ -0,0 +1,171 @@
<?php
namespace Modules\PMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Auth;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\PMS\Models\Ticket;
use Modules\PMS\Repositories\TicketInterface;
use Modules\Admin\Services\AdminService;
class TicketController extends Controller
{
private $ticketRepository;
private $adminService;
public function __construct(TicketInterface $ticketRepository, AdminService $adminService)
{
$this->adminService = $adminService;
$this->ticketRepository = $ticketRepository;
}
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$data['title'] = 'Ticket List';
$data['tickets'] = $this->ticketRepository->findAll();
$data['statusList'] = Ticket::STATUS;
return view('pms::ticket.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Ticket';
$data['statusList'] = Ticket::STATUS;
$data['priority'] = Ticket::PRIORITY;
$data['ticketType'] = Ticket::TICKET_TYPE;
$data['departmentList'] = $this->adminService->pluckDepartments();
return view('pms::ticket.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
$ticket = $this->ticketRepository->create($inputData);
if ($request->hasFile('file')) {
$path = 'uploads/task';
$inputData['file'] = uploadImage($request->file, $path);
$ticket->documents()->updateOrCreate([
'documentable_id' => $ticket->id,
'documentable_type' => 'Modules\PMS\Models\Ticket',
], [
'document_name' => 'Ticket Files',
'document_path' => $inputData['file'],
]);
}
toastr()->success('Ticket Created Succesfully');
return redirect()->route('ticket.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'View Ticket';
$data['tickets'] = $this->ticketRepository->getTicketById($id);
$data['status'] = Ticket::STATUS;
$data['priority'] = Ticket::PRIORITY;
$data['ticketType'] = Ticket::TICKET_TYPE;
return view('pms::ticket.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Ticket';
$data['ticket'] = $this->ticketRepository->getTicketById($id);
return view('pms::ticket.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
try {
$this->ticketRepository->update($id, $inputData);
toastr()->success('Ticket Update Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('ticket.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->ticketRepository->delete($id);
toastr()->success('Ticket Deleted Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
}
public function storeComment(Request $request)
{
$request->validate([
'content' => 'required',
]);
$ticket = $this->ticketRepository->getTicketById($request->tickets_id);
$ticket->comments()->create(['content' => $request->content, 'comment_by' => Auth::id()]);
return redirect()->back();
}
public function uploadFile(Request $request)
{
$task = $this->ticketRepository->getTicketById($request->task_id);
if ($request->hasFile('file')) {
$path = 'uploads/ticket1';
$fileName = $request->file->getClientOriginalName();
$filePath = uploadImage($request->file, $path);
$task->documents()->create(['document_name' => $fileName, 'document_path' => $filePath]);
}
return response()->json([
'status' => true,
'msg' => 'File Upload',
], 200);
}
public function changeStatus(Request $request)
{
try {
$taskModel = $this->ticketRepository->getTicketById($request->id);
$taskModel->status = $request->changeStatus;
$taskModel->save();
return response()->json([
'status' => true,
'msg' => 'Status Changed',
], 200);
} catch (\Throwable $th) {
return response()->json([
'status' => false,
'msg' => $th->getMessage(),
], 400);
}
}
}