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,178 @@
<?php
namespace Modules\Reminder\Http\Controllers;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Modules\Employee\Models\Employee;
use Modules\Employee\Interfaces\EmployeeInterface;
use Modules\Reminder\Models\Reminder;
use Modules\Template\Emails\SendMail;
use Modules\Template\Repositories\TemplateRepository;
class ReminderController extends Controller
{
private $employee;
/**
* Display a listing of the resource.
*/
public function __construct(
EmployeeInterface $employee,
) {
$this->employee = $employee;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Reminder Lists';
$reminders = Reminder::all()->map(function ($reminder) {
$reminder->assignedEmployees = collect($reminder->members['ids'] ?? [])
->map(function ($id) {
return $this->employee->getEmployeeById($id);
})
->filter();
return $reminder;
});
if (auth()->user()->hasRole('employee')) {
$userId = auth()->user()->employee_id;
$reminders = $reminders->filter(function ($reminder) use ($userId) {
$memberIds = collect($reminder->members['ids'] ?? []);
return $reminder->createdBy == $userId || $memberIds->contains($userId);
});
}
$data['reminderLists'] = $reminders;
return view('reminder::reminder.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Reminder';
$data['editable'] = false;
$data['employeeList'] = $this->employee->pluck(1);
return view('reminder::reminder.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$inputData = $request->except('_token');
$inputData['createdBy'] = Auth::user()->id;
if (auth()->user()->hasRole('employee')) {
$inputData['createdBy'] = auth()->user()->employee_id;
}
$reminderDateTime = Carbon::createFromFormat('Y-m-d H:i', $inputData['reminder_date'] . ' ' . $inputData['reminder_time'], config('app.timezone'));
if ($reminderDateTime->isPast()) {
flash()->error('The reminder date and time must be in the future.');
return back()->withInput();
}
$uploadedFiles = [];
if ($request->hasFile('files')) {
$files = $request->file('files');
if (is_array($files)) {
foreach ($files as $file) {
$uploadedFiles[] = uploadImage($file, 'uploads/reminders/files');
}
} else {
$uploadedFiles[] = uploadImage($files, 'uploads/reminders/files');
}
}
$inputData['files'] = $uploadedFiles;
$reminder = Reminder::create($inputData);
if (config('app.send_mail')) {
$templateModel = (new TemplateRepository())->where(['alias' => 'reminder-template'])->first();
$message = $templateModel->message;
$message = str_replace('#image', asset('storage/' . setting('logo_pic')), $message);
$message = str_replace('#reminder_title', $reminder->title, $message);
$message = str_replace('#reminder_desc', $reminder->description, $message);
$message = str_replace('#reminder_date', Carbon::parse($reminder->reminder_date)->format('d M, Y'), $message);
$message = str_replace('#reminder_time', Carbon::parse($reminder->reminder_time)->format('h:i A'), $message);
$members = $reminder->members ?? [];
foreach ($members as $memberId) {
$employee = $this->employee->getEmployeeById($memberId);
$data = [
'subject' => "New Reminder Assigned: $reminder->title",
'body' => $message,
];
$mail = new SendMail($data);
if (!empty($uploadedFiles)) {
foreach ($uploadedFiles as $filePath) {
$mail->attach(storage_path('app/' . $filePath), [
'as' => basename($filePath),
'mime' => mime_content_type(storage_path('app/' . $filePath))
]);
}
}
Mail::to($employee->email)->send($mail);
}
}
flash()->success('Reminder created successfully!');
return to_route('reminder.index');
}
/**
* Show the specified resource.
*/
public function show(Reminder $reminder)
{
$data['title'] = 'Show Reminder';
$data['reminder'] = $reminder;
return view('reminder::reminder.show', $data);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Reminder $reminder)
{
$originalFiles = json_decode($reminder->getRawOriginal('files'));
if (!empty($originalFiles) && is_array($originalFiles)) {
foreach ($originalFiles as $filePath) {
removeFileFromStorage($filePath);
}
}
$reminder->delete();
return response()->json([
'success' => true,
'message' => 'Reminder deleted successfully!'
]);
}
}